From a5db072dc2e85be1c8c6411b67844a53fafcb522 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 1 Apr 2022 15:01:45 +0200 Subject: [PATCH] rhi: Add explicit subclass for RTs from swapchains We want to enable gaining access to the underlying resource(s) by inspecting a QRhiRenderTarget. This is not currently possible for swapchains since there is nothing that references the actual QRhiSwapChain. To clean this up, make an explicit, new QRhiSwapChainRenderTarget subclass. Thus the logic already used in a couple of places to examine the resources attached to a QRhiTextureRenderTarget can now work with swapchain render targets too, by branching based on the resourceType(). This eliminates the somewhat odd setup where a "RenderTarget" resource is QRhiRenderTarget corresponding (but not exposing!) a swapchain, whereas a "TextureRenderTarget" is a QRhiTextureRenderTarget which is a subclass of QRhiRenderTarget. Now we correctly have an (abstract) base and two subclasses, one for each type of render targets. Besides, it allows us to clean up the oddly named Q...ReferenceRenderTarget classes in the backends, which initially tried to indicate that this "render target" merely references (or, in practice, is) a swapchain. We can now have a nice and symmetrical Q...SwapChainRenderTarget and Q...TextureRenderTarget naming scheme. Change-Id: Ib07e9be99a316eec67b94de0860e08f5f4638959 Reviewed-by: Andy Nichols --- src/gui/rhi/qrhi.cpp | 54 ++++++++++++++++++++++------ src/gui/rhi/qrhi_p.h | 16 +++++++-- src/gui/rhi/qrhid3d11.cpp | 22 ++++++------ src/gui/rhi/qrhid3d11_p_p.h | 8 ++--- src/gui/rhi/qrhigles2.cpp | 20 +++++------ src/gui/rhi/qrhigles2_p_p.h | 8 ++--- src/gui/rhi/qrhimetal.mm | 20 +++++------ src/gui/rhi/qrhimetal_p_p.h | 8 ++--- src/gui/rhi/qrhinull.cpp | 16 ++++----- src/gui/rhi/qrhinull_p_p.h | 8 ++--- src/gui/rhi/qrhivulkan.cpp | 24 ++++++------- src/gui/rhi/qrhivulkan_p_p.h | 8 ++--- tests/auto/gui/rhi/qrhi/tst_qrhi.cpp | 2 ++ 13 files changed, 130 insertions(+), 84 deletions(-) diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index adf7b781ff7..4ed9370fa2a 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -2943,6 +2943,8 @@ const QRhiNativeHandles *QRhiRenderPassDescriptor::nativeHandles() \internal \inmodule QtGui \brief Represents an onscreen (swapchain) or offscreen (texture) render target. + + \sa QRhiSwapChainRenderTarget, QRhiTextureRenderTarget */ /*! @@ -2953,14 +2955,6 @@ QRhiRenderTarget::QRhiRenderTarget(QRhiImplementation *rhi) { } -/*! - \return the resource type. - */ -QRhiResource::Type QRhiRenderTarget::resourceType() const -{ - return RenderTarget; -} - /*! \fn QSize QRhiRenderTarget::pixelSize() const @@ -2988,6 +2982,42 @@ QRhiResource::Type QRhiRenderTarget::resourceType() const QWindow. */ +/*! + \internal + */ +QRhiSwapChainRenderTarget::QRhiSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain_) + : QRhiRenderTarget(rhi), + m_swapchain(swapchain_) +{ +} + +/*! + \class QRhiSwapChainRenderTarget + \internal + \inmodule QtGui + \brief Swapchain render target resource. + + When targeting the color buffers of a swapchain, active render target is a + QRhiSwapChainRenderTarget. This is what + QRhiSwapChain::currentFrameRenderTarget() returns. + + \sa QRhiSwapChain + */ + +/*! + \return the resource type. + */ +QRhiResource::Type QRhiSwapChainRenderTarget::resourceType() const +{ + return SwapChainRenderTarget; +} + +/*! + \fn QRhiSwapChain *QRhiSwapChainRenderTarget::swapChain() const + + \return the swapchain object. + */ + /*! \class QRhiTextureRenderTarget \internal @@ -2997,6 +3027,10 @@ QRhiResource::Type QRhiRenderTarget::resourceType() const A texture render target allows rendering into one or more textures, optionally with a depth texture or depth/stencil renderbuffer. + For multisample rendering the common approach is to use a renderbuffer as + the color attachment and set the non-multisample destination texture as the + \c{resolve texture}. + \note Textures used in combination with QRhiTextureRenderTarget must be created with the QRhiTexture::RenderTarget flag. @@ -4911,8 +4945,8 @@ static const char *resourceTypeStr(QRhiResource *res) return "RenderBuffer"; case QRhiResource::RenderPassDescriptor: return "RenderPassDescriptor"; - case QRhiResource::RenderTarget: - return "RenderTarget"; + case QRhiResource::SwapChainRenderTarget: + return "SwapChainRenderTarget"; case QRhiResource::TextureRenderTarget: return "TextureRenderTarget"; case QRhiResource::ShaderResourceBindings: diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h index 07f3ad69be3..bbc404f09b4 100644 --- a/src/gui/rhi/qrhi_p.h +++ b/src/gui/rhi/qrhi_p.h @@ -74,6 +74,7 @@ class QRhiSampler; class QRhiCommandBuffer; class QRhiResourceUpdateBatch; class QRhiResourceUpdateBatchPrivate; +class QRhiSwapChain; class Q_GUI_EXPORT QRhiDepthStencilClearValue { @@ -697,7 +698,7 @@ public: Sampler, RenderBuffer, RenderPassDescriptor, - RenderTarget, + SwapChainRenderTarget, TextureRenderTarget, ShaderResourceBindings, GraphicsPipeline, @@ -1031,8 +1032,6 @@ protected: class Q_GUI_EXPORT QRhiRenderTarget : public QRhiResource { public: - QRhiResource::Type resourceType() const override; - virtual QSize pixelSize() const = 0; virtual float devicePixelRatio() const = 0; virtual int sampleCount() const = 0; @@ -1045,6 +1044,17 @@ protected: QRhiRenderPassDescriptor *m_renderPassDesc = nullptr; }; +class Q_GUI_EXPORT QRhiSwapChainRenderTarget : public QRhiRenderTarget +{ +public: + QRhiResource::Type resourceType() const override; + QRhiSwapChain *swapChain() const { return m_swapchain; } + +protected: + QRhiSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain_); + QRhiSwapChain *m_swapchain; +}; + class Q_GUI_EXPORT QRhiTextureRenderTarget : public QRhiRenderTarget { public: diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index 3fde58af8e0..f6e07f347e5 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -1759,8 +1759,8 @@ void QRhiD3D11::finishActiveReadbacks() static inline QD3D11RenderTargetData *rtData(QRhiRenderTarget *rt) { switch (rt->resourceType()) { - case QRhiResource::RenderTarget: - return &QRHI_RES(QD3D11ReferenceRenderTarget, rt)->d; + case QRhiResource::SwapChainRenderTarget: + return &QRHI_RES(QD3D11SwapChainRenderTarget, rt)->d; case QRhiResource::TextureRenderTarget: return &QRHI_RES(QD3D11TextureRenderTarget, rt)->d; default: @@ -3453,33 +3453,33 @@ QVector QD3D11RenderPassDescriptor::serializedFormat() const return {}; } -QD3D11ReferenceRenderTarget::QD3D11ReferenceRenderTarget(QRhiImplementation *rhi) - : QRhiRenderTarget(rhi), +QD3D11SwapChainRenderTarget::QD3D11SwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain) + : QRhiSwapChainRenderTarget(rhi, swapchain), d(rhi) { } -QD3D11ReferenceRenderTarget::~QD3D11ReferenceRenderTarget() +QD3D11SwapChainRenderTarget::~QD3D11SwapChainRenderTarget() { destroy(); } -void QD3D11ReferenceRenderTarget::destroy() +void QD3D11SwapChainRenderTarget::destroy() { // nothing to do here } -QSize QD3D11ReferenceRenderTarget::pixelSize() const +QSize QD3D11SwapChainRenderTarget::pixelSize() const { return d.pixelSize; } -float QD3D11ReferenceRenderTarget::devicePixelRatio() const +float QD3D11SwapChainRenderTarget::devicePixelRatio() const { return d.dpr; } -int QD3D11ReferenceRenderTarget::sampleCount() const +int QD3D11SwapChainRenderTarget::sampleCount() const { return d.sampleCount; } @@ -4380,7 +4380,7 @@ void QD3D11CommandBuffer::destroy() QD3D11SwapChain::QD3D11SwapChain(QRhiImplementation *rhi) : QRhiSwapChain(rhi), - rt(rhi), + rt(rhi, this), cb(rhi) { backBufferTex = nullptr; @@ -4825,7 +4825,7 @@ bool QD3D11SwapChain::createOrResize() frameCount = 0; ds = m_depthStencil ? QRHI_RES(QD3D11RenderBuffer, m_depthStencil) : nullptr; - QD3D11ReferenceRenderTarget *rtD = QRHI_RES(QD3D11ReferenceRenderTarget, &rt); + QD3D11SwapChainRenderTarget *rtD = QRHI_RES(QD3D11SwapChainRenderTarget, &rt); rtD->d.rp = QRHI_RES(QD3D11RenderPassDescriptor, m_renderPassDesc); rtD->d.pixelSize = pixelSize; rtD->d.dpr = float(window->devicePixelRatio()); diff --git a/src/gui/rhi/qrhid3d11_p_p.h b/src/gui/rhi/qrhid3d11_p_p.h index 9e12defbfd5..76a40ebce6a 100644 --- a/src/gui/rhi/qrhid3d11_p_p.h +++ b/src/gui/rhi/qrhid3d11_p_p.h @@ -177,10 +177,10 @@ struct QD3D11RenderTargetData QRhiRenderTargetAttachmentTracker::ResIdList currentResIdList; }; -struct QD3D11ReferenceRenderTarget : public QRhiRenderTarget +struct QD3D11SwapChainRenderTarget : public QRhiSwapChainRenderTarget { - QD3D11ReferenceRenderTarget(QRhiImplementation *rhi); - ~QD3D11ReferenceRenderTarget(); + QD3D11SwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain); + ~QD3D11SwapChainRenderTarget(); void destroy() override; QSize pixelSize() const override; @@ -571,7 +571,7 @@ struct QD3D11SwapChain : public QRhiSwapChain QWindow *window = nullptr; QSize pixelSize; - QD3D11ReferenceRenderTarget rt; + QD3D11SwapChainRenderTarget rt; QD3D11CommandBuffer cb; DXGI_FORMAT colorFormat; DXGI_FORMAT srgbAdjustedColorFormat; diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 94844cbb660..cbafa95f5d2 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -3953,8 +3953,8 @@ QGles2RenderTargetData *QRhiGles2::enqueueBindFramebuffer(QRhiRenderTarget *rt, static const bool doClearColorBuffer = qEnvironmentVariableIntValue("QT_GL_NO_CLEAR_COLOR_BUFFER") == 0; switch (rt->resourceType()) { - case QRhiResource::RenderTarget: - rtD = &QRHI_RES(QGles2ReferenceRenderTarget, rt)->d; + case QRhiResource::SwapChainRenderTarget: + rtD = &QRHI_RES(QGles2SwapChainRenderTarget, rt)->d; if (wantsColorClear) *wantsColorClear = doClearBuffers && doClearColorBuffer; if (wantsDsClear) @@ -5196,33 +5196,33 @@ QVector QGles2RenderPassDescriptor::serializedFormat() const return {}; } -QGles2ReferenceRenderTarget::QGles2ReferenceRenderTarget(QRhiImplementation *rhi) - : QRhiRenderTarget(rhi), +QGles2SwapChainRenderTarget::QGles2SwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain) + : QRhiSwapChainRenderTarget(rhi, swapchain), d(rhi) { } -QGles2ReferenceRenderTarget::~QGles2ReferenceRenderTarget() +QGles2SwapChainRenderTarget::~QGles2SwapChainRenderTarget() { destroy(); } -void QGles2ReferenceRenderTarget::destroy() +void QGles2SwapChainRenderTarget::destroy() { // nothing to do here } -QSize QGles2ReferenceRenderTarget::pixelSize() const +QSize QGles2SwapChainRenderTarget::pixelSize() const { return d.pixelSize; } -float QGles2ReferenceRenderTarget::devicePixelRatio() const +float QGles2SwapChainRenderTarget::devicePixelRatio() const { return d.dpr; } -int QGles2ReferenceRenderTarget::sampleCount() const +int QGles2SwapChainRenderTarget::sampleCount() const { return d.sampleCount; } @@ -5731,7 +5731,7 @@ void QGles2CommandBuffer::destroy() QGles2SwapChain::QGles2SwapChain(QRhiImplementation *rhi) : QRhiSwapChain(rhi), - rt(rhi), + rt(rhi, this), cb(rhi) { } diff --git a/src/gui/rhi/qrhigles2_p_p.h b/src/gui/rhi/qrhigles2_p_p.h index 3af4178a246..3fbdb8dceb4 100644 --- a/src/gui/rhi/qrhigles2_p_p.h +++ b/src/gui/rhi/qrhigles2_p_p.h @@ -219,10 +219,10 @@ struct QGles2RenderTargetData QRhiRenderTargetAttachmentTracker::ResIdList currentResIdList; }; -struct QGles2ReferenceRenderTarget : public QRhiRenderTarget +struct QGles2SwapChainRenderTarget : public QRhiSwapChainRenderTarget { - QGles2ReferenceRenderTarget(QRhiImplementation *rhi); - ~QGles2ReferenceRenderTarget(); + QGles2SwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain); + ~QGles2SwapChainRenderTarget(); void destroy() override; QSize pixelSize() const override; @@ -735,7 +735,7 @@ struct QGles2SwapChain : public QRhiSwapChain QSurface *surface = nullptr; QSize pixelSize; - QGles2ReferenceRenderTarget rt; + QGles2SwapChainRenderTarget rt; QGles2CommandBuffer cb; int frameCount = 0; }; diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index 72145b39e84..be38e92bcc4 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -2032,8 +2032,8 @@ void QRhiMetal::beginPass(QRhiCommandBuffer *cb, QMetalRenderTargetData *rtD = nullptr; switch (rt->resourceType()) { - case QRhiResource::RenderTarget: - rtD = QRHI_RES(QMetalReferenceRenderTarget, rt)->d; + case QRhiResource::SwapChainRenderTarget: + rtD = QRHI_RES(QMetalSwapChainRenderTarget, rt)->d; cbD->d->currentPassRpDesc = d->createDefaultRenderPass(rtD->dsAttCount, colorClearValue, depthStencilClearValue, rtD->colorAttCount); if (rtD->colorAttCount) { QMetalRenderTargetData::ColorAtt &color0(rtD->fb.colorAtt[0]); @@ -3053,34 +3053,34 @@ QVector QMetalRenderPassDescriptor::serializedFormat() const return serializedFormatData; } -QMetalReferenceRenderTarget::QMetalReferenceRenderTarget(QRhiImplementation *rhi) - : QRhiRenderTarget(rhi), +QMetalSwapChainRenderTarget::QMetalSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain) + : QRhiSwapChainRenderTarget(rhi, swapchain), d(new QMetalRenderTargetData) { } -QMetalReferenceRenderTarget::~QMetalReferenceRenderTarget() +QMetalSwapChainRenderTarget::~QMetalSwapChainRenderTarget() { destroy(); delete d; } -void QMetalReferenceRenderTarget::destroy() +void QMetalSwapChainRenderTarget::destroy() { // nothing to do here } -QSize QMetalReferenceRenderTarget::pixelSize() const +QSize QMetalSwapChainRenderTarget::pixelSize() const { return d->pixelSize; } -float QMetalReferenceRenderTarget::devicePixelRatio() const +float QMetalSwapChainRenderTarget::devicePixelRatio() const { return d->dpr; } -int QMetalReferenceRenderTarget::sampleCount() const +int QMetalSwapChainRenderTarget::sampleCount() const { return d->sampleCount; } @@ -3947,7 +3947,7 @@ void QMetalCommandBuffer::resetPerPassCachedState() QMetalSwapChain::QMetalSwapChain(QRhiImplementation *rhi) : QRhiSwapChain(rhi), - rtWrapper(rhi), + rtWrapper(rhi, this), cbWrapper(rhi), d(new QMetalSwapChainData) { diff --git a/src/gui/rhi/qrhimetal_p_p.h b/src/gui/rhi/qrhimetal_p_p.h index f96ddbe2091..cbb6e537b55 100644 --- a/src/gui/rhi/qrhimetal_p_p.h +++ b/src/gui/rhi/qrhimetal_p_p.h @@ -163,10 +163,10 @@ struct QMetalRenderPassDescriptor : public QRhiRenderPassDescriptor struct QMetalRenderTargetData; -struct QMetalReferenceRenderTarget : public QRhiRenderTarget +struct QMetalSwapChainRenderTarget : public QRhiSwapChainRenderTarget { - QMetalReferenceRenderTarget(QRhiImplementation *rhi); - ~QMetalReferenceRenderTarget(); + QMetalSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain); + ~QMetalSwapChainRenderTarget(); void destroy() override; QSize pixelSize() const override; @@ -337,7 +337,7 @@ struct QMetalSwapChain : public QRhiSwapChain int currentFrameSlot = 0; // 0..QMTL_FRAMES_IN_FLIGHT-1 int frameCount = 0; int samples = 1; - QMetalReferenceRenderTarget rtWrapper; + QMetalSwapChainRenderTarget rtWrapper; QMetalCommandBuffer cbWrapper; QMetalRenderBuffer *ds = nullptr; QMetalSwapChainData *d = nullptr; diff --git a/src/gui/rhi/qrhinull.cpp b/src/gui/rhi/qrhinull.cpp index 7136c7e73fb..f567894a9e6 100644 --- a/src/gui/rhi/qrhinull.cpp +++ b/src/gui/rhi/qrhinull.cpp @@ -788,32 +788,32 @@ QVector QNullRenderPassDescriptor::serializedFormat() const return {}; } -QNullReferenceRenderTarget::QNullReferenceRenderTarget(QRhiImplementation *rhi) - : QRhiRenderTarget(rhi), +QNullSwapChainRenderTarget::QNullSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain) + : QRhiSwapChainRenderTarget(rhi, swapchain), d(rhi) { } -QNullReferenceRenderTarget::~QNullReferenceRenderTarget() +QNullSwapChainRenderTarget::~QNullSwapChainRenderTarget() { destroy(); } -void QNullReferenceRenderTarget::destroy() +void QNullSwapChainRenderTarget::destroy() { } -QSize QNullReferenceRenderTarget::pixelSize() const +QSize QNullSwapChainRenderTarget::pixelSize() const { return d.pixelSize; } -float QNullReferenceRenderTarget::devicePixelRatio() const +float QNullSwapChainRenderTarget::devicePixelRatio() const { return d.dpr; } -int QNullReferenceRenderTarget::sampleCount() const +int QNullSwapChainRenderTarget::sampleCount() const { return 1; } @@ -965,7 +965,7 @@ void QNullCommandBuffer::destroy() QNullSwapChain::QNullSwapChain(QRhiImplementation *rhi) : QRhiSwapChain(rhi), - rt(rhi), + rt(rhi, this), cb(rhi) { } diff --git a/src/gui/rhi/qrhinull_p_p.h b/src/gui/rhi/qrhinull_p_p.h index 90c448dd240..b43cbc76878 100644 --- a/src/gui/rhi/qrhinull_p_p.h +++ b/src/gui/rhi/qrhinull_p_p.h @@ -124,10 +124,10 @@ struct QNullRenderTargetData QRhiRenderTargetAttachmentTracker::ResIdList currentResIdList; }; -struct QNullReferenceRenderTarget : public QRhiRenderTarget +struct QNullSwapChainRenderTarget : public QRhiSwapChainRenderTarget { - QNullReferenceRenderTarget(QRhiImplementation *rhi); - ~QNullReferenceRenderTarget(); + QNullSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain); + ~QNullSwapChainRenderTarget(); void destroy() override; QSize pixelSize() const override; @@ -201,7 +201,7 @@ struct QNullSwapChain : public QRhiSwapChain bool createOrResize() override; QWindow *window = nullptr; - QNullReferenceRenderTarget rt; + QNullSwapChainRenderTarget rt; QNullCommandBuffer cb; int frameCount = 0; }; diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index 9c39ab668ac..851b225a56f 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -2322,8 +2322,8 @@ void QRhiVulkan::beginPass(QRhiCommandBuffer *cb, QVkRenderTargetData *rtD = nullptr; switch (rt->resourceType()) { - case QRhiResource::RenderTarget: - rtD = &QRHI_RES(QVkReferenceRenderTarget, rt)->d; + case QRhiResource::SwapChainRenderTarget: + rtD = &QRHI_RES(QVkSwapChainRenderTarget, rt)->d; rtD->rp->lastActiveFrameSlot = currentFrameSlot; Q_ASSERT(currentSwapChain); currentSwapChain->imageRes[currentSwapChain->currentImageIndex].lastUse = @@ -5122,8 +5122,8 @@ static inline QVkRenderTargetData *maybeRenderTargetData(QVkCommandBuffer *cbD) QVkRenderTargetData *rtD = nullptr; if (cbD->recordingPass == QVkCommandBuffer::RenderPass) { switch (cbD->currentTarget->resourceType()) { - case QRhiResource::RenderTarget: - rtD = &QRHI_RES(QVkReferenceRenderTarget, cbD->currentTarget)->d; + case QRhiResource::SwapChainRenderTarget: + rtD = &QRHI_RES(QVkSwapChainRenderTarget, cbD->currentTarget)->d; break; case QRhiResource::TextureRenderTarget: rtD = &QRHI_RES(QVkTextureRenderTarget, cbD->currentTarget)->d; @@ -6432,32 +6432,32 @@ const QRhiNativeHandles *QVkRenderPassDescriptor::nativeHandles() return &nativeHandlesStruct; } -QVkReferenceRenderTarget::QVkReferenceRenderTarget(QRhiImplementation *rhi) - : QRhiRenderTarget(rhi) +QVkSwapChainRenderTarget::QVkSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain) + : QRhiSwapChainRenderTarget(rhi, swapchain) { } -QVkReferenceRenderTarget::~QVkReferenceRenderTarget() +QVkSwapChainRenderTarget::~QVkSwapChainRenderTarget() { destroy(); } -void QVkReferenceRenderTarget::destroy() +void QVkSwapChainRenderTarget::destroy() { // nothing to do here } -QSize QVkReferenceRenderTarget::pixelSize() const +QSize QVkSwapChainRenderTarget::pixelSize() const { return d.pixelSize; } -float QVkReferenceRenderTarget::devicePixelRatio() const +float QVkSwapChainRenderTarget::devicePixelRatio() const { return d.dpr; } -int QVkReferenceRenderTarget::sampleCount() const +int QVkSwapChainRenderTarget::sampleCount() const { return d.sampleCount; } @@ -7250,7 +7250,7 @@ const QRhiNativeHandles *QVkCommandBuffer::nativeHandles() QVkSwapChain::QVkSwapChain(QRhiImplementation *rhi) : QRhiSwapChain(rhi), - rtWrapper(rhi), + rtWrapper(rhi, this), cbWrapper(rhi) { } diff --git a/src/gui/rhi/qrhivulkan_p_p.h b/src/gui/rhi/qrhivulkan_p_p.h index f916d7d2b5c..30cde199c86 100644 --- a/src/gui/rhi/qrhivulkan_p_p.h +++ b/src/gui/rhi/qrhivulkan_p_p.h @@ -219,10 +219,10 @@ struct QVkRenderTargetData static const int MAX_COLOR_ATTACHMENTS = 8; }; -struct QVkReferenceRenderTarget : public QRhiRenderTarget +struct QVkSwapChainRenderTarget : public QRhiSwapChainRenderTarget { - QVkReferenceRenderTarget(QRhiImplementation *rhi); - ~QVkReferenceRenderTarget(); + QVkSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain); + ~QVkSwapChainRenderTarget(); void destroy() override; QSize pixelSize() const override; @@ -625,7 +625,7 @@ struct QVkSwapChain : public QRhiSwapChain VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT; QVarLengthArray supportedPresentationModes; VkDeviceMemory msaaImageMem = VK_NULL_HANDLE; - QVkReferenceRenderTarget rtWrapper; + QVkSwapChainRenderTarget rtWrapper; QVkCommandBuffer cbWrapper; struct ImageResources { diff --git a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp index 613ba053237..a0b2345d246 100644 --- a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp +++ b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp @@ -3454,6 +3454,8 @@ void tst_QRhi::renderToWindowSimple() QVERIFY(rhi->beginFrame(swapChain.data()) == QRhi::FrameOpSuccess); QRhiCommandBuffer *cb = swapChain->currentFrameCommandBuffer(); QRhiRenderTarget *rt = swapChain->currentFrameRenderTarget(); + QCOMPARE(rt->resourceType(), QRhiResource::SwapChainRenderTarget); + QCOMPARE(static_cast(rt)->swapChain(), swapChain.data()); const QSize outputSize = swapChain->currentPixelSize(); QCOMPARE(rt->pixelSize(), outputSize); QRhiViewport viewport(0, 0, float(outputSize.width()), float(outputSize.height()));