Signed-off-by: Francisco Casas fcasas@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 100 +++++++++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 31 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 8fd18868..61c94fa8 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -272,8 +272,8 @@ static bool implicit_compatible_data_types(struct hlsl_type *t1, struct hlsl_typ return false; }
-static struct hlsl_ir_load *add_load(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *var_node, - struct hlsl_ir_node *offset, struct hlsl_type *data_type, const struct vkd3d_shader_location loc); +static struct hlsl_ir_load *add_load_component(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *var_node, + unsigned int comp, const struct vkd3d_shader_location loc);
static struct hlsl_ir_node *add_cast(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *node, struct hlsl_type *dst_type, const struct vkd3d_shader_location *loc) @@ -311,8 +311,8 @@ static struct hlsl_ir_node *add_cast(struct hlsl_ctx *ctx, struct list *instrs,
for (dst_idx = 0; dst_idx < dst_type->dimx * dst_type->dimy; ++dst_idx) { - struct hlsl_type *src_scalar_type, *dst_scalar_type; - unsigned int src_idx, src_offset, dst_offset; + struct hlsl_type *dst_scalar_type; + unsigned int src_idx, dst_offset; struct hlsl_ir_store *store; struct hlsl_ir_constant *c;
@@ -335,13 +335,8 @@ 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); - src_offset = hlsl_compute_component_offset(ctx, src_type, src_idx, &src_scalar_type); - - if (!(c = hlsl_new_uint_constant(ctx, src_offset, loc))) - return NULL; - list_add_tail(instrs, &c->node.entry);
- if (!(load = add_load(ctx, instrs, node, &c->node, src_scalar_type, *loc))) + if (!(load = add_load_component(ctx, instrs, node, src_idx, *loc))) return NULL;
if (!(cast = hlsl_new_cast(ctx, &load->node, dst_scalar_type, loc))) @@ -668,6 +663,64 @@ static struct hlsl_ir_load *add_load(struct hlsl_ctx *ctx, struct list *instrs, return load; }
+static struct hlsl_ir_load *add_load_component(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *var_node, + unsigned int comp, const struct vkd3d_shader_location loc) +{ + struct hlsl_type *comp_type; + struct hlsl_ir_node *offset; + struct hlsl_ir_constant *c; + struct hlsl_ir_load *load; + unsigned int comp_offset; + struct hlsl_ir_var *var; + + comp_offset = hlsl_compute_component_offset(ctx, var_node->data_type, comp, &comp_type); + + if (!(c = hlsl_new_uint_constant(ctx, comp_offset, &loc))) + return NULL; + list_add_tail(instrs, &c->node.entry); + + offset = &c->node; + + if (var_node->type == HLSL_IR_LOAD) + { + const struct hlsl_deref *src = &hlsl_ir_load(var_node)->src; + struct hlsl_ir_node *add; + + var = src->var; + if (src->offset.node) + { + if (!(add = hlsl_new_binary_expr(ctx, HLSL_OP2_ADD, src->offset.node, &c->node))) + return NULL; + list_add_tail(instrs, &add->entry); + offset = add; + } + + if (!(load = hlsl_new_load(ctx, var, offset, comp_type, loc))) + return NULL; + list_add_tail(instrs, &load->node.entry); + } + else + { + struct hlsl_ir_store *store; + struct hlsl_ir_var *var; + char name[27]; + + sprintf(name, "<deref-%p>", var_node); + if (!(var = hlsl_new_synthetic_var(ctx, name, var_node->data_type, var_node->loc))) + return NULL; + + if (!(store = hlsl_new_simple_store(ctx, var, var_node))) + return NULL; + list_add_tail(instrs, &store->node.entry); + + if (!(load = hlsl_new_load(ctx, var, offset, comp_type, loc))) + return NULL; + list_add_tail(instrs, &load->node.entry); + } + + return load; +} + static bool add_record_load(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *record, unsigned int idx, const struct vkd3d_shader_location loc) { @@ -1770,22 +1823,17 @@ static void initialize_var_components(struct hlsl_ctx *ctx, struct list *instrs,
for (k = 0; k < src_comp_count; ++k) { - struct hlsl_type *dst_comp_type, *src_comp_type; - unsigned int dst_reg_offset, src_reg_offset; + 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;
- dst_reg_offset = hlsl_compute_component_offset(ctx, dst->data_type, *store_index, &dst_comp_type); - src_reg_offset = hlsl_compute_component_offset(ctx, src->data_type, k, &src_comp_type); - - if (!(c = hlsl_new_uint_constant(ctx, src_reg_offset, &src->loc))) + if (!(load = add_load_component(ctx, instrs, src, k, src->loc))) return; - list_add_tail(instrs, &c->node.entry);
- if (!(load = add_load(ctx, instrs, src, &c->node, src_comp_type, src->loc))) - return; + dst_reg_offset = hlsl_compute_component_offset(ctx, dst->data_type, *store_index, &dst_comp_type);
if (!(conv = add_implicit_conversion(ctx, instrs, &load->node, dst_comp_type, &src->loc))) return; @@ -2222,20 +2270,10 @@ static bool intrinsic_mul(struct hlsl_ctx *ctx, struct hlsl_ir_load *value1, *value2; struct hlsl_ir_node *mul;
- offset = hlsl_compute_component_offset(ctx, cast_type1, j * cast_type1->dimx + k, &scalar_type); - if (!(c = hlsl_new_uint_constant(ctx, offset, loc))) - return false; - list_add_tail(params->instrs, &c->node.entry); - - if (!(value1 = add_load(ctx, params->instrs, cast1, &c->node, scalar_type, *loc))) - return false; - - offset = hlsl_compute_component_offset(ctx, cast_type2, k * cast_type2->dimx + i, &scalar_type); - if (!(c = hlsl_new_uint_constant(ctx, offset, loc))) + if (!(value1 = add_load_component(ctx, params->instrs, cast1, j * cast1->data_type->dimx + k, *loc))) return false; - list_add_tail(params->instrs, &c->node.entry);
- if (!(value2 = add_load(ctx, params->instrs, cast2, &c->node, scalar_type, *loc))) + if (!(value2 = add_load_component(ctx, params->instrs, cast2, k * cast2->data_type->dimx + i, *loc))) return false;
if (!(mul = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, &value1->node, &value2->node, loc)))
On 7/1/22 16:24, Francisco Casas wrote:
Signed-off-by: Francisco Casas fcasas@codeweavers.com
libs/vkd3d-shader/hlsl.y | 100 +++++++++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 31 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 8fd18868..61c94fa8 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -272,8 +272,8 @@ static bool implicit_compatible_data_types(struct hlsl_type *t1, struct hlsl_typ return false; }
-static struct hlsl_ir_load *add_load(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *var_node,
struct hlsl_ir_node *offset, struct hlsl_type *data_type, const struct vkd3d_shader_location loc);
+static struct hlsl_ir_load *add_load_component(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *var_node,
unsigned int comp, const struct vkd3d_shader_location loc);
Can you please use "const struct vkd3d_shader_location *" for any new functions?
On 04-07-22 19:02, Zebediah Figura wrote:
On 7/1/22 16:24, Francisco Casas wrote:
Signed-off-by: Francisco Casas fcasas@codeweavers.com
libs/vkd3d-shader/hlsl.y | 100 +++++++++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 31 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 8fd18868..61c94fa8 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -272,8 +272,8 @@ static bool implicit_compatible_data_types(struct hlsl_type *t1, struct hlsl_typ return false; } -static struct hlsl_ir_load *add_load(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *var_node, - struct hlsl_ir_node *offset, struct hlsl_type *data_type, const struct vkd3d_shader_location loc); +static struct hlsl_ir_load *add_load_component(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *var_node, + unsigned int comp, const struct vkd3d_shader_location loc);
Can you please use "const struct vkd3d_shader_location *" for any new functions?
Okay, I will do the same for hlsl_new_load_index(), hlsl_new_load_component(), and hlsl_new_store_index() in the next version of the batch then.
Hi,
about the patch subject, there is probably no real need to explicitly mention hlsl.y.
Il 01/07/22 23:24, Francisco Casas ha scritto:
+static struct hlsl_ir_load *add_load_component(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *var_node,
unsigned int comp, const struct vkd3d_shader_location loc)
+{
- struct hlsl_type *comp_type;
- struct hlsl_ir_node *offset;
- struct hlsl_ir_constant *c;
- struct hlsl_ir_load *load;
- unsigned int comp_offset;
- struct hlsl_ir_var *var;
- comp_offset = hlsl_compute_component_offset(ctx, var_node->data_type, comp, &comp_type);
- if (!(c = hlsl_new_uint_constant(ctx, comp_offset, &loc)))
return NULL;
- list_add_tail(instrs, &c->node.entry);
- offset = &c->node;
- if (var_node->type == HLSL_IR_LOAD)
- {
const struct hlsl_deref *src = &hlsl_ir_load(var_node)->src;
struct hlsl_ir_node *add;
var = src->var;
if (src->offset.node)
{
if (!(add = hlsl_new_binary_expr(ctx, HLSL_OP2_ADD, src->offset.node, &c->node)))
return NULL;
list_add_tail(instrs, &add->entry);
offset = add;
}
if (!(load = hlsl_new_load(ctx, var, offset, comp_type, loc)))
return NULL;
list_add_tail(instrs, &load->node.entry);
- }
- else
- {
struct hlsl_ir_store *store;
struct hlsl_ir_var *var;
char name[27];
sprintf(name, "<deref-%p>", var_node);
I think the new trend is to use string buffers. See how this is done in intrinsic_mul(), for example.
(if you ask me, I would also stop using global static counters, but that's not happening yet; also, it's just a cosmetic issue)
if (!(var = hlsl_new_synthetic_var(ctx, name, var_node->data_type, var_node->loc)))
return NULL;
if (!(store = hlsl_new_simple_store(ctx, var, var_node)))
return NULL;
list_add_tail(instrs, &store->node.entry);
if (!(load = hlsl_new_load(ctx, var, offset, comp_type, loc)))
return NULL;
list_add_tail(instrs, &load->node.entry);
This last block is identical in both branches, and it remains mostly identical also in later patches. Maybe it could be brought outside of the if, like it is in add_load()?
Thanks, Giovanni.
Hello,
On 05-07-22 06:26, Giovanni Mascellani wrote:
Hi,
about the patch subject, there is probably no real need to explicitly mention hlsl.y.
Right, I will change that.
Il 01/07/22 23:24, Francisco Casas ha scritto:
+static struct hlsl_ir_load *add_load_component(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *var_node, + unsigned int comp, const struct vkd3d_shader_location loc) +{ + struct hlsl_type *comp_type; + struct hlsl_ir_node *offset; + struct hlsl_ir_constant *c; + struct hlsl_ir_load *load; + unsigned int comp_offset; + struct hlsl_ir_var *var;
+ comp_offset = hlsl_compute_component_offset(ctx, var_node->data_type, comp, &comp_type);
+ if (!(c = hlsl_new_uint_constant(ctx, comp_offset, &loc))) + return NULL; + list_add_tail(instrs, &c->node.entry);
+ offset = &c->node;
+ if (var_node->type == HLSL_IR_LOAD) + { + const struct hlsl_deref *src = &hlsl_ir_load(var_node)->src; + struct hlsl_ir_node *add;
+ var = src->var; + if (src->offset.node) + { + if (!(add = hlsl_new_binary_expr(ctx, HLSL_OP2_ADD, src->offset.node, &c->node))) + return NULL; + list_add_tail(instrs, &add->entry); + offset = add; + }
+ if (!(load = hlsl_new_load(ctx, var, offset, comp_type, loc))) + return NULL; + list_add_tail(instrs, &load->node.entry); + } + else + { + struct hlsl_ir_store *store; + struct hlsl_ir_var *var; + char name[27];
+ sprintf(name, "<deref-%p>", var_node);
I think the new trend is to use string buffers. See how this is done in intrinsic_mul(), for example.
I see. I will use string buffers in the next version.
(if you ask me, I would also stop using global static counters, but that's not happening yet; also, it's just a cosmetic issue)
+ if (!(var = hlsl_new_synthetic_var(ctx, name, var_node->data_type, var_node->loc))) + return NULL;
+ if (!(store = hlsl_new_simple_store(ctx, var, var_node))) + return NULL; + list_add_tail(instrs, &store->node.entry);
+ if (!(load = hlsl_new_load(ctx, var, offset, comp_type, loc))) + return NULL; + list_add_tail(instrs, &load->node.entry);
This last block is identical in both branches, and it remains mostly identical also in later patches. Maybe it could be brought outside of the if, like it is in add_load()?
Good observation. I changed this in add_load_component() and add_load_index() for the next version. It requires moving some declarations to the outermost scope though.
I realized that here we have two "struct hlsl_ir_var *var;" declarations in different scopes too. I got rid of that too.
Thanks, Giovanni.