From d10e68f46c7a180b9cf8bdbfc1cf0151d6ee78ab Mon Sep 17 00:00:00 2001 From: emoose Date: Fri, 26 Jan 2024 13:58:55 +0000 Subject: [PATCH] rtx-hdr: force RTX HDR to activate --- Source/D3D11VP.cpp | 50 +++++++++++++++++++++++++++++++++++ Source/D3D11VP.h | 1 + Source/DX11VideoProcessor.cpp | 4 +-- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Source/D3D11VP.cpp b/Source/D3D11VP.cpp index 9babd43c..c7861690 100644 --- a/Source/D3D11VP.cpp +++ b/Source/D3D11VP.cpp @@ -377,6 +377,7 @@ HRESULT CD3D11VP::InitVideoProcessor( // other m_pVideoContext->VideoProcessorSetOutputTargetRect(m_pVideoProcessor, FALSE, nullptr); m_pVideoContext->VideoProcessorSetStreamRotation(m_pVideoProcessor, 0, m_Rotation ? TRUE : FALSE, m_Rotation); + SetRtxHdrNvidia(true); m_srcFormat = inputFmt; m_srcWidth = width; @@ -696,6 +697,55 @@ HRESULT CD3D11VP::SetSuperResNvidia(const bool enable) return hr; } +HRESULT CD3D11VP::SetRtxHdrNvidia(const bool enable) +{ + constexpr GUID kNvidiaTrueHDRInterfaceGUID = { + 0xfdd62bb4, + 0x620b, + 0x4fd7, + {0x9a, 0xb3, 0x1e, 0x59, 0xd0, 0xd5, 0x44, 0xb3} + }; + constexpr UINT kStreamExtensionVersionV4 = 0x4; + constexpr UINT kStreamExtensionMethodTrueHDR = 0x3; + + struct { + UINT version; + UINT method; + UINT enable : 1; + UINT reserved : 31; + } + stream_extension_info = { + kStreamExtensionVersionV4, + kStreamExtensionMethodTrueHDR, + enable ? 1u : 0u, + 0u + }; + + HRESULT hr; + + UINT driver_supports_true_hdr = 0; + hr = m_pVideoContext->VideoProcessorGetStreamExtension( + m_pVideoProcessor, 0, &kNvidiaTrueHDRInterfaceGUID, + sizeof(driver_supports_true_hdr), &driver_supports_true_hdr); + + if (FAILED(hr)) { + return S_FALSE; + } + if (driver_supports_true_hdr != 1) { + return S_FALSE; + } + + hr = m_pVideoContext->VideoProcessorSetStreamExtension( + m_pVideoProcessor, 0, &kNvidiaTrueHDRInterfaceGUID, + sizeof(stream_extension_info), &stream_extension_info); + + if (hr == S_OK && !enable) { + return S_FALSE; + } + + return hr; +} + HRESULT CD3D11VP::SetSuperResIntel(const bool enable) { constexpr GUID GUID_INTEL_VPE_INTERFACE = { diff --git a/Source/D3D11VP.h b/Source/D3D11VP.h index 96d77952..3546e938 100644 --- a/Source/D3D11VP.h +++ b/Source/D3D11VP.h @@ -184,6 +184,7 @@ class CD3D11VP HRESULT SetSuperResIntel(const bool enable); public: HRESULT SetSuperRes(const int iSuperRes); + HRESULT SetRtxHdrNvidia(const bool enable); HRESULT Process(ID3D11Texture2D* pRenderTarget, const D3D11_VIDEO_FRAME_FORMAT sampleFormat, const bool second); }; diff --git a/Source/DX11VideoProcessor.cpp b/Source/DX11VideoProcessor.cpp index 55e066f3..8b983f28 100644 --- a/Source/DX11VideoProcessor.cpp +++ b/Source/DX11VideoProcessor.cpp @@ -1310,7 +1310,7 @@ HRESULT CDX11VideoProcessor::InitSwapChain() } } - const auto bHdrOutput = m_bHdrPassthroughSupport && m_bHdrPassthrough && SourceIsHDR(); + const auto bHdrOutput = m_bHdrPassthroughSupport && m_bHdrPassthrough; const auto b10BitOutput = bHdrOutput || Preferred10BitOutput(); m_SwapChainFmt = b10BitOutput ? DXGI_FORMAT_R10G10B10A2_UNORM : DXGI_FORMAT_B8G8R8A8_UNORM; @@ -1741,7 +1741,7 @@ HRESULT CDX11VideoProcessor::InitializeD3D11VP(const FmtConvParams_t& params, co m_TexSrcVideo.Release(); - const bool bHdrPassthrough = m_bHdrDisplayModeEnabled && SourceIsPQorHLG(); + const bool bHdrPassthrough = m_bHdrDisplayModeEnabled; m_D3D11OutputFmt = m_InternalTexFmt; HRESULT hr = m_D3D11VP.InitVideoProcessor(dxgiFormat, width, height, m_srcExFmt, m_bInterlaced, bHdrPassthrough, m_D3D11OutputFmt); if (FAILED(hr)) {