From 1fa1c7b01d47d2cc69955ef32eb1dafa98b12489 Mon Sep 17 00:00:00 2001 From: sunshineinabox Date: Mon, 2 Sep 2024 20:18:24 -0700 Subject: [PATCH] Need to test this on Windows --- src/Ryujinx.Graphics.Vulkan/PipelineBase.cs | 11 ++++------- src/Ryujinx.Graphics.Vulkan/PipelineConverter.cs | 8 ++++---- src/Ryujinx.Graphics.Vulkan/PipelineDynamicState.cs | 2 -- src/Ryujinx.Graphics.Vulkan/PipelineState.cs | 10 ++++++++-- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs b/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs index 406372dc83..5d00a30caf 100644 --- a/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs +++ b/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs @@ -674,9 +674,9 @@ namespace Ryujinx.Graphics.Vulkan if (_supportExtDynamic) { - if (oldTopology.ConvertToClass() != _newState.Topology.ConvertToClass()) + if (oldTopology != _newState.Topology.ConvertToClass()) { - _newState.Topology = oldTopology.ConvertToClass(); + _newState.Topology = oldTopology; } DynamicState.SetCullMode(oldCullMode); @@ -971,7 +971,7 @@ namespace Ryujinx.Graphics.Vulkan // so we need to force disable them here. bool logicOpEnable = enable && (Gd.Vendor == Vendor.Nvidia || _newState.Internal.LogicOpsAllowed); - _newState.LogicOpEnable = logicOpEnable; + _newState.LogicOpEnable = enable; if (Gd.Capabilities.SupportsExtendedDynamicState2.ExtendedDynamicState2LogicOp) { @@ -979,7 +979,6 @@ namespace Ryujinx.Graphics.Vulkan { DynamicState.SetLogicOp(op.Convert()); } - } else { @@ -1041,8 +1040,6 @@ namespace Ryujinx.Graphics.Vulkan public void SetPrimitiveTopology(PrimitiveTopology topology) { - topology = _newState.HasTessellationControlShader ? PrimitiveTopology.Patches : topology; - _topology = topology; var vkTopology = Gd.TopologyRemap(topology).Convert(); @@ -1402,7 +1399,7 @@ namespace Ryujinx.Graphics.Vulkan _newState.Internal.VertexBindingDescriptions[descriptorIndex] = new VertexInputBindingDescription( (uint)binding, - _supportExtDynamic && !Gd.IsMoltenVk ? 0 : (uint)vertexBuffer.Stride, + _supportExtDynamic && !Gd.IsMoltenVk ? default : (uint)vertexBuffer.Stride, inputRate); int vbSize = vertexBuffer.Buffer.Size; diff --git a/src/Ryujinx.Graphics.Vulkan/PipelineConverter.cs b/src/Ryujinx.Graphics.Vulkan/PipelineConverter.cs index 27f1c047b5..4c1c1dad20 100644 --- a/src/Ryujinx.Graphics.Vulkan/PipelineConverter.cs +++ b/src/Ryujinx.Graphics.Vulkan/PipelineConverter.cs @@ -229,6 +229,8 @@ namespace Ryujinx.Graphics.Vulkan pipeline.Topology = topology; + pipeline.LogicOpEnable = state.LogicOpEnable; + int vaCount = Math.Min(Constants.MaxVertexAttributes, state.VertexAttribCount); int vbCount = Math.Min(Constants.MaxVertexBuffers, state.VertexBufferCount); @@ -272,7 +274,7 @@ namespace Ryujinx.Graphics.Vulkan // TODO: Support divisor > 1 pipeline.Internal.VertexBindingDescriptions[descriptorIndex++] = new VertexInputBindingDescription( (uint)i + 1, - extendedDynamicState && !gd.IsMoltenVk ? 0 : (uint)alignedStride, + extendedDynamicState && !gd.IsMoltenVk ? default : (uint)alignedStride, inputRate); } } @@ -336,9 +338,7 @@ namespace Ryujinx.Graphics.Vulkan pipeline.Internal.LogicOpsAllowed = attachmentCount == 0 || !allFormatsFloatOrSrgb; bool logicOpEnable = state.LogicOpEnable && - (gd.Vendor == Vendor.Nvidia || (attachmentCount == 0 || !allFormatsFloatOrSrgb)); - - pipeline.LogicOpEnable = logicOpEnable; + (gd.Vendor == Vendor.Nvidia || pipeline.Internal.LogicOpsAllowed); if (!extendedDynamicState2.ExtendedDynamicState2LogicOp) { diff --git a/src/Ryujinx.Graphics.Vulkan/PipelineDynamicState.cs b/src/Ryujinx.Graphics.Vulkan/PipelineDynamicState.cs index 66dfc1b3e7..8a3fa7f82f 100644 --- a/src/Ryujinx.Graphics.Vulkan/PipelineDynamicState.cs +++ b/src/Ryujinx.Graphics.Vulkan/PipelineDynamicState.cs @@ -276,8 +276,6 @@ namespace Ryujinx.Graphics.Vulkan public void ReplayIfDirty(VulkanRenderer gd, CommandBuffer commandBuffer) { - _ = gd.Api; - if (_dirty.HasFlag(DirtyFlags.Blend)) { RecordBlend(gd.Api, commandBuffer); diff --git a/src/Ryujinx.Graphics.Vulkan/PipelineState.cs b/src/Ryujinx.Graphics.Vulkan/PipelineState.cs index 8739aaec56..a3b60e74cf 100644 --- a/src/Ryujinx.Graphics.Vulkan/PipelineState.cs +++ b/src/Ryujinx.Graphics.Vulkan/PipelineState.cs @@ -420,10 +420,12 @@ namespace Ryujinx.Graphics.Vulkan PVertexBindingDescriptions = pVertexBindingDescriptions, }; + var topology = HasTessellationControlShader ? PrimitiveTopology.PatchList : Topology; + var inputAssemblyState = new PipelineInputAssemblyStateCreateInfo { SType = StructureType.PipelineInputAssemblyStateCreateInfo, - Topology = Topology, + Topology = topology, }; PipelineTessellationStateCreateInfo tessellationState; @@ -554,12 +556,16 @@ namespace Ryujinx.Graphics.Vulkan } } + // Vendors other than NVIDIA have a bug where it enables logical operations even for float formats, + // so we need to force disable them here. + bool logicOpEnable = LogicOpEnable && (gd.Vendor == Vendor.Nvidia || Internal.LogicOpsAllowed); + var colorBlendState = new PipelineColorBlendStateCreateInfo { SType = StructureType.PipelineColorBlendStateCreateInfo, AttachmentCount = ColorBlendAttachmentStateCount, PAttachments = pColorBlendAttachmentState, - LogicOpEnable = LogicOpEnable, + LogicOpEnable = logicOpEnable, }; if (!gd.Capabilities.SupportsExtendedDynamicState2.ExtendedDynamicState2LogicOp)