From c26f6ed94f2e6dcbb9c849cc95ed56ba155aa43d Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 22 Jan 2022 23:12:42 -0400 Subject: [PATCH] metal: improve performance of auto depth/stencil in setCanvas. --- src/modules/graphics/Graphics.cpp | 5 +++++ src/modules/graphics/metal/Graphics.mm | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index ee43b8275..dbfda2983 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -907,6 +907,11 @@ void Graphics::setRenderTargets(const RenderTargets &rts) renderTargetSwitchCount++; resetProjection(); + + // Invalidate temporary depth/stencil. This could be a clear, but if the + // user also clears a double-clear may be slow... + if (rts.depthStencil.texture == nullptr && rts.temporaryRTFlags != 0) + discard({}, true); } void Graphics::setRenderTarget() diff --git a/src/modules/graphics/metal/Graphics.mm b/src/modules/graphics/metal/Graphics.mm index 232ef1ebd..12e65b80c 100644 --- a/src/modules/graphics/metal/Graphics.mm +++ b/src/modules/graphics/metal/Graphics.mm @@ -1370,10 +1370,12 @@ void Graphics::endPass() // Discard the depth/stencil buffer if we're using an internal cached one, // or if this is the backbuffer. - if (depthstencil == nullptr && (rts.temporaryRTFlags & (TEMPORARY_RT_DEPTH | TEMPORARY_RT_STENCIL)) != 0) - discard({}, true); - else if (!rts.getFirstTarget().texture.get()) - discard({}, true); // Backbuffer + if ((depthstencil == nullptr && (rts.temporaryRTFlags & (TEMPORARY_RT_DEPTH | TEMPORARY_RT_STENCIL)) != 0) + || !rts.getFirstTarget().texture.get()) + { + attachmentStoreActions.depth = MTLStoreActionDontCare; + attachmentStoreActions.stencil = MTLStoreActionDontCare; + } submitRenderEncoder(SUBMIT_DONE);