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 <laszlo.agocs@qt.io>
bb10
Andy Nichols 2022-08-03 20:33:09 +02:00
parent f49d35084c
commit 09a8283fb6
1 changed files with 7 additions and 1 deletions

View File

@ -241,6 +241,7 @@ struct QMetalCommandBufferData
int currentFirstVertexBinding;
QRhiBatchedBindings<id<MTLBuffer> > currentVertexInputsBuffers;
QRhiBatchedBindings<NSUInteger> currentVertexInputOffsets;
id<MTLDepthStencilState> 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();