KhronosGroup / KhronosGroup/glslang

glslang doesn't apply `NoContraction` through function parameters when LHS has `precise` fields

Open
#2,710 0 comments 0 reactions 1 assignee Claimed by @greg-lunarg View on GitHub
bug GLSL/ESSL SPIR-V
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;
};

S1 func(float f, int i, vec4 v, mat4 m)
{
m /= f;
--i;
v *= m;
return S1(f, i, v, m);
}

void main()
{
float f = u; // f is precise
int i = int(u); // i is precise
vec4 v1 = vec4(u); // v1 is precise
vec4 v2 = vec4(u); // v2 is precise

f += 1.0; // NoContraction

i--; // NoContraction
i--; // NoContraction

v1 *= 2.0; // NoContraction
v1 *= 2.0; // NoContraction
v1 *= 2.0; // NoContraction
v1 *= 2.0; // NoContraction

v2 /= 3.0; // NoContraction
v2 /= 3.0; // NoContraction
v2 /= 3.0; // NoContraction
v2 /= 3.0; // NoContraction
v2 /= 3.0; // NoContraction
v2 /= 3.0; // NoContraction
v2 /= 3.0; // NoContraction
v2 /= 3.0; // NoContraction
v2 /= 3.0; // NoContraction

// s.f and s.v1 are precise, but to calculate them, all parameters of the function must be made
// precise.
S1 s = func(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 assigns to `s`, which has `precise` fields, should propagate precise-ness to variables `f`, `i`, `v1` and `v2`, making their calculation precise. glslang produces no NoContraction decorations. I believe this is due to the fact that when processing the function arguments, it's attempting to make a "subobject" of them precise (which doesn't exist). That is, [in this code][1], `remained_accesschain_` should be cleared when recursing to function arguments!

[1]: https://github.com/KhronosGroup/glslang/blob/master/glslang/MachineIndependent/propagateNoContraction.cpp#L691

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.