summaryrefslogtreecommitdiffstats
path: root/video/out
diff options
context:
space:
mode:
authorPhilip Langdale <philipl@overt.org>2022-02-06 14:18:59 -0800
committerPhilip Langdale <github.philipl@overt.org>2022-02-17 20:02:32 -0800
commit5186651f304fb49867f2542d2eb149f8191cf0de (patch)
treec04acfdbf374bb4142c0c564a73aecd98082c977 /video/out
parentbc9805c71a67b2717c79533731608eff679cded1 (diff)
downloadmpv-5186651f304fb49867f2542d2eb149f8191cf0de.tar.bz2
mpv-5186651f304fb49867f2542d2eb149f8191cf0de.tar.xz
vo_gpu: hwdec: load hwdec interops on-demand by default
Historically, we have treated hwdec interop loading as a completely separate step from loading the hwdecs themselves. Some hwdecs need an interop, and some don't, and users generally configure the exact hwdec they want, so interops that aren't relevant for that hwdec shouldn't be loaded to save time and avoid warning/error spam. The basic approach here is to recognise that interops are tied to hwdecs by imgfmt. The hwdec outputs some format, and an interop is needed to get that format to the vo without read back. So, when we try to load an hwdec, instead of just blindly loading all interops as we do today, let's pass the imgfmt in and only load interops that work for that format. If more than one interop is available for the format, the existing logic (whatever it is) will continue to be used to pick one. We also have one callsite in filters where we seem to pre-emptively load all the interops. It's probably possible to trace down a specific format but for now I'm just letting it keep loading all of them; it's no worse than before. You may notice there is no documentation update - and that's because the current docs say that when the interop mode is `auto`, the interop is loaded on demand. So reality now reflects the docs. How nice.
Diffstat (limited to 'video/out')
-rw-r--r--video/out/gpu/video.c75
-rw-r--r--video/out/gpu/video.h3
-rw-r--r--video/out/vo_gpu.c11
3 files changed, 77 insertions, 12 deletions
diff --git a/video/out/gpu/video.c b/video/out/gpu/video.c
index 449728ccb5..e28a88de5b 100644
--- a/video/out/gpu/video.c
+++ b/video/out/gpu/video.c
@@ -4329,15 +4329,49 @@ struct mp_image *gl_video_get_image(struct gl_video *p, int imgfmt, int w, int h
static void load_add_hwdec(struct gl_video *p, struct mp_hwdec_devices *devs,
const struct ra_hwdec_driver *drv, bool is_auto)
{
+ bool needs_loading = true;
+ for (int j = 0; j < p->num_hwdecs; j++) {
+ const struct ra_hwdec *hwdec = p->hwdecs[j];
+ if (hwdec->driver == drv) {
+ needs_loading = false;
+ break;
+ }
+ }
+ if (!needs_loading) {
+ return;
+ }
+
struct ra_hwdec *hwdec =
ra_hwdec_load_driver(p->ra, p->log, p->global, devs, drv, is_auto);
if (hwdec)
MP_TARRAY_APPEND(p, p->hwdecs, p->num_hwdecs, hwdec);
}
+static void load_hwdecs_all(struct gl_video *p, struct mp_hwdec_devices *devs)
+{
+ if (!p->hwdec_interop_loading_done) {
+ for (int n = 0; ra_hwdec_drivers[n]; n++)
+ load_add_hwdec(p, devs, ra_hwdec_drivers[n], true);
+ p->hwdec_interop_loading_done = true;
+ }
+}
+
void gl_video_load_hwdecs(struct gl_video *p, struct mp_hwdec_devices *devs,
bool load_all_by_default)
{
+ /*
+ * By default, or if the option value is "auto", we will not pre-emptively
+ * load any interops, and instead allow them to be loaded on-demand.
+ *
+ * If the option value is "no", then no interops will be loaded now, and
+ * no interops will be loaded, even if requested later.
+ *
+ * If the option value is "all", then all interops will be loaded now, and
+ * obviously no interops will need to be loaded later.
+ *
+ * Finally, if a specific interop is requested, it will be loaded now, and
+ * no other interop will be loaded, even if requested later.
+ */
char *type = p->opts.hwdec_interop;
if (!type || !type[0] || strcmp(type, "auto") == 0) {
if (!load_all_by_default)
@@ -4347,7 +4381,7 @@ void gl_video_load_hwdecs(struct gl_video *p, struct mp_hwdec_devices *devs,
if (strcmp(type, "no") == 0) {
// do nothing, just block further loading
} else if (strcmp(type, "all") == 0) {
- gl_video_load_hwdecs_all(p, devs);
+ load_hwdecs_all(p, devs);
} else {
for (int n = 0; ra_hwdec_drivers[n]; n++) {
const struct ra_hwdec_driver *drv = ra_hwdec_drivers[n];
@@ -4360,11 +4394,40 @@ void gl_video_load_hwdecs(struct gl_video *p, struct mp_hwdec_devices *devs,
p->hwdec_interop_loading_done = true;
}
-void gl_video_load_hwdecs_all(struct gl_video *p, struct mp_hwdec_devices *devs)
+void gl_video_load_hwdecs_for_img_fmt(struct gl_video *p,
+ struct mp_hwdec_devices *devs,
+ int imgfmt)
{
- if (!p->hwdec_interop_loading_done) {
- for (int n = 0; ra_hwdec_drivers[n]; n++)
- load_add_hwdec(p, devs, ra_hwdec_drivers[n], true);
- p->hwdec_interop_loading_done = true;
+ if (p->hwdec_interop_loading_done) {
+ /*
+ * If we previously marked interop loading as done (for reasons
+ * discussed above), then do not load any other interops regardless
+ * of imgfmt.
+ */
+ return;
+ }
+
+ if (imgfmt == IMGFMT_NONE) {
+ MP_VERBOSE(p, "Loading hwdec drivers for all formats\n");
+ load_hwdecs_all(p, devs);
+ return;
+ }
+
+ MP_VERBOSE(p, "Loading hwdec drivers for format: '%s'\n",
+ mp_imgfmt_to_name(imgfmt));
+ for (int i = 0; ra_hwdec_drivers[i]; i++) {
+ bool matched_fmt = false;
+ const struct ra_hwdec_driver *drv = ra_hwdec_drivers[i];
+ for (int j = 0; drv->imgfmts[j]; j++) {
+ if (imgfmt == drv->imgfmts[j]) {
+ matched_fmt = true;
+ break;
+ }
+ }
+ if (!matched_fmt) {
+ continue;
+ }
+
+ load_add_hwdec(p, devs, drv, false);
}
}
diff --git a/video/out/gpu/video.h b/video/out/gpu/video.h
index 0bb180e514..4c6422b1ab 100644
--- a/video/out/gpu/video.h
+++ b/video/out/gpu/video.h
@@ -220,7 +220,8 @@ bool gl_video_showing_interpolated_frame(struct gl_video *p);
struct mp_hwdec_devices;
void gl_video_load_hwdecs(struct gl_video *p, struct mp_hwdec_devices *devs,
bool load_all_by_default);
-void gl_video_load_hwdecs_all(struct gl_video *p, struct mp_hwdec_devices *devs);
+void gl_video_load_hwdecs_for_img_fmt(struct gl_video *p, struct mp_hwdec_devices *devs,
+ int imgfmt);
struct vo;
void gl_video_configure_queue(struct gl_video *p, struct vo *vo);
diff --git a/video/out/vo_gpu.c b/video/out/vo_gpu.c
index 9e83b380b8..817d750c76 100644
--- a/video/out/vo_gpu.c
+++ b/video/out/vo_gpu.c
@@ -126,18 +126,19 @@ static int reconfig(struct vo *vo, struct mp_image_params *params)
return 0;
}
-static void request_hwdec_api(struct vo *vo)
+static void request_hwdec_api(struct vo *vo, void *data)
{
struct gpu_priv *p = vo->priv;
+ int imgfmt = (intptr_t)data;
- gl_video_load_hwdecs_all(p->renderer, vo->hwdec_devs);
+ gl_video_load_hwdecs_for_img_fmt(p->renderer, vo->hwdec_devs, imgfmt);
}
-static void call_request_hwdec_api(void *ctx)
+static void call_request_hwdec_api(void *ctx, int imgfmt)
{
// Roundabout way to run hwdec loading on the VO thread.
// Redirects to request_hwdec_api().
- vo_control(ctx, VOCTRL_LOAD_HWDEC_API, NULL);
+ vo_control(ctx, VOCTRL_LOAD_HWDEC_API, (void *)(intptr_t)imgfmt);
}
static void get_and_update_icc_profile(struct gpu_priv *p)
@@ -200,7 +201,7 @@ static int control(struct vo *vo, uint32_t request, void *data)
return true;
}
case VOCTRL_LOAD_HWDEC_API:
- request_hwdec_api(vo);
+ request_hwdec_api(vo, data);
return true;
case VOCTRL_UPDATE_RENDER_OPTS: {
update_ra_ctx_options(vo);