Commit 8b8c7752 authored by Laszlo Agocs's avatar Laszlo Agocs
Browse files

mtl: Make sure depth is written out when using a depth texture

As we assume the texture will then be sampled afterwards so a store
action of DontCare is potentially wrong.
parent 5b7b391c
...@@ -247,6 +247,7 @@ struct QMetalRenderTargetData ...@@ -247,6 +247,7 @@ struct QMetalRenderTargetData
ColorAtt colorAtt[QMetalRenderPassDescriptor::MAX_COLOR_ATTACHMENTS]; ColorAtt colorAtt[QMetalRenderPassDescriptor::MAX_COLOR_ATTACHMENTS];
id<MTLTexture> dsTex = nil; id<MTLTexture> dsTex = nil;
bool hasStencil = false; bool hasStencil = false;
bool depthNeedsStore = false;
} fb; } fb;
}; };
...@@ -1011,6 +1012,7 @@ QRhi::FrameOpResult QRhiMetal::beginFrame(QRhiSwapChain *swapChain, QRhi::BeginF ...@@ -1011,6 +1012,7 @@ QRhi::FrameOpResult QRhiMetal::beginFrame(QRhiSwapChain *swapChain, QRhi::BeginF
swapChainD->rtWrapper.d->fb.colorAtt[0] = colorAtt; swapChainD->rtWrapper.d->fb.colorAtt[0] = colorAtt;
swapChainD->rtWrapper.d->fb.dsTex = swapChainD->ds ? swapChainD->ds->d->tex : nil; swapChainD->rtWrapper.d->fb.dsTex = swapChainD->ds ? swapChainD->ds->d->tex : nil;
swapChainD->rtWrapper.d->fb.hasStencil = swapChainD->ds ? true : false; swapChainD->rtWrapper.d->fb.hasStencil = swapChainD->ds ? true : false;
swapChainD->rtWrapper.d->fb.depthNeedsStore = false;
QRhiProfilerPrivate *rhiP = profilerPrivateOrNull(); QRhiProfilerPrivate *rhiP = profilerPrivateOrNull();
QRHI_PROF_F(beginSwapChainFrame(swapChain)); QRHI_PROF_F(beginSwapChainFrame(swapChain));
...@@ -1572,6 +1574,8 @@ void QRhiMetal::beginPass(QRhiCommandBuffer *cb, ...@@ -1572,6 +1574,8 @@ void QRhiMetal::beginPass(QRhiCommandBuffer *cb,
Q_ASSERT(rtD->fb.dsTex); Q_ASSERT(rtD->fb.dsTex);
cbD->d->currentPassRpDesc.depthAttachment.texture = rtD->fb.dsTex; cbD->d->currentPassRpDesc.depthAttachment.texture = rtD->fb.dsTex;
cbD->d->currentPassRpDesc.stencilAttachment.texture = rtD->fb.hasStencil ? rtD->fb.dsTex : nil; cbD->d->currentPassRpDesc.stencilAttachment.texture = rtD->fb.hasStencil ? rtD->fb.dsTex : nil;
if (rtD->fb.depthNeedsStore) // Depth/Stencil is set to DontCare by default, override if needed
cbD->d->currentPassRpDesc.depthAttachment.storeAction = MTLStoreActionStore;
} }
cbD->d->currentPassEncoder = [cbD->d->cb renderCommandEncoderWithDescriptor: cbD->d->currentPassRpDesc]; cbD->d->currentPassEncoder = [cbD->d->cb renderCommandEncoderWithDescriptor: cbD->d->currentPassRpDesc];
...@@ -2374,6 +2378,7 @@ bool QMetalTextureRenderTarget::build() ...@@ -2374,6 +2378,7 @@ bool QMetalTextureRenderTarget::build()
QMetalTexture *depthTexD = QRHI_RES(QMetalTexture, m_desc.depthTexture()); QMetalTexture *depthTexD = QRHI_RES(QMetalTexture, m_desc.depthTexture());
d->fb.dsTex = depthTexD->d->tex; d->fb.dsTex = depthTexD->d->tex;
d->fb.hasStencil = false; d->fb.hasStencil = false;
d->fb.depthNeedsStore = true;
if (d->colorAttCount == 0) { if (d->colorAttCount == 0) {
d->pixelSize = depthTexD->pixelSize(); d->pixelSize = depthTexD->pixelSize();
d->sampleCount = depthTexD->samples; d->sampleCount = depthTexD->samples;
...@@ -2382,6 +2387,7 @@ bool QMetalTextureRenderTarget::build() ...@@ -2382,6 +2387,7 @@ bool QMetalTextureRenderTarget::build()
QMetalRenderBuffer *depthRbD = QRHI_RES(QMetalRenderBuffer, m_desc.depthStencilBuffer()); QMetalRenderBuffer *depthRbD = QRHI_RES(QMetalRenderBuffer, m_desc.depthStencilBuffer());
d->fb.dsTex = depthRbD->d->tex; d->fb.dsTex = depthRbD->d->tex;
d->fb.hasStencil = true; d->fb.hasStencil = true;
d->fb.depthNeedsStore = false;
if (d->colorAttCount == 0) { if (d->colorAttCount == 0) {
d->pixelSize = depthRbD->pixelSize(); d->pixelSize = depthRbD->pixelSize();
d->sampleCount = depthRbD->samples; d->sampleCount = depthRbD->samples;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment