Hi,
Recently I encountered a strange problem when using Angle's Vulkan backend on RTX3080 card with the latest driver.
Here is the simplified pixel shader in question:
out vec4 color;
void main() {
mediump vec4 a = vec4(0.6, 0.6, 0.6, 1.0);
mediump float m = max(max(a.x, a.y), a.z);
if (m == a.x || m == a.y || m == a.z) { // should be always true
color = vec4(0.0, 1.0, 0.0, 1.0); // green color
} else {
color = vec4(1.0, 0.0, 0.0, 1.0); // red color
}
}
In this shader, a constant vec4 'a' is given, and 'm' is the largest component of
a.xyz.
By looking at the source, the if check should always be true and the output color should be green.
However, on RTX3080, when runing with vulkan backend, the output is red.
Interestingly, there are several ways to make it right:
1. remove all mediump decorators. Or
2. change a to vec4(0.5, 0.5, 0.5, 1.0). Or
3. turn off the enablePrecisionQualifiers feature in vulkan backend. Or
3. use a different gpu, like GTX1650.
So this issue should related to the shader variable precision handling.
I noticed [[RelaxedPrecision]] decoration is added in the shader spirv to the corresponding variable.
I am not familier with spirv, and my question is:
* I checked the spirv spec and it provides OpTypeFloat to explicitly indicate the bit size of a float,
why using [[RelaxedPrecision]] instead of OpTypeFloat. Also I found that [[RelaxedPrecision]]'s documentation
is a bit hard to follow and seems its behavior is relying on the implementation?
* Given the previous thought, what is the real reason of the previous problem.
Can we treat it as a driver bug? or is it because of the undefined hehavior of [[RelaxedPrecision]], and we encounter
a rare but reasonable situation, which means the spriv generated should be adjusted in some way.
* As a cheap workaround of this problem, we can turn off enablePrecisionQualifiers in Angle, removing all
[[RelaxedPrecision]]. Will this hurt the performance? and if so, by how much? Again I am not familier with spirv and
its performance, and I hope anyone can give me a general idea that how serious this change will impact performance.
It has been a long way to finally locate this issue and now I am stuck here, any help will be much appreciated. Thank you.
Yours.