Avoid setting DepthBias when not needed.

This commit is contained in:
sunshineinabox 2024-07-05 00:40:49 -07:00
parent 1a919e99b2
commit 7404d782ce
10 changed files with 90 additions and 34 deletions

View file

@ -47,7 +47,8 @@ namespace Ryujinx.Graphics.GAL
void SetBlendState(AdvancedBlendDescriptor blend);
void SetBlendState(int index, BlendDescriptor blend);
void SetDepthBias(PolygonModeMask enables, float factor, float units, float clamp);
void SetDepthBias(float factor, float units, float clamp);
void SetDepthBiasEnable(PolygonModeMask enables);
void SetDepthClamp(bool clamp);
void SetDepthMode(DepthMode mode);
void SetDepthTest(DepthTestDescriptor depthTest);

View file

@ -116,6 +116,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading
Register<SetBlendStateAdvancedCommand>(CommandType.SetBlendStateAdvanced);
Register<SetBlendStateCommand>(CommandType.SetBlendState);
Register<SetDepthBiasCommand>(CommandType.SetDepthBias);
Register<SetDepthBiasEnableCommand>(CommandType.SetDepthBiasEnable);
Register<SetDepthClampCommand>(CommandType.SetDepthClamp);
Register<SetDepthModeCommand>(CommandType.SetDepthMode);
Register<SetDepthTestCommand>(CommandType.SetDepthTest);

View file

@ -76,6 +76,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading
SetBlendStateAdvanced,
SetBlendState,
SetDepthBias,
SetDepthBiasEnable,
SetDepthClamp,
SetDepthMode,
SetDepthTest,

View file

@ -3,14 +3,12 @@ namespace Ryujinx.Graphics.GAL.Multithreading.Commands
struct SetDepthBiasCommand : IGALCommand, IGALCommand<SetDepthBiasCommand>
{
public readonly CommandType CommandType => CommandType.SetDepthBias;
private PolygonModeMask _enables;
private float _factor;
private float _units;
private float _clamp;
public void Set(PolygonModeMask enables, float factor, float units, float clamp)
public void Set(float factor, float units, float clamp)
{
_enables = enables;
_factor = factor;
_units = units;
_clamp = clamp;
@ -18,7 +16,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading.Commands
public static void Run(ref SetDepthBiasCommand command, ThreadedRenderer threaded, IRenderer renderer)
{
renderer.Pipeline.SetDepthBias(command._enables, command._factor, command._units, command._clamp);
renderer.Pipeline.SetDepthBias(command._factor, command._units, command._clamp);
}
}
}

View file

@ -0,0 +1,19 @@
namespace Ryujinx.Graphics.GAL.Multithreading.Commands
{
struct SetDepthBiasEnableCommand : IGALCommand, IGALCommand<SetDepthBiasEnableCommand>
{
public readonly CommandType CommandType => CommandType.SetDepthBias;
private PolygonModeMask _enables;
public void Set(PolygonModeMask enables)
{
_enables = enables;
}
public static void Run(ref SetDepthBiasEnableCommand command, ThreadedRenderer threaded, IRenderer renderer)
{
renderer.Pipeline.SetDepthBiasEnable(command._enables);
}
}
}

View file

@ -141,9 +141,15 @@ namespace Ryujinx.Graphics.GAL.Multithreading
_renderer.QueueCommand();
}
public void SetDepthBias(PolygonModeMask enables, float factor, float units, float clamp)
public void SetDepthBias(float factor, float units, float clamp)
{
_renderer.New<SetDepthBiasCommand>().Set(enables, factor, units, clamp);
_renderer.New<SetDepthBiasCommand>().Set(factor, units, clamp);
_renderer.QueueCommand();
}
public void SetDepthBiasEnable(PolygonModeMask enables)
{
_renderer.New<SetDepthBiasEnableCommand>().Set(enables);
_renderer.QueueCommand();
}

View file

@ -849,12 +849,25 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
PolygonModeMask enables;
if (factor == 0 && units == 0)
{
enables = 0;
}
else
{
enables = (depthBias.PointEnable ? PolygonModeMask.Point : 0);
enables |= (depthBias.LineEnable ? PolygonModeMask.Line : 0);
enables |= (depthBias.FillEnable ? PolygonModeMask.Fill : 0);
}
_pipeline.BiasEnable = enables;
_context.Renderer.Pipeline.SetDepthBias(enables, factor, units / 2f, clamp);
_context.Renderer.Pipeline.SetDepthBiasEnable(enables);
if (enables != 0)
{
_context.Renderer.Pipeline.SetDepthBias(factor, units / 2f, clamp);
}
}
/// <summary>

View file

@ -831,8 +831,25 @@ namespace Ryujinx.Graphics.OpenGL
GL.Enable(IndexedEnableCap.Blend, index);
}
public void SetDepthBias(PolygonModeMask enables, float factor, float units, float clamp)
public void SetDepthBias(float factor, float units, float clamp)
{
if (HwCapabilities.SupportsPolygonOffsetClamp)
{
GL.PolygonOffsetClamp(factor, units, clamp);
}
else
{
GL.PolygonOffset(factor, units);
}
}
public void SetDepthBiasEnable(PolygonModeMask enables)
{
if (enables == 0)
{
return;
}
if ((enables & PolygonModeMask.Point) != 0)
{
GL.Enable(EnableCap.PolygonOffsetPoint);
@ -859,20 +876,6 @@ namespace Ryujinx.Graphics.OpenGL
{
GL.Disable(EnableCap.PolygonOffsetFill);
}
if (enables == 0)
{
return;
}
if (HwCapabilities.SupportsPolygonOffsetClamp)
{
GL.PolygonOffsetClamp(factor, units, clamp);
}
else
{
GL.PolygonOffset(factor, units);
}
}
public void SetDepthClamp(bool clamp)

View file

@ -785,11 +785,17 @@ namespace Ryujinx.Graphics.Vulkan
SignalStateChange();
}
public void SetDepthBias(PolygonModeMask enables, float factor, float units, float clamp)
public void SetDepthBias(float factor, float units, float clamp)
{
DynamicState.SetDepthBias(factor, units, clamp);
SignalStateChange();
}
public void SetDepthBiasEnable(PolygonModeMask enables)
{
_newState.DepthBiasEnable = enables != 0;
SignalStateChange();
}

View file

@ -564,21 +564,29 @@ namespace Ryujinx.Graphics.Vulkan
}
bool supportsExtDynamicState = gd.Capabilities.SupportsExtendedDynamicState;
int dynamicStatesCount = supportsExtDynamicState ? 8 : 7;
int dynamicStatesCount = supportsExtDynamicState ? 7 : 6;
if (DepthBiasEnable)
{
dynamicStatesCount++;
}
DynamicState* dynamicStates = stackalloc DynamicState[dynamicStatesCount];
dynamicStates[0] = DynamicState.Viewport;
dynamicStates[1] = DynamicState.Scissor;
dynamicStates[2] = DynamicState.DepthBias;
dynamicStates[3] = DynamicState.StencilCompareMask;
dynamicStates[4] = DynamicState.StencilWriteMask;
dynamicStates[5] = DynamicState.StencilReference;
dynamicStates[6] = DynamicState.BlendConstants;
dynamicStates[2] = DynamicState.StencilCompareMask;
dynamicStates[3] = DynamicState.StencilWriteMask;
dynamicStates[4] = DynamicState.StencilReference;
dynamicStates[5] = DynamicState.BlendConstants;
if (DepthBiasEnable)
{
dynamicStates[6] = DynamicState.DepthBias;
}
if (supportsExtDynamicState)
{
dynamicStates[7] = DynamicState.VertexInputBindingStrideExt;
dynamicStates[dynamicStatesCount - 1] = DynamicState.VertexInputBindingStrideExt;
}
var pipelineDynamicStateCreateInfo = new PipelineDynamicStateCreateInfo