From cd01a2f74aea8729c22eeee7e6b431ec1cd72bdd Mon Sep 17 00:00:00 2001 From: gdk Date: Thu, 9 Dec 2021 20:04:31 -0300 Subject: [PATCH] Fix triangle overlay on SMO, Captain Toad, maybe others? --- .../Engine/Threed/StateUpdater.cs | 5 +++-- Ryujinx.Graphics.Vulkan/BufferState.cs | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs b/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs index dbb5327ed..2482d3e9f 100644 --- a/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs +++ b/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs @@ -953,6 +953,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed _drawState.IsAnyVbInstanced |= divisor != 0; + ulong vbSize = endAddress.Pack() - address + 1; ulong size; if (_drawState.IbStreamer.HasInlineIndexData || _drawState.DrawIndexed || stride == 0 || instanced) @@ -960,7 +961,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed // This size may be (much) larger than the real vertex buffer size. // Avoid calculating it this way, unless we don't have any other option. - size = endAddress.Pack() - address + 1; + size = vbSize; if (stride > 0 && indexTypeSmall && _drawState.DrawIndexed && !instanced) { @@ -984,7 +985,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed var drawState = _state.State.VertexBufferDrawState; - size = (ulong)((firstInstance + drawState.First + drawState.Count) * stride); + size = Math.Min(vbSize, (ulong)((firstInstance + drawState.First + drawState.Count) * stride)); } _channel.BufferManager.SetVertexBuffer(index, address, size, stride, divisor); diff --git a/Ryujinx.Graphics.Vulkan/BufferState.cs b/Ryujinx.Graphics.Vulkan/BufferState.cs index 80fc49036..ccf2aca0e 100644 --- a/Ryujinx.Graphics.Vulkan/BufferState.cs +++ b/Ryujinx.Graphics.Vulkan/BufferState.cs @@ -57,7 +57,21 @@ namespace Ryujinx.Graphics.Vulkan { var buffer = _buffer.Get(cbs, _offset, _size).Value; - gd.Api.CmdBindVertexBuffers(cbs.CommandBuffer, binding, 1, buffer, (ulong)_offset); + if (gd.Capabilities.SupportsExtendedDynamicState) + { + gd.ExtendedDynamicStateApi.CmdBindVertexBuffers2( + cbs.CommandBuffer, + binding, + 1, + buffer, + (ulong)_offset, + (ulong)_size, + _stride); + } + else + { + gd.Api.CmdBindVertexBuffers(cbs.CommandBuffer, binding, 1, buffer, (ulong)_offset); + } } }