glslang
glslang copied to clipboard
[HLSL] Wrong precision of built-in functions
I have a problem while compiling HLSL to Spir-V. Built-in function's precision are not calculated by it's operands. Here is an example. http://shader-playground.timjones.io/0706b6081a3d0a341b373bbbf7923d9a
struct PSInput
{
float4 color : COLOR;
};
min16float f(in min16float a, in min16float b)
{
return max(a, b);
}
min16float f2(in min16float a)
{
return a * a;
}
float4 PSMain(PSInput input) : SV_TARGET
{
min16float a = input.color.a;
min16float b = input.color.b;
min16float c = f(a, b);
min16float d = f2(max(a, b));
return float4(c,d,c,c);
}
In the above code, all operations should have relaxed precision. Microsoft dxc compiler would mark them all to relaxed precision. But when using glslang, the two max results don't have relaxed precision decoration.
min16float is currently steered to either float16 or just float, depending on whether 16-bit types are enabled, e.g., through --hlsl-enable-16bit-types
.
Yeah it is float, I didn't use --hlsl-enable-16bit-types option. But it's not equal to float, it should has RelaxedPrecision as decoration in vulkan code.
We are facing the same problem. I experiment with the following code:
half3 N = half3(0.0, 0.0, 1.0);
half3 L = half3(0.0, 0.0, 1.0);
half NdotL = dot(N, L);
that generates the following error in the last line:
'=' : cannot convert from ' temp float' to ' temp float16_t'
This happens because the result of dot
is float
, not half
.
The following change fixes the error:
half NdotL = half(dot(N, L));
Is there a chance this issue can be fixed?
With all intrinsic converting halfs to floats, half floats are not very useful.
I use GLSLang in the code and I set the EShMsgHlslEnable16BitTypes
flag.
It would be great if this long standing issue gets fixed. 🙏
I would appreciate this being fixed, as well! For complete 16bit float support, am I correct that the low precision templated texture types are missing?
When trying to parse a Texture2D<min16float4>
I get the message error: 'basic type in texture' : Unimplemented
Any ETA as of 2024? Still having the issue as well after all these years. Half-precision floats have their use on mobile :)