[PATCH vkd3d 11/17] vkd3d-shader/hlsl: Introduce hlsl_new_store_component().
Francisco Casas
fcasas at codeweavers.com
Thu Jul 14 20:23:53 CDT 2022
Signed-off-by: Francisco Casas <fcasas at codeweavers.com>
---
v2:
* Split from a previous patch.
---
libs/vkd3d-shader/hlsl.c | 57 ++++++++++++++++++++++++++++++++++++++++
libs/vkd3d-shader/hlsl.h | 2 ++
libs/vkd3d-shader/hlsl.y | 40 ++++++++++++++--------------
3 files changed, 78 insertions(+), 21 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index d44c103e..2d7d33fa 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -968,6 +968,63 @@ 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)
+{
+ unsigned int *path, path_len, i;
+ struct hlsl_ir_store *store;
+ struct hlsl_ir_constant *c;
+ struct hlsl_type *type;
+
+ list_init(&block->instrs);
+
+ if (!(store = hlsl_alloc(ctx, sizeof(*store))))
+ return NULL;
+ init_node(&store->node, HLSL_IR_STORE, NULL, rhs->loc);
+
+ type = get_type_from_deref(ctx, lhs);
+ path = compute_component_path(ctx, type, comp, &path_len);
+ if (!path)
+ {
+ vkd3d_free(store);
+ return NULL;
+ }
+
+ if (!init_deref(ctx, &store->lhs, lhs->var, lhs->path_len + path_len))
+ {
+ vkd3d_free(path);
+ vkd3d_free(store);
+ return NULL;
+ }
+
+ for (i = 0; i < lhs->path_len; ++i)
+ hlsl_src_from_node(&store->lhs.path[i], lhs->path[i].node);
+ for (i = 0; i < path_len; ++i)
+ {
+ if (!(c = hlsl_new_uint_constant(ctx, path[i], &rhs->loc)))
+ {
+ vkd3d_free(path);
+ hlsl_free_instr_list(&block->instrs);
+ hlsl_cleanup_deref(&store->lhs);
+ vkd3d_free(store);
+ return NULL;
+ }
+ list_add_tail(&block->instrs, &c->node.entry);
+
+ hlsl_src_from_node(&store->lhs.path[lhs->path_len + i], &c->node);
+ }
+ vkd3d_free(path);
+
+ 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 3447ddd5..8e5b8323 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)))
@@ -721,6 +719,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;
@@ -736,12 +735,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;
@@ -753,9 +754,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)))
@@ -2121,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;
@@ -2167,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)
{
@@ -2202,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