summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas Haas <git@haasn.xyz>2021-04-18 11:48:35 +0200
committerNiklas Haas <github-daiK1o@haasn.dev>2021-11-03 14:09:27 +0100
commit432581b60485433d5497d461730960fa3a2af402 (patch)
tree2500cf6d6f2e1abd9d3e8256c1843f9beb8a39c0
parent5512f53722a46dd7b4844ca8f7e47b5fed2d7259 (diff)
downloadmpv-432581b60485433d5497d461730960fa3a2af402.tar.bz2
mpv-432581b60485433d5497d461730960fa3a2af402.tar.xz
vo_gpu: lift ra_ctx_* opts to a global struct
So I can re-use them for vo_gpu_next.
-rw-r--r--options/options.c2
-rw-r--r--options/options.h1
-rw-r--r--video/out/gpu/context.c43
-rw-r--r--video/out/gpu/context.h17
-rw-r--r--video/out/gpu/lcms.c16
-rw-r--r--video/out/gpu/lcms.h12
-rw-r--r--video/out/gpu/video_shaders.c8
-rw-r--r--video/out/gpu/video_shaders.h7
-rw-r--r--video/out/vo_gpu.c25
9 files changed, 63 insertions, 68 deletions
diff --git a/options/options.c b/options/options.c
index 2f8885e0ba..1341cb891c 100644
--- a/options/options.c
+++ b/options/options.c
@@ -73,6 +73,7 @@ extern const struct m_sub_options vd_lavc_conf;
extern const struct m_sub_options ad_lavc_conf;
extern const struct m_sub_options input_config;
extern const struct m_sub_options encode_config;
+extern const struct m_sub_options ra_ctx_conf;
extern const struct m_sub_options gl_video_conf;
extern const struct m_sub_options ao_alsa_conf;
@@ -779,6 +780,7 @@ static const m_option_t mp_opts[] = {
{"", OPT_SUBSTRUCT(demux_cache_opts, demux_cache_conf)},
{"", OPT_SUBSTRUCT(stream_opts, stream_conf)},
+ {"", OPT_SUBSTRUCT(ra_ctx_opts, ra_ctx_conf)},
{"", OPT_SUBSTRUCT(gl_video_opts, gl_video_conf)},
{"", OPT_SUBSTRUCT(spirv_opts, spirv_conf)},
diff --git a/options/options.h b/options/options.h
index f3c8e318e8..53e8de7852 100644
--- a/options/options.h
+++ b/options/options.h
@@ -344,6 +344,7 @@ typedef struct MPOpts {
struct mp_resample_opts *resample_opts;
+ struct ra_ctx_opts *ra_ctx_opts;
struct gl_video_opts *gl_video_opts;
struct angle_opts *angle_opts;
struct opengl_opts *opengl_opts;
diff --git a/video/out/gpu/context.c b/video/out/gpu/context.c
index 6e58cce485..e0beb845c2 100644
--- a/video/out/gpu/context.c
+++ b/video/out/gpu/context.c
@@ -112,8 +112,8 @@ static const struct ra_ctx_fns *contexts[] = {
#endif
};
-int ra_ctx_api_help(struct mp_log *log, const struct m_option *opt,
- struct bstr name)
+static int ra_ctx_api_help(struct mp_log *log, const struct m_option *opt,
+ struct bstr name)
{
mp_info(log, "GPU APIs (contexts):\n");
mp_info(log, " auto (autodetect)\n");
@@ -122,8 +122,8 @@ int ra_ctx_api_help(struct mp_log *log, const struct m_option *opt,
return M_OPT_EXIT;
}
-int ra_ctx_validate_api(struct mp_log *log, const struct m_option *opt,
- struct bstr name, const char **value)
+static int ra_ctx_validate_api(struct mp_log *log, const struct m_option *opt,
+ struct bstr name, const char **value)
{
struct bstr param = bstr0(*value);
if (bstr_equals0(param, "auto"))
@@ -135,8 +135,8 @@ int ra_ctx_validate_api(struct mp_log *log, const struct m_option *opt,
return M_OPT_INVALID;
}
-int ra_ctx_context_help(struct mp_log *log, const struct m_option *opt,
- struct bstr name)
+static int ra_ctx_context_help(struct mp_log *log, const struct m_option *opt,
+ struct bstr name)
{
mp_info(log, "GPU contexts (APIs):\n");
mp_info(log, " auto (autodetect)\n");
@@ -145,8 +145,8 @@ int ra_ctx_context_help(struct mp_log *log, const struct m_option *opt,
return M_OPT_EXIT;
}
-int ra_ctx_validate_context(struct mp_log *log, const struct m_option *opt,
- struct bstr name, const char **value)
+static int ra_ctx_validate_context(struct mp_log *log, const struct m_option *opt,
+ struct bstr name, const char **value)
{
struct bstr param = bstr0(*value);
if (bstr_equals0(param, "auto"))
@@ -160,11 +160,10 @@ int ra_ctx_validate_context(struct mp_log *log, const struct m_option *opt,
// Create a VO window and create a RA context on it.
// vo_flags: passed to the backend's create window function
-struct ra_ctx *ra_ctx_create(struct vo *vo, const char *context_type,
- const char *context_name, struct ra_ctx_opts opts)
+struct ra_ctx *ra_ctx_create(struct vo *vo, struct ra_ctx_opts opts)
{
- bool api_auto = !context_type || strcmp(context_type, "auto") == 0;
- bool ctx_auto = !context_name || strcmp(context_name, "auto") == 0;
+ bool api_auto = !opts.context_type || strcmp(opts.context_type, "auto") == 0;
+ bool ctx_auto = !opts.context_name || strcmp(opts.context_name, "auto") == 0;
if (ctx_auto) {
MP_VERBOSE(vo, "Probing for best GPU context.\n");
@@ -177,9 +176,9 @@ struct ra_ctx *ra_ctx_create(struct vo *vo, const char *context_type,
vo->probing = opts.probing;
for (int i = 0; i < MP_ARRAY_SIZE(contexts); i++) {
- if (!opts.probing && strcmp(contexts[i]->name, context_name) != 0)
+ if (!opts.probing && strcmp(contexts[i]->name, opts.context_name) != 0)
continue;
- if (!api_auto && strcmp(contexts[i]->type, context_type) != 0)
+ if (!api_auto && strcmp(contexts[i]->type, opts.context_type) != 0)
continue;
struct ra_ctx *ctx = talloc_ptrtype(NULL, ctx);
@@ -223,3 +222,19 @@ 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_FLAG(debug)},
+ {"gpu-sw", OPT_FLAG(allow_sw)},
+ {0}
+ },
+ .size = sizeof(struct ra_ctx_opts),
+};
diff --git a/video/out/gpu/context.h b/video/out/gpu/context.h
index ca71150f54..7ad37f0d61 100644
--- a/video/out/gpu/context.h
+++ b/video/out/gpu/context.h
@@ -11,8 +11,12 @@ struct ra_ctx_opts {
int want_alpha; // create an alpha framebuffer if possible
int debug; // enable debugging layers/callbacks etc.
bool probing; // the backend was auto-probed
+ char *context_name; // filter by `ra_ctx_fns.name`
+ char *context_type; // filter by `ra_ctx_fns.type`
};
+extern const struct m_sub_options ra_ctx_conf;
+
struct ra_ctx {
struct vo *vo;
struct ra *ra;
@@ -95,16 +99,5 @@ struct ra_swapchain_fns {
// Create and destroy a ra_ctx. This also takes care of creating and destroying
// the underlying `struct ra`, and perhaps the underlying VO backend.
-struct ra_ctx *ra_ctx_create(struct vo *vo, const char *context_type,
- const char *context_name, struct ra_ctx_opts opts);
+struct ra_ctx *ra_ctx_create(struct vo *vo, struct ra_ctx_opts opts);
void ra_ctx_destroy(struct ra_ctx **ctx);
-
-struct m_option;
-int ra_ctx_api_help(struct mp_log *log, const struct m_option *opt,
- struct bstr name);
-int ra_ctx_validate_api(struct mp_log *log, const struct m_option *opt,
- struct bstr name, const char **value);
-int ra_ctx_context_help(struct mp_log *log, const struct m_option *opt,
- struct bstr name);
-int ra_ctx_validate_context(struct mp_log *log, const struct m_option *opt,
- struct bstr name, const char **value);
diff --git a/video/out/gpu/lcms.c b/video/out/gpu/lcms.c
index 704f1fbf1d..17edf96f3b 100644
--- a/video/out/gpu/lcms.c
+++ b/video/out/gpu/lcms.c
@@ -54,18 +54,6 @@ struct gl_lcms {
struct mp_icc_opts *opts;
};
-static bool parse_3dlut_size(const char *arg, int *p1, int *p2, int *p3)
-{
- if (sscanf(arg, "%dx%dx%d", p1, p2, p3) != 3)
- return false;
- for (int n = 0; n < 3; n++) {
- int s = ((int[]) { *p1, *p2, *p3 })[n];
- if (s < 2 || s > 512)
- return false;
- }
- return true;
-}
-
static int validate_3dlut_size_opt(struct mp_log *log, const m_option_t *opt,
struct bstr name, const char **value)
{
@@ -73,7 +61,7 @@ static int validate_3dlut_size_opt(struct mp_log *log, const m_option_t *opt,
int p1, p2, p3;
char s[20];
snprintf(s, sizeof(s), "%.*s", BSTR_P(param));
- return parse_3dlut_size(s, &p1, &p2, &p3);
+ return gl_parse_3dlut_size(s, &p1, &p2, &p3);
}
#define OPT_BASE_STRUCT struct mp_icc_opts
@@ -367,7 +355,7 @@ bool gl_lcms_get_lut3d(struct gl_lcms *p, struct lut3d **result_lut3d,
abort();
}
- if (!parse_3dlut_size(p->opts->size_str, &s_r, &s_g, &s_b))
+ if (!gl_parse_3dlut_size(p->opts->size_str, &s_r, &s_g, &s_b))
return false;
if (!gl_lcms_has_profile(p))
diff --git a/video/out/gpu/lcms.h b/video/out/gpu/lcms.h
index 35bbd61fe0..62b2437194 100644
--- a/video/out/gpu/lcms.h
+++ b/video/out/gpu/lcms.h
@@ -40,4 +40,16 @@ bool gl_lcms_get_lut3d(struct gl_lcms *p, struct lut3d **,
bool gl_lcms_has_changed(struct gl_lcms *p, enum mp_csp_prim prim,
enum mp_csp_trc trc, struct AVBufferRef *vid_profile);
+static inline bool gl_parse_3dlut_size(const char *arg, int *p1, int *p2, int *p3)
+{
+ if (sscanf(arg, "%dx%dx%d", p1, p2, p3) != 3)
+ return false;
+ for (int n = 0; n < 3; n++) {
+ int s = ((int[]) { *p1, *p2, *p3 })[n];
+ if (s < 2 || s > 512)
+ return false;
+ }
+ return true;
+}
+
#endif
diff --git a/video/out/gpu/video_shaders.c b/video/out/gpu/video_shaders.c
index d39b867e2a..d5bc678145 100644
--- a/video/out/gpu/video_shaders.c
+++ b/video/out/gpu/video_shaders.c
@@ -937,14 +937,6 @@ static void prng_init(struct gl_shader_cache *sc, AVLFG *lfg)
gl_sc_uniform_f(sc, "random", (double)av_lfg_get(lfg) / UINT32_MAX);
}
-struct deband_opts {
- int enabled;
- int iterations;
- float threshold;
- float range;
- float grain;
-};
-
const struct deband_opts deband_opts_def = {
.iterations = 1,
.threshold = 32.0,
diff --git a/video/out/gpu/video_shaders.h b/video/out/gpu/video_shaders.h
index f20d643e99..27e7874c6d 100644
--- a/video/out/gpu/video_shaders.h
+++ b/video/out/gpu/video_shaders.h
@@ -23,6 +23,13 @@
#include "utils.h"
#include "video.h"
+struct deband_opts {
+ int iterations;
+ float threshold;
+ float range;
+ float grain;
+};
+
extern const struct deband_opts deband_opts_def;
extern const struct m_sub_options deband_conf;
diff --git a/video/out/vo_gpu.c b/video/out/vo_gpu.c
index 38b29c3ceb..9e83b380b8 100644
--- a/video/out/vo_gpu.c
+++ b/video/out/vo_gpu.c
@@ -48,7 +48,6 @@ struct gpu_priv {
char *context_name;
char *context_type;
- struct ra_ctx_opts opts;
struct gl_video *renderer;
int events;
@@ -291,13 +290,13 @@ static int preinit(struct vo *vo)
struct gpu_priv *p = vo->priv;
p->log = vo->log;
- struct ra_ctx_opts opts = p->opts;
- struct gl_video_opts *gl_opts =
- mp_get_config_group(p->ctx, vo->global, &gl_video_conf);
+ struct ra_ctx_opts *ctx_opts = mp_get_config_group(vo, vo->global, &ra_ctx_conf);
+ struct gl_video_opts *gl_opts = mp_get_config_group(vo, vo->global, &gl_video_conf);
+ struct ra_ctx_opts opts = *ctx_opts;
opts.want_alpha = gl_opts->alpha_mode == 1;
+ p->ctx = ra_ctx_create(vo, opts);
+ talloc_free(ctx_opts);
talloc_free(gl_opts);
-
- p->ctx = ra_ctx_create(vo, p->context_type, p->context_name, opts);
if (!p->ctx)
goto err_out;
assert(p->ctx->ra);
@@ -321,19 +320,6 @@ err_out:
return -1;
}
-#define OPT_BASE_STRUCT struct gpu_priv
-static const m_option_t options[] = {
- {"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_FLAG(opts.debug)},
- {"gpu-sw", OPT_FLAG(opts.allow_sw)},
- {0}
-};
-
const struct vo_driver video_out_gpu = {
.description = "Shader-based GPU Renderer",
.name = "gpu",
@@ -350,5 +336,4 @@ const struct vo_driver video_out_gpu = {
.wakeup = wakeup,
.uninit = uninit,
.priv_size = sizeof(struct gpu_priv),
- .options = options,
};