Signed-off-by: Francisco Casas fcasas@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 98 +++++++++++++++------------------------- 1 file changed, 37 insertions(+), 61 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index a89e4432..69ae48a1 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1326,25 +1326,13 @@ static void numeric_var_initializer(struct hlsl_ctx *ctx, struct hlsl_ir_var *va } }
-static void struct_var_initializer(struct hlsl_ctx *ctx, struct list *list, struct hlsl_ir_var *var, +static void struct_var_initializer(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, struct parse_initializer *initializer) { struct hlsl_type *type = var->data_type; 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)); - free_parse_initializer(initializer); - return; - } - - list_move_tail(list, initializer->instrs); - vkd3d_free(initializer->instrs); - LIST_FOR_EACH_ENTRY(field, type->e.elements, struct hlsl_struct_field, entry) { struct hlsl_ir_node *node = initializer->args[i]; @@ -1358,19 +1346,41 @@ static void struct_var_initializer(struct hlsl_ctx *ctx, struct list *list, stru { if (!(c = hlsl_new_uint_constant(ctx, field->reg_offset, node->loc))) break; - list_add_tail(list, &c->node.entry); + list_add_tail(initializer->instrs, &c->node.entry);
if (!(store = hlsl_new_store(ctx, var, &c->node, node, 0, node->loc))) break; - list_add_tail(list, &store->node.entry); + list_add_tail(initializer->instrs, &store->node.entry); } else { hlsl_fixme(ctx, &node->loc, "Implicit cast in structure initializer."); } } +}
- vkd3d_free(initializer->args); +static void generic_var_initializer(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, + struct parse_variable_def *v, unsigned int reg_offset, struct hlsl_type *type, + unsigned int *initializer_i, struct list *instrs) +{ + if (type->type <= HLSL_CLASS_LAST_NUMERIC) + { + numeric_var_initializer(ctx, var, v, reg_offset, type, initializer_i, v->initializer.instrs); + } + else if (type->type == HLSL_CLASS_STRUCT) + { + struct_var_initializer(ctx, var, &v->initializer); + } + else if (type->type == HLSL_CLASS_ARRAY) + { + hlsl_fixme(ctx, &v->loc, "Initializers for arrays not supported yet."); + return; + } + else if (type->type == HLSL_CLASS_OBJECT) + { + hlsl_fixme(ctx, &var->loc, "Initializers for objects not supported yet.\n"); + return; + } }
static void free_parse_variable_def(struct parse_variable_def *v) @@ -1498,50 +1508,6 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t { unsigned int size = initializer_size(&v->initializer);
- if (type->type <= HLSL_CLASS_LAST_NUMERIC - && type->dimx * type->dimy != size && size != 1) - { - if (size < type->dimx * type->dimy) - { - 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, size); - 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, statements_list, var, &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); - 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 (type->type <= HLSL_CLASS_LAST_NUMERIC && size == 1) { struct hlsl_ir_load *load = hlsl_new_var_load(ctx, var, var->loc); @@ -1553,7 +1519,17 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t { unsigned int initializer_i = 0;
- numeric_var_initializer(ctx, var, v, 0, type, &initializer_i, v->initializer.instrs); + if (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->arrays.sizes); + vkd3d_free(v); + continue; + } + + generic_var_initializer(ctx, var, v, 0, type, &initializer_i, v->initializer.instrs); }
if (modifiers & HLSL_STORAGE_STATIC)
On 1/10/22 13:33, Francisco Casas wrote:
Signed-off-by: Francisco Casas fcasas@codeweavers.com
libs/vkd3d-shader/hlsl.y | 98 +++++++++++++++------------------------- 1 file changed, 37 insertions(+), 61 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index a89e4432..69ae48a1 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1326,25 +1326,13 @@ static void numeric_var_initializer(struct hlsl_ctx *ctx, struct hlsl_ir_var *va } }
-static void struct_var_initializer(struct hlsl_ctx *ctx, struct list *list, struct hlsl_ir_var *var, +static void struct_var_initializer(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, struct parse_initializer *initializer)
Getting rid of the "list" parameter is fine but should probably be a separate patch. Note that it also makes the "statements_list" variable redundant, so that should probably just be removed entirely.
{ struct hlsl_type *type = var->data_type; 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));
free_parse_initializer(initializer);
return;
- }
- list_move_tail(list, initializer->instrs);
- vkd3d_free(initializer->instrs);
LIST_FOR_EACH_ENTRY(field, type->e.elements, struct hlsl_struct_field, entry) { struct hlsl_ir_node *node = initializer->args[i];
@@ -1358,19 +1346,41 @@ static void struct_var_initializer(struct hlsl_ctx *ctx, struct list *list, stru { if (!(c = hlsl_new_uint_constant(ctx, field->reg_offset, node->loc))) break;
list_add_tail(list, &c->node.entry);
list_add_tail(initializer->instrs, &c->node.entry); if (!(store = hlsl_new_store(ctx, var, &c->node, node, 0, node->loc))) break;
list_add_tail(list, &store->node.entry);
list_add_tail(initializer->instrs, &store->node.entry); } else { hlsl_fixme(ctx, &node->loc, "Implicit cast in structure initializer."); } }
+}
- vkd3d_free(initializer->args);
+static void generic_var_initializer(struct hlsl_ctx *ctx, struct hlsl_ir_var *var,
struct parse_variable_def *v, unsigned int reg_offset, struct hlsl_type *type,
unsigned int *initializer_i, struct list *instrs)
+{
- if (type->type <= HLSL_CLASS_LAST_NUMERIC)
- {
numeric_var_initializer(ctx, var, v, reg_offset, type, initializer_i, v->initializer.instrs);
- }
- else if (type->type == HLSL_CLASS_STRUCT)
- {
struct_var_initializer(ctx, var, &v->initializer);
- }
- else if (type->type == HLSL_CLASS_ARRAY)
- {
hlsl_fixme(ctx, &v->loc, "Initializers for arrays not supported yet.");
return;
These "return" statements are redundant.
- }
- else if (type->type == HLSL_CLASS_OBJECT)
- {
hlsl_fixme(ctx, &var->loc, "Initializers for objects not supported yet.\n");
return;
- } }