From 9e3b8ec98a9e5cca1ea2e02018d7262a3f8a193b Mon Sep 17 00:00:00 2001 From: Feifan He Date: Sun, 20 Oct 2024 21:25:10 +0800 Subject: [PATCH] vkd3d-shader/msl: Output the generated shader code. --- libs/vkd3d-shader/msl.c | 19 +++++++++++++++---- libs/vkd3d-shader/vkd3d_shader_main.c | 2 +- libs/vkd3d-shader/vkd3d_shader_private.h | 3 ++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/libs/vkd3d-shader/msl.c b/libs/vkd3d-shader/msl.c index 0c31c09a..691cc759 100644 --- a/libs/vkd3d-shader/msl.c +++ b/libs/vkd3d-shader/msl.c @@ -39,6 +39,8 @@ struct msl_generator struct vkd3d_shader_message_context *message_context; unsigned int indent; const char *prefix; + bool failed; + const struct vkd3d_shader_interface_info *interface_info; const struct vkd3d_shader_scan_descriptor_info1 *descriptor_info; }; @@ -51,6 +53,7 @@ static void VKD3D_PRINTF_FUNC(3, 4) msl_compiler_error(struct msl_generator *gen va_start(args, fmt); vkd3d_shader_verror(gen->message_context, &gen->location, error, fmt, args); va_end(args); + gen->failed = true; } static const char *msl_get_prefix(enum vkd3d_shader_type type) @@ -778,7 +781,7 @@ static void msl_generate_entrypoint(struct msl_generator *gen) vkd3d_string_buffer_printf(gen->buffer, " return output;\n}\n"); } -static void msl_generator_generate(struct msl_generator *gen) +static int msl_generator_generate(struct msl_generator *gen, struct vkd3d_shader_code *out) { const struct vkd3d_shader_instruction_array *instructions = &gen->program->instructions; unsigned int i; @@ -829,6 +832,13 @@ static void msl_generator_generate(struct msl_generator *gen) if (TRACE_ON()) vkd3d_string_buffer_trace(gen->buffer); + + if (gen->failed) + return VKD3D_ERROR_INVALID_SHADER; + + vkd3d_shader_code_from_string_buffer(out, gen->buffer); + + return VKD3D_OK; } static void msl_generator_cleanup(struct msl_generator *gen) @@ -867,7 +877,8 @@ static int msl_generator_init(struct msl_generator *gen, struct vsir_program *pr int msl_compile(struct vsir_program *program, uint64_t config_flags, const struct vkd3d_shader_scan_descriptor_info1 *descriptor_info, - const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_message_context *message_context) + const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out, + struct vkd3d_shader_message_context *message_context) { struct msl_generator generator; int ret; @@ -879,8 +890,8 @@ int msl_compile(struct vsir_program *program, uint64_t config_flags, if ((ret = msl_generator_init(&generator, program, compile_info, descriptor_info, message_context)) < 0) return ret; - msl_generator_generate(&generator); + ret = msl_generator_generate(&generator, out); msl_generator_cleanup(&generator); - return VKD3D_ERROR_INVALID_SHADER; + return ret; } diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index 1bdd5aa5..94899d03 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -1680,7 +1680,7 @@ int vsir_program_compile(struct vsir_program *program, uint64_t config_flags, case VKD3D_SHADER_TARGET_MSL: if ((ret = vsir_program_scan(program, &scan_info, message_context, &scan_descriptor_info)) < 0) return ret; - ret = msl_compile(program, config_flags, &scan_descriptor_info, compile_info, message_context); + ret = msl_compile(program, config_flags, &scan_descriptor_info, compile_info, out, message_context); vkd3d_shader_free_scan_descriptor_info1(&scan_descriptor_info); break; diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index 90e7b0f4..c3f9dc2e 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -1658,7 +1658,8 @@ int spirv_compile(struct vsir_program *program, uint64_t config_flags, int msl_compile(struct vsir_program *program, uint64_t config_flags, const struct vkd3d_shader_scan_descriptor_info1 *descriptor_info, - const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_message_context *message_context); + const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out, + struct vkd3d_shader_message_context *message_context); enum vkd3d_md5_variant {