From c2eb563e503c787ab63b79971e4c462a2225e08d Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Tue, 23 Apr 2024 21:38:06 +0200 Subject: [PATCH] vkd3d-shader/fx: Skip uniform copy logic for global variables. --- libs/vkd3d-shader/fx.c | 14 ++++++++++---- libs/vkd3d-shader/hlsl.h | 1 - libs/vkd3d-shader/hlsl_codegen.c | 17 +++++------------ 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/libs/vkd3d-shader/fx.c b/libs/vkd3d-shader/fx.c index fae9d791..07c78528 100644 --- a/libs/vkd3d-shader/fx.c +++ b/libs/vkd3d-shader/fx.c @@ -169,7 +169,7 @@ static void fx_write_context_init(struct hlsl_ctx *ctx, const struct fx_write_co struct fx_write_context *fx) { unsigned int version = ctx->profile->major_version; - struct hlsl_block block; + struct hlsl_ir_var *var; memset(fx, 0, sizeof(*fx)); @@ -197,9 +197,15 @@ static void fx_write_context_init(struct hlsl_ctx *ctx, const struct fx_write_co fx->child_effect = fx->ops->are_child_effects_supported && ctx->child_effect; fx->include_empty_buffers = version == 4 && ctx->include_empty_buffers; - hlsl_block_init(&block); - hlsl_prepend_global_uniform_copy(fx->ctx, &block); - hlsl_block_cleanup(&block); + LIST_FOR_EACH_ENTRY(var, &ctx->globals->vars, struct hlsl_ir_var, scope_entry) + { + if (var->storage_modifiers & HLSL_STORAGE_UNIFORM) + { + list_add_tail(&ctx->extern_vars, &var->extern_entry); + var->is_uniform = 1; + } + } + hlsl_calculate_buffer_offsets(fx->ctx); } diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 556d6b5f..4e33c1bd 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -1400,7 +1400,6 @@ unsigned int hlsl_type_get_sm4_offset(const struct hlsl_type *type, unsigned int bool hlsl_types_are_equal(const struct hlsl_type *t1, const struct hlsl_type *t2); void hlsl_calculate_buffer_offsets(struct hlsl_ctx *ctx); -void hlsl_prepend_global_uniform_copy(struct hlsl_ctx *ctx, struct hlsl_block *block); const struct hlsl_type *hlsl_get_multiarray_element_type(const struct hlsl_type *type); unsigned int hlsl_get_multiarray_size(const struct hlsl_type *type); diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index e0254ef4..8882deaf 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -5314,17 +5314,6 @@ static void remove_unreachable_code(struct hlsl_ctx *ctx, struct hlsl_block *bod } } -void hlsl_prepend_global_uniform_copy(struct hlsl_ctx *ctx, struct hlsl_block *body) -{ - struct hlsl_ir_var *var; - - LIST_FOR_EACH_ENTRY(var, &ctx->globals->vars, struct hlsl_ir_var, scope_entry) - { - if (var->storage_modifiers & HLSL_STORAGE_UNIFORM) - prepend_uniform_copy(ctx, body, var); - } -} - int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func, enum vkd3d_shader_target_type target_type, struct vkd3d_shader_code *out) { @@ -5353,7 +5342,11 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry lower_ir(ctx, lower_matrix_swizzles, body); lower_ir(ctx, lower_index_loads, body); - hlsl_prepend_global_uniform_copy(ctx, body); + LIST_FOR_EACH_ENTRY(var, &ctx->globals->vars, struct hlsl_ir_var, scope_entry) + { + if (var->storage_modifiers & HLSL_STORAGE_UNIFORM) + prepend_uniform_copy(ctx, body, var); + } for (i = 0; i < entry_func->parameters.count; ++i) {