/src/mpv/video/out/gpu/spirv.c
Line | Count | Source (jump to first uncovered line) |
1 | | #include "common/msg.h" |
2 | | #include "options/m_config.h" |
3 | | |
4 | | #include "spirv.h" |
5 | | #include "config.h" |
6 | | |
7 | | extern const struct spirv_compiler_fns spirv_shaderc; |
8 | | |
9 | | // in probe-order |
10 | | enum { |
11 | | SPIRV_AUTO = 0, |
12 | | SPIRV_SHADERC, // generally preferred, but not packaged everywhere |
13 | | }; |
14 | | |
15 | | static const struct spirv_compiler_fns *compilers[] = { |
16 | | #if HAVE_SHADERC |
17 | | [SPIRV_SHADERC] = &spirv_shaderc, |
18 | | #endif |
19 | | NULL |
20 | | }; |
21 | | |
22 | | static const struct m_opt_choice_alternatives compiler_choices[] = { |
23 | | {"auto", SPIRV_AUTO}, |
24 | | #if HAVE_SHADERC |
25 | | {"shaderc", SPIRV_SHADERC}, |
26 | | #endif |
27 | | {0} |
28 | | }; |
29 | | |
30 | | struct spirv_opts { |
31 | | int compiler; |
32 | | }; |
33 | | |
34 | | #define OPT_BASE_STRUCT struct spirv_opts |
35 | | const struct m_sub_options spirv_conf = { |
36 | | .opts = (const struct m_option[]) { |
37 | | {"spirv-compiler", OPT_CHOICE_C(compiler, compiler_choices)}, |
38 | | {0} |
39 | | }, |
40 | | .size = sizeof(struct spirv_opts), |
41 | | }; |
42 | | |
43 | | bool spirv_compiler_init(struct ra_ctx *ctx) |
44 | 0 | { |
45 | 0 | void *tmp = talloc_new(NULL); |
46 | 0 | struct spirv_opts *opts = mp_get_config_group(tmp, ctx->global, &spirv_conf); |
47 | 0 | int compiler = opts->compiler; |
48 | 0 | talloc_free(tmp); |
49 | |
|
50 | 0 | for (int i = SPIRV_AUTO+1; i < MP_ARRAY_SIZE(compilers); i++) { |
51 | 0 | if (compiler != SPIRV_AUTO && i != compiler) |
52 | 0 | continue; |
53 | 0 | if (!compilers[i]) |
54 | 0 | continue; |
55 | | |
56 | 0 | ctx->spirv = talloc_zero(ctx, struct spirv_compiler); |
57 | 0 | ctx->spirv->log = ctx->log, |
58 | 0 | ctx->spirv->fns = compilers[i]; |
59 | |
|
60 | 0 | const char *name = m_opt_choice_str(compiler_choices, i); |
61 | 0 | strncpy(ctx->spirv->name, name, sizeof(ctx->spirv->name) - 1); |
62 | 0 | MP_VERBOSE(ctx, "Initializing SPIR-V compiler '%s'\n", name); |
63 | 0 | if (ctx->spirv->fns->init(ctx)) |
64 | 0 | return true; |
65 | 0 | talloc_free(ctx->spirv); |
66 | 0 | ctx->spirv = NULL; |
67 | 0 | } |
68 | | |
69 | 0 | MP_ERR(ctx, "Failed initializing SPIR-V compiler!\n"); |
70 | 0 | return false; |
71 | 0 | } |