1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-12-24 15:36:01 +00:00

Fix VertexBuffers

Naive non-managed approach
This commit is contained in:
Isaac Marovitz 2024-03-19 19:02:05 -04:00 committed by Isaac Marovitz
parent e517cfeb8f
commit 8dca53685a
2 changed files with 25 additions and 18 deletions

View file

@ -0,0 +1,10 @@
using System;
namespace Ryujinx.Graphics.Metal
{
public struct BufferInfo
{
public IntPtr Handle;
public int Offset;
}
}

View file

@ -31,7 +31,7 @@ namespace Ryujinx.Graphics.Metal
private RenderEncoderState _renderEncoderState; private RenderEncoderState _renderEncoderState;
private readonly MTLVertexDescriptor _vertexDescriptor = new(); private readonly MTLVertexDescriptor _vertexDescriptor = new();
private MTLBuffer[] _vertexBuffers = []; private BufferInfo[] _vertexBuffers = [];
private MTLBuffer _indexBuffer; private MTLBuffer _indexBuffer;
private MTLIndexType _indexType; private MTLIndexType _indexType;
@ -134,10 +134,7 @@ namespace Ryujinx.Graphics.Metal
for (int i = 0; i < _vertexBuffers.Length; i++) for (int i = 0; i < _vertexBuffers.Length; i++)
{ {
if (_vertexBuffers[i] != null) renderCommandEncoder.SetVertexBuffer(new MTLBuffer(_vertexBuffers[i].Handle), (ulong)_vertexBuffers[i].Offset, (ulong)i);
{
renderCommandEncoder.SetVertexBuffer(_vertexBuffers[i], 0, (ulong)i);
}
} }
_currentEncoder = renderCommandEncoder; _currentEncoder = renderCommandEncoder;
@ -613,32 +610,32 @@ namespace Ryujinx.Graphics.Metal
if (!vertexAttribs[i].IsZero) if (!vertexAttribs[i].IsZero)
{ {
// TODO: Format should not be hardcoded // TODO: Format should not be hardcoded
// var attrib = _vertexDescriptor.Attributes.Object((ulong)i); var attrib = _vertexDescriptor.Attributes.Object((ulong)i);
// attrib.Format = MTLVertexFormat.Float4; attrib.Format = MTLVertexFormat.Float4;
// attrib.BufferIndex = (ulong)vertexAttribs[i].BufferIndex; attrib.BufferIndex = (ulong)vertexAttribs[i].BufferIndex;
// attrib.Offset = (ulong)vertexAttribs[i].Offset; attrib.Offset = (ulong)vertexAttribs[i].Offset;
// _vertexDescriptor.Attributes.SetObject(attrib, (ulong)i);
var layout = _vertexDescriptor.Layouts.Object((ulong)vertexAttribs[i].BufferIndex);
layout.Stride = 1;
} }
} }
} }
public void SetVertexBuffers(ReadOnlySpan<VertexBufferDescriptor> vertexBuffers) public void SetVertexBuffers(ReadOnlySpan<VertexBufferDescriptor> vertexBuffers)
{ {
_vertexBuffers = new MTLBuffer[vertexBuffers.Length]; _vertexBuffers = new BufferInfo[vertexBuffers.Length];
for (int i = 0; i < vertexBuffers.Length; i++) for (int i = 0; i < vertexBuffers.Length; i++)
{ {
if (vertexBuffers[i].Stride != 0) if (vertexBuffers[i].Stride != 0)
{ {
var layout = _vertexDescriptor.Layouts.Object(0); var layout = _vertexDescriptor.Layouts.Object((ulong)i);
layout.Stride = (ulong)vertexBuffers[i].Stride; layout.Stride = (ulong)vertexBuffers[i].Stride;
_vertexDescriptor.Layouts.SetObject(layout, (ulong)i); _vertexBuffers[i] = new BufferInfo {
_vertexBuffers[i] = _device.NewBuffer( Handle = vertexBuffers[i].Buffer.Handle.ToIntPtr(),
vertexBuffers[i].Buffer.Handle.ToIntPtr(), Offset = vertexBuffers[i].Buffer.Offset
(ulong)vertexBuffers[i].Buffer.Size, };
MTLResourceOptions.ResourceStorageModeManaged);
} }
} }
} }