KhronosGroup / KhronosGroup/glslang
glslang doesn't apply `NoContraction` through struct constructors
- Dominant language
- C++
- Stars
- 3.6k
- Forks
- 989
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 31
Description
Noticed while implementing a similar algorithm in ANGLE. Take the following shader:
```c
#version 450 core
float u;
struct S1
{
precise float f;
int i;
precise vec4 v;
mat4 m;
};
void main()
{
float f = u; // f is precise
int i = int(u);
vec4 v1 = vec4(u); // v1 is precise
vec4 v2 = vec4(u);
f += 1.0; // NoContraction
i--;
i--;
v1 *= 2.0; // NoContraction
v1 *= 2.0; // NoContraction
v1 *= 2.0; // NoContraction
v1 *= 2.0; // NoContraction
v2 /= 3.0;
v2 /= 3.0;
v2 /= 3.0;
v2 /= 3.0;
v2 /= 3.0;
v2 /= 3.0;
v2 /= 3.0;
v2 /= 3.0;
v2 /= 3.0;
S1 s = S1(f, i, v1, mat4(v2, v2, v2, v2));
gl_Position = vec4(s.f, float(s.i), s.v[0], s.m[0][0]);
}
```
The line that constructs S1 should propagate precise-ness to variables `f` and `v1`, making their calculation precise. glslang produces no `NoContraction` decorations. It's not for a lack of trying though, [there is code][1] that's supposed to do this.
[1]: https://github.com/KhronosGroup/glslang/blob/master/glslang/MachineIndependent/propagateNoContraction.cpp#L666
Contributor guide
Assessment
This issue has not been assessed yet.