Zebediah Figura : vkd3d-shader/hlsl: Lower scalar-to-vector casts to swizzles.

Alexandre Julliard julliard at winehq.org
Thu Dec 16 16:36:30 CST 2021


Module: vkd3d
Branch: master
Commit: 0a4e948453ff9beef0ee04b7fb22f52cccb57fb5
URL:    https://source.winehq.org/git/vkd3d.git/?a=commit;h=0a4e948453ff9beef0ee04b7fb22f52cccb57fb5

Author: Zebediah Figura <zfigura at codeweavers.com>
Date:   Wed Dec  1 17:14:55 2021 +0100

vkd3d-shader/hlsl: Lower scalar-to-vector casts to swizzles.

Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 Makefile.am                      |  1 -
 libs/vkd3d-shader/hlsl_codegen.c | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index be3d8ec..4010533 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -290,7 +290,6 @@ XFAIL_TESTS = \
 	tests/conditional.shader_test \
 	tests/hlsl-array-dimension.shader_test \
 	tests/hlsl-bool-cast.shader_test \
-	tests/hlsl-comma.shader_test \
 	tests/hlsl-cross.shader_test \
 	tests/hlsl-duplicate-modifiers.shader_test \
 	tests/hlsl-for.shader_test \
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
index d3957f8..4e1d043 100644
--- a/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d-shader/hlsl_codegen.c
@@ -237,6 +237,43 @@ static void replace_node(struct hlsl_ir_node *old, struct hlsl_ir_node *new)
     hlsl_free_instr(old);
 }
 
+/* Lower casts from vec1 to vecN to swizzles. */
+static bool lower_broadcasts(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
+{
+    const struct hlsl_type *src_type, *dst_type;
+    struct hlsl_type *dst_scalar_type;
+    struct hlsl_ir_expr *cast;
+
+    if (instr->type != HLSL_IR_EXPR)
+        return false;
+    cast = hlsl_ir_expr(instr);
+    src_type = cast->operands[0].node->data_type;
+    dst_type = cast->node.data_type;
+
+    if (cast->op == HLSL_OP1_CAST
+            && src_type->type <= HLSL_CLASS_VECTOR && dst_type->type <= HLSL_CLASS_VECTOR
+            && src_type->dimx == 1)
+    {
+        struct hlsl_ir_swizzle *swizzle;
+        struct hlsl_ir_expr *new_cast;
+
+        dst_scalar_type = hlsl_get_scalar_type(ctx, dst_type->base_type);
+        /* We need to preserve the cast since it might be doing more than just
+         * turning the scalar into a vector. */
+        if (!(new_cast = hlsl_new_cast(ctx, cast->operands[0].node, dst_scalar_type, &cast->node.loc)))
+            return false;
+        list_add_after(&cast->node.entry, &new_cast->node.entry);
+        if (!(swizzle = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(X, X, X, X), dst_type->dimx, &new_cast->node, &cast->node.loc)))
+            return false;
+        list_add_after(&new_cast->node.entry, &swizzle->node.entry);
+
+        replace_node(&cast->node, &swizzle->node);
+        return true;
+    }
+
+    return false;
+}
+
 struct copy_propagation_value
 {
     struct hlsl_ir_node *node;
@@ -1624,6 +1661,7 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun
         append_output_var_copy(ctx, &body->instrs, entry_func->return_var);
     }
 
+    transform_ir(ctx, lower_broadcasts, body, NULL);
     while (transform_ir(ctx, fold_redundant_casts, body, NULL));
     do
     {




More information about the wine-cvs mailing list