1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-26 00:42:57 +00:00
mpv/video/out/gpu/spirv.c
wm4 26f4f18c06 options: change option macros and all option declarations
Change all OPT_* macros such that they don't define the entire m_option
initializer, and instead expand only to a part of it, which sets certain
fields. This requires changing almost every option declaration, because
they all use these macros. A declaration now always starts with

   {"name", ...

followed by designated initializers only (possibly wrapped in macros).
The OPT_* macros now initialize the .offset and .type fields only,
sometimes also .priv and others.

I think this change makes the option macros less tricky. The old code
had to stuff everything into macro arguments (and attempted to allow
setting arbitrary fields by letting the user pass designated
initializers in the vararg parts). Some of this was made messy due to
C99 and C11 not allowing 0-sized varargs with ',' removal. It's also
possible that this change is pointless, other than cosmetic preferences.

Not too happy about some things. For example, the OPT_CHOICE()
indentation I applied looks a bit ugly.

Much of this change was done with regex search&replace, but some places
required manual editing. In particular, code in "obscure" areas (which I
didn't include in compilation) might be broken now.

In wayland_common.c the author of some option declarations confused the
flags parameter with the default value (though the default value was
also properly set below). I fixed this with this change.
2020-03-18 19:52:01 +01:00

71 lines
1.8 KiB
C

#include "common/msg.h"
#include "options/m_config.h"
#include "spirv.h"
#include "config.h"
extern const struct spirv_compiler_fns spirv_shaderc;
// in probe-order
enum {
SPIRV_AUTO = 0,
SPIRV_SHADERC, // generally preferred, but not packaged everywhere
};
static const struct spirv_compiler_fns *compilers[] = {
#if HAVE_SHADERC
[SPIRV_SHADERC] = &spirv_shaderc,
#endif
};
static const struct m_opt_choice_alternatives compiler_choices[] = {
{"auto", SPIRV_AUTO},
#if HAVE_SHADERC
{"shaderc", SPIRV_SHADERC},
#endif
{0}
};
struct spirv_opts {
int compiler;
};
#define OPT_BASE_STRUCT struct spirv_opts
const struct m_sub_options spirv_conf = {
.opts = (const struct m_option[]) {
{"spirv-compiler", OPT_CHOICE_C(compiler, compiler_choices)},
{0}
},
.size = sizeof(struct spirv_opts),
};
bool spirv_compiler_init(struct ra_ctx *ctx)
{
void *tmp = talloc_new(NULL);
struct spirv_opts *opts = mp_get_config_group(tmp, ctx->global, &spirv_conf);
int compiler = opts->compiler;
talloc_free(tmp);
for (int i = SPIRV_AUTO+1; i < MP_ARRAY_SIZE(compilers); i++) {
if (compiler != SPIRV_AUTO && i != compiler)
continue;
if (!compilers[i])
continue;
ctx->spirv = talloc_zero(ctx, struct spirv_compiler);
ctx->spirv->log = ctx->log,
ctx->spirv->fns = compilers[i];
const char *name = m_opt_choice_str(compiler_choices, i);
strncpy(ctx->spirv->name, name, sizeof(ctx->spirv->name) - 1);
MP_VERBOSE(ctx, "Initializing SPIR-V compiler '%s'\n", name);
if (ctx->spirv->fns->init(ctx))
return true;
talloc_free(ctx->spirv);
ctx->spirv = NULL;
}
MP_ERR(ctx, "Failed initializing SPIR-V compiler!\n");
return false;
}