Skip to content

[wgpu-hal]: MVP no_std support #7599

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

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 wgpu-hal --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 wgpu-hal --no-default-features --features fragile-send-sync-non-atomic-wasm

# Building for native platforms with standard tests.
- name: Check native
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ Naga now infers the correct binding layout when a resource appears only in an as

- Remove the need for dxil.dll. By @teoxoy in [#7566](https://github.com/gfx-rs/wgpu/pull/7566)

#### HAL

- Added initial `no_std` support to `wgpu-hal`. By @bushrat011899 in [#7599](https://github.com/gfx-rs/wgpu/pull/7599)

### Bug Fixes

#### Naga
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.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ wgpu-core = { version = "25.0.0", path = "./wgpu-core" }
wgpu-hal = { version = "25.0.0", path = "./wgpu-hal" }
wgpu-macros = { version = "25.0.0", path = "./wgpu-macros" }
wgpu-test = { version = "25.0.0", path = "./tests" }
wgpu-types = { version = "25.0.0", path = "./wgpu-types" }
wgpu-types = { version = "25.0.0", path = "./wgpu-types", default-features = false }

wgpu-core-deps-windows-linux-android = { version = "25.0.0", path = "./wgpu-core/platform-deps/windows-linux-android" }
wgpu-core-deps-apple = { version = "25.0.0", path = "./wgpu-core/platform-deps/apple" }
Expand Down
2 changes: 1 addition & 1 deletion deno_webgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ wgpu-core = { workspace = true, features = [
"wgsl",
"gles",
] }
wgpu-types = { workspace = true, features = ["serde"] }
wgpu-types = { workspace = true, features = ["serde", "std"] }

deno_core.workspace = true
deno_error.workspace = true
Expand Down
1 change: 1 addition & 0 deletions examples/features/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ png.workspace = true
pollster.workspace = true
web-time.workspace = true
wgpu-types = { workspace = true, features = [
"std",
"trace", # TODO(#5974): this should be a dep on wgpu/trace and not wgpu-types at all
] }
winit.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion player/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ name = "play"
test = false

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

env_logger.workspace = true
log.workspace = true
Expand Down
1 change: 1 addition & 0 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ webgl = ["wgpu/webgl"]

[dependencies]
wgpu = { workspace = true, features = ["noop"] }
wgpu-hal = { workspace = true, features = ["validation_canary"] }
wgpu-macros.workspace = true

anyhow.workspace = true
Expand Down
10 changes: 8 additions & 2 deletions wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ metal = [
"dep:log",
"dep:metal",
"dep:objc",
"dep:parking_lot",
"dep:profiling",
]
vulkan = [
Expand All @@ -96,6 +97,7 @@ vulkan = [
"dep:libloading",
"dep:log",
"dep:ordered-float",
"dep:parking_lot",
"dep:profiling",
"dep:smallvec",
"dep:windows",
Expand All @@ -115,6 +117,7 @@ gles = [
"dep:log",
"dep:ndk-sys",
"dep:objc",
"dep:parking_lot",
"dep:profiling",
"dep:wasm-bindgen",
"dep:web-sys",
Expand All @@ -133,6 +136,7 @@ dx12 = [
"dep:libloading",
"dep:log",
"dep:ordered-float",
"dep:parking_lot",
"dep:profiling",
"dep:range-alloc",
"dep:windows-core",
Expand Down Expand Up @@ -174,6 +178,8 @@ device_lost_panic = []
#
# Only affects the d3d12 and vulkan backends.
internal_error_panic = []
# Tracks validation errors in a `VALIDATION_CANARY` static.
validation_canary = ["dep:parking_lot"]

###################
### Workarounds ###
Expand All @@ -196,12 +202,12 @@ required-features = ["gles"]

[dependencies]
naga.workspace = true
wgpu-types.workspace = true
wgpu-types = { workspace = true, default-features = false }

# Dependencies in the lib and empty backend
bitflags.workspace = true
raw-window-handle.workspace = true
parking_lot.workspace = true
parking_lot = { workspace = true, optional = true }
thiserror.workspace = true

# Target agnostic dependencies used only in backends.
Expand Down
9 changes: 5 additions & 4 deletions wgpu-hal/src/auxil/dxgi/exception.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use alloc::{
borrow::Cow,
string::{String, ToString as _},
};
use alloc::{borrow::Cow, string::String};

use parking_lot::Mutex;
use windows::Win32::{Foundation, System::Diagnostics::Debug};

#[cfg(feature = "validation_canary")]
use alloc::string::ToString as _;

// This is a mutex as opposed to an atomic as we need to completely
// lock everyone out until we have registered or unregistered the
// exception handler, otherwise really nasty races could happen.
Expand Down Expand Up @@ -86,6 +86,7 @@ unsafe extern "system" fn output_debug_string_handler(
log::log!(level, "{}", message);
});

#[cfg(feature = "validation_canary")]
if cfg!(debug_assertions) && level == log::Level::Error {
// Set canary and continue
crate::VALIDATION_CANARY.add(message.to_string());
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/gles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,7 @@ fn gl_debug_message_callback(source: u32, gltype: u32, id: u32, severity: u32, m
);
});

#[cfg(feature = "validation_canary")]
if cfg!(debug_assertions) && log_severity == log::Level::Error {
// Set canary and continue
crate::VALIDATION_CANARY.add(message.to_string());
Expand Down
43 changes: 6 additions & 37 deletions wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ pub mod api {

mod dynamic;

#[cfg(feature = "validation_canary")]
mod validation_canary;

#[cfg(feature = "validation_canary")]
pub use validation_canary::{ValidationCanary, VALIDATION_CANARY};

pub(crate) use dynamic::impl_dyn_resource;
pub use dynamic::{
DynAccelerationStructure, DynAcquiredSurfaceTexture, DynAdapter, DynBindGroup,
Expand All @@ -298,7 +304,6 @@ use core::{
};

use bitflags::bitflags;
use parking_lot::Mutex;
use thiserror::Error;
use wgt::WasmNotSendSync;

Expand Down Expand Up @@ -2374,42 +2379,6 @@ pub struct ComputePassDescriptor<'a, Q: DynQuerySet + ?Sized> {
pub timestamp_writes: Option<PassTimestampWrites<'a, Q>>,
}

/// Stores the text of any validation errors that have occurred since
/// the last call to `get_and_reset`.
///
/// Each value is a validation error and a message associated with it,
/// or `None` if the error has no message from the api.
///
/// This is used for internal wgpu testing only and _must not_ be used
/// as a way to check for errors.
///
/// This works as a static because `cargo nextest` runs all of our
/// tests in separate processes, so each test gets its own canary.
///
/// This prevents the issue of one validation error terminating the
/// entire process.
pub static VALIDATION_CANARY: ValidationCanary = ValidationCanary {
inner: Mutex::new(Vec::new()),
};

/// Flag for internal testing.
pub struct ValidationCanary {
inner: Mutex<Vec<String>>,
}

impl ValidationCanary {
#[allow(dead_code)] // in some configurations this function is dead
fn add(&self, msg: String) {
self.inner.lock().push(msg);
}

/// Returns any API validation errors that have occurred in this process
/// since the last call to this function.
pub fn get_and_reset(&self) -> Vec<String> {
self.inner.lock().drain(..).collect()
}
}

#[test]
fn test_default_limits() {
let limits = wgt::Limits::default();
Expand Down
39 changes: 39 additions & 0 deletions wgpu-hal/src/validation_canary.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use alloc::{string::String, vec::Vec};

use parking_lot::Mutex;

/// Stores the text of any validation errors that have occurred since
/// the last call to `get_and_reset`.
///
/// Each value is a validation error and a message associated with it,
/// or `None` if the error has no message from the api.
///
/// This is used for internal wgpu testing only and _must not_ be used
/// as a way to check for errors.
///
/// This works as a static because `cargo nextest` runs all of our
/// tests in separate processes, so each test gets its own canary.
///
/// This prevents the issue of one validation error terminating the
/// entire process.
pub static VALIDATION_CANARY: ValidationCanary = ValidationCanary {
inner: Mutex::new(Vec::new()),
};

/// Flag for internal testing.
pub struct ValidationCanary {
inner: Mutex<Vec<String>>,
}

impl ValidationCanary {
#[allow(dead_code)] // in some configurations this function is dead
pub(crate) fn add(&self, msg: String) {
self.inner.lock().push(msg);
}

/// Returns any API validation errors that have occurred in this process
/// since the last call to this function.
pub fn get_and_reset(&self) -> Vec<String> {
self.inner.lock().drain(..).collect()
}
}
13 changes: 5 additions & 8 deletions wgpu-hal/src/vulkan/instance.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
use alloc::{
borrow::ToOwned as _,
boxed::Box,
ffi::CString,
string::{String, ToString as _},
sync::Arc,
vec::Vec,
};
use alloc::{borrow::ToOwned as _, boxed::Box, ffi::CString, string::String, sync::Arc, vec::Vec};
use core::{
ffi::{c_void, CStr},
slice,
Expand All @@ -17,6 +10,9 @@ use arrayvec::ArrayVec;
use ash::{ext, khr, vk};
use parking_lot::RwLock;

#[cfg(feature = "validation_canary")]
use alloc::string::ToString as _;

unsafe extern "system" fn debug_utils_messenger_callback(
message_severity: vk::DebugUtilsMessageSeverityFlagsEXT,
message_type: vk::DebugUtilsMessageTypeFlagsEXT,
Expand Down Expand Up @@ -145,6 +141,7 @@ unsafe extern "system" fn debug_utils_messenger_callback(
});
}

#[cfg(feature = "validation_canary")]
if cfg!(debug_assertions) && level == log::Level::Error {
// Set canary and continue
crate::VALIDATION_CANARY.add(message.to_string());
Expand Down
Loading