summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authornanahi <130121847+na-na-hi@users.noreply.github.com>2024-04-15 22:47:20 -0400
committerKacper Michajłow <kasper93@gmail.com>2024-04-18 16:28:21 +0200
commit96e1f1dfa587a4f21e8a7264ab9e28fad7e5739b (patch)
tree15e6ea8dfc5214e006775454c2a7ac967d6f4fb4 /video
parentd5ec0698291692eda03f9204e3201fd739ece207 (diff)
downloadmpv-96e1f1dfa587a4f21e8a7264ab9e28fad7e5739b.tar.bz2
mpv-96e1f1dfa587a4f21e8a7264ab9e28fad7e5739b.tar.xz
video/out/gpu/context: convert --gpu-context to use obj_settings_list
Since the list of available GPU contexts is a compile time constant, use obj_settings_list instead of opt_string_validate for GPU contexts. This has several advantages: - Aligns with the existing usage of vo, ao, and filter lists. - Allows custom probing order. - Allows list option suffixes. (--gpu-context-append, etc.) - Allows autocomplete in console.lua. - Uses the standard obj_settings_list help printing, so the custom help printing function is no longer needed. This also deduplicates some context creation code for ra_ctx_create and ra_ctx_create_by_name.
Diffstat (limited to 'video')
-rw-r--r--video/out/gpu/context.c187
-rw-r--r--video/out/gpu/context.h2
2 files changed, 100 insertions, 89 deletions
diff --git a/video/out/gpu/context.c b/video/out/gpu/context.c
index 008e9416cc..7eb8185fdc 100644
--- a/video/out/gpu/context.c
+++ b/video/out/gpu/context.c
@@ -119,6 +119,38 @@ static const struct ra_ctx_fns *no_api_contexts[] = {
#endif
};
+static bool get_desc(struct m_obj_desc *dst, int index)
+{
+ if (index >= MP_ARRAY_SIZE(contexts))
+ return false;
+ const struct ra_ctx_fns *ctx = contexts[index];
+ *dst = (struct m_obj_desc) {
+ .name = ctx->name,
+ };
+ return true;
+}
+
+static bool check_unknown_entry(const char *name)
+{
+ struct bstr param = bstr0(name);
+ if (bstr_equals0(param, "auto"))
+ return true;
+ for (int i = 0; i < MP_ARRAY_SIZE(contexts); i++) {
+ if (bstr_equals0(param, contexts[i]->name))
+ return true;
+ }
+ return false;
+}
+
+const struct m_obj_list ra_ctx_obj_list = {
+ .get_desc = get_desc,
+ .check_unknown_entry = check_unknown_entry,
+ .description = "GPU contexts",
+ .allow_trailer = true,
+ .disallow_positional_parameters = true,
+ .use_global_options = true,
+};
+
static int ra_ctx_api_help(struct mp_log *log, const struct m_option *opt,
struct bstr name)
{
@@ -142,27 +174,56 @@ static inline OPT_STRING_VALIDATE_FUNC(ra_ctx_validate_api)
return M_OPT_INVALID;
}
-static int ra_ctx_context_help(struct mp_log *log, const struct m_option *opt,
- struct bstr name)
+#define OPT_BASE_STRUCT struct ra_ctx_opts
+const struct m_sub_options ra_ctx_conf = {
+ .opts = (const m_option_t[]) {
+ {"gpu-context",
+ OPT_SETTINGSLIST(context_list, &ra_ctx_obj_list)},
+ {"gpu-api",
+ OPT_STRING_VALIDATE(context_type, ra_ctx_validate_api),
+ .help = ra_ctx_api_help},
+ {"gpu-debug", OPT_BOOL(debug)},
+ {"gpu-sw", OPT_BOOL(allow_sw)},
+ {0}
+ },
+ .size = sizeof(struct ra_ctx_opts),
+};
+
+static struct ra_ctx *create_in_contexts(struct vo *vo, const char *name, bool api_auto,
+ const struct ra_ctx_fns *ctxs[],
+ size_t size, struct ra_ctx_opts opts)
{
- mp_info(log, "GPU contexts (APIs):\n");
- mp_info(log, " auto (autodetect)\n");
- for (int n = 0; n < MP_ARRAY_SIZE(contexts); n++) {
- mp_info(log, " %s (%s)\n", contexts[n]->name, contexts[n]->type);
+ for (int i = 0; i < size; i++) {
+ if (strcmp(name, ctxs[i]->name) != 0)
+ continue;
+ if (!api_auto && strcmp(ctxs[i]->type, opts.context_type) != 0)
+ continue;
+ struct ra_ctx *ctx = talloc_ptrtype(NULL, ctx);
+ *ctx = (struct ra_ctx) {
+ .vo = vo,
+ .global = vo->global,
+ .log = mp_log_new(ctx, vo->log, ctxs[i]->type),
+ .opts = opts,
+ .fns = ctxs[i],
+ };
+
+ MP_VERBOSE(ctx, "Initializing GPU context '%s'\n", ctx->fns->name);
+ if (ctxs[i]->init(ctx))
+ return ctx;
+ talloc_free(ctx);
}
- return M_OPT_EXIT;
+ return NULL;
}
-static inline OPT_STRING_VALIDATE_FUNC(ra_ctx_validate_context)
+struct ra_ctx *ra_ctx_create_by_name(struct vo *vo, const char *name)
{
- struct bstr param = bstr0(*value);
- if (bstr_equals0(param, "auto"))
- return 1;
- for (int i = 0; i < MP_ARRAY_SIZE(contexts); i++) {
- if (bstr_equals0(param, contexts[i]->name))
- return 1;
- }
- return M_OPT_INVALID;
+ struct ra_ctx_opts dummy = {0};
+ struct ra_ctx *ctx = create_in_contexts(vo, name, true, contexts,
+ MP_ARRAY_SIZE(contexts), dummy);
+ if (ctx)
+ return ctx;
+ return create_in_contexts(vo, name, true, no_api_contexts,
+ MP_ARRAY_SIZE(no_api_contexts), dummy);
}
// Create a VO window and create a RA context on it.
@@ -170,7 +231,9 @@ static inline OPT_STRING_VALIDATE_FUNC(ra_ctx_validate_context)
struct ra_ctx *ra_ctx_create(struct vo *vo, struct ra_ctx_opts opts)
{
bool api_auto = !opts.context_type || strcmp(opts.context_type, "auto") == 0;
- bool ctx_auto = !opts.context_name || strcmp(opts.context_name, "auto") == 0;
+ bool ctx_auto = !opts.context_list ||
+ (opts.context_list[0].name &&
+ strcmp(opts.context_list[0].name, "auto") == 0);
if (ctx_auto) {
MP_VERBOSE(vo, "Probing for best GPU context.\n");
@@ -182,29 +245,27 @@ struct ra_ctx *ra_ctx_create(struct vo *vo, struct ra_ctx_opts opts)
bool old_probing = vo->probing;
vo->probing = opts.probing;
- for (int i = 0; i < MP_ARRAY_SIZE(contexts); i++) {
- if (!opts.probing && strcmp(contexts[i]->name, opts.context_name) != 0)
- continue;
- if (!api_auto && strcmp(contexts[i]->type, opts.context_type) != 0)
- continue;
-
- struct ra_ctx *ctx = talloc_ptrtype(NULL, ctx);
- *ctx = (struct ra_ctx) {
- .vo = vo,
- .global = vo->global,
- .log = mp_log_new(ctx, vo->log, contexts[i]->type),
- .opts = opts,
- .fns = contexts[i],
- };
-
- MP_VERBOSE(ctx, "Initializing GPU context '%s'\n", ctx->fns->name);
- if (contexts[i]->init(ctx)) {
- vo->probing = old_probing;
- vo->context_name = ctx->fns->name;
- return ctx;
+ struct ra_ctx *ctx = NULL;
+ if (opts.probing) {
+ for (int i = 0; i < MP_ARRAY_SIZE(contexts); i++) {
+ ctx = create_in_contexts(vo, contexts[i]->name, api_auto,
+ contexts, MP_ARRAY_SIZE(contexts), opts);
+ if (ctx)
+ goto done;
}
+ }
+ for (int i = 0; opts.context_list && opts.context_list[i].name; i++) {
+ ctx = create_in_contexts(vo, opts.context_list[i].name, api_auto,
+ contexts, MP_ARRAY_SIZE(contexts), opts);
+ if (ctx)
+ goto done;
+ }
- talloc_free(ctx);
+done:
+ if (ctx) {
+ vo->probing = old_probing;
+ vo->context_name = ctx->fns->name;
+ return ctx;
}
vo->probing = old_probing;
@@ -216,40 +277,6 @@ struct ra_ctx *ra_ctx_create(struct vo *vo, struct ra_ctx_opts opts)
return NULL;
}
-static struct ra_ctx *create_in_contexts(struct vo *vo, const char *name,
- const struct ra_ctx_fns *ctxs[],
- size_t size)
-{
- for (int i = 0; i < size; i++) {
- if (strcmp(name, ctxs[i]->name) != 0)
- continue;
-
- struct ra_ctx *ctx = talloc_ptrtype(NULL, ctx);
- *ctx = (struct ra_ctx) {
- .vo = vo,
- .global = vo->global,
- .log = mp_log_new(ctx, vo->log, ctxs[i]->type),
- .fns = ctxs[i],
- };
-
- MP_VERBOSE(ctx, "Initializing GPU context '%s'\n", ctx->fns->name);
- if (ctxs[i]->init(ctx))
- return ctx;
- talloc_free(ctx);
- }
- return NULL;
-}
-
-struct ra_ctx *ra_ctx_create_by_name(struct vo *vo, const char *name)
-{
- struct ra_ctx *ctx = create_in_contexts(vo, name, contexts,
- MP_ARRAY_SIZE(contexts));
- if (ctx)
- return ctx;
- return create_in_contexts(vo, name, no_api_contexts,
- MP_ARRAY_SIZE(no_api_contexts));
-}
-
void ra_ctx_destroy(struct ra_ctx **ctx_ptr)
{
struct ra_ctx *ctx = *ctx_ptr;
@@ -264,19 +291,3 @@ void ra_ctx_destroy(struct ra_ctx **ctx_ptr)
*ctx_ptr = NULL;
}
-
-#define OPT_BASE_STRUCT struct ra_ctx_opts
-const struct m_sub_options ra_ctx_conf = {
- .opts = (const m_option_t[]) {
- {"gpu-context",
- OPT_STRING_VALIDATE(context_name, ra_ctx_validate_context),
- .help = ra_ctx_context_help},
- {"gpu-api",
- OPT_STRING_VALIDATE(context_type, ra_ctx_validate_api),
- .help = ra_ctx_api_help},
- {"gpu-debug", OPT_BOOL(debug)},
- {"gpu-sw", OPT_BOOL(allow_sw)},
- {0}
- },
- .size = sizeof(struct ra_ctx_opts),
-};
diff --git a/video/out/gpu/context.h b/video/out/gpu/context.h
index f7107c9a71..0b422384d8 100644
--- a/video/out/gpu/context.h
+++ b/video/out/gpu/context.h
@@ -10,7 +10,7 @@ struct ra_ctx_opts {
bool want_alpha; // create an alpha framebuffer if possible
bool debug; // enable debugging layers/callbacks etc.
bool probing; // the backend was auto-probed
- char *context_name; // filter by `ra_ctx_fns.name`
+ struct m_obj_settings *context_list; // list of `ra_ctx_fns.name` to probe
char *context_type; // filter by `ra_ctx_fns.type`
};