diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2024-04-18 12:44:58 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-04-26 17:58:29 +0000 |
commit | f268b9828935ff9834e2ea5b12b194db59396800 (patch) | |
tree | 3cf45e347f42de2af2de117b4d10245cbdec8064 | |
parent | a4c271007743719dc74aa333b37bd1ec78831c94 (diff) |
metal: Tie drawable's MTLTexture lifetime to MTLCommandBuffer
By default we define QRHI_METAL_COMMAND_BUFFERS_WITH_UNRETAINED_REFERENCES,
which means we create MTLCommandBuffer via commandBufferWithUnretainedReferences.
In this case, if Metal API validation diagnostics is enabled in Xcode,
the texture is released before the command buffer is done with it, so
we manually ensure the lifetime of the texture extends until the command
buffer is complete.
Change-Id: I9b9efa96b4a004f43e0b72144aafc4b440c7fbb4
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
(cherry picked from commit 94e83aa7d7d05cf0b6636bdfac5cdcb38706aa73)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/gui/rhi/qrhimetal.mm | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index b90c8aecb7..06ae86605e 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -2394,6 +2394,16 @@ QRhi::FrameOpResult QRhiMetal::endFrame(QRhiSwapChain *swapChain, QRhi::EndFrame dispatch_semaphore_signal(swapChainD->d->sem[thisFrameSlot]); }]; +#ifdef QRHI_METAL_COMMAND_BUFFERS_WITH_UNRETAINED_REFERENCES + // When Metal API validation diagnostics is enabled in Xcode the texture is + // released before the command buffer is done with it. Manually keep it alive + // to work around this. + id<MTLTexture> drawableTexture = [swapChainD->d->curDrawable.texture retain]; + [swapChainD->cbWrapper.d->cb addCompletedHandler:^(id<MTLCommandBuffer>) { + [drawableTexture release]; + }]; +#endif + const bool needsPresent = !flags.testFlag(QRhi::SkipPresent); const bool presentsWithTransaction = swapChainD->d->layer.presentsWithTransaction; if (!presentsWithTransaction && needsPresent) { |