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:
virtual Type type() const = 0;
virtual QSize sizeInPixels() const = 0;
virtual float devicePixelRatio() const = 0;
virtual int sampleCount() const = 0;
QRhiRenderPassDescriptor *renderPassDescriptor() const { return m_renderPassDesc; }
void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
......
......@@ -1898,7 +1898,8 @@ bool QD3D11RenderBuffer::build()
}
D3D11_RENDER_TARGET_VIEW_DESC 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;
hr = rhiD->dev->CreateRenderTargetView(tex, &rtvDesc, &rtv);
if (FAILED(hr)) {
......@@ -2283,6 +2284,11 @@ float QD3D11ReferenceRenderTarget::devicePixelRatio() const
return d.dpr;
}
int QD3D11ReferenceRenderTarget::sampleCount() const
{
return d.sampleCount;
}
QD3D11TextureRenderTarget::QD3D11TextureRenderTarget(QRhiImplementation *rhi,
const QRhiTextureRenderTargetDescription &desc,
Flags flags)
......@@ -2365,16 +2371,18 @@ bool QD3D11TextureRenderTarget::build()
return false;
}
ownsRtv[i] = true;
if (i == 0)
if (i == 0) {
d.pixelSize = texD->pixelSize();
d.sampleCount = texD->sampleDesc.Count;
}
} else if (rb) {
QD3D11RenderBuffer *rbD = QRHI_RES(QD3D11RenderBuffer, rb);
ownsRtv[i] = false;
rtv[i] = rbD->rtv;
if (i == 0)
if (i == 0) {
d.pixelSize = rbD->pixelSize();
} else {
Q_UNREACHABLE();
d.sampleCount = rbD->sampleDesc.Count;
}
}
}
d.dpr = 1;
......@@ -2393,13 +2401,18 @@ bool QD3D11TextureRenderTarget::build()
qWarning("Failed to create dsv: %s", qPrintable(comErrorMessage(hr)));
return false;
}
if (d.colorAttCount == 0)
if (d.colorAttCount == 0) {
d.pixelSize = depthTexD->pixelSize();
d.sampleCount = depthTexD->sampleDesc.Count;
}
} else {
ownsDsv = false;
dsv = QRHI_RES(QD3D11RenderBuffer, m_desc.depthStencilBuffer())->dsv;
if (d.colorAttCount == 0)
QD3D11RenderBuffer *depthRbD = QRHI_RES(QD3D11RenderBuffer, m_desc.depthStencilBuffer());
dsv = depthRbD->dsv;
if (d.colorAttCount == 0) {
d.pixelSize = m_desc.depthStencilBuffer()->pixelSize();
d.sampleCount = depthRbD->sampleDesc.Count;
}
}
d.dsAttCount = 1;
} else {
......@@ -2431,6 +2444,11 @@ float QD3D11TextureRenderTarget::devicePixelRatio() const
return d.dpr;
}
int QD3D11TextureRenderTarget::sampleCount() const
{
return d.sampleCount;
}
QD3D11ShaderResourceBindings::QD3D11ShaderResourceBindings(QRhiImplementation *rhi)
: QRhiShaderResourceBindings(rhi)
{
......@@ -3133,6 +3151,7 @@ bool QD3D11SwapChain::buildOrResize()
rtD->d.rp = QRHI_RES(QD3D11RenderPassDescriptor, m_renderPassDesc);
rtD->d.pixelSize = pixelSize;
rtD->d.dpr = window->devicePixelRatio();
rtD->d.sampleCount = sampleDesc.Count;
rtD->d.colorAttCount = 1;
rtD->d.dsAttCount = m_depthStencil ? 1 : 0;
......
......@@ -132,6 +132,7 @@ struct QD3D11RenderTargetData
QD3D11RenderPassDescriptor *rp = nullptr;
QSize pixelSize;
float dpr = 1;
int sampleCount = 1;
int colorAttCount = 0;
int dsAttCount = 0;
......@@ -144,9 +145,11 @@ struct QD3D11ReferenceRenderTarget : public QRhiRenderTarget
{
QD3D11ReferenceRenderTarget(QRhiImplementation *rhi);
void release() override;
Type type() const override;
QSize sizeInPixels() const override;
float devicePixelRatio() const override;
int sampleCount() const override;
QD3D11RenderTargetData d;
};
......@@ -159,6 +162,7 @@ struct QD3D11TextureRenderTarget : public QRhiTextureRenderTarget
Type type() const override;
QSize sizeInPixels() const override;
float devicePixelRatio() const override;
int sampleCount() const override;
QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override;
bool build() override;
......
......@@ -2239,6 +2239,11 @@ float QGles2ReferenceRenderTarget::devicePixelRatio() const
return d.dpr;
}
int QGles2ReferenceRenderTarget::sampleCount() const
{
return d.sampleCount;
}
QGles2TextureRenderTarget::QGles2TextureRenderTarget(QRhiImplementation *rhi,
const QRhiTextureRenderTargetDescription &desc,
Flags flags)
......@@ -2306,10 +2311,12 @@ bool QGles2TextureRenderTarget::build()
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());
d.pixelSize = texD->pixelSize();
} else {
d.sampleCount = 1;
} else if (renderBuffer) {
QGles2RenderBuffer *rbD = QRHI_RES(QGles2RenderBuffer, renderBuffer);
rhiD->f->glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbD->renderbuffer);
d.pixelSize = rbD->pixelSize();
d.sampleCount = rbD->samples;
}
d.dpr = 1;
......@@ -2345,6 +2352,11 @@ float QGles2TextureRenderTarget::devicePixelRatio() const
return d.dpr;
}
int QGles2TextureRenderTarget::sampleCount() const
{
return d.sampleCount;
}
QGles2ShaderResourceBindings::QGles2ShaderResourceBindings(QRhiImplementation *rhi)
: QRhiShaderResourceBindings(rhi)
{
......@@ -2587,6 +2599,7 @@ bool QGles2SwapChain::buildOrResize()
rt.d.rp = QRHI_RES(QGles2RenderPassDescriptor, m_renderPassDesc);
rt.d.pixelSize = pixelSize;
rt.d.dpr = m_window->devicePixelRatio();
rt.d.sampleCount = qBound(1, m_sampleCount, 64);
rt.d.attCount = m_depthStencil ? 2 : 1;
rt.d.srgbUpdateAndBlend = m_flags.testFlag(QRhiSwapChain::sRGB);
......
......@@ -131,6 +131,7 @@ struct QGles2RenderTargetData
QGles2RenderPassDescriptor *rp = nullptr;
QSize pixelSize;
float dpr = 1;
int sampleCount = 1;
int attCount = 0;
bool srgbUpdateAndBlend = false;
};
......@@ -139,9 +140,11 @@ struct QGles2ReferenceRenderTarget : public QRhiRenderTarget
{
QGles2ReferenceRenderTarget(QRhiImplementation *rhi);
void release() override;
Type type() const override;
QSize sizeInPixels() const override;
float devicePixelRatio() const override;
int sampleCount() const override;
QGles2RenderTargetData d;
};
......@@ -154,6 +157,7 @@ struct QGles2TextureRenderTarget : public QRhiTextureRenderTarget
Type type() const override;
QSize sizeInPixels() const override;
float devicePixelRatio() const override;
int sampleCount() const override;
QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override;
bool build() override;
......
......@@ -227,6 +227,7 @@ struct QMetalRenderTargetData
{
QSize pixelSize;
float dpr = 1;
int sampleCount = 1;
int colorAttCount = 0;
int dsAttCount = 0;
......@@ -2238,6 +2239,11 @@ float QMetalReferenceRenderTarget::devicePixelRatio() const
return d->dpr;
}
int QMetalReferenceRenderTarget::sampleCount() const
{
return d->sampleCount;
}
QMetalTextureRenderTarget::QMetalTextureRenderTarget(QRhiImplementation *rhi,
const QRhiTextureRenderTargetDescription &desc,
Flags flags)
......@@ -2289,15 +2295,19 @@ bool QMetalTextureRenderTarget::build()
QMetalTexture *texD = QRHI_RES(QMetalTexture, colorAttachments[i].texture());
QMetalRenderBuffer *rbD = QRHI_RES(QMetalRenderBuffer, colorAttachments[i].renderBuffer());
Q_ASSERT(texD || rbD);
id<MTLTexture> dst;
id<MTLTexture> dst = nil;
if (texD) {
dst = texD->d->tex;
if (i == 0)
if (i == 0) {
d->pixelSize = texD->pixelSize();
} else {
d->sampleCount = texD->samples;
}
} else if (rbD) {
dst = rbD->d->tex;
if (i == 0)
if (i == 0) {
d->pixelSize = rbD->pixelSize();
d->sampleCount = rbD->samples;
}
}
QMetalRenderTargetData::ColorAtt colorAtt;
colorAtt.tex = dst;
......@@ -2313,15 +2323,21 @@ bool QMetalTextureRenderTarget::build()
if (hasDepthStencil) {
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;
if (d->colorAttCount == 0)
d->pixelSize = m_desc.depthTexture()->pixelSize();
if (d->colorAttCount == 0) {
d->pixelSize = depthTexD->pixelSize();
d->sampleCount = depthTexD->samples;
}
} 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;
if (d->colorAttCount == 0)
d->pixelSize = m_desc.depthStencilBuffer()->pixelSize();
if (d->colorAttCount == 0) {
d->pixelSize = depthRbD->pixelSize();
d->sampleCount = depthRbD->samples;
}
}
d->dsAttCount = 1;
} else {
......@@ -2346,6 +2362,11 @@ float QMetalTextureRenderTarget::devicePixelRatio() const
return d->dpr;
}
int QMetalTextureRenderTarget::sampleCount() const
{
return d->sampleCount;
}
QMetalShaderResourceBindings::QMetalShaderResourceBindings(QRhiImplementation *rhi)
: QRhiShaderResourceBindings(rhi)
{
......@@ -3057,6 +3078,7 @@ bool QMetalSwapChain::buildOrResize()
rtWrapper.d->pixelSize = pixelSize;
rtWrapper.d->dpr = window->devicePixelRatio();
rtWrapper.d->sampleCount = samples;
rtWrapper.d->colorAttCount = 1;
rtWrapper.d->dsAttCount = ds ? 1 : 0;
......
......@@ -152,6 +152,7 @@ struct QMetalReferenceRenderTarget : public QRhiRenderTarget
Type type() const override;
QSize sizeInPixels() const override;
float devicePixelRatio() const override;
int sampleCount() const override;
QMetalRenderTargetData *d;
};
......@@ -165,6 +166,7 @@ struct QMetalTextureRenderTarget : public QRhiTextureRenderTarget
Type type() const override;
QSize sizeInPixels() const override;
float devicePixelRatio() const override;
int sampleCount() const override;
QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override;
bool build() override;
......
......@@ -471,6 +471,11 @@ float QNullReferenceRenderTarget::devicePixelRatio() const
return d.dpr;
}
int QNullReferenceRenderTarget::sampleCount() const
{
return 1;
}
QNullTextureRenderTarget::QNullTextureRenderTarget(QRhiImplementation *rhi,
const QRhiTextureRenderTargetDescription &desc,
Flags flags)
......@@ -519,6 +524,11 @@ float QNullTextureRenderTarget::devicePixelRatio() const
return d.dpr;
}
int QNullTextureRenderTarget::sampleCount() const
{
return 1;
}
QNullShaderResourceBindings::QNullShaderResourceBindings(QRhiImplementation *rhi)
: QRhiShaderResourceBindings(rhi)
{
......
......@@ -101,9 +101,11 @@ struct QNullReferenceRenderTarget : public QRhiRenderTarget
{
QNullReferenceRenderTarget(QRhiImplementation *rhi);
void release() override;
Type type() const override;
QSize sizeInPixels() const override;
float devicePixelRatio() const override;
int sampleCount() const override;
QNullRenderTargetData d;
};
......@@ -116,6 +118,7 @@ struct QNullTextureRenderTarget : public QRhiTextureRenderTarget
Type type() const override;
QSize sizeInPixels() const override;
float devicePixelRatio() const override;
int sampleCount() const override;
QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override;
bool build() override;
......
......@@ -1392,6 +1392,7 @@ QRhi::FrameOpResult QRhiVulkan::beginWrapperFrame(QRhiSwapChain *swapChain)
swapChainD->rtWrapper.d.fb = w->currentFramebuffer();
swapChainD->m_currentPixelSize = swapChainD->pixelSize = swapChainD->rtWrapper.d.pixelSize = w->swapChainImageSize();
swapChainD->rtWrapper.d.dpr = w->devicePixelRatio();
swapChainD->rtWrapper.d.sampleCount = w->sampleCountFlagBits();
currentFrameSlot = w->currentFrame();
currentSwapChain = swapChainD;
......@@ -4210,6 +4211,11 @@ float QVkReferenceRenderTarget::devicePixelRatio() const
return d.dpr;
}
int QVkReferenceRenderTarget::sampleCount() const
{
return d.sampleCount;
}
QVkTextureRenderTarget::QVkTextureRenderTarget(QRhiImplementation *rhi,
const QRhiTextureRenderTargetDescription &desc,
Flags flags)
......@@ -4309,26 +4315,38 @@ bool QVkTextureRenderTarget::build()
return false;
}
views.append(rtv[i]);
if (i == 0)
if (i == 0) {
d.pixelSize = texD->pixelSize();
d.sampleCount = texD->samples;
}
} else if (rbD) {
Q_ASSERT(rbD->backingTexture);
views.append(rbD->backingTexture->imageView);
if (i == 0)
if (i == 0) {
d.pixelSize = rbD->pixelSize();
} else {
Q_UNREACHABLE();
d.sampleCount = rbD->samples;
}
}
}
d.dpr = 1;
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;
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 {
d.dsAttCount = 0;
}
......@@ -4405,6 +4423,11 @@ float QVkTextureRenderTarget::devicePixelRatio() const
return d.dpr;
}
int QVkTextureRenderTarget::sampleCount() const
{
return d.sampleCount;
}
QVkShaderResourceBindings::QVkShaderResourceBindings(QRhiImplementation *rhi)
: QRhiShaderResourceBindings(rhi)
{
......@@ -4918,6 +4941,7 @@ bool QVkSwapChain::buildOrResize()
Q_ASSERT(rtWrapper.d.rp && rtWrapper.d.rp->rp);
m_currentPixelSize = pixelSize = rtWrapper.d.pixelSize = vkw->swapChainImageSize();
rtWrapper.d.dpr = vkw->devicePixelRatio();
rtWrapper.d.sampleCount = vkw->sampleCountFlagBits();
rtWrapper.d.colorAttCount = 1;
rtWrapper.d.dsAttCount = 1;
rtWrapper.d.resolveAttCount = vkw->sampleCountFlagBits() > VK_SAMPLE_COUNT_1_BIT ? 1 : 0;
......@@ -4967,6 +4991,7 @@ bool QVkSwapChain::buildOrResize()
rtWrapper.d.pixelSize = pixelSize;
rtWrapper.d.dpr = window->devicePixelRatio();
rtWrapper.d.sampleCount = samples;
rtWrapper.d.colorAttCount = 1;
if (m_depthStencil) {
rtWrapper.d.dsAttCount = 1;
......
......@@ -156,6 +156,7 @@ struct QVkRenderTargetData
QVkRenderPassDescriptor *rp = nullptr;
QSize pixelSize;
float dpr = 1;
int sampleCount = 1;
int colorAttCount = 0;
int dsAttCount = 0;
int resolveAttCount = 0;
......@@ -166,9 +167,11 @@ struct QVkReferenceRenderTarget : public QRhiRenderTarget
{
QVkReferenceRenderTarget(QRhiImplementation *rhi);
void release() override;
Type type() const override;
QSize sizeInPixels() const override;
float devicePixelRatio() const override;
int sampleCount() const override;
QVkRenderTargetData d;
};
......@@ -181,6 +184,7 @@ struct QVkTextureRenderTarget : public QRhiTextureRenderTarget
Type type() const override;
QSize sizeInPixels() const override;
float devicePixelRatio() const override;
int sampleCount() const override;
QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override;
bool build() override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment