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
It rounds using round-to-nearest-even, which can round 1743028479.999... up to 1743028480. SPIR-V Specification
fnmain(){let x = 1743028480i32;let y = (x asf64)*(1.0 / (i32::MAXasf64));// Without explicit rounding, differs:let without = (y *(i32::MAXasf64))asi32;// Using `trunc()` forces Rust’s truncation:let with = (y *(i32::MAXasf64)).trunc()asi32;println!("x = {}. Without rounding = {}. With trunc() = {}.", x, without, with);}
I'm not sure which should be the default. If it is Rust's we'll want to polyfill on the spir-v side. Might be good to have this user controlled in any case.
There is a footgun when trying to share code between CPU and GPU. Rust and SPIR-V have different semantics when rounding floats:
Rust:
as
truncates the fractional part, effectively rounding toward zero.Rust Language Reference
SPIR-V:
OpConvertFToS
instruction for converting floating-point values to integers. Here is where it happens in rust-gpu.SPIR-V Specification
I'm not sure which should be the default. If it is Rust's we'll want to polyfill on the spir-v side. Might be good to have this user controlled in any case.
Originally posted by @LegNeato in #228 (comment)
The text was updated successfully, but these errors were encountered: