From d076a708163e126108e32e17504b1f3878ebff95 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Fri, 28 Jul 2023 16:51:07 -0400 Subject: [PATCH] Clear Buffer --- src/Ryujinx.Graphics.Metal/Pipeline.cs | 22 +++++++++++++++++++++- src/Ryujinx.Graphics.Metal/Texture.cs | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Ryujinx.Graphics.Metal/Pipeline.cs b/src/Ryujinx.Graphics.Metal/Pipeline.cs index f45eba34c0..a0af3c33f3 100644 --- a/src/Ryujinx.Graphics.Metal/Pipeline.cs +++ b/src/Ryujinx.Graphics.Metal/Pipeline.cs @@ -92,7 +92,27 @@ namespace Ryujinx.Graphics.Metal public void ClearBuffer(BufferHandle destination, int offset, int size, uint value) { - throw new NotImplementedException(); + MTLBlitCommandEncoder blitCommandEncoder; + + if (_currentEncoder is MTLBlitCommandEncoder encoder) + { + blitCommandEncoder = encoder; + } + else + { + blitCommandEncoder = BeginBlitPass(); + } + + // Might need a closer look, range's count, lower, and upper bound + // must be a multiple of 4 + MTLBuffer mtlBuffer = new(Unsafe.As(ref destination)); + blitCommandEncoder.FillBuffer(mtlBuffer, + new NSRange + { + location = (ulong)offset, + length = (ulong)size + }, + (byte)value); } public void ClearRenderTargetColor(int index, int layer, int layerCount, uint componentMask, ColorF color) diff --git a/src/Ryujinx.Graphics.Metal/Texture.cs b/src/Ryujinx.Graphics.Metal/Texture.cs index 177582a2b2..1372ba5510 100644 --- a/src/Ryujinx.Graphics.Metal/Texture.cs +++ b/src/Ryujinx.Graphics.Metal/Texture.cs @@ -136,6 +136,7 @@ namespace Ryujinx.Graphics.Metal throw new NotImplementedException(); } + // TODO: Rewrite using MTLBlitCommandEncoder public void SetData(SpanOrArray data, int layer, int level, Rectangle region) { ulong bytesPerRow = (ulong)Info.GetMipStride(level);