Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-std support in naga #6940

Draft
wants to merge 22 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cb81b76
no-std support in naga
brody4hire Jan 17, 2025
af03315
Merge branch 'trunk' of https://github.com/gfx-rs/wgpu into no-std-su…
brody4hire Jan 19, 2025
d384d26
no-std clippy check for naga
brody4hire Jan 19, 2025
ed241c3
start CI testing with no std features
brody4hire Jan 19, 2025
e610a43
Merge branch 'trunk' of https://github.com/gfx-rs/wgpu into no-std-su…
brody4hire Jan 19, 2025
136206d
fixup no-std feature test CI task
brody4hire Jan 19, 2025
2cd4f23
update no-std feature test comment in ci.yml
brody4hire Jan 19, 2025
e4ec12a
fixup no-std build - partial fixup with XXX TODO remaining in naga/sr…
brody4hire Jan 19, 2025
cca6cef
fixup naga/tests/snapshots.rs
brody4hire Jan 19, 2025
b078c6c
additional fixup: naga/src/proc/constant_evaluator.rs
brody4hire Jan 19, 2025
e143422
XXX UPDATE: wgpu-hal/src/gles/device.rs
brody4hire Jan 19, 2025
24e1f0d
XXX TODO in ci.yml
brody4hire Jan 19, 2025
b650dfe
remove import not needed: borrow::ToOwned
brody4hire Jan 19, 2025
141b1cd
fixup fmt: naga/src/proc/constant_evaluator.rs
brody4hire Jan 19, 2025
2384b13
fixup fmt etc: naga/src/lib.rs
brody4hire Jan 19, 2025
a5a963d
use #[allow(unused_imports] as quick workaround to avoid failures wit…
brody4hire Jan 19, 2025
c80ae2f
fixup: use naga::FastHashMap in wgpu-hal
brody4hire Jan 19, 2025
e51f78d
XXX temporary build fixup: wgpu-hal/src/vulkan/device.rs
brody4hire Jan 19, 2025
45efdf2
XXX TBD std feature gate for front::wgsl::parse::directive
brody4hire Jan 19, 2025
ad325dc
fixup feature spec for std & multiple dependencies
brody4hire Jan 20, 2025
d706eae
update feature spec for feature: glsl-in
brody4hire Jan 20, 2025
b2964a9
Merge branch 'trunk' of https://github.com/gfx-rs/wgpu into no-std-su…
brody4hire Jan 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
no-std support in naga
  • Loading branch information
brody4hire committed Jan 17, 2025
commit cb81b7606fc5107a6b02ef65b6b78a038386349b
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ Bottom level categories:

## Unreleased

### Major changes

#### no-std support in naga

XXX TODO

### Bug Fixes

#### Vulkan
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion naga/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions naga/src/arena/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions naga/src/arena/handle_set.rs
Original file line number Diff line number Diff line change
@@ -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<T>` values.
Expand Down
3 changes: 3 additions & 0 deletions naga/src/arena/handlevec.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 3 additions & 0 deletions naga/src/arena/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions naga/src/arena/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
//!
//! [`Arena`]: super::Arena

#[cfg(not(feature = "std"))]
use crate::aliases::*;

use super::{
handle::{Handle, Index},
Arena,
Expand Down
3 changes: 3 additions & 0 deletions naga/src/arena/unique_arena.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
3 changes: 3 additions & 0 deletions naga/src/back/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 4 additions & 0 deletions naga/src/block.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 3 additions & 0 deletions naga/src/common/wgsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

use std::fmt::{self, Display, Formatter};

#[cfg(not(feature = "std"))]
use crate::aliases::*;

use crate::diagnostic_filter::{
FilterableTriggeringRule, Severity, StandardFilterableTriggeringRule,
};
Expand Down
3 changes: 3 additions & 0 deletions naga/src/diagnostic_filter.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
3 changes: 3 additions & 0 deletions naga/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(not(feature = "std"))]
use crate::aliases::*;

use std::{error::Error, fmt};

#[derive(Clone, Debug)]
Expand Down
3 changes: 3 additions & 0 deletions naga/src/front/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
3 changes: 3 additions & 0 deletions naga/src/front/type_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Type generators.
*/

#[cfg(not(feature = "std"))]
use crate::aliases::*;

use crate::{arena::Handle, span::Span};

impl crate::Module {
Expand Down
61 changes: 61 additions & 0 deletions naga/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions naga/src/non_max_u32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
Expand Down
8 changes: 8 additions & 0 deletions naga/src/proc/constant_evaluator.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#[cfg(not(feature = "std"))]
use crate::aliases::*;

// XXX TBD MOVE IMPORTS ???

use std::iter;

use arrayvec::ArrayVec;
Expand Down Expand Up @@ -2468,6 +2473,9 @@ impl TryFromAbstract<f64> 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,
Expand Down
4 changes: 4 additions & 0 deletions naga/src/proc/layouter.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions naga/src/proc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
4 changes: 4 additions & 0 deletions naga/src/proc/namer.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
3 changes: 3 additions & 0 deletions naga/src/proc/typifier.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(not(feature = "std"))]
use crate::aliases::*;

use crate::arena::{Arena, Handle, UniqueArena};

use thiserror::Error;
Expand Down
2 changes: 2 additions & 0 deletions naga/src/span.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[cfg(not(feature = "std"))]
use crate::aliases::*;
use crate::{Arena, Handle, UniqueArena};
use std::{error::Error, fmt, ops::Range};

Expand Down
5 changes: 5 additions & 0 deletions naga/src/valid/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Handle<crate::Expression>>;
Expand Down
5 changes: 5 additions & 0 deletions naga/src/valid/expression.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down
5 changes: 5 additions & 0 deletions naga/src/valid/function.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(not(feature = "std"))]
use crate::aliases::*;

use crate::arena::{Arena, UniqueArena};
use crate::arena::{Handle, HandleSet};

Expand All @@ -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 _};

Expand Down
3 changes: 3 additions & 0 deletions naga/src/valid/handles.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
5 changes: 5 additions & 0 deletions naga/src/valid/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading
Loading