Skip to content
Merged
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
60 changes: 0 additions & 60 deletions wgpu-core/src/assertions.rs

This file was deleted.

24 changes: 14 additions & 10 deletions wgpu-hal/src/dx12/suballocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ mod allocation {
let name = desc.label.unwrap_or("Unlabeled buffer");

// SAFETY: allocator exists when the windows_rs feature is enabled
let mut allocator = device
.mem_allocator
.as_ref()
.strict_unwrap_unchecked()
.lock();
let mut allocator = unsafe {
device
.mem_allocator
.as_ref()
.strict_unwrap_unchecked()
.lock()
};

// let mut allocator = unsafe { device.mem_allocator.as_ref().unwrap_unchecked().lock() };
let allocation_desc = AllocationCreateDesc::from_winapi_d3d12_resource_desc(
Expand Down Expand Up @@ -114,11 +116,13 @@ mod allocation {
let name = desc.label.unwrap_or("Unlabeled texture");

// SAFETY: allocator exists when the windows_rs feature is enabled
let mut allocator = device
.mem_allocator
.as_ref()
.strict_unwrap_unchecked()
.lock();
let mut allocator = unsafe {
device
.mem_allocator
.as_ref()
.strict_unwrap_unchecked()
.lock()
};
let allocation_desc = AllocationCreateDesc::from_winapi_d3d12_resource_desc(
allocator.allocator.device().as_winapi(),
&raw_desc,
Expand Down
28 changes: 17 additions & 11 deletions wgpu-types/src/assertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! `wgpu-core`'s `"strict_asserts"` feature enables that validation
//! in both debug and release builds.

/// This is equivalent to [`std::assert`] if the `strict_asserts` feature is activated.
/// This is equivalent to [`std::assert`] if the `strict_asserts` feature is activated, otherwise equal to [`std::debug_assert`].
#[cfg(feature = "strict_asserts")]
#[macro_export]
macro_rules! strict_assert {
Expand All @@ -20,7 +20,7 @@ macro_rules! strict_assert {
}
}

/// This is equivalent to [`std::assert_eq`] if the `strict_asserts` feature is activated.
/// This is equivalent to [`std::assert_eq`] if the `strict_asserts` feature is activated, otherwise equal to [`std::debug_assert_eq`].
#[cfg(feature = "strict_asserts")]
#[macro_export]
macro_rules! strict_assert_eq {
Expand All @@ -29,7 +29,7 @@ macro_rules! strict_assert_eq {
}
}

/// This is equivalent to [`std::assert_ne`] if the `strict_asserts` feature is activated.
/// This is equivalent to [`std::assert_ne`] if the `strict_asserts` feature is activated, otherwise equal to [`std::debug_assert_ne`].
#[cfg(feature = "strict_asserts")]
#[macro_export]
macro_rules! strict_assert_ne {
Expand All @@ -38,7 +38,7 @@ macro_rules! strict_assert_ne {
}
}

/// This is equivalent to [`std::assert`] if the `strict_asserts` feature is activated.
/// This is equivalent to [`std::assert`] if the `strict_asserts` feature is activated, otherwise equal to [`std::debug_assert`]
#[cfg(not(feature = "strict_asserts"))]
#[macro_export]
macro_rules! strict_assert {
Expand All @@ -47,7 +47,7 @@ macro_rules! strict_assert {
};
}

/// This is equivalent to [`std::assert_eq`] if the `strict_asserts` feature is activated.
/// This is equivalent to [`std::assert_eq`] if the `strict_asserts` feature is activated, otherwise equal to [`std::debug_assert_eq`]
#[cfg(not(feature = "strict_asserts"))]
#[macro_export]
macro_rules! strict_assert_eq {
Expand All @@ -56,7 +56,7 @@ macro_rules! strict_assert_eq {
};
}

/// This is equivalent to [`std::assert_ne`] if the `strict_asserts` feature is activated.
/// This is equivalent to [`std::assert_ne`] if the `strict_asserts` feature is activated, otherwise equal to [`std::debug_assert_ne`]
#[cfg(not(feature = "strict_asserts"))]
#[macro_export]
macro_rules! strict_assert_ne {
Expand All @@ -65,22 +65,28 @@ macro_rules! strict_assert_ne {
};
}

/// Used to implement strict_assert for unwrap_unchecked
/// Unwrapping using strict_asserts
pub trait StrictAssertUnwrapExt<T> {
/// Implementation of strict_assert for unwrap_unchecked
fn strict_unwrap_unchecked(self) -> T;
/// Unchecked unwrap, with a [`strict_assert`] backed assertion of validitly.
///
/// # Safety
///
/// It _must_ be valid to call unwrap_unchecked on this value.
unsafe fn strict_unwrap_unchecked(self) -> T;
}

impl<T> StrictAssertUnwrapExt<T> for Option<T> {
fn strict_unwrap_unchecked(self) -> T {
unsafe fn strict_unwrap_unchecked(self) -> T {
strict_assert!(self.is_some(), "Called strict_unwrap_unchecked on None");
// SAFETY: Checked by above assert, or by assertion by unsafe.
unsafe { self.unwrap_unchecked() }
}
}

impl<T, E> StrictAssertUnwrapExt<T> for Result<T, E> {
fn strict_unwrap_unchecked(self) -> T {
unsafe fn strict_unwrap_unchecked(self) -> T {
strict_assert!(self.is_ok(), "Called strict_unwrap_unchecked on Err");
// SAFETY: Checked by above assert, or by assertion by unsafe.
unsafe { self.unwrap_unchecked() }
}
}
4 changes: 2 additions & 2 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ name = "water"
test = true

[features]
default = ["wgsl", "expose-ids", "strict_asserts"]
default = ["wgsl", "expose-ids"]
# Apply run-time checks, even in release builds. These are in addition
# to the validation carried out at public APIs in all builds.
strict_asserts = ["wgc/strict_asserts", "wgt/strict_asserts"]
strict_asserts = ["wgc?/strict_asserts", "wgt/strict_asserts"]
spirv = ["naga/spv-in"]
glsl = ["naga/glsl-in"]
wgsl = ["wgc?/wgsl"]
Expand Down