Skip to content

Commit 6151330

Browse files
[wgpu-hal]: MVP no_std support (#7599)
* MVP `no_std` support in `wgpu-hal` * Update CHANGELOG.md * Fix visibility * Fix unused imports * Response to feedback Co-Authored-By: Connor Fitzgerald <[email protected]> * Update other `validation_canary` usages Co-Authored-By: Connor Fitzgerald <[email protected]> --------- Co-authored-by: Connor Fitzgerald <[email protected]>
1 parent d190106 commit 6151330

File tree

14 files changed

+73
-54
lines changed

14 files changed

+73
-54
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,12 @@ jobs:
302302
# check with no features
303303
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-types --no-default-features
304304
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p naga --no-default-features
305+
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-hal --no-default-features
305306
306307
# Check with all compatible features
307308
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
308309
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p naga --no-default-features --features dot-out,compact
310+
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-hal --no-default-features --features fragile-send-sync-non-atomic-wasm
309311
310312
# Building for native platforms with standard tests.
311313
- name: Check native

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ Naga now infers the correct binding layout when a resource appears only in an as
106106

107107
- The type of the `size` parameter to `copy_buffer_to_buffer` has changed from `BufferAddress` to `impl Into<Option<BufferAddress>>`. This achieves the spec-defined behavior of the value being optional, while still accepting existing calls without changes. By @andyleiserson in [#7659](https://github.com/gfx-rs/wgpu/pull/7659).
108108

109+
#### HAL
110+
111+
- Added initial `no_std` support to `wgpu-hal`. By @bushrat011899 in [#7599](https://github.com/gfx-rs/wgpu/pull/7599)
112+
109113
### Bug Fixes
110114

111115
#### Naga

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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ wgpu-core = { version = "25.0.0", path = "./wgpu-core" }
7878
wgpu-hal = { version = "25.0.0", path = "./wgpu-hal" }
7979
wgpu-macros = { version = "25.0.0", path = "./wgpu-macros" }
8080
wgpu-test = { version = "25.0.0", path = "./tests" }
81-
wgpu-types = { version = "25.0.0", path = "./wgpu-types" }
81+
wgpu-types = { version = "25.0.0", path = "./wgpu-types", default-features = false }
8282

8383
# These _cannot_ have a version specified. If it does, crates.io will look
8484
# for a version of the package on crates when we publish naga. Path dependencies

deno_webgpu/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ wgpu-core = { workspace = true, features = [
2525
"wgsl",
2626
"gles",
2727
] }
28-
wgpu-types = { workspace = true, features = ["serde"] }
28+
wgpu-types = { workspace = true, features = ["serde", "std"] }
2929

3030
deno_core.workspace = true
3131
deno_error.workspace = true

examples/features/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ png.workspace = true
4545
pollster.workspace = true
4646
web-time.workspace = true
4747
wgpu-types = { workspace = true, features = [
48+
"std",
4849
"trace", # TODO(#5974): this should be a dep on wgpu/trace and not wgpu-types at all
4950
] }
5051
winit.workspace = true

player/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ name = "play"
1919
test = false
2020

2121
[dependencies]
22-
wgpu-types = { workspace = true, features = ["serde"] }
22+
wgpu-types = { workspace = true, features = ["serde", "std"] }
2323

2424
env_logger.workspace = true
2525
log.workspace = true

tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ webgl = ["wgpu/webgl"]
3232

3333
[dependencies]
3434
wgpu = { workspace = true, features = ["noop"] }
35+
wgpu-hal = { workspace = true, features = ["validation_canary"] }
3536
wgpu-macros.workspace = true
3637

3738
anyhow.workspace = true

wgpu-hal/Cargo.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ metal = [
8181
"dep:log",
8282
"dep:metal",
8383
"dep:objc",
84+
"dep:parking_lot",
8485
"dep:profiling",
8586
]
8687
vulkan = [
@@ -96,6 +97,7 @@ vulkan = [
9697
"dep:libloading",
9798
"dep:log",
9899
"dep:ordered-float",
100+
"dep:parking_lot",
99101
"dep:profiling",
100102
"dep:smallvec",
101103
"dep:windows",
@@ -115,6 +117,7 @@ gles = [
115117
"dep:log",
116118
"dep:ndk-sys",
117119
"dep:objc",
120+
"dep:parking_lot",
118121
"dep:profiling",
119122
"dep:wasm-bindgen",
120123
"dep:web-sys",
@@ -134,6 +137,7 @@ dx12 = [
134137
"dep:libloading",
135138
"dep:log",
136139
"dep:ordered-float",
140+
"dep:parking_lot",
137141
"dep:profiling",
138142
"dep:range-alloc",
139143
"dep:windows-core",
@@ -175,6 +179,8 @@ device_lost_panic = []
175179
#
176180
# Only affects the d3d12 and vulkan backends.
177181
internal_error_panic = []
182+
# Tracks validation errors in a `VALIDATION_CANARY` static.
183+
validation_canary = ["dep:parking_lot"]
178184

179185
###################
180186
### Workarounds ###
@@ -197,12 +203,12 @@ required-features = ["gles"]
197203

198204
[dependencies]
199205
naga.workspace = true
200-
wgpu-types.workspace = true
206+
wgpu-types = { workspace = true, default-features = false }
201207

202208
# Dependencies in the lib and empty backend
203209
bitflags.workspace = true
204210
raw-window-handle.workspace = true
205-
parking_lot.workspace = true
211+
parking_lot = { workspace = true, optional = true }
206212
thiserror.workspace = true
207213

208214
# Target agnostic dependencies used only in backends.

wgpu-hal/src/auxil/dxgi/exception.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use alloc::{
2-
borrow::Cow,
3-
string::{String, ToString as _},
4-
};
1+
use alloc::{borrow::Cow, string::String};
52

63
use parking_lot::Mutex;
74
use windows::Win32::{Foundation, System::Diagnostics::Debug};
@@ -86,7 +83,10 @@ unsafe extern "system" fn output_debug_string_handler(
8683
log::log!(level, "{}", message);
8784
});
8885

86+
#[cfg(feature = "validation_canary")]
8987
if cfg!(debug_assertions) && level == log::Level::Error {
88+
use alloc::string::ToString as _;
89+
9090
// Set canary and continue
9191
crate::VALIDATION_CANARY.add(message.to_string());
9292
}

wgpu-hal/src/gles/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,7 @@ fn gl_debug_message_callback(source: u32, gltype: u32, id: u32, severity: u32, m
10871087
);
10881088
});
10891089

1090+
#[cfg(feature = "validation_canary")]
10901091
if cfg!(debug_assertions) && log_severity == log::Level::Error {
10911092
// Set canary and continue
10921093
crate::VALIDATION_CANARY.add(message.to_string());

wgpu-hal/src/lib.rs

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ pub mod api {
275275
}
276276

277277
mod dynamic;
278+
#[cfg(feature = "validation_canary")]
279+
mod validation_canary;
280+
281+
#[cfg(feature = "validation_canary")]
282+
pub use validation_canary::{ValidationCanary, VALIDATION_CANARY};
278283

279284
pub(crate) use dynamic::impl_dyn_resource;
280285
pub use dynamic::{
@@ -298,7 +303,6 @@ use core::{
298303
};
299304

300305
use bitflags::bitflags;
301-
use parking_lot::Mutex;
302306
use thiserror::Error;
303307
use wgt::WasmNotSendSync;
304308

@@ -2375,42 +2379,6 @@ pub struct ComputePassDescriptor<'a, Q: DynQuerySet + ?Sized> {
23752379
pub timestamp_writes: Option<PassTimestampWrites<'a, Q>>,
23762380
}
23772381

2378-
/// Stores the text of any validation errors that have occurred since
2379-
/// the last call to `get_and_reset`.
2380-
///
2381-
/// Each value is a validation error and a message associated with it,
2382-
/// or `None` if the error has no message from the api.
2383-
///
2384-
/// This is used for internal wgpu testing only and _must not_ be used
2385-
/// as a way to check for errors.
2386-
///
2387-
/// This works as a static because `cargo nextest` runs all of our
2388-
/// tests in separate processes, so each test gets its own canary.
2389-
///
2390-
/// This prevents the issue of one validation error terminating the
2391-
/// entire process.
2392-
pub static VALIDATION_CANARY: ValidationCanary = ValidationCanary {
2393-
inner: Mutex::new(Vec::new()),
2394-
};
2395-
2396-
/// Flag for internal testing.
2397-
pub struct ValidationCanary {
2398-
inner: Mutex<Vec<String>>,
2399-
}
2400-
2401-
impl ValidationCanary {
2402-
#[allow(dead_code)] // in some configurations this function is dead
2403-
fn add(&self, msg: String) {
2404-
self.inner.lock().push(msg);
2405-
}
2406-
2407-
/// Returns any API validation errors that have occurred in this process
2408-
/// since the last call to this function.
2409-
pub fn get_and_reset(&self) -> Vec<String> {
2410-
self.inner.lock().drain(..).collect()
2411-
}
2412-
}
2413-
24142382
#[test]
24152383
fn test_default_limits() {
24162384
let limits = wgt::Limits::default();

wgpu-hal/src/validation_canary.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use alloc::{string::String, vec::Vec};
2+
3+
use parking_lot::Mutex;
4+
5+
/// Stores the text of any validation errors that have occurred since
6+
/// the last call to `get_and_reset`.
7+
///
8+
/// Each value is a validation error and a message associated with it,
9+
/// or `None` if the error has no message from the api.
10+
///
11+
/// This is used for internal wgpu testing only and _must not_ be used
12+
/// as a way to check for errors.
13+
///
14+
/// This works as a static because `cargo nextest` runs all of our
15+
/// tests in separate processes, so each test gets its own canary.
16+
///
17+
/// This prevents the issue of one validation error terminating the
18+
/// entire process.
19+
pub static VALIDATION_CANARY: ValidationCanary = ValidationCanary {
20+
inner: Mutex::new(Vec::new()),
21+
};
22+
23+
/// Flag for internal testing.
24+
pub struct ValidationCanary {
25+
inner: Mutex<Vec<String>>,
26+
}
27+
28+
impl ValidationCanary {
29+
#[allow(dead_code)] // in some configurations this function is dead
30+
pub(crate) fn add(&self, msg: String) {
31+
self.inner.lock().push(msg);
32+
}
33+
34+
/// Returns any API validation errors that have occurred in this process
35+
/// since the last call to this function.
36+
pub fn get_and_reset(&self) -> Vec<String> {
37+
self.inner.lock().drain(..).collect()
38+
}
39+
}

wgpu-hal/src/vulkan/instance.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
use alloc::{
2-
borrow::ToOwned as _,
3-
boxed::Box,
4-
ffi::CString,
5-
string::{String, ToString as _},
6-
sync::Arc,
7-
vec::Vec,
8-
};
1+
use alloc::{borrow::ToOwned as _, boxed::Box, ffi::CString, string::String, sync::Arc, vec::Vec};
92
use core::{
103
ffi::{c_void, CStr},
114
slice,
@@ -145,7 +138,10 @@ unsafe extern "system" fn debug_utils_messenger_callback(
145138
});
146139
}
147140

141+
#[cfg(feature = "validation_canary")]
148142
if cfg!(debug_assertions) && level == log::Level::Error {
143+
use alloc::string::ToString as _;
144+
149145
// Set canary and continue
150146
crate::VALIDATION_CANARY.add(message.to_string());
151147
}

0 commit comments

Comments
 (0)