From 09a8283fb6b831ed05f580313dd6857ee3a94e8d Mon Sep 17 00:00:00 2001 From: Andy Nichols Date: Wed, 3 Aug 2022 20:33:09 +0200 Subject: RHI: Reduce redundant MTLDepthStencilState changes The metal profiler reports many redundant state changes of MTLDepthStencilState which can be reduced by checking if the current depthStencilState is the same as already set before setting it again. Pick-to: 6.4 Change-Id: Ie14f0491ad2cb1c3ce13c1cf3992d06561fbb826 Reviewed-by: Laszlo Agocs --- src/gui/rhi/qrhimetal.mm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/gui/rhi/qrhimetal.mm') diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index 186fca63d7..3aec160c74 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -241,6 +241,7 @@ struct QMetalCommandBufferData int currentFirstVertexBinding; QRhiBatchedBindings > currentVertexInputsBuffers; QRhiBatchedBindings currentVertexInputOffsets; + id currentDepthStencilState; }; struct QMetalRenderTargetData @@ -1051,7 +1052,11 @@ void QRhiMetal::setGraphicsPipeline(QRhiCommandBuffer *cb, QRhiGraphicsPipeline cbD->currentPipelineGeneration = psD->generation; [cbD->d->currentRenderPassEncoder setRenderPipelineState: psD->d->ps]; - [cbD->d->currentRenderPassEncoder setDepthStencilState: psD->d->ds]; + + if (cbD->d->currentDepthStencilState != psD->d->ds) { + [cbD->d->currentRenderPassEncoder setDepthStencilState: psD->d->ds]; + cbD->d->currentDepthStencilState = psD->d->ds; + } if (cbD->currentCullMode == -1 || psD->d->cullMode != uint(cbD->currentCullMode)) { [cbD->d->currentRenderPassEncoder setCullMode: psD->d->cullMode]; @@ -3952,6 +3957,7 @@ void QMetalCommandBuffer::resetPerPassCachedState() currentFrontFaceWinding = -1; currentDepthBiasValues = { 0.0f, 0.0f }; + d->currentDepthStencilState = nil; d->currentFirstVertexBinding = -1; d->currentVertexInputsBuffers.clear(); d->currentVertexInputOffsets.clear(); -- cgit v1.2.3