diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b1f7c8ef0..c2e4e1241a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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". 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 afbbcdab41..79f3379736 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/naga/src/back/mod.rs b/naga/src/back/mod.rs index 8eee9b6ff6..384ddc25af 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..83b2c6897c 100644 --- a/naga/src/proc/constant_evaluator.rs +++ b/naga/src/proc/constant_evaluator.rs @@ -1171,34 +1171,46 @@ impl<'a> ConstantEvaluator<'a> { component_wise_float!(self, span, [arg], |e| { Ok([e.floor()]) }) } 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::F16([e]) => { - // TODO: `round_ties_even` is not available on `half::f16` yet. - // - // This polyfill is shamelessly [~~stolen from~~ inspired by `ndarray-image`][polyfill source], - // which has licensing compatible with ours. See also - // . - // - // [polyfill source]: https://github.com/imeka/ndarray-ndimage/blob/8b14b4d6ecfbc96a8a052f802e342a7049c68d8f/src/lib.rs#L98 - fn round_ties_even(x: f64) -> f64 { - let i = x as i64; - let f = (x - i as f64).abs(); - if f == 0.5 { - if i & 1 == 1 { - // -1.5, 1.5, 3.5, ... - (x.abs() + 0.5).copysign(x) - } else { - (x.abs() - 0.5).copysign(x) - } - } else { - x.round() - } - } + /// Rounds to the nearest integer, with ties biasing towards an even result. + /// + /// # TODO + /// + /// - `round_ties_even` is not available on `half::f16` yet. + /// - It is also not available on `no_std` + /// + /// This polyfill is shamelessly [~~stolen from~~ inspired by `ndarray-image`][polyfill source], + /// which has licensing compatible with ours. See also + /// . + /// + /// [polyfill source]: https://github.com/imeka/ndarray-ndimage/blob/8b14b4d6ecfbc96a8a052f802e342a7049c68d8f/src/lib.rs#L98 + fn round_ties_even(x: T) -> T { + let half = (T::one() + T::one()).recip(); + + if x.fract().abs() != half { + x.round() + } else { + let i = x.abs().trunc(); - Ok(Float::F16([(f16::from_f64(round_ties_even(f64::from(e))))])) + let value = if (i * half).fract() == half { + // -1.5, 1.5, 3.5, ... + x.abs() + half + } else { + // -0.5, 0.5, 2.5, ... + x.abs() - half + }; + + if x.signum() != value.signum() { + -value + } else { + value + } } + } + + component_wise_float(self, span, [arg], |e| match e { + Float::Abstract([e]) => Ok(Float::Abstract([round_ties_even(e)])), + Float::F32([e]) => Ok(Float::F32([round_ties_even(e)])), + Float::F16([e]) => Ok(Float::F16([round_ties_even(e)])), }) } crate::MathFunction::Fract => {