Browse Source

metal: improve performance of auto depth/stencil in setCanvas.

Alex Szpakowski 3 years ago
parent
commit
c26f6ed94f
2 changed files with 11 additions and 4 deletions
  1. 5 0
      src/modules/graphics/Graphics.cpp
  2. 6 4
      src/modules/graphics/metal/Graphics.mm

+ 5 - 0
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()

+ 6 - 4
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);