This is not a continuation of the Metal backend; this is simply bringing the branch up to date and merging it as-is behind an experiment. --------- Co-authored-by: Isaac Marovitz <isaacryu@icloud.com> Co-authored-by: Samuliak <samuliak77@gmail.com> Co-authored-by: SamoZ256 <96914946+SamoZ256@users.noreply.github.com> Co-authored-by: Isaac Marovitz <42140194+IsaacMarovitz@users.noreply.github.com> Co-authored-by: riperiperi <rhy3756547@hotmail.com> Co-authored-by: Gabriel A <gab.dark.100@gmail.com>
61 lines
1.7 KiB
C#
61 lines
1.7 KiB
C#
using Ryujinx.Graphics.GAL;
|
|
using SharpMetal.Metal;
|
|
using System;
|
|
using System.Runtime.Versioning;
|
|
|
|
namespace Ryujinx.Graphics.Metal
|
|
{
|
|
[SupportedOSPlatform("macos")]
|
|
readonly 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);
|
|
}
|
|
}
|
|
}
|