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

@@ -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