vkd3d-shader/glsl: Introduce glsl_compile().

This commit is contained in:
Henri Verbeet 2023-11-17 18:36:33 +01:00 committed by Alexandre Julliard
parent bdc096d437
commit 9b0d304f8f
Notes: Alexandre Julliard 2024-03-12 22:59:25 +01:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/710
3 changed files with 27 additions and 35 deletions

View File

@ -27,21 +27,6 @@ struct vkd3d_glsl_generator
bool failed; bool failed;
}; };
struct vkd3d_glsl_generator *vkd3d_glsl_generator_create(const struct vkd3d_shader_version *version,
struct vkd3d_shader_message_context *message_context)
{
struct vkd3d_glsl_generator *generator;
if (!(generator = vkd3d_malloc(sizeof(*generator))))
return NULL;
memset(generator, 0, sizeof(*generator));
generator->version = *version;
vkd3d_string_buffer_init(&generator->buffer);
generator->message_context = message_context;
return generator;
}
static void VKD3D_PRINTF_FUNC(3, 4) vkd3d_glsl_compiler_error( static void VKD3D_PRINTF_FUNC(3, 4) vkd3d_glsl_compiler_error(
struct vkd3d_glsl_generator *generator, struct vkd3d_glsl_generator *generator,
enum vkd3d_shader_error error, const char *fmt, ...) enum vkd3d_shader_error error, const char *fmt, ...)
@ -91,7 +76,7 @@ static void vkd3d_glsl_handle_instruction(struct vkd3d_glsl_generator *generator
} }
} }
int vkd3d_glsl_generator_generate(struct vkd3d_glsl_generator *generator, static int vkd3d_glsl_generator_generate(struct vkd3d_glsl_generator *generator,
struct vsir_program *program, struct vkd3d_shader_code *out) struct vsir_program *program, struct vkd3d_shader_code *out)
{ {
unsigned int i; unsigned int i;
@ -123,8 +108,29 @@ int vkd3d_glsl_generator_generate(struct vkd3d_glsl_generator *generator,
return VKD3D_OK; return VKD3D_OK;
} }
void vkd3d_glsl_generator_destroy(struct vkd3d_glsl_generator *generator) static void vkd3d_glsl_generator_cleanup(struct vkd3d_glsl_generator *gen)
{ {
vkd3d_string_buffer_cleanup(&generator->buffer); vkd3d_string_buffer_cleanup(&gen->buffer);
vkd3d_free(generator); }
static void vkd3d_glsl_generator_init(struct vkd3d_glsl_generator *gen,
const struct vkd3d_shader_version *version, struct vkd3d_shader_message_context *message_context)
{
memset(gen, 0, sizeof(*gen));
gen->version = *version;
vkd3d_string_buffer_init(&gen->buffer);
gen->message_context = message_context;
}
int glsl_compile(struct vsir_program *program, struct vkd3d_shader_code *out,
struct vkd3d_shader_message_context *message_context)
{
struct vkd3d_glsl_generator generator;
int ret;
vkd3d_glsl_generator_init(&generator, &program->shader_version, message_context);
ret = vkd3d_glsl_generator_generate(&generator, program, out);
vkd3d_glsl_generator_cleanup(&generator);
return ret;
} }

View File

@ -1554,7 +1554,6 @@ static int vkd3d_shader_parser_compile(struct vkd3d_shader_parser *parser,
{ {
struct vkd3d_shader_scan_descriptor_info1 scan_descriptor_info; struct vkd3d_shader_scan_descriptor_info1 scan_descriptor_info;
struct vsir_program *program = &parser->program; struct vsir_program *program = &parser->program;
struct vkd3d_glsl_generator *glsl_generator;
struct vkd3d_shader_compile_info scan_info; struct vkd3d_shader_compile_info scan_info;
int ret; int ret;
@ -1569,15 +1568,7 @@ static int vkd3d_shader_parser_compile(struct vkd3d_shader_parser *parser,
case VKD3D_SHADER_TARGET_GLSL: case VKD3D_SHADER_TARGET_GLSL:
if ((ret = scan_with_parser(&scan_info, message_context, &scan_descriptor_info, parser)) < 0) if ((ret = scan_with_parser(&scan_info, message_context, &scan_descriptor_info, parser)) < 0)
return ret; return ret;
if (!(glsl_generator = vkd3d_glsl_generator_create(&program->shader_version, message_context))) ret = glsl_compile(program, out, message_context);
{
ERR("Failed to create GLSL generator.\n");
vkd3d_shader_free_scan_descriptor_info1(&scan_descriptor_info);
return VKD3D_ERROR;
}
ret = vkd3d_glsl_generator_generate(glsl_generator, program, out);
vkd3d_glsl_generator_destroy(glsl_generator);
vkd3d_shader_free_scan_descriptor_info1(&scan_descriptor_info); vkd3d_shader_free_scan_descriptor_info1(&scan_descriptor_info);
break; break;

View File

@ -1504,13 +1504,8 @@ int shader_extract_from_dxbc(const struct vkd3d_shader_code *dxbc,
int shader_parse_input_signature(const struct vkd3d_shader_code *dxbc, int shader_parse_input_signature(const struct vkd3d_shader_code *dxbc,
struct vkd3d_shader_message_context *message_context, struct shader_signature *signature); struct vkd3d_shader_message_context *message_context, struct shader_signature *signature);
struct vkd3d_glsl_generator; int glsl_compile(struct vsir_program *program, struct vkd3d_shader_code *out,
struct vkd3d_glsl_generator *vkd3d_glsl_generator_create(const struct vkd3d_shader_version *version,
struct vkd3d_shader_message_context *message_context); struct vkd3d_shader_message_context *message_context);
int vkd3d_glsl_generator_generate(struct vkd3d_glsl_generator *generator,
struct vsir_program *program, struct vkd3d_shader_code *out);
void vkd3d_glsl_generator_destroy(struct vkd3d_glsl_generator *generator);
#define SPIRV_MAX_SRC_COUNT 6 #define SPIRV_MAX_SRC_COUNT 6