History

vd_lavc: add "auto" choice for vd-lavc-dr

--vd-lavc-dr defaulted to "yes", which caused issues on certain hardware. Instead of disabling it, add a new "auto" value and make it the default. The "auto" choice will enable DR only when we can request host-cached buffers (as signalled by the new VO_DR_FLAG_HOST_CACHED).

sfan5 committed 3 years ago

Commit c7ea0cd1 parent f8c17f54 files · +19 −6Browse files

Unified · Split

4 files
  1. DOCS/interface-changes.rst +1 −0
  2. DOCS/man/options.rst +6 −2
  3. video/decode/vd_lavc.c +7 −4
  4. video/out/vo.h +5 −0
DOCS/interface-changes.rst+1−0
@@ -45,6 +45,7 @@ Interface changes · 44 unmodified lines
4545 watch-later. It is still written by default but you may
4646 need to explictly add `start` depending on how you have
4747 `--watch-later-options` configured.
48+ - add `--vd-lavc-dr=auto` and make it the default
4849 --- mpv 0.35.0 ---
4950 - add the `--vo=gpu-next` video output driver, as well as the options
5051 `--allow-delayed-peak-detect`, `--builtin-scalers`,
DOCS/man/options.rst+6−2
@@ -1700,8 +1700,8 @@ Video · 1699 unmodified lines
17001700 support this, then it will be treated as ``cpu``, regardless of the setting.
17011701 Currently, only ``gpu-next`` supports film grain application.
17021702
1703−``--vd-lavc-dr=<yes|no>``
1704− Enable direct rendering (default: yes). If this is set to ``yes``, the
1703+``--vd-lavc-dr=<auto|yes|no>``
1704+ Enable direct rendering (default: auto). If this is set to ``yes``, the
17051705 video will be decoded directly to GPU video memory (or staging buffers).
17061706 This can speed up video upload, and may help with large resolutions or
17071707 slow hardware. This works only with the following VOs:
@@ -1709,6 +1709,10 @@ Video · 1 unmodified line
17091709 - ``gpu``: requires at least OpenGL 4.4 or Vulkan.
17101710 - ``libmpv``: The libmpv render API has optional support.
17111711
1712+ The ``auto`` option will try to guess whether DR can improve performance
1713+ on your particular hardware. Currently this enables it on AMD or NVIDIA
1714+ if using OpenGL or unconditionally if using Vulkan.
1715+
17121716 Using video filters of any kind that write to the image data (or output
17131717 newly allocated frames) will silently disable the DR code path.
17141718
video/decode/vd_lavc.c+7−4
@@ -120,7 +120,8 @@ const struct m_sub_options vd_lavc_conf = { · 119 unmodified lines
120120 {"vd-lavc-software-fallback", OPT_CHOICE(software_fallback,
121121 {"no", INT_MAX}, {"yes", 1}), M_RANGE(1, INT_MAX)},
122122 {"vd-lavc-o", OPT_KEYVALUELIST(avopts)},
123− {"vd-lavc-dr", OPT_FLAG(dr)},
123+ {"vd-lavc-dr", OPT_CHOICE(dr,
124+ {"auto", -1}, {"no", 0}, {"yes", 1})},
124125 {"hwdec", OPT_STRING(hwdec_api),
125126 .help = hwdec_opt_help,
126127 .flags = M_OPT_OPTIONAL_PARAM | UPDATE_HWDEC},
@@ -139,7 +140,7 @@ const struct m_sub_options vd_lavc_conf = { · 12 unmodified lines
139140 .skip_idct = AVDISCARD_DEFAULT,
140141 .skip_frame = AVDISCARD_DEFAULT,
141142 .framedrop = AVDISCARD_NONREF,
142− .dr = 1,
143+ .dr = -1,
143144 .hwdec_api = "no",
144145 .hwdec_codecs = "h264,vc1,hevc,vp8,vp9,av1,prores",
145146 // Maximum number of surfaces the player wants to buffer. This number
@@ -984,8 +985,10 @@ static int get_buffer2_direct(AVCodecContext *avctx, AVFrame *pic, int flags) · 838 unmodified lines
984985
985986 struct mp_image *img = mp_image_pool_get_no_alloc(p->dr_pool, imgfmt, w, h);
986987 if (!img) {
987− MP_DBG(p, "Allocating new DR image...\n");
988− img = vo_get_image(p->vo, imgfmt, w, h, stride_align, 0);
988+ bool host_cached = p->opts->dr == -1; // auto
989+ int dr_flags = host_cached ? VO_DR_FLAG_HOST_CACHED : 0;
990+ MP_DBG(p, "Allocating new%s DR image...\n", host_cached ? " (host-cached)" : "");
991+ img = vo_get_image(p->vo, imgfmt, w, h, stride_align, dr_flags);
989992 if (!img) {
990993 MP_DBG(p, "...failed..\n");
991994 goto fallback;
video/out/vo.h+5−0
@@ -194,6 +194,11 @@ enum { · 193 unmodified lines
194194 VO_CAP_FILM_GRAIN = 1 << 3,
195195 };
196196
197+enum {
198+ // Require DR buffers to be host-cached (i.e. fast readback)
199+ VO_DR_FLAG_HOST_CACHED = 1 << 0,
200+};
201+
197202 #define VO_MAX_REQ_FRAMES 10
198203
199204 struct vo;

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