Signed-off-by: Francisco Casas fcasas@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 103 ++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 61 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 9cb14f52..547eb00b 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1476,14 +1476,6 @@ static void struct_var_initializer(struct hlsl_ctx *ctx, struct hlsl_ir_var *var struct hlsl_struct_field *field; unsigned int i = 0;
- if (initializer_size(initializer) != hlsl_type_component_count(type)) - { - hlsl_error(ctx, &var->loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT, - "Expected %u components in initializer, but got %u.", - hlsl_type_component_count(type), initializer_size(initializer)); - return; - } - LIST_FOR_EACH_ENTRY(field, type->e.elements, struct hlsl_struct_field, entry) { struct hlsl_ir_node *node = initializer->args[i]; @@ -1510,6 +1502,28 @@ static void struct_var_initializer(struct hlsl_ctx *ctx, struct hlsl_ir_var *var } }
+static void initialize_generic_var(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, + struct parse_initializer *initializer, unsigned int reg_offset, struct hlsl_type *type, + unsigned int *initializer_offset) +{ + if (type->type <= HLSL_CLASS_LAST_NUMERIC) + { + initialize_numeric_var(ctx, var, initializer, reg_offset, type, initializer_offset); + } + else if (type->type == HLSL_CLASS_STRUCT) + { + struct_var_initializer(ctx, var, initializer); + } + else if (type->type == HLSL_CLASS_ARRAY) + { + hlsl_fixme(ctx, &var->loc, "Initializers for arrays not supported yet."); + } + else if (type->type == HLSL_CLASS_OBJECT) + { + hlsl_fixme(ctx, &var->loc, "Initializers for objects not supported yet."); + } +} + static void free_parse_variable_def(struct parse_variable_def *v) { free_parse_initializer(&v->initializer); @@ -1633,69 +1647,36 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t
if (v->initializer.args_count) { - unsigned int size = initializer_size(&v->initializer); - - if (type->type <= HLSL_CLASS_LAST_NUMERIC && v->initializer.args_count != 1 - && type->dimx * type->dimy != size) - { - hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT, - "Expected %u components in numeric initializer, but got %u.", - type->dimx * type->dimy, v->initializer.args_count); - free_parse_initializer(&v->initializer); - vkd3d_free(v); - continue; - } - if ((type->type == HLSL_CLASS_STRUCT || type->type == HLSL_CLASS_ARRAY) - && hlsl_type_component_count(type) != size) - { - hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT, - "Expected %u components in initializer, but got %u.", hlsl_type_component_count(type), size); - free_parse_initializer(&v->initializer); - vkd3d_free(v); - continue; - } - - if (type->type == HLSL_CLASS_STRUCT) - { - struct_var_initializer(ctx, var, &v->initializer); - list_move_tail(statements_list, v->initializer.instrs); - - free_parse_initializer(&v->initializer); - vkd3d_free(v); - continue; - } - if (type->type > HLSL_CLASS_LAST_NUMERIC) - { - FIXME("Initializers for non scalar/struct variables not supported yet.\n"); - free_parse_initializer(&v->initializer); - if (v->arrays.count) - vkd3d_free(v->arrays.sizes); - vkd3d_free(v); - continue; - } - if (v->arrays.count) - { - hlsl_fixme(ctx, &v->loc, "Array initializer."); - free_parse_initializer(&v->initializer); - vkd3d_free(v->arrays.sizes); - vkd3d_free(v); - continue; - } - if (v->initializer.args_count > 1) { + unsigned int size = initializer_size(&v->initializer); unsigned int initializer_offset = 0;
- flatten_parse_initializer(ctx, &v->initializer); - if (v->initializer.args_count != size) + if (hlsl_type_component_count(type) != size) { - hlsl_fixme(ctx, &v->loc, "Could not flatten initializer."); + hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT, + "Expected %u components in initializer, but got %u.", hlsl_type_component_count(type), size); free_parse_initializer(&v->initializer); + if (v->arrays.count) + vkd3d_free(v->arrays.sizes); vkd3d_free(v); continue; }
- initialize_numeric_var(ctx, var, &v->initializer, 0, type, &initializer_offset); + if (type->type <= HLSL_CLASS_LAST_NUMERIC) + { + flatten_parse_initializer(ctx, &v->initializer); + if (v->initializer.args_count != size) + { + hlsl_fixme(ctx, &v->loc, "Could not flatten initializer."); + free_parse_initializer(&v->initializer); + if (v->arrays.count) + vkd3d_free(v->arrays.sizes); + vkd3d_free(v); + continue; + } + } + initialize_generic_var(ctx, var, &v->initializer, 0, type, &initializer_offset); } else {
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- Again, a few minor comments you might want to address later.
Il 15/02/22 21:17, Francisco Casas ha scritto:
@@ -1633,69 +1647,36 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t
if (v->initializer.args_count) {
unsigned int size = initializer_size(&v->initializer);
if (type->type <= HLSL_CLASS_LAST_NUMERIC && v->initializer.args_count != 1
&& type->dimx * type->dimy != size)
{
hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT,
"Expected %u components in numeric initializer, but got %u.",
type->dimx * type->dimy, v->initializer.args_count);
free_parse_initializer(&v->initializer);
vkd3d_free(v);
continue;
}
if ((type->type == HLSL_CLASS_STRUCT || type->type == HLSL_CLASS_ARRAY)
&& hlsl_type_component_count(type) != size)
{
hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT,
"Expected %u components in initializer, but got %u.", hlsl_type_component_count(type), size);
free_parse_initializer(&v->initializer);
vkd3d_free(v);
continue;
}
if (type->type == HLSL_CLASS_STRUCT)
{
struct_var_initializer(ctx, var, &v->initializer);
list_move_tail(statements_list, v->initializer.instrs);
free_parse_initializer(&v->initializer);
vkd3d_free(v);
continue;
}
if (type->type > HLSL_CLASS_LAST_NUMERIC)
{
FIXME("Initializers for non scalar/struct variables not supported yet.\n");
free_parse_initializer(&v->initializer);
if (v->arrays.count)
vkd3d_free(v->arrays.sizes);
vkd3d_free(v);
continue;
}
if (v->arrays.count)
{
hlsl_fixme(ctx, &v->loc, "Array initializer.");
free_parse_initializer(&v->initializer);
vkd3d_free(v->arrays.sizes);
vkd3d_free(v);
continue;
}
if (v->initializer.args_count > 1) {
The flow structure here is a bit funny: instead of
if (count != 0) { if (count > 1) ... else ... }
I'd find more logical
if (count == 1) ... else if (count > 1) ...
(main point here is not introducing a useless embedding level, not really the case order)
initialize_numeric_var(ctx, var, &v->initializer, 0, type, &initializer_offset);
if (type->type <= HLSL_CLASS_LAST_NUMERIC)
{
flatten_parse_initializer(ctx, &v->initializer);
if (v->initializer.args_count != size)
{
hlsl_fixme(ctx, &v->loc, "Could not flatten initializer.");
free_parse_initializer(&v->initializer);
if (v->arrays.count)
vkd3d_free(v->arrays.sizes);
Here there is a missing indentation.
BTW, this gadget "if (count) free(sizes)" appears frequently. But I guess that if count is zero, then you can assume that sizes is NULL. If so, you don't need to guard the call to free(): free(NULL) is a no-op.
Thanks, Giovanni.