Signed-off-by: Atharva Nimbalkar atharvakn@gmail.com --- libs/vkd3d-shader/glsl.c | 23 ++++++++++++++++++++++- libs/vkd3d-shader/vkd3d_shader_main.c | 2 +- libs/vkd3d-shader/vkd3d_shader_private.h | 3 ++- 3 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/libs/vkd3d-shader/glsl.c b/libs/vkd3d-shader/glsl.c index ee2acdb..d34b5e8 100644 --- a/libs/vkd3d-shader/glsl.c +++ b/libs/vkd3d-shader/glsl.c @@ -20,13 +20,15 @@
struct vkd3d_glsl_generator { + struct vkd3d_shader_version version; struct vkd3d_string_buffer buffer; struct vkd3d_shader_location location; struct vkd3d_shader_message_context *message_context; bool failed; };
-struct vkd3d_glsl_generator *vkd3d_glsl_generator_create(const struct vkd3d_shader_compile_info *compile_info, +struct vkd3d_glsl_generator *vkd3d_glsl_generator_create(const struct vkd3d_shader_version *version, + const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_message_context *message_context) { struct vkd3d_glsl_generator *generator; @@ -35,6 +37,7 @@ struct vkd3d_glsl_generator *vkd3d_glsl_generator_create(const struct vkd3d_shad return NULL;
memset(generator, 0, sizeof(*generator)); + generator->version = *version; generator->location.source_name = compile_info->source_name; generator->location.line = 2; /* Line 1 is the version token. */ generator->message_context = message_context; @@ -54,6 +57,21 @@ static void VKD3D_PRINTF_FUNC(3, 4) vkd3d_glsl_compiler_error( return; }
+static void shader_glsl_ret(struct vkd3d_glsl_generator *generator, + const struct vkd3d_shader_instruction *ins) +{ + const struct vkd3d_shader_version *version = &generator->version; + + /* + * TODO: Implement in_subroutine + * TODO: shader_glsl_generate_shader_epilogue(generator); + */ + if (version->major >= 4) + { + vkd3d_string_buffer_printf(&generator->buffer, "return;\n"); + } +} + static void vkd3d_glsl_handle_instruction(struct vkd3d_glsl_generator *generator, const struct vkd3d_shader_instruction *instruction) { @@ -62,6 +80,9 @@ static void vkd3d_glsl_handle_instruction(struct vkd3d_glsl_generator *generator case VKD3DSIH_DCL_INPUT: case VKD3DSIH_DCL_OUTPUT_SIV: break; + case VKD3DSIH_RET: + shader_glsl_ret(generator, instruction); + break; default: vkd3d_glsl_compiler_error(generator, VKD3D_SHADER_ERROR_GLSL_INTERNAL, diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index d2182e1..16994d2 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -1036,7 +1036,7 @@ static int compile_dxbc_tpf(const struct vkd3d_shader_compile_info *compile_info { struct vkd3d_glsl_generator *glsl_generator;
- if (!(glsl_generator = vkd3d_glsl_generator_create(compile_info, message_context))) + if (!(glsl_generator = vkd3d_glsl_generator_create(&parser.shader_version, compile_info, message_context))) { ERR("Failed to create GLSL generator.\n"); vkd3d_shader_parser_destroy(&parser); diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index 3863797..9efa598 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -986,7 +986,8 @@ int shader_parse_input_signature(const void *dxbc, size_t dxbc_length,
struct vkd3d_glsl_generator;
-struct vkd3d_glsl_generator *vkd3d_glsl_generator_create(const struct vkd3d_shader_compile_info *compile_info, +struct vkd3d_glsl_generator *vkd3d_glsl_generator_create(const struct vkd3d_shader_version *version, + const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_message_context *message_context); int vkd3d_glsl_generator_generate(void *parser_data, const uint32_t *parser_ptr, struct vkd3d_glsl_generator *generator,