From 15bb78f947c224ba77d710e0bc915abd982f5432 Mon Sep 17 00:00:00 2001 From: JTGaming <38790084+JTGaming@users.noreply.github.com> Date: Tue, 6 Feb 2024 08:36:51 +0100 Subject: [PATCH] better check for SuperRes/RTX Video HDR support Hopefully having these features enabled in the renderer shouldn't create bugs/visual artifacts on systems that do not support them. Plus simplified the code for RTX Video HDR to more follow the example of SuperResolution. --- Source/D3D11VP.cpp | 21 ++++++--------------- Source/D3D11VP.h | 5 ++--- Source/DX11VideoProcessor.cpp | 23 ++++++++++++++++++++--- Source/DX11VideoProcessor.h | 3 +++ 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/Source/D3D11VP.cpp b/Source/D3D11VP.cpp index 467d61af..4b99474d 100644 --- a/Source/D3D11VP.cpp +++ b/Source/D3D11VP.cpp @@ -778,8 +778,11 @@ HRESULT CD3D11VP::SetRTXVideoHDR(bool enable) return E_ABORT; } - bool support = GpuDriverSupportsVpAutoHDR(); - return ToggleVpAutoHDR(support, enable); + if (m_VendorId == PCIV_NVIDIA) { + return ToggleNvidiaVpTrueHDR(enable); + } + + return E_NOT_SET; } constexpr GUID kNvidiaTrueHDRInterfaceGUID = { @@ -815,15 +818,11 @@ bool CD3D11VP::GpuDriverSupportsVpAutoHDR() { return false; } -HRESULT CD3D11VP::ToggleNvidiaVpTrueHDR(bool driver_supports_vp_auto_hdr, bool enable) { +HRESULT CD3D11VP::ToggleNvidiaVpTrueHDR(bool enable) { if (!m_pVideoContext || !m_pVideoProcessor) { return E_ABORT; } - if (enable && !driver_supports_vp_auto_hdr) { - return E_NOTIMPL; - } - constexpr UINT kStreamExtensionVersionV4 = 0x4; constexpr UINT kStreamExtensionMethodTrueHDR = 0x3; struct { @@ -846,14 +845,6 @@ HRESULT CD3D11VP::ToggleNvidiaVpTrueHDR(bool driver_supports_vp_auto_hdr, bool e return hr; } -HRESULT CD3D11VP::ToggleVpAutoHDR(bool driver_supports_vp_auto_hdr, bool enable) { - if (m_VendorId == PCIV_NVIDIA) { - return ToggleNvidiaVpTrueHDR(driver_supports_vp_auto_hdr, enable); - } - - return E_NOTIMPL; -} - HRESULT CD3D11VP::Process(ID3D11Texture2D* pRenderTarget, const D3D11_VIDEO_FRAME_FORMAT sampleFormat, const bool second) { ASSERT(m_pVideoDevice); diff --git a/Source/D3D11VP.h b/Source/D3D11VP.h index c00b4364..eba2d525 100644 --- a/Source/D3D11VP.h +++ b/Source/D3D11VP.h @@ -184,14 +184,13 @@ class CD3D11VP HRESULT SetSuperResIntel(const bool enable); //tests if there is HDR support for RTX Video HDR - HRESULT ToggleNvidiaVpTrueHDR(bool driver_supports_vp_auto_hdr, bool enable); - HRESULT ToggleVpAutoHDR(bool driver_supports_vp_auto_hdr, bool enable); + HRESULT ToggleNvidiaVpTrueHDR(bool enable); bool NvidiaDriverSupportsTrueHDR(); - bool GpuDriverSupportsVpAutoHDR(); public: HRESULT SetSuperRes(const bool enable); HRESULT SetRTXVideoHDR(bool enable); + bool GpuDriverSupportsVpAutoHDR(); HRESULT Process(ID3D11Texture2D* pRenderTarget, const D3D11_VIDEO_FRAME_FORMAT sampleFormat, const bool second); }; diff --git a/Source/DX11VideoProcessor.cpp b/Source/DX11VideoProcessor.cpp index b44d2ba1..fbc9d91b 100644 --- a/Source/DX11VideoProcessor.cpp +++ b/Source/DX11VideoProcessor.cpp @@ -998,6 +998,10 @@ void CDX11VideoProcessor::UpdateTexParams(int cdepth) //check if RTX Video HDR is valid based on settings and input video bool CDX11VideoProcessor::RTXVideoHDRValid() { + if (!m_bRTXVideoHDR_supported) + return false; + + bool DriverSupport = m_D3D11VP.GpuDriverSupportsVpAutoHDR(); if (m_VendorId == PCIV_NVIDIA) { //hacky fix for checking if video is HDR before all the video data is loaded/processed on first launch //RTX Video HDR does not work for HDR videos, nor HDR-to-SDR videos, but does work for 10bit SDR videos. @@ -1007,7 +1011,7 @@ bool CDX11VideoProcessor::RTXVideoHDRValid() bool ValidSettings = m_bHdrPassthroughSupport && m_bVPRTXVideoHDR; //does not work if another video is already using this feature, // but there is no good way to test for this. - return ValidFormat && ValidSettings && !SourceIsHDR(); + return DriverSupport && ValidFormat && ValidSettings && !SourceIsHDR(); } return false; } @@ -1015,7 +1019,7 @@ bool CDX11VideoProcessor::RTXVideoHDRValid() //check if SuperRes is valid based on settings and input video bool CDX11VideoProcessor::SuperResValid() { - if (m_windowRect.Width() == 0 || m_windowRect.Height() == 0) + if (!m_bSuperRes_supported || m_windowRect.Width() == 0 || m_windowRect.Height() == 0) return false; const UINT AR_width = std::max(m_srcRectWidth, m_srcRectHeight); @@ -1886,6 +1890,19 @@ HRESULT CDX11VideoProcessor::InitializeD3D11VP(const FmtConvParams_t& params, co return hr; } + //check if these technologies are supported on this system. + //only way I could think of force-disabling them entirely + // where the Valid() checks would pass but Set() functions would fail, + // thus causing problems such as the renderer preparing the window for HDR. + //does not check if these are enabled in settings by the user, or if they will work for this video, + // just checks that it could in theory work on this system. + //only runs once on launch, but does rerun the checks on new videos. + //the code right below this will toggle these functions as requested by the user after. + if (!std::exchange(m_bGPUEnhancementsChecked, true)) { + m_bSuperRes_supported = (m_D3D11VP.SetSuperRes(true) == S_OK); + m_bRTXVideoHDR_supported = (m_D3D11VP.SetRTXVideoHDR(true) == S_OK); + } + //Now we control when SuperRes turns on more thoroughly //There should be less instances where this setting is on, but SuperRes itself is off m_bVPUseSuperRes = (m_D3D11VP.SetSuperRes(SuperResValid()) == S_OK); @@ -3815,7 +3832,7 @@ void CDX11VideoProcessor::UpdateStatsStatic() if (sourceHDR || m_bVPUseRTXVideoHDR) { m_strStatsHDR.assign(L"\nHDR processing: "); if (m_bVPUseRTXVideoHDR && !sourceHDR) - m_strStatsHDR.append(L"RTX Video HDR"); + m_strStatsHDR.append(L"RTX Video HDR*"); else if (m_bHdrPassthroughSupport && m_bHdrPassthrough) { m_strStatsHDR.append(L"Passthrough"); if (m_lastHdr10.bValid) { diff --git a/Source/DX11VideoProcessor.h b/Source/DX11VideoProcessor.h index c7e047c4..f54df6b4 100644 --- a/Source/DX11VideoProcessor.h +++ b/Source/DX11VideoProcessor.h @@ -154,6 +154,9 @@ class CDX11VideoProcessor bool m_bVPRTXVideoHDR = false; bool m_bVPUseRTXVideoHDR = false; bool m_bVPSuperResIfScaling = false; + bool m_bSuperRes_supported = false; + bool m_bRTXVideoHDR_supported = false; + bool m_bGPUEnhancementsChecked = false; bool m_bHdrPassthroughSupport = false; bool m_bHdrDisplaySwitching = false; // switching HDR display in progress