Skip to content

Commit

Permalink
better check for SuperRes/RTX Video HDR support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JTGaming committed Feb 6, 2024
1 parent 18143f5 commit 15bb78f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
21 changes: 6 additions & 15 deletions Source/D3D11VP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions Source/D3D11VP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
23 changes: 20 additions & 3 deletions Source/DX11VideoProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -1007,15 +1011,15 @@ 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;
}

//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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions Source/DX11VideoProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 15bb78f

Please sign in to comment.