diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2023-04-17 15:44:42 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2023-04-18 14:42:45 +0200 |
commit | 62a4ca773a9e8a2f0c993c159c045f2794078aad (patch) | |
tree | f8b0c594cd526ab40280a1d8268aa123e439c043 /src/gui/rhi/qrhimetal.mm | |
parent | e3c9dce0b6e5aa1844f51cf2f3bdc550a5b884ce (diff) |
rhi: Make it safe to always call deleteLater on a resource
...even when the QRhi is already gone. This should not happen in
well-written applications and libraries, but we handle this
gracefully in the regular dtor and destroy() for resources that
register themselves to their creator QRhi, so by registering
everything we can offer this to all QRhiResource subclasses.
We still want to differentiate between native resource owning
QRhiResources and others (that do not create native graphics
objects), so do this via a flag passed to registerResource().
This way the behavior with QT_RHI_LEAK_CHECK=1 does not change.
Pick-to: 6.5
Fixes: QTBUG-112914
Change-Id: I9bafc81ef7a4ae76f356fc5f6248628d1f8791e0
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
Diffstat (limited to 'src/gui/rhi/qrhimetal.mm')
-rw-r--r-- | src/gui/rhi/qrhimetal.mm | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index 8666c4b032..b05b35f81c 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -3930,7 +3930,9 @@ QMetalRenderPassDescriptor::~QMetalRenderPassDescriptor() void QMetalRenderPassDescriptor::destroy() { - // nothing to do here + QRHI_RES_RHI(QRhiMetal); + if (rhiD) + rhiD->unregisterResource(this); } bool QMetalRenderPassDescriptor::isCompatible(const QRhiRenderPassDescriptor *other) const @@ -3973,13 +3975,17 @@ void QMetalRenderPassDescriptor::updateSerializedFormat() QRhiRenderPassDescriptor *QMetalRenderPassDescriptor::newCompatibleRenderPassDescriptor() const { - QMetalRenderPassDescriptor *rp = new QMetalRenderPassDescriptor(m_rhi); - rp->colorAttachmentCount = colorAttachmentCount; - rp->hasDepthStencil = hasDepthStencil; - memcpy(rp->colorFormat, colorFormat, sizeof(colorFormat)); - rp->dsFormat = dsFormat; - rp->updateSerializedFormat(); - return rp; + QMetalRenderPassDescriptor *rpD = new QMetalRenderPassDescriptor(m_rhi); + rpD->colorAttachmentCount = colorAttachmentCount; + rpD->hasDepthStencil = hasDepthStencil; + memcpy(rpD->colorFormat, colorFormat, sizeof(colorFormat)); + rpD->dsFormat = dsFormat; + + rpD->updateSerializedFormat(); + + QRHI_RES_RHI(QRhiMetal); + rhiD->registerResource(rpD, false); + return rpD; } QVector<quint32> QMetalRenderPassDescriptor::serializedFormat() const @@ -4035,7 +4041,9 @@ QMetalTextureRenderTarget::~QMetalTextureRenderTarget() void QMetalTextureRenderTarget::destroy() { - // nothing to do here + QRHI_RES_RHI(QRhiMetal); + if (rhiD) + rhiD->unregisterResource(this); } QRhiRenderPassDescriptor *QMetalTextureRenderTarget::newCompatibleRenderPassDescriptor() @@ -4058,6 +4066,9 @@ QRhiRenderPassDescriptor *QMetalTextureRenderTarget::newCompatibleRenderPassDesc rpD->dsFormat = int(QRHI_RES(QMetalRenderBuffer, m_desc.depthStencilBuffer())->d->format); rpD->updateSerializedFormat(); + + QRHI_RES_RHI(QRhiMetal); + rhiD->registerResource(rpD, false); return rpD; } @@ -4131,6 +4142,7 @@ bool QMetalTextureRenderTarget::create() QRhiRenderTargetAttachmentTracker::updateResIdList<QMetalTexture, QMetalRenderBuffer>(m_desc, &d->currentResIdList); + rhiD->registerResource(this, false); return true; } @@ -4166,6 +4178,10 @@ void QMetalShaderResourceBindings::destroy() { sortedBindings.clear(); maxBinding = -1; + + QRHI_RES_RHI(QRhiMetal); + if (rhiD) + rhiD->unregisterResource(this); } bool QMetalShaderResourceBindings::create() @@ -4192,6 +4208,7 @@ bool QMetalShaderResourceBindings::create() memset(&bd, 0, sizeof(BoundResourceData)); generation += 1; + rhiD->registerResource(this, false); return true; } @@ -6053,6 +6070,8 @@ bool QMetalSwapChain::isFormatSupported(Format f) QRhiRenderPassDescriptor *QMetalSwapChain::newCompatibleRenderPassDescriptor() { + QRHI_RES_RHI(QRhiMetal); + chooseFormats(); // ensure colorFormat and similar are filled out QMetalRenderPassDescriptor *rpD = new QMetalRenderPassDescriptor(m_rhi); @@ -6063,7 +6082,6 @@ QRhiRenderPassDescriptor *QMetalSwapChain::newCompatibleRenderPassDescriptor() #ifdef Q_OS_MACOS // m_depthStencil may not be built yet so cannot rely on computed fields in it - QRHI_RES_RHI(QRhiMetal); rpD->dsFormat = rhiD->d->dev.depth24Stencil8PixelFormatSupported ? MTLPixelFormatDepth24Unorm_Stencil8 : MTLPixelFormatDepth32Float_Stencil8; #else @@ -6071,6 +6089,8 @@ QRhiRenderPassDescriptor *QMetalSwapChain::newCompatibleRenderPassDescriptor() #endif rpD->updateSerializedFormat(); + + rhiD->registerResource(rpD, false); return rpD; } |