[naga]: Add no_std polyfill for round_ties_even for f32 and f64 (#7585)

* Rely on `libm` for a `no_std` alternative to `round_ties_even`

Update comments around `no_std` CI task

* Update Cargo.toml

* Feedback

Co-Authored-By: Connor Fitzgerald <connorwadefitzgerald@gmail.com>

---------

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
This commit is contained in:
Zachary Harrold 2025-05-08 23:59:19 +10:00 committed by GitHub
parent 2a924a330a
commit f04391d916
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 20 additions and 4 deletions

View File

@ -292,7 +292,7 @@ jobs:
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-hal --all-features
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu --all-features
# Building for no_std platforms where every feature is enabled except "std".
# Building for no_std platforms.
- name: Check `no_std`
if: matrix.kind == 'no_std'
shell: bash
@ -301,9 +301,11 @@ jobs:
# check with no features
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-types --no-default-features
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p naga --no-default-features
# Check with all features except "std".
# Check with all compatible features
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-types --no-default-features --features strict_asserts,fragile-send-sync-non-atomic-wasm,serde,counters
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p naga --no-default-features --features dot-out,compact
# Building for native platforms with standard tests.
- name: Check native

View File

@ -42,6 +42,10 @@ Bottom level categories:
### New Features
#### Naga
- Added `no_std` support with default features disabled. By @Bushrat011899 in [#7585](https://github.com/gfx-rs/wgpu/pull/7585).
#### General
- Add support for astc-sliced-3d feature. By @mehmetoguzderin in [#7577](https://github.com/gfx-rs/wgpu/issues/7577)

1
Cargo.lock generated
View File

@ -2513,6 +2513,7 @@ dependencies = [
"hlsl-snapshots",
"indexmap",
"itertools 0.14.0",
"libm",
"log",
"num-traits",
"once_cell",

View File

@ -135,6 +135,7 @@ libc = { version = "0.2.168", default-features = false }
# See https://github.com/rust-fuzz/libfuzzer/issues/126
libfuzzer-sys = ">0.4.0,<=0.4.7"
libloading = "0.8"
libm = { version = "0.2.6", default-features = false }
libtest-mimic = "0.8"
log = "0.4.21"
nanoserde = "0.2"

View File

@ -91,6 +91,7 @@ hashbrown.workspace = true
half = { workspace = true, features = ["num-traits"] }
rustc-hash.workspace = true
indexmap.workspace = true
libm = { workspace = true, default-features = false }
log.workspace = true
num-traits.workspace = true
once_cell = { workspace = true, features = ["alloc", "race"] }

View File

@ -46,6 +46,13 @@ pub type NeedBakeExpressions = crate::FastHashSet<crate::Handle<crate::Expressio
///
/// [`Expression`]: crate::Expression
/// [`Handle`]: crate::Handle
#[cfg_attr(
not(any(glsl_out, hlsl_out, msl_out, wgsl_out)),
allow(
dead_code,
reason = "shared helpers can be dead if none of the enabled backends need it"
)
)]
struct Baked(crate::Handle<crate::Expression>);
impl core::fmt::Display for Baked {

View File

@ -1172,8 +1172,8 @@ impl<'a> ConstantEvaluator<'a> {
}
crate::MathFunction::Round => {
component_wise_float(self, span, [arg], |e| match e {
Float::Abstract([e]) => Ok(Float::Abstract([e.round_ties_even()])),
Float::F32([e]) => Ok(Float::F32([e.round_ties_even()])),
Float::Abstract([e]) => Ok(Float::Abstract([libm::rint(e)])),
Float::F32([e]) => Ok(Float::F32([libm::rintf(e)])),
Float::F16([e]) => {
// TODO: `round_ties_even` is not available on `half::f16` yet.
//