Skip to content
Snippets Groups Projects
Commit 7c378cc6 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard
Browse files

vkd3d-shader/hlsl: Remove conditional branching when condition is a compile time constant.

parent f3389789
No related branches found
No related tags found
1 merge request!375vkd3d-shader/hlsl: Remove conditional branching when condition is a compile time constant.
Pipeline #16140 skipped
......@@ -2062,6 +2062,25 @@ static bool remove_trivial_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *i
return true;
}
static bool remove_trivial_conditional_branches(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{
struct hlsl_ir_constant *condition;
struct hlsl_ir_if *iff;
if (instr->type != HLSL_IR_IF)
return false;
iff = hlsl_ir_if(instr);
if (iff->condition.node->type != HLSL_IR_CONSTANT)
return false;
condition = hlsl_ir_constant(iff->condition.node);
list_move_before(&instr->entry, condition->value.u[0].u ? &iff->then_block.instrs : &iff->else_block.instrs);
list_remove(&instr->entry);
hlsl_free_instr(instr);
return true;
}
static bool lower_nonconstant_vector_derefs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, struct hlsl_block *block)
{
struct hlsl_ir_node *idx;
......@@ -4417,6 +4436,7 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry
progress |= hlsl_copy_propagation_execute(ctx, body);
progress |= hlsl_transform_ir(ctx, fold_swizzle_chains, body, NULL);
progress |= hlsl_transform_ir(ctx, remove_trivial_swizzles, body, NULL);
progress |= hlsl_transform_ir(ctx, remove_trivial_conditional_branches, body, NULL);
}
while (progress);
......
......@@ -82,3 +82,20 @@ float4 main(uniform float4 u) : sv_target
uniform 0 float4 0.0 0.0 0.0 0.0
draw quad
probe all rgba (0.9, 0.8, 0.7, 0.6)
[pixel shader]
float4 main() : sv_target
{
bool c = false;
float a = -1.0f;
if (c)
return float4(1.0, 2.0, 3.0, 4.0);
else if (a > 0)
return float4(5.0, 6.0, 7.0, 8.0);
else
return float4(9.0, 10.0, 11.0, 12.0);
}
[test]
draw quad
probe all rgba (9.0, 10.0, 11.0, 12.0)
......@@ -85,7 +85,7 @@ float4 main() : sv_target
}
[pixel shader todo]
[pixel shader]
// This is allowed in 10.0.10011.16384 but not in 9.29.952.3111
static Texture2D tex;
sampler sam;
......@@ -177,7 +177,7 @@ size (1, 1)
0.5
[pixel shader todo]
[pixel shader]
// This is allowed in 10.0.10011.16384 but not in 9.29.952.3111
static RWTexture2D<float> tex;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment