19 #include <shaderc/shaderc.h>
26 size_t *
size,
const char *entrypoint,
29 int loglevel, err, warn,
ret;
31 shaderc_compilation_result_t res;
32 static const char *shdc_result[] = {
33 [shaderc_compilation_status_success] =
"success",
34 [shaderc_compilation_status_invalid_stage] =
"invalid stage",
35 [shaderc_compilation_status_compilation_error] =
"error",
36 [shaderc_compilation_status_internal_error] =
"internal error",
37 [shaderc_compilation_status_null_result_object] =
"no result",
38 [shaderc_compilation_status_invalid_assembly] =
"invalid assembly",
40 static const shaderc_shader_kind shdc_kind[] = {
41 [VK_SHADER_STAGE_VERTEX_BIT] = shaderc_glsl_vertex_shader,
42 [VK_SHADER_STAGE_FRAGMENT_BIT] = shaderc_glsl_fragment_shader,
43 [VK_SHADER_STAGE_COMPUTE_BIT] = shaderc_glsl_compute_shader,
46 shaderc_compile_options_t
opts = shaderc_compile_options_initialize();
51 shaderc_compile_options_set_target_env(
opts, shaderc_target_env_vulkan,
52 shaderc_env_version_vulkan_1_2);
53 shaderc_compile_options_set_target_spirv(
opts, shaderc_spirv_version_1_5);
54 shaderc_compile_options_set_optimization_level(
opts,
55 shaderc_optimization_level_performance);
57 res = shaderc_compile_into_spv((shaderc_compiler_t)
ctx->priv,
58 shd->
src.str, strlen(shd->
src.str),
59 shdc_kind[shd->
shader.stage],
61 shaderc_compile_options_release(
opts);
63 ret = shaderc_result_get_compilation_status(res);
64 err = shaderc_result_get_num_errors(res);
65 warn = shaderc_result_get_num_warnings(res);
66 message = shaderc_result_get_error_message(res);
74 av_log(avctx, loglevel,
"shaderc compile status '%s' (%d errors, %d warnings)\n",
80 *
data = (uint8_t *)shaderc_result_get_bytes(res);
81 *
size = shaderc_result_get_length(res);
89 if (!opaque || !*opaque)
92 shaderc_result_release((shaderc_compilation_result_t)*opaque);
105 shaderc_compiler_release((shaderc_compiler_t)
s->priv);
119 ret->priv = (
void *)shaderc_compiler_initialize();