Better vertex buffer management

This commit is contained in:
Isaac Marovitz
2024-07-08 13:55:46 +01:00
committed by Isaac Marovitz
parent a6f5f2f82b
commit 9f2c99fcfa
3 changed files with 85 additions and 18 deletions

View File

@@ -0,0 +1,60 @@
using Ryujinx.Graphics.GAL;
using SharpMetal.Metal;
using System;
using System.Runtime.Versioning;
namespace Ryujinx.Graphics.Metal
{
[SupportedOSPlatform("macos")]
internal struct VertexBufferState
{
public static VertexBufferState Null => new(BufferHandle.Null, 0, 0, 0);
private readonly BufferHandle _handle;
private readonly int _offset;
private readonly int _size;
public readonly int Stride;
public readonly int Divisor;
public VertexBufferState(BufferHandle handle, int offset, int size, int divisor, int stride = 0)
{
_handle = handle;
_offset = offset;
_size = size;
Stride = stride;
Divisor = divisor;
}
public (MTLBuffer, int) GetVertexBuffer(BufferManager bufferManager, CommandBufferScoped cbs)
{
Auto<DisposableBuffer> autoBuffer = null;
if (_handle != BufferHandle.Null)
{
// TODO: Handle restride if necessary
autoBuffer = bufferManager.GetBuffer(_handle, false, out int size);
// The original stride must be reapplied in case it was rewritten.
// TODO: Handle restride if necessary
if (_offset >= size)
{
autoBuffer = null;
}
}
if (autoBuffer != null)
{
int offset = _offset;
var buffer = autoBuffer.Get(cbs, offset, _size).Value;
return (buffer, offset);
}
return (new MTLBuffer(IntPtr.Zero), 0);
}
}
}