[PATCH vkd3d v3 11/11] vkd3d-shader/hlsl: Parse matrix constructors.

Giovanni Mascellani gmascellani at codeweavers.com
Fri Apr 22 05:25:07 CDT 2022


Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
---
v2:
* Do not use the comma operator inside a "for" statement.
* Prepend "add_" to the name of functions that mutate the instruction stream.
* Add a vector and a matrix to the constructor test.
v3:
* Move the "idx++" expression in a dedicated statement.
* Rewritten in the same philosphy as Francisco's initializers work
---
 libs/vkd3d-shader/hlsl.y                      | 46 ++++++++++++-------
 tests/hlsl-matrix-indexing.shader_test        | 16 +++++++
 ...numeric-constructor-truncation.shader_test |  2 +-
 ...lsl-return-implicit-conversion.shader_test |  8 ++--
 4 files changed, 50 insertions(+), 22 deletions(-)

diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index 887bcdc8..f2384d64 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -2035,16 +2035,12 @@ static struct list *add_call(struct hlsl_ctx *ctx, const char *name,
 static struct list *add_constructor(struct hlsl_ctx *ctx, struct hlsl_type *type,
         struct parse_initializer *params, struct vkd3d_shader_location loc)
 {
-    unsigned int i, writemask_offset = 0;
-    struct hlsl_ir_store *store;
     static unsigned int counter;
+    unsigned int i, j, idx = 0;
     struct hlsl_ir_load *load;
     struct hlsl_ir_var *var;
     char name[23];
 
-    if (type->type == HLSL_CLASS_MATRIX)
-        hlsl_fixme(ctx, &loc, "Matrix constructor.");
-
     sprintf(name, "<constructor-%x>", counter++);
     if (!(var = hlsl_new_synthetic_var(ctx, name, type, loc)))
         return NULL;
@@ -2066,22 +2062,38 @@ static struct list *add_constructor(struct hlsl_ctx *ctx, struct hlsl_type *type
         }
         width = hlsl_type_component_count(arg->data_type);
 
-        if (width > 4)
+        for (j = 0; j < width; ++j)
         {
-            FIXME("Constructor argument with %u components.\n", width);
-            continue;
-        }
+            struct hlsl_ir_constant *src_offset_const, *dst_offset_const;
+            struct hlsl_type *src_type, *dst_type;
+            unsigned int src_offset, dst_offset;
+            struct hlsl_ir_node *converted;
+            struct hlsl_ir_store *store;
+            struct hlsl_ir_load *value;
 
-        if (!(arg = add_implicit_conversion(ctx, params->instrs, arg,
-                hlsl_get_vector_type(ctx, type->base_type, width), &arg->loc)))
-            continue;
+            src_offset = hlsl_compute_component_reg_offset(ctx, arg->data_type, j, &src_type, &arg->loc);
+            dst_offset = hlsl_compute_component_reg_offset(ctx, type, idx, &dst_type, &arg->loc);
 
-        if (!(store = hlsl_new_store(ctx, var, NULL, arg,
-                ((1u << width) - 1) << writemask_offset, arg->loc)))
-            return NULL;
-        list_add_tail(params->instrs, &store->node.entry);
+            if (!(src_offset_const = hlsl_new_uint_constant(ctx, src_offset, &loc)))
+                return NULL;
+            list_add_tail(params->instrs, &src_offset_const->node.entry);
 
-        writemask_offset += width;
+            if (!(dst_offset_const = hlsl_new_uint_constant(ctx, dst_offset, &loc)))
+                return NULL;
+            list_add_tail(params->instrs, &dst_offset_const->node.entry);
+
+            if (!(value = add_load(ctx, params->instrs, arg, &src_offset_const->node, src_type, loc)))
+                return NULL;
+
+            if (!(converted = add_implicit_conversion(ctx, params->instrs, &value->node, dst_type, &arg->loc)))
+                return NULL;
+
+            if (!(store = hlsl_new_store(ctx, var, &dst_offset_const->node, converted, 0, arg->loc)))
+                return NULL;
+            list_add_tail(params->instrs, &store->node.entry);
+
+            idx++;
+        }
     }
 
     if (!(load = hlsl_new_var_load(ctx, var, loc)))
diff --git a/tests/hlsl-matrix-indexing.shader_test b/tests/hlsl-matrix-indexing.shader_test
index a0a89829..9336a67a 100644
--- a/tests/hlsl-matrix-indexing.shader_test
+++ b/tests/hlsl-matrix-indexing.shader_test
@@ -60,3 +60,19 @@ uniform 0 float4 1.0 2.0 3.0 0.0
 uniform 4 float4 5.0 6.0 7.0 0.0
 draw quad
 probe all rgba (1.0, 3.0, 6.0, 7.0)
+
+[pixel shader]
+float4 main() : SV_TARGET
+{
+    float2x2 a = float2x2(11.0, 12.0, 13.0, 14.0);
+    float4x4 m = float4x4(1.0, 2.0, 3.0, 4.0,
+                          float3(5.0, 6.0, 7.0), 8.0,
+                          9.0, 10.0,
+                          a,
+                          15.0, 16.0);
+    return float4(m[0][0], m[1][0], m[1][2], m[2][3]);
+}
+
+[test]
+todo draw quad
+probe all rgba (1.0, 5.0, 7.0, 12.0)
diff --git a/tests/hlsl-numeric-constructor-truncation.shader_test b/tests/hlsl-numeric-constructor-truncation.shader_test
index 27768dcc..f18b34d6 100644
--- a/tests/hlsl-numeric-constructor-truncation.shader_test
+++ b/tests/hlsl-numeric-constructor-truncation.shader_test
@@ -29,5 +29,5 @@ float4 main() : sv_target
 }
 
 [test]
-todo draw quad
+draw quad
 probe all rgba (1.0, 2.0, 3.0, 5.0)
diff --git a/tests/hlsl-return-implicit-conversion.shader_test b/tests/hlsl-return-implicit-conversion.shader_test
index 38d21633..bf99d9cb 100644
--- a/tests/hlsl-return-implicit-conversion.shader_test
+++ b/tests/hlsl-return-implicit-conversion.shader_test
@@ -98,7 +98,7 @@ float4 main() : sv_target
 todo draw quad
 probe all rgba (0.4, 0.3, 0.2, 0.0)
 
-[pixel shader fail todo]
+[pixel shader fail]
 float3x1 func()
 {
     return float1x3(0.4, 0.3, 0.2);
@@ -109,7 +109,7 @@ float4 main() : sv_target
     return float4(func(), 0.0);
 }
 
-[pixel shader fail todo]
+[pixel shader fail]
 float1x3 func()
 {
     return float3x1(0.4, 0.3, 0.2);
@@ -191,7 +191,7 @@ float4 main() : sv_target
 todo draw quad
 probe all rgba (0.4, 0.3, 0.2, 0.0)
 
-[pixel shader fail todo]
+[pixel shader fail]
 float3x1 func()
 {
     return float1x4(0.4, 0.3, 0.2, 0.1);
@@ -217,7 +217,7 @@ float4 main() : sv_target
 todo draw quad
 probe all rgba (0.4, 0.3, 0.2, 0.0)
 
-[pixel shader fail todo]
+[pixel shader fail]
 float1x3 func()
 {
     return float4x1(0.4, 0.3, 0.2, 0.1);
-- 
2.35.2




More information about the wine-devel mailing list