diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index c0fe6ec6f5..3faae39a42 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 851b0462ad..b9bb580357 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) {