-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Non-32-bit integer overflow should be well-defined in Naga-enhanced WGSL, but Naga generates HLSL with UB #7109
Comments
I will note that it's IB not UB. https://microsoft.github.io/hlsl-specs/specs/hlsl.html#Conv.iconv |
You both beat me to the punch, for filing the issue in the first place and then explaining that it's implementation-defined 😄 To clarify for future readers: as things stand we don't do any conversion, we just operate on signed types, for which we believe overflow is undefined behaviour. For 32-bit signed integers we avoid this by using Or if we want to be fully above board we could do something like this: int64_t to_signed(uint64_t u) {
return u <= INT64_MAX ? int64_t(u) : -int64_t(-u);
} I checked on godbolt and DXC seems to be smart enough to optimize that away |
Actually I think that's still UB if |
Maybe int64_t to_signed(uint64_t u) {
return u <= INT64_MAX ? int64_t(u) : int64_t(u - uint64_t(INT64_MIN)) + INT64_MIN;
} |
I reverted the title, as the current situation (signed overflow) is indeed UB 🙂 |
I hate all of this. |
…ivision, modulo, abs(), and unary negation Explain we need the wrapper functions not just to avoid undefined behaviour, but also to ensure we adhere to the WGSL spec. Additionally link to issue gfx-rs#7109 in cases where our workaround needs follow-up work for non-32-bit integer types.
…ivision, modulo, abs(), and unary negation Explain we need the wrapper functions not just to avoid undefined behaviour, but also to ensure we adhere to the WGSL spec. Additionally link to issue gfx-rs#7109 in cases where our workaround needs follow-up work for non-32-bit integer types.
…ivision, modulo, abs(), and unary negation Explain we need the wrapper functions not just to avoid undefined behaviour, but also to ensure we adhere to the WGSL spec. Additionally link to issue #7109 in cases where our workaround needs follow-up work for non-32-bit integer types.
…ivision, modulo, abs(), and unary negation Explain we need the wrapper functions not just to avoid undefined behaviour, but also to ensure we adhere to the WGSL spec. Additionally link to issue gfx-rs#7109 in cases where our workaround needs follow-up work for non-32-bit integer types.
#7012 ensures that 32-bit signed integer overflow cannot cause UB in HLSL, but it doesn't address other integer bit widths. Official WGSL only has 32-bit integers anyway, but Naga has a 64-bit integer extension, and you could imagine a 16-bit integer extension as well. These should all work the same way as official WGSL integers do.
The text was updated successfully, but these errors were encountered: