From 7aa430f1a51fd793971992b4454540975222b848 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sun, 19 Feb 2023 22:37:37 -0300 Subject: Add support for advanced blend (part 1/2) (#2801) * Add blend microcode registers * Add advanced blend support using host extension * Remove debug message * Use pre-generated table for blend functions * XML docs * Rename AdvancedBlendMode to AdvancedBlendOp for consistency * Remove redundant code * Fix some advanced blend related issues on Vulkan * Formatting --- .../Engine/Threed/Blender/AdvancedBlendUcode.cs | 126 +++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 Ryujinx.Graphics.Gpu/Engine/Threed/Blender/AdvancedBlendUcode.cs (limited to 'Ryujinx.Graphics.Gpu/Engine/Threed/Blender/AdvancedBlendUcode.cs') diff --git a/Ryujinx.Graphics.Gpu/Engine/Threed/Blender/AdvancedBlendUcode.cs b/Ryujinx.Graphics.Gpu/Engine/Threed/Blender/AdvancedBlendUcode.cs new file mode 100644 index 00000000..f06b4bf7 --- /dev/null +++ b/Ryujinx.Graphics.Gpu/Engine/Threed/Blender/AdvancedBlendUcode.cs @@ -0,0 +1,126 @@ +using Ryujinx.Graphics.GAL; + +namespace Ryujinx.Graphics.Gpu.Engine.Threed.Blender +{ + /// + /// Fixed function alpha state used for a advanced blend function. + /// + struct FixedFunctionAlpha + { + /// + /// Fixed function alpha state with alpha blending disabled. + /// + public static FixedFunctionAlpha Disabled => new FixedFunctionAlpha(BlendUcodeEnable.EnableRGBA, default, default, default); + + /// + /// Individual enable bits for the RGB and alpha components. + /// + public BlendUcodeEnable Enable { get; } + + /// + /// Alpha blend operation. + /// + public BlendOp AlphaOp { get; } + + /// + /// Value multiplied with the blend source operand. + /// + public BlendFactor AlphaSrcFactor { get; } + + /// + /// Value multiplied with the blend destination operand. + /// + public BlendFactor AlphaDstFactor { get; } + + /// + /// Creates a new blend fixed function alpha state. + /// + /// Individual enable bits for the RGB and alpha components + /// Alpha blend operation + /// Value multiplied with the blend source operand + /// Value multiplied with the blend destination operand + public FixedFunctionAlpha(BlendUcodeEnable enable, BlendOp alphaOp, BlendFactor alphaSrc, BlendFactor alphaDst) + { + Enable = enable; + AlphaOp = alphaOp; + AlphaSrcFactor = alphaSrc; + AlphaDstFactor = alphaDst; + } + + /// + /// Creates a new blend fixed function alpha state. + /// + /// Alpha blend operation + /// Value multiplied with the blend source operand + /// Value multiplied with the blend destination operand + public FixedFunctionAlpha(BlendOp alphaOp, BlendFactor alphaSrc, BlendFactor alphaDst) : this(BlendUcodeEnable.EnableRGB, alphaOp, alphaSrc, alphaDst) + { + } + } + + /// + /// Blend microcode assembly function delegate. + /// + /// Assembler + /// Fixed function alpha state for the microcode + delegate FixedFunctionAlpha GenUcodeFunc(ref UcodeAssembler asm); + + /// + /// Advanced blend microcode state. + /// + struct AdvancedBlendUcode + { + /// + /// Advanced blend operation. + /// + public AdvancedBlendOp Op { get; } + + /// + /// Advanced blend overlap mode. + /// + public AdvancedBlendOverlap Overlap { get; } + + /// + /// Whenever the source input is pre-multiplied. + /// + public bool SrcPreMultiplied { get; } + + /// + /// Fixed function alpha state. + /// + public FixedFunctionAlpha Alpha { get; } + + /// + /// Microcode. + /// + public uint[] Code { get; } + + /// + /// Constants used by the microcode. + /// + public RgbFloat[] Constants { get; } + + /// + /// Creates a new advanced blend state. + /// + /// Advanced blend operation + /// Advanced blend overlap mode + /// Whenever the source input is pre-multiplied + /// Function that will generate the advanced blend microcode + public AdvancedBlendUcode( + AdvancedBlendOp op, + AdvancedBlendOverlap overlap, + bool srcPreMultiplied, + GenUcodeFunc genFunc) + { + Op = op; + Overlap = overlap; + SrcPreMultiplied = srcPreMultiplied; + + UcodeAssembler asm = new UcodeAssembler(); + Alpha = genFunc(ref asm); + Code = asm.GetCode(); + Constants = asm.GetConstants(); + } + } +} \ No newline at end of file -- cgit v1.2.3