From 1a0b928c354fcdbaffade4b380e005637b3e3328 Mon Sep 17 00:00:00 2001 From: Samuliak Date: Fri, 24 May 2024 18:37:31 +0200 Subject: [PATCH] do memory barriers --- src/Ryujinx.Graphics.Metal/HelperShader.cs | 3 +++ src/Ryujinx.Graphics.Metal/Pipeline.cs | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Ryujinx.Graphics.Metal/HelperShader.cs b/src/Ryujinx.Graphics.Metal/HelperShader.cs index d26aa345e..7ff839418 100644 --- a/src/Ryujinx.Graphics.Metal/HelperShader.cs +++ b/src/Ryujinx.Graphics.Metal/HelperShader.cs @@ -73,6 +73,9 @@ namespace Ryujinx.Graphics.Metal _pipeline.SaveState(); _pipeline.SetProgram(_programColorBlit); + // Viewport and scissor needs to be set before render pass begin so as not to bind the old ones + //_pipeline.SetViewports([]); + //_pipeline.SetScissors([]); _pipeline.SetRenderTargets([destination], null); _pipeline.SetTextureAndSampler(ShaderStage.Fragment, 0, source, new Sampler(sampler)); _pipeline.SetPrimitiveTopology(PrimitiveTopology.Triangles); diff --git a/src/Ryujinx.Graphics.Metal/Pipeline.cs b/src/Ryujinx.Graphics.Metal/Pipeline.cs index a53d7cc1e..66984c2bb 100644 --- a/src/Ryujinx.Graphics.Metal/Pipeline.cs +++ b/src/Ryujinx.Graphics.Metal/Pipeline.cs @@ -191,7 +191,22 @@ namespace Ryujinx.Graphics.Metal public void Barrier() { - Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!"); + + if (_currentEncoderType == EncoderType.Render) + { + var renderCommandEncoder = GetOrCreateRenderEncoder(); + + var scope = MTLBarrierScope.Buffers | MTLBarrierScope.Textures | MTLBarrierScope.RenderTargets; + MTLRenderStages stages = MTLRenderStages.RenderStageVertex | MTLRenderStages.RenderStageFragment; + renderCommandEncoder.MemoryBarrier(scope, stages, stages); + } else if (_currentEncoderType == EncoderType.Compute) + { + var computeCommandEncoder = GetOrCreateComputeEncoder(); + + // TODO: Should there be a barrier on render targets? + var scope = MTLBarrierScope.Buffers | MTLBarrierScope.Textures; + computeCommandEncoder.MemoryBarrier(scope); + } } public void ClearBuffer(BufferHandle destination, int offset, int size, uint value)