From 810b5792a84e5fe627dc781b5c96bd0b9b4766d7 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Sun, 28 Jul 2024 18:45:43 +0100 Subject: [PATCH] Partial indirect draw support --- src/Ryujinx.Graphics.Metal/Pipeline.cs | 54 ++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/src/Ryujinx.Graphics.Metal/Pipeline.cs b/src/Ryujinx.Graphics.Metal/Pipeline.cs index 2d70903cf3..617034cf8b 100644 --- a/src/Ryujinx.Graphics.Metal/Pipeline.cs +++ b/src/Ryujinx.Graphics.Metal/Pipeline.cs @@ -402,30 +402,68 @@ namespace Ryujinx.Graphics.Metal public void DrawIndexedIndirect(BufferRange indirectBuffer) { - // var renderCommandEncoder = GetOrCreateRenderEncoder(true); + // TODO: Reindex unsupported topologies + if (TopologyUnsupported(_encoderStateManager.Topology)) + { + Logger.Warning?.Print(LogClass.Gpu, $"Drawing indexed with unsupported topology: {_encoderStateManager.Topology}"); + } - Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!"); + var buffer = _renderer.BufferManager + .GetBuffer(indirectBuffer.Handle, indirectBuffer.Offset, indirectBuffer.Size, false) + .Get(Cbs, indirectBuffer.Offset, indirectBuffer.Size).Value; + + var primitiveType = TopologyRemap(_encoderStateManager.Topology).Convert(); + + (MTLBuffer indexBuffer, int offset, MTLIndexType type) = _encoderStateManager.IndexBuffer.GetIndexBuffer(_renderer, Cbs); + + if (indexBuffer.NativePtr != IntPtr.Zero && buffer.NativePtr != IntPtr.Zero) + { + var renderCommandEncoder = GetOrCreateRenderEncoder(true); + + renderCommandEncoder.DrawIndexedPrimitives( + primitiveType, + type, + indexBuffer, + (ulong)offset, + buffer, + (ulong)indirectBuffer.Offset); + } } public void DrawIndexedIndirectCount(BufferRange indirectBuffer, BufferRange parameterBuffer, int maxDrawCount, int stride) { - // var renderCommandEncoder = GetOrCreateRenderEncoder(true); + // TODO: Properly support count - Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!"); + DrawIndexedIndirect(indirectBuffer); } public void DrawIndirect(BufferRange indirectBuffer) { - // var renderCommandEncoder = GetOrCreateRenderEncoder(true); + var renderCommandEncoder = GetOrCreateRenderEncoder(true); - Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!"); + if (TopologyUnsupported(_encoderStateManager.Topology)) + { + // TODO: Reindex unsupported topologies + Logger.Warning?.Print(LogClass.Gpu, $"Drawing indirect with unsupported topology: {_encoderStateManager.Topology}"); + } + + var buffer = _renderer.BufferManager + .GetBuffer(indirectBuffer.Handle, indirectBuffer.Offset, indirectBuffer.Size, false) + .Get(Cbs, indirectBuffer.Offset, indirectBuffer.Size).Value; + + var primitiveType = TopologyRemap(_encoderStateManager.Topology).Convert(); + + renderCommandEncoder.DrawPrimitives( + primitiveType, + buffer, + (ulong)indirectBuffer.Offset); } public void DrawIndirectCount(BufferRange indirectBuffer, BufferRange parameterBuffer, int maxDrawCount, int stride) { - // var renderCommandEncoder = GetOrCreateRenderEncoder(true); + // TODO: Properly support count - Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!"); + DrawIndirect(indirectBuffer); } public void DrawTexture(ITexture texture, ISampler sampler, Extents2DF srcRegion, Extents2DF dstRegion)