1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-12-21 09:32:01 +00:00

Vertex buffer data

This commit is contained in:
Isaac Marovitz 2023-10-10 19:02:38 -04:00 committed by Isaac Marovitz
parent 7f41e7dbd4
commit 2890fc1069
2 changed files with 29 additions and 0 deletions

View file

@ -0,0 +1,14 @@
using Ryujinx.Graphics.GAL;
using System;
using System.Runtime.CompilerServices;
namespace Ryujinx.Graphics.Metal
{
static class Handle
{
public static IntPtr ToIntPtr(this BufferHandle handle)
{
return Unsafe.As<BufferHandle, IntPtr>(ref handle);
}
}
}

View file

@ -27,6 +27,7 @@ namespace Ryujinx.Graphics.Metal
private RenderEncoderState _renderEncoderState; private RenderEncoderState _renderEncoderState;
private MTLVertexDescriptor _vertexDescriptor = new(); private MTLVertexDescriptor _vertexDescriptor = new();
private MTLBuffer[] _vertexBuffers;
private MTLBuffer _indexBuffer; private MTLBuffer _indexBuffer;
private MTLIndexType _indexType; private MTLIndexType _indexType;
@ -120,6 +121,14 @@ namespace Ryujinx.Graphics.Metal
var renderCommandEncoder = _commandBuffer.RenderCommandEncoder(descriptor); var renderCommandEncoder = _commandBuffer.RenderCommandEncoder(descriptor);
_renderEncoderState.SetEncoderState(renderCommandEncoder, _vertexDescriptor); _renderEncoderState.SetEncoderState(renderCommandEncoder, _vertexDescriptor);
for (int i = 0; i < _vertexBuffers.Length; i++)
{
if (_vertexBuffers[i] != null)
{
renderCommandEncoder.SetVertexBuffer(_vertexBuffers[i], 0, (ulong)i);
}
}
_currentEncoder = renderCommandEncoder; _currentEncoder = renderCommandEncoder;
return renderCommandEncoder; return renderCommandEncoder;
} }
@ -542,11 +551,17 @@ namespace Ryujinx.Graphics.Metal
public void SetVertexBuffers(ReadOnlySpan<VertexBufferDescriptor> vertexBuffers) public void SetVertexBuffers(ReadOnlySpan<VertexBufferDescriptor> vertexBuffers)
{ {
_vertexBuffers = new MTLBuffer[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)
{ {
_vertexDescriptor.Layouts.Object((ulong)i).Stride = (ulong)vertexBuffers[i].Stride; _vertexDescriptor.Layouts.Object((ulong)i).Stride = (ulong)vertexBuffers[i].Stride;
_vertexBuffers[i] = _device.NewBuffer(
vertexBuffers[i].Buffer.Handle.ToIntPtr(),
(ulong)vertexBuffers[i].Buffer.Size,
MTLResourceOptions.ResourceStorageModeManaged);
} }
} }
} }