[PATCH vkd3d v3 6/6] vkd3d-shader/hlsl: Allow more implicit conversions between matrices and vectors.

Giovanni Mascellani gmascellani at codeweavers.com
Mon Oct 25 02:06:30 CDT 2021


HLSL seems to treat matrices 1xN or Nx1 as vectors when looking for
implicit conversions.

Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
---
 libs/vkd3d-shader/hlsl.y | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index 249d1bfd..a2e27b5d 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -240,14 +240,22 @@ static bool implicit_compatible_data_types(struct hlsl_type *t1, struct hlsl_typ
 
     if (t1->type == HLSL_CLASS_MATRIX || t2->type == HLSL_CLASS_MATRIX)
     {
-        if (t1->type == HLSL_CLASS_MATRIX && t2->type == HLSL_CLASS_MATRIX
-                && t1->dimx >= t2->dimx && t1->dimy >= t2->dimy)
-            return true;
+        if (t1->type == HLSL_CLASS_MATRIX && t2->type == HLSL_CLASS_MATRIX)
+            return t1->dimx >= t2->dimx && t1->dimy >= t2->dimy;
+
+        /* Matrix-vector conversion is apparently allowed if they have
+         * the same components count, or if the matrix is 1xN or Nx1
+         * and we are reducing the component count */
+        if (t1->type == HLSL_CLASS_VECTOR || t2->type == HLSL_CLASS_VECTOR)
+        {
+            if (hlsl_type_component_count(t1) == hlsl_type_component_count(t2))
+                return true;
+
+            if ((t1->type == HLSL_CLASS_VECTOR || t1->dimx == 1 || t1->dimy == 1) &&
+                    (t2->type == HLSL_CLASS_VECTOR || t2->dimx == 1 || t2->dimy == 1))
+                return hlsl_type_component_count(t1) >= hlsl_type_component_count(t2);
+        }
 
-        /* Matrix-vector conversion is apparently allowed if they have the same components count */
-        if ((t1->type == HLSL_CLASS_VECTOR || t2->type == HLSL_CLASS_VECTOR)
-                && hlsl_type_component_count(t1) == hlsl_type_component_count(t2))
-            return true;
         return false;
     }
 
-- 
2.33.0




More information about the wine-devel mailing list