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 @@
1add `--vf=d3d11vpp=scaling-mode`
DOCS/man/vf.rst+12−0
@@ -694,6 +694,18 @@ Available mpv-only filters are: · 693 unmodified lines
694 Whether deinterlacing is enabled (default: no).694 Whether deinterlacing is enabled (default: no).
695 ``scale``695 ``scale``
696 Scaling factor for the video frames (default: 1.0).696 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.
697 ``interlaced-only=<yes|no>``709 ``interlaced-only=<yes|no>``
698 If ``yes``, only deinterlace frames marked as interlaced (default: no).710 If ``yes``, only deinterlace frames marked as interlaced (default: no).
699 ``mode=<blend|bob|adaptive|mocomp|ivctc|none>``711 ``mode=<blend|bob|adaptive|mocomp|ivctc|none>``
video/filter/vf_d3d11vpp.c+113−0
@@ -42,9 +42,40 @@ · 41 unmodified lines
42#define D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_INVERSE_TELECINE 0x1042#define D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_INVERSE_TELECINE 0x10
43#define D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_FRAME_RATE_CONVERSION 0x2043#define D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_FRAME_RATE_CONVERSION 0x20
44 44
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
49DEFINE_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
55DEFINE_GUID(INTEL_VPE_INTERFACE_GUID,
56 0xedd1d4b9, 0x8659, 0x4cbc, 0xa4, 0xd6,
57 0x98, 0x31, 0xa2, 0x16, 0x3a, 0xc3);
58#endif
59
60static const unsigned int intel_vpe_fn_version = 0x1;
61static const unsigned int intel_vpe_version = 0x3;
62
63static const unsigned int intel_vpe_fn_scaling = 0x37;
64static const unsigned int intel_vpe_scaling_vsr = 0x2;
65
66static const unsigned int intel_vpe_fn_mode = 0x20;
67static const unsigned int intel_vpe_mode_preproc = 0x1;
68
69enum scaling_mode {
70 SCALING_BASIC,
71 SCALING_INTEL_VSR,
72 SCALING_NVIDIA_RTX,
73};
74
45struct opts {75struct opts {
46 bool deint_enabled;76 bool deint_enabled;
47 float scale;77 float scale;
78 int scaling_mode;
48 bool interlaced_only;79 bool interlaced_only;
49 int mode;80 int mode;
50 int field_parity;81 int field_parity;
@@ -135,6 +166,74 @@ static void destroy_video_proc(struct mp_filter *vf) · 84 unmodified lines
135 p->vp_enum = NULL;166 p->vp_enum = NULL;
136}167}
137 168
169static 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
193static 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
233failed:
234 MP_WARN(vf, "Failed to enable Intel Video Super Resolution: %s\n", mp_HRESULT_to_str(hr));
235}
236
138static int recreate_video_proc(struct mp_filter *vf)237static int recreate_video_proc(struct mp_filter *vf)
139{238{
140 struct priv *p = vf->priv;239 struct priv *p = vf->priv;
@@ -222,6 +321,15 @@ static int recreate_video_proc(struct mp_filter *vf) · 81 unmodified lines
222 p->video_proc,321 p->video_proc,
223 &csp);322 &csp);
224 323
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
225 return 0;333 return 0;
226fail:334fail:
227 destroy_video_proc(vf);335 destroy_video_proc(vf);
@@ -499,6 +607,10 @@ fail: · 271 unmodified lines
499static const m_option_t vf_opts_fields[] = {607static const m_option_t vf_opts_fields[] = {
500 {"deint", OPT_BOOL(deint_enabled)},608 {"deint", OPT_BOOL(deint_enabled)},
501 {"scale", OPT_FLOAT(scale)},609 {"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})},
502 {"interlaced-only", OPT_BOOL(interlaced_only)},614 {"interlaced-only", OPT_BOOL(interlaced_only)},
503 {"mode", OPT_CHOICE(mode,615 {"mode", OPT_CHOICE(mode,
504 {"blend", D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_DEINTERLACE_BLEND},616 {"blend", D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_DEINTERLACE_BLEND},
@@ -522,6 +634,7 @@ const struct mp_user_filter_entry vf_d3d11vpp = { · 17 unmodified lines
522 .priv_defaults = &(const OPT_BASE_STRUCT) {634 .priv_defaults = &(const OPT_BASE_STRUCT) {
523 .deint_enabled = false,635 .deint_enabled = false,
524 .scale = 1.0,636 .scale = 1.0,
637 .scaling_mode = SCALING_BASIC,
525 .mode = 0,638 .mode = 0,
526 .field_parity = MP_FIELD_PARITY_AUTO,639 .field_parity = MP_FIELD_PARITY_AUTO,
527 },640 },

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