From: Francisco Casas fcasas@codeweavers.com
Since the new copy_propagation_compute_load_replacement() function doesn't have information about the swizzle instruction (in case it is called from copy_propagation_transform_swizzle()), new instructions are inserted after the load, which can cause a difference in the ordering of the resulting instructions but no one that should change the behavior of the resulting shader. --- libs/vkd3d-shader/hlsl_codegen.c | 60 +++++++++++++++----------------- 1 file changed, 29 insertions(+), 31 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 00be55ad..58d76744 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -759,13 +759,36 @@ static struct hlsl_ir_node *copy_propagation_compute_load_constant_replacement(s return &cons->node; }
+static struct hlsl_ir_node *copy_propagation_compute_load_replacement(struct hlsl_ctx *ctx, + const struct copy_propagation_state *state, struct hlsl_ir_load *load, + unsigned int swizzle, unsigned int comp_count) +{ + struct hlsl_ir_swizzle *new_swizzle; + struct hlsl_ir_node *new_instr; + + if ((new_instr = copy_propagation_compute_load_constant_replacement(ctx, state, load, swizzle, comp_count))) + { + list_add_before(&load->node.entry, &new_instr->entry); + return new_instr; + } + + if (!(new_instr = copy_propagation_compute_replacement(ctx, state, &load->src, &swizzle, comp_count))) + return NULL; + if (load->node.data_type->type != HLSL_CLASS_OBJECT) + { + if (!(new_swizzle = hlsl_new_swizzle(ctx, swizzle, comp_count, new_instr, &load->node.loc))) + return NULL; + new_instr = &new_swizzle->node; + list_add_before(&load->node.entry, &new_instr->entry); + } + return new_instr; +} + static bool copy_propagation_transform_load(struct hlsl_ctx *ctx, struct hlsl_ir_load *load, struct copy_propagation_state *state) { struct hlsl_ir_node *instr = &load->node, *new_instr; - unsigned int swizzle = HLSL_SWIZZLE(X, Y, Z, W); struct hlsl_type *type = instr->data_type; - struct hlsl_ir_swizzle *swizzle_node; unsigned int dimx = 0;
switch (type->type) @@ -787,25 +810,12 @@ static bool copy_propagation_transform_load(struct hlsl_ctx *ctx, return false; }
- if ((new_instr = copy_propagation_compute_load_constant_replacement(ctx, state, load, swizzle, dimx))) + if ((new_instr = copy_propagation_compute_load_replacement(ctx, state, load, HLSL_SWIZZLE(X, Y, Z, W), dimx))) { - list_add_before(&instr->entry, &new_instr->entry); hlsl_replace_node(instr, new_instr); return true; } - - if (!(new_instr = copy_propagation_compute_replacement(ctx, state, &load->src, &swizzle, dimx))) - return false; - - if (type->type != HLSL_CLASS_OBJECT) - { - if (!(swizzle_node = hlsl_new_swizzle(ctx, swizzle, dimx, new_instr, &instr->loc))) - return false; - list_add_before(&instr->entry, &swizzle_node->node.entry); - new_instr = &swizzle_node->node; - } - hlsl_replace_node(instr, new_instr); - return true; + return false; }
static bool copy_propagation_transform_object_load(struct hlsl_ctx *ctx, @@ -844,30 +854,18 @@ static bool copy_propagation_transform_swizzle(struct hlsl_ctx *ctx, { struct hlsl_ir_node *instr = &swizzle->node, *new_instr; struct hlsl_type *type = swizzle->node.data_type; - unsigned int swizzle_bits = swizzle->swizzle; - struct hlsl_ir_swizzle *new_swizzle; struct hlsl_ir_load *load;
if (swizzle->val.node->type != HLSL_IR_LOAD) return false; load = hlsl_ir_load(swizzle->val.node);
- if ((new_instr = copy_propagation_compute_load_constant_replacement(ctx, state, load, swizzle_bits, type->dimx))) + if ((new_instr = copy_propagation_compute_load_replacement(ctx, state, load, swizzle->swizzle, type->dimx))) { - list_add_before(&instr->entry, &new_instr->entry); hlsl_replace_node(instr, new_instr); return true; } - - if (!(new_instr = copy_propagation_compute_replacement(ctx, state, &load->src, &swizzle_bits, type->dimx))) - return false; - if (!(new_swizzle = hlsl_new_swizzle(ctx, swizzle_bits, type->dimx, new_instr, &instr->loc))) - return false; - new_instr = &new_swizzle->node; - list_add_before(&instr->entry, &new_instr->entry); - - hlsl_replace_node(instr, new_instr); - return true; + return false; }
static bool copy_propagation_transform_resource_store(struct hlsl_ctx *ctx,