From: Francisco Casas fcasas@codeweavers.com
--- libs/vkd3d-shader/hlsl_codegen.c | 22 ++++++++++++++++++++++ tests/swizzle-constant-prop.shader_test | 6 +++--- 2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 6763558a..8aaf9b71 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -886,6 +886,8 @@ static bool copy_propagation_transform_swizzle(struct hlsl_ctx *ctx, struct hlsl_ir_swizzle *swizzle, struct copy_propagation_state *state) { struct hlsl_ir_node *instr = &swizzle->node, *new_instr; + struct hlsl_ir_node *next_val = swizzle->val.node; + unsigned int combined_swizzle = swizzle->swizzle;
if ((new_instr = copy_propagation_compute_swizzle_constant_replacement(ctx, state, swizzle))) { @@ -893,6 +895,26 @@ static bool copy_propagation_transform_swizzle(struct hlsl_ctx *ctx, hlsl_replace_node(instr, new_instr); return true; } + + while (next_val->type == HLSL_IR_SWIZZLE) + { + combined_swizzle = hlsl_combine_swizzles(hlsl_ir_swizzle(next_val)->swizzle, + combined_swizzle, instr->data_type->dimx); + next_val = hlsl_ir_swizzle(next_val)->val.node; + } + if (next_val != swizzle->val.node) + { + struct hlsl_ir_swizzle *new_swizzle; + + if (!(new_swizzle = hlsl_new_swizzle(ctx, combined_swizzle, instr->data_type->dimx, next_val, &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; }
diff --git a/tests/swizzle-constant-prop.shader_test b/tests/swizzle-constant-prop.shader_test index 86eb3f19..468a66b6 100644 --- a/tests/swizzle-constant-prop.shader_test +++ b/tests/swizzle-constant-prop.shader_test @@ -26,7 +26,7 @@ draw quad probe all rgba (110, 210, 410, 410)
-[pixel shader todo] +[pixel shader] Texture2D tex; uniform int i;
@@ -41,5 +41,5 @@ float4 main() : sv_target
[test] uniform 0 int 3 -todo draw quad -todo probe all rgba (105, 5, 305, 305) +draw quad +probe all rgba (105, 5, 305, 305)