[PATCH vkd3d 5/6] vkd3d-shader/hlsl: Cache matrix types.

Zebediah Figura zfigura at codeweavers.com
Mon Sep 27 20:51:46 CDT 2021


Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
 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 8a531d627..6dfcc7bb5 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 7e6283921..9686a496b 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 56b996991..b058ee502 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
         {
-- 
2.33.0




More information about the wine-devel mailing list