From 2890fc1069303b7d529d00f356c7b4f02b61d05b Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Tue, 10 Oct 2023 19:02:38 -0400 Subject: [PATCH] Vertex buffer data --- src/Ryujinx.Graphics.Metal/Handle.cs | 14 ++++++++++++++ src/Ryujinx.Graphics.Metal/Pipeline.cs | 15 +++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/Ryujinx.Graphics.Metal/Handle.cs diff --git a/src/Ryujinx.Graphics.Metal/Handle.cs b/src/Ryujinx.Graphics.Metal/Handle.cs new file mode 100644 index 000000000..82f8dbd5b --- /dev/null +++ b/src/Ryujinx.Graphics.Metal/Handle.cs @@ -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(ref handle); + } + } +} diff --git a/src/Ryujinx.Graphics.Metal/Pipeline.cs b/src/Ryujinx.Graphics.Metal/Pipeline.cs index b71266c04..3a92d3435 100644 --- a/src/Ryujinx.Graphics.Metal/Pipeline.cs +++ b/src/Ryujinx.Graphics.Metal/Pipeline.cs @@ -27,6 +27,7 @@ namespace Ryujinx.Graphics.Metal private RenderEncoderState _renderEncoderState; private MTLVertexDescriptor _vertexDescriptor = new(); + private MTLBuffer[] _vertexBuffers; private MTLBuffer _indexBuffer; private MTLIndexType _indexType; @@ -120,6 +121,14 @@ namespace Ryujinx.Graphics.Metal var renderCommandEncoder = _commandBuffer.RenderCommandEncoder(descriptor); _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; return renderCommandEncoder; } @@ -542,11 +551,17 @@ namespace Ryujinx.Graphics.Metal public void SetVertexBuffers(ReadOnlySpan vertexBuffers) { + _vertexBuffers = new MTLBuffer[vertexBuffers.Length]; + for (int i = 0; i < vertexBuffers.Length; i++) { if (vertexBuffers[i].Stride != 0) { _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); } } }