Zebediah Figura : vkd3d-shader/hlsl: Cache matrix types.

Alexandre Julliard julliard at winehq.org
Fri Oct 1 18:00:41 CDT 2021


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

Author: Zebediah Figura <zfigura at codeweavers.com>
Date:   Mon Sep 27 20:51:46 2021 -0500

vkd3d-shader/hlsl: Cache matrix types.

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

---

 libs/vkd3d-shader/hlsl.c | 3 ++-
 libs/vkd3d-shader/hlsl.h | 4 ++--
 libs/vkd3d-shader/hlsl.y | 4 ++--
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index 14ad90c..fc6d1e4 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -200,7 +200,7 @@ static void hlsl_type_calculate_reg_size(struct hlsl_ctx *ctx, struct hlsl_type
     }
 }
 
-struct hlsl_type *hlsl_new_type(struct hlsl_ctx *ctx, const char *name, enum hlsl_type_class type_class,
+static struct hlsl_type *hlsl_new_type(struct hlsl_ctx *ctx, const char *name, enum hlsl_type_class type_class,
         enum hlsl_base_type base_type, unsigned dimx, unsigned dimy)
 {
     struct hlsl_type *type;
@@ -1658,6 +1658,7 @@ static void declare_predefined_types(struct hlsl_ctx *ctx)
                 sprintf(name, "%s%ux%u", names[bt], y, x);
                 type = hlsl_new_type(ctx, hlsl_strdup(ctx, name), HLSL_CLASS_MATRIX, bt, x, y);
                 hlsl_scope_add_type(ctx->globals, type);
+                ctx->builtin_types.matrix[bt][x - 1][y - 1] = type;
 
                 if (y == 1)
                 {
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index 7e62839..9686a49 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -459,6 +459,8 @@ struct hlsl_ctx
     {
         struct hlsl_type *scalar[HLSL_TYPE_LAST_SCALAR + 1];
         struct hlsl_type *vector[HLSL_TYPE_LAST_SCALAR + 1][4];
+        /* matrix[float][2][4] is a float4x2, i.e. dimx = 2, dimy = 4 */
+        struct hlsl_type *matrix[HLSL_TYPE_LAST_SCALAR + 1][4][4];
         struct hlsl_type *sampler[HLSL_SAMPLER_DIM_MAX + 1];
         struct hlsl_type *Void;
     } builtin_types;
@@ -653,8 +655,6 @@ struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned
         struct hlsl_ir_node *val, struct vkd3d_shader_location *loc);
 struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *name, struct hlsl_type *type,
         const struct vkd3d_shader_location loc);
-struct hlsl_type *hlsl_new_type(struct hlsl_ctx *ctx, const char *name, enum hlsl_type_class type_class,
-        enum hlsl_base_type base_type, unsigned dimx, unsigned dimy);
 struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n,
         const struct vkd3d_shader_location loc);
 struct hlsl_ir_node *hlsl_new_unary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg,
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index 5c10659..d1ef9eb 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -1019,7 +1019,7 @@ static struct hlsl_type *expr_common_type(struct hlsl_ctx *ctx, struct hlsl_type
         return ctx->builtin_types.scalar[base];
     if (type == HLSL_CLASS_VECTOR)
         return ctx->builtin_types.vector[base][dimx - 1];
-    return hlsl_new_type(ctx, NULL, type, base, dimx, dimy);
+    return ctx->builtin_types.matrix[base][dimx - 1][dimy - 1];
 }
 
 static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs, enum hlsl_ir_expr_op op,
@@ -2425,7 +2425,7 @@ type:
                 YYABORT;
             }
 
-            $$ = hlsl_new_type(ctx, NULL, HLSL_CLASS_MATRIX, $3->base_type, $7, $5);
+            $$ = ctx->builtin_types.matrix[$3->base_type][$7 - 1][$5 - 1];
         }
     | KW_VOID
         {




More information about the wine-cvs mailing list