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 <andy.nichols@qt.io>
(cherry picked from commit 2bfa2d6b21e807dcf375a82e10c40616e7e475ce)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Laszlo Agocs 2024-10-16 12:24:06 +02:00 committed by Qt Cherry-pick Bot
parent 00d3afe4ff
commit 565e3aaf8b
2 changed files with 8 additions and 2 deletions

View File

@ -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);

View File

@ -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) {