From d396c4ce27a343e9668046c964eea238ff9041f6 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Tue, 29 Aug 2023 16:50:13 -0500 Subject: [PATCH] vkd3d-shader/hlsl: Store the internal name counter in struct hlsl_ctx. This is minutely more efficient than using a global variable and atomic instructions. --- libs/vkd3d-shader/hlsl.c | 3 +-- libs/vkd3d-shader/hlsl.h | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index a6747cd1..be5b4052 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1060,11 +1060,10 @@ struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *tem { struct vkd3d_string_buffer *string; struct hlsl_ir_var *var; - static LONG counter; if (!(string = hlsl_get_string_buffer(ctx))) return NULL; - vkd3d_string_buffer_printf(string, "<%s-%u>", template, InterlockedIncrement(&counter)); + vkd3d_string_buffer_printf(string, "<%s-%u>", template, ctx->internal_name_counter++); var = hlsl_new_synthetic_var_named(ctx, string->buffer, type, loc, true); hlsl_release_string_buffer(ctx, string); return var; diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 2f2f1f29..d1fd6fef 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -798,6 +798,9 @@ struct hlsl_ctx /* Pointer to the current function; changes as the parser reads the code. */ const struct hlsl_ir_function_decl *cur_function; + /* Counter for generating unique internal variable names. */ + unsigned int internal_name_counter; + /* Default matrix majority for matrix types. Can be set by a pragma within the HLSL source. */ unsigned int matrix_majority;