From de86f20b94b2038e9e8a7247b2a148024160f482 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 16 May 2024 21:06:04 -0400 Subject: [PATCH] Clamp ScissorRect --- src/Ryujinx.Graphics.Metal/Pipeline.cs | 6 +++--- src/Ryujinx.Graphics.Metal/RenderEncoderState.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Ryujinx.Graphics.Metal/Pipeline.cs b/src/Ryujinx.Graphics.Metal/Pipeline.cs index 3fbfc07bf..fbb3e31b6 100644 --- a/src/Ryujinx.Graphics.Metal/Pipeline.cs +++ b/src/Ryujinx.Graphics.Metal/Pipeline.cs @@ -539,7 +539,7 @@ namespace Ryujinx.Graphics.Metal public unsafe void SetScissors(ReadOnlySpan> regions) { - int maxScissors = Math.Min(regions.Length, _renderEncoderState.ViewportCount); + int maxScissors = Math.Min(regions.Length, _renderEncoderState.Viewports.Length); if (maxScissors == 0) { @@ -554,8 +554,8 @@ namespace Ryujinx.Graphics.Metal mtlScissorRects[i] = new MTLScissorRect { - height = (ulong)region.Height, - width = (ulong)region.Width, + height = Math.Clamp((ulong)region.Height, 0, (ulong)_renderEncoderState.Viewports[i].height), + width = Math.Clamp((ulong)region.Width, 0, (ulong)_renderEncoderState.Viewports[i].width), x = (ulong)region.X, y = (ulong)region.Y }; diff --git a/src/Ryujinx.Graphics.Metal/RenderEncoderState.cs b/src/Ryujinx.Graphics.Metal/RenderEncoderState.cs index 2ce5cbad1..c22f98522 100644 --- a/src/Ryujinx.Graphics.Metal/RenderEncoderState.cs +++ b/src/Ryujinx.Graphics.Metal/RenderEncoderState.cs @@ -27,7 +27,7 @@ namespace Ryujinx.Graphics.Metal private MTLViewport[] _viewports = []; private MTLScissorRect[] _scissors = []; - public readonly int ViewportCount => _viewports.Length; + public readonly MTLViewport[] Viewports => _viewports; public RenderEncoderState(MTLFunction vertexFunction, MTLFunction fragmentFunction, MTLDevice device) { @@ -36,7 +36,7 @@ namespace Ryujinx.Graphics.Metal _device = device; } - public unsafe readonly void SetEncoderState(MTLRenderCommandEncoder renderCommandEncoder, MTLRenderPassDescriptor descriptor, MTLVertexDescriptor vertexDescriptor) + public unsafe void SetEncoderState(MTLRenderCommandEncoder renderCommandEncoder, MTLRenderPassDescriptor descriptor, MTLVertexDescriptor vertexDescriptor) { var renderPipelineDescriptor = new MTLRenderPipelineDescriptor {