From aefadb87b67f78ca88fbd993f0b1dd6cae91ec49 Mon Sep 17 00:00:00 2001 From: Francisco Casas Date: Thu, 14 Apr 2022 12:52:38 +0200 Subject: [PATCH] vkd3d-shader/hlsl: Support complex numeric initializers. Signed-off-by: Francisco Casas Signed-off-by: Giovanni Mascellani Signed-off-by: Henri Verbeet Signed-off-by: Zebediah Figura Signed-off-by: Alexandre Julliard --- libs/vkd3d-shader/hlsl.y | 47 ++++++++++++++++++++-- tests/hlsl-initializer-flatten.shader_test | 4 +- tests/hlsl-initializer-nested.shader_test | 2 +- tests/hlsl-initializer-numeric.shader_test | 8 ++-- 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index f0a74826..58d71ff6 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1447,6 +1447,39 @@ static bool add_increment(struct hlsl_ctx *ctx, struct list *instrs, bool decrem return true; } +static void initialize_numeric_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) +{ + unsigned int i; + + if (type->type == HLSL_CLASS_MATRIX) + hlsl_fixme(ctx, &var->loc, "Matrix initializer."); + + for (i = 0; i < type->dimx; i++) + { + struct hlsl_ir_store *store; + struct hlsl_ir_constant *c; + struct hlsl_ir_node *node; + + node = initializer->args[*initializer_offset]; + *initializer_offset += 1; + + if (!(node = add_implicit_conversion(ctx, initializer->instrs, node, + hlsl_get_scalar_type(ctx, type->base_type), &node->loc))) + return; + + if (!(c = hlsl_new_uint_constant(ctx, reg_offset + i, &node->loc))) + return; + list_add_tail(initializer->instrs, &c->node.entry); + + if (!(store = hlsl_new_store(ctx, var, &c->node, node, 0, node->loc))) + return; + + list_add_tail(initializer->instrs, &store->node.entry); + } +} + static void struct_var_initializer(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, struct parse_initializer *initializer) { @@ -1612,6 +1645,7 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t if (v->initializer.braces) { unsigned int size = initializer_size(&v->initializer); + unsigned int initializer_offset = 0; if (type->type <= HLSL_CLASS_LAST_NUMERIC && type->dimx * type->dimy != size) { @@ -1647,10 +1681,15 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t } else { - hlsl_fixme(ctx, &v->loc, "Complex initializer."); - free_parse_initializer(&v->initializer); - vkd3d_free(v); - continue; + if (v->initializer.args_count != size) + { + hlsl_fixme(ctx, &v->loc, "Flatten initializer."); + free_parse_initializer(&v->initializer); + vkd3d_free(v); + continue; + } + + initialize_numeric_var(ctx, var, &v->initializer, 0, type, &initializer_offset); } } else diff --git a/tests/hlsl-initializer-flatten.shader_test b/tests/hlsl-initializer-flatten.shader_test index 439ead5e..3a430e0d 100644 --- a/tests/hlsl-initializer-flatten.shader_test +++ b/tests/hlsl-initializer-flatten.shader_test @@ -37,8 +37,8 @@ float4 main() : sv_target } [test] -todo draw quad -probe all rgba (40, 10, 20, 30) +draw quad +todo probe all rgba (40, 10, 20, 30) [pixel shader] diff --git a/tests/hlsl-initializer-nested.shader_test b/tests/hlsl-initializer-nested.shader_test index 0204afc9..bcb37cf4 100644 --- a/tests/hlsl-initializer-nested.shader_test +++ b/tests/hlsl-initializer-nested.shader_test @@ -6,7 +6,7 @@ float4 main() : sv_target } [test] -todo draw quad +draw quad probe all rgba (1, 2, 3, 4) diff --git a/tests/hlsl-initializer-numeric.shader_test b/tests/hlsl-initializer-numeric.shader_test index 92117591..40576887 100644 --- a/tests/hlsl-initializer-numeric.shader_test +++ b/tests/hlsl-initializer-numeric.shader_test @@ -6,7 +6,7 @@ float4 main() : sv_target } [test] -todo draw quad +draw quad probe all rgba (1.0, 2.0, 3.0, 4.0) 4 @@ -18,7 +18,7 @@ float4 main() : sv_target } [test] -todo draw quad +draw quad probe all rgba (1.0, 2.0, 3.0, 4.0) 4 @@ -31,7 +31,7 @@ float4 main() : sv_target } [test] -todo draw quad +draw quad probe all rgba (1.0, 2.0, 3.0, 4.0) 4 @@ -44,5 +44,5 @@ float4 main() : sv_target } [test] -todo draw quad +draw quad probe all rgba (10.1, 1.1, 1.2, 2.1) 4