From cb81b7606fc5107a6b02ef65b6b78a038386349b Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Fri, 17 Jan 2025 12:08:40 -0500 Subject: [PATCH 01/22] no-std support in naga --- .github/workflows/ci.yml | 2 + CHANGELOG.md | 6 +++ Cargo.lock | 1 + naga/Cargo.toml | 10 ++++- naga/src/arena/handle.rs | 3 ++ naga/src/arena/handle_set.rs | 3 ++ naga/src/arena/handlevec.rs | 3 ++ naga/src/arena/mod.rs | 3 ++ naga/src/arena/range.rs | 3 ++ naga/src/arena/unique_arena.rs | 3 ++ naga/src/back/mod.rs | 3 ++ naga/src/block.rs | 4 ++ naga/src/common/wgsl.rs | 3 ++ naga/src/diagnostic_filter.rs | 3 ++ naga/src/error.rs | 3 ++ naga/src/front/mod.rs | 3 ++ naga/src/front/type_gen.rs | 3 ++ naga/src/lib.rs | 61 +++++++++++++++++++++++++++++ naga/src/non_max_u32.rs | 3 ++ naga/src/proc/constant_evaluator.rs | 8 ++++ naga/src/proc/layouter.rs | 4 ++ naga/src/proc/mod.rs | 3 ++ naga/src/proc/namer.rs | 4 ++ naga/src/proc/typifier.rs | 3 ++ naga/src/span.rs | 2 + naga/src/valid/analyzer.rs | 5 +++ naga/src/valid/expression.rs | 5 +++ naga/src/valid/function.rs | 5 +++ naga/src/valid/handles.rs | 3 ++ naga/src/valid/interface.rs | 5 +++ naga/src/valid/mod.rs | 6 +++ naga/src/valid/type.rs | 4 ++ 32 files changed, 179 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f7a3cbe23..af96a56eaf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -281,9 +281,11 @@ jobs: run: | set -e + # XXX TODO REPEAT THIS SUB-STEP for naga # check with no features cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-types --no-default-features + # XXX TODO SIMILAR SUB-STEP for naga with all features possible with no-std (once this is supported) # 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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 2201ec3ffc..63d8bcdaf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,12 @@ Bottom level categories: ## Unreleased +### Major changes + +#### no-std support in naga + +XXX TODO + ### Bug Fixes #### Vulkan diff --git a/Cargo.lock b/Cargo.lock index 41d277851d..10413f8e49 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2177,6 +2177,7 @@ dependencies = [ "codespan-reporting", "diff", "env_logger", + "hashbrown", "hexf-parse", "hlsl-snapshots", "indexmap", diff --git a/naga/Cargo.toml b/naga/Cargo.toml index 2c8d846289..2a16130db5 100644 --- a/naga/Cargo.toml +++ b/naga/Cargo.toml @@ -25,7 +25,14 @@ path = "tests/root.rs" all-features = true [features] -default = [] +default = ["std"] + +# XXX TBD ADD DESCRIPTION HERE (???) +std = [] + +# XXX TODO ALL FEATURES BELOW REQUIRE std feature to build - NEED TO SPECIFY THIS +# XXX TODO DETERMINE which features may or may not be able to work with no-std + dot-out = [] glsl-in = ["dep:pp-rs"] glsl-out = [] @@ -72,6 +79,7 @@ termcolor = { version = "1.4.1" } # termcolor minimum version was wrong and was fixed in # https://github.com/brendanzab/codespan/commit/e99c867339a877731437e7ee6a903a3d03b5439e codespan-reporting = { version = "0.11.0" } +hashbrown = { workspace = true, features = ["serde"] } rustc-hash.workspace = true indexmap.workspace = true log = "0.4" diff --git a/naga/src/arena/handle.rs b/naga/src/arena/handle.rs index d486d6e054..6be5ae5bce 100644 --- a/naga/src/arena/handle.rs +++ b/naga/src/arena/handle.rs @@ -5,6 +5,9 @@ //! [`Arena`]: super::Arena //! [`UniqueArena`]: super::UniqueArena +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use std::{cmp::Ordering, fmt, hash, marker::PhantomData}; /// An unique index in the arena array that a handle points to. diff --git a/naga/src/arena/handle_set.rs b/naga/src/arena/handle_set.rs index f2ce058d12..4c2efb993d 100644 --- a/naga/src/arena/handle_set.rs +++ b/naga/src/arena/handle_set.rs @@ -1,5 +1,8 @@ //! The [`HandleSet`] type and associated definitions. +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::arena::{Arena, Handle, UniqueArena}; /// A set of `Handle` values. diff --git a/naga/src/arena/handlevec.rs b/naga/src/arena/handlevec.rs index 2ddb65c9a4..8106ec244b 100644 --- a/naga/src/arena/handlevec.rs +++ b/naga/src/arena/handlevec.rs @@ -1,5 +1,8 @@ //! The [`HandleVec`] type and associated definitions. +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use super::handle::Handle; use std::marker::PhantomData; diff --git a/naga/src/arena/mod.rs b/naga/src/arena/mod.rs index 0747eaef72..3d3b9e080a 100644 --- a/naga/src/arena/mod.rs +++ b/naga/src/arena/mod.rs @@ -32,6 +32,9 @@ pub(crate) use handlevec::HandleVec; pub use range::{BadRangeError, Range}; pub use unique_arena::UniqueArena; +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::Span; use handle::Index; diff --git a/naga/src/arena/range.rs b/naga/src/arena/range.rs index b448f83c8c..9e9787a1a5 100644 --- a/naga/src/arena/range.rs +++ b/naga/src/arena/range.rs @@ -5,6 +5,9 @@ //! //! [`Arena`]: super::Arena +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use super::{ handle::{Handle, Index}, Arena, diff --git a/naga/src/arena/unique_arena.rs b/naga/src/arena/unique_arena.rs index c64bb302eb..40dca78c3c 100644 --- a/naga/src/arena/unique_arena.rs +++ b/naga/src/arena/unique_arena.rs @@ -1,5 +1,8 @@ //! The [`UniqueArena`] type and supporting definitions. +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::{FastIndexSet, Span}; use super::handle::{BadHandle, Handle, Index}; diff --git a/naga/src/back/mod.rs b/naga/src/back/mod.rs index 58c7fa02cb..d49555efca 100644 --- a/naga/src/back/mod.rs +++ b/naga/src/back/mod.rs @@ -3,6 +3,9 @@ Backend functions that export shader [`Module`](super::Module)s into binary and */ #![allow(dead_code)] // can be dead if none of the enabled backends need it +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::proc::ExpressionKindTracker; #[cfg(dot_out)] diff --git a/naga/src/block.rs b/naga/src/block.rs index 2e86a928f1..9cbd1d51e2 100644 --- a/naga/src/block.rs +++ b/naga/src/block.rs @@ -1,4 +1,8 @@ +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::{Span, Statement}; + use std::ops::{Deref, DerefMut, RangeBounds}; /// A code block is a vector of statements, with maybe a vector of spans. diff --git a/naga/src/common/wgsl.rs b/naga/src/common/wgsl.rs index 07459d7f34..3b73504343 100644 --- a/naga/src/common/wgsl.rs +++ b/naga/src/common/wgsl.rs @@ -2,6 +2,9 @@ use std::fmt::{self, Display, Formatter}; +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::diagnostic_filter::{ FilterableTriggeringRule, Severity, StandardFilterableTriggeringRule, }; diff --git a/naga/src/diagnostic_filter.rs b/naga/src/diagnostic_filter.rs index 2fa5464cdf..336b5f9eb8 100644 --- a/naga/src/diagnostic_filter.rs +++ b/naga/src/diagnostic_filter.rs @@ -1,5 +1,8 @@ //! [`DiagnosticFilter`]s and supporting functionality. +#[cfg(not(feature = "std"))] +use crate::aliases::*; + #[cfg(feature = "wgsl-in")] use crate::Span; use crate::{Arena, Handle}; diff --git a/naga/src/error.rs b/naga/src/error.rs index 21c1a13d3c..bab040d06f 100644 --- a/naga/src/error.rs +++ b/naga/src/error.rs @@ -1,3 +1,6 @@ +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use std::{error::Error, fmt}; #[derive(Clone, Debug)] diff --git a/naga/src/front/mod.rs b/naga/src/front/mod.rs index 11c8aa047e..8d2f708c36 100644 --- a/naga/src/front/mod.rs +++ b/naga/src/front/mod.rs @@ -14,6 +14,9 @@ pub mod spv; #[cfg(feature = "wgsl-in")] pub mod wgsl; +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::{ arena::{Arena, Handle, HandleVec, UniqueArena}, proc::{ResolveContext, ResolveError, TypeResolution}, diff --git a/naga/src/front/type_gen.rs b/naga/src/front/type_gen.rs index 737c456bbd..4065c3b6cf 100644 --- a/naga/src/front/type_gen.rs +++ b/naga/src/front/type_gen.rs @@ -2,6 +2,9 @@ Type generators. */ +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::{arena::Handle, span::Span}; impl crate::Module { diff --git a/naga/src/lib.rs b/naga/src/lib.rs index ddf78f1b68..4a959ca1fe 100644 --- a/naga/src/lib.rs +++ b/naga/src/lib.rs @@ -249,6 +249,67 @@ An override expression can be evaluated at pipeline creation time. clippy::todo ) )] +// XXX TODO ADD SOME COMMENTS FOR THIS: +#![cfg_attr(not(feature = "std"), no_std)] + +// XXX TBD WHERE TO PUT THIS MOD - ??? - XXX TBD SEPARATE SOURCE FILE ??? +#[cfg(not(feature = "std"))] +pub(crate) mod aliases { + pub(crate) mod external { + pub(crate) extern crate alloc; + } + + pub(crate) mod std { + pub(crate) mod prelude { + pub(crate) mod v1 { + pub(crate) use crate::aliases::std::{ + // XXX XXX TBD COMBINE LINES ??? + borrow::ToOwned, + boxed::Box, + format, + string::String, + string::ToString, + vec, + vec::Vec, + }; + } + } + + pub(crate) use core::{ + // XXX XXX TBD COMBINE LINES ??? + any, + cmp, + convert, + fmt, + hash, + iter, + marker, + mem, + num, + ops, + slice, + }; + + pub(crate) use super::external::alloc::{ + // XXX XXX TBD COMBINE LINES ??? + borrow, + boxed, + format, + string, + vec, + }; + + // XXX TODO REMOVE THIS HACK IN FAVOR OF UPDATE FROM OTHER PR: https://github.com/gfx-rs/wgpu/pull/6938 + pub(crate) use hashbrown as collections; + + // XXX TBD POSSIBLE IMPACT ON CORE MSRV with no-std - ??? + pub(crate) use core::error; + } + pub(crate) use std::prelude::v1::*; +} + +#[cfg(not(feature = "std"))] +use crate::aliases::*; mod arena; pub mod back; diff --git a/naga/src/non_max_u32.rs b/naga/src/non_max_u32.rs index 2ad402e497..80c422b700 100644 --- a/naga/src/non_max_u32.rs +++ b/naga/src/non_max_u32.rs @@ -16,6 +16,9 @@ //! [`NonZeroU32`]: std::num::NonZeroU32 #![allow(dead_code)] +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use std::num::NonZeroU32; /// An unsigned 32-bit value known not to be [`u32::MAX`]. diff --git a/naga/src/proc/constant_evaluator.rs b/naga/src/proc/constant_evaluator.rs index 42ba489790..997315cd6a 100644 --- a/naga/src/proc/constant_evaluator.rs +++ b/naga/src/proc/constant_evaluator.rs @@ -1,3 +1,8 @@ +#[cfg(not(feature = "std"))] +use crate::aliases::*; + +// XXX TBD MOVE IMPORTS ??? + use std::iter; use arrayvec::ArrayVec; @@ -2468,6 +2473,9 @@ impl TryFromAbstract for u64 { mod tests { use std::vec; + #[cfg(not(feature = "std"))] + use crate::aliases::*; + use crate::{ Arena, Constant, Expression, Literal, ScalarKind, Type, TypeInner, UnaryOperator, UniqueArena, VectorSize, diff --git a/naga/src/proc/layouter.rs b/naga/src/proc/layouter.rs index 82b1be094a..ba4ee8be6d 100644 --- a/naga/src/proc/layouter.rs +++ b/naga/src/proc/layouter.rs @@ -1,4 +1,8 @@ +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::arena::{Handle, HandleVec}; + use std::{fmt::Display, num::NonZeroU32, ops}; /// A newtype struct where its only valid values are powers of 2 diff --git a/naga/src/proc/mod.rs b/naga/src/proc/mod.rs index fafac8cb30..92233e0861 100644 --- a/naga/src/proc/mod.rs +++ b/naga/src/proc/mod.rs @@ -10,6 +10,9 @@ mod namer; mod terminator; mod typifier; +#[cfg(not(feature = "std"))] +use crate::aliases::*; + pub use constant_evaluator::{ ConstantEvaluator, ConstantEvaluatorError, ExpressionKind, ExpressionKindTracker, }; diff --git a/naga/src/proc/namer.rs b/naga/src/proc/namer.rs index 8afacb593d..7d065cc1fb 100644 --- a/naga/src/proc/namer.rs +++ b/naga/src/proc/namer.rs @@ -1,4 +1,8 @@ +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::{arena::Handle, FastHashMap, FastHashSet}; + use std::borrow::Cow; use std::hash::{Hash, Hasher}; diff --git a/naga/src/proc/typifier.rs b/naga/src/proc/typifier.rs index 1359289900..0ca22137a1 100644 --- a/naga/src/proc/typifier.rs +++ b/naga/src/proc/typifier.rs @@ -1,3 +1,6 @@ +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::arena::{Arena, Handle, UniqueArena}; use thiserror::Error; diff --git a/naga/src/span.rs b/naga/src/span.rs index 7c1ce17dca..608df11cd3 100644 --- a/naga/src/span.rs +++ b/naga/src/span.rs @@ -1,3 +1,5 @@ +#[cfg(not(feature = "std"))] +use crate::aliases::*; use crate::{Arena, Handle, UniqueArena}; use std::{error::Error, fmt, ops::Range}; diff --git a/naga/src/valid/analyzer.rs b/naga/src/valid/analyzer.rs index 8417bf77be..16f7ce6bfb 100644 --- a/naga/src/valid/analyzer.rs +++ b/naga/src/valid/analyzer.rs @@ -6,12 +6,17 @@ //! - expression reference counts use super::{ExpressionError, FunctionError, ModuleInfo, ShaderStages, ValidationFlags}; + +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::diagnostic_filter::{DiagnosticFilterNode, StandardFilterableTriggeringRule}; use crate::span::{AddSpan as _, WithSpan}; use crate::{ arena::{Arena, Handle}, proc::{ResolveContext, TypeResolution}, }; + use std::ops; pub type NonUniformResult = Option>; diff --git a/naga/src/valid/expression.rs b/naga/src/valid/expression.rs index 9ef3a9edfb..88beca4bf9 100644 --- a/naga/src/valid/expression.rs +++ b/naga/src/valid/expression.rs @@ -1,4 +1,9 @@ use super::{compose::validate_compose, FunctionInfo, ModuleInfo, ShaderStages, TypeFlags}; + +#[cfg(not(feature = "std"))] +use crate::aliases::*; + +// XXX TODO COMBINE with arena::Handle import below: use crate::arena::UniqueArena; use crate::{ diff --git a/naga/src/valid/function.rs b/naga/src/valid/function.rs index a910be992c..0fc0e82756 100644 --- a/naga/src/valid/function.rs +++ b/naga/src/valid/function.rs @@ -1,3 +1,6 @@ +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::arena::{Arena, UniqueArena}; use crate::arena::{Handle, HandleSet}; @@ -7,6 +10,8 @@ use super::{ analyzer::{UniformityDisruptor, UniformityRequirements}, ExpressionError, FunctionInfo, ModuleInfo, }; + +// XXX TODO MOVE THESE CLOSER TO OTHER use::crate::... imports use crate::span::WithSpan; use crate::span::{AddSpan as _, MapErrWithSpan as _}; diff --git a/naga/src/valid/handles.rs b/naga/src/valid/handles.rs index 260d442c79..54c976f9cd 100644 --- a/naga/src/valid/handles.rs +++ b/naga/src/valid/handles.rs @@ -1,5 +1,8 @@ //! Implementation of `Validator::validate_module_handles`. +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::{ arena::{BadHandle, BadRangeError}, diagnostic_filter::DiagnosticFilterNode, diff --git a/naga/src/valid/interface.rs b/naga/src/valid/interface.rs index 08bdda0329..3514340d02 100644 --- a/naga/src/valid/interface.rs +++ b/naga/src/valid/interface.rs @@ -2,9 +2,14 @@ use super::{ analyzer::{FunctionInfo, GlobalUse}, Capabilities, Disalignment, FunctionError, ModuleInfo, }; + +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::arena::{Handle, UniqueArena}; use crate::span::{AddSpan as _, MapErrWithSpan as _, SpanProvider as _, WithSpan}; + use bit_set::BitSet; const MAX_WORKGROUP_SIZE: u32 = 0x4000; diff --git a/naga/src/valid/mod.rs b/naga/src/valid/mod.rs index 906d449362..9992f56d4f 100644 --- a/naga/src/valid/mod.rs +++ b/naga/src/valid/mod.rs @@ -10,18 +10,24 @@ mod handles; mod interface; mod r#type; +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::{ arena::{Handle, HandleSet}, proc::{ExpressionKindTracker, LayoutError, Layouter, TypeResolution}, FastHashSet, }; + use bit_set::BitSet; use std::ops; //TODO: analyze the model at the same time as we validate it, // merge the corresponding matches over expressions and statements. +// XXX TODO MOVE THIS CRATE IMPORT use crate::span::{AddSpan as _, WithSpan}; + pub use analyzer::{ExpressionInfo, FunctionInfo, GlobalUse, Uniformity, UniformityRequirements}; pub use compose::ComposeError; pub use expression::{check_literal_value, LiteralError}; diff --git a/naga/src/valid/type.rs b/naga/src/valid/type.rs index 8c6825b842..595aba26d5 100644 --- a/naga/src/valid/type.rs +++ b/naga/src/valid/type.rs @@ -1,4 +1,8 @@ use super::Capabilities; + +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::{arena::Handle, proc::Alignment}; bitflags::bitflags! { From d384d26a89aecbe776cb086a0d4c083b34e4c5f0 Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Sun, 19 Jan 2025 00:52:38 -0500 Subject: [PATCH 02/22] no-std clippy check for naga --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 02100700e6..18ed15928f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -284,9 +284,10 @@ jobs: run: | set -e - # XXX TODO REPEAT THIS SUB-STEP for naga - # check with no features + # check with no features - wgpu-types cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-types --no-default-features + # check with no features - naga + cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p naga --no-default-features # XXX TODO SIMILAR SUB-STEP for naga with all features possible with no-std (once this is supported) # Check with all features except "std". From ed241c3be59d626c4f7f47d7f1d85d07a03a9002 Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Sun, 19 Jan 2025 15:56:07 -0500 Subject: [PATCH 03/22] start CI testing with no std features --- .github/workflows/ci.yml | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 18ed15928f..d017fefd6d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -161,7 +161,9 @@ jobs: target: wasm32-unknown-emscripten tier: 2 kind: wgpu-only - + + # XXX TODO REMOVE TRAILING SPACE IN SEPARATE PR + # TODO: Uncomment once web-sys updates past 0.3.76 # See https://github.com/rustwasm/wasm-bindgen/pull/4378 for details # - name: WebAssembly Core 1.0 @@ -169,7 +171,9 @@ jobs: # target: wasm32v1-none # tier: 2 # kind: no_std - + + # XXX TODO REMOVE TRAILING SPACE IN SEPARATE PR + # Bare-metal x86-64 # TODO: Remove once web-sys updates past 0.3.76 # Included while wasm32v1-none is failing to ensure `no_std` does not regress @@ -179,6 +183,13 @@ jobs: tier: 2 kind: no_std + # XXX TODO MOVE INTO SEPARATE CI JOB: + - name: no-std feature test + os: ubuntu-22.04 + target: x86_64-unknown-none + tier: 2 + kind: no-std-test + name: Clippy ${{ matrix.name }} runs-on: ${{ matrix.os }} @@ -276,7 +287,9 @@ jobs: # Check with all features. 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 - + + # XXX TODO REMOVE TRAILING SPACE IN SEPARATE PR + # Building for no_std platforms where every feature is enabled except "std". - name: check no_std if: matrix.kind == 'no_std' @@ -309,6 +322,20 @@ jobs: # build docs cargo doc --target ${{ matrix.target }} ${{ matrix.extra-flags }} --all-features --no-deps + # XXX TODO MOVE INTO SEPARATE CI JOB: + - name: no-std feature test + if: matrix.kind == 'no-std-test' + shell: bash + run: | + set -e + + # no-std test with no features - naga + cargo test --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p naga --no-default-features + + # XXX TODO FIX & TEST MULTIPLE naga features for no-std + # no-std test with multiple features - naga + # cargo test [...] + - name: check private item docs if: matrix.kind == 'native' shell: bash From 136206d2148898c793331108fa61db9c30d4370c Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Sun, 19 Jan 2025 16:05:35 -0500 Subject: [PATCH 04/22] fixup no-std feature test CI task --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d017fefd6d..a7e752c658 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -184,11 +184,11 @@ jobs: kind: no_std # XXX TODO MOVE INTO SEPARATE CI JOB: - - name: no-std feature test + - name: no-std feature test - Linux x86_64 os: ubuntu-22.04 - target: x86_64-unknown-none - tier: 2 - kind: no-std-test + target: x86_64-unknown-linux-gnu + tier: 1 + kind: no-std-feature-test name: Clippy ${{ matrix.name }} runs-on: ${{ matrix.os }} @@ -322,9 +322,9 @@ jobs: # build docs cargo doc --target ${{ matrix.target }} ${{ matrix.extra-flags }} --all-features --no-deps - # XXX TODO MOVE INTO SEPARATE CI JOB: + # XXX TODO MOVE INTO SEPARATE CI JOB - MAY SHOW UP AS A "Clippy" job in GitHub CI - name: no-std feature test - if: matrix.kind == 'no-std-test' + if: matrix.kind == 'no-std-feature-test' shell: bash run: | set -e From 2cd4f23df65c8668470209965481f47a56c2f7d6 Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Sun, 19 Jan 2025 16:11:51 -0500 Subject: [PATCH 05/22] update no-std feature test comment in ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a7e752c658..c2e819acbd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -329,7 +329,7 @@ jobs: run: | set -e - # no-std test with no features - naga + # no-std feature test with no features - naga cargo test --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p naga --no-default-features # XXX TODO FIX & TEST MULTIPLE naga features for no-std From e4ec12a6f410625db6660b4c227ce44d5b0b57fb Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Sun, 19 Jan 2025 16:22:04 -0500 Subject: [PATCH 06/22] fixup no-std build - partial fixup with XXX TODO remaining in naga/src/proc/constant_evaluator.rs --- Cargo.lock | 8 ++++++++ Cargo.toml | 13 +++++++------ naga/Cargo.toml | 22 +++++++++++++++------- naga/src/error.rs | 2 ++ naga/src/lib.rs | 8 ++++++-- naga/src/proc/constant_evaluator.rs | 5 +++++ naga/src/span.rs | 6 ++++++ 7 files changed, 49 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 10413f8e49..206ae6c787 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1977,6 +1977,12 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "libm" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" + [[package]] name = "libredox" version = "0.1.3" @@ -2183,6 +2189,7 @@ dependencies = [ "indexmap", "itertools 0.13.0", "log", + "num-traits", "petgraph 0.7.1", "pp-rs", "ron", @@ -2331,6 +2338,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", + "libm", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index fc5c0e0b85..f2321e09a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,8 +76,9 @@ version = "24.0.0" [workspace.dependencies] anyhow = "1.0.95" argh = "0.1.13" -arrayvec = "0.7" +arrayvec = { version = "0.7", default-features = false } bincode = "1" +bit-set = { version = "0.8", default-features = false } bit-vec = "0.8" bitflags = "2.7" bytemuck = { version = "1.21", features = ["derive", "min_const_generics"] } @@ -100,7 +101,7 @@ hashbrown = { version = "0.15.2", default-features = false, features = [ ] } heck = "0.5.0" image = { version = "0.24", default-features = false, features = ["png"] } -indexmap = "2" +indexmap = { version = "2", default-features = false } itertools = { version = "0.13.0" } ktx2 = "0.3" libc = "0.2" @@ -129,15 +130,16 @@ rayon = "1" renderdoc-sys = "1.1.0" ron = "0.8" # rustc-hash 2.0 is a completely different hasher with different performance characteristics +# XXX TODO NEED UPDATE FROM OTHER PR WITH UPDATED COMMENT: https://github.com/gfx-rs/wgpu/pull/6938 +rustc-hash = { version = "1", default-features = false } serde_json = "1.0.134" -rustc-hash = "1" serde = { version = "1", default-features = false } smallvec = "1" static_assertions = "1.1.0" -strum = { version = "0.26.0", features = ["derive"] } +strum = { version = "0.26", default-features = false, features = ["derive"] } trybuild = "1" tracy-client = "0.17" -thiserror = "2" +thiserror = { version = "2", default-features = false } wgpu = { version = "24.0.0", path = "./wgpu", default-features = false, features = [ "serde", "wgsl", @@ -164,7 +166,6 @@ gpu-alloc = "0.6" gpu-descriptor = "0.3" # DX dependencies -bit-set = "0.8" gpu-allocator = { version = "0.27", default-features = false } range-alloc = "0.1" mach-dxcompiler-rs = { version = "0.1.4", default-features = false } diff --git a/naga/Cargo.toml b/naga/Cargo.toml index 2a16130db5..c79d28897a 100644 --- a/naga/Cargo.toml +++ b/naga/Cargo.toml @@ -28,7 +28,7 @@ all-features = true default = ["std"] # XXX TBD ADD DESCRIPTION HERE (???) -std = [] +std = ["dep:codespan-reporting", "dep:termcolor"] # XXX TODO ALL FEATURES BELOW REQUIRE std feature to build - NEED TO SPECIFY THIS # XXX TODO DETERMINE which features may or may not be able to work with no-std @@ -48,8 +48,13 @@ msl-out = [] ## If you want to enable MSL output it regardless of the target platform, use `naga/msl-out`. msl-out-if-target-apple = [] -serialize = ["dep:serde", "bitflags/serde", "indexmap/serde"] -deserialize = ["dep:serde", "bitflags/serde", "indexmap/serde"] +serialize = ["dep:serde", "bitflags/serde", "hashbrown/serde", "indexmap/serde"] +deserialize = [ + "dep:serde", + "bitflags/serde", + "hashbrown/serde", + "indexmap/serde", +] arbitrary = ["dep:arbitrary", "bitflags/arbitrary", "indexmap/arbitrary"] spv-in = ["dep:petgraph", "dep:spirv"] spv-out = ["dep:spirv"] @@ -74,15 +79,18 @@ arbitrary = { version = "1.4", features = ["derive"], optional = true } arrayvec.workspace = true bitflags.workspace = true bit-set.workspace = true -termcolor = { version = "1.4.1" } -# remove termcolor dep when updating to the next version of codespan-reporting +# remove termcolor from here when updating to the next version of codespan-reporting # termcolor minimum version was wrong and was fixed in # https://github.com/brendanzab/codespan/commit/e99c867339a877731437e7ee6a903a3d03b5439e -codespan-reporting = { version = "0.11.0" } -hashbrown = { workspace = true, features = ["serde"] } +termcolor = { version = "1.4.1", optional = true } +codespan-reporting = { version = "0.11.0", optional = true } +hashbrown.workspace = true rustc-hash.workspace = true indexmap.workspace = true log = "0.4" +num-traits = { version = "0.2.19", default-features = false, features = [ + "libm", +] } strum.workspace = true spirv = { version = "0.3", optional = true } thiserror.workspace = true diff --git a/naga/src/error.rs b/naga/src/error.rs index bab040d06f..4b502cf5cd 100644 --- a/naga/src/error.rs +++ b/naga/src/error.rs @@ -35,6 +35,8 @@ impl fmt::Display for ShaderError { write!(f, "\nShader '{label}' parsing {string}") } } +// XXX TBD FIX for no-std ??? +#[cfg(feature = "std")] impl fmt::Display for ShaderError> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { use codespan_reporting::{files::SimpleFile, term}; diff --git a/naga/src/lib.rs b/naga/src/lib.rs index 4a959ca1fe..95b1b739b8 100644 --- a/naga/src/lib.rs +++ b/naga/src/lib.rs @@ -343,10 +343,14 @@ pub const BOOL_WIDTH: Bytes = 1; /// Width of abstract types, in bytes. pub const ABSTRACT_WIDTH: Bytes = 8; +// XXX TODO NEED UPDATES FROM OTHER PR: https://github.com/gfx-rs/wgpu/pull/6938 /// Hash map that is faster but not resilient to DoS attacks. -pub type FastHashMap = rustc_hash::FxHashMap; +// pub type FastHashMap = rustc_hash::FxHashMap; +pub type FastHashMap = std::collections::HashMap>; +// XXX TODO NEED UPDATES FROM OTHER PR: https://github.com/gfx-rs/wgpu/pull/6938 /// Hash set that is faster but not resilient to DoS attacks. -pub type FastHashSet = rustc_hash::FxHashSet; +// pub type FastHashSet = rustc_hash::FxHashSet; +pub type FastHashSet = std::collections::HashSet>; /// Insertion-order-preserving hash set (`IndexSet`), but with the same /// hasher as `FastHashSet` (faster but not resilient to DoS attacks). diff --git a/naga/src/proc/constant_evaluator.rs b/naga/src/proc/constant_evaluator.rs index 997315cd6a..c9d5a2a5af 100644 --- a/naga/src/proc/constant_evaluator.rs +++ b/naga/src/proc/constant_evaluator.rs @@ -1,6 +1,10 @@ #[cfg(not(feature = "std"))] use crate::aliases::*; +// XXX TBD ??? ??? +#[cfg(not(feature = "std"))] +use num_traits::real::*; + // XXX TBD MOVE IMPORTS ??? use std::iter; @@ -1188,6 +1192,7 @@ impl<'a> ConstantEvaluator<'a> { // . // // [polyfill source]: https://github.com/imeka/ndarray-ndimage/blob/8b14b4d6ecfbc96a8a052f802e342a7049c68d8f/src/lib.rs#L98 + // XXX TODO NEED copysign for f64 & no-std fn round_ties_even(x: f64) -> f64 { let i = x as i64; let f = (x - i as f64).abs(); diff --git a/naga/src/span.rs b/naga/src/span.rs index 608df11cd3..2827aa24ab 100644 --- a/naga/src/span.rs +++ b/naga/src/span.rs @@ -241,6 +241,7 @@ impl WithSpan { Some(self.spans[0].0.location(source)) } + #[cfg(feature = "std")] pub(crate) fn diagnostic(&self) -> codespan_reporting::diagnostic::Diagnostic<()> where E: Error, @@ -268,6 +269,7 @@ impl WithSpan { } /// Emits a summary of the error to standard error stream. + #[cfg(feature = "std")] pub fn emit_to_stderr(&self, source: &str) where E: Error, @@ -276,6 +278,7 @@ impl WithSpan { } /// Emits a summary of the error to standard error stream. + #[cfg(feature = "std")] pub fn emit_to_stderr_with_path(&self, source: &str, path: &str) where E: Error, @@ -290,7 +293,9 @@ impl WithSpan { .expect("cannot write error"); } + // XXX TBD FIX FOR no-std - ??? /// Emits a summary of the error to a string. + #[cfg(feature = "std")] pub fn emit_to_string(&self, source: &str) -> String where E: Error, @@ -299,6 +304,7 @@ impl WithSpan { } /// Emits a summary of the error to a string. + #[cfg(feature = "std")] pub fn emit_to_string_with_path(&self, source: &str, path: &str) -> String where E: Error, From cca6cef5af7dc88d84a0f91cf2118427d945156e Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Sun, 19 Jan 2025 16:26:09 -0500 Subject: [PATCH 07/22] fixup naga/tests/snapshots.rs --- naga/tests/snapshots.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/naga/tests/snapshots.rs b/naga/tests/snapshots.rs index 691878959d..2fd5e59e5b 100644 --- a/naga/tests/snapshots.rs +++ b/naga/tests/snapshots.rs @@ -30,6 +30,7 @@ bitflags::bitflags! { } } +// XXX TBD add cfg condition - ??? #[derive(serde::Deserialize)] struct SpvOutVersion(u8, u8); impl Default for SpvOutVersion { @@ -38,8 +39,9 @@ impl Default for SpvOutVersion { } } -#[derive(Default, serde::Deserialize)] -#[serde(default)] +#[derive(Default)] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "deserialize", serde(default))] struct SpirvOutParameters { version: SpvOutVersion, capabilities: naga::FastHashSet, @@ -52,14 +54,17 @@ struct SpirvOutParameters { binding_map: naga::back::spv::BindingMap, } -#[derive(Default, serde::Deserialize)] -#[serde(default)] +#[derive(Default)] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "deserialize", serde(default))] struct WgslOutParameters { explicit_types: bool, } -#[derive(Default, serde::Deserialize)] -#[serde(default)] +#[derive(Default)] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "deserialize", serde(default))] +// #[serde(default)] struct Parameters { // -- GOD MODE -- god_mode: bool, @@ -235,6 +240,7 @@ impl Input { } /// Return this input's parameter file, parsed. + #[cfg(feature = "deserialize")] fn read_parameters(&self) -> Parameters { let mut param_path = self.input_path(); param_path.set_extension("param.ron"); @@ -261,6 +267,7 @@ type FragmentEntryPoint<'a> = naga::back::hlsl::FragmentEntryPoint<'a>; type FragmentEntryPoint<'a> = (); #[allow(unused_variables)] +#[cfg(feature = "deserialize")] fn check_targets( input: &Input, module: &mut naga::Module, From b078c6c10088bbebf44a1750273a74d13f50e437 Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Sun, 19 Jan 2025 16:34:22 -0500 Subject: [PATCH 08/22] additional fixup: naga/src/proc/constant_evaluator.rs --- naga/src/proc/constant_evaluator.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/naga/src/proc/constant_evaluator.rs b/naga/src/proc/constant_evaluator.rs index c9d5a2a5af..44a11035fe 100644 --- a/naga/src/proc/constant_evaluator.rs +++ b/naga/src/proc/constant_evaluator.rs @@ -1192,21 +1192,31 @@ impl<'a> ConstantEvaluator<'a> { // . // // [polyfill source]: https://github.com/imeka/ndarray-ndimage/blob/8b14b4d6ecfbc96a8a052f802e342a7049c68d8f/src/lib.rs#L98 - // XXX TODO NEED copysign for f64 & no-std 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) + with_sign(x.abs() + 0.5, x.is_sign_negative()) } else { - (x.abs() - 0.5).copysign(x) + with_sign(x.abs() - 0.5, x.is_sign_positive()) } } else { x.round() } } + // Additional helper shamelessly adapted, based on: + // - https://github.com/rust-num/num-traits/blob/num-traits-0.2.19/src/float.rs#L1905 + // (with compatible licensing as well) + #[inline] + fn with_sign(magnitude :f64, with_negative_sign: bool) -> f64 { + if with_negative_sign { + -magnitude.abs() + } else { + magnitude.abs() + } + } 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 as f64) as f32)])), From e1434227c47a075cb47fe5f12586d5264180150a Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Sun, 19 Jan 2025 16:39:36 -0500 Subject: [PATCH 09/22] XXX UPDATE: wgpu-hal/src/gles/device.rs --- wgpu-hal/src/gles/device.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wgpu-hal/src/gles/device.rs b/wgpu-hal/src/gles/device.rs index 0df9568698..83d93a2129 100644 --- a/wgpu-hal/src/gles/device.rs +++ b/wgpu-hal/src/gles/device.rs @@ -16,7 +16,8 @@ type ShaderStage<'a> = ( naga::ShaderStage, &'a crate::ProgrammableStage<'a, super::ShaderModule>, ); -type NameBindingMap = rustc_hash::FxHashMap; +// XXX TODO NEED UPDATE FROM OTHER PR: https://github.com/gfx-rs/wgpu/pull/6938 +type NameBindingMap = naga::FastHashMap; struct CompilationContext<'a> { layout: &'a super::PipelineLayout, From 24e1f0d60430159b635a2a781ed6558211403b76 Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Sun, 19 Jan 2025 16:42:17 -0500 Subject: [PATCH 10/22] XXX TODO in ci.yml --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c2e819acbd..6e774adffe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,6 +56,7 @@ env: RUST_LOG: debug RUST_BACKTRACE: full PKG_CONFIG_ALLOW_CROSS: 1 # allow android to work + # XXX TODO CONFIGURE THIS PER JOB - NOT ALL JOBS SHOULD FAIL WITH CARGO WARNINGS RUSTFLAGS: -D warnings RUSTDOCFLAGS: -D warnings WASM_BINDGEN_TEST_TIMEOUT: 300 # 5 minutes From b650dfe2905118fc61d4b0fd96157b6ff09348b3 Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Sun, 19 Jan 2025 16:43:31 -0500 Subject: [PATCH 11/22] remove import not needed: borrow::ToOwned --- naga/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/naga/src/lib.rs b/naga/src/lib.rs index 95b1b739b8..80c540f7b3 100644 --- a/naga/src/lib.rs +++ b/naga/src/lib.rs @@ -264,7 +264,6 @@ pub(crate) mod aliases { pub(crate) mod v1 { pub(crate) use crate::aliases::std::{ // XXX XXX TBD COMBINE LINES ??? - borrow::ToOwned, boxed::Box, format, string::String, From 141b1cd9c243bea2fca404e686eb32e089dee72f Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Sun, 19 Jan 2025 16:56:32 -0500 Subject: [PATCH 12/22] fixup fmt: naga/src/proc/constant_evaluator.rs --- naga/src/proc/constant_evaluator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/naga/src/proc/constant_evaluator.rs b/naga/src/proc/constant_evaluator.rs index 44a11035fe..a0816beec2 100644 --- a/naga/src/proc/constant_evaluator.rs +++ b/naga/src/proc/constant_evaluator.rs @@ -1210,7 +1210,7 @@ impl<'a> ConstantEvaluator<'a> { // - https://github.com/rust-num/num-traits/blob/num-traits-0.2.19/src/float.rs#L1905 // (with compatible licensing as well) #[inline] - fn with_sign(magnitude :f64, with_negative_sign: bool) -> f64 { + fn with_sign(magnitude: f64, with_negative_sign: bool) -> f64 { if with_negative_sign { -magnitude.abs() } else { From 2384b13cbb0088cf22750d95dc9be1b0e23a35ee Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Sun, 19 Jan 2025 16:57:15 -0500 Subject: [PATCH 13/22] fixup fmt etc: naga/src/lib.rs --- naga/src/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/naga/src/lib.rs b/naga/src/lib.rs index 80c540f7b3..ba0254c24a 100644 --- a/naga/src/lib.rs +++ b/naga/src/lib.rs @@ -344,12 +344,13 @@ pub const ABSTRACT_WIDTH: Bytes = 8; // XXX TODO NEED UPDATES FROM OTHER PR: https://github.com/gfx-rs/wgpu/pull/6938 /// Hash map that is faster but not resilient to DoS attacks. -// pub type FastHashMap = rustc_hash::FxHashMap; -pub type FastHashMap = std::collections::HashMap>; +pub type FastHashMap = + std::collections::HashMap>; + // XXX TODO NEED UPDATES FROM OTHER PR: https://github.com/gfx-rs/wgpu/pull/6938 /// Hash set that is faster but not resilient to DoS attacks. -// pub type FastHashSet = rustc_hash::FxHashSet; -pub type FastHashSet = std::collections::HashSet>; +pub type FastHashSet = + std::collections::HashSet>; /// Insertion-order-preserving hash set (`IndexSet`), but with the same /// hasher as `FastHashSet` (faster but not resilient to DoS attacks). From a5a963d5a0b6ace5153613885b1ea2cd86c5961f Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Sun, 19 Jan 2025 17:00:56 -0500 Subject: [PATCH 14/22] use #[allow(unused_imports] as quick workaround to avoid failures with clippy warnings --- naga/src/proc/constant_evaluator.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/naga/src/proc/constant_evaluator.rs b/naga/src/proc/constant_evaluator.rs index a0816beec2..fef75c24ae 100644 --- a/naga/src/proc/constant_evaluator.rs +++ b/naga/src/proc/constant_evaluator.rs @@ -1,7 +1,8 @@ #[cfg(not(feature = "std"))] use crate::aliases::*; -// XXX TBD ??? ??? +// XXX TBD ??? ??? - IGNORING unused_imports warning HERE - XXX TBD COMBINE WITH ALIASES ??? +#[allow(unused_imports)] #[cfg(not(feature = "std"))] use num_traits::real::*; From c80ae2f290596ed2856165566aedf1bbf41400af Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Sun, 19 Jan 2025 17:38:26 -0500 Subject: [PATCH 15/22] fixup: use naga::FastHashMap in wgpu-hal --- wgpu-hal/src/metal/mod.rs | 6 ++++-- wgpu-hal/src/vulkan/mod.rs | 11 ++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index cd1136a3b4..c51666bd30 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -937,9 +937,11 @@ struct CommandState { /// See `device::CompiledShader::sized_bindings` for more details. /// /// [`ResourceBinding`]: naga::ResourceBinding - storage_buffer_length_map: rustc_hash::FxHashMap, + // XXX TODO NEED UPDATE FROM OTHER PR: https://github.com/gfx-rs/wgpu/pull/6938 + storage_buffer_length_map: naga::FastHashMap, - vertex_buffer_size_map: rustc_hash::FxHashMap, + // XXX TODO NEED UPDATE FROM OTHER PR: https://github.com/gfx-rs/wgpu/pull/6938 + vertex_buffer_size_map: naga::FastHashMap, work_group_memory_sizes: Vec, push_constants: Vec, diff --git a/wgpu-hal/src/vulkan/mod.rs b/wgpu-hal/src/vulkan/mod.rs index b0d27a9a36..d15f9b115e 100644 --- a/wgpu-hal/src/vulkan/mod.rs +++ b/wgpu-hal/src/vulkan/mod.rs @@ -42,17 +42,13 @@ use std::{ use arrayvec::ArrayVec; use ash::{ext, khr, vk}; -use hashbrown::{HashMap, HashSet}; +use hashbrown::HashSet; use parking_lot::{Mutex, RwLock}; -use rustc_hash::FxHasher; use wgt::InternalCounter; const MILLIS_TO_NANOS: u64 = 1_000_000; const MAX_TOTAL_ATTACHMENTS: usize = crate::MAX_COLOR_ATTACHMENTS * 2 + 1; -// NOTE: This type alias is similar to rustc_hash::FxHashMap but works with hashbrown. -type FxHashMap = HashMap>; - #[derive(Clone, Debug)] pub struct Api; @@ -646,8 +642,9 @@ struct DeviceShared { private_caps: PrivateCapabilities, workarounds: Workarounds, features: wgt::Features, - render_passes: Mutex>, - framebuffers: Mutex>, + // XXX TODO NEED UPDATE FROM OTHER PR: https://github.com/gfx-rs/wgpu/pull/6938 + render_passes: Mutex>, + framebuffers: Mutex>, sampler_cache: Mutex, memory_allocations_counter: InternalCounter, } From e51f78d1b65827d9572e2b55eb1cdfecfe94280c Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Sun, 19 Jan 2025 18:20:32 -0500 Subject: [PATCH 16/22] XXX temporary build fixup: wgpu-hal/src/vulkan/device.rs --- wgpu-hal/src/vulkan/device.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wgpu-hal/src/vulkan/device.rs b/wgpu-hal/src/vulkan/device.rs index 03fa9c0c59..83aad710de 100644 --- a/wgpu-hal/src/vulkan/device.rs +++ b/wgpu-hal/src/vulkan/device.rs @@ -2,7 +2,6 @@ use super::{conv, RawTlasInstance}; use arrayvec::ArrayVec; use ash::{khr, vk}; -use hashbrown::hash_map::Entry; use parking_lot::Mutex; use crate::TlasInstance; @@ -16,6 +15,9 @@ use std::{ sync::Arc, }; +// XXX TODO NEED TO USE UPDATE FROM OTHER PR: https://github.com/gfx-rs/wgpu/pull/6938 +use std::collections::hash_map::Entry; + impl super::DeviceShared { /// Set the name of `object` to `name`. /// From 45efdf2e247d14b04427642ab7d49e83084919f3 Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Sun, 19 Jan 2025 18:32:33 -0500 Subject: [PATCH 17/22] XXX TBD std feature gate for front::wgsl::parse::directive --- naga/src/front/wgsl/parse/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/naga/src/front/wgsl/parse/mod.rs b/naga/src/front/wgsl/parse/mod.rs index 739a1b15c6..196131764e 100644 --- a/naga/src/front/wgsl/parse/mod.rs +++ b/naga/src/front/wgsl/parse/mod.rs @@ -16,6 +16,8 @@ use crate::{Arena, FastIndexSet, Handle, ShaderStage, Span}; pub mod ast; pub mod conv; +// XXX TBD ENABLE OR ENABLE PARTIALLY for no-std ??? +#[cfg(feature = "std")] pub mod directive; pub mod lexer; pub mod number; From ad325dc59e22181026940211d28563a66c86f1b7 Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Sun, 19 Jan 2025 19:17:54 -0500 Subject: [PATCH 18/22] fixup feature spec for std & multiple dependencies --- naga/Cargo.toml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/naga/Cargo.toml b/naga/Cargo.toml index c79d28897a..a2c417f1ab 100644 --- a/naga/Cargo.toml +++ b/naga/Cargo.toml @@ -28,7 +28,15 @@ all-features = true default = ["std"] # XXX TBD ADD DESCRIPTION HERE (???) -std = ["dep:codespan-reporting", "dep:termcolor"] +std = [ + "dep:codespan-reporting", + # XXX TBD does strum need to be gated on std ??? + "dep:strum", + "dep:termcolor", + "indexmap/std", + # XXX TBD IS / WHY IS THIS NEEDED ??? + "strum/std", +] # XXX TODO ALL FEATURES BELOW REQUIRE std feature to build - NEED TO SPECIFY THIS # XXX TODO DETERMINE which features may or may not be able to work with no-std @@ -91,7 +99,7 @@ log = "0.4" num-traits = { version = "0.2.19", default-features = false, features = [ "libm", ] } -strum.workspace = true +strum = { workspace = true, optional = true } spirv = { version = "0.3", optional = true } thiserror.workspace = true serde = { version = "1.0.217", features = [ From d706eaed8d03eb1e1eda1711ed34ec6b7fa4baa0 Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Sun, 19 Jan 2025 19:20:24 -0500 Subject: [PATCH 19/22] update feature spec for feature: glsl-in --- naga/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/naga/Cargo.toml b/naga/Cargo.toml index a2c417f1ab..a4d27ec294 100644 --- a/naga/Cargo.toml +++ b/naga/Cargo.toml @@ -42,7 +42,7 @@ std = [ # XXX TODO DETERMINE which features may or may not be able to work with no-std dot-out = [] -glsl-in = ["dep:pp-rs"] +glsl-in = ["std", "dep:pp-rs"] glsl-out = [] ## Enables outputting to the Metal Shading Language (MSL). From 203cafdabcdac02c39ff79c3ba9f5a0bace6a0db Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Wed, 29 Jan 2025 17:56:55 -0500 Subject: [PATCH 20/22] remove a couple XXX TODO comments no longer needed --- naga/src/lib.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/naga/src/lib.rs b/naga/src/lib.rs index bfe39d1c87..1a06809f9b 100644 --- a/naga/src/lib.rs +++ b/naga/src/lib.rs @@ -298,9 +298,6 @@ pub(crate) mod aliases { vec, }; - // XXX TODO COMPLETELY REMOVE HACK NO LONGER NEEDED: - // pub(crate) use hashbrown as collections; - // XXX TBD POSSIBLE IMPACT ON CORE MSRV with no-std - ??? pub(crate) use core::error; } @@ -342,7 +339,6 @@ pub const BOOL_WIDTH: Bytes = 1; /// Width of abstract types, in bytes. pub const ABSTRACT_WIDTH: Bytes = 8; -// XXX TODO REMOVE THIS OUTDATED COMMENT RE: UPDATES FROM XXX /// Hash map that is faster but not resilient to DoS attacks. /// (Similar to rustc_hash::FxHashMap but using hashbrown::HashMap instead of std::collections::HashMap.) /// To construct a new instance: `FastHashMap::default()` From c1d79cb4c388359841573ee301ecccafb5579d2a Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Wed, 29 Jan 2025 18:18:26 -0500 Subject: [PATCH 21/22] remove where clause not needed from: naga/src/span.rs - XXX TODO REMOVE IN SEPARATE PR --- naga/src/span.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/naga/src/span.rs b/naga/src/span.rs index 2827aa24ab..c2b40e7dd9 100644 --- a/naga/src/span.rs +++ b/naga/src/span.rs @@ -360,8 +360,9 @@ impl SpanProvider for UniqueArena { } impl AddSpan for E -where - E: Error, +// XXX TODO REMOVE IN SEPARATE PR: +// where +// ... { type Output = WithSpan; fn with_span(self) -> WithSpan { From dac8d4d26f6e575ade131884b0b810724e7ac90a Mon Sep 17 00:00:00 2001 From: "@brody4hire - C. Jonathan Brody" Date: Wed, 29 Jan 2025 18:43:48 -0500 Subject: [PATCH 22/22] drop use of core::error::Error for now, at least, to avoid increasing core MSRV --- naga/src/error.rs | 10 +++++++++- naga/src/lib.rs | 3 --- naga/src/span.rs | 8 +++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/naga/src/error.rs b/naga/src/error.rs index 4b502cf5cd..34dbc06223 100644 --- a/naga/src/error.rs +++ b/naga/src/error.rs @@ -1,7 +1,12 @@ #[cfg(not(feature = "std"))] use crate::aliases::*; -use std::{error::Error, fmt}; +#[cfg(feature = "std")] +use std::error::Error; + +// XXX TODO ADD & IMPROVE NOTE: multiple features below only working with std at this point +#[cfg(feature = "std")] +use std::fmt; #[derive(Clone, Debug)] pub struct ShaderError { @@ -54,6 +59,9 @@ impl fmt::Display for ShaderError ) } } + +// XXX TODO ADD NOTE WITH TODO: supporting core::error::Error would be a nice feature but may affect core MSRV +#[cfg(feature = "std")] impl Error for ShaderError where ShaderError: fmt::Display, diff --git a/naga/src/lib.rs b/naga/src/lib.rs index 1a06809f9b..3a73a5b74b 100644 --- a/naga/src/lib.rs +++ b/naga/src/lib.rs @@ -297,9 +297,6 @@ pub(crate) mod aliases { string, vec, }; - - // XXX TBD POSSIBLE IMPACT ON CORE MSRV with no-std - ??? - pub(crate) use core::error; } pub(crate) use std::prelude::v1::*; } diff --git a/naga/src/span.rs b/naga/src/span.rs index c2b40e7dd9..f6ab8b35f7 100644 --- a/naga/src/span.rs +++ b/naga/src/span.rs @@ -1,7 +1,11 @@ #[cfg(not(feature = "std"))] use crate::aliases::*; use crate::{Arena, Handle, UniqueArena}; -use std::{error::Error, fmt, ops::Range}; + +#[cfg(feature = "std")] +use std::error::Error; + +use std::{fmt, ops::Range}; /// A source code span, used for error reporting. #[derive(Clone, Copy, Debug, PartialEq, Default)] @@ -154,6 +158,8 @@ where } } +// XXX TODO ADD NOTE WITH TODO: supporting core::error::Error would be a nice feature but may affect core MSRV +#[cfg(feature = "std")] impl Error for WithSpan where E: Error,