mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-12-15 08:03:30 -08:00
vkd3d-shader/hlsl: Store statically initialized constant scalars/vectors in ctx->static_initializers.
Constant numeric local variables can be used in places were literals are expected if they're initialized with a static expression. Storing such constant in ctx->static_initializers allows copy-prop to handle such cases properly.
This commit is contained in:
committed by
Henri Verbeet
parent
4a8eabf517
commit
13ee6d74ad
Notes:
Henri Verbeet
2025-11-24 19:12:24 +01:00
Approved-by: Elizabeth Figura (@zfigura) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Francisco Casas (@fcasas) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1529
@@ -544,16 +544,9 @@ static void check_loop_attributes(struct hlsl_ctx *ctx, const struct parse_attri
|
||||
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX, "Unroll attribute can't be used with 'fastopt' attribute.");
|
||||
}
|
||||
|
||||
static struct hlsl_default_value evaluate_static_expression(struct hlsl_ctx *ctx,
|
||||
struct hlsl_block *block, struct hlsl_type *dst_type, const struct vkd3d_shader_location *loc)
|
||||
static bool is_static_expression(struct hlsl_block *block)
|
||||
{
|
||||
struct hlsl_default_value ret = {0};
|
||||
struct hlsl_ir_node *node;
|
||||
struct hlsl_block expr;
|
||||
struct hlsl_src src;
|
||||
|
||||
if (node_from_block(block)->data_type->class == HLSL_CLASS_ERROR)
|
||||
return ret;
|
||||
|
||||
LIST_FOR_EACH_ENTRY(node, &block->instrs, struct hlsl_ir_node, entry)
|
||||
{
|
||||
@@ -582,12 +575,28 @@ static struct hlsl_default_value evaluate_static_expression(struct hlsl_ctx *ctx
|
||||
case HLSL_IR_SWITCH:
|
||||
case HLSL_IR_STATEBLOCK_CONSTANT:
|
||||
case HLSL_IR_SYNC:
|
||||
hlsl_error(ctx, &node->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX,
|
||||
"Expected literal expression.");
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static struct hlsl_default_value evaluate_static_expression(struct hlsl_ctx *ctx,
|
||||
struct hlsl_block *block, struct hlsl_type *dst_type, const struct vkd3d_shader_location *loc)
|
||||
{
|
||||
struct hlsl_default_value ret = {0};
|
||||
struct hlsl_ir_node *node;
|
||||
struct hlsl_block expr;
|
||||
struct hlsl_src src;
|
||||
|
||||
if (node_from_block(block)->data_type->class == HLSL_CLASS_ERROR)
|
||||
return ret;
|
||||
|
||||
if (!is_static_expression(block))
|
||||
hlsl_error(ctx, &node_from_block(block)->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX,
|
||||
"Expected literal expression.");
|
||||
|
||||
if (!hlsl_clone_block(ctx, &expr, &ctx->static_initializers))
|
||||
return ret;
|
||||
hlsl_block_add_block(&expr, block);
|
||||
@@ -2670,7 +2679,7 @@ static struct hlsl_block *initialize_vars(struct hlsl_ctx *ctx, struct list *var
|
||||
|
||||
if (v->initializer.args_count)
|
||||
{
|
||||
bool is_default_values_initializer;
|
||||
bool is_default_values_initializer, static_initialization;
|
||||
|
||||
is_default_values_initializer = (ctx->cur_buffer != ctx->globals_buffer)
|
||||
|| (var->storage_modifiers & HLSL_STORAGE_UNIFORM)
|
||||
@@ -2680,6 +2689,10 @@ static struct hlsl_block *initialize_vars(struct hlsl_ctx *ctx, struct list *var
|
||||
if (hlsl_type_is_shader(type))
|
||||
is_default_values_initializer = false;
|
||||
|
||||
static_initialization = var->storage_modifiers & HLSL_STORAGE_STATIC
|
||||
|| (var->data_type->modifiers & HLSL_MODIFIER_CONST
|
||||
&& is_static_expression(v->initializer.instrs));
|
||||
|
||||
if (is_default_values_initializer)
|
||||
{
|
||||
/* Default values might have been allocated already for another variable of the same name,
|
||||
@@ -2708,7 +2721,7 @@ static struct hlsl_block *initialize_vars(struct hlsl_ctx *ctx, struct list *var
|
||||
{
|
||||
hlsl_dump_var_default_values(var);
|
||||
}
|
||||
else if (var->storage_modifiers & HLSL_STORAGE_STATIC)
|
||||
else if (static_initialization)
|
||||
{
|
||||
hlsl_block_add_block(&ctx->static_initializers, v->initializer.instrs);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user