Commit 7188859e authored by Laszlo Agocs's avatar Laszlo Agocs

Expose sample count from render targets

This is a convenience to allow renderers to figure out the sample
count for their pso by just querying renderTarget()->sampleCount()
where the render target is set up and provided from another component
outside of the renderer's knowledge and control.
parent 23915b58
...@@ -814,6 +814,7 @@ public: ...@@ -814,6 +814,7 @@ public:
virtual Type type() const = 0; virtual Type type() const = 0;
virtual QSize sizeInPixels() const = 0; virtual QSize sizeInPixels() const = 0;
virtual float devicePixelRatio() const = 0; virtual float devicePixelRatio() const = 0;
virtual int sampleCount() const = 0;
QRhiRenderPassDescriptor *renderPassDescriptor() const { return m_renderPassDesc; } QRhiRenderPassDescriptor *renderPassDescriptor() const { return m_renderPassDesc; }
void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; } void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
......
...@@ -1898,7 +1898,8 @@ bool QD3D11RenderBuffer::build() ...@@ -1898,7 +1898,8 @@ bool QD3D11RenderBuffer::build()
} }
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
memset(&rtvDesc, 0, sizeof(rtvDesc)); memset(&rtvDesc, 0, sizeof(rtvDesc));
rtvDesc.Format = dxgiFormat; rtvDesc.ViewDimension = desc.SampleDesc.Count > 1 ? D3D11_RTV_DIMENSION_TEXTURE2DMS rtvDesc.Format = dxgiFormat;
rtvDesc.ViewDimension = desc.SampleDesc.Count > 1 ? D3D11_RTV_DIMENSION_TEXTURE2DMS
: D3D11_RTV_DIMENSION_TEXTURE2D; : D3D11_RTV_DIMENSION_TEXTURE2D;
hr = rhiD->dev->CreateRenderTargetView(tex, &rtvDesc, &rtv); hr = rhiD->dev->CreateRenderTargetView(tex, &rtvDesc, &rtv);
if (FAILED(hr)) { if (FAILED(hr)) {
...@@ -2283,6 +2284,11 @@ float QD3D11ReferenceRenderTarget::devicePixelRatio() const ...@@ -2283,6 +2284,11 @@ float QD3D11ReferenceRenderTarget::devicePixelRatio() const
return d.dpr; return d.dpr;
} }
int QD3D11ReferenceRenderTarget::sampleCount() const
{
return d.sampleCount;
}
QD3D11TextureRenderTarget::QD3D11TextureRenderTarget(QRhiImplementation *rhi, QD3D11TextureRenderTarget::QD3D11TextureRenderTarget(QRhiImplementation *rhi,
const QRhiTextureRenderTargetDescription &desc, const QRhiTextureRenderTargetDescription &desc,
Flags flags) Flags flags)
...@@ -2365,16 +2371,18 @@ bool QD3D11TextureRenderTarget::build() ...@@ -2365,16 +2371,18 @@ bool QD3D11TextureRenderTarget::build()
return false; return false;
} }
ownsRtv[i] = true; ownsRtv[i] = true;
if (i == 0) if (i == 0) {
d.pixelSize = texD->pixelSize(); d.pixelSize = texD->pixelSize();
d.sampleCount = texD->sampleDesc.Count;
}
} else if (rb) { } else if (rb) {
QD3D11RenderBuffer *rbD = QRHI_RES(QD3D11RenderBuffer, rb); QD3D11RenderBuffer *rbD = QRHI_RES(QD3D11RenderBuffer, rb);
ownsRtv[i] = false; ownsRtv[i] = false;
rtv[i] = rbD->rtv; rtv[i] = rbD->rtv;
if (i == 0) if (i == 0) {
d.pixelSize = rbD->pixelSize(); d.pixelSize = rbD->pixelSize();
} else { d.sampleCount = rbD->sampleDesc.Count;
Q_UNREACHABLE(); }
} }
} }
d.dpr = 1; d.dpr = 1;
...@@ -2393,13 +2401,18 @@ bool QD3D11TextureRenderTarget::build() ...@@ -2393,13 +2401,18 @@ bool QD3D11TextureRenderTarget::build()
qWarning("Failed to create dsv: %s", qPrintable(comErrorMessage(hr))); qWarning("Failed to create dsv: %s", qPrintable(comErrorMessage(hr)));
return false; return false;
} }
if (d.colorAttCount == 0) if (d.colorAttCount == 0) {
d.pixelSize = depthTexD->pixelSize(); d.pixelSize = depthTexD->pixelSize();
d.sampleCount = depthTexD->sampleDesc.Count;
}
} else { } else {
ownsDsv = false; ownsDsv = false;
dsv = QRHI_RES(QD3D11RenderBuffer, m_desc.depthStencilBuffer())->dsv; QD3D11RenderBuffer *depthRbD = QRHI_RES(QD3D11RenderBuffer, m_desc.depthStencilBuffer());
if (d.colorAttCount == 0) dsv = depthRbD->dsv;
if (d.colorAttCount == 0) {
d.pixelSize = m_desc.depthStencilBuffer()->pixelSize(); d.pixelSize = m_desc.depthStencilBuffer()->pixelSize();
d.sampleCount = depthRbD->sampleDesc.Count;
}
} }
d.dsAttCount = 1; d.dsAttCount = 1;
} else { } else {
...@@ -2431,6 +2444,11 @@ float QD3D11TextureRenderTarget::devicePixelRatio() const ...@@ -2431,6 +2444,11 @@ float QD3D11TextureRenderTarget::devicePixelRatio() const
return d.dpr; return d.dpr;
} }
int QD3D11TextureRenderTarget::sampleCount() const
{
return d.sampleCount;
}
QD3D11ShaderResourceBindings::QD3D11ShaderResourceBindings(QRhiImplementation *rhi) QD3D11ShaderResourceBindings::QD3D11ShaderResourceBindings(QRhiImplementation *rhi)
: QRhiShaderResourceBindings(rhi) : QRhiShaderResourceBindings(rhi)
{ {
...@@ -3133,6 +3151,7 @@ bool QD3D11SwapChain::buildOrResize() ...@@ -3133,6 +3151,7 @@ bool QD3D11SwapChain::buildOrResize()
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 = window->devicePixelRatio(); rtD->d.dpr = window->devicePixelRatio();
rtD->d.sampleCount = sampleDesc.Count;
rtD->d.colorAttCount = 1; rtD->d.colorAttCount = 1;
rtD->d.dsAttCount = m_depthStencil ? 1 : 0; rtD->d.dsAttCount = m_depthStencil ? 1 : 0;
......
...@@ -132,6 +132,7 @@ struct QD3D11RenderTargetData ...@@ -132,6 +132,7 @@ struct QD3D11RenderTargetData
QD3D11RenderPassDescriptor *rp = nullptr; QD3D11RenderPassDescriptor *rp = nullptr;
QSize pixelSize; QSize pixelSize;
float dpr = 1; float dpr = 1;
int sampleCount = 1;
int colorAttCount = 0; int colorAttCount = 0;
int dsAttCount = 0; int dsAttCount = 0;
...@@ -144,9 +145,11 @@ struct QD3D11ReferenceRenderTarget : public QRhiRenderTarget ...@@ -144,9 +145,11 @@ struct QD3D11ReferenceRenderTarget : public QRhiRenderTarget
{ {
QD3D11ReferenceRenderTarget(QRhiImplementation *rhi); QD3D11ReferenceRenderTarget(QRhiImplementation *rhi);
void release() override; void release() override;
Type type() const override; Type type() const override;
QSize sizeInPixels() const override; QSize sizeInPixels() const override;
float devicePixelRatio() const override; float devicePixelRatio() const override;
int sampleCount() const override;
QD3D11RenderTargetData d; QD3D11RenderTargetData d;
}; };
...@@ -159,6 +162,7 @@ struct QD3D11TextureRenderTarget : public QRhiTextureRenderTarget ...@@ -159,6 +162,7 @@ struct QD3D11TextureRenderTarget : public QRhiTextureRenderTarget
Type type() const override; Type type() const override;
QSize sizeInPixels() const override; QSize sizeInPixels() const override;
float devicePixelRatio() const override; float devicePixelRatio() const override;
int sampleCount() const override;
QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override; QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override;
bool build() override; bool build() override;
......
...@@ -2239,6 +2239,11 @@ float QGles2ReferenceRenderTarget::devicePixelRatio() const ...@@ -2239,6 +2239,11 @@ float QGles2ReferenceRenderTarget::devicePixelRatio() const
return d.dpr; return d.dpr;
} }
int QGles2ReferenceRenderTarget::sampleCount() const
{
return d.sampleCount;
}
QGles2TextureRenderTarget::QGles2TextureRenderTarget(QRhiImplementation *rhi, QGles2TextureRenderTarget::QGles2TextureRenderTarget(QRhiImplementation *rhi,
const QRhiTextureRenderTargetDescription &desc, const QRhiTextureRenderTargetDescription &desc,
Flags flags) Flags flags)
...@@ -2306,10 +2311,12 @@ bool QGles2TextureRenderTarget::build() ...@@ -2306,10 +2311,12 @@ bool QGles2TextureRenderTarget::build()
const GLenum faceTargetBase = texD->flags().testFlag(QRhiTexture::CubeMap) ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : texD->target; const GLenum faceTargetBase = texD->flags().testFlag(QRhiTexture::CubeMap) ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : texD->target;
rhiD->f->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, faceTargetBase + colorAtt.layer(), texD->texture, colorAtt.level()); rhiD->f->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, faceTargetBase + colorAtt.layer(), texD->texture, colorAtt.level());
d.pixelSize = texD->pixelSize(); d.pixelSize = texD->pixelSize();
} else { d.sampleCount = 1;
} else if (renderBuffer) {
QGles2RenderBuffer *rbD = QRHI_RES(QGles2RenderBuffer, renderBuffer); QGles2RenderBuffer *rbD = QRHI_RES(QGles2RenderBuffer, renderBuffer);
rhiD->f->glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbD->renderbuffer); rhiD->f->glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbD->renderbuffer);
d.pixelSize = rbD->pixelSize(); d.pixelSize = rbD->pixelSize();
d.sampleCount = rbD->samples;
} }
d.dpr = 1; d.dpr = 1;
...@@ -2345,6 +2352,11 @@ float QGles2TextureRenderTarget::devicePixelRatio() const ...@@ -2345,6 +2352,11 @@ float QGles2TextureRenderTarget::devicePixelRatio() const
return d.dpr; return d.dpr;
} }
int QGles2TextureRenderTarget::sampleCount() const
{
return d.sampleCount;
}
QGles2ShaderResourceBindings::QGles2ShaderResourceBindings(QRhiImplementation *rhi) QGles2ShaderResourceBindings::QGles2ShaderResourceBindings(QRhiImplementation *rhi)
: QRhiShaderResourceBindings(rhi) : QRhiShaderResourceBindings(rhi)
{ {
...@@ -2587,6 +2599,7 @@ bool QGles2SwapChain::buildOrResize() ...@@ -2587,6 +2599,7 @@ bool QGles2SwapChain::buildOrResize()
rt.d.rp = QRHI_RES(QGles2RenderPassDescriptor, m_renderPassDesc); rt.d.rp = QRHI_RES(QGles2RenderPassDescriptor, m_renderPassDesc);
rt.d.pixelSize = pixelSize; rt.d.pixelSize = pixelSize;
rt.d.dpr = m_window->devicePixelRatio(); rt.d.dpr = m_window->devicePixelRatio();
rt.d.sampleCount = qBound(1, m_sampleCount, 64);
rt.d.attCount = m_depthStencil ? 2 : 1; rt.d.attCount = m_depthStencil ? 2 : 1;
rt.d.srgbUpdateAndBlend = m_flags.testFlag(QRhiSwapChain::sRGB); rt.d.srgbUpdateAndBlend = m_flags.testFlag(QRhiSwapChain::sRGB);
......
...@@ -131,6 +131,7 @@ struct QGles2RenderTargetData ...@@ -131,6 +131,7 @@ struct QGles2RenderTargetData
QGles2RenderPassDescriptor *rp = nullptr; QGles2RenderPassDescriptor *rp = nullptr;
QSize pixelSize; QSize pixelSize;
float dpr = 1; float dpr = 1;
int sampleCount = 1;
int attCount = 0; int attCount = 0;
bool srgbUpdateAndBlend = false; bool srgbUpdateAndBlend = false;
}; };
...@@ -139,9 +140,11 @@ struct QGles2ReferenceRenderTarget : public QRhiRenderTarget ...@@ -139,9 +140,11 @@ struct QGles2ReferenceRenderTarget : public QRhiRenderTarget
{ {
QGles2ReferenceRenderTarget(QRhiImplementation *rhi); QGles2ReferenceRenderTarget(QRhiImplementation *rhi);
void release() override; void release() override;
Type type() const override; Type type() const override;
QSize sizeInPixels() const override; QSize sizeInPixels() const override;
float devicePixelRatio() const override; float devicePixelRatio() const override;
int sampleCount() const override;
QGles2RenderTargetData d; QGles2RenderTargetData d;
}; };
...@@ -154,6 +157,7 @@ struct QGles2TextureRenderTarget : public QRhiTextureRenderTarget ...@@ -154,6 +157,7 @@ struct QGles2TextureRenderTarget : public QRhiTextureRenderTarget
Type type() const override; Type type() const override;
QSize sizeInPixels() const override; QSize sizeInPixels() const override;
float devicePixelRatio() const override; float devicePixelRatio() const override;
int sampleCount() const override;
QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override; QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override;
bool build() override; bool build() override;
......
...@@ -227,6 +227,7 @@ struct QMetalRenderTargetData ...@@ -227,6 +227,7 @@ struct QMetalRenderTargetData
{ {
QSize pixelSize; QSize pixelSize;
float dpr = 1; float dpr = 1;
int sampleCount = 1;
int colorAttCount = 0; int colorAttCount = 0;
int dsAttCount = 0; int dsAttCount = 0;
...@@ -2238,6 +2239,11 @@ float QMetalReferenceRenderTarget::devicePixelRatio() const ...@@ -2238,6 +2239,11 @@ float QMetalReferenceRenderTarget::devicePixelRatio() const
return d->dpr; return d->dpr;
} }
int QMetalReferenceRenderTarget::sampleCount() const
{
return d->sampleCount;
}
QMetalTextureRenderTarget::QMetalTextureRenderTarget(QRhiImplementation *rhi, QMetalTextureRenderTarget::QMetalTextureRenderTarget(QRhiImplementation *rhi,
const QRhiTextureRenderTargetDescription &desc, const QRhiTextureRenderTargetDescription &desc,
Flags flags) Flags flags)
...@@ -2289,15 +2295,19 @@ bool QMetalTextureRenderTarget::build() ...@@ -2289,15 +2295,19 @@ bool QMetalTextureRenderTarget::build()
QMetalTexture *texD = QRHI_RES(QMetalTexture, colorAttachments[i].texture()); QMetalTexture *texD = QRHI_RES(QMetalTexture, colorAttachments[i].texture());
QMetalRenderBuffer *rbD = QRHI_RES(QMetalRenderBuffer, colorAttachments[i].renderBuffer()); QMetalRenderBuffer *rbD = QRHI_RES(QMetalRenderBuffer, colorAttachments[i].renderBuffer());
Q_ASSERT(texD || rbD); Q_ASSERT(texD || rbD);
id<MTLTexture> dst; id<MTLTexture> dst = nil;
if (texD) { if (texD) {
dst = texD->d->tex; dst = texD->d->tex;
if (i == 0) if (i == 0) {
d->pixelSize = texD->pixelSize(); d->pixelSize = texD->pixelSize();
} else { d->sampleCount = texD->samples;
}
} else if (rbD) {
dst = rbD->d->tex; dst = rbD->d->tex;
if (i == 0) if (i == 0) {
d->pixelSize = rbD->pixelSize(); d->pixelSize = rbD->pixelSize();
d->sampleCount = rbD->samples;
}
} }
QMetalRenderTargetData::ColorAtt colorAtt; QMetalRenderTargetData::ColorAtt colorAtt;
colorAtt.tex = dst; colorAtt.tex = dst;
...@@ -2313,15 +2323,21 @@ bool QMetalTextureRenderTarget::build() ...@@ -2313,15 +2323,21 @@ bool QMetalTextureRenderTarget::build()
if (hasDepthStencil) { if (hasDepthStencil) {
if (m_desc.depthTexture()) { if (m_desc.depthTexture()) {
d->fb.dsTex = QRHI_RES(QMetalTexture, m_desc.depthTexture())->d->tex; QMetalTexture *depthTexD = QRHI_RES(QMetalTexture, m_desc.depthTexture());
d->fb.dsTex = depthTexD->d->tex;
d->fb.hasStencil = false; d->fb.hasStencil = false;
if (d->colorAttCount == 0) if (d->colorAttCount == 0) {
d->pixelSize = m_desc.depthTexture()->pixelSize(); d->pixelSize = depthTexD->pixelSize();
d->sampleCount = depthTexD->samples;
}
} else { } else {
d->fb.dsTex = QRHI_RES(QMetalRenderBuffer, m_desc.depthStencilBuffer())->d->tex; QMetalRenderBuffer *depthRbD = QRHI_RES(QMetalRenderBuffer, m_desc.depthStencilBuffer());
d->fb.dsTex = depthRbD->d->tex;
d->fb.hasStencil = true; d->fb.hasStencil = true;
if (d->colorAttCount == 0) if (d->colorAttCount == 0) {
d->pixelSize = m_desc.depthStencilBuffer()->pixelSize(); d->pixelSize = depthRbD->pixelSize();
d->sampleCount = depthRbD->samples;
}
} }
d->dsAttCount = 1; d->dsAttCount = 1;
} else { } else {
...@@ -2346,6 +2362,11 @@ float QMetalTextureRenderTarget::devicePixelRatio() const ...@@ -2346,6 +2362,11 @@ float QMetalTextureRenderTarget::devicePixelRatio() const
return d->dpr; return d->dpr;
} }
int QMetalTextureRenderTarget::sampleCount() const
{
return d->sampleCount;
}
QMetalShaderResourceBindings::QMetalShaderResourceBindings(QRhiImplementation *rhi) QMetalShaderResourceBindings::QMetalShaderResourceBindings(QRhiImplementation *rhi)
: QRhiShaderResourceBindings(rhi) : QRhiShaderResourceBindings(rhi)
{ {
...@@ -3057,6 +3078,7 @@ bool QMetalSwapChain::buildOrResize() ...@@ -3057,6 +3078,7 @@ bool QMetalSwapChain::buildOrResize()
rtWrapper.d->pixelSize = pixelSize; rtWrapper.d->pixelSize = pixelSize;
rtWrapper.d->dpr = window->devicePixelRatio(); rtWrapper.d->dpr = window->devicePixelRatio();
rtWrapper.d->sampleCount = samples;
rtWrapper.d->colorAttCount = 1; rtWrapper.d->colorAttCount = 1;
rtWrapper.d->dsAttCount = ds ? 1 : 0; rtWrapper.d->dsAttCount = ds ? 1 : 0;
......
...@@ -152,6 +152,7 @@ struct QMetalReferenceRenderTarget : public QRhiRenderTarget ...@@ -152,6 +152,7 @@ struct QMetalReferenceRenderTarget : public QRhiRenderTarget
Type type() const override; Type type() const override;
QSize sizeInPixels() const override; QSize sizeInPixels() const override;
float devicePixelRatio() const override; float devicePixelRatio() const override;
int sampleCount() const override;
QMetalRenderTargetData *d; QMetalRenderTargetData *d;
}; };
...@@ -165,6 +166,7 @@ struct QMetalTextureRenderTarget : public QRhiTextureRenderTarget ...@@ -165,6 +166,7 @@ struct QMetalTextureRenderTarget : public QRhiTextureRenderTarget
Type type() const override; Type type() const override;
QSize sizeInPixels() const override; QSize sizeInPixels() const override;
float devicePixelRatio() const override; float devicePixelRatio() const override;
int sampleCount() const override;
QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override; QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override;
bool build() override; bool build() override;
......
...@@ -471,6 +471,11 @@ float QNullReferenceRenderTarget::devicePixelRatio() const ...@@ -471,6 +471,11 @@ float QNullReferenceRenderTarget::devicePixelRatio() const
return d.dpr; return d.dpr;
} }
int QNullReferenceRenderTarget::sampleCount() const
{
return 1;
}
QNullTextureRenderTarget::QNullTextureRenderTarget(QRhiImplementation *rhi, QNullTextureRenderTarget::QNullTextureRenderTarget(QRhiImplementation *rhi,
const QRhiTextureRenderTargetDescription &desc, const QRhiTextureRenderTargetDescription &desc,
Flags flags) Flags flags)
...@@ -519,6 +524,11 @@ float QNullTextureRenderTarget::devicePixelRatio() const ...@@ -519,6 +524,11 @@ float QNullTextureRenderTarget::devicePixelRatio() const
return d.dpr; return d.dpr;
} }
int QNullTextureRenderTarget::sampleCount() const
{
return 1;
}
QNullShaderResourceBindings::QNullShaderResourceBindings(QRhiImplementation *rhi) QNullShaderResourceBindings::QNullShaderResourceBindings(QRhiImplementation *rhi)
: QRhiShaderResourceBindings(rhi) : QRhiShaderResourceBindings(rhi)
{ {
......
...@@ -101,9 +101,11 @@ struct QNullReferenceRenderTarget : public QRhiRenderTarget ...@@ -101,9 +101,11 @@ struct QNullReferenceRenderTarget : public QRhiRenderTarget
{ {
QNullReferenceRenderTarget(QRhiImplementation *rhi); QNullReferenceRenderTarget(QRhiImplementation *rhi);
void release() override; void release() override;
Type type() const override; Type type() const override;
QSize sizeInPixels() const override; QSize sizeInPixels() const override;
float devicePixelRatio() const override; float devicePixelRatio() const override;
int sampleCount() const override;
QNullRenderTargetData d; QNullRenderTargetData d;
}; };
...@@ -116,6 +118,7 @@ struct QNullTextureRenderTarget : public QRhiTextureRenderTarget ...@@ -116,6 +118,7 @@ struct QNullTextureRenderTarget : public QRhiTextureRenderTarget
Type type() const override; Type type() const override;
QSize sizeInPixels() const override; QSize sizeInPixels() const override;
float devicePixelRatio() const override; float devicePixelRatio() const override;
int sampleCount() const override;
QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override; QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override;
bool build() override; bool build() override;
......
...@@ -1392,6 +1392,7 @@ QRhi::FrameOpResult QRhiVulkan::beginWrapperFrame(QRhiSwapChain *swapChain) ...@@ -1392,6 +1392,7 @@ QRhi::FrameOpResult QRhiVulkan::beginWrapperFrame(QRhiSwapChain *swapChain)
swapChainD->rtWrapper.d.fb = w->currentFramebuffer(); swapChainD->rtWrapper.d.fb = w->currentFramebuffer();
swapChainD->m_currentPixelSize = swapChainD->pixelSize = swapChainD->rtWrapper.d.pixelSize = w->swapChainImageSize(); swapChainD->m_currentPixelSize = swapChainD->pixelSize = swapChainD->rtWrapper.d.pixelSize = w->swapChainImageSize();
swapChainD->rtWrapper.d.dpr = w->devicePixelRatio(); swapChainD->rtWrapper.d.dpr = w->devicePixelRatio();
swapChainD->rtWrapper.d.sampleCount = w->sampleCountFlagBits();
currentFrameSlot = w->currentFrame(); currentFrameSlot = w->currentFrame();
currentSwapChain = swapChainD; currentSwapChain = swapChainD;
...@@ -4210,6 +4211,11 @@ float QVkReferenceRenderTarget::devicePixelRatio() const ...@@ -4210,6 +4211,11 @@ float QVkReferenceRenderTarget::devicePixelRatio() const
return d.dpr; return d.dpr;
} }
int QVkReferenceRenderTarget::sampleCount() const
{
return d.sampleCount;
}
QVkTextureRenderTarget::QVkTextureRenderTarget(QRhiImplementation *rhi, QVkTextureRenderTarget::QVkTextureRenderTarget(QRhiImplementation *rhi,
const QRhiTextureRenderTargetDescription &desc, const QRhiTextureRenderTargetDescription &desc,
Flags flags) Flags flags)
...@@ -4309,26 +4315,38 @@ bool QVkTextureRenderTarget::build() ...@@ -4309,26 +4315,38 @@ bool QVkTextureRenderTarget::build()
return false; return false;
} }
views.append(rtv[i]); views.append(rtv[i]);
if (i == 0) if (i == 0) {
d.pixelSize = texD->pixelSize(); d.pixelSize = texD->pixelSize();
d.sampleCount = texD->samples;
}
} else if (rbD) { } else if (rbD) {
Q_ASSERT(rbD->backingTexture); Q_ASSERT(rbD->backingTexture);
views.append(rbD->backingTexture->imageView); views.append(rbD->backingTexture->imageView);
if (i == 0) if (i == 0) {
d.pixelSize = rbD->pixelSize(); d.pixelSize = rbD->pixelSize();
} else { d.sampleCount = rbD->samples;
Q_UNREACHABLE(); }
} }
} }
d.dpr = 1; d.dpr = 1;
if (hasDepthStencil) { if (hasDepthStencil) {
if (m_desc.depthTexture()) {
QVkTexture *depthTexD = QRHI_RES(QVkTexture, m_desc.depthTexture());
views.append(depthTexD->imageView);
if (d.colorAttCount == 0) {
d.pixelSize = depthTexD->pixelSize();
d.sampleCount = depthTexD->samples;
}
} else {
QVkRenderBuffer *depthRbD = QRHI_RES(QVkRenderBuffer, m_desc.depthStencilBuffer());
views.append(depthRbD->imageView);
if (d.colorAttCount == 0) {
d.pixelSize = depthRbD->pixelSize();
d.sampleCount = depthRbD->samples;
}
}
d.dsAttCount = 1; d.dsAttCount = 1;
views.append(m_desc.depthTexture() ? QRHI_RES(QVkTexture, m_desc.depthTexture())->imageView
: QRHI_RES(QVkRenderBuffer, m_desc.depthStencilBuffer())->imageView);
if (d.colorAttCount == 0)
d.pixelSize = m_desc.depthTexture() ? m_desc.depthTexture()->pixelSize() : m_desc.depthStencilBuffer()->pixelSize();
} else { } else {
d.dsAttCount = 0; d.dsAttCount = 0;
} }
...@@ -4405,6 +4423,11 @@ float QVkTextureRenderTarget::devicePixelRatio() const ...@@ -4405,6 +4423,11 @@ float QVkTextureRenderTarget::devicePixelRatio() const
return d.dpr; return d.dpr;
} }
int QVkTextureRenderTarget::sampleCount() const
{
return d.sampleCount;
}
QVkShaderResourceBindings::QVkShaderResourceBindings(QRhiImplementation *rhi) QVkShaderResourceBindings::QVkShaderResourceBindings(QRhiImplementation *rhi)
: QRhiShaderResourceBindings(rhi) : QRhiShaderResourceBindings(rhi)
{ {
...@@ -4918,6 +4941,7 @@ bool QVkSwapChain::buildOrResize() ...@@ -4918,6 +4941,7 @@ bool QVkSwapChain::buildOrResize()
Q_ASSERT(rtWrapper.d.rp && rtWrapper.d.rp->rp); Q_ASSERT(rtWrapper.d.rp && rtWrapper.d.rp->rp);
m_currentPixelSize = pixelSize = rtWrapper.d.pixelSize = vkw->swapChainImageSize(); m_currentPixelSize = pixelSize = rtWrapper.d.pixelSize = vkw->swapChainImageSize();
rtWrapper.d.dpr = vkw->devicePixelRatio(); rtWrapper.d.dpr = vkw->devicePixelRatio();
rtWrapper.d.sampleCount = vkw->sampleCountFlagBits();
rtWrapper.d.colorAttCount = 1; rtWrapper.d.colorAttCount = 1;
rtWrapper.d.dsAttCount = 1; rtWrapper.d.dsAttCount = 1;
rtWrapper.d.resolveAttCount = vkw->sampleCountFlagBits() > VK_SAMPLE_COUNT_1_BIT ? 1 : 0; rtWrapper.d.resolveAttCount = vkw->sampleCountFlagBits() > VK_SAMPLE_COUNT_1_BIT ? 1 : 0;
...@@ -4967,6 +4991,7 @@ bool QVkSwapChain::buildOrResize() ...@@ -4967,6 +4991,7 @@ bool QVkSwapChain::buildOrResize()
rtWrapper.d.pixelSize = pixelSize; rtWrapper.d.pixelSize = pixelSize;
rtWrapper.d.dpr = window->devicePixelRatio(); rtWrapper.d.dpr = window->devicePixelRatio();
rtWrapper.d.sampleCount = samples;
rtWrapper.d.colorAttCount = 1; rtWrapper.d.colorAttCount = 1;
if (m_depthStencil) { if (m_depthStencil) {
rtWrapper.d.dsAttCount = 1; rtWrapper.d.dsAttCount = 1;
......
...@@ -156,6 +156,7 @@ struct QVkRenderTargetData ...@@ -156,6 +156,7 @@ struct QVkRenderTargetData
QVkRenderPassDescriptor *rp = nullptr; QVkRenderPassDescriptor *rp = nullptr;
QSize pixelSize; QSize pixelSize;
float dpr = 1; float dpr = 1;
int sampleCount = 1;
int colorAttCount = 0; int colorAttCount = 0;
int dsAttCount = 0; int dsAttCount = 0;
int resolveAttCount = 0; int resolveAttCount = 0;
...@@ -166,9 +167,11 @@ struct QVkReferenceRenderTarget : public QRhiRenderTarget ...@@ -166,9 +167,11 @@ struct QVkReferenceRenderTarget : public QRhiRenderTarget
{ {
QVkReferenceRenderTarget(QRhiImplementation *rhi); QVkReferenceRenderTarget(QRhiImplementation *rhi);
void release() override; void release() override;
Type type() const override; Type type() const override;
QSize sizeInPixels() const override; QSize sizeInPixels() const override;
float devicePixelRatio() const override; float devicePixelRatio() const override;
int sampleCount() const override;
QVkRenderTargetData d; QVkRenderTargetData d;
}; };
...@@ -181,6 +184,7 @@ struct QVkTextureRenderTarget : public QRhiTextureRenderTarget ...@@ -181,6 +184,7 @@ struct QVkTextureRenderTarget : public QRhiTextureRenderTarget
Type type() const override; Type type() const override;
QSize sizeInPixels() const override; QSize sizeInPixels() const override;
float devicePixelRatio() const override; <