From 5a391f38fd70abf66aa5e4d390f48afd3f98c3f0 Mon Sep 17 00:00:00 2001 From: sunshineinabox Date: Mon, 9 Sep 2024 21:50:18 -0700 Subject: [PATCH] Refactor Cull Mode to only send face. --- src/Ryujinx.Graphics.GAL/Face.cs | 1 + src/Ryujinx.Graphics.GAL/IPipeline.cs | 2 +- .../Commands/SetFaceCullingCommand.cs | 6 ++---- .../Multithreading/ThreadedPipeline.cs | 4 ++-- src/Ryujinx.Graphics.GAL/ProgramPipelineState.cs | 1 - .../Engine/Threed/StateUpdater.cs | 13 ++++++++++--- src/Ryujinx.Graphics.OpenGL/EnumConversion.cs | 3 +++ src/Ryujinx.Graphics.OpenGL/Pipeline.cs | 6 +++--- src/Ryujinx.Graphics.Vulkan/EnumConversion.cs | 1 + src/Ryujinx.Graphics.Vulkan/PipelineBase.cs | 6 +++--- src/Ryujinx.Graphics.Vulkan/PipelineConverter.cs | 2 +- 11 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/Ryujinx.Graphics.GAL/Face.cs b/src/Ryujinx.Graphics.GAL/Face.cs index 73e43cf239..e204278eb0 100644 --- a/src/Ryujinx.Graphics.GAL/Face.cs +++ b/src/Ryujinx.Graphics.GAL/Face.cs @@ -2,6 +2,7 @@ namespace Ryujinx.Graphics.GAL { public enum Face { + None = 0, Front = 0x404, Back = 0x405, FrontAndBack = 0x408, diff --git a/src/Ryujinx.Graphics.GAL/IPipeline.cs b/src/Ryujinx.Graphics.GAL/IPipeline.cs index cbf1bc3a22..8c71adb9d3 100644 --- a/src/Ryujinx.Graphics.GAL/IPipeline.cs +++ b/src/Ryujinx.Graphics.GAL/IPipeline.cs @@ -52,7 +52,7 @@ namespace Ryujinx.Graphics.GAL void SetDepthMode(DepthMode mode); void SetDepthTest(DepthTestDescriptor depthTest); - void SetFaceCulling(bool enable, Face face); + void SetFaceCulling(Face face); void SetFrontFace(FrontFace frontFace); diff --git a/src/Ryujinx.Graphics.GAL/Multithreading/Commands/SetFaceCullingCommand.cs b/src/Ryujinx.Graphics.GAL/Multithreading/Commands/SetFaceCullingCommand.cs index 611168f850..c88ddba636 100644 --- a/src/Ryujinx.Graphics.GAL/Multithreading/Commands/SetFaceCullingCommand.cs +++ b/src/Ryujinx.Graphics.GAL/Multithreading/Commands/SetFaceCullingCommand.cs @@ -3,18 +3,16 @@ namespace Ryujinx.Graphics.GAL.Multithreading.Commands struct SetFaceCullingCommand : IGALCommand, IGALCommand { public readonly CommandType CommandType => CommandType.SetFaceCulling; - private bool _enable; private Face _face; - public void Set(bool enable, Face face) + public void Set(Face face) { - _enable = enable; _face = face; } public static void Run(ref SetFaceCullingCommand command, ThreadedRenderer threaded, IRenderer renderer) { - renderer.Pipeline.SetFaceCulling(command._enable, command._face); + renderer.Pipeline.SetFaceCulling(command._face); } } } diff --git a/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedPipeline.cs b/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedPipeline.cs index edd79d8a07..8931e10565 100644 --- a/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedPipeline.cs +++ b/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedPipeline.cs @@ -165,9 +165,9 @@ namespace Ryujinx.Graphics.GAL.Multithreading _renderer.QueueCommand(); } - public void SetFaceCulling(bool enable, Face face) + public void SetFaceCulling(Face face) { - _renderer.New().Set(enable, face); + _renderer.New().Set(face); _renderer.QueueCommand(); } diff --git a/src/Ryujinx.Graphics.GAL/ProgramPipelineState.cs b/src/Ryujinx.Graphics.GAL/ProgramPipelineState.cs index fc6e16267e..5bc8e00b71 100644 --- a/src/Ryujinx.Graphics.GAL/ProgramPipelineState.cs +++ b/src/Ryujinx.Graphics.GAL/ProgramPipelineState.cs @@ -51,7 +51,6 @@ namespace Ryujinx.Graphics.GAL public StencilTestDescriptor StencilTest; public FrontFace FrontFace; public Face CullMode; - public bool CullEnable; public PolygonModeMask BiasEnable; diff --git a/src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs b/src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs index 153eef8b01..a5ab82978f 100644 --- a/src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs +++ b/src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs @@ -1198,9 +1198,16 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed var yControl = _state.State.YControl; var face = _state.State.FaceState; - _pipeline.CullEnable = face.CullEnable; - _pipeline.CullMode = face.CullFace; - _context.Renderer.Pipeline.SetFaceCulling(face.CullEnable, face.CullFace); + if (face.CullEnable) + { + _pipeline.CullMode = face.CullFace; + _context.Renderer.Pipeline.SetFaceCulling(face.CullFace); + } + else + { + _pipeline.CullMode = Face.None; + _context.Renderer.Pipeline.SetFaceCulling(Face.None); + } UpdateFrontFace(yControl, face.FrontFace); } diff --git a/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs b/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs index a92c1ce89d..498ba4cc73 100644 --- a/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs +++ b/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs @@ -2,6 +2,7 @@ using OpenTK.Graphics.OpenGL; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.Shader; +using GL = OpenTK.Graphics.ES11.GL; namespace Ryujinx.Graphics.OpenGL { @@ -334,6 +335,8 @@ namespace Ryujinx.Graphics.OpenGL return CullFaceMode.Front; case Face.FrontAndBack: return CullFaceMode.FrontAndBack; + case Face.None: + return (CullFaceMode)All.None; } Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(Face)} enum value: {face}."); diff --git a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs index 54f6b3f7b2..de32695729 100644 --- a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -915,11 +915,11 @@ namespace Ryujinx.Graphics.OpenGL _depthTestEnable = depthTest.TestEnable; } - public void SetFaceCulling(bool enable, Face face) + public void SetFaceCulling(Face face) { - _cullEnable = enable; + _cullEnable = face != Face.None; - if (!enable) + if (!_cullEnable) { GL.Disable(EnableCap.CullFace); return; diff --git a/src/Ryujinx.Graphics.Vulkan/EnumConversion.cs b/src/Ryujinx.Graphics.Vulkan/EnumConversion.cs index babcf992c3..753a2fd43b 100644 --- a/src/Ryujinx.Graphics.Vulkan/EnumConversion.cs +++ b/src/Ryujinx.Graphics.Vulkan/EnumConversion.cs @@ -238,6 +238,7 @@ namespace Ryujinx.Graphics.Vulkan Face.Back => CullModeFlags.BackBit, Face.Front => CullModeFlags.FrontBit, Face.FrontAndBack => CullModeFlags.FrontAndBack, + Face.None => CullModeFlags.None, _ => LogInvalidAndReturn(face, nameof(Face), CullModeFlags.BackBit), }; } diff --git a/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs b/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs index 5eb2fc5594..1716469179 100644 --- a/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs +++ b/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs @@ -908,15 +908,15 @@ namespace Ryujinx.Graphics.Vulkan UpdatePassDepthStencil(); } - public void SetFaceCulling(bool enable, Face face) + public void SetFaceCulling(Face face) { if (_supportExtDynamic) { - DynamicState.SetCullMode(enable ? face.Convert() : CullModeFlags.None); + DynamicState.SetCullMode(face.Convert()); } else { - _newState.CullMode = enable ? face.Convert() : CullModeFlags.None; + _newState.CullMode = face.Convert(); SignalStateChange(); } diff --git a/src/Ryujinx.Graphics.Vulkan/PipelineConverter.cs b/src/Ryujinx.Graphics.Vulkan/PipelineConverter.cs index ecfa1d839b..acf42a9bc1 100644 --- a/src/Ryujinx.Graphics.Vulkan/PipelineConverter.cs +++ b/src/Ryujinx.Graphics.Vulkan/PipelineConverter.cs @@ -180,7 +180,7 @@ namespace Ryujinx.Graphics.Vulkan if (!extendedDynamicState) { pipeline.DepthCompareOp = state.DepthTest.Func.Convert(); - pipeline.CullMode = state.CullEnable ? state.CullMode.Convert() : CullModeFlags.None; + pipeline.CullMode = state.CullMode.Convert(); pipeline.DepthTestEnable = state.DepthTest.TestEnable; pipeline.DepthWriteEnable = state.DepthTest.WriteEnable;