History

vf_d3d11vpp: add support for Intel VSR and NVIDIA RTX scaling modes

Adds `--vf=d3d11vpp=scaling-mode` to control which extensions should be enabled.

Kacper Michajłow committed 2 years ago

Commit 2848af51 parent bbb3d5b3 files · +126 −0Browse files

Unified · Split

3 files
  1. DOCS/interface-changes/d3d11va-scaling-mode.txt +1 −0
  2. DOCS/man/vf.rst +12 −0
  3. video/filter/vf_d3d11vpp.c +113 −0
DOCS/interface-changes/d3d11va-scaling-mode.txt+1−0
@@ -0,0 +1 @@
1+add `--vf=d3d11vpp=scaling-mode`
DOCS/man/vf.rst+12−0
@@ -694,6 +694,18 @@ Available mpv-only filters are: · 693 unmodified lines
694694 Whether deinterlacing is enabled (default: no).
695695 ``scale``
696696 Scaling factor for the video frames (default: 1.0).
697+ ``scaling-mode=<standard,intel,nvidia>``
698+ Select the scaling mode to be used. Note that this only enables the
699+ appropriate processing extensions; whether it actually works or not
700+ depends on your hardware and the settings in your GPU driver's control
701+ panel (default: standard).
702+
703+ standard
704+ Default scaling mode as decided by d3d11vpp implementation.
705+ intel
706+ Intel Video Super Resolution.
707+ nvidia
708+ NVIDIA RTX Super Resolution.
697709 ``interlaced-only=<yes|no>``
698710 If ``yes``, only deinterlace frames marked as interlaced (default: no).
699711 ``mode=<blend|bob|adaptive|mocomp|ivctc|none>``
video/filter/vf_d3d11vpp.c+113−0
@@ -42,9 +42,40 @@ · 41 unmodified lines
4242 #define D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_INVERSE_TELECINE 0x10
4343 #define D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_FRAME_RATE_CONVERSION 0x20
4444
45+// For video procesor extensions identifiers reference see:
46+// https://chromium.googlesource.com/chromium/src/+/5f354f38/ui/gl/swap_chain_presenter.cc
47+
48+#ifndef NVIDIA_PPE_INTERFACE_GUID
49+DEFINE_GUID(NVIDIA_PPE_INTERFACE_GUID,
50+ 0xd43ce1b3, 0x1f4b, 0x48ac, 0xba, 0xee,
51+ 0xc3, 0xc2, 0x53, 0x75, 0xe6, 0xf7);
52+#endif
53+
54+#ifndef INTEL_VPE_INTERFACE_GUID
55+DEFINE_GUID(INTEL_VPE_INTERFACE_GUID,
56+ 0xedd1d4b9, 0x8659, 0x4cbc, 0xa4, 0xd6,
57+ 0x98, 0x31, 0xa2, 0x16, 0x3a, 0xc3);
58+#endif
59+
60+static const unsigned int intel_vpe_fn_version = 0x1;
61+static const unsigned int intel_vpe_version = 0x3;
62+
63+static const unsigned int intel_vpe_fn_scaling = 0x37;
64+static const unsigned int intel_vpe_scaling_vsr = 0x2;
65+
66+static const unsigned int intel_vpe_fn_mode = 0x20;
67+static const unsigned int intel_vpe_mode_preproc = 0x1;
68+
69+enum scaling_mode {
70+ SCALING_BASIC,
71+ SCALING_INTEL_VSR,
72+ SCALING_NVIDIA_RTX,
73+};
74+
4575 struct opts {
4676 bool deint_enabled;
4777 float scale;
78+ int scaling_mode;
4879 bool interlaced_only;
4980 int mode;
5081 int field_parity;
@@ -135,6 +166,74 @@ static void destroy_video_proc(struct mp_filter *vf) · 84 unmodified lines
135166 p->vp_enum = NULL;
136167 }
137168
169+static void enable_nvidia_rtx_extension(struct mp_filter *vf)
170+{
171+ struct priv *p = vf->priv;
172+
173+ struct nvidia_ext {
174+ unsigned int version;
175+ unsigned int method;
176+ unsigned int enable;
177+ } ext = {1, 2, 1};
178+
179+ HRESULT hr = ID3D11VideoContext_VideoProcessorSetStreamExtension(p->video_ctx,
180+ p->video_proc,
181+ 0,
182+ &NVIDIA_PPE_INTERFACE_GUID,
183+ sizeof(ext),
184+ &ext);
185+
186+ if (FAILED(hr)) {
187+ MP_WARN(vf, "Failed to enable NVIDIA RTX Super Resolution: %s\n", mp_HRESULT_to_str(hr));
188+ } else {
189+ MP_VERBOSE(vf, "NVIDIA RTX Super Resolution enabled\n");
190+ }
191+}
192+
193+static void enable_intel_vsr_extension(struct mp_filter *vf)
194+{
195+ struct priv *p = vf->priv;
196+
197+ struct intel_vpe_ext {
198+ unsigned int function;
199+ const void* param;
200+ } ext;
201+
202+ ext = (struct intel_vpe_ext){intel_vpe_fn_version, &intel_vpe_version};
203+ HRESULT hr = ID3D11VideoContext_VideoProcessorSetOutputExtension(p->video_ctx,
204+ p->video_proc,
205+ &INTEL_VPE_INTERFACE_GUID,
206+ sizeof(ext),
207+ &ext);
208+ if (FAILED(hr))
209+ goto failed;
210+
211+ ext = (struct intel_vpe_ext){intel_vpe_fn_mode, &intel_vpe_mode_preproc};
212+ hr = ID3D11VideoContext_VideoProcessorSetOutputExtension(p->video_ctx,
213+ p->video_proc,
214+ &INTEL_VPE_INTERFACE_GUID,
215+ sizeof(ext),
216+ &ext);
217+ if (FAILED(hr))
218+ goto failed;
219+
220+ ext = (struct intel_vpe_ext){intel_vpe_fn_scaling, &intel_vpe_scaling_vsr};
221+ hr = ID3D11VideoContext_VideoProcessorSetStreamExtension(p->video_ctx,
222+ p->video_proc,
223+ 0,
224+ &INTEL_VPE_INTERFACE_GUID,
225+ sizeof(ext),
226+ &ext);
227+ if (FAILED(hr))
228+ goto failed;
229+
230+ MP_VERBOSE(vf, "Intel Video Super Resolution enabled\n");
231+ return;
232+
233+failed:
234+ MP_WARN(vf, "Failed to enable Intel Video Super Resolution: %s\n", mp_HRESULT_to_str(hr));
235+}
236+
138237 static int recreate_video_proc(struct mp_filter *vf)
139238 {
140239 struct priv *p = vf->priv;
@@ -222,6 +321,15 @@ static int recreate_video_proc(struct mp_filter *vf) · 81 unmodified lines
222321 p->video_proc,
223322 &csp);
224323
324+ switch (p->opts->scaling_mode) {
325+ case SCALING_INTEL_VSR:
326+ enable_intel_vsr_extension(vf);
327+ break;
328+ case SCALING_NVIDIA_RTX:
329+ enable_nvidia_rtx_extension(vf);
330+ break;
331+ }
332+
225333 return 0;
226334 fail:
227335 destroy_video_proc(vf);
@@ -499,6 +607,10 @@ fail: · 271 unmodified lines
499607 static const m_option_t vf_opts_fields[] = {
500608 {"deint", OPT_BOOL(deint_enabled)},
501609 {"scale", OPT_FLOAT(scale)},
610+ {"scaling-mode", OPT_CHOICE(scaling_mode,
611+ {"standard", SCALING_BASIC},
612+ {"intel", SCALING_INTEL_VSR},
613+ {"nvidia", SCALING_NVIDIA_RTX})},
502614 {"interlaced-only", OPT_BOOL(interlaced_only)},
503615 {"mode", OPT_CHOICE(mode,
504616 {"blend", D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_DEINTERLACE_BLEND},
@@ -522,6 +634,7 @@ const struct mp_user_filter_entry vf_d3d11vpp = { · 17 unmodified lines
522634 .priv_defaults = &(const OPT_BASE_STRUCT) {
523635 .deint_enabled = false,
524636 .scale = 1.0,
637+ .scaling_mode = SCALING_BASIC,
525638 .mode = 0,
526639 .field_parity = MP_FIELD_PARITY_AUTO,
527640 },

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t