mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
51f13391e6
The structurizer is implemented along the lines of what is usually called the "structured program theorem": the control flow is completely virtualized by mean of an additional TEMP register which stores the block index which is currently running. The whole program is then converted to a huge switch construction enclosed in a loop, executing at each iteration the appropriate block and updating the register depending on block jump instruction. The algorithm's generality is also its major weakness: it accepts any input program, even if its CFG is not reducible, but the output program lacks any useful convergence information. It satisfies the letter of the SPIR-V requirements, but it is expected that it will be very inefficient to run on a GPU (unless a downstream compiler is able to devirtualize the control flow and do a proper convergence analysis pass). The algorithm is however very simple, and good enough to at least pass tests, enabling further development. A better alternative is expected to be upstreamed incrementally. Side note: the structured program theorem is often called the Böhm-Jacopini theorem; Böhm and Jacopini did indeed prove a variation of it, but their algorithm is different from what is commontly attributed to them and implemented here, so I opted for not using their name.
100 lines
1.9 KiB
Plaintext
100 lines
1.9 KiB
Plaintext
[vertex shader]
|
|
void main(float4 pos : position, out float tex : texcoord, out float4 out_pos : sv_position)
|
|
{
|
|
tex = pos.x;
|
|
out_pos = pos;
|
|
}
|
|
|
|
[pixel shader todo(sm<4)]
|
|
float4 main(float tex : texcoord) : sv_target
|
|
{
|
|
int i;
|
|
float x = 0.0;
|
|
[unroll] for (i = 0; i < 10; i++)
|
|
{
|
|
x += i;
|
|
if (tex > 0.5 && i == 5)
|
|
break;
|
|
if (tex > -0.5 && i >= 7)
|
|
continue;
|
|
x -= 1;
|
|
}
|
|
return float4(i, x, 0.0, 0.0);
|
|
}
|
|
|
|
[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)
|
|
|
|
[require]
|
|
shader model >= 4.0
|
|
|
|
% Identical to the previous, except we prevent DXC from unrolling the
|
|
% loop so we can test non-trivial control flow
|
|
[pixel shader]
|
|
uniform uint iter;
|
|
|
|
float4 main(float tex : texcoord) : sv_target
|
|
{
|
|
int i;
|
|
float x = 0.0;
|
|
for (i = 0; i < iter; i++)
|
|
{
|
|
x += i;
|
|
if (tex > 0.5 && i == 5)
|
|
break;
|
|
if (tex > -0.5 && i >= 7)
|
|
continue;
|
|
x -= 1;
|
|
}
|
|
return float4(i, x, 0.0, 0.0);
|
|
}
|
|
|
|
[test]
|
|
uniform 0 uint4 10 0 0 0
|
|
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)
|
|
|
|
|
|
[require]
|
|
% Reset requirements
|
|
|
|
[pixel shader todo(sm<4)]
|
|
float4 main(float tex : texcoord) : sv_target
|
|
{
|
|
int i;
|
|
float x = 0.0;
|
|
[unroll] [attr1] for (i = 0; i < 10; i++)
|
|
{
|
|
x += i;
|
|
}
|
|
return float4(i, x, 0.0, 0.0);
|
|
}
|
|
|
|
[test]
|
|
todo(sm<4) draw quad
|
|
probe all rgba (10.0, 45.0, 0.0, 0.0)
|
|
|
|
[pixel shader fail(sm<6)]
|
|
float4 main(float tex : texcoord) : sv_target
|
|
{
|
|
int i;
|
|
float x = 0.0;
|
|
[unroll] [unroll] for (i = 0; i < 10; i++)
|
|
{
|
|
x += i;
|
|
}
|
|
return float4(i, x, 0.0, 0.0);
|
|
}
|
|
|
|
[pixel shader fail]
|
|
float4 main() : sv_target
|
|
{
|
|
break;
|
|
return float4(0.0, 0.0, 0.0, 0.0);
|
|
}
|