summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2023-06-27 15:47:48 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2023-06-28 15:18:28 +0200
commit277de5ca4b0c147846bb9db7613a920427fcce79 (patch)
treeb9e34763956f00d841aaa2a68952c4ddb154fcb3
parent409cd2be188af6ace294f46276c69a7aab87fcb1 (diff)
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>
-rw-r--r--src/gui/rhi/qrhi.cpp11
-rw-r--r--src/gui/rhi/qrhi_p.h1
-rw-r--r--src/gui/rhi/qrhigles2.cpp9
-rw-r--r--src/gui/rhi/qrhimetal.mm2
-rw-r--r--tests/manual/rhi/multiview/multiview.cpp2
5 files changed, 23 insertions, 2 deletions
diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp
index e5aa36817a..c0214debdf 100644
--- a/src/gui/rhi/qrhi.cpp
+++ b/src/gui/rhi/qrhi.cpp
@@ -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()) {
diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h
index 05df169a35..0a0e5e4d37 100644
--- a/src/gui/rhi/qrhi_p.h
+++ b/src/gui/rhi/qrhi_p.h
@@ -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)
{
diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp
index 0355345f07..0d820c00ab 100644
--- a/src/gui/rhi/qrhigles2.cpp
+++ b/src/gui/rhi/qrhigles2.cpp
@@ -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();
diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm
index 1d0e84f871..345494c9f6 100644
--- a/src/gui/rhi/qrhimetal.mm
+++ b/src/gui/rhi/qrhimetal.mm
@@ -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();
diff --git a/tests/manual/rhi/multiview/multiview.cpp b/tests/manual/rhi/multiview/multiview.cpp
index 203bc2b668..1ade109d1c 100644
--- a/tests/manual/rhi/multiview/multiview.cpp
+++ b/tests/manual/rhi/multiview/multiview.cpp
@@ -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();