From db80f09c7ad34c907eab700d5550319d8ae71a2d Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Thu, 3 Jul 2025 02:41:14 +0200 Subject: [PATCH] vkd3d-shader/hlsl: Don't create a temporary copy for a uniform if one already exists. This can currently never happen, because we only ever process each uniform once. However, this will change once we support compiling multiple shaders in effects. --- libs/vkd3d-shader/hlsl_codegen.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 1d06ffd61..4fd86881a 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -186,30 +186,34 @@ static void prepend_uniform_copy(struct hlsl_ctx *ctx, struct hlsl_block *block, { struct hlsl_ir_node *store; struct hlsl_ir_load *load; - struct hlsl_ir_var *temp; - char *new_name; uniform->is_uniform = 1; list_add_tail(&ctx->extern_vars, &uniform->extern_entry); - if (!(new_name = hlsl_sprintf_alloc(ctx, "", uniform->name))) - return; - - if (!(temp = hlsl_new_var(ctx, new_name, uniform->data_type, - &uniform->loc, NULL, uniform->storage_modifiers, NULL))) + if (!uniform->temp_copy) { - vkd3d_free(new_name); - return; - } - list_add_tail(&ctx->dummy_scope->vars, &temp->scope_entry); + struct hlsl_ir_var *temp; + char *new_name; - uniform->temp_copy = temp; + if (!(new_name = hlsl_sprintf_alloc(ctx, "", uniform->name))) + return; + + if (!(temp = hlsl_new_var(ctx, new_name, uniform->data_type, + &uniform->loc, NULL, uniform->storage_modifiers, NULL))) + { + vkd3d_free(new_name); + return; + } + list_add_tail(&ctx->dummy_scope->vars, &temp->scope_entry); + + uniform->temp_copy = temp; + } if (!(load = hlsl_new_var_load(ctx, uniform, &uniform->loc))) return; list_add_head(&block->instrs, &load->node.entry); - if (!(store = hlsl_new_simple_store(ctx, temp, &load->node))) + if (!(store = hlsl_new_simple_store(ctx, uniform->temp_copy, &load->node))) return; list_add_after(&load->node.entry, &store->entry); }