/ src / Ryujinx.Graphics.Gpu / Engine / Threed / Blender / AdvancedBlendUcode.cs
AdvancedBlendUcode.cs
  1  using Ryujinx.Graphics.GAL;
  2  
  3  namespace Ryujinx.Graphics.Gpu.Engine.Threed.Blender
  4  {
  5      /// <summary>
  6      /// Fixed function alpha state used for a advanced blend function.
  7      /// </summary>
  8      readonly struct FixedFunctionAlpha
  9      {
 10          /// <summary>
 11          /// Fixed function alpha state with alpha blending disabled.
 12          /// </summary>
 13          public static FixedFunctionAlpha Disabled => new(BlendUcodeEnable.EnableRGBA, default, default, default);
 14  
 15          /// <summary>
 16          /// Individual enable bits for the RGB and alpha components.
 17          /// </summary>
 18          public BlendUcodeEnable Enable { get; }
 19  
 20          /// <summary>
 21          /// Alpha blend operation.
 22          /// </summary>
 23          public BlendOp AlphaOp { get; }
 24  
 25          /// <summary>
 26          /// Value multiplied with the blend source operand.
 27          /// </summary>
 28          public BlendFactor AlphaSrcFactor { get; }
 29  
 30          /// <summary>
 31          /// Value multiplied with the blend destination operand.
 32          /// </summary>
 33          public BlendFactor AlphaDstFactor { get; }
 34  
 35          /// <summary>
 36          /// Creates a new blend fixed function alpha state.
 37          /// </summary>
 38          /// <param name="enable">Individual enable bits for the RGB and alpha components</param>
 39          /// <param name="alphaOp">Alpha blend operation</param>
 40          /// <param name="alphaSrc">Value multiplied with the blend source operand</param>
 41          /// <param name="alphaDst">Value multiplied with the blend destination operand</param>
 42          public FixedFunctionAlpha(BlendUcodeEnable enable, BlendOp alphaOp, BlendFactor alphaSrc, BlendFactor alphaDst)
 43          {
 44              Enable = enable;
 45              AlphaOp = alphaOp;
 46              AlphaSrcFactor = alphaSrc;
 47              AlphaDstFactor = alphaDst;
 48          }
 49  
 50          /// <summary>
 51          /// Creates a new blend fixed function alpha state.
 52          /// </summary>
 53          /// <param name="alphaOp">Alpha blend operation</param>
 54          /// <param name="alphaSrc">Value multiplied with the blend source operand</param>
 55          /// <param name="alphaDst">Value multiplied with the blend destination operand</param>
 56          public FixedFunctionAlpha(BlendOp alphaOp, BlendFactor alphaSrc, BlendFactor alphaDst) : this(BlendUcodeEnable.EnableRGB, alphaOp, alphaSrc, alphaDst)
 57          {
 58          }
 59      }
 60  
 61      /// <summary>
 62      /// Blend microcode assembly function delegate.
 63      /// </summary>
 64      /// <param name="asm">Assembler</param>
 65      /// <returns>Fixed function alpha state for the microcode</returns>
 66      delegate FixedFunctionAlpha GenUcodeFunc(ref UcodeAssembler asm);
 67  
 68      /// <summary>
 69      /// Advanced blend microcode state.
 70      /// </summary>
 71      readonly struct AdvancedBlendUcode
 72      {
 73          /// <summary>
 74          /// Advanced blend operation.
 75          /// </summary>
 76          public AdvancedBlendOp Op { get; }
 77  
 78          /// <summary>
 79          /// Advanced blend overlap mode.
 80          /// </summary>
 81          public AdvancedBlendOverlap Overlap { get; }
 82  
 83          /// <summary>
 84          /// Whenever the source input is pre-multiplied.
 85          /// </summary>
 86          public bool SrcPreMultiplied { get; }
 87  
 88          /// <summary>
 89          /// Fixed function alpha state.
 90          /// </summary>
 91          public FixedFunctionAlpha Alpha { get; }
 92  
 93          /// <summary>
 94          /// Microcode.
 95          /// </summary>
 96          public uint[] Code { get; }
 97  
 98          /// <summary>
 99          /// Constants used by the microcode.
100          /// </summary>
101          public RgbFloat[] Constants { get; }
102  
103          /// <summary>
104          /// Creates a new advanced blend state.
105          /// </summary>
106          /// <param name="op">Advanced blend operation</param>
107          /// <param name="overlap">Advanced blend overlap mode</param>
108          /// <param name="srcPreMultiplied">Whenever the source input is pre-multiplied</param>
109          /// <param name="genFunc">Function that will generate the advanced blend microcode</param>
110          public AdvancedBlendUcode(
111              AdvancedBlendOp op,
112              AdvancedBlendOverlap overlap,
113              bool srcPreMultiplied,
114              GenUcodeFunc genFunc)
115          {
116              Op = op;
117              Overlap = overlap;
118              SrcPreMultiplied = srcPreMultiplied;
119  
120              UcodeAssembler asm = new();
121              Alpha = genFunc(ref asm);
122              Code = asm.GetCode();
123              Constants = asm.GetConstants();
124          }
125      }
126  }