From 2170fdc6333b4fdbee82f79f9f017a40a5cc8c49 Mon Sep 17 00:00:00 2001 From: Atharva Nimbalkar Date: Mon, 23 Aug 2021 21:02:31 +0530 Subject: [PATCH] vkd3d-shader/glsl: Implement support for VKD3DSPR_TEMP registers. --- libs/vkd3d-shader/glsl.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/libs/vkd3d-shader/glsl.c b/libs/vkd3d-shader/glsl.c index c8d62ce5..10e12ea5 100644 --- a/libs/vkd3d-shader/glsl.c +++ b/libs/vkd3d-shader/glsl.c @@ -61,9 +61,18 @@ static void shader_glsl_print_indent(struct vkd3d_string_buffer *buffer, unsigne static void shader_glsl_print_register_name(struct vkd3d_string_buffer *buffer, struct vkd3d_glsl_generator *gen, const struct vkd3d_shader_register *reg) { - vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL, - "Internal compiler error: Unhandled register type %#x.", reg->type); - vkd3d_string_buffer_printf(buffer, "", reg->type); + switch (reg->type) + { + case VKD3DSPR_TEMP: + vkd3d_string_buffer_printf(buffer, "r[%u]", reg->idx[0].offset); + break; + + default: + vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL, + "Internal compiler error: Unhandled register type %#x.", reg->type); + vkd3d_string_buffer_printf(buffer, "", reg->type); + break; + } } static void shader_glsl_print_swizzle(struct vkd3d_string_buffer *buffer, uint32_t swizzle, uint32_t mask) @@ -228,6 +237,15 @@ static void vkd3d_glsl_handle_instruction(struct vkd3d_glsl_generator *gen, } } +static void shader_glsl_generate_declarations(struct vkd3d_glsl_generator *gen) +{ + const struct vsir_program *program = gen->program; + struct vkd3d_string_buffer *buffer = gen->buffer; + + if (program->temp_count) + vkd3d_string_buffer_printf(buffer, "vec4 r[%u];\n\n", program->temp_count); +} + static int vkd3d_glsl_generator_generate(struct vkd3d_glsl_generator *gen, struct vkd3d_shader_code *out) { const struct vkd3d_shader_instruction_array *instructions = &gen->program->instructions; @@ -241,6 +259,8 @@ static int vkd3d_glsl_generator_generate(struct vkd3d_glsl_generator *gen, struc vkd3d_string_buffer_printf(buffer, "/* Generated by %s. */\n\n", vkd3d_shader_get_version(NULL, NULL)); + shader_glsl_generate_declarations(gen); + vkd3d_string_buffer_printf(buffer, "void main()\n{\n"); ++gen->indent;