From 10506afc239fae18e18f216ff70f09f6a33a92d4 Mon Sep 17 00:00:00 2001 From: sunshineinabox Date: Mon, 15 Jul 2024 22:25:20 -0700 Subject: [PATCH] Avoid unncessary DepthBias state updates --- .../Engine/Threed/StateUpdater.cs | 24 +++++++++++++------ src/Ryujinx.Graphics.OpenGL/Pipeline.cs | 9 +++++++ src/Ryujinx.Graphics.Vulkan/PipelineBase.cs | 23 ++++++++++++++++-- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs b/src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs index 569481d8c..c4388fe96 100644 --- a/src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs +++ b/src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs @@ -841,19 +841,29 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed /// 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); } diff --git a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs index 1dcafd718..fb277f94a 100644 --- a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -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); diff --git a/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs b/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs index b664980a7..04d877a0c 100644 --- a/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs +++ b/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs @@ -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,9 +807,15 @@ 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(); + } - SignalStateChange(); } public void SetDepthClamp(bool clamp)