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,33 +2435,29 @@ 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;
if (component_count != size)
{ {
hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT,
"Expected %u components in initializer, but got %u.", component_count, size);
free_parse_variable_def(v); free_parse_variable_def(v);
continue; continue;
} }
for (k = 0; k < v->initializer.args_count; ++k) v->initializer.args[0] = node_from_block(v->initializer.instrs);
{
initialize_var_components(ctx, v->initializer.instrs, var,
&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); size = initializer_size(&v->initializer);
hlsl_block_add_instr(v->initializer.instrs, &load->node); if (component_count != size)
add_assignment(ctx, v->initializer.instrs, &load->node, ASSIGN_OP_ASSIGN, v->initializer.args[0]); {
hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT,
"Expected %u components in initializer, but got %u.", component_count, size);
free_parse_variable_def(v);
continue;
}
for (k = 0; k < v->initializer.args_count; ++k)
{
initialize_var_components(ctx, v->initializer.instrs, var, &store_index, v->initializer.args[k]);
} }
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;