From f7ed1bab355c5c9e26d98c9f44700980e87c2043 Mon Sep 17 00:00:00 2001 From: Zac Harrold Date: Mon, 21 Apr 2025 19:46:25 +1000 Subject: [PATCH 1/2] Rely on `libm` for a `no_std` alternative to `round_ties_even` Update comments around `no_std` CI task --- .github/workflows/ci.yml | 6 ++++-- CHANGELOG.md | 4 ++++ Cargo.lock | 1 + naga/Cargo.toml | 1 + naga/src/back/mod.rs | 7 +++++++ naga/src/proc/constant_evaluator.rs | 4 ++-- 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9cfc2d874..c27d0a67a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 95c000c9b4..12b49a611f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 rendering to slices of 3D texture views and single layered 2D-Array texture views (this requires `VK_KHR_maintenance1` which should be widely available on newer drivers). By @teoxoy in [#7596](https://github.com/gfx-rs/wgpu/pull/7596) diff --git a/Cargo.lock b/Cargo.lock index 94e9041661..9bfd874191 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2513,6 +2513,7 @@ dependencies = [ "hlsl-snapshots", "indexmap", "itertools 0.14.0", + "libm", "log", "num-traits", "once_cell", diff --git a/naga/Cargo.toml b/naga/Cargo.toml index e9a2890003..2a57665552 100644 --- a/naga/Cargo.toml +++ b/naga/Cargo.toml @@ -91,6 +91,7 @@ hashbrown.workspace = true half = { workspace = true, features = ["num-traits"] } rustc-hash.workspace = true indexmap.workspace = true +libm = { version = "0.2", default-features = false } log.workspace = true num-traits.workspace = true once_cell = { workspace = true, features = ["alloc", "race"] } diff --git a/naga/src/back/mod.rs b/naga/src/back/mod.rs index 175c5481b3..d7b14475bf 100644 --- a/naga/src/back/mod.rs +++ b/naga/src/back/mod.rs @@ -46,6 +46,13 @@ pub type NeedBakeExpressions = crate::FastHashSet); impl core::fmt::Display for Baked { diff --git a/naga/src/proc/constant_evaluator.rs b/naga/src/proc/constant_evaluator.rs index 27d6addc82..dca082ec82 100644 --- a/naga/src/proc/constant_evaluator.rs +++ b/naga/src/proc/constant_evaluator.rs @@ -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. // From 17cef376333cdbc372b67340e46c1187ab3b4abb Mon Sep 17 00:00:00 2001 From: Zac Harrold Date: Wed, 30 Apr 2025 22:17:25 +1000 Subject: [PATCH 2/2] Update Cargo.toml --- naga/Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/naga/Cargo.toml b/naga/Cargo.toml index 2a57665552..96d0b4b091 100644 --- a/naga/Cargo.toml +++ b/naga/Cargo.toml @@ -91,7 +91,8 @@ hashbrown.workspace = true half = { workspace = true, features = ["num-traits"] } rustc-hash.workspace = true indexmap.workspace = true -libm = { version = "0.2", default-features = false } +# Earliest version of libm with rint and rintf +libm = { version = "0.2.6", default-features = false } log.workspace = true num-traits.workspace = true once_cell = { workspace = true, features = ["alloc", "race"] }