diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2021-08-11 17:06:09 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-11 22:06:09 +0200 |
| commit | 10d649e6d3ad3e4af32d2b41e718bb0a2924da67 (patch) | |
| tree | 874be1577eaa76e58f4084cbeefd97069184bd0e /Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs | |
| parent | bb8a920b63d6d287dba8ec42e298329b933f9654 (diff) | |
Calculate vertex buffer sizes from index buffer (#1663)
* Calculate vertex buffer size from maximum index buffer index
* Increase maximum index buffer count for it to be considered profitable for counting
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs')
| -rw-r--r-- | Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs b/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs index d9484cf6..fb4ab007 100644 --- a/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs +++ b/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs @@ -34,6 +34,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed private byte _vsClipDistancesWritten; private bool _prevDrawIndexed; + private int _prevFirstIndex; + private int _prevIndexCount; private bool _prevTfEnable; /// <summary> @@ -182,10 +184,25 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed // method when doing indexed draws, so we need to make sure // to update the vertex buffers if we are doing a regular // draw after a indexed one and vice-versa. - if (_drawState.DrawIndexed != _prevDrawIndexed) + if (GraphicsConfig.EnableIndexedVbSizeDetection) { - _updateTracker.ForceDirty(VertexBufferStateIndex); - _prevDrawIndexed = _drawState.DrawIndexed; + if (_drawState.DrawIndexed != _prevDrawIndexed || + _drawState.FirstIndex != _prevFirstIndex || + _drawState.IndexCount != _prevIndexCount) + { + _updateTracker.ForceDirty(VertexBufferStateIndex); + _prevDrawIndexed = _drawState.DrawIndexed; + _prevFirstIndex = _drawState.FirstIndex; + _prevIndexCount = _drawState.IndexCount; + } + } + else + { + if (_drawState.DrawIndexed != _prevDrawIndexed) + { + _updateTracker.ForceDirty(VertexBufferStateIndex); + _prevDrawIndexed = _drawState.DrawIndexed; + } } bool tfEnable = _state.State.TfEnable; @@ -782,7 +799,25 @@ 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; + ulong vbSizeMax = endAddress.Pack() - address + 1; + + int firstIndex = _drawState.FirstIndex; + int indexCount = _drawState.IndexCount; + + bool ibCountingProfitable = GraphicsConfig.EnableIndexedVbSizeDetection && IbUtils.IsIbCountingProfitable(vbSizeMax, indexCount); + + if (ibCountingProfitable && !_drawState.IbStreamer.HasInlineIndexData && _drawState.DrawIndexed && stride != 0) + { + IndexType ibType = _state.State.IndexBufferState.Type; + ulong ibGpuVa = _state.State.IndexBufferState.Address.Pack(); + ulong vertexCount = IbUtils.GetVertexCount(_channel.MemoryManager, ibType, ibGpuVa, firstIndex, indexCount); + + size = Math.Min(vertexCount * (ulong)stride, vbSizeMax); + } + else + { + size = vbSizeMax; + } } else { |
