From 2cba50a9ed595d46beea3a94194a6b37bacc76ce Mon Sep 17 00:00:00 2001 From: sunshineinabox Date: Tue, 23 Jul 2024 21:54:01 -0700 Subject: [PATCH] Move TopologyClass conversoin to EnumConversion.cs --- src/Ryujinx.Graphics.Vulkan/EnumConversion.cs | 22 ++++++++++ src/Ryujinx.Graphics.Vulkan/PipelineBase.cs | 41 +++---------------- 2 files changed, 28 insertions(+), 35 deletions(-) diff --git a/src/Ryujinx.Graphics.Vulkan/EnumConversion.cs b/src/Ryujinx.Graphics.Vulkan/EnumConversion.cs index 9d1fd9ffd..d58603cd6 100644 --- a/src/Ryujinx.Graphics.Vulkan/EnumConversion.cs +++ b/src/Ryujinx.Graphics.Vulkan/EnumConversion.cs @@ -310,6 +310,28 @@ namespace Ryujinx.Graphics.Vulkan }; } + public static PrimitiveTopology ConvertToClass(this GAL.PrimitiveTopology topology) + { + return topology switch + { + GAL.PrimitiveTopology.Points => PrimitiveTopology.PointList, + GAL.PrimitiveTopology.Lines or + GAL.PrimitiveTopology.LineStrip or + GAL.PrimitiveTopology.LinesAdjacency or + GAL.PrimitiveTopology.LineStripAdjacency => PrimitiveTopology.LineList, + GAL.PrimitiveTopology.Triangles or + GAL.PrimitiveTopology.TriangleStrip or + GAL.PrimitiveTopology.TriangleFan or + GAL.PrimitiveTopology.TrianglesAdjacency or + GAL.PrimitiveTopology.TriangleStripAdjacency or + GAL.PrimitiveTopology.Polygon => PrimitiveTopology.TriangleList, + GAL.PrimitiveTopology.Patches => PrimitiveTopology.PatchList, + GAL.PrimitiveTopology.Quads => throw new NotSupportedException("Quad topology is not available in Vulkan."), + GAL.PrimitiveTopology.QuadStrip => throw new NotSupportedException("QuadStrip topology is not available in Vulkan."), + _ => LogInvalidAndReturn(topology, nameof(GAL.PrimitiveTopology), PrimitiveTopology.TriangleList), + }; + } + public static StencilOp Convert(this GAL.StencilOp op) { return op switch diff --git a/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs b/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs index eed18c6dd..4b3221fdd 100644 --- a/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs +++ b/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs @@ -640,6 +640,7 @@ namespace Ryujinx.Graphics.Vulkan var oldDepthTestEnable = _supportExtDynamic ? DynamicState.DepthTestEnable : _newState.DepthTestEnable; var oldDepthWriteEnable = _supportExtDynamic ? DynamicState.DepthWriteEnable : _newState.DepthWriteEnable; var oldTopology = _newState.Topology; + var oldTopologyClass = _newState.TopologyClass; var oldViewports = DynamicState.Viewports; var oldViewportsCount = _supportExtDynamic ? DynamicState.ViewportsCount : _newState.ViewportsCount; @@ -669,9 +670,7 @@ namespace Ryujinx.Graphics.Vulkan if (_supportExtDynamic) { - var oldTopologyClass = GetTopologyClass(oldTopology); - - if (oldTopologyClass != TopologyClass.Triangle) + if (oldTopologyClass != Silk.NET.Vulkan.PrimitiveTopology.TriangleList) { _newState.TopologyClass = oldTopology; } @@ -1070,12 +1069,12 @@ namespace Ryujinx.Graphics.Vulkan if (_supportExtDynamic) { - var newTopologyClass = GetTopologyClass(vkTopology); - var currentTopologyClass = GetTopologyClass(_newState.TopologyClass); + var oldTopologyClass = _newState.TopologyClass; + var newTopologyClass = Gd.TopologyRemap(topology).ConvertToClass(); - if ((currentTopologyClass != newTopologyClass)) + if ((oldTopologyClass != newTopologyClass)) { - _newState.TopologyClass = vkTopology; + _newState.TopologyClass = newTopologyClass; } DynamicState.SetPrimitiveTopology(vkTopology); @@ -1086,34 +1085,6 @@ namespace Ryujinx.Graphics.Vulkan SignalStateChange(); } - private TopologyClass GetTopologyClass(Silk.NET.Vulkan.PrimitiveTopology topology) - { - return _topologyClassMapping.TryGetValue(topology, out var topologyClass) ? topologyClass : throw new ArgumentOutOfRangeException(nameof(topology), topology, null); - } - - private static readonly Dictionary _topologyClassMapping = new() - { - { Silk.NET.Vulkan.PrimitiveTopology.PointList, TopologyClass.Point }, - { Silk.NET.Vulkan.PrimitiveTopology.LineList, TopologyClass.Line }, - { Silk.NET.Vulkan.PrimitiveTopology.LineStrip, TopologyClass.Line }, - { Silk.NET.Vulkan.PrimitiveTopology.LineListWithAdjacency, TopologyClass.Line }, - { Silk.NET.Vulkan.PrimitiveTopology.LineStripWithAdjacency, TopologyClass.Line }, - { Silk.NET.Vulkan.PrimitiveTopology.TriangleList, TopologyClass.Triangle }, - { Silk.NET.Vulkan.PrimitiveTopology.TriangleStrip, TopologyClass.Triangle }, - { Silk.NET.Vulkan.PrimitiveTopology.TriangleFan, TopologyClass.Triangle }, - { Silk.NET.Vulkan.PrimitiveTopology.TriangleListWithAdjacency, TopologyClass.Triangle }, - { Silk.NET.Vulkan.PrimitiveTopology.TriangleStripWithAdjacency, TopologyClass.Triangle }, - { Silk.NET.Vulkan.PrimitiveTopology.PatchList, TopologyClass.Patch } - }; - - private enum TopologyClass - { - Point, - Line, - Triangle, - Patch - } - public void SetProgram(IProgram program) { var internalProgram = (ShaderCollection)program;