This patch originally was in !93 but I decided to separate it, since it solves a different bug that the first part of that series.
Currently, in copy-prop, we may create nodes of different dimensions than the ones we are replacing, i.e. the assertions included in this patch fail for many tests.
Without the patch, the following assertion in `hlsl_sm4.c` fails for me
```c /* Narrowing casts were already lowered. */ assert(src_type->dimx == dst_type->dimx); ```
for some tests in one of my branches, because narrowing casts end up appearing if the node is replaced with a node with more components. This error happens under quite complex conditions (involving casts and matrices) that I still try to narrow down.
The cause of this problem is that, for the generated swizzles, we are passing `count` instead of `instr_component_count`. `count` is the number of components of the source deref (without considering the swizzle), while `instr_component_count` is the actual number of components of the instruction to be replaced.
From: Francisco Casas fcasas@codeweavers.com
Otherwise we may create nodes of different dimensions than the ones we are replacing.
"count" is the number of components of the source deref (without considering the swizzle), while "instr_component_count" is the actual number of components of the instruction to be replaced. --- libs/vkd3d-shader/hlsl.c | 3 +++ libs/vkd3d-shader/hlsl_codegen.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 97713343..c5ae57c2 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -2292,6 +2292,9 @@ void hlsl_replace_node(struct hlsl_ir_node *old, struct hlsl_ir_node *new) { struct hlsl_src *src, *next;
+ assert(old->data_type->dimx == new->data_type->dimx); + assert(old->data_type->dimy == new->data_type->dimy); + LIST_FOR_EACH_ENTRY_SAFE(src, next, &old->uses, struct hlsl_src, entry) { hlsl_src_remove(src); diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 80d52dfc..87559502 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -1031,7 +1031,7 @@ static bool copy_propagation_replace_with_single_instr(struct hlsl_ctx *ctx, { struct hlsl_ir_swizzle *swizzle_node;
- if (!(swizzle_node = hlsl_new_swizzle(ctx, ret_swizzle, count, new_instr, &instr->loc))) + if (!(swizzle_node = hlsl_new_swizzle(ctx, ret_swizzle, instr_component_count, new_instr, &instr->loc))) return false; list_add_before(&instr->entry, &swizzle_node->node.entry); new_instr = &swizzle_node->node;
This merge request was approved by Zebediah Figura.
This merge request was approved by Giovanni Mascellani.
This merge request was approved by Henri Verbeet.