Module: vkd3d Branch: master Commit: 70cfd58be6e012fc36016ab34edce7c5c6c863b1 URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/70cfd58be6e012fc36016ab34edce7...
Author: Zebediah Figura zfigura@codeweavers.com Date: Sat Aug 6 18:39:40 2022 -0500
vkd3d-shader/spirv: Introduce a spirv_compile() helper.
---
libs/vkd3d-shader/spirv.c | 29 ++++++++++++++++++++++++++--- libs/vkd3d-shader/vkd3d_shader_main.c | 13 +------------ libs/vkd3d-shader/vkd3d_shader_private.h | 12 +++--------- 3 files changed, 30 insertions(+), 24 deletions(-)
diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index ddd77ffb..e0b39420 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -2310,7 +2310,9 @@ static const char *spirv_compiler_get_entry_point_name(const struct spirv_compil return info && info->entry_point ? info->entry_point : "main"; }
-struct spirv_compiler *spirv_compiler_create(const struct vkd3d_shader_version *shader_version, +static void spirv_compiler_destroy(struct spirv_compiler *compiler); + +static struct spirv_compiler *spirv_compiler_create(const struct vkd3d_shader_version *shader_version, const struct vkd3d_shader_desc *shader_desc, const struct vkd3d_shader_compile_info *compile_info, const struct vkd3d_shader_scan_descriptor_info *scan_descriptor_info, struct vkd3d_shader_message_context *message_context, const struct vkd3d_shader_location *location) @@ -9823,7 +9825,7 @@ static int spirv_compiler_handle_instruction(struct spirv_compiler *compiler, return ret; }
-int spirv_compiler_generate_spirv(struct spirv_compiler *compiler, +static int spirv_compiler_generate_spirv(struct spirv_compiler *compiler, const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_parser *parser, struct vkd3d_shader_code *spirv) { @@ -9916,7 +9918,28 @@ int spirv_compiler_generate_spirv(struct spirv_compiler *compiler, return VKD3D_OK; }
-void spirv_compiler_destroy(struct spirv_compiler *compiler) +int spirv_compile(struct vkd3d_shader_parser *parser, + const struct vkd3d_shader_scan_descriptor_info *scan_descriptor_info, + const struct vkd3d_shader_compile_info *compile_info, + struct vkd3d_shader_code *out, struct vkd3d_shader_message_context *message_context) +{ + struct spirv_compiler *spirv_compiler; + int ret; + + if (!(spirv_compiler = spirv_compiler_create(&parser->shader_version, &parser->shader_desc, + compile_info, scan_descriptor_info, message_context, &parser->location))) + { + ERR("Failed to create SPIR-V compiler.\n"); + return VKD3D_ERROR; + } + + ret = spirv_compiler_generate_spirv(spirv_compiler, compile_info, parser, out); + + spirv_compiler_destroy(spirv_compiler); + return ret; +} + +static void spirv_compiler_destroy(struct spirv_compiler *compiler) { vkd3d_free(compiler->control_flow_info);
diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index 732d1cdc..b2b885aa 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -1173,7 +1173,6 @@ static int compile_dxbc_tpf(const struct vkd3d_shader_compile_info *compile_info { struct vkd3d_shader_scan_descriptor_info scan_descriptor_info; struct vkd3d_shader_compile_info scan_info; - struct spirv_compiler *spirv_compiler; struct vkd3d_shader_parser *parser; int ret;
@@ -1223,18 +1222,8 @@ static int compile_dxbc_tpf(const struct vkd3d_shader_compile_info *compile_info return ret; }
- if (!(spirv_compiler = spirv_compiler_create(&parser->shader_version, &parser->shader_desc, - compile_info, &scan_descriptor_info, message_context, &parser->location))) - { - ERR("Failed to create DXBC compiler.\n"); - vkd3d_shader_parser_destroy(parser); - vkd3d_shader_free_scan_descriptor_info(&scan_descriptor_info); - return VKD3D_ERROR; - } - - ret = spirv_compiler_generate_spirv(spirv_compiler, compile_info, parser, out); + ret = spirv_compile(parser, &scan_descriptor_info, compile_info, out, message_context);
- spirv_compiler_destroy(spirv_compiler); vkd3d_shader_parser_destroy(parser); vkd3d_shader_free_scan_descriptor_info(&scan_descriptor_info); return ret; diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index e2891de2..b048d5ef 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -1150,16 +1150,10 @@ void vkd3d_glsl_generator_destroy(struct vkd3d_glsl_generator *generator);
#define SPIRV_MAX_SRC_COUNT 6
-struct spirv_compiler; - -struct spirv_compiler *spirv_compiler_create(const struct vkd3d_shader_version *shader_version, - const struct vkd3d_shader_desc *shader_desc, const struct vkd3d_shader_compile_info *compile_info, +int spirv_compile(struct vkd3d_shader_parser *parser, const struct vkd3d_shader_scan_descriptor_info *scan_descriptor_info, - struct vkd3d_shader_message_context *message_context, const struct vkd3d_shader_location *location); -int spirv_compiler_generate_spirv(struct spirv_compiler *compiler, - const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_parser *parser, - struct vkd3d_shader_code *spirv); -void spirv_compiler_destroy(struct spirv_compiler *compiler); + const struct vkd3d_shader_compile_info *compile_info, + struct vkd3d_shader_code *out, struct vkd3d_shader_message_context *message_context);
void vkd3d_compute_dxbc_checksum(const void *dxbc, size_t size, uint32_t checksum[4]);