From 9310861cc2b310d98c4c9a78dd96a12e1668f7f6 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Sun, 13 Aug 2023 02:22:15 -0500 Subject: [PATCH] GS:MTL: Properly set stencil reference on draw encoders --- pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm b/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm index b43160cec1..945c438a4a 100644 --- a/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm +++ b/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm @@ -2049,6 +2049,18 @@ static id getTexture(GSTexture* tex) return tex ? static_cast(tex)->GetTexture() : nil; } +static bool usesStencil(GSHWDrawConfig::DestinationAlphaMode dstalpha) +{ + switch (dstalpha) + { + case GSHWDrawConfig::DestinationAlphaMode::Stencil: + case GSHWDrawConfig::DestinationAlphaMode::StencilOne: + return true; + default: + return false; + } +} + void GSDeviceMTL::MREInitHWDraw(GSHWDrawConfig& config, const Map& verts) { MRESetScissor(config.scissor); @@ -2159,6 +2171,8 @@ void GSDeviceMTL::RenderHW(GSHWDrawConfig& config) BeginRenderPass(@"RenderHW", rt, MTLLoadActionLoad, config.ds, MTLLoadActionLoad, stencil, MTLLoadActionLoad); id mtlenc = m_current_render.encoder; FlushDebugEntries(mtlenc); + if (usesStencil(config.destination_alpha)) + [mtlenc setStencilReferenceValue:1]; MREInitHWDraw(config, allocation); if (config.require_one_barrier || config.require_full_barrier) MRESetTexture(config.rt, GSMTLTextureIndexRenderTarget);