AdvancedBlendUcode.cs 4.3 KB

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