19 #include <shaderc/shaderc.h>
25 size_t *
size,
const char *entrypoint,
28 int loglevel, err, warn,
ret;
30 shaderc_compilation_result_t res;
31 static const char *shdc_result[] = {
32 [shaderc_compilation_status_success] =
"success",
33 [shaderc_compilation_status_invalid_stage] =
"invalid stage",
34 [shaderc_compilation_status_compilation_error] =
"error",
35 [shaderc_compilation_status_internal_error] =
"internal error",
36 [shaderc_compilation_status_null_result_object] =
"no result",
37 [shaderc_compilation_status_invalid_assembly] =
"invalid assembly",
39 static const shaderc_shader_kind shdc_kind[] = {
40 [VK_SHADER_STAGE_VERTEX_BIT] = shaderc_glsl_vertex_shader,
41 [VK_SHADER_STAGE_FRAGMENT_BIT] = shaderc_glsl_fragment_shader,
42 [VK_SHADER_STAGE_COMPUTE_BIT] = shaderc_glsl_compute_shader,
45 shaderc_compile_options_t
opts = shaderc_compile_options_initialize();
49 shaderc_compile_options_set_target_env(
opts, shaderc_target_env_vulkan,
50 shaderc_env_version_vulkan_1_2);
51 shaderc_compile_options_set_target_spirv(
opts, shaderc_spirv_version_1_5);
52 shaderc_compile_options_set_optimization_level(
opts,
53 shaderc_optimization_level_performance);
55 res = shaderc_compile_into_spv((shaderc_compiler_t)
ctx->priv,
56 shd->
src.str, strlen(shd->
src.str),
57 shdc_kind[shd->
shader.stage],
59 shaderc_compile_options_release(
opts);
61 ret = shaderc_result_get_compilation_status(res);
62 err = shaderc_result_get_num_errors(res);
63 warn = shaderc_result_get_num_warnings(res);
64 message = shaderc_result_get_error_message(res);
72 av_log(avctx, loglevel,
"shaderc compile status '%s' (%d errors, %d warnings)\n",
78 *
data = (uint8_t *)shaderc_result_get_bytes(res);
79 *
size = shaderc_result_get_length(res);
87 if (!opaque || !*opaque)
90 shaderc_result_release((shaderc_compilation_result_t)*opaque);
103 shaderc_compiler_release((shaderc_compiler_t)
s->priv);
117 ret->priv = (
void *)shaderc_compiler_initialize();