From 4a3932ed54e40dfc5692a7664b5d2c76720137e1 Mon Sep 17 00:00:00 2001 From: sunshineinabox Date: Sun, 26 May 2024 22:33:49 -0700 Subject: [PATCH] Use dictionary instead for clarity and rework some logic. --- src/Ryujinx.Graphics.Vulkan/PipelineBase.cs | 44 +++++++++---------- .../PipelineDynamicState.cs | 4 +- src/Ryujinx.Graphics.Vulkan/PipelineState.cs | 15 +++---- 3 files changed, 29 insertions(+), 34 deletions(-) diff --git a/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs b/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs index 1f8677b81..32e27ada9 100644 --- a/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs +++ b/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs @@ -2,6 +2,7 @@ using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.Shader; using Silk.NET.Vulkan; using System; +using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Runtime.CompilerServices; @@ -1067,7 +1068,7 @@ namespace Ryujinx.Graphics.Vulkan primitiveRestartEnable &= topologySupportsRestart; - //Cannot disable primitveRestartEnable for these Topoligies on MacOS + //Cannot disable primitiveRestartEnable for these Topologies on MacOS if ((_newState.Topology == Silk.NET.Vulkan.PrimitiveTopology.LineStrip || _newState.Topology == Silk.NET.Vulkan.PrimitiveTopology.TriangleStrip || _newState.Topology == Silk.NET.Vulkan.PrimitiveTopology.LineStripWithAdjacency || _newState.Topology == Silk.NET.Vulkan.PrimitiveTopology.TriangleStripWithAdjacency) && Gd.IsMoltenVk) @@ -1093,19 +1094,15 @@ namespace Ryujinx.Graphics.Vulkan _topology = topology; var vkTopology = Gd.TopologyRemap(topology).Convert(); - - var currentTopologyClass = GetTopologyClass(_newState.Topology); var newTopologyClass = GetTopologyClass(vkTopology); + var currentTopologyClass = GetTopologyClass(_newState.Topology); if (_supportExtDynamic) { DynamicState.SetPrimitiveTopology(vkTopology); - if (currentTopologyClass != newTopologyClass) - { - _newState.Topology = vkTopology; - } } - else + + if (!_supportExtDynamic || currentTopologyClass != newTopologyClass) { _newState.Topology = vkTopology; } @@ -1115,23 +1112,24 @@ namespace Ryujinx.Graphics.Vulkan private TopologyClass GetTopologyClass(Silk.NET.Vulkan.PrimitiveTopology topology) { - return topology switch - { - 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, - _ => throw new ArgumentOutOfRangeException(nameof(topology), topology, null) - }; + 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, diff --git a/src/Ryujinx.Graphics.Vulkan/PipelineDynamicState.cs b/src/Ryujinx.Graphics.Vulkan/PipelineDynamicState.cs index d421086dd..e873e1d5e 100644 --- a/src/Ryujinx.Graphics.Vulkan/PipelineDynamicState.cs +++ b/src/Ryujinx.Graphics.Vulkan/PipelineDynamicState.cs @@ -230,12 +230,12 @@ namespace Ryujinx.Graphics.Vulkan if (gd.Capabilities.SupportsExtendedDynamicState) { - _dirty = DirtyFlags.Standard | DirtyFlags.Extended; + _dirty |= DirtyFlags.Extended; } if (gd.Capabilities.SupportsExtendedDynamicState2) { - _dirty = DirtyFlags.Standard | DirtyFlags.Extended | DirtyFlags.Extended2; + _dirty |= DirtyFlags.Extended2; } if (gd.IsMoltenVk) diff --git a/src/Ryujinx.Graphics.Vulkan/PipelineState.cs b/src/Ryujinx.Graphics.Vulkan/PipelineState.cs index fa66e9fd8..c8ffece2d 100644 --- a/src/Ryujinx.Graphics.Vulkan/PipelineState.cs +++ b/src/Ryujinx.Graphics.Vulkan/PipelineState.cs @@ -391,11 +391,6 @@ namespace Ryujinx.Graphics.Vulkan RenderPass renderPass, bool throwOnError = false) { - if (program.TryGetGraphicsPipeline(ref Internal, out var pipeline)) - { - return pipeline; - } - // Using patches topology without a tessellation shader is invalid. // If we find such a case, return null pipeline to skip the draw. if (Topology == PrimitiveTopology.PatchList && !HasTessellationControlShader) @@ -405,6 +400,11 @@ namespace Ryujinx.Graphics.Vulkan return null; } + if (program.TryGetGraphicsPipeline(ref Internal, out var pipeline)) + { + return pipeline; + } + Pipeline pipelineHandle = default; bool isMoltenVk = gd.IsMoltenVk; @@ -426,6 +426,7 @@ namespace Ryujinx.Graphics.Vulkan { SType = StructureType.PipelineVertexInputStateCreateInfo, VertexAttributeDescriptionCount = VertexAttributeDescriptionsCount, + PVertexAttributeDescriptions = isMoltenVk ? pVertexAttributeDescriptions2 : pVertexAttributeDescriptions, VertexBindingDescriptionCount = VertexBindingDescriptionsCount, PVertexBindingDescriptions = pVertexBindingDescriptions, }; @@ -455,8 +456,6 @@ namespace Ryujinx.Graphics.Vulkan if (isMoltenVk) { - vertexInputState.PVertexAttributeDescriptions = pVertexAttributeDescriptions2; - //When widelines feature is not supported it must be 1.0f per spec. rasterizationState.LineWidth = 1.0f; } @@ -585,8 +584,6 @@ namespace Ryujinx.Graphics.Vulkan if (!isMoltenVk) { - vertexInputState.PVertexAttributeDescriptions = pVertexAttributeDescriptions; - baseDynamicStatesCount++; }