From cb70e7bb30e8ecf5bcdd58b976f2ed5ea8cff947 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Wed, 21 Dec 2022 15:08:12 -0300 Subject: [PATCH] Fix DrawArrays vertex buffer size (#4141) --- Ryujinx.Graphics.Gpu/Engine/Threed/DrawManager.cs | 13 +++++++------ Ryujinx.Graphics.Gpu/Engine/Threed/DrawState.cs | 10 ++++++++++ Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs | 6 +++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Ryujinx.Graphics.Gpu/Engine/Threed/DrawManager.cs b/Ryujinx.Graphics.Gpu/Engine/Threed/DrawManager.cs index cd14259a..0f249512 100644 --- a/Ryujinx.Graphics.Gpu/Engine/Threed/DrawManager.cs +++ b/Ryujinx.Graphics.Gpu/Engine/Threed/DrawManager.cs @@ -142,6 +142,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed _drawState.FirstIndex = firstIndex; _drawState.IndexCount = indexCount; + _drawState.DrawFirstVertex = drawFirstVertex; + _drawState.DrawVertexCount = drawVertexCount; _currentSpecState.SetHasConstantBufferDrawParameters(false); engine.UpdateState(); @@ -163,10 +165,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed _instancedIndexCount = ibCount != 0 ? ibCount : indexCount; - var drawState = _state.State.VertexBufferDrawState; - - _instancedDrawStateFirst = drawState.First; - _instancedDrawStateCount = drawState.Count; + _instancedDrawStateFirst = drawFirstVertex; + _instancedDrawStateCount = drawVertexCount; _drawState.DrawIndexed = false; @@ -415,6 +415,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed bool oldDrawIndexed = _drawState.DrawIndexed; _drawState.DrawIndexed = false; + engine.ForceStateDirty(VertexBufferFirstMethodOffset * 4); DrawEnd(engine, 0, 0, firstVertex, vertexCount); @@ -526,8 +527,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed } else { - _state.State.VertexBufferDrawState.First = firstVertex; - _state.State.VertexBufferDrawState.Count = count; + _drawState.DrawFirstVertex = firstVertex; + _drawState.DrawVertexCount = count; engine.ForceStateDirty(VertexBufferFirstMethodOffset * 4); } diff --git a/Ryujinx.Graphics.Gpu/Engine/Threed/DrawState.cs b/Ryujinx.Graphics.Gpu/Engine/Threed/DrawState.cs index fd1cb0ea..42ec2442 100644 --- a/Ryujinx.Graphics.Gpu/Engine/Threed/DrawState.cs +++ b/Ryujinx.Graphics.Gpu/Engine/Threed/DrawState.cs @@ -17,6 +17,16 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed /// public int IndexCount; + /// + /// First vertex used on non-indexed draws. This value is stored somewhere else on indexed draws. + /// + public int DrawFirstVertex; + + /// + /// Vertex count used on non-indexed draws. Indexed draws have a index count instead. + /// + public int DrawVertexCount; + /// /// Indicates if the next draw will be a indexed draw. /// diff --git a/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs b/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs index 014a1739..64fa1735 100644 --- a/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs +++ b/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs @@ -989,6 +989,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed bool drawIndexed = _drawState.DrawIndexed; bool drawIndirect = _drawState.DrawIndirect; + int drawFirstVertex = _drawState.DrawFirstVertex; + int drawVertexCount = _drawState.DrawVertexCount; uint vbEnableMask = 0; for (int index = 0; index < Constants.TotalVertexBuffers; index++) @@ -1050,9 +1052,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed int firstInstance = (int)_state.State.FirstInstance; - var drawState = _state.State.VertexBufferDrawState; - - size = Math.Min(vbSize, (ulong)((firstInstance + drawState.First + drawState.Count) * stride)); + size = Math.Min(vbSize, (ulong)((firstInstance + drawFirstVertex + drawVertexCount) * stride)); } _pipeline.VertexBuffers[index] = new BufferPipelineDescriptor(_channel.MemoryManager.IsMapped(address), stride, divisor);