You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Adding constant half precision value with 'h' postfix in HLSL promotes operation to full precision #7811
Description
When adding a constant half precision value in HLSL using the 'h' postfix (e.g. + 1.0h), the resulting operation is incorrectly promoted to full precision. However, if the constant does not use the 'h' postfix (e.g. + 1.0), the operation remains in half precision as expected. This behavior is inconsistent and leads to incorrect precision in generated output.
This is a question for Chris B (@llvm-beanz). I believe this is expected behaviour. When you do not use -enable-16bit-types, the half types does not exist, and it the same as a float. This is then the same issue as #7791.
See the recommended solution there. You need to cast the literals to min16float explicitly. There is not suffix for a min16float literal.
This is a question for @llvm-beanz. I believe this is expected behaviour. When you do not use -enable-16bit-types, the half types does not exist, and it the same as a float. This is then the same issue as #7791.
See the recommended solution there. You need to cast the literals to min16float explicitly. There is not suffix for a min16float literal.
Thank you for the clarification. I understand that enabling -enable-16bit-types would require additional extensions when converting to ESSL, and since these extensions have very low support rates on Android, we can only use relaxed precision decoration instead.
To summarize my understanding:
min16float corresponds to mediump in ES, representing a relaxed 16-bit float (which drivers may interpret as 32-bit float when necessary)
float16_t corresponds to float16 in Vulkan GLSL, representing a strict 16-bit float
Chris B (@llvm-beanz) - this seems to interact with -HV 202x as well. I'm going to put this in the 202x milestone so we can try and bottom out on what we think the right thing to do here is.
Activity
damyanp commentedon Oct 9, 2025
A couple of quick thoughts:
min16float3rather thanhalf3?-enable-16bit-typeson the command line and usehalf.wegatron commentedon Oct 10, 2025
I want to generate spirv with relaxed decoration.
damyanp commentedon Oct 10, 2025
Could you come up with a repro that demonstrates what you're expecting to see with
-spirvplease?s-perron commentedon Oct 10, 2025
This is a question for Chris B (@llvm-beanz). I believe this is expected behaviour. When you do not use
-enable-16bit-types, thehalftypes does not exist, and it the same as a float. This is then the same issue as #7791.See the recommended solution there. You need to cast the literals to min16float explicitly. There is not suffix for a min16float literal.
wegatron commentedon Oct 11, 2025
Compare these two case:
The without
hcase (https://godbolt.org/z/nTEPocra6), the output is decorated as RelaxedPrecisionin this case the spirv-cross output will be
The with
hcase (https://godbolt.org/z/shMGf4qMa), the output have no RelaxPrecision decorationin this case the spirv-cross output will be
wegatron commentedon Oct 11, 2025
Thank you for the clarification. I understand that enabling
-enable-16bit-typeswould require additional extensions when converting to ESSL, and since these extensions have very low support rates on Android, we can only use relaxed precision decoration instead.To summarize my understanding:
min16float corresponds to mediump in ES, representing a relaxed 16-bit float (which drivers may interpret as 32-bit float when necessary)
float16_t corresponds to float16 in Vulkan GLSL, representing a strict 16-bit float
s-perron commentedon Oct 21, 2025
The other part is that
float16_tis the same asfloatin HLSL when you do not use-enable-16bit-types. That is why you see the behaviour you see.damyanp commentedon Oct 29, 2025
Chris B (@llvm-beanz) - this seems to interact with
-HV 202xas well. I'm going to put this in the 202x milestone so we can try and bottom out on what we think the right thing to do here is.