From c5387cfec227e0aa13cb01955838b9bf8ee1cce9 Mon Sep 17 00:00:00 2001 From: Seremo <48060122+Seremo@users.noreply.github.com> Date: Thu, 22 Jan 2026 19:34:12 +0100 Subject: [PATCH] DX11/DX12: Fix detecting depth capabilities for BGFX_CAPS_FORMAT_TEXTURE_MSAA (#3562) --- src/renderer_d3d11.cpp | 27 ++++++++++++++++++++++++++- src/renderer_d3d12.cpp | 27 ++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 50068dd64..5c3f70ba4 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -1372,7 +1372,8 @@ namespace bgfx { namespace d3d11 { uint16_t support = BGFX_CAPS_FORMAT_TEXTURE_NONE; - const DXGI_FORMAT fmt = bimg::isDepth(bimg::TextureFormat::Enum(ii) ) + const bool isDepthFormat = bimg::isDepth(bimg::TextureFormat::Enum(ii)); + const DXGI_FORMAT fmt = isDepthFormat ? s_textureFormat[ii].m_fmtDsv : s_textureFormat[ii].m_fmt ; @@ -1464,6 +1465,30 @@ namespace bgfx { namespace d3d11 ); } + if (isDepthFormat) + { + const DXGI_FORMAT fmtDepthSampling = s_textureFormat[ii].m_fmtSrv; + if (DXGI_FORMAT_UNKNOWN != fmtDepthSampling) + { + D3D11_FEATURE_DATA_FORMAT_SUPPORT dataSampling; + dataSampling.InFormat = fmtDepthSampling; + hr = m_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT, &dataSampling, sizeof(dataSampling)); + if (SUCCEEDED(hr)) + { + support |= 0 != (dataSampling.OutFormatSupport & (0 + | D3D11_FORMAT_SUPPORT_MULTISAMPLE_LOAD + )) + ? BGFX_CAPS_FORMAT_TEXTURE_MSAA + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + } + else + { + BX_TRACE("CheckFeatureSupport depth srv failed with %x for format %s.", hr, getName(TextureFormat::Enum(ii))); + } + } + } + if (0 != (support & BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ) ) { D3D11_FEATURE_DATA_FORMAT_SUPPORT2 data2; diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index d281eda21..050a10ab2 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -1641,7 +1641,8 @@ namespace bgfx { namespace d3d12 { uint16_t support = BGFX_CAPS_FORMAT_TEXTURE_NONE; - const DXGI_FORMAT fmt = bimg::isDepth(bimg::TextureFormat::Enum(ii) ) + const bool isDepthFormat = bimg::isDepth(bimg::TextureFormat::Enum(ii)); + const DXGI_FORMAT fmt = isDepthFormat ? s_textureFormat[ii].m_fmtDsv : s_textureFormat[ii].m_fmt ; @@ -1718,6 +1719,30 @@ namespace bgfx { namespace d3d12 BX_TRACE("CheckFeatureSupport failed with %x for format %s.", hr, getName(TextureFormat::Enum(ii) ) ); } + if (isDepthFormat) + { + const DXGI_FORMAT fmtDepthSampling = s_textureFormat[ii].m_fmtSrv; + if (DXGI_FORMAT_UNKNOWN != fmtDepthSampling) + { + D3D12_FEATURE_DATA_FORMAT_SUPPORT dataSampling; + dataSampling.Format = fmtDepthSampling; + hr = m_device->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &dataSampling, sizeof(dataSampling)); + if (SUCCEEDED(hr)) + { + support |= 0 != (dataSampling.Support1 & (0 + | D3D12_FORMAT_SUPPORT1_MULTISAMPLE_LOAD + )) + ? BGFX_CAPS_FORMAT_TEXTURE_MSAA + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + } + else + { + BX_TRACE("CheckFeatureSupport depth srv failed with %x for format %s.", hr, getName(TextureFormat::Enum(ii))); + } + } + } + if (0 != (support & BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ) ) { // clear image flag for additional testing