vkd3d-shader/hlsl: Flatten conditional branches containing stores.

For an if block

    if (cond)
    {
        <then_block>
    }
    else
    {
        <else_block>
    }

We flatten it by first replacing any store instruction `v[[k]] = x`
in the then_block with the following:

    1: load(v[[k]])
    2: cond ? x : @1
    3: v[[k]] = @2

Similarly, we replace any store instruction `v[[k]] = x` in the
else_block with the following:

    1: load(v[[k]])
    2: cond ? @1 : x
    3: v[[k]] = @2

Then we can concatenate <then_block> and <else_block> together and
get rid of the if block.
This commit is contained in:
Shaun Ren
2025-10-16 23:30:46 -04:00
committed by Henri Verbeet
parent 200e66ba4f
commit 4d5a1528ab
Notes: Henri Verbeet 2025-10-30 19:59:51 +01:00
Approved-by: Francisco Casas (@fcasas)
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1732
10 changed files with 374 additions and 141 deletions

View File

@@ -3916,6 +3916,233 @@ static bool remove_trivial_conditional_branches(struct hlsl_ctx *ctx, struct hls
return true;
}
static bool is_conditional_block_simple(const struct hlsl_block *cond_block)
{
static const unsigned int max_cost = 10;
struct hlsl_ir_node *instr;
unsigned int cost = 0;
LIST_FOR_EACH_ENTRY(instr, &cond_block->instrs, struct hlsl_ir_node, entry)
{
switch (instr->type)
{
case HLSL_IR_CONSTANT:
case HLSL_IR_STRING_CONSTANT:
case HLSL_IR_SWIZZLE:
break;
case HLSL_IR_EXPR:
++cost;
break;
case HLSL_IR_JUMP:
return false;
case HLSL_IR_STORE:
if (hlsl_ir_store(instr)->lhs.var->is_tgsm)
return false;
++cost;
break;
case HLSL_IR_LOAD:
if (hlsl_ir_load(instr)->src.var->is_tgsm)
return false;
break;
default:
return false;
}
if (cost > max_cost)
return false;
}
return true;
}
static bool can_flatten_conditional_block(struct hlsl_ctx *ctx, const struct hlsl_block *cond_block)
{
struct hlsl_ir_node *instr;
LIST_FOR_EACH_ENTRY(instr, &cond_block->instrs, struct hlsl_ir_node, entry)
{
switch (instr->type)
{
case HLSL_IR_CALL:
case HLSL_IR_RESOURCE_STORE:
case HLSL_IR_INTERLOCKED:
case HLSL_IR_SYNC:
goto fail;
case HLSL_IR_JUMP:
{
struct hlsl_ir_jump *jump = hlsl_ir_jump(instr);
if (jump->type != HLSL_IR_JUMP_DISCARD_NZ && jump->type != HLSL_IR_JUMP_DISCARD_NEG)
{
hlsl_fixme(ctx, &instr->loc, "Flattening conditional blocks with non-discard jump instructions.");
return false;
}
hlsl_fixme(ctx, &instr->loc, "Flattening conditional blocks with discard instructions.");
return false;
}
case HLSL_IR_STORE:
if (hlsl_ir_store(instr)->lhs.var->is_tgsm)
goto fail;
break;
case HLSL_IR_IF:
{
struct hlsl_ir_if *iff = hlsl_ir_if(instr);
if (!can_flatten_conditional_block(ctx, &iff->then_block)
|| !can_flatten_conditional_block(ctx, &iff->else_block))
return false;
break;
}
case HLSL_IR_LOOP:
{
struct hlsl_ir_loop *loop = hlsl_ir_loop(instr);
if (!can_flatten_conditional_block(ctx, &loop->iter)
|| !can_flatten_conditional_block(ctx, &loop->body))
return false;
break;
}
case HLSL_IR_SWITCH:
{
struct hlsl_ir_switch *s = hlsl_ir_switch(instr);
struct hlsl_ir_switch_case *c;
LIST_FOR_EACH_ENTRY(c, &s->cases, struct hlsl_ir_switch_case, entry)
{
if (!can_flatten_conditional_block(ctx, &c->body))
return false;
}
break;
}
case HLSL_IR_CONSTANT:
case HLSL_IR_EXPR:
case HLSL_IR_INDEX:
case HLSL_IR_LOAD:
case HLSL_IR_RESOURCE_LOAD:
case HLSL_IR_STRING_CONSTANT:
case HLSL_IR_SWIZZLE:
case HLSL_IR_COMPILE:
case HLSL_IR_SAMPLER_STATE:
case HLSL_IR_STATEBLOCK_CONSTANT:
break;
}
}
return true;
fail:
hlsl_error(ctx, &instr->loc, VKD3D_SHADER_ERROR_HLSL_CANNOT_FLATTEN,
"Conditional branches with side effects cannot be flattened.");
return false;
}
static bool lower_conditional_block_stores(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
struct hlsl_ir_node *cond, bool is_then)
{
struct hlsl_ir_node *load, *new_val;
struct hlsl_ir_store *store;
struct hlsl_type *rhs_type;
struct hlsl_block block;
if (instr->type != HLSL_IR_STORE)
return false;
store = hlsl_ir_store(instr);
rhs_type = store->rhs.node->data_type;
VKD3D_ASSERT(rhs_type->class <= HLSL_CLASS_VECTOR);
VKD3D_ASSERT(cond->data_type->e.numeric.dimx == 1);
hlsl_block_init(&block);
load = hlsl_block_add_load_index(ctx, &block, &store->lhs, NULL, &store->node.loc);
if (store->writemask && !hlsl_types_are_equal(rhs_type, load->data_type))
load = hlsl_block_add_swizzle(ctx, &block, hlsl_swizzle_from_writemask(store->writemask),
rhs_type->e.numeric.dimx, load, &store->node.loc);
if (rhs_type->e.numeric.dimx != 1)
cond = hlsl_block_add_swizzle(ctx, &block, HLSL_SWIZZLE(X, X, X, X),
rhs_type->e.numeric.dimx, cond, &store->node.loc);
if (is_then)
new_val = hlsl_add_conditional(ctx, &block, cond, store->rhs.node, load);
else
new_val = hlsl_add_conditional(ctx, &block, cond, load, store->rhs.node);
list_move_before(&store->node.entry, &block.instrs);
hlsl_src_remove(&store->rhs);
hlsl_src_from_node(&store->rhs, new_val);
return true;
}
struct flatten_conditional_block_ctx
{
struct hlsl_ir_node *cond;
bool is_then;
};
static bool lower_conditional_block_instrs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{
struct flatten_conditional_block_ctx *flatten_ctx = context;
return lower_conditional_block_stores(ctx, instr, flatten_ctx->cond, flatten_ctx->is_then);
}
static bool flatten_conditional_branches(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{
struct flatten_conditional_block_ctx flatten_ctx;
struct hlsl_ir_if *iff;
bool force_flatten;
if (instr->type != HLSL_IR_IF)
return false;
iff = hlsl_ir_if(instr);
if (iff->flatten_type == HLSL_IF_FORCE_BRANCH)
return false;
force_flatten = iff->flatten_type == HLSL_IF_FORCE_FLATTEN
|| hlsl_version_lt(ctx, 2, 1); /* Always flatten branches for SM < 2.1. */
if (force_flatten)
{
if (!can_flatten_conditional_block(ctx, &iff->then_block)
|| !can_flatten_conditional_block(ctx, &iff->else_block))
return false;
}
else if (!is_conditional_block_simple(&iff->then_block) || !is_conditional_block_simple(&iff->else_block))
{
/* Only flatten simple blocks by default. */
return false;
}
flatten_ctx.cond = iff->condition.node;
flatten_ctx.is_then = true;
hlsl_transform_ir(ctx, lower_conditional_block_instrs, &iff->then_block, &flatten_ctx);
flatten_ctx.is_then = false;
hlsl_transform_ir(ctx, lower_conditional_block_instrs, &iff->else_block, &flatten_ctx);
list_move_before(&instr->entry, &iff->then_block.instrs);
list_move_before(&instr->entry, &iff->else_block.instrs);
list_remove(&instr->entry);
hlsl_free_instr(instr);
return true;
}
static bool normalize_switch_cases(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{
struct hlsl_ir_switch_case *c, *def = NULL;
@@ -8494,6 +8721,7 @@ static void hlsl_run_folding_passes(struct hlsl_ctx *ctx, struct hlsl_block *bod
progress |= replace_ir(ctx, fold_swizzle_chains, body);
progress |= replace_ir(ctx, fold_trivial_swizzles, body);
progress |= hlsl_transform_ir(ctx, remove_trivial_conditional_branches, body, NULL);
progress |= hlsl_transform_ir(ctx, flatten_conditional_branches, body, NULL);
} while (progress);
replace_ir(ctx, fold_redundant_casts, body);
}
@@ -10047,11 +10275,9 @@ static void sm1_generate_vsir_instr_if(struct hlsl_ctx *ctx, struct vsir_program
struct hlsl_ir_node *instr = &iff->node;
struct vkd3d_shader_instruction *ins;
if (hlsl_version_lt(ctx, 2, 1))
{
hlsl_fixme(ctx, &instr->loc, "Flatten \"if\" conditionals branches.");
return;
}
/* Conditional branches should have already been flattened for SM < 2.1. */
VKD3D_ASSERT(hlsl_version_ge(ctx, 2, 1));
VKD3D_ASSERT(condition->data_type->e.numeric.dimx == 1 && condition->data_type->e.numeric.dimy == 1);
if (!(ins = generate_vsir_add_program_instruction(ctx, program, &instr->loc, VSIR_OP_IFC, 0, 2)))
@@ -14880,6 +15106,14 @@ static void process_entry_function(struct hlsl_ctx *ctx, struct list *semantic_v
hlsl_run_folding_passes(ctx, body);
if (profile->major_version < 4)
{
/* Ternary operations can be potentially introduced by hlsl_run_folding_passes(). */
replace_ir(ctx, lower_ternary, body);
if (ctx->profile->type != VKD3D_SHADER_TYPE_PIXEL)
replace_ir(ctx, lower_cmp, body);
}
do
compute_liveness(ctx, body);
while (hlsl_transform_ir(ctx, dce, body, NULL));

View File

@@ -175,6 +175,7 @@ enum vkd3d_shader_error
VKD3D_SHADER_ERROR_HLSL_MISSING_PRIMITIVE_TYPE = 5043,
VKD3D_SHADER_ERROR_HLSL_MISPLACED_STREAM_OUTPUT = 5044,
VKD3D_SHADER_ERROR_HLSL_MISSING_INPUT_PATCH = 5045,
VKD3D_SHADER_ERROR_HLSL_CANNOT_FLATTEN = 5046,
VKD3D_SHADER_WARNING_HLSL_IMPLICIT_TRUNCATION = 5300,
VKD3D_SHADER_WARNING_HLSL_DIVISION_BY_ZERO = 5301,

View File

@@ -113,7 +113,7 @@ float4 main() : sv_target
return 0;
}
[pixel shader todo(sm<4)]
[pixel shader]
uniform float1 f;
float4 main() : sv_target
{
@@ -124,8 +124,8 @@ float4 main() : sv_target
[test]
uniform 0 float4 -2.0 0.0 0.0 0.0
todo(sm<4) draw quad
probe (0, 0) rgba (1.0, 1.0, 1.0, 1.0)
draw quad
probe (0, 0) f32(1.0, 1.0, 1.0, 1.0)
uniform 0 float4 -0.0 0.0 0.0 0.0
todo(sm<4) draw quad
probe (0, 0) rgba (0.0, 0.0, 0.0, 0.0)
draw quad
probe (0, 0) f32(0.0, 0.0, 0.0, 0.0)

View File

@@ -1,4 +1,4 @@
[pixel shader todo(sm<4)]
[pixel shader]
uniform float4 u;
float4 main() : sv_target
@@ -11,13 +11,13 @@ float4 main() : sv_target
[test]
uniform 0 float4 0.0 0.0 0.0 0.0
todo(sm<4) draw quad
probe (0, 0) rgba (0.9, 0.8, 0.7, 0.6)
draw quad
probe (0, 0) f32(0.9, 0.8, 0.7, 0.6)
uniform 0 float4 0.1 0.0 0.0 0.0
todo(sm<4) draw quad
probe (0, 0) rgba (0.1, 0.2, 0.3, 0.4)
draw quad
probe (0, 0) f32(0.1, 0.2, 0.3, 0.4)
[pixel shader todo(sm<4)]
[pixel shader]
uniform float4 u;
float4 main() : sv_target
@@ -29,7 +29,7 @@ float4 main() : sv_target
return float4(0.9, 0.8, 0.7, 0.6);
}
[pixel shader todo(sm<4)]
[pixel shader]
uniform float4 u;
float4 main() : sv_target
@@ -43,8 +43,8 @@ float4 main() : sv_target
[test]
uniform 0 float4 0.0 0.0 0.0 0.0
todo(sm<4) draw quad
probe (0, 0) rgba (0.9, 0.8, 0.7, 0.6)
draw quad
probe (0, 0) f32(0.9, 0.8, 0.7, 0.6)
[pixel shader fail(sm<6)]
float4 u;
@@ -370,7 +370,7 @@ todo(msl & sm>=6) draw quad
probe (0, 0) rgba (1.0, 1.0, 0.0, 4.0)
% Branches with resource stores can't be flattened.
[pixel shader fail(sm<6) todo]
[pixel shader fail(sm<6)]
uniform float a;
RWBuffer<float> u;

View File

@@ -16,7 +16,7 @@ uniform 0 float4 9 8 7 6
todo(sm<4 | glsl | msl & sm>=6) draw quad
probe (0, 0) f32(1, 2, 3, 4)
[pixel shader todo(sm<4)]
[pixel shader todo]
uniform float4 x;
float4 main() : sv_target
@@ -29,10 +29,10 @@ float4 main() : sv_target
[test]
uniform 0 float4 1 2 3 4
todo(sm<4 | glsl | msl & sm>=6) draw quad
todo(sm<6 | msl) draw quad
probe (0, 0) f32(1, 2, 3, 4)
uniform 0 float4 9 8 7 6
todo(sm<4 | glsl | msl & sm>=6) draw quad
todo(sm<6 | msl) draw quad
probe (0, 0) f32(1, 2, 3, 4)
[pixel shader todo(sm<4)]
@@ -56,7 +56,7 @@ uniform 0 float4 9 8 7 6
todo(sm<4 | glsl | msl & sm>=6) draw quad
probe (0, 0) f32(1, 2, 3, 4)
[pixel shader todo(sm<4)]
[pixel shader todo]
uniform float4 x;
float4 main() : sv_target
@@ -72,10 +72,10 @@ float4 main() : sv_target
[test]
uniform 0 float4 1 2 3 4
todo(sm<4 | glsl | msl & sm>=6) draw quad
todo(sm<6 | msl) draw quad
probe (0, 0) f32(1, 2, 3, 4)
uniform 0 float4 9 8 7 6
todo(sm<4 | glsl | msl & sm>=6) draw quad
todo(sm<6 | msl) draw quad
probe (0, 0) f32(1, 2, 3, 4)
[require]

View File

@@ -5,7 +5,7 @@ void main(float4 pos : position, out float tex : texcoord, out float4 out_pos :
out_pos = pos;
}
[pixel shader todo(sm<4)]
[pixel shader]
float4 main(float tex : texcoord) : sv_target
{
int i;
@@ -23,10 +23,10 @@ float4 main(float tex : texcoord) : sv_target
}
[test]
todo(sm<4) draw quad
probe ( 0, 0, 159, 480) rgba (10.0, 35.0, 0.0, 0.0)
probe (161, 0, 479, 480) rgba (10.0, 38.0, 0.0, 0.0)
probe (481, 0, 640, 480) rgba ( 5.0, 10.0, 0.0, 0.0)
draw quad
probe ( 0, 0, 159, 480) f32(10.0, 35.0, 0.0, 0.0)
probe (161, 0, 479, 480) f32(10.0, 38.0, 0.0, 0.0)
probe (481, 0, 640, 480) f32( 5.0, 10.0, 0.0, 0.0)
[require]
shader model >= 4.0

View File

@@ -32,7 +32,7 @@ float4 main() : sv_target
draw quad
probe (0, 0) rgba (0.2, 0.1, 0.8, 0.5);
[pixel shader todo(sm<4)]
[pixel shader]
uniform float f;
float func(out float o)
@@ -79,19 +79,19 @@ float4 main() : sv_target
[test]
uniform 0 float 0.1
todo(sm<4) draw quad
probe (0, 0) rgba (0.3, 0.2, 0.6, 0.3) 1
draw quad
probe (0, 0) f32(0.3, 0.2, 0.6, 0.3) 1
uniform 0 float 0.4
todo(sm<4) draw quad
probe (0, 0) rgba (0.6, 0.5, 0.6, 0.3) 1
draw quad
probe (0, 0) f32(0.6, 0.5, 0.6, 0.3) 1
uniform 0 float 0.6
todo(sm<4) draw quad
probe (0, 0) rgba (0.6, 0.5, 0.4, 0.5) 1
draw quad
probe (0, 0) f32(0.6, 0.5, 0.4, 0.5) 1
uniform 0 float 0.8
todo(sm<4) draw quad
probe (0, 0) rgba (0.8, 0.7, 0.4, 0.5) 1
draw quad
probe (0, 0) f32(0.8, 0.7, 0.4, 0.5) 1
[pixel shader todo(sm<4)]
[pixel shader]
uniform float f;
float func(out float o)
@@ -134,14 +134,14 @@ float4 main() : sv_target
[test]
uniform 0 float 0.1
todo(sm<4 | msl & sm>=6) draw quad
probe (0, 0) rgba (0.2, 0.1, 0.2, 0.1) 1
todo(msl & sm>=6) draw quad
probe (0, 0) f32(0.2, 0.1, 0.2, 0.1) 1
uniform 0 float 0.5
todo(sm<4 | msl & sm>=6) draw quad
probe (0, 0) rgba (0.5, 0.4, 1.0, 0.9) 1
todo(msl & sm>=6) draw quad
probe (0, 0) f32(0.5, 0.4, 1.0, 0.9) 1
uniform 0 float 0.9
todo(sm<4 | msl & sm>=6) draw quad
probe (0, 0) rgba (1.0, 0.9, 1.0, 0.6) 1
todo(msl & sm>=6) draw quad
probe (0, 0) f32(1.0, 0.9, 1.0, 0.6) 1
[pixel shader]
float func(out float o)
@@ -184,7 +184,7 @@ float4 main() : sv_target
draw quad
probe (0, 0) rgba (0.4, 0.3, 0.3, 0.9) 1
[pixel shader todo(sm<4)]
[pixel shader]
uniform float f;
float func(out float o)
@@ -235,26 +235,26 @@ float4 main() : sv_target
[test]
uniform 0 float 0.0
todo(sm<4) draw quad
probe (0, 0) rgba (0.3, 0.2, 0.3, 0.3) 1
draw quad
probe (0, 0) f32(0.3, 0.2, 0.3, 0.3) 1
uniform 0 float 0.1
todo(sm<4) draw quad
probe (0, 0) rgba (0.3, 0.3, 0.3, 0.3) 1
draw quad
probe (0, 0) f32(0.3, 0.3, 0.3, 0.3) 1
uniform 0 float 0.3
todo(sm<4) draw quad
probe (0, 0) rgba (0.3, 0.5, 0.3, 0.3) 1
draw quad
probe (0, 0) f32(0.3, 0.5, 0.3, 0.3) 1
uniform 0 float 0.7
todo(sm<4) draw quad
probe (0, 0) rgba (0.3, 0.9, 0.7, 0.6) 1
draw quad
probe (0, 0) f32(0.3, 0.9, 0.7, 0.6) 1
uniform 0 float 0.9
todo(sm<4) draw quad
probe (0, 0) rgba (0.4, 0.1, 0.7, 0.6) 1
draw quad
probe (0, 0) f32(0.4, 0.1, 0.7, 0.6) 1
[pixel shader todo(sm<4)]
[pixel shader]
uniform float4 f[3];
@@ -291,24 +291,24 @@ float4 main() : sv_target
uniform 0 float4 0.3 0.0 0.0 0.0
uniform 4 float4 0.0 0.0 0.0 0.0
uniform 8 float4 0.1 0.0 0.0 0.0
todo(sm<4) draw quad
probe (0, 0) rgba (0.3, 0.2, 0.6, 0.6) 1
draw quad
probe (0, 0) f32(0.3, 0.2, 0.6, 0.6) 1
uniform 4 float4 0.35 0.0 0.0 0.0
todo(sm<4) draw quad
probe (0, 0) rgba (0.3, 0.3, 0.6, 0.6) 1
draw quad
probe (0, 0) f32(0.3, 0.3, 0.6, 0.6) 1
uniform 8 float4 0.5 0.0 0.0 0.0
todo(sm<4) draw quad
draw quad
% Apparently fixed by Mesa commit 9785fa460c41b9498c24a82b98069655a91224c5,
% which only adds optimization; so it might just be hiding the bug rather than
% solving it; see also https://gitlab.freedesktop.org/mesa/mesa/-/issues/13092
bug(mesa<25.1 & llvm>=16) probe (0, 0) f32(0.3, 0.5, 0.6, 0.6) 1
uniform 0 float4 1.0 0.0 0.0 0.0
todo(sm<4) draw quad
probe (0, 0) rgba (0.3, 0.5, 0.6, 0.6) 1
draw quad
probe (0, 0) f32(0.3, 0.5, 0.6, 0.6) 1
uniform 4 float4 2.0 0.0 0.0 0.0
todo(sm<4) draw quad
probe (0, 0) rgba (0.4, 0.1, 0.6, 0.6) 1
draw quad
probe (0, 0) f32(0.4, 0.1, 0.6, 0.6) 1

View File

@@ -1,4 +1,4 @@
[pixel shader todo(sm<4)]
[pixel shader]
float cond;
float4 main() : sv_target
@@ -17,14 +17,13 @@ float4 main() : sv_target
[test]
uniform 0 float 0.0
todo(sm<4) draw quad
probe (0, 0) rgba (2.0, 2.0, 2.0, 2.0)
draw quad
probe (0, 0) f32(2.0, 2.0, 2.0, 2.0)
uniform 0 float 1.0
todo(sm<4) draw quad
probe (0, 0) rgba (-2.0, -2.0, -2.0, -2.0)
draw quad
probe (0, 0) f32(-2.0, -2.0, -2.0, -2.0)
[pixel shader todo(sm<4)]
[pixel shader]
float cond;
float4 main() : sv_target
@@ -43,14 +42,13 @@ float4 main() : sv_target
[test]
uniform 0 float 0.0
todo(sm<4) draw quad
probe (0, 0) rgba (2.0, 2.0, 2.0, 2.0)
draw quad
probe (0, 0) f32(2.0, 2.0, 2.0, 2.0)
uniform 0 float 1.0
todo(sm<4) draw quad
probe (0, 0) rgba (20.0, 20.0, 20.0, 20.0)
draw quad
probe (0, 0) f32(20.0, 20.0, 20.0, 20.0)
[pixel shader todo(sm<4)]
[pixel shader]
float cond;
float4 main() : sv_target
@@ -69,11 +67,11 @@ float4 main() : sv_target
[test]
uniform 0 float 0.0
todo(sm<4) draw quad
probe (0, 0) rgba (1.0, 4.0, 0.0, 0.0)
draw quad
probe (0, 0) f32(1.0, 4.0, 0.0, 0.0)
uniform 0 float 1.0
todo(sm<4) draw quad
probe (0, 0) rgba (1.0, 40.0, 0.0, 0.0)
draw quad
probe (0, 0) f32(1.0, 40.0, 0.0, 0.0)
[pixel shader]
float x[6];
@@ -206,7 +204,7 @@ float4 main() : sv_target
return 0;
}
[pixel shader todo(sm<4)]
[pixel shader]
float a;
float4 main() : sv_target
@@ -221,8 +219,8 @@ float4 main() : sv_target
[test]
uniform 0 float 11.0
todo(sm<4) draw quad
probe (0, 0) rgba(1, 2, 3, 5)
draw quad
probe (0, 0) f32(1, 2, 3, 5)
[require]
shader model < 5.1

View File

@@ -25,7 +25,7 @@ void main(out float4 ret : sv_target)
draw quad
probe (0, 0) rgba (0.1, 0.2, 0.3, 0.4)
[pixel shader todo(sm<4)]
[pixel shader]
uniform float f;
float4 main() : sv_target
@@ -37,13 +37,13 @@ float4 main() : sv_target
[test]
uniform 0 float 0.2
todo(sm<4) draw quad
probe (0, 0) rgba (0.1, 0.2, 0.3, 0.4)
draw quad
probe (0, 0) f32(0.1, 0.2, 0.3, 0.4)
uniform 0 float 0.8
todo(sm<4) draw quad
probe (0, 0) rgba (0.5, 0.6, 0.7, 0.8)
draw quad
probe (0, 0) f32(0.5, 0.6, 0.7, 0.8)
[pixel shader todo(sm<4)]
[pixel shader]
uniform float f;
void main(out float4 ret : sv_target)
@@ -63,13 +63,13 @@ void main(out float4 ret : sv_target)
[test]
uniform 0 float 0.2
todo(sm<4) draw quad
probe (0, 0) rgba (0.3, 0.4, 0.5, 0.6)
draw quad
probe (0, 0) f32(0.3, 0.4, 0.5, 0.6)
uniform 0 float 0.8
todo(sm<4) draw quad
probe (0, 0) rgba (0.1, 0.2, 0.3, 0.4)
draw quad
probe (0, 0) f32(0.1, 0.2, 0.3, 0.4)
[pixel shader todo(sm<4)]
[pixel shader]
uniform float f;
void main(out float4 ret : sv_target)
@@ -89,16 +89,16 @@ void main(out float4 ret : sv_target)
[test]
uniform 0 float 0.1
todo(sm<4) draw quad
probe (0, 0) rgba (0.1, 0.2, 0.3, 0.4) 1
draw quad
probe (0, 0) f32(0.1, 0.2, 0.3, 0.4) 1
uniform 0 float 0.5
todo(sm<4) draw quad
probe (0, 0) rgba (0.2, 0.3, 0.4, 0.5) 1
draw quad
probe (0, 0) f32(0.2, 0.3, 0.4, 0.5) 1
uniform 0 float 0.9
todo(sm<4) draw quad
probe (0, 0) rgba (0.5, 0.6, 0.7, 0.8) 1
draw quad
probe (0, 0) f32(0.5, 0.6, 0.7, 0.8) 1
[pixel shader todo(sm<4)]
[pixel shader]
uniform float f;
void main(out float4 ret : sv_target)
@@ -115,14 +115,14 @@ void main(out float4 ret : sv_target)
[test]
uniform 0 float 0.1
todo(sm<4) draw quad
probe (0, 0) rgba (0.1, 0.2, 0.3, 0.4) 1
draw quad
probe (0, 0) f32(0.1, 0.2, 0.3, 0.4) 1
uniform 0 float 0.5
todo(sm<4) draw quad
probe (0, 0) rgba (0.5, 0.6, 0.7, 0.8) 1
draw quad
probe (0, 0) f32(0.5, 0.6, 0.7, 0.8) 1
uniform 0 float 0.9
todo(sm<4) draw quad
probe (0, 0) rgba (0.4, 0.5, 0.6, 0.7) 1
draw quad
probe (0, 0) f32(0.4, 0.5, 0.6, 0.7) 1
[pixel shader]
void main(out float4 ret : sv_target)
@@ -141,7 +141,7 @@ void main(out float4 ret : sv_target)
draw quad
probe (0, 0) rgba (0.2, 0.4, 0.6, 0.8)
[pixel shader todo(sm<4)]
[pixel shader]
uniform float f;
void main(out float4 ret : sv_target)
@@ -160,26 +160,26 @@ void main(out float4 ret : sv_target)
[test]
uniform 0 float 0.0
todo(sm<4) draw quad
probe (0, 0) rgba (0.1, 0.1, 0.1, 0.1) 1
draw quad
probe (0, 0) f32(0.1, 0.1, 0.1, 0.1) 1
uniform 0 float 0.1
todo(sm<4) draw quad
probe (0, 0) rgba (0.2, 0.2, 0.2, 0.2) 1
draw quad
probe (0, 0) f32(0.2, 0.2, 0.2, 0.2) 1
uniform 0 float 0.3
todo(sm<4) draw quad
probe (0, 0) rgba (0.4, 0.4, 0.4, 0.4) 1
draw quad
probe (0, 0) f32(0.4, 0.4, 0.4, 0.4) 1
uniform 0 float 0.7
todo(sm<4) draw quad
probe (0, 0) rgba (0.8, 0.8, 0.8, 0.8) 1
draw quad
probe (0, 0) f32(0.8, 0.8, 0.8, 0.8) 1
uniform 0 float 0.9
todo(sm<4) draw quad
probe (0, 0) rgba (0.9, 0.9, 0.9, 0.9) 1
draw quad
probe (0, 0) f32(0.9, 0.9, 0.9, 0.9) 1
[pixel shader todo(sm<4)]
[pixel shader]
uniform float f;
void main(out float4 ret : sv_target)
@@ -204,13 +204,13 @@ void main(out float4 ret : sv_target)
[test]
uniform 0 float 0.2
todo(sm<4) draw quad
probe (0, 0) rgba (0.2, 0.2, 0.2, 0.2)
draw quad
probe (0, 0) f32(0.2, 0.2, 0.2, 0.2)
uniform 0 float 0.8
todo(sm<4) draw quad
probe (0, 0) rgba (0.5, 0.5, 0.5, 0.5)
draw quad
probe (0, 0) f32(0.5, 0.5, 0.5, 0.5)
[pixel shader todo(sm<4)]
[pixel shader]
uniform float4 f[3];
@@ -236,23 +236,23 @@ void main(out float4 ret : sv_target)
uniform 0 float4 0.3 0.0 0.0 0.0
uniform 4 float4 0.0 0.0 0.0 0.0
uniform 8 float4 0.1 0.0 0.0 0.0
todo(sm<4) draw quad
probe (0, 0) rgba (0.1, 0.1, 0.1, 0.1) 1
draw quad
probe (0, 0) f32(0.1, 0.1, 0.1, 0.1) 1
uniform 4 float4 0.35 0.0 0.0 0.0
todo(sm<4) draw quad
probe (0, 0) rgba (0.2, 0.2, 0.2, 0.2) 1
draw quad
probe (0, 0) f32(0.2, 0.2, 0.2, 0.2) 1
uniform 8 float4 0.5 0.0 0.0 0.0
todo(sm<4) draw quad
probe (0, 0) rgba (0.4, 0.4, 0.4, 0.4) 1
draw quad
probe (0, 0) f32(0.4, 0.4, 0.4, 0.4) 1
uniform 0 float4 1.0 0.0 0.0 0.0
todo(sm<4) draw quad
probe (0, 0) rgba (0.4, 0.4, 0.4, 0.4) 1
draw quad
probe (0, 0) f32(0.4, 0.4, 0.4, 0.4) 1
uniform 4 float4 2.0 0.0 0.0 0.0
todo(sm<4) draw quad
draw quad
% Apparently fixed by Mesa commit 9785fa460c41b9498c24a82b98069655a91224c5,
% which only adds optimization; so it might just be hiding the bug rather than
% solving it; see also https://gitlab.freedesktop.org/mesa/mesa/-/issues/13092

View File

@@ -1,6 +1,6 @@
% Unrolling edge cases.
[pixel shader todo(sm<4)]
[pixel shader]
float a : register(c0);
float4 main() : sv_target
@@ -19,8 +19,8 @@ float4 main() : sv_target
[test]
uniform 0 float 1
todo(sm<4) draw quad
probe (0,0) rgba(10.0, 1.0, 2.0, 3.0)
draw quad
probe (0,0) f32(10.0, 1.0, 2.0, 3.0)
[pixel shader]
float4 main() : sv_target