[PATCH vkd3d v3 11/17] vkd3d-shader/hlsl: Introduce hlsl_new_store_component().

Francisco Casas fcasas at codeweavers.com
Wed Jul 20 08:23:18 CDT 2022


Signed-off-by: Francisco Casas <fcasas at codeweavers.com>
---

v3:
* Make hlsl_new_store_component() use deref_from_component_index()
  instead of the old compute_component_path().
* Using hlsl_new_store_component() in initialize_var_components() in
  this patch instead of the next.

Signed-off-by: Francisco Casas <fcasas at codeweavers.com>
---
 libs/vkd3d-shader/hlsl.c | 28 ++++++++++++++++++++
 libs/vkd3d-shader/hlsl.h |  2 ++
 libs/vkd3d-shader/hlsl.y | 56 +++++++++++++++++++---------------------
 3 files changed, 56 insertions(+), 30 deletions(-)

diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index 75cb8f41..8e95ee83 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -988,6 +988,34 @@ struct hlsl_ir_store *hlsl_new_simple_store(struct hlsl_ctx *ctx, struct hlsl_ir
     return hlsl_new_store(ctx, lhs, NULL, rhs, 0, rhs->loc);
 }
 
+struct hlsl_ir_store *hlsl_new_store_component(struct hlsl_ctx *ctx, struct hlsl_block *block,
+        const struct hlsl_deref *lhs, unsigned int comp, struct hlsl_ir_node *rhs)
+{
+    struct hlsl_block comp_path_block;
+    struct hlsl_ir_store *store;
+
+    list_init(&block->instrs);
+
+    if (!(store = hlsl_alloc(ctx, sizeof(*store))))
+        return NULL;
+    init_node(&store->node, HLSL_IR_STORE, NULL, rhs->loc);
+
+    if (!deref_from_component_index(ctx, &comp_path_block, &store->lhs, lhs, comp, &rhs->loc))
+    {
+        vkd3d_free(store);
+        return NULL;
+    }
+    list_move_tail(&block->instrs, &comp_path_block.instrs);
+    hlsl_src_from_node(&store->rhs, rhs);
+
+    if (type_is_single_reg(rhs->data_type))
+        store->writemask = (1 << rhs->data_type->dimx) - 1;
+
+    list_add_tail(&block->instrs, &store->node.entry);
+
+    return store;
+}
+
 struct hlsl_ir_constant *hlsl_new_constant(struct hlsl_ctx *ctx, struct hlsl_type *type,
         const struct vkd3d_shader_location *loc)
 {
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index 3a6af2a3..c8820711 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -768,6 +768,8 @@ struct hlsl_ir_load *hlsl_new_load_component(struct hlsl_ctx *ctx, struct hlsl_b
         const struct hlsl_deref *deref, unsigned int comp, const struct vkd3d_shader_location *loc);
 
 struct hlsl_ir_store *hlsl_new_simple_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs);
+struct hlsl_ir_store *hlsl_new_store_component(struct hlsl_ctx *ctx, struct hlsl_block *block,
+        const struct hlsl_deref *lhs, unsigned int comp, struct hlsl_ir_node *rhs);
 
 struct hlsl_ir_node *hlsl_new_offset_node_from_deref(struct hlsl_ctx *ctx, struct hlsl_block *block,
         const struct hlsl_deref *deref, const struct vkd3d_shader_location *loc);
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index 710d5748..b51735af 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -289,6 +289,7 @@ static struct hlsl_ir_node *add_cast(struct hlsl_ctx *ctx, struct list *instrs,
     {
         struct vkd3d_string_buffer *name;
         static unsigned int counter = 0;
+        struct hlsl_deref var_deref;
         struct hlsl_ir_load *load;
         struct hlsl_ir_var *var;
         unsigned int dst_idx;
@@ -308,13 +309,14 @@ static struct hlsl_ir_node *add_cast(struct hlsl_ctx *ctx, struct list *instrs,
         vkd3d_string_buffer_release(&ctx->string_buffers, name);
         if (!var)
             return NULL;
+        hlsl_init_simple_deref_from_var(&var_deref, var);
 
         for (dst_idx = 0; dst_idx < dst_type->dimx * dst_type->dimy; ++dst_idx)
         {
             struct hlsl_type *dst_scalar_type;
-            unsigned int src_idx, dst_offset;
             struct hlsl_ir_store *store;
-            struct hlsl_ir_constant *c;
+            struct hlsl_block block;
+            unsigned int src_idx;
 
             if (broadcast)
             {
@@ -334,7 +336,7 @@ static struct hlsl_ir_node *add_cast(struct hlsl_ctx *ctx, struct list *instrs,
                 }
             }
 
-            dst_offset = hlsl_compute_component_offset(ctx, dst_type, dst_idx, &dst_scalar_type);
+            dst_scalar_type = hlsl_type_get_component_type(ctx, dst_type, dst_idx);
 
             if (!(load = add_load_component(ctx, instrs, node, src_idx, loc)))
                 return NULL;
@@ -343,13 +345,9 @@ static struct hlsl_ir_node *add_cast(struct hlsl_ctx *ctx, struct list *instrs,
                 return NULL;
             list_add_tail(instrs, &cast->node.entry);
 
-            if (!(c = hlsl_new_uint_constant(ctx, dst_offset, loc)))
-                return NULL;
-            list_add_tail(instrs, &c->node.entry);
-
-            if (!(store = hlsl_new_store(ctx, var, &c->node, &cast->node, 0, *loc)))
+            if (!(store = hlsl_new_store_component(ctx, &block, &var_deref, dst_idx, &cast->node)))
                 return NULL;
-            list_add_tail(instrs, &store->node.entry);
+            list_move_tail(instrs, &block.instrs);
         }
 
         if (!(load = hlsl_new_var_load(ctx, var, *loc)))
@@ -723,6 +721,7 @@ static bool add_matrix_index(struct hlsl_ctx *ctx, struct list *instrs,
     struct hlsl_type *mat_type = matrix->data_type, *ret_type;
     struct vkd3d_string_buffer *name;
     static unsigned int counter = 0;
+    struct hlsl_deref var_deref;
     struct hlsl_ir_load *load;
     struct hlsl_ir_var *var;
     unsigned int i;
@@ -738,12 +737,14 @@ static bool add_matrix_index(struct hlsl_ctx *ctx, struct list *instrs,
     vkd3d_string_buffer_release(&ctx->string_buffers, name);
     if (!var)
         return false;
+    hlsl_init_simple_deref_from_var(&var_deref, var);
 
     for (i = 0; i < mat_type->dimx; ++i)
     {
         struct hlsl_ir_load *column, *value;
         struct hlsl_ir_store *store;
         struct hlsl_ir_constant *c;
+        struct hlsl_block block;
 
         if (!(c = hlsl_new_uint_constant(ctx, i, loc)))
             return false;
@@ -755,9 +756,9 @@ static bool add_matrix_index(struct hlsl_ctx *ctx, struct list *instrs,
         if (!(value = add_load_index(ctx, instrs, &column->node, index, loc)))
             return false;
 
-        if (!(store = hlsl_new_store(ctx, var, &c->node, &value->node, 0, *loc)))
+        if (!(store = hlsl_new_store_component(ctx, &block, &var_deref, i, &value->node)))
             return false;
-        list_add_tail(instrs, &store->node.entry);
+        list_move_tail(instrs, &block.instrs);
     }
 
     if (!(load = hlsl_new_var_load(ctx, var, *loc)))
@@ -1733,32 +1734,30 @@ static void initialize_var_components(struct hlsl_ctx *ctx, struct list *instrs,
         struct hlsl_ir_var *dst, unsigned int *store_index, struct hlsl_ir_node *src)
 {
     unsigned int src_comp_count = hlsl_type_component_count(src->data_type);
+    struct hlsl_deref dst_deref;
     unsigned int k;
 
+    hlsl_init_simple_deref_from_var(&dst_deref, dst);
+
     for (k = 0; k < src_comp_count; ++k)
     {
         struct hlsl_type *dst_comp_type;
-        unsigned int dst_reg_offset;
         struct hlsl_ir_store *store;
-        struct hlsl_ir_constant *c;
         struct hlsl_ir_load *load;
         struct hlsl_ir_node *conv;
+        struct hlsl_block block;
 
         if (!(load = add_load_component(ctx, instrs, src, k, &src->loc)))
             return;
 
-        dst_reg_offset = hlsl_compute_component_offset(ctx, dst->data_type, *store_index, &dst_comp_type);
+        dst_comp_type = hlsl_type_get_component_type(ctx, dst->data_type, *store_index);
 
         if (!(conv = add_implicit_conversion(ctx, instrs, &load->node, dst_comp_type, &src->loc)))
             return;
 
-        if (!(c = hlsl_new_uint_constant(ctx, dst_reg_offset, &src->loc)))
+        if (!(store = hlsl_new_store_component(ctx, &block, &dst_deref, *store_index, conv)))
             return;
-        list_add_tail(instrs, &c->node.entry);
-
-        if (!(store = hlsl_new_store(ctx, dst, &c->node, conv, 0, src->loc)))
-            return;
-        list_add_tail(instrs, &store->node.entry);
+        list_move_tail(instrs, &block.instrs);
 
         ++*store_index;
     }
@@ -2123,6 +2122,7 @@ static bool intrinsic_mul(struct hlsl_ctx *ctx,
     unsigned int i, j, k, vect_count = 0;
     struct vkd3d_string_buffer *name;
     static unsigned int counter = 0;
+    struct hlsl_deref var_deref;
     struct hlsl_ir_load *load;
     struct hlsl_ir_var *var;
 
@@ -2169,15 +2169,15 @@ static bool intrinsic_mul(struct hlsl_ctx *ctx,
     vkd3d_string_buffer_release(&ctx->string_buffers, name);
     if (!var)
         return false;
+    hlsl_init_simple_deref_from_var(&var_deref, var);
 
     for (i = 0; i < matrix_type->dimx; ++i)
+    {
         for (j = 0; j < matrix_type->dimy; ++j)
         {
             struct hlsl_ir_node *node = NULL;
-            struct hlsl_type *scalar_type;
             struct hlsl_ir_store *store;
-            struct hlsl_ir_constant *c;
-            unsigned int offset;
+            struct hlsl_block block;
 
             for (k = 0; k < cast_type1->dimx && k < cast_type2->dimy; ++k)
             {
@@ -2204,15 +2204,11 @@ static bool intrinsic_mul(struct hlsl_ctx *ctx,
                 }
             }
 
-            offset = hlsl_compute_component_offset(ctx, matrix_type, j * matrix_type->dimx + i, &scalar_type);
-            if (!(c = hlsl_new_uint_constant(ctx, offset, loc)))
+            if (!(store = hlsl_new_store_component(ctx, &block, &var_deref, j * matrix_type->dimx + i, node)))
                 return false;
-            list_add_tail(params->instrs, &c->node.entry);
-
-            if (!(store = hlsl_new_store(ctx, var, &c->node, node, 0, *loc)))
-                return false;
-            list_add_tail(params->instrs, &store->node.entry);
+            list_move_tail(params->instrs, &block.instrs);
         }
+    }
 
     if (!(load = hlsl_new_var_load(ctx, var, *loc)))
         return false;
-- 
2.34.1




More information about the wine-devel mailing list