[PATCH vkd3d 12/12] vkd3d-shader/hlsl: Replace register offsets with index paths in split copies.
Francisco Casas
fcasas at codeweavers.com
Fri Jul 1 16:24:35 CDT 2022
hlsl_new_store() and hlsl_new_load() are deleted, so now there are no more
direct ways to create derefs with offsets in hlsl.c and hlsl.h.
Signed-off-by: Francisco Casas <fcasas at codeweavers.com>
---
libs/vkd3d-shader/hlsl.c | 32 -------------------------
libs/vkd3d-shader/hlsl.h | 4 ----
libs/vkd3d-shader/hlsl_codegen.c | 40 +++++++++-----------------------
3 files changed, 11 insertions(+), 65 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index 3454e5ee..fdf023f1 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -744,25 +744,6 @@ static struct hlsl_type *get_type_from_deref(struct hlsl_ctx *ctx, const struct
return type;
}
-struct hlsl_ir_store *hlsl_new_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, struct hlsl_ir_node *offset,
- struct hlsl_ir_node *rhs, unsigned int writemask, struct vkd3d_shader_location loc)
-{
- struct hlsl_ir_store *store;
-
- if (!writemask && type_is_single_reg(rhs->data_type))
- writemask = (1 << rhs->data_type->dimx) - 1;
-
- if (!(store = hlsl_alloc(ctx, sizeof(*store))))
- return NULL;
-
- init_node(&store->node, HLSL_IR_STORE, NULL, loc);
- init_deref(ctx, &store->lhs, var, 0);
- hlsl_src_from_node(&store->lhs.offset, offset);
- hlsl_src_from_node(&store->rhs, rhs);
- store->writemask = writemask;
- return store;
-}
-
/* Returns a simple variable derefence, so that the value can be stored and then passed by reference
* to load/store functions. It shall not be modified afterwards. */
struct hlsl_deref hlsl_get_direct_var_deref(struct hlsl_ir_var *var)
@@ -948,19 +929,6 @@ struct hlsl_ir_if *hlsl_new_if(struct hlsl_ctx *ctx, struct hlsl_ir_node *condit
return iff;
}
-struct hlsl_ir_load *hlsl_new_load(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, struct hlsl_ir_node *offset,
- struct hlsl_type *type, const struct vkd3d_shader_location loc)
-{
- struct hlsl_ir_load *load;
-
- if (!(load = hlsl_alloc(ctx, sizeof(*load))))
- return NULL;
- init_node(&load->node, HLSL_IR_LOAD, type, loc);
- init_deref(ctx, &load->src, var, 0);
- hlsl_src_from_node(&load->src.offset, offset);
- return load;
-}
-
struct hlsl_ir_load *hlsl_new_load_index(struct hlsl_ctx *ctx, const struct hlsl_deref *deref,
struct hlsl_ir_node *idx, struct vkd3d_shader_location loc)
{
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index dd5ea1d7..efb186cf 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -774,11 +774,7 @@ struct hlsl_ir_resource_load *hlsl_new_resource_load(struct hlsl_ctx *ctx, struc
enum hlsl_resource_load_type type, struct hlsl_deref *resource, struct hlsl_deref *sampler,
struct hlsl_ir_node *coords, struct hlsl_ir_node *texel_offset, const struct vkd3d_shader_location *loc);
-struct hlsl_ir_load *hlsl_new_load(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, struct hlsl_ir_node *offset,
- struct hlsl_type *type, struct vkd3d_shader_location loc);
struct hlsl_ir_loop *hlsl_new_loop(struct hlsl_ctx *ctx, struct vkd3d_shader_location loc);
-struct hlsl_ir_store *hlsl_new_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, struct hlsl_ir_node *offset,
- struct hlsl_ir_node *rhs, unsigned int writemask, struct vkd3d_shader_location loc);
struct hlsl_type *hlsl_new_struct_type(struct hlsl_ctx *ctx, const char *name,
struct hlsl_struct_field *fields, size_t field_count);
struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned int components,
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
index 0276fb89..2c7b5f20 100644
--- a/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d-shader/hlsl_codegen.c
@@ -946,39 +946,21 @@ static bool fold_redundant_casts(struct hlsl_ctx *ctx, struct hlsl_ir_node *inst
* split_matrix_copies(). Inserts new instructions right before
* "store". */
static bool split_copy(struct hlsl_ctx *ctx, struct hlsl_ir_store *store,
- const struct hlsl_ir_load *load, const unsigned int offset, struct hlsl_type *type)
+ const struct hlsl_ir_load *load, const unsigned int indx, struct hlsl_type *type)
{
- struct hlsl_ir_node *offset_instr, *add;
struct hlsl_ir_store *split_store;
struct hlsl_ir_load *split_load;
struct hlsl_ir_constant *c;
- if (!(c = hlsl_new_uint_constant(ctx, offset, &store->node.loc)))
+ if (!(c = hlsl_new_uint_constant(ctx, indx, &store->node.loc)))
return false;
list_add_before(&store->node.entry, &c->node.entry);
- offset_instr = &c->node;
- if (load->src.offset.node)
- {
- if (!(add = hlsl_new_binary_expr(ctx, HLSL_OP2_ADD, load->src.offset.node, &c->node)))
- return false;
- list_add_before(&store->node.entry, &add->entry);
- offset_instr = add;
- }
- if (!(split_load = hlsl_new_load(ctx, load->src.var, offset_instr, type, store->node.loc)))
+ if (!(split_load = hlsl_new_load_index(ctx, &load->src, &c->node, store->node.loc)))
return false;
list_add_before(&store->node.entry, &split_load->node.entry);
- offset_instr = &c->node;
- if (store->lhs.offset.node)
- {
- if (!(add = hlsl_new_binary_expr(ctx, HLSL_OP2_ADD, store->lhs.offset.node, &c->node)))
- return false;
- list_add_before(&store->node.entry, &add->entry);
- offset_instr = add;
- }
-
- if (!(split_store = hlsl_new_store(ctx, store->lhs.var, offset_instr, &split_load->node, 0, store->node.loc)))
+ if (!(split_store = hlsl_new_store_index(ctx, &store->lhs, &c->node, &split_load->node, 0, store->node.loc)))
return false;
list_add_before(&store->node.entry, &split_store->node.entry);
@@ -990,8 +972,8 @@ static bool split_array_copies(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
const struct hlsl_ir_node *rhs;
struct hlsl_type *element_type;
const struct hlsl_type *type;
- unsigned int element_size, i;
struct hlsl_ir_store *store;
+ unsigned int i;
if (instr->type != HLSL_IR_STORE)
return false;
@@ -1002,7 +984,6 @@ static bool split_array_copies(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
if (type->type != HLSL_CLASS_ARRAY)
return false;
element_type = type->e.array.type;
- element_size = hlsl_type_get_array_element_reg_size(element_type);
if (rhs->type != HLSL_IR_LOAD)
{
@@ -1012,7 +993,7 @@ static bool split_array_copies(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
for (i = 0; i < type->e.array.elements_count; ++i)
{
- if (!split_copy(ctx, store, hlsl_ir_load(rhs), i * element_size, element_type))
+ if (!split_copy(ctx, store, hlsl_ir_load(rhs), i, element_type))
return false;
}
@@ -1050,7 +1031,7 @@ static bool split_struct_copies(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr
{
const struct hlsl_struct_field *field = &type->e.record.fields[i];
- if (!split_copy(ctx, store, hlsl_ir_load(rhs), field->reg_offset, field->type))
+ if (!split_copy(ctx, store, hlsl_ir_load(rhs), i, field->type))
return false;
}
@@ -1088,7 +1069,7 @@ static bool split_matrix_copies(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr
for (i = 0; i < hlsl_type_major_size(type); ++i)
{
- if (!split_copy(ctx, store, hlsl_ir_load(rhs), 4 * i, element_type))
+ if (!split_copy(ctx, store, hlsl_ir_load(rhs), i, element_type))
return false;
}
@@ -2102,8 +2083,6 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry
append_output_var_copy(ctx, &body->instrs, entry_func->return_var);
}
- transform_ir(ctx, transform_deref_paths_into_offsets, body, NULL); /* TODO: move forward, remove when no longer needed */
-
transform_ir(ctx, lower_broadcasts, body, NULL);
while (transform_ir(ctx, fold_redundant_casts, body, NULL));
do
@@ -2113,6 +2092,9 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry
}
while (progress);
transform_ir(ctx, split_matrix_copies, body, NULL);
+
+ transform_ir(ctx, transform_deref_paths_into_offsets, body, NULL); /* TODO: move forward, remove when no longer needed */
+
transform_ir(ctx, lower_narrowing_casts, body, NULL);
transform_ir(ctx, lower_casts_to_bool, body, NULL);
do
--
2.34.1
More information about the wine-devel
mailing list