mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2025-08-05 16:22:34 -07:00
Better vertex buffer management
This commit is contained in:
committed by
Isaac Marovitz
parent
a6f5f2f82b
commit
9f2c99fcfa
60
src/Ryujinx.Graphics.Metal/VertexBufferState.cs
Normal file
60
src/Ryujinx.Graphics.Metal/VertexBufferState.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user