From a684e0adff37fbdbe217db464df77beb0e8ca514 Mon Sep 17 00:00:00 2001 From: emoose Date: Tue, 28 Feb 2023 14:14:07 +0000 Subject: [PATCH] `CD3D11VP::SetSuperRes`: allows enabling NVIDIA/Intel superres --- Source/D3D11VP.cpp | 95 +++++++++++++++++++++++++++++++++++ Source/D3D11VP.h | 8 +++ Source/DX11VideoProcessor.cpp | 7 +++ 3 files changed, 110 insertions(+) diff --git a/Source/D3D11VP.cpp b/Source/D3D11VP.cpp index 3122256a..399b1e6f 100644 --- a/Source/D3D11VP.cpp +++ b/Source/D3D11VP.cpp @@ -428,6 +428,101 @@ void CD3D11VP::GetVPParams(D3D11_VIDEO_PROCESSOR_CAPS& caps, UINT& rateConvIndex rateConvCaps = m_RateConvCaps; } +HRESULT CD3D11VP::SetSuperRes(const int iType) +{ + // This func calls into both Intel & NV functions, so that we can tell Intel to disable itself if only NV was picked, or vice-versa + + // Intel VP SuperRes + HRESULT hr; + { + constexpr GUID GUID_INTEL_VPE_INTERFACE = { + 0xedd1d4b9, + 0x8659, + 0x4cbc, + {0xa4, 0xd6, 0x98, 0x31, 0xa2, 0x16, 0x3a, 0xc3} }; + + enum : UINT { + kIntelVpeFnVersion = 0x01, + kIntelVpeFnMode = 0x20, + kIntelVpeFnScaling = 0x37, + }; + + enum : UINT { + kIntelVpeVersion3 = 0x0003, + }; + + enum : UINT { + kIntelVpeModeNone = 0x0, + kIntelVpeModePreproc = 0x01, + }; + + enum : UINT { + kIntelVpeScalingDefault = 0x0, + kIntelVpeScalingSuperResolution = 0x2, + }; + + struct IntelVpeExt { + UINT function; + void* param; + }; + + IntelVpeExt ext = {}; + UINT param = 0; + ext.param = ¶m; + + ext.function = kIntelVpeFnVersion; + param = kIntelVpeVersion3; + hr = m_pVideoContext->VideoProcessorSetOutputExtension( + m_pVideoProcessor, &GUID_INTEL_VPE_INTERFACE, sizeof(ext), &ext); + if (!SUCCEEDED(hr)) { + return hr; + } + + ext.function = kIntelVpeFnMode; + param = (iType == SUPERRES_Intel) ? kIntelVpeModePreproc : kIntelVpeModeNone; + hr = m_pVideoContext->VideoProcessorSetOutputExtension( + m_pVideoProcessor, &GUID_INTEL_VPE_INTERFACE, sizeof(ext), &ext); + if (!SUCCEEDED(hr)) { + return hr; + } + + ext.function = kIntelVpeFnScaling; + param = (iType == SUPERRES_Intel) ? kIntelVpeScalingSuperResolution : kIntelVpeScalingDefault; + + hr = m_pVideoContext->VideoProcessorSetStreamExtension( + m_pVideoProcessor, 0, &GUID_INTEL_VPE_INTERFACE, sizeof(ext), &ext); + if (!SUCCEEDED(hr)) { + return hr; + } + } + + // NVIDIA RTX Super Resolution + { + constexpr GUID kNvidiaPPEInterfaceGUID = { + 0xd43ce1b3, + 0x1f4b, + 0x48ac, + {0xba, 0xee, 0xc3, 0xc2, 0x53, 0x75, 0xe6, 0xf7} }; + constexpr UINT kStreamExtensionVersionV1 = 0x1; + constexpr UINT kStreamExtensionMethodSuperResolution = 0x2; + + struct { + UINT version; + UINT method; + UINT enable; + } stream_extension_info = { kStreamExtensionVersionV1, + kStreamExtensionMethodSuperResolution, iType == SUPERRES_Nvidia ? 1 : 0 }; + + hr = m_pVideoContext->VideoProcessorSetStreamExtension(m_pVideoProcessor, 0, &kNvidiaPPEInterfaceGUID, + sizeof(stream_extension_info), &stream_extension_info); + if (!SUCCEEDED(hr)) { + return hr; + } + } + + return hr; +} + HRESULT CD3D11VP::SetRectangles(const RECT* pSrcRect, const RECT* pDstRect) { CheckPointer(m_pVideoContext, E_ABORT); diff --git a/Source/D3D11VP.h b/Source/D3D11VP.h index 7c96d601..cb240d66 100644 --- a/Source/D3D11VP.h +++ b/Source/D3D11VP.h @@ -22,6 +22,13 @@ #include +// TODO: move this somewhere better? +enum :int { + SUPERRES_None = 0, + SUPERRES_Intel = 1, + SUPERRES_Nvidia = 2 +}; + class VideoTextureBuffer { private: @@ -163,6 +170,7 @@ class CD3D11VP ID3D11Texture2D* GetNextInputTexture(const D3D11_VIDEO_FRAME_FORMAT vframeFormat); void ResetFrameOrder(); + HRESULT SetSuperRes(const int iType); HRESULT SetRectangles(const RECT * pSrcRect, const RECT* pDstRect); HRESULT SetColorSpace(const DXVA2_ExtendedFormat exFmt, const bool bHdrPassthrough); void SetRotation(D3D11_VIDEO_PROCESSOR_ROTATION rotation); diff --git a/Source/DX11VideoProcessor.cpp b/Source/DX11VideoProcessor.cpp index c8f797e3..36eb7138 100644 --- a/Source/DX11VideoProcessor.cpp +++ b/Source/DX11VideoProcessor.cpp @@ -1585,6 +1585,13 @@ HRESULT CDX11VideoProcessor::InitializeD3D11VP(const FmtConvParams_t& params, co return hr; } + // TODO: SetSuperRes can enable Intel superres too, but this only calls with SUPERRES_Nvidia atm + hr = m_D3D11VP.SetSuperRes(SUPERRES_Nvidia); + if (FAILED(hr)) { + DLog(L"CDX11VideoProcessor::InitializeD3D11VP() : SetSuperRes() failed with error {}", HR2Str(hr)); + return hr; + } + hr = m_D3D11VP.SetColorSpace(m_srcExFmt, m_bHdrDisplayModeEnabled && SourceIsHDR()); hr = m_TexSrcVideo.Create(m_pDevice, dxgiFormat, width, height, Tex2D_DynamicShaderWriteNoSRV);