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 28 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 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
cc1b1d7
MERGE & UPDATE from trunk with MERGE UPDATES
brody4hire Jan 29, 2025
203cafd
remove a couple XXX TODO comments no longer needed
brody4hire Jan 29, 2025
c1d79cb
remove where clause not needed from: naga/src/span.rs - XXX TODO REMO…
brody4hire Jan 29, 2025
dac8d4d
drop use of core::error::Error for now, at least, to avoid increasing…
brody4hire Jan 29, 2025
bfc7dfe
Merge branch 'trunk' of https://github.com/gfx-rs/wgpu into no-std-su…
brody4hire Jan 29, 2025
3cd1a49
Merge branch 'trunk' into no-std-support-in-naga
brody4hire Jan 30, 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
27 changes: 26 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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
Expand Down Expand Up @@ -175,6 +176,13 @@ jobs:
tier: 2
kind: no_std

# XXX TODO MOVE INTO SEPARATE CI JOB:
- name: no-std feature test - Linux x86_64
os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
tier: 1
kind: no-std-feature-test

name: Clippy ${{ matrix.name }}
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -282,9 +290,12 @@ jobs:
run: |
set -e

# 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".
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 All @@ -304,6 +315,20 @@ jobs:
# build docs
cargo doc --target ${{ matrix.target }} ${{ matrix.extra-flags }} --all-features --no-deps

# 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-feature-test'
shell: bash
run: |
set -e

# 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
# no-std test with multiple features - naga
# cargo test [...]

- name: check private item docs
if: matrix.kind == 'native'
shell: bash
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

### New Features

#### Naga
Expand Down
8 changes: 8 additions & 0 deletions Cargo.lock

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

12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ wgpu-types = { version = "24.0.0", path = "./wgpu-types" }

anyhow = "1.0.95"
argh = "0.1.13"
arrayvec = "0.7"
arrayvec = { version = "0.7", default-features = false }
# XXX TODO MOVE ITEM IN SEPARATE PR: approx
approx = "0.5"
bincode = "1"
# XXX RESOLVE WHERE TO KEEP ITEM: bit-set - ???
bit-set = { version = "0.8", default-features = false }
bit-vec = "0.8"
bitflags = "2.7"
bytemuck = { version = "1.21", features = ["derive", "min_const_generics"] }
Expand All @@ -99,7 +102,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"
Expand Down Expand Up @@ -135,10 +138,10 @@ serde_json = "1.0.137"
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 }
winit = { version = "0.29", features = ["android-native-activity"] }

# Metal dependencies
Expand All @@ -154,7 +157,6 @@ gpu-alloc = "0.6"
gpu-descriptor = "0.3"

# DX12 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 }
Expand Down
31 changes: 25 additions & 6 deletions naga/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,24 @@ path = "tests/root.rs"
all-features = true

[features]
default = []
default = ["std"]

# XXX TBD ADD DESCRIPTION HERE (???)
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

dot-out = []
glsl-in = ["dep:pp-rs"]
glsl-in = ["std", "dep:pp-rs"]
glsl-out = []

## Enables outputting to the Metal Shading Language (MSL).
Expand Down Expand Up @@ -72,16 +87,20 @@ 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
# XXX TODO RAISE SEPARATE PR FOR UPDATE RE: remove termcolor dep [...]
# 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" }
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"
strum.workspace = true
num-traits = { version = "0.2.19", default-features = false, features = [
"libm",
] }
strum = { workspace = true, optional = true }
spirv = { version = "0.3", optional = true }
thiserror.workspace = true
serde = { version = "1.0.217", features = [
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 @@ -31,6 +31,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
15 changes: 14 additions & 1 deletion naga/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
use std::{error::Error, fmt};
#[cfg(not(feature = "std"))]
use crate::aliases::*;

#[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<E> {
Expand Down Expand Up @@ -32,6 +40,8 @@ impl fmt::Display for ShaderError<crate::front::spv::Error> {
write!(f, "\nShader '{label}' parsing {string}")
}
}
// XXX TBD FIX for no-std ???
#[cfg(feature = "std")]
impl fmt::Display for ShaderError<crate::WithSpan<crate::valid::ValidationError>> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use codespan_reporting::{files::SimpleFile, term};
Expand All @@ -49,6 +59,9 @@ impl fmt::Display for ShaderError<crate::WithSpan<crate::valid::ValidationError>
)
}
}

// XXX TODO ADD NOTE WITH TODO: supporting core::error::Error would be a nice feature but may affect core MSRV
#[cfg(feature = "std")]
impl<E> Error for ShaderError<E>
where
ShaderError<E>: fmt::Display,
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
2 changes: 2 additions & 0 deletions naga/src/front/wgsl/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading
Loading