vkd3d-shader/spirv: Introduce a spirv_compile() helper.

This commit is contained in:
Zebediah Figura 2022-08-06 18:39:40 -05:00 committed by Alexandre Julliard
parent 24c1eb562f
commit 70cfd58be6
Notes: Alexandre Julliard 2023-04-06 22:23:38 +02:00
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/147
3 changed files with 30 additions and 24 deletions

View File

@ -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);

View File

@ -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_compile(parser, &scan_descriptor_info, compile_info, out, message_context);
ret = spirv_compiler_generate_spirv(spirv_compiler, compile_info, parser, out);
spirv_compiler_destroy(spirv_compiler);
vkd3d_shader_parser_destroy(parser);
vkd3d_shader_free_scan_descriptor_info(&scan_descriptor_info);
return ret;

View File

@ -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]);