vkd3d/tests/hlsl-static-initializer.shader_test
Francisco Casas 5cfc8d378f vkd3d-shader/hlsl: Initialize static variables to 0 by default.
We are currently not initializing static values to zero by default.

Consider the following shader:
```hlsl
static float4 va;

float4 main() : sv_target
{
  return va;
}
```
we get the following output:
```
ps_5_0
dcl_output o0.xyzw
dcl_temps 2
mov r0.xyzw, r1.xyzw
mov o0.xyzw, r0.xyzw
ret
```
where r1.xyzw is not initialized.

This patch solves this by assigning the static variable the value of an
uint 0, and thus, relying on complex broadcasts.

This seems to be the behaviour of the 9.29.952.3111 version of the native
compiler, since it retrieves the following error on a shader that lacks
an initializer on a data type with object components:

```
error X3017: cannot convert from 'uint' to 'struct <unnamed>'
```
2023-01-19 12:29:36 +01:00

26 lines
327 B
Plaintext

[pixel shader]
float myfunc()
{
return 0.6;
}
static float a = myfunc() + 0.2;
static float b;
static const float c;
float4 main() : sv_target
{
return float4(a, b, c, 0);
}
[test]
draw quad
todo probe all rgba (0.8, 0.0, 0.0, 0.0)
[pixel shader fail]
static uint i;
float4 main() : sv_target
{
return 1 / i;
}