vkd3d-shader/hlsl: Fold basic idempotencies.
While not strictly necessary, this pass allows to remove some unnecessary instructions.
For instance:
float4 a;
float4 main() : sv_target
{
float4 zero = {0, 0, 0, 0};
float4 one = {1, 1, 1, 1};
return a + zero + a * one + zero * one;
}
Compiles to:
ps_4_0
dcl_constantbuffer cb0[1], immediateIndexed
dcl_output o0.xyzw
dcl_temps 1
mov r0.xyzw, cb0[0].xyzw
add r0.xyzw, r0.xyzw, r0.xyzw
mov o0.xyzw, r0.xyzw
ret
Instead of
ps_4_0
dcl_constantbuffer cb0[1], immediateIndexed
dcl_output o0.xyzw
dcl_temps 2
mov r0.xyzw, cb0[0].xyzw
add r1.xyzw, r0.xyzw, l(0.000000, 0.000000, 0.000000, 0.000000)
mul r0.xyzw, r0.xyzw, l(1.000000, 1.000000, 1.000000, 1.000000)
add r0.xyzw, r1.xyzw, r0.xyzw
add r0.xyzw, r0.xyzw, l(0.000000, 0.000000, 0.000000, 0.000000)
mov o0.xyzw, r0.xyzw
ret