Skip to content

Commit f04391d

Browse files
[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 <[email protected]> --------- Co-authored-by: Connor Fitzgerald <[email protected]>
1 parent 2a924a3 commit f04391d

File tree

7 files changed

+20
-4
lines changed

7 files changed

+20
-4
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ jobs:
292292
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-hal --all-features
293293
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu --all-features
294294
295-
# Building for no_std platforms where every feature is enabled except "std".
295+
# Building for no_std platforms.
296296
- name: Check `no_std`
297297
if: matrix.kind == 'no_std'
298298
shell: bash
@@ -301,9 +301,11 @@ jobs:
301301
302302
# check with no features
303303
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-types --no-default-features
304+
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p naga --no-default-features
304305
305-
# Check with all features except "std".
306+
# Check with all compatible features
306307
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
308+
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p naga --no-default-features --features dot-out,compact
307309
308310
# Building for native platforms with standard tests.
309311
- name: Check native

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ Bottom level categories:
4242

4343
### New Features
4444

45+
#### Naga
46+
47+
- Added `no_std` support with default features disabled. By @Bushrat011899 in [#7585](https://github.com/gfx-rs/wgpu/pull/7585).
48+
4549
#### General
4650

4751
- Add support for astc-sliced-3d feature. By @mehmetoguzderin in [#7577](https://github.com/gfx-rs/wgpu/issues/7577)

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ libc = { version = "0.2.168", default-features = false }
135135
# See https://github.com/rust-fuzz/libfuzzer/issues/126
136136
libfuzzer-sys = ">0.4.0,<=0.4.7"
137137
libloading = "0.8"
138+
libm = { version = "0.2.6", default-features = false }
138139
libtest-mimic = "0.8"
139140
log = "0.4.21"
140141
nanoserde = "0.2"

naga/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ hashbrown.workspace = true
9191
half = { workspace = true, features = ["num-traits"] }
9292
rustc-hash.workspace = true
9393
indexmap.workspace = true
94+
libm = { workspace = true, default-features = false }
9495
log.workspace = true
9596
num-traits.workspace = true
9697
once_cell = { workspace = true, features = ["alloc", "race"] }

naga/src/back/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ pub type NeedBakeExpressions = crate::FastHashSet<crate::Handle<crate::Expressio
4646
///
4747
/// [`Expression`]: crate::Expression
4848
/// [`Handle`]: crate::Handle
49+
#[cfg_attr(
50+
not(any(glsl_out, hlsl_out, msl_out, wgsl_out)),
51+
allow(
52+
dead_code,
53+
reason = "shared helpers can be dead if none of the enabled backends need it"
54+
)
55+
)]
4956
struct Baked(crate::Handle<crate::Expression>);
5057

5158
impl core::fmt::Display for Baked {

naga/src/proc/constant_evaluator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,8 +1172,8 @@ impl<'a> ConstantEvaluator<'a> {
11721172
}
11731173
crate::MathFunction::Round => {
11741174
component_wise_float(self, span, [arg], |e| match e {
1175-
Float::Abstract([e]) => Ok(Float::Abstract([e.round_ties_even()])),
1176-
Float::F32([e]) => Ok(Float::F32([e.round_ties_even()])),
1175+
Float::Abstract([e]) => Ok(Float::Abstract([libm::rint(e)])),
1176+
Float::F32([e]) => Ok(Float::F32([libm::rintf(e)])),
11771177
Float::F16([e]) => {
11781178
// TODO: `round_ties_even` is not available on `half::f16` yet.
11791179
//

0 commit comments

Comments
 (0)