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 <andy.nichols@qt.io>
This commit is contained in:
Laszlo Agocs 2022-04-01 15:01:45 +02:00
parent d72f2ca9ea
commit a5db072dc2
13 changed files with 130 additions and 84 deletions

View File

@ -2943,6 +2943,8 @@ const QRhiNativeHandles *QRhiRenderPassDescriptor::nativeHandles()
\internal \internal
\inmodule QtGui \inmodule QtGui
\brief Represents an onscreen (swapchain) or offscreen (texture) render target. \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 \fn QSize QRhiRenderTarget::pixelSize() const
@ -2988,6 +2982,42 @@ QRhiResource::Type QRhiRenderTarget::resourceType() const
QWindow. 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 \class QRhiTextureRenderTarget
\internal \internal
@ -2997,6 +3027,10 @@ QRhiResource::Type QRhiRenderTarget::resourceType() const
A texture render target allows rendering into one or more textures, A texture render target allows rendering into one or more textures,
optionally with a depth texture or depth/stencil renderbuffer. 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 \note Textures used in combination with QRhiTextureRenderTarget must be
created with the QRhiTexture::RenderTarget flag. created with the QRhiTexture::RenderTarget flag.
@ -4911,8 +4945,8 @@ static const char *resourceTypeStr(QRhiResource *res)
return "RenderBuffer"; return "RenderBuffer";
case QRhiResource::RenderPassDescriptor: case QRhiResource::RenderPassDescriptor:
return "RenderPassDescriptor"; return "RenderPassDescriptor";
case QRhiResource::RenderTarget: case QRhiResource::SwapChainRenderTarget:
return "RenderTarget"; return "SwapChainRenderTarget";
case QRhiResource::TextureRenderTarget: case QRhiResource::TextureRenderTarget:
return "TextureRenderTarget"; return "TextureRenderTarget";
case QRhiResource::ShaderResourceBindings: case QRhiResource::ShaderResourceBindings:

View File

@ -74,6 +74,7 @@ class QRhiSampler;
class QRhiCommandBuffer; class QRhiCommandBuffer;
class QRhiResourceUpdateBatch; class QRhiResourceUpdateBatch;
class QRhiResourceUpdateBatchPrivate; class QRhiResourceUpdateBatchPrivate;
class QRhiSwapChain;
class Q_GUI_EXPORT QRhiDepthStencilClearValue class Q_GUI_EXPORT QRhiDepthStencilClearValue
{ {
@ -697,7 +698,7 @@ public:
Sampler, Sampler,
RenderBuffer, RenderBuffer,
RenderPassDescriptor, RenderPassDescriptor,
RenderTarget, SwapChainRenderTarget,
TextureRenderTarget, TextureRenderTarget,
ShaderResourceBindings, ShaderResourceBindings,
GraphicsPipeline, GraphicsPipeline,
@ -1031,8 +1032,6 @@ protected:
class Q_GUI_EXPORT QRhiRenderTarget : public QRhiResource class Q_GUI_EXPORT QRhiRenderTarget : public QRhiResource
{ {
public: public:
QRhiResource::Type resourceType() const override;
virtual QSize pixelSize() const = 0; virtual QSize pixelSize() const = 0;
virtual float devicePixelRatio() const = 0; virtual float devicePixelRatio() const = 0;
virtual int sampleCount() const = 0; virtual int sampleCount() const = 0;
@ -1045,6 +1044,17 @@ protected:
QRhiRenderPassDescriptor *m_renderPassDesc = nullptr; 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 class Q_GUI_EXPORT QRhiTextureRenderTarget : public QRhiRenderTarget
{ {
public: public:

View File

@ -1759,8 +1759,8 @@ void QRhiD3D11::finishActiveReadbacks()
static inline QD3D11RenderTargetData *rtData(QRhiRenderTarget *rt) static inline QD3D11RenderTargetData *rtData(QRhiRenderTarget *rt)
{ {
switch (rt->resourceType()) { switch (rt->resourceType()) {
case QRhiResource::RenderTarget: case QRhiResource::SwapChainRenderTarget:
return &QRHI_RES(QD3D11ReferenceRenderTarget, rt)->d; return &QRHI_RES(QD3D11SwapChainRenderTarget, rt)->d;
case QRhiResource::TextureRenderTarget: case QRhiResource::TextureRenderTarget:
return &QRHI_RES(QD3D11TextureRenderTarget, rt)->d; return &QRHI_RES(QD3D11TextureRenderTarget, rt)->d;
default: default:
@ -3453,33 +3453,33 @@ QVector<quint32> QD3D11RenderPassDescriptor::serializedFormat() const
return {}; return {};
} }
QD3D11ReferenceRenderTarget::QD3D11ReferenceRenderTarget(QRhiImplementation *rhi) QD3D11SwapChainRenderTarget::QD3D11SwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain)
: QRhiRenderTarget(rhi), : QRhiSwapChainRenderTarget(rhi, swapchain),
d(rhi) d(rhi)
{ {
} }
QD3D11ReferenceRenderTarget::~QD3D11ReferenceRenderTarget() QD3D11SwapChainRenderTarget::~QD3D11SwapChainRenderTarget()
{ {
destroy(); destroy();
} }
void QD3D11ReferenceRenderTarget::destroy() void QD3D11SwapChainRenderTarget::destroy()
{ {
// nothing to do here // nothing to do here
} }
QSize QD3D11ReferenceRenderTarget::pixelSize() const QSize QD3D11SwapChainRenderTarget::pixelSize() const
{ {
return d.pixelSize; return d.pixelSize;
} }
float QD3D11ReferenceRenderTarget::devicePixelRatio() const float QD3D11SwapChainRenderTarget::devicePixelRatio() const
{ {
return d.dpr; return d.dpr;
} }
int QD3D11ReferenceRenderTarget::sampleCount() const int QD3D11SwapChainRenderTarget::sampleCount() const
{ {
return d.sampleCount; return d.sampleCount;
} }
@ -4380,7 +4380,7 @@ void QD3D11CommandBuffer::destroy()
QD3D11SwapChain::QD3D11SwapChain(QRhiImplementation *rhi) QD3D11SwapChain::QD3D11SwapChain(QRhiImplementation *rhi)
: QRhiSwapChain(rhi), : QRhiSwapChain(rhi),
rt(rhi), rt(rhi, this),
cb(rhi) cb(rhi)
{ {
backBufferTex = nullptr; backBufferTex = nullptr;
@ -4825,7 +4825,7 @@ bool QD3D11SwapChain::createOrResize()
frameCount = 0; frameCount = 0;
ds = m_depthStencil ? QRHI_RES(QD3D11RenderBuffer, m_depthStencil) : nullptr; 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.rp = QRHI_RES(QD3D11RenderPassDescriptor, m_renderPassDesc);
rtD->d.pixelSize = pixelSize; rtD->d.pixelSize = pixelSize;
rtD->d.dpr = float(window->devicePixelRatio()); rtD->d.dpr = float(window->devicePixelRatio());

View File

@ -177,10 +177,10 @@ struct QD3D11RenderTargetData
QRhiRenderTargetAttachmentTracker::ResIdList currentResIdList; QRhiRenderTargetAttachmentTracker::ResIdList currentResIdList;
}; };
struct QD3D11ReferenceRenderTarget : public QRhiRenderTarget struct QD3D11SwapChainRenderTarget : public QRhiSwapChainRenderTarget
{ {
QD3D11ReferenceRenderTarget(QRhiImplementation *rhi); QD3D11SwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain);
~QD3D11ReferenceRenderTarget(); ~QD3D11SwapChainRenderTarget();
void destroy() override; void destroy() override;
QSize pixelSize() const override; QSize pixelSize() const override;
@ -571,7 +571,7 @@ struct QD3D11SwapChain : public QRhiSwapChain
QWindow *window = nullptr; QWindow *window = nullptr;
QSize pixelSize; QSize pixelSize;
QD3D11ReferenceRenderTarget rt; QD3D11SwapChainRenderTarget rt;
QD3D11CommandBuffer cb; QD3D11CommandBuffer cb;
DXGI_FORMAT colorFormat; DXGI_FORMAT colorFormat;
DXGI_FORMAT srgbAdjustedColorFormat; DXGI_FORMAT srgbAdjustedColorFormat;

View File

@ -3953,8 +3953,8 @@ QGles2RenderTargetData *QRhiGles2::enqueueBindFramebuffer(QRhiRenderTarget *rt,
static const bool doClearColorBuffer = qEnvironmentVariableIntValue("QT_GL_NO_CLEAR_COLOR_BUFFER") == 0; static const bool doClearColorBuffer = qEnvironmentVariableIntValue("QT_GL_NO_CLEAR_COLOR_BUFFER") == 0;
switch (rt->resourceType()) { switch (rt->resourceType()) {
case QRhiResource::RenderTarget: case QRhiResource::SwapChainRenderTarget:
rtD = &QRHI_RES(QGles2ReferenceRenderTarget, rt)->d; rtD = &QRHI_RES(QGles2SwapChainRenderTarget, rt)->d;
if (wantsColorClear) if (wantsColorClear)
*wantsColorClear = doClearBuffers && doClearColorBuffer; *wantsColorClear = doClearBuffers && doClearColorBuffer;
if (wantsDsClear) if (wantsDsClear)
@ -5196,33 +5196,33 @@ QVector<quint32> QGles2RenderPassDescriptor::serializedFormat() const
return {}; return {};
} }
QGles2ReferenceRenderTarget::QGles2ReferenceRenderTarget(QRhiImplementation *rhi) QGles2SwapChainRenderTarget::QGles2SwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain)
: QRhiRenderTarget(rhi), : QRhiSwapChainRenderTarget(rhi, swapchain),
d(rhi) d(rhi)
{ {
} }
QGles2ReferenceRenderTarget::~QGles2ReferenceRenderTarget() QGles2SwapChainRenderTarget::~QGles2SwapChainRenderTarget()
{ {
destroy(); destroy();
} }
void QGles2ReferenceRenderTarget::destroy() void QGles2SwapChainRenderTarget::destroy()
{ {
// nothing to do here // nothing to do here
} }
QSize QGles2ReferenceRenderTarget::pixelSize() const QSize QGles2SwapChainRenderTarget::pixelSize() const
{ {
return d.pixelSize; return d.pixelSize;
} }
float QGles2ReferenceRenderTarget::devicePixelRatio() const float QGles2SwapChainRenderTarget::devicePixelRatio() const
{ {
return d.dpr; return d.dpr;
} }
int QGles2ReferenceRenderTarget::sampleCount() const int QGles2SwapChainRenderTarget::sampleCount() const
{ {
return d.sampleCount; return d.sampleCount;
} }
@ -5731,7 +5731,7 @@ void QGles2CommandBuffer::destroy()
QGles2SwapChain::QGles2SwapChain(QRhiImplementation *rhi) QGles2SwapChain::QGles2SwapChain(QRhiImplementation *rhi)
: QRhiSwapChain(rhi), : QRhiSwapChain(rhi),
rt(rhi), rt(rhi, this),
cb(rhi) cb(rhi)
{ {
} }

View File

@ -219,10 +219,10 @@ struct QGles2RenderTargetData
QRhiRenderTargetAttachmentTracker::ResIdList currentResIdList; QRhiRenderTargetAttachmentTracker::ResIdList currentResIdList;
}; };
struct QGles2ReferenceRenderTarget : public QRhiRenderTarget struct QGles2SwapChainRenderTarget : public QRhiSwapChainRenderTarget
{ {
QGles2ReferenceRenderTarget(QRhiImplementation *rhi); QGles2SwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain);
~QGles2ReferenceRenderTarget(); ~QGles2SwapChainRenderTarget();
void destroy() override; void destroy() override;
QSize pixelSize() const override; QSize pixelSize() const override;
@ -735,7 +735,7 @@ struct QGles2SwapChain : public QRhiSwapChain
QSurface *surface = nullptr; QSurface *surface = nullptr;
QSize pixelSize; QSize pixelSize;
QGles2ReferenceRenderTarget rt; QGles2SwapChainRenderTarget rt;
QGles2CommandBuffer cb; QGles2CommandBuffer cb;
int frameCount = 0; int frameCount = 0;
}; };

View File

@ -2032,8 +2032,8 @@ void QRhiMetal::beginPass(QRhiCommandBuffer *cb,
QMetalRenderTargetData *rtD = nullptr; QMetalRenderTargetData *rtD = nullptr;
switch (rt->resourceType()) { switch (rt->resourceType()) {
case QRhiResource::RenderTarget: case QRhiResource::SwapChainRenderTarget:
rtD = QRHI_RES(QMetalReferenceRenderTarget, rt)->d; rtD = QRHI_RES(QMetalSwapChainRenderTarget, rt)->d;
cbD->d->currentPassRpDesc = d->createDefaultRenderPass(rtD->dsAttCount, colorClearValue, depthStencilClearValue, rtD->colorAttCount); cbD->d->currentPassRpDesc = d->createDefaultRenderPass(rtD->dsAttCount, colorClearValue, depthStencilClearValue, rtD->colorAttCount);
if (rtD->colorAttCount) { if (rtD->colorAttCount) {
QMetalRenderTargetData::ColorAtt &color0(rtD->fb.colorAtt[0]); QMetalRenderTargetData::ColorAtt &color0(rtD->fb.colorAtt[0]);
@ -3053,34 +3053,34 @@ QVector<quint32> QMetalRenderPassDescriptor::serializedFormat() const
return serializedFormatData; return serializedFormatData;
} }
QMetalReferenceRenderTarget::QMetalReferenceRenderTarget(QRhiImplementation *rhi) QMetalSwapChainRenderTarget::QMetalSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain)
: QRhiRenderTarget(rhi), : QRhiSwapChainRenderTarget(rhi, swapchain),
d(new QMetalRenderTargetData) d(new QMetalRenderTargetData)
{ {
} }
QMetalReferenceRenderTarget::~QMetalReferenceRenderTarget() QMetalSwapChainRenderTarget::~QMetalSwapChainRenderTarget()
{ {
destroy(); destroy();
delete d; delete d;
} }
void QMetalReferenceRenderTarget::destroy() void QMetalSwapChainRenderTarget::destroy()
{ {
// nothing to do here // nothing to do here
} }
QSize QMetalReferenceRenderTarget::pixelSize() const QSize QMetalSwapChainRenderTarget::pixelSize() const
{ {
return d->pixelSize; return d->pixelSize;
} }
float QMetalReferenceRenderTarget::devicePixelRatio() const float QMetalSwapChainRenderTarget::devicePixelRatio() const
{ {
return d->dpr; return d->dpr;
} }
int QMetalReferenceRenderTarget::sampleCount() const int QMetalSwapChainRenderTarget::sampleCount() const
{ {
return d->sampleCount; return d->sampleCount;
} }
@ -3947,7 +3947,7 @@ void QMetalCommandBuffer::resetPerPassCachedState()
QMetalSwapChain::QMetalSwapChain(QRhiImplementation *rhi) QMetalSwapChain::QMetalSwapChain(QRhiImplementation *rhi)
: QRhiSwapChain(rhi), : QRhiSwapChain(rhi),
rtWrapper(rhi), rtWrapper(rhi, this),
cbWrapper(rhi), cbWrapper(rhi),
d(new QMetalSwapChainData) d(new QMetalSwapChainData)
{ {

View File

@ -163,10 +163,10 @@ struct QMetalRenderPassDescriptor : public QRhiRenderPassDescriptor
struct QMetalRenderTargetData; struct QMetalRenderTargetData;
struct QMetalReferenceRenderTarget : public QRhiRenderTarget struct QMetalSwapChainRenderTarget : public QRhiSwapChainRenderTarget
{ {
QMetalReferenceRenderTarget(QRhiImplementation *rhi); QMetalSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain);
~QMetalReferenceRenderTarget(); ~QMetalSwapChainRenderTarget();
void destroy() override; void destroy() override;
QSize pixelSize() const override; QSize pixelSize() const override;
@ -337,7 +337,7 @@ struct QMetalSwapChain : public QRhiSwapChain
int currentFrameSlot = 0; // 0..QMTL_FRAMES_IN_FLIGHT-1 int currentFrameSlot = 0; // 0..QMTL_FRAMES_IN_FLIGHT-1
int frameCount = 0; int frameCount = 0;
int samples = 1; int samples = 1;
QMetalReferenceRenderTarget rtWrapper; QMetalSwapChainRenderTarget rtWrapper;
QMetalCommandBuffer cbWrapper; QMetalCommandBuffer cbWrapper;
QMetalRenderBuffer *ds = nullptr; QMetalRenderBuffer *ds = nullptr;
QMetalSwapChainData *d = nullptr; QMetalSwapChainData *d = nullptr;

View File

@ -788,32 +788,32 @@ QVector<quint32> QNullRenderPassDescriptor::serializedFormat() const
return {}; return {};
} }
QNullReferenceRenderTarget::QNullReferenceRenderTarget(QRhiImplementation *rhi) QNullSwapChainRenderTarget::QNullSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain)
: QRhiRenderTarget(rhi), : QRhiSwapChainRenderTarget(rhi, swapchain),
d(rhi) d(rhi)
{ {
} }
QNullReferenceRenderTarget::~QNullReferenceRenderTarget() QNullSwapChainRenderTarget::~QNullSwapChainRenderTarget()
{ {
destroy(); destroy();
} }
void QNullReferenceRenderTarget::destroy() void QNullSwapChainRenderTarget::destroy()
{ {
} }
QSize QNullReferenceRenderTarget::pixelSize() const QSize QNullSwapChainRenderTarget::pixelSize() const
{ {
return d.pixelSize; return d.pixelSize;
} }
float QNullReferenceRenderTarget::devicePixelRatio() const float QNullSwapChainRenderTarget::devicePixelRatio() const
{ {
return d.dpr; return d.dpr;
} }
int QNullReferenceRenderTarget::sampleCount() const int QNullSwapChainRenderTarget::sampleCount() const
{ {
return 1; return 1;
} }
@ -965,7 +965,7 @@ void QNullCommandBuffer::destroy()
QNullSwapChain::QNullSwapChain(QRhiImplementation *rhi) QNullSwapChain::QNullSwapChain(QRhiImplementation *rhi)
: QRhiSwapChain(rhi), : QRhiSwapChain(rhi),
rt(rhi), rt(rhi, this),
cb(rhi) cb(rhi)
{ {
} }

View File

@ -124,10 +124,10 @@ struct QNullRenderTargetData
QRhiRenderTargetAttachmentTracker::ResIdList currentResIdList; QRhiRenderTargetAttachmentTracker::ResIdList currentResIdList;
}; };
struct QNullReferenceRenderTarget : public QRhiRenderTarget struct QNullSwapChainRenderTarget : public QRhiSwapChainRenderTarget
{ {
QNullReferenceRenderTarget(QRhiImplementation *rhi); QNullSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain);
~QNullReferenceRenderTarget(); ~QNullSwapChainRenderTarget();
void destroy() override; void destroy() override;
QSize pixelSize() const override; QSize pixelSize() const override;
@ -201,7 +201,7 @@ struct QNullSwapChain : public QRhiSwapChain
bool createOrResize() override; bool createOrResize() override;
QWindow *window = nullptr; QWindow *window = nullptr;
QNullReferenceRenderTarget rt; QNullSwapChainRenderTarget rt;
QNullCommandBuffer cb; QNullCommandBuffer cb;
int frameCount = 0; int frameCount = 0;
}; };

View File

@ -2322,8 +2322,8 @@ void QRhiVulkan::beginPass(QRhiCommandBuffer *cb,
QVkRenderTargetData *rtD = nullptr; QVkRenderTargetData *rtD = nullptr;
switch (rt->resourceType()) { switch (rt->resourceType()) {
case QRhiResource::RenderTarget: case QRhiResource::SwapChainRenderTarget:
rtD = &QRHI_RES(QVkReferenceRenderTarget, rt)->d; rtD = &QRHI_RES(QVkSwapChainRenderTarget, rt)->d;
rtD->rp->lastActiveFrameSlot = currentFrameSlot; rtD->rp->lastActiveFrameSlot = currentFrameSlot;
Q_ASSERT(currentSwapChain); Q_ASSERT(currentSwapChain);
currentSwapChain->imageRes[currentSwapChain->currentImageIndex].lastUse = currentSwapChain->imageRes[currentSwapChain->currentImageIndex].lastUse =
@ -5122,8 +5122,8 @@ static inline QVkRenderTargetData *maybeRenderTargetData(QVkCommandBuffer *cbD)
QVkRenderTargetData *rtD = nullptr; QVkRenderTargetData *rtD = nullptr;
if (cbD->recordingPass == QVkCommandBuffer::RenderPass) { if (cbD->recordingPass == QVkCommandBuffer::RenderPass) {
switch (cbD->currentTarget->resourceType()) { switch (cbD->currentTarget->resourceType()) {
case QRhiResource::RenderTarget: case QRhiResource::SwapChainRenderTarget:
rtD = &QRHI_RES(QVkReferenceRenderTarget, cbD->currentTarget)->d; rtD = &QRHI_RES(QVkSwapChainRenderTarget, cbD->currentTarget)->d;
break; break;
case QRhiResource::TextureRenderTarget: case QRhiResource::TextureRenderTarget:
rtD = &QRHI_RES(QVkTextureRenderTarget, cbD->currentTarget)->d; rtD = &QRHI_RES(QVkTextureRenderTarget, cbD->currentTarget)->d;
@ -6432,32 +6432,32 @@ const QRhiNativeHandles *QVkRenderPassDescriptor::nativeHandles()
return &nativeHandlesStruct; return &nativeHandlesStruct;
} }
QVkReferenceRenderTarget::QVkReferenceRenderTarget(QRhiImplementation *rhi) QVkSwapChainRenderTarget::QVkSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain)
: QRhiRenderTarget(rhi) : QRhiSwapChainRenderTarget(rhi, swapchain)
{ {
} }
QVkReferenceRenderTarget::~QVkReferenceRenderTarget() QVkSwapChainRenderTarget::~QVkSwapChainRenderTarget()
{ {
destroy(); destroy();
} }
void QVkReferenceRenderTarget::destroy() void QVkSwapChainRenderTarget::destroy()
{ {
// nothing to do here // nothing to do here
} }
QSize QVkReferenceRenderTarget::pixelSize() const QSize QVkSwapChainRenderTarget::pixelSize() const
{ {
return d.pixelSize; return d.pixelSize;
} }
float QVkReferenceRenderTarget::devicePixelRatio() const float QVkSwapChainRenderTarget::devicePixelRatio() const
{ {
return d.dpr; return d.dpr;
} }
int QVkReferenceRenderTarget::sampleCount() const int QVkSwapChainRenderTarget::sampleCount() const
{ {
return d.sampleCount; return d.sampleCount;
} }
@ -7250,7 +7250,7 @@ const QRhiNativeHandles *QVkCommandBuffer::nativeHandles()
QVkSwapChain::QVkSwapChain(QRhiImplementation *rhi) QVkSwapChain::QVkSwapChain(QRhiImplementation *rhi)
: QRhiSwapChain(rhi), : QRhiSwapChain(rhi),
rtWrapper(rhi), rtWrapper(rhi, this),
cbWrapper(rhi) cbWrapper(rhi)
{ {
} }

View File

@ -219,10 +219,10 @@ struct QVkRenderTargetData
static const int MAX_COLOR_ATTACHMENTS = 8; static const int MAX_COLOR_ATTACHMENTS = 8;
}; };
struct QVkReferenceRenderTarget : public QRhiRenderTarget struct QVkSwapChainRenderTarget : public QRhiSwapChainRenderTarget
{ {
QVkReferenceRenderTarget(QRhiImplementation *rhi); QVkSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain);
~QVkReferenceRenderTarget(); ~QVkSwapChainRenderTarget();
void destroy() override; void destroy() override;
QSize pixelSize() const override; QSize pixelSize() const override;
@ -625,7 +625,7 @@ struct QVkSwapChain : public QRhiSwapChain
VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT; VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT;
QVarLengthArray<VkPresentModeKHR, 8> supportedPresentationModes; QVarLengthArray<VkPresentModeKHR, 8> supportedPresentationModes;
VkDeviceMemory msaaImageMem = VK_NULL_HANDLE; VkDeviceMemory msaaImageMem = VK_NULL_HANDLE;
QVkReferenceRenderTarget rtWrapper; QVkSwapChainRenderTarget rtWrapper;
QVkCommandBuffer cbWrapper; QVkCommandBuffer cbWrapper;
struct ImageResources { struct ImageResources {

View File

@ -3454,6 +3454,8 @@ void tst_QRhi::renderToWindowSimple()
QVERIFY(rhi->beginFrame(swapChain.data()) == QRhi::FrameOpSuccess); QVERIFY(rhi->beginFrame(swapChain.data()) == QRhi::FrameOpSuccess);
QRhiCommandBuffer *cb = swapChain->currentFrameCommandBuffer(); QRhiCommandBuffer *cb = swapChain->currentFrameCommandBuffer();
QRhiRenderTarget *rt = swapChain->currentFrameRenderTarget(); QRhiRenderTarget *rt = swapChain->currentFrameRenderTarget();
QCOMPARE(rt->resourceType(), QRhiResource::SwapChainRenderTarget);
QCOMPARE(static_cast<QRhiSwapChainRenderTarget *>(rt)->swapChain(), swapChain.data());
const QSize outputSize = swapChain->currentPixelSize(); const QSize outputSize = swapChain->currentPixelSize();
QCOMPARE(rt->pixelSize(), outputSize); QCOMPARE(rt->pixelSize(), outputSize);
QRhiViewport viewport(0, 0, float(outputSize.width()), float(outputSize.height())); QRhiViewport viewport(0, 0, float(outputSize.width()), float(outputSize.height()));