Avoid unncessary DepthBias state updates

This commit is contained in:
sunshineinabox 2024-07-15 22:25:20 -07:00
parent 7404d782ce
commit 10506afc23
3 changed files with 47 additions and 9 deletions

View file

@ -841,19 +841,29 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
private void UpdateDepthBiasState()
{
if (_pipeline.BiasEnable == 0 && (_state.State.DepthBiasFactor == 0 && _state.State.DepthBiasUnits == 0))
{
return;
}
else if (_pipeline.BiasEnable != 0 &&
(_state.State.DepthBiasFactor == 0 && _state.State.DepthBiasUnits == 0))
{
_pipeline.BiasEnable = 0;
_context.Renderer.Pipeline.SetDepthBiasEnable(0);
return;
}
var depthBias = _state.State.DepthBiasState;
float factor = _state.State.DepthBiasFactor;
float units = _state.State.DepthBiasUnits;
float clamp = _state.State.DepthBiasClamp;
PolygonModeMask enables;
PolygonModeMask enables = 0;
if (factor == 0 && units == 0)
{
enables = 0;
}
else
if (factor != 0 && units != 0)
{
enables = (depthBias.PointEnable ? PolygonModeMask.Point : 0);
enables |= (depthBias.LineEnable ? PolygonModeMask.Line : 0);
@ -864,7 +874,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
_context.Renderer.Pipeline.SetDepthBiasEnable(enables);
if (enables != 0)
if (enables > 0)
{
_context.Renderer.Pipeline.SetDepthBias(factor, units / 2f, clamp);
}

View file

@ -833,6 +833,15 @@ namespace Ryujinx.Graphics.OpenGL
public void SetDepthBias(float factor, float units, float clamp)
{
if (factor == 0 && units == 0)
{
GL.Disable(EnableCap.PolygonOffsetPoint);
GL.Disable(EnableCap.PolygonOffsetLine);
GL.Disable(EnableCap.PolygonOffsetFill);
return;
}
if (HwCapabilities.SupportsPolygonOffsetClamp)
{
GL.PolygonOffsetClamp(factor, units, clamp);

View file

@ -787,6 +787,19 @@ namespace Ryujinx.Graphics.Vulkan
public void SetDepthBias(float factor, float units, float clamp)
{
if (factor == 0 && units == 0 && _newState.DepthBiasEnable)
{
_newState.DepthBiasEnable = false;
SignalStateChange();
return;
}
else if (factor == 0 && units == 0 && !_newState.DepthBiasEnable)
{
return;
}
DynamicState.SetDepthBias(factor, units, clamp);
SignalStateChange();
@ -794,11 +807,17 @@ namespace Ryujinx.Graphics.Vulkan
public void SetDepthBiasEnable(PolygonModeMask enables)
{
_newState.DepthBiasEnable = enables != 0;
bool depthBiasEnable = enables != 0;
if (_newState.DepthBiasEnable != depthBiasEnable)
{
_newState.DepthBiasEnable = depthBiasEnable;
SignalStateChange();
}
}
public void SetDepthClamp(bool clamp)
{
_newState.DepthClampEnable = clamp;