vkd3d-shader/hlsl: Initialize default values with braceless initializers.

It is hard to initialize default values on add_assignment() and calling
add_assignment() for initializers is not really necessary: the only
thing we need from it the implicit cast.
This commit is contained in:
Francisco Casas 2024-04-11 13:34:13 -04:00 committed by Henri Verbeet
parent e8dbc36bd2
commit 099a64aeb2
Notes: Henri Verbeet 2024-06-11 16:55:09 +02:00
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/787
2 changed files with 22 additions and 22 deletions

View File

@ -2418,7 +2418,11 @@ static struct hlsl_block *initialize_vars(struct hlsl_ctx *ctx, struct list *var
if (v->initializer.args_count) if (v->initializer.args_count)
{ {
bool is_default_values_initializer = (ctx->cur_buffer != ctx->globals_buffer) unsigned int store_index = 0;
bool is_default_values_initializer;
unsigned int size, k;
is_default_values_initializer = (ctx->cur_buffer != ctx->globals_buffer)
|| (var->storage_modifiers & HLSL_STORAGE_UNIFORM); || (var->storage_modifiers & HLSL_STORAGE_UNIFORM);
if (is_default_values_initializer) if (is_default_values_initializer)
@ -2431,12 +2435,18 @@ static struct hlsl_block *initialize_vars(struct hlsl_ctx *ctx, struct list *var
} }
} }
if (v->initializer.braces) if (!v->initializer.braces)
{ {
unsigned int size = initializer_size(&v->initializer); if (!(add_implicit_conversion(ctx, v->initializer.instrs, v->initializer.args[0], type, &v->loc)))
unsigned int store_index = 0; {
unsigned int k; free_parse_variable_def(v);
continue;
}
v->initializer.args[0] = node_from_block(v->initializer.instrs);
}
size = initializer_size(&v->initializer);
if (component_count != size) if (component_count != size)
{ {
hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT, hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT,
@ -2447,17 +2457,7 @@ static struct hlsl_block *initialize_vars(struct hlsl_ctx *ctx, struct list *var
for (k = 0; k < v->initializer.args_count; ++k) for (k = 0; k < v->initializer.args_count; ++k)
{ {
initialize_var_components(ctx, v->initializer.instrs, var, initialize_var_components(ctx, v->initializer.instrs, var, &store_index, v->initializer.args[k]);
&store_index, v->initializer.args[k]);
}
}
else
{
struct hlsl_ir_load *load = hlsl_new_var_load(ctx, var, &var->loc);
assert(v->initializer.args_count == 1);
hlsl_block_add_instr(v->initializer.instrs, &load->node);
add_assignment(ctx, v->initializer.instrs, &load->node, ASSIGN_OP_ASSIGN, v->initializer.args[0]);
} }
if (is_default_values_initializer) if (is_default_values_initializer)

View File

@ -21,7 +21,7 @@ todo(glsl) draw quad
probe all rgba (10, 20, 50, 60) probe all rgba (10, 20, 50, 60)
[pixel shader fail(sm<6) todo] [pixel shader fail(sm<6)]
float a = 7; float a = 7;
float4 b = a; // initial value must be a literal expression. float4 b = a; // initial value must be a literal expression.
@ -138,7 +138,7 @@ todo(glsl) draw quad
probe all rgba (10, 20, 50, 60) probe all rgba (10, 20, 50, 60)
[pixel shader fail(sm<6) todo] [pixel shader fail(sm<6)]
cbuffer buff cbuffer buff
{ {
float a = 7; float a = 7;