From 565e3aaf8b8fe1837a69b01d28c35bc14cd8d70d Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 16 Oct 2024 12:24:06 +0200 Subject: [PATCH] rhi: d3d: Bail out properly when texture format is not supported Have QRhiTexture::create() fail by returning false, as expected, when trying to create a texture with an unsupported compressed texture format (ASTC, ETC). Right now there are warnings, but create() does not indicate failure, and then Quick 3D apps almost certainly end up in a crash when they try to use ASTC textures. Change-Id: I09b4bb01b1655788d87a263b1b47ea8856c975cb Reviewed-by: Andy Nichols (cherry picked from commit 2bfa2d6b21e807dcf375a82e10c40616e7e475ce) Reviewed-by: Qt Cherry-pick Bot --- src/gui/rhi/qrhid3d11.cpp | 5 ++++- src/gui/rhi/qrhid3d12.cpp | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index c0fe6ec6f50..3faae39a42a 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -3301,6 +3301,10 @@ bool QD3D11Texture::prepareCreate(QSize *adjustedSize) if (tex || tex3D || tex1D) destroy(); + QRHI_RES_RHI(QRhiD3D11); + if (!rhiD->isTextureFormatSupported(m_format, m_flags)) + return false; + const bool isDepth = isDepthTextureFormat(m_format); const bool isCube = m_flags.testFlag(CubeMap); const bool is3D = m_flags.testFlag(ThreeDimensional); @@ -3311,7 +3315,6 @@ bool QD3D11Texture::prepareCreate(QSize *adjustedSize) const QSize size = is1D ? QSize(qMax(1, m_pixelSize.width()), 1) : (m_pixelSize.isEmpty() ? QSize(1, 1) : m_pixelSize); - QRHI_RES_RHI(QRhiD3D11); dxgiFormat = toD3DTextureFormat(m_format, m_flags); mipLevelCount = uint(hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1); sampleDesc = rhiD->effectiveSampleDesc(m_sampleCount); diff --git a/src/gui/rhi/qrhid3d12.cpp b/src/gui/rhi/qrhid3d12.cpp index 851b0462ad0..b9bb5803579 100644 --- a/src/gui/rhi/qrhid3d12.cpp +++ b/src/gui/rhi/qrhid3d12.cpp @@ -4184,6 +4184,10 @@ bool QD3D12Texture::prepareCreate(QSize *adjustedSize) if (!handle.isNull()) destroy(); + QRHI_RES_RHI(QRhiD3D12); + if (!rhiD->isTextureFormatSupported(m_format, m_flags)) + return false; + const bool isDepth = isDepthTextureFormat(m_format); const bool isCube = m_flags.testFlag(CubeMap); const bool is3D = m_flags.testFlag(ThreeDimensional); @@ -4215,7 +4219,6 @@ bool QD3D12Texture::prepareCreate(QSize *adjustedSize) srvFormat = toD3DTextureFormat(m_readViewFormat.format, m_readViewFormat.srgb ? sRGB : Flags()); } - QRHI_RES_RHI(QRhiD3D12); mipLevelCount = uint(hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1); sampleDesc = rhiD->effectiveSampleDesc(m_sampleCount, dxgiFormat); if (sampleDesc.Count > 1) {