vo_gpu: lift ra_ctx_* opts to a global struct

So I can re-use them for vo_gpu_next.
This commit is contained in:
Niklas Haas 2021-04-18 11:48:35 +02:00 committed by Niklas Haas
parent 5512f53722
commit 432581b604
9 changed files with 63 additions and 68 deletions

View File

@ -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)},

View File

@ -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;

View File

@ -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),
};

View File

@ -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);

View File

@ -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))

View File

@ -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

View File

@ -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,

View File

@ -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;

View File

@ -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,
};