mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Currently we generate code to convert floating point values to integers using constructor-style casts in HLSL, static_cast in MSL, and OpConvertFToS/OpConvertFToU instructions in SPV. Unfortunately the behaviour of these operations is undefined when the original value is outside of the range of the target type. This patch avoids undefined behaviour by first clamping the value to be inside the target type's range, then performing the cast. Additionally, we specifically clamp to the minimum and maximum values that are exactly representable in both the original and the target type, as per the WGSL spec[1]. Note that these may not be the same as the minimum and maximum values of the target type. We additionally must ensure we clamp in the same manner for conversions during const evaluation. Lastly, although not part of the WGSL spec, we do the same for casting from F64 and/or to I64 or U64. [1] https://www.w3.org/TR/WGSL/#floating-point-conversion
5 lines
130 B
TOML
5 lines
130 B
TOML
# Other backends are tested by conversion-float-to-int.wgsl which is a
|
|
# superset of this test.
|
|
targets = "METAL"
|
|
god_mode = true
|