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
This commit is contained in:
gdkchan
2023-02-19 22:37:37 -03:00
committed by GitHub
parent 6bf460e104
commit 7aa430f1a5
27 changed files with 5605 additions and 14 deletions

View File

@ -34,6 +34,126 @@ namespace Ryujinx.Graphics.OpenGL
return TextureWrapMode.Clamp;
}
public static NvBlendEquationAdvanced Convert(this AdvancedBlendOp op)
{
switch (op)
{
case AdvancedBlendOp.Zero:
return NvBlendEquationAdvanced.Zero;
case AdvancedBlendOp.Src:
return NvBlendEquationAdvanced.SrcNv;
case AdvancedBlendOp.Dst:
return NvBlendEquationAdvanced.DstNv;
case AdvancedBlendOp.SrcOver:
return NvBlendEquationAdvanced.SrcOverNv;
case AdvancedBlendOp.DstOver:
return NvBlendEquationAdvanced.DstOverNv;
case AdvancedBlendOp.SrcIn:
return NvBlendEquationAdvanced.SrcInNv;
case AdvancedBlendOp.DstIn:
return NvBlendEquationAdvanced.DstInNv;
case AdvancedBlendOp.SrcOut:
return NvBlendEquationAdvanced.SrcOutNv;
case AdvancedBlendOp.DstOut:
return NvBlendEquationAdvanced.DstOutNv;
case AdvancedBlendOp.SrcAtop:
return NvBlendEquationAdvanced.SrcAtopNv;
case AdvancedBlendOp.DstAtop:
return NvBlendEquationAdvanced.DstAtopNv;
case AdvancedBlendOp.Xor:
return NvBlendEquationAdvanced.XorNv;
case AdvancedBlendOp.Plus:
return NvBlendEquationAdvanced.PlusNv;
case AdvancedBlendOp.PlusClamped:
return NvBlendEquationAdvanced.PlusClampedNv;
case AdvancedBlendOp.PlusClampedAlpha:
return NvBlendEquationAdvanced.PlusClampedAlphaNv;
case AdvancedBlendOp.PlusDarker:
return NvBlendEquationAdvanced.PlusDarkerNv;
case AdvancedBlendOp.Multiply:
return NvBlendEquationAdvanced.MultiplyNv;
case AdvancedBlendOp.Screen:
return NvBlendEquationAdvanced.ScreenNv;
case AdvancedBlendOp.Overlay:
return NvBlendEquationAdvanced.OverlayNv;
case AdvancedBlendOp.Darken:
return NvBlendEquationAdvanced.DarkenNv;
case AdvancedBlendOp.Lighten:
return NvBlendEquationAdvanced.LightenNv;
case AdvancedBlendOp.ColorDodge:
return NvBlendEquationAdvanced.ColordodgeNv;
case AdvancedBlendOp.ColorBurn:
return NvBlendEquationAdvanced.ColorburnNv;
case AdvancedBlendOp.HardLight:
return NvBlendEquationAdvanced.HardlightNv;
case AdvancedBlendOp.SoftLight:
return NvBlendEquationAdvanced.SoftlightNv;
case AdvancedBlendOp.Difference:
return NvBlendEquationAdvanced.DifferenceNv;
case AdvancedBlendOp.Minus:
return NvBlendEquationAdvanced.MinusNv;
case AdvancedBlendOp.MinusClamped:
return NvBlendEquationAdvanced.MinusClampedNv;
case AdvancedBlendOp.Exclusion:
return NvBlendEquationAdvanced.ExclusionNv;
case AdvancedBlendOp.Contrast:
return NvBlendEquationAdvanced.ContrastNv;
case AdvancedBlendOp.Invert:
return NvBlendEquationAdvanced.Invert;
case AdvancedBlendOp.InvertRGB:
return NvBlendEquationAdvanced.InvertRgbNv;
case AdvancedBlendOp.InvertOvg:
return NvBlendEquationAdvanced.InvertOvgNv;
case AdvancedBlendOp.LinearDodge:
return NvBlendEquationAdvanced.LineardodgeNv;
case AdvancedBlendOp.LinearBurn:
return NvBlendEquationAdvanced.LinearburnNv;
case AdvancedBlendOp.VividLight:
return NvBlendEquationAdvanced.VividlightNv;
case AdvancedBlendOp.LinearLight:
return NvBlendEquationAdvanced.LinearlightNv;
case AdvancedBlendOp.PinLight:
return NvBlendEquationAdvanced.PinlightNv;
case AdvancedBlendOp.HardMix:
return NvBlendEquationAdvanced.HardmixNv;
case AdvancedBlendOp.Red:
return NvBlendEquationAdvanced.RedNv;
case AdvancedBlendOp.Green:
return NvBlendEquationAdvanced.GreenNv;
case AdvancedBlendOp.Blue:
return NvBlendEquationAdvanced.BlueNv;
case AdvancedBlendOp.HslHue:
return NvBlendEquationAdvanced.HslHueNv;
case AdvancedBlendOp.HslSaturation:
return NvBlendEquationAdvanced.HslSaturationNv;
case AdvancedBlendOp.HslColor:
return NvBlendEquationAdvanced.HslColorNv;
case AdvancedBlendOp.HslLuminosity:
return NvBlendEquationAdvanced.HslLuminosityNv;
}
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(AdvancedBlendOp)} enum value: {op}.");
return NvBlendEquationAdvanced.Zero;
}
public static All Convert(this AdvancedBlendOverlap overlap)
{
switch (overlap)
{
case AdvancedBlendOverlap.Uncorrelated:
return All.UncorrelatedNv;
case AdvancedBlendOverlap.Disjoint:
return All.DisjointNv;
case AdvancedBlendOverlap.Conjoint:
return All.ConjointNv;
}
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(AdvancedBlendOverlap)} enum value: {overlap}.");
return All.UncorrelatedNv;
}
public static All Convert(this BlendFactor factor)
{
switch (factor)

View File

@ -7,6 +7,7 @@ namespace Ryujinx.Graphics.OpenGL
{
private static readonly Lazy<bool> _supportsAlphaToCoverageDitherControl = new Lazy<bool>(() => HasExtension("GL_NV_alpha_to_coverage_dither_control"));
private static readonly Lazy<bool> _supportsAstcCompression = new Lazy<bool>(() => HasExtension("GL_KHR_texture_compression_astc_ldr"));
private static readonly Lazy<bool> _supportsBlendEquationAdvanced = new Lazy<bool>(() => HasExtension("GL_NV_blend_equation_advanced"));
private static readonly Lazy<bool> _supportsDrawTexture = new Lazy<bool>(() => HasExtension("GL_NV_draw_texture"));
private static readonly Lazy<bool> _supportsFragmentShaderInterlock = new Lazy<bool>(() => HasExtension("GL_ARB_fragment_shader_interlock"));
private static readonly Lazy<bool> _supportsFragmentShaderOrdering = new Lazy<bool>(() => HasExtension("GL_INTEL_fragment_shader_ordering"));
@ -51,6 +52,7 @@ namespace Ryujinx.Graphics.OpenGL
public static bool SupportsAlphaToCoverageDitherControl => _supportsAlphaToCoverageDitherControl.Value;
public static bool SupportsAstcCompression => _supportsAstcCompression.Value;
public static bool SupportsBlendEquationAdvanced => _supportsBlendEquationAdvanced.Value;
public static bool SupportsDrawTexture => _supportsDrawTexture.Value;
public static bool SupportsFragmentShaderInterlock => _supportsFragmentShaderInterlock.Value;
public static bool SupportsFragmentShaderOrdering => _supportsFragmentShaderOrdering.Value;

View File

@ -119,6 +119,7 @@ namespace Ryujinx.Graphics.OpenGL
supportsR4G4B4A4Format: true,
supportsSnormBufferTextureFormat: false,
supports5BitComponentFormat: true,
supportsBlendEquationAdvanced: HwCapabilities.SupportsBlendEquationAdvanced,
supportsFragmentShaderInterlock: HwCapabilities.SupportsFragmentShaderInterlock,
supportsFragmentShaderOrderingIntel: HwCapabilities.SupportsFragmentShaderOrdering,
supportsGeometryShaderPassthrough: HwCapabilities.SupportsGeometryShaderPassthrough,

View File

@ -59,6 +59,7 @@ namespace Ryujinx.Graphics.OpenGL
private uint _fragmentOutputMap;
private uint _componentMasks;
private uint _currentComponentMasks;
private bool _advancedBlendEnable;
private uint _scissorEnables;
@ -784,8 +785,26 @@ namespace Ryujinx.Graphics.OpenGL
GL.Enable(EnableCap.AlphaTest);
}
public void SetBlendState(AdvancedBlendDescriptor blend)
{
if (HwCapabilities.SupportsBlendEquationAdvanced)
{
GL.BlendEquation((BlendEquationMode)blend.Op.Convert());
GL.NV.BlendParameter(NvBlendEquationAdvanced.BlendOverlapNv, (int)blend.Overlap.Convert());
GL.NV.BlendParameter(NvBlendEquationAdvanced.BlendPremultipliedSrcNv, blend.SrcPreMultiplied ? 1 : 0);
GL.Enable(EnableCap.Blend);
_advancedBlendEnable = true;
}
}
public void SetBlendState(int index, BlendDescriptor blend)
{
if (_advancedBlendEnable)
{
GL.Disable(EnableCap.Blend);
_advancedBlendEnable = false;
}
if (!blend.Enable)
{
GL.Disable(IndexedEnableCap.Blend, index);