rhi: gl: metal: Enable depth-stencil correctly with multiview

After fixing the data type for D24S8, we can now implement attaching
depth and stencil (with the same texture).

For Metal we need to set a stencil flag correctly.

This allows using D24S8 in the manual test, which is likely the format
that is going to be commonly used when setting up multiview with
Qt Quick.

Fixes: QTBUG-114904
Change-Id: Ife425c6cb3e09bfe40092c841b78f7a93bb6a4cd
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
This commit is contained in:
Laszlo Agocs 2023-06-27 15:47:48 +02:00
parent 409cd2be18
commit 277de5ca4b
5 changed files with 23 additions and 2 deletions

View File

@ -7926,6 +7926,17 @@ void QRhiImplementation::textureFormatInfo(QRhiTexture::Format format, const QSi
*bytesPerPixel = bpc;
}
bool QRhiImplementation::isStencilSupportingFormat(QRhiTexture::Format format) const
{
switch (format) {
case QRhiTexture::D24S8:
return true;
default:
break;
}
return false;
}
bool QRhiImplementation::sanityCheckGraphicsPipeline(QRhiGraphicsPipeline *ps)
{
if (ps->cbeginShaderStages() == ps->cendShaderStages()) {

View File

@ -149,6 +149,7 @@ public:
QSize *blockDim) const;
void textureFormatInfo(QRhiTexture::Format format, const QSize &size,
quint32 *bpl, quint32 *byteSize, quint32 *bytesPerPixel) const;
bool isStencilSupportingFormat(QRhiTexture::Format format) const;
void registerResource(QRhiResource *res, bool ownsNativeResources = true)
{

View File

@ -5706,8 +5706,17 @@ bool QGles2TextureRenderTarget::create()
rhiD->f->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthTexD->target,
depthTexD->texture, 0);
} else {
// This path is OpenGL (ES) 3.0+ and specific to multiview, so
// needsDepthStencilCombinedAttach is not a thing. The depth
// texture here must be an array with at least multiViewCount
// elements, and the format should be D24 or D32F for depth
// only, or D24S8 for depth and stencil.
rhiD->glFramebufferTextureMultiviewOVR(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthTexD->texture,
0, 0, multiViewCount);
if (rhiD->isStencilSupportingFormat(depthTexD->format())) {
rhiD->glFramebufferTextureMultiviewOVR(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, depthTexD->texture,
0, 0, multiViewCount);
}
}
if (d.colorAttCount == 0) {
d.pixelSize = depthTexD->pixelSize();

View File

@ -4209,7 +4209,7 @@ bool QMetalTextureRenderTarget::create()
if (m_desc.depthTexture()) {
QMetalTexture *depthTexD = QRHI_RES(QMetalTexture, m_desc.depthTexture());
d->fb.dsTex = depthTexD->d->tex;
d->fb.hasStencil = false;
d->fb.hasStencil = rhiD->isStencilSupportingFormat(depthTexD->format());
d->fb.depthNeedsStore = true;
if (d->colorAttCount == 0) {
d->pixelSize = depthTexD->pixelSize();

View File

@ -96,7 +96,7 @@ void Window::customInit()
// rendered with depth test/write enabled. The catch here is that we must
// use a texture array for depth/stencil as well, so QRhiRenderBuffer is
// not an option anymore.
d.ds = m_r->newTextureArray(QRhiTexture::D24, 2, QSize(512, 512), sampleCount, QRhiTexture::RenderTarget);
d.ds = m_r->newTextureArray(QRhiTexture::D24S8, 2, QSize(512, 512), sampleCount, QRhiTexture::RenderTarget);
d.releasePool << d.ds;
d.ds->create();