[PATCH vkd3d 6/6] vkd3d-shader/hlsl: Reroute initialization towards a generic variable initializer.
Giovanni Mascellani
gmascellani at codeweavers.com
Thu Feb 17 03:30:22 CST 2022
Signed-off-by: Giovanni Mascellani <gmascellani at 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.
More information about the wine-devel
mailing list