From 410287aba253a45e79ad805c89aa071c49ee0f7d Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 20 Jun 2024 14:14:05 +0100 Subject: [PATCH] Use buffer manager for color blit --- src/Ryujinx.Graphics.Metal/HelperShader.cs | 30 ++++++++++------------ 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/Ryujinx.Graphics.Metal/HelperShader.cs b/src/Ryujinx.Graphics.Metal/HelperShader.cs index 9b9d5d73e0..f836756986 100644 --- a/src/Ryujinx.Graphics.Metal/HelperShader.cs +++ b/src/Ryujinx.Graphics.Metal/HelperShader.cs @@ -79,10 +79,15 @@ namespace Ryujinx.Graphics.Metal Extents2D dstRegion, bool linearFilter) { + // Save current state + _pipeline.SaveAndResetState(); + const int RegionBufferSize = 16; var sampler = linearFilter ? _samplerLinear : _samplerNearest; + _pipeline.SetTextureAndSampler(ShaderStage.Fragment, 0, src, sampler); + Span region = stackalloc float[RegionBufferSize / sizeof(float)]; region[0] = srcRegion.X1 / (float)src.Width; @@ -100,9 +105,9 @@ namespace Ryujinx.Graphics.Metal (region[2], region[3]) = (region[3], region[2]); } - // using var buffer = _renderer.BufferManager.ReserveOrCreate(cbs, RegionBufferSize); - // buffer.Holder.SetDataUnchecked(buffer.Offset, region); - // _pipeline.SetUniformBuffers([new BufferAssignment(0, buffer.Range)]); + using var buffer = _renderer.BufferManager.ReserveOrCreate(cbs, RegionBufferSize); + buffer.Holder.SetDataUnchecked(buffer.Offset, region); + _pipeline.SetUniformBuffers([new BufferAssignment(0, buffer.Range)]); var rect = new Rectangle( MathF.Min(dstRegion.X1, dstRegion.X2), @@ -121,25 +126,18 @@ namespace Ryujinx.Graphics.Metal 0f, 1f); + _pipeline.SetProgram(_programColorBlit); + int dstWidth = dst.Width; int dstHeight = dst.Height; - // Save current state - _pipeline.SaveAndResetState(); - - _pipeline.SetProgram(_programColorBlit); - _pipeline.SetViewports(viewports); - _pipeline.SetScissors(stackalloc Rectangle[] { new Rectangle(0, 0, dstWidth, dstHeight) }); _pipeline.SetRenderTargets([dst], null); + _pipeline.SetScissors(stackalloc Rectangle[] { new Rectangle(0, 0, dstWidth, dstHeight) }); + _pipeline.SetClearLoadAction(true); - _pipeline.SetTextureAndSampler(ShaderStage.Fragment, 0, src, sampler); + + _pipeline.SetViewports(viewports); _pipeline.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip); - - fixed (float* ptr = region) - { - _pipeline.GetOrCreateRenderEncoder(true).SetVertexBytes((IntPtr)ptr, RegionBufferSize, 0); - } - _pipeline.Draw(4, 1, 0, 0); // Restore previous state