Skip to content

Commit

Permalink
move strict_asserts macro to wgpu-types
Browse files Browse the repository at this point in the history
  • Loading branch information
i509VCB committed Dec 9, 2022
1 parent 98971c6 commit 225fcc7
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 61 deletions.
1 change: 0 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ run-wasm = "run --release --package run-wasm --"
rustflags = [
"--cfg=web_sys_unstable_apis"
]
target = "wasm32-unknown-unknown"
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Additionally `Surface::get_default_config` now returns an Option and returns Non
- Combine `Surface::get_supported_formats`, `Surface::get_supported_present_modes`, and `Surface::get_supported_alpha_modes` into `Surface::get_capabilities` and `SurfaceCapabilities`. By @cwfitzgerald in [#3157](https://github.com/gfx-rs/wgpu/pull/3157)
- Make `Surface::get_default_config` return an Option to prevent panics. By @cwfitzgerald in [#3157](https://github.com/gfx-rs/wgpu/pull/3157)
- Lower the `max_buffer_size` limit value for compatibility with Apple2 and WebGPU compliance. By @jinleili in [#3255](https://github.com/gfx-rs/wgpu/pull/3255)
- The `strict_assert` family of macros was moved to `wgpu-types`. By @i509VCB in [#3051](https://github.com/gfx-rs/wgpu/pull/3051)

#### WebGPU

Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ emscripten = ["hal/emscripten"]

# 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 = []
strict_asserts = ["wgt/strict_asserts"]
angle = ["hal/gles"]
# Enable API tracing
trace = ["ron", "serde", "wgt/trace", "arrayvec/serde", "naga/serialize"]
Expand Down
3 changes: 0 additions & 3 deletions wgpu-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
clippy::pattern_type_mismatch,
)]

#[macro_use]
mod assertions;

pub mod binding_model;
pub mod command;
mod conv;
Expand Down
1 change: 1 addition & 0 deletions wgpu-core/src/track/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
LifeGuard, RefCount,
};
use hal::BufferUses;
use wgt::{strict_assert, strict_assert_eq};

impl ResourceUses for BufferUses {
const EXCLUSIVE: Self = Self::EXCLUSIVE;
Expand Down
1 change: 1 addition & 0 deletions wgpu-core/src/track/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
};
use bit_vec::BitVec;
use std::{borrow::Cow, marker::PhantomData, mem};
use wgt::strict_assert;

/// A set of resources, holding a [`RefCount`] and epoch for each member.
///
Expand Down
1 change: 1 addition & 0 deletions wgpu-core/src/track/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ pub(crate) use stateless::{StatelessBindGroupSate, StatelessTracker};
pub(crate) use texture::{
TextureBindGroupState, TextureSelector, TextureTracker, TextureUsageScope,
};
use wgt::strict_assert_ne;

/// A structure containing all the information about a particular resource
/// transition. User code should be able to generate a pipeline barrier
Expand Down
1 change: 1 addition & 0 deletions wgpu-core/src/track/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use hal::TextureUses;

use arrayvec::ArrayVec;
use naga::FastHashMap;
use wgt::{strict_assert, strict_assert_eq};

use std::{borrow::Cow, iter, marker::PhantomData, ops::Range, vec::Drain};

Expand Down
1 change: 1 addition & 0 deletions wgpu-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rustdoc-args = ["--cfg", "docsrs"]
[features]
trace = ["serde"]
replay = ["serde"]
strict_asserts = []

[dependencies]
bitflags.workspace = true
Expand Down
66 changes: 66 additions & 0 deletions wgpu-types/src/assertions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//! Macros for validation internal to the wgpu.
//!
//! This module defines assertion macros that respect `wgpu-type`'s
//! `"strict_asserts"` feature.
//!
//! Because `wgpu-core`'s public APIs validate their arguments in all
//! types of builds, for performance, the `track` module skips some of
//! Rust's usual run-time checks on its internal operations in release
//! builds. However, some `wgpu-core` applications have a strong
//! preference for robustness over performance. To accommodate them,
//! `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.
#[cfg(feature = "strict_asserts")]
#[macro_export]
macro_rules! strict_assert {
( $( $arg:tt )* ) => {
assert!( $( $arg )* )
}
}

/// This is equivalent to [`std::assert_eq`] if the `strict_asserts` feature is activated.
#[cfg(feature = "strict_asserts")]
#[macro_export]
macro_rules! strict_assert_eq {
( $( $arg:tt )* ) => {
assert_eq!( $( $arg )* )
}
}

/// This is equivalent to [`std::assert_ne`] if the `strict_asserts` feature is activated.
#[cfg(feature = "strict_asserts")]
#[macro_export]
macro_rules! strict_assert_ne {
( $( $arg:tt )* ) => {
assert_ne!( $( $arg )* )
}
}

/// This is equivalent to [`std::assert`] if the `strict_asserts` feature is activated.
#[cfg(not(feature = "strict_asserts"))]
#[macro_export]
macro_rules! strict_assert {
( $( $arg:tt )* ) => {
debug_assert!( $( $arg )* )
};
}

/// This is equivalent to [`std::assert_eq`] if the `strict_asserts` feature is activated.
#[cfg(not(feature = "strict_asserts"))]
#[macro_export]
macro_rules! strict_assert_eq {
( $( $arg:tt )* ) => {
debug_assert_eq!( $( $arg )* )
};
}

/// This is equivalent to [`std::assert_ne`] if the `strict_asserts` feature is activated.
#[cfg(not(feature = "strict_asserts"))]
#[macro_export]
macro_rules! strict_assert_ne {
( $( $arg:tt )* ) => {
debug_assert_ne!( $( $arg )* )
};
}
2 changes: 2 additions & 0 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use serde::{Deserialize, Serialize};
use std::hash::{Hash, Hasher};
use std::{num::NonZeroU32, ops::Range};

mod assertions;

// Use this macro instead of the one provided by the bitflags_serde_shim crate
// because the latter produces an error when deserializing bits that are not
// specified in the bitflags, while we want deserialization to succeed and
Expand Down
2 changes: 1 addition & 1 deletion wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ test = true
default = ["wgsl", "expose-ids", "strict_asserts"]
# 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"]
strict_asserts = ["wgc/strict_asserts", "wgt/strict_asserts"]
spirv = ["naga/spv-in"]
glsl = ["naga/glsl-in"]
wgsl = ["wgc?/wgsl"]
Expand Down
50 changes: 0 additions & 50 deletions wgpu/src/assertions.rs

This file was deleted.

6 changes: 3 additions & 3 deletions wgpu/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::{
};

use wgt::{
AdapterInfo, BufferAddress, BufferSize, Color, DownlevelCapabilities, DynamicOffset, Extent3d,
Features, ImageDataLayout, ImageSubresourceRange, IndexFormat, Limits, ShaderStages,
SurfaceConfiguration, SurfaceStatus, TextureFormat, TextureFormatFeatures,
strict_assert, AdapterInfo, BufferAddress, BufferSize, Color, DownlevelCapabilities,
DynamicOffset, Extent3d, Features, ImageDataLayout, ImageSubresourceRange, IndexFormat, Limits,
ShaderStages, SurfaceConfiguration, SurfaceStatus, TextureFormat, TextureFormatFeatures,
};

use crate::{
Expand Down
2 changes: 0 additions & 2 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#![doc(html_logo_url = "https://raw.githubusercontent.com/gfx-rs/wgpu/master/logo.png")]
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]

#[macro_use]
mod assertions;
mod backend;
mod context;
pub mod util;
Expand Down

0 comments on commit 225fcc7

Please sign in to comment.