From c63a7e3ba7c0f567945a7df0e3c528d74bb0de5c Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 11 Jun 2024 13:44:39 +0200 Subject: [PATCH] rhi: Add D32FS8 This is commonly supported in the desktop world, more commonly than D24S8. (which AMD does not like for instance) Change-Id: I43104bd9dbf28159fd8a806ff44ad5d094bdd599 Reviewed-by: Andy Nichols --- src/gui/rhi/qrhi.cpp | 8 ++++++++ src/gui/rhi/qrhi.h | 1 + src/gui/rhi/qrhid3d11.cpp | 7 +++++++ src/gui/rhi/qrhid3d12.cpp | 7 +++++++ src/gui/rhi/qrhigles2.cpp | 15 +++++++++++++++ src/gui/rhi/qrhimetal.mm | 2 ++ src/gui/rhi/qrhivulkan.cpp | 3 +++ 7 files changed, 43 insertions(+) diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index a39709c7263..8a2e150b1bb 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -4362,6 +4362,9 @@ bool QRhiRenderBuffer::createFrom(NativeRenderBuffer src) \value D32F 32-bit depth (32-bit float) + \value D32FS8 32-bit depth (32-bit float), 8 bits of stencil, 24 bits unused + (64 bits total) This enum value is introduced in Qt 6.9. + \value BC1 \value BC2 \value BC3 @@ -8240,6 +8243,10 @@ void QRhiImplementation::textureFormatInfo(QRhiTexture::Format format, const QSi bpc = 4; break; + case QRhiTexture::D32FS8: + bpc = 8; + break; + default: Q_UNREACHABLE(); break; @@ -8257,6 +8264,7 @@ bool QRhiImplementation::isStencilSupportingFormat(QRhiTexture::Format format) c { switch (format) { case QRhiTexture::D24S8: + case QRhiTexture::D32FS8: return true; default: break; diff --git a/src/gui/rhi/qrhi.h b/src/gui/rhi/qrhi.h index d20b7e00d1c..5ee8c736799 100644 --- a/src/gui/rhi/qrhi.h +++ b/src/gui/rhi/qrhi.h @@ -933,6 +933,7 @@ public: D24, D24S8, D32F, + D32FS8, BC1, BC2, diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index b09baf57b26..5dd32611cde 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -1555,6 +1555,8 @@ static inline DXGI_FORMAT toD3DTextureFormat(QRhiTexture::Format format, QRhiTex return DXGI_FORMAT_R24G8_TYPELESS; case QRhiTexture::D32F: return DXGI_FORMAT_R32_TYPELESS; + case QRhiTexture::D32FS8: + return DXGI_FORMAT_R32G8X24_TYPELESS; case QRhiTexture::BC1: return srgb ? DXGI_FORMAT_BC1_UNORM_SRGB : DXGI_FORMAT_BC1_UNORM; @@ -1635,6 +1637,7 @@ static inline bool isDepthTextureFormat(QRhiTexture::Format format) case QRhiTexture::Format::D24: case QRhiTexture::Format::D24S8: case QRhiTexture::Format::D32F: + case QRhiTexture::Format::D32FS8: return true; default: @@ -3255,6 +3258,8 @@ static inline DXGI_FORMAT toD3DDepthTextureSRVFormat(QRhiTexture::Format format) return DXGI_FORMAT_R24_UNORM_X8_TYPELESS; case QRhiTexture::Format::D32F: return DXGI_FORMAT_R32_FLOAT; + case QRhiTexture::Format::D32FS8: + return DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS; default: Q_UNREACHABLE(); return DXGI_FORMAT_R32_FLOAT; @@ -3272,6 +3277,8 @@ static inline DXGI_FORMAT toD3DDepthTextureDSVFormat(QRhiTexture::Format format) return DXGI_FORMAT_D24_UNORM_S8_UINT; case QRhiTexture::Format::D32F: return DXGI_FORMAT_D32_FLOAT; + case QRhiTexture::Format::D32FS8: + return DXGI_FORMAT_D32_FLOAT_S8X24_UINT; default: Q_UNREACHABLE(); return DXGI_FORMAT_D32_FLOAT; diff --git a/src/gui/rhi/qrhid3d12.cpp b/src/gui/rhi/qrhid3d12.cpp index 0f176c683dc..d5f8082a1fd 100644 --- a/src/gui/rhi/qrhid3d12.cpp +++ b/src/gui/rhi/qrhid3d12.cpp @@ -3894,6 +3894,8 @@ static inline DXGI_FORMAT toD3DTextureFormat(QRhiTexture::Format format, QRhiTex return DXGI_FORMAT_R24G8_TYPELESS; case QRhiTexture::D32F: return DXGI_FORMAT_R32_TYPELESS; + case QRhiTexture::Format::D32FS8: + return DXGI_FORMAT_R32G8X24_TYPELESS; case QRhiTexture::BC1: return srgb ? DXGI_FORMAT_BC1_UNORM_SRGB : DXGI_FORMAT_BC1_UNORM; @@ -4131,6 +4133,8 @@ static inline DXGI_FORMAT toD3DDepthTextureSRVFormat(QRhiTexture::Format format) return DXGI_FORMAT_R24_UNORM_X8_TYPELESS; case QRhiTexture::Format::D32F: return DXGI_FORMAT_R32_FLOAT; + case QRhiTexture::Format::D32FS8: + return DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS; default: break; } @@ -4149,6 +4153,8 @@ static inline DXGI_FORMAT toD3DDepthTextureDSVFormat(QRhiTexture::Format format) return DXGI_FORMAT_D24_UNORM_S8_UINT; case QRhiTexture::Format::D32F: return DXGI_FORMAT_D32_FLOAT; + case QRhiTexture::Format::D32FS8: + return DXGI_FORMAT_D32_FLOAT_S8X24_UINT; default: break; } @@ -4162,6 +4168,7 @@ static inline bool isDepthTextureFormat(QRhiTexture::Format format) case QRhiTexture::Format::D24: case QRhiTexture::Format::D24S8: case QRhiTexture::Format::D32F: + case QRhiTexture::Format::D32FS8: return true; default: return false; diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 7e886a5d002..4f1aceea487 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -216,6 +216,14 @@ QT_BEGIN_NAMESPACE #define GL_DEPTH_COMPONENT32F 0x8CAC #endif +#ifndef GL_DEPTH32F_STENCIL8 +#define GL_DEPTH32F_STENCIL8 0x8CAD +#endif + +#ifndef GL_FLOAT_32_UNSIGNED_INT_24_8_REV +#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD +#endif + #ifndef GL_UNSIGNED_INT_24_8 #define GL_UNSIGNED_INT_24_8 0x84FA #endif @@ -1313,6 +1321,12 @@ static inline void toGlTextureFormat(QRhiTexture::Format format, const QRhiGles2 *glformat = GL_DEPTH_COMPONENT; *gltype = GL_FLOAT; break; + case QRhiTexture::D32FS8: + *glintformat = GL_DEPTH32F_STENCIL8; + *glsizedintformat = *glintformat; + *glformat = GL_DEPTH_STENCIL; + *gltype = GL_FLOAT_32_UNSIGNED_INT_24_8_REV; + break; default: Q_UNREACHABLE(); *glintformat = GL_RGBA; @@ -1331,6 +1345,7 @@ bool QRhiGles2::isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture switch (format) { case QRhiTexture::D16: case QRhiTexture::D32F: + case QRhiTexture::D32FS8: return caps.depthTexture; case QRhiTexture::D24: diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index 887d40c7a59..659149b080f 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -3460,6 +3460,8 @@ static inline MTLPixelFormat toMetalTextureFormat(QRhiTexture::Format format, QR #endif case QRhiTexture::D32F: return MTLPixelFormatDepth32Float; + case QRhiTexture::D32FS8: + return MTLPixelFormatDepth32Float_Stencil8; #ifdef Q_OS_MACOS case QRhiTexture::BC1: diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index 3dd3c57bd46..36bbd989cf4 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -1072,6 +1072,8 @@ static inline VkFormat toVkTextureFormat(QRhiTexture::Format format, QRhiTexture return VK_FORMAT_D24_UNORM_S8_UINT; case QRhiTexture::D32F: return VK_FORMAT_D32_SFLOAT; + case QRhiTexture::D32FS8: + return VK_FORMAT_D32_SFLOAT_S8_UINT; case QRhiTexture::BC1: return srgb ? VK_FORMAT_BC1_RGB_SRGB_BLOCK : VK_FORMAT_BC1_RGB_UNORM_BLOCK; @@ -1164,6 +1166,7 @@ static constexpr inline bool isDepthTextureFormat(QRhiTexture::Format format) case QRhiTexture::Format::D24: case QRhiTexture::Format::D24S8: case QRhiTexture::Format::D32F: + case QRhiTexture::Format::D32FS8: return true; default: