From 38e818cfd1ef7da85b430e49a37e7a8d701d908e Mon Sep 17 00:00:00 2001 From: Allen Pestaluky Date: Tue, 5 Aug 2025 11:43:23 -0400 Subject: [PATCH] Fix issue where HDR support is not correctly reported for multi-adapter setups. --- Samples/Desktop/D3D12HDR/src/D3D12HDR.cpp | 70 ++++++++++++----------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/Samples/Desktop/D3D12HDR/src/D3D12HDR.cpp b/Samples/Desktop/D3D12HDR/src/D3D12HDR.cpp index ce1643afb..bc3fd7a9f 100644 --- a/Samples/Desktop/D3D12HDR/src/D3D12HDR.cpp +++ b/Samples/Desktop/D3D12HDR/src/D3D12HDR.cpp @@ -1071,46 +1071,48 @@ void D3D12HDR::CheckDisplayHDRSupport() // intersection with the app window bounds. Then, use the DXGI output found in previous step to determine if the // app is on a HDR capable display. - // Retrieve the current default adapter. - ComPtr dxgiAdapter; - ThrowIfFailed(m_dxgiFactory->EnumAdapters1(0, &dxgiAdapter)); - - // Iterate through the DXGI outputs associated with the DXGI adapter, - // and find the output whose bounds have the greatest overlap with the - // app window (i.e. the output for which the intersection area is the - // greatest). - - UINT i = 0; + UINT adapterI = 0; ComPtr currentOutput; ComPtr bestOutput; float bestIntersectArea = -1; - while (dxgiAdapter->EnumOutputs(i, ¤tOutput) != DXGI_ERROR_NOT_FOUND) - { - // Get the retangle bounds of the app window - int ax1 = m_windowBounds.left; - int ay1 = m_windowBounds.top; - int ax2 = m_windowBounds.right; - int ay2 = m_windowBounds.bottom; - - // Get the rectangle bounds of current output - DXGI_OUTPUT_DESC desc; - ThrowIfFailed(currentOutput->GetDesc(&desc)); - RECT r = desc.DesktopCoordinates; - int bx1 = r.left; - int by1 = r.top; - int bx2 = r.right; - int by2 = r.bottom; - - // Compute the intersection - int intersectArea = ComputeIntersectionArea(ax1, ay1, ax2, ay2, bx1, by1, bx2, by2); - if (intersectArea > bestIntersectArea) + // Iterate through all adapters + ComPtr dxgiAdapter; + while (SUCCEEDED(m_dxgiFactory->EnumAdapters1(adapterI, &dxgiAdapter))) { + // Iterate through the DXGI outputs associated with the DXGI adapter, + // and find the output whose bounds have the greatest overlap with the + // app window (i.e. the output for which the intersection area is the + // greatest). + + UINT outputI = 0; + while (dxgiAdapter->EnumOutputs(outputI, ¤tOutput) != DXGI_ERROR_NOT_FOUND) { - bestOutput = currentOutput; - bestIntersectArea = static_cast(intersectArea); - } + // Get the retangle bounds of the app window + int ax1 = m_windowBounds.left; + int ay1 = m_windowBounds.top; + int ax2 = m_windowBounds.right; + int ay2 = m_windowBounds.bottom; + + // Get the rectangle bounds of current output + DXGI_OUTPUT_DESC desc; + ThrowIfFailed(currentOutput->GetDesc(&desc)); + RECT r = desc.DesktopCoordinates; + int bx1 = r.left; + int by1 = r.top; + int bx2 = r.right; + int by2 = r.bottom; + + // Compute the intersection + int intersectArea = ComputeIntersectionArea(ax1, ay1, ax2, ay2, bx1, by1, bx2, by2); + if (intersectArea > bestIntersectArea) + { + bestOutput = currentOutput; + bestIntersectArea = static_cast(intersectArea); + } - i++; + outputI++; + } + adapterI++; } // Having determined the output (display) upon which the app is primarily being