From 45ce25e84702383ef0dc0f7edef029556b96b2dd Mon Sep 17 00:00:00 2001 From: sunshineinabox Date: Mon, 30 Sep 2024 21:04:39 -0700 Subject: [PATCH] Upon closer inspection actually descriptorIndex is only iterrated when there is a valid buffer, but bindings are always i+1. This could lead to potential errors. --- src/Ryujinx.Graphics.Vulkan/PipelineBase.cs | 25 ++++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs b/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs index 7ea06b3dec..ee16714643 100644 --- a/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs +++ b/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs @@ -100,6 +100,8 @@ namespace Ryujinx.Graphics.Vulkan public ulong DrawCount { get; private set; } public bool RenderPassActive { get; private set; } + private readonly int[] _vertexBufferBindings; + public unsafe PipelineBase(VulkanRenderer gd, Device device) { Gd = gd; @@ -138,7 +140,11 @@ namespace Ryujinx.Graphics.Vulkan _bindingsSet = false; - _newState.Internal.VertexBindingDescriptions[0] = new VertexInputBindingDescription(0, _supportExtDynamic && (!Gd.IsMoltenVk || Gd.SupportsMTL31) ? null : 0, VertexInputRate.Vertex); + _vertexBufferBindings = new int[Constants.MaxVertexBuffers]; + for (int i = 0; i < Constants.MaxVertexBuffers; i++) + { + _vertexBufferBindings[i] = i + 1; + } _newState.Initialize(gd.Capabilities); } @@ -1397,6 +1403,8 @@ namespace Ryujinx.Graphics.Vulkan if (!_bindingsSet) { + _newState.Internal.VertexBindingDescriptions[0] = new VertexInputBindingDescription(0, _supportExtDynamic && (!Gd.IsMoltenVk || Gd.SupportsMTL31) ? null : 0, VertexInputRate.Vertex); + for (int i = 1; i < count; i++) { _newState.Internal.VertexBindingDescriptions[i] = new VertexInputBindingDescription((uint)i); @@ -1431,17 +1439,22 @@ namespace Ryujinx.Graphics.Vulkan if (_supportExtDynamic && (!Gd.IsMoltenVk || Gd.SupportsMTL31)) { - if (_newState.Internal.VertexBindingDescriptions[descriptorIndex].InputRate != inputRate) + if (_newState.Internal.VertexBindingDescriptions[descriptorIndex].InputRate != inputRate || + _newState.Internal.VertexBindingDescriptions[descriptorIndex].Binding != _vertexBufferBindings[i]) { _newState.Internal.VertexBindingDescriptions[descriptorIndex].InputRate = inputRate; + _newState.Internal.VertexBindingDescriptions[descriptorIndex].Binding = (uint)_vertexBufferBindings[i]; vertexBindingDescriptionChanged = true; } } else { - if (_newState.Internal.VertexBindingDescriptions[descriptorIndex].InputRate != inputRate || _newState.Internal.VertexBindingDescriptions[descriptorIndex].Stride != vertexBuffer.Stride) + if (_newState.Internal.VertexBindingDescriptions[descriptorIndex].InputRate != inputRate || + _newState.Internal.VertexBindingDescriptions[descriptorIndex].Stride != vertexBuffer.Stride || + _newState.Internal.VertexBindingDescriptions[descriptorIndex].Binding != _vertexBufferBindings[i]) { + _newState.Internal.VertexBindingDescriptions[descriptorIndex].Binding = (uint)_vertexBufferBindings[i]; _newState.Internal.VertexBindingDescriptions[descriptorIndex].Stride = (uint)vertexBuffer.Stride; _newState.Internal.VertexBindingDescriptions[descriptorIndex].InputRate = inputRate; @@ -1463,7 +1476,7 @@ namespace Ryujinx.Graphics.Vulkan } } - ref var buffer = ref _vertexBuffers[descriptorIndex]; + ref var buffer = ref _vertexBuffers[_vertexBufferBindings[i]]; int oldScalarAlign = buffer.AttributeScalarAlignment; if (Gd.Capabilities.VertexBufferAlignment < 2 && @@ -1480,7 +1493,7 @@ namespace Ryujinx.Graphics.Vulkan vbSize, vertexBuffer.Stride); - buffer.BindVertexBuffer(Gd, Cbs, (uint)descriptorIndex, ref _newState, _vertexBufferUpdater); + buffer.BindVertexBuffer(Gd, Cbs, (uint)_vertexBufferBindings[i], ref _newState, _vertexBufferUpdater); } } else @@ -1496,7 +1509,7 @@ namespace Ryujinx.Graphics.Vulkan vbSize, vertexBuffer.Stride); - _vertexBuffersDirty |= 1UL << descriptorIndex; + _vertexBuffersDirty |= 1UL << _vertexBufferBindings[i]; } buffer.AttributeScalarAlignment = oldScalarAlign;