77
88namespace Magpie {
99
10+ static bool IsHdrPresentation () noexcept {
11+ return ScalingWindow::Get ().Options ().captureMethod == CaptureMethod::GraphicsCaptureHDR;
12+ }
13+
1014static bool ShouldLogPresentationDiagnostic (uint32_t count) noexcept {
1115 return count <= 3 || count % 120 == 0 ;
1216}
1317
1418bool AdaptivePresenter::_Initialize (HWND hwndAttach) noexcept {
15- if (ScalingWindow::Get ().Options ().IsDirectFlipDisabled ()) {
19+ if (ScalingWindow::Get ().Options ().IsDirectFlipDisabled () && ! IsHdrPresentation () ) {
1620 // 禁用 DirectFlip 时始终使用 DirectComposition 呈现
1721 if (!_ResizeDCompVisual (hwndAttach)) {
1822 Logger::Get ().Error (" _ResizeDCompVisual 失败" );
@@ -29,7 +33,7 @@ bool AdaptivePresenter::_Initialize(HWND hwndAttach) noexcept {
2933 DXGI_SWAP_CHAIN_DESC1 sd{
3034 .Width = (UINT )rendererSize.cx ,
3135 .Height = (UINT )rendererSize.cy ,
32- .Format = DXGI_FORMAT_R8G8B8A8_UNORM ,
36+ .Format = IsHdrPresentation () ? DXGI_FORMAT_R16G16B16A16_FLOAT : DXGI_FORMAT_R8G8B8A8_UNORM ,
3337 .SampleDesc = {
3438 .Count = 1
3539 },
@@ -70,6 +74,10 @@ bool AdaptivePresenter::_Initialize(HWND hwndAttach) noexcept {
7074 Logger::Get ().Error (" 获取 IDXGISwapChain2 失败" );
7175 return false ;
7276 }
77+ if (IsHdrPresentation ()) {
78+ hr = _dxgiSwapChain->SetColorSpace1 (DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 );
79+ if (FAILED (hr)) Logger::Get ().ComWarn (" SetColorSpace1(scRGB) 失败" , hr);
80+ }
7381
7482 uint32_t maximumFrameLatency = bufferCount - 1 ;
7583 for (const EffectOption& effect : ScalingWindow::Get ().Options ().effects ) {
@@ -103,6 +111,10 @@ bool AdaptivePresenter::_Initialize(HWND hwndAttach) noexcept {
103111 Logger::Get ().ComError (" 获取后缓冲区失败" , hr);
104112 return false ;
105113 }
114+ if (IsHdrPresentation ()) {
115+ hr = _dxgiSwapChain->SetColorSpace1 (DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 );
116+ if (FAILED (hr)) Logger::Get ().ComWarn (" Resize 后设置 scRGB 色彩空间失败" , hr);
117+ }
106118
107119 hr = d3dDevice->CreateRenderTargetView (_backBuffer.get (), nullptr , _backBufferRtv.put ());
108120 if (FAILED (hr)) {
@@ -383,7 +395,7 @@ bool AdaptivePresenter::_ResizeDCompVisual(HWND hwndAttach) noexcept {
383395 hr = _dcompDevice->CreateVirtualSurface (
384396 (UINT )rendererSize.cx ,
385397 (UINT )rendererSize.cy ,
386- DXGI_FORMAT_R8G8B8A8_UNORM ,
398+ IsHdrPresentation () ? DXGI_FORMAT_R16G16B16A16_FLOAT : DXGI_FORMAT_R8G8B8A8_UNORM ,
387399 DXGI_ALPHA_MODE_IGNORE ,
388400 _dcompSurface.put ()
389401 );
0 commit comments