diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f7a3cbe23..1783c22801 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -278,15 +278,25 @@ jobs: - name: check no_std if: matrix.kind == 'no_std' shell: bash + # XXX TBD CHECK no-std for wgpu-types & wgpu-core in separate steps - ??? run: | set -e - # check with no features + # check wgpu-types with no features cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-types --no-default-features - # Check with all features except "std". + # XXX TODO RESOLVE BUILD ISSUE WITH DEPENDENCIES & RE-ENABLE THIS SUB-STEP - XXX TBD MAY NEED TO UPDATE naga for no-std before this will work + # check wgpu-core with no features + # cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-core --no-default-features + + # Check wgpu-types 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 + # XXX TODO ENABLE: + # check wgpu-core with all no-std features (all features possible for no-std) + # XXX TODO IMPROVE COMMA-SEPARATED no-std feature list here + # cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-core --no-default-features --features counters,api_log_info,resource_log_info,renderdoc,strict_asserts,indirect-validation,serde,raw-window-handle,wgsl,glsl,fragile-send-sync-non-atomic-wasm,metal,vulkan,gles,dx12 + # Building for native platforms with standard tests. - name: check native if: matrix.kind == 'native' @@ -303,6 +313,10 @@ jobs: # build docs cargo doc --target ${{ matrix.target }} ${{ matrix.extra-flags }} --all-features --no-deps + # XXX EXTRA SUB-STEP - (SHOULD) DETECT MISSING IMPORT for no-std + # check wgpu-core with no features + cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-core --no-default-features + - name: check private item docs if: matrix.kind == 'native' shell: bash diff --git a/CHANGELOG.md b/CHANGELOG.md index 2201ec3ffc..06e8d1daeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,14 @@ Bottom level categories: ## Unreleased +### Major changes + +#### no-std support in `wgpu-core` + +XXX TODO + +By XXX in XXX + ### Bug Fixes #### Vulkan diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 00872dcbb8..837bd2e4b6 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -35,6 +35,13 @@ unexpected_cfgs = { level = "warn", check-cfg = ['cfg(wgpu_validate_locks)'] } [lib] [features] +default = ["std"] + +## XXX TODO DOCUMENT THIS +std = [] + +# XXX TODO I think I got it right which features actually require std - I think we should find a way to check this in CI + ## Internally count resources and events for debugging purposes. If the counters ## feature is disabled, the counting infrastructure is removed from the build and ## the exposed counters always return 0. @@ -63,13 +70,13 @@ indirect-validation = ["naga/wgsl-in"] serde = ["dep:serde", "wgt/serde", "arrayvec/serde"] ## Enable API tracing. -trace = ["dep:ron", "serde", "naga/serialize"] +trace = ["std", "dep:ron", "serde", "naga/serialize"] ## Enable lock order observation. -observe_locks = ["dep:ron", "serde/serde_derive"] +observe_locks = ["std", "dep:ron", "serde/serde_derive"] ## Enable API replaying -replay = ["serde", "naga/deserialize"] +replay = ["std", "serde", "naga/deserialize"] ## Enable creating instances using raw-window-handle raw-window-handle = ["dep:raw-window-handle"] diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index 5f1ebce991..234a7ea41f 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -1,4 +1,5 @@ use crate::{ + alias::*, device::{ bgl, Device, DeviceError, MissingDownlevelFlags, MissingFeatures, SHADER_STAGE_COUNT, }, diff --git a/wgpu-core/src/command/allocator.rs b/wgpu-core/src/command/allocator.rs index 82839c37e4..31cc9ec100 100644 --- a/wgpu-core/src/command/allocator.rs +++ b/wgpu-core/src/command/allocator.rs @@ -1,3 +1,4 @@ +use crate::alias::*; use crate::lock::{rank, Mutex}; /// A pool of free [`wgpu_hal::CommandEncoder`]s, owned by a `Device`. diff --git a/wgpu-core/src/command/bind.rs b/wgpu-core/src/command/bind.rs index 2e1ffa030e..40b284268d 100644 --- a/wgpu-core/src/command/bind.rs +++ b/wgpu-core/src/command/bind.rs @@ -1,6 +1,7 @@ use std::sync::Arc; use crate::{ + alias::*, binding_model::{BindGroup, LateMinBufferBindingSizeMismatch, PipelineLayout}, device::SHADER_STAGE_COUNT, pipeline::LateSizedBufferGroup, @@ -16,6 +17,7 @@ mod compat { use wgt::{BindingType, ShaderStages}; use crate::{ + alias::*, binding_model::BindGroupLayout, error::MultiError, resource::{Labeled, ParentDevice, ResourceErrorIdent}, diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index 6aa614ac5f..f052708ffe 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -79,6 +79,7 @@ index format changes. #![allow(clippy::reversed_empty_ranges)] use crate::{ + alias::*, binding_model::{BindError, BindGroup, PipelineLayout}, command::{ BasePass, BindGroupStateChange, ColorAttachmentError, DrawError, MapPassErr, @@ -1573,7 +1574,7 @@ where pub mod bundle_ffi { use super::{RenderBundleEncoder, RenderCommand}; - use crate::{id, RawString}; + use crate::{alias::*, id, RawString}; use std::{convert::TryInto, slice}; use wgt::{BufferAddress, BufferSize, DynamicOffset, IndexFormat}; diff --git a/wgpu-core/src/command/clear.rs b/wgpu-core/src/command/clear.rs index 0811c2ac42..00bdbdf3c8 100644 --- a/wgpu-core/src/command/clear.rs +++ b/wgpu-core/src/command/clear.rs @@ -1,3 +1,5 @@ +use crate::alias::*; + use std::{ops::Range, sync::Arc}; #[cfg(feature = "trace")] diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 0fa6845d28..a5de4b508d 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -1,4 +1,5 @@ use crate::{ + alias::*, binding_model::{ BindError, BindGroup, LateMinBufferBindingSizeMismatch, PushConstantUploadError, }, diff --git a/wgpu-core/src/command/compute_command.rs b/wgpu-core/src/command/compute_command.rs index 67c23d9452..9f72a48060 100644 --- a/wgpu-core/src/command/compute_command.rs +++ b/wgpu-core/src/command/compute_command.rs @@ -1,6 +1,7 @@ use std::sync::Arc; use crate::{ + alias::*, binding_model::BindGroup, id, pipeline::ComputePipeline, diff --git a/wgpu-core/src/command/draw.rs b/wgpu-core/src/command/draw.rs index 76a4cfb063..4575b1e916 100644 --- a/wgpu-core/src/command/draw.rs +++ b/wgpu-core/src/command/draw.rs @@ -1,4 +1,5 @@ use crate::{ + alias::*, binding_model::{LateMinBufferBindingSizeMismatch, PushConstantUploadError}, resource::{ DestroyedResourceError, MissingBufferUsageError, MissingTextureUsageError, diff --git a/wgpu-core/src/command/memory_init.rs b/wgpu-core/src/command/memory_init.rs index 909b001b61..9010821cf3 100644 --- a/wgpu-core/src/command/memory_init.rs +++ b/wgpu-core/src/command/memory_init.rs @@ -3,6 +3,7 @@ use std::{ops::Range, sync::Arc, vec::Drain}; use hashbrown::hash_map::Entry; use crate::{ + alias::*, device::Device, init_tracker::*, resource::{DestroyedResourceError, ParentDevice, Texture, Trackable}, diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index f4ff30a392..065f1efdad 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -13,6 +13,8 @@ mod render_command; mod timestamp_writes; mod transfer; +use crate::alias::*; + use std::mem::{self, ManuallyDrop}; use std::sync::Arc; diff --git a/wgpu-core/src/command/query.rs b/wgpu-core/src/command/query.rs index c2444aa129..305ef8e052 100644 --- a/wgpu-core/src/command/query.rs +++ b/wgpu-core/src/command/query.rs @@ -1,6 +1,7 @@ #[cfg(feature = "trace")] use crate::device::trace::Command as TraceCommand; use crate::{ + alias::*, command::{CommandBuffer, CommandEncoderError}, device::{DeviceError, MissingFeatures}, global::Global, diff --git a/wgpu-core/src/command/ray_tracing.rs b/wgpu-core/src/command/ray_tracing.rs index 22970d542b..ed7cb47c82 100644 --- a/wgpu-core/src/command/ray_tracing.rs +++ b/wgpu-core/src/command/ray_tracing.rs @@ -1,4 +1,5 @@ use crate::{ + alias::*, device::queue::TempResource, global::Global, hub::Hub, diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index abbbcfb46a..99b68c476d 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -1,3 +1,4 @@ +use crate::alias::*; use crate::binding_model::BindGroup; use crate::command::{ validate_and_begin_occlusion_query, validate_and_begin_pipeline_statistics_query, diff --git a/wgpu-core/src/command/render_command.rs b/wgpu-core/src/command/render_command.rs index 549d140bb5..4507928653 100644 --- a/wgpu-core/src/command/render_command.rs +++ b/wgpu-core/src/command/render_command.rs @@ -1,4 +1,5 @@ use crate::{ + alias::*, binding_model::BindGroup, id, pipeline::RenderPipeline, diff --git a/wgpu-core/src/command/timestamp_writes.rs b/wgpu-core/src/command/timestamp_writes.rs index e91b48534d..33235e938f 100644 --- a/wgpu-core/src/command/timestamp_writes.rs +++ b/wgpu-core/src/command/timestamp_writes.rs @@ -1,5 +1,6 @@ use std::sync::Arc; +use crate::alias::*; use crate::id; /// Describes the writing of timestamp values in a render or compute pass. diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index 291c44bd2c..e570e5cab5 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -1,6 +1,7 @@ #[cfg(feature = "trace")] use crate::device::trace::Command as TraceCommand; use crate::{ + alias::*, api_log, command::{clear_texture, CommandEncoderError}, conv, diff --git a/wgpu-core/src/device/bgl.rs b/wgpu-core/src/device/bgl.rs index 9b7bdc0fee..07ab384745 100644 --- a/wgpu-core/src/device/bgl.rs +++ b/wgpu-core/src/device/bgl.rs @@ -1,6 +1,7 @@ use std::hash::{Hash, Hasher}; use crate::{ + alias::*, binding_model::{self}, FastIndexMap, }; diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index eff2e811be..cde380521c 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -1,6 +1,7 @@ #[cfg(feature = "trace")] use crate::device::trace; use crate::{ + alias::*, api_log, binding_model::{ self, BindGroupEntry, BindingResource, BufferBinding, ResolvedBindGroupDescriptor, diff --git a/wgpu-core/src/device/life.rs b/wgpu-core/src/device/life.rs index 4d91d1d98f..96eea6ee01 100644 --- a/wgpu-core/src/device/life.rs +++ b/wgpu-core/src/device/life.rs @@ -1,4 +1,5 @@ use crate::{ + alias::*, device::{ queue::{EncoderInFlight, SubmittedWorkDoneClosure, TempResource}, DeviceError, diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index e9600f72d6..cd021f226f 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -1,4 +1,5 @@ use crate::{ + alias::*, binding_model, hub::Hub, id::{BindGroupLayoutId, PipelineLayoutId}, diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index 763edf2121..4aacca6d89 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -1,6 +1,7 @@ #[cfg(feature = "trace")] use crate::device::trace::Action; use crate::{ + alias::*, api_log, command::{ extract_texture_selector, validate_linear_texture_data, validate_texture_copy_range, diff --git a/wgpu-core/src/device/ray_tracing.rs b/wgpu-core/src/device/ray_tracing.rs index 0917831afa..31fe4e7545 100644 --- a/wgpu-core/src/device/ray_tracing.rs +++ b/wgpu-core/src/device/ray_tracing.rs @@ -1,3 +1,5 @@ +use crate::alias::*; + use std::mem::ManuallyDrop; use std::sync::Arc; diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 1d6ef946ea..38a6338961 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -1,6 +1,7 @@ #[cfg(feature = "trace")] use crate::device::trace; use crate::{ + alias::*, binding_model::{self, BindGroup, BindGroupLayout, BindGroupLayoutEntryError}, command, conv, device::{ diff --git a/wgpu-core/src/device/trace.rs b/wgpu-core/src/device/trace.rs index a5f849cb8c..0b5a3103ee 100644 --- a/wgpu-core/src/device/trace.rs +++ b/wgpu-core/src/device/trace.rs @@ -1,3 +1,4 @@ +use crate::alias::*; use crate::id; use std::ops::Range; #[cfg(feature = "trace")] diff --git a/wgpu-core/src/error.rs b/wgpu-core/src/error.rs index 519a5f930c..ce31f2d89e 100644 --- a/wgpu-core/src/error.rs +++ b/wgpu-core/src/error.rs @@ -1,3 +1,5 @@ +use crate::alias::*; + use core::fmt; use std::{error::Error, sync::Arc}; diff --git a/wgpu-core/src/global.rs b/wgpu-core/src/global.rs index 0be903382c..ee71e4f3e5 100644 --- a/wgpu-core/src/global.rs +++ b/wgpu-core/src/global.rs @@ -1,3 +1,5 @@ +use crate::alias::*; + use std::{fmt, sync::Arc}; use crate::{ diff --git a/wgpu-core/src/hash_utils.rs b/wgpu-core/src/hash_utils.rs index fa2db6bf27..450c9b9960 100644 --- a/wgpu-core/src/hash_utils.rs +++ b/wgpu-core/src/hash_utils.rs @@ -2,6 +2,8 @@ //! //! Named hash_utils to prevent clashing with the std::hash module. +use crate::alias::*; + /// HashMap using a fast, non-cryptographic hash algorithm. pub type FastHashMap = hashbrown::HashMap>; diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index 15d3e3c06b..8263994134 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -101,6 +101,7 @@ flagged as errors as well. */ use crate::{ + alias::*, binding_model::{BindGroup, BindGroupLayout, PipelineLayout}, command::{CommandBuffer, RenderBundle}, device::{queue::Queue, Device}, diff --git a/wgpu-core/src/id.rs b/wgpu-core/src/id.rs index 2fdfde9116..fea9a72f03 100644 --- a/wgpu-core/src/id.rs +++ b/wgpu-core/src/id.rs @@ -1,3 +1,5 @@ +// XXX TBD FMT ??? +use crate::alias::*; use crate::{Epoch, Index}; use std::{ cmp::Ordering, diff --git a/wgpu-core/src/identity.rs b/wgpu-core/src/identity.rs index 0493b9d2cf..b59422f0f3 100644 --- a/wgpu-core/src/identity.rs +++ b/wgpu-core/src/identity.rs @@ -1,4 +1,5 @@ use crate::{ + alias::*, id::{Id, Marker}, lock::{rank, Mutex}, Epoch, Index, diff --git a/wgpu-core/src/indirect_validation.rs b/wgpu-core/src/indirect_validation.rs index 3045965435..22e31ed400 100644 --- a/wgpu-core/src/indirect_validation.rs +++ b/wgpu-core/src/indirect_validation.rs @@ -1,3 +1,5 @@ +use crate::alias::*; + use std::mem::size_of; use std::num::NonZeroU64; diff --git a/wgpu-core/src/init_tracker/buffer.rs b/wgpu-core/src/init_tracker/buffer.rs index ee8e99aa22..5a32703856 100644 --- a/wgpu-core/src/init_tracker/buffer.rs +++ b/wgpu-core/src/init_tracker/buffer.rs @@ -1,4 +1,5 @@ use super::{InitTracker, MemoryInitKind}; +use crate::alias::*; use crate::resource::Buffer; use std::{ops::Range, sync::Arc}; diff --git a/wgpu-core/src/init_tracker/mod.rs b/wgpu-core/src/init_tracker/mod.rs index 15a79bf520..b0d3e9eaea 100644 --- a/wgpu-core/src/init_tracker/mod.rs +++ b/wgpu-core/src/init_tracker/mod.rs @@ -31,6 +31,8 @@ system there are two kind of writes: */ +use crate::alias::*; + use smallvec::SmallVec; use std::{fmt, iter, ops::Range}; @@ -280,6 +282,7 @@ impl InitTracker { #[cfg(test)] mod test { + use crate::alias::*; use std::ops::Range; type Tracker = super::InitTracker; diff --git a/wgpu-core/src/init_tracker/texture.rs b/wgpu-core/src/init_tracker/texture.rs index 4bf7278f21..85c952dfbe 100644 --- a/wgpu-core/src/init_tracker/texture.rs +++ b/wgpu-core/src/init_tracker/texture.rs @@ -1,4 +1,6 @@ use super::{InitTracker, MemoryInitKind}; +// XXX TBD FMT ??? +use crate::alias::*; use crate::{resource::Texture, track::TextureSelector}; use arrayvec::ArrayVec; use std::{ops::Range, sync::Arc}; diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 549bff7866..9cecd69b7a 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -1,3 +1,5 @@ +use crate::alias::*; + use std::borrow::Cow; use std::sync::Arc; diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index 4c2ea81490..0019666284 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -55,6 +55,8 @@ // Therefore, this is only really a concern for users targeting WebGL // (the only reason to use wgpu-core on the web in the first place) that have atomics enabled. #![cfg_attr(not(send_sync), allow(clippy::arc_with_non_send_sync))] +// XXX TODO ADD NICE SEPARATING COMMENT HERE +#![no_std] pub mod binding_model; pub mod command; @@ -95,7 +97,13 @@ pub use validation::{map_storage_format_from_naga, map_storage_format_to_naga}; pub use hal::{api, MAX_BIND_GROUPS, MAX_COLOR_ATTACHMENTS, MAX_VERTEX_BUFFERS}; pub use naga; -use std::{borrow::Cow, os::raw::c_char}; +// XXX TBD PLACEMENT - ??? +use core::ffi::c_char; +use std::borrow::Cow; + +// XXX TBD PLACEMENT - ??? +#[cfg(not(feature = "std"))] +use once_cell::sync::OnceCell; pub(crate) use hash_utils::*; @@ -211,6 +219,72 @@ pub(crate) fn get_greatest_common_divisor(mut a: u32, mut b: u32) -> u32 { } } +// XXX TBD CLEANUP NEEDED BELOW - ??? +// XXX TBD SHOULD THIS BE A SEPARATE MODULE - ??? +// XXX TODO CLEANUP WARNING(S) & REMOVE ALLOW(S) +#[allow(unused_imports)] +pub(crate) mod alias { + pub(crate) use std::prelude::v1::*; + pub(crate) mod std { + pub(crate) mod prelude { + pub(crate) mod v1 { + pub(crate) use super::super::{ + alloc::format, borrow::ToOwned, boxed::Box, string::String, string::ToString, + vec, vec::Vec, + }; + // XXX TBD ??? - UPDATE FOR std vs test ??? + // #[cfg(feature = "std")] + #[cfg(any(feature = "std", test))] + pub(crate) use super::super::{eprintln, thread_local}; + } + } + pub(crate) use core::{ + cell, cmp, convert, ffi, fmt, hash, iter, marker, mem, num, ops, panic, ptr, slice, + str, time, + }; + extern crate alloc; + pub(crate) use alloc::{boxed, string, vec}; + pub(crate) mod borrow { + pub(crate) use super::alloc::borrow::*; + } + pub(crate) mod sync { + pub(crate) use super::alloc::sync::*; + #[cfg(any(feature = "std", test))] + pub(crate) use super::std::sync::*; + pub(crate) use core::sync::*; + // XXX TBD ??? - UPDATE FOR std vs test ??? + // XXX TBD NAMING - ??? + #[cfg(not(any(feature = "std", test)))] + pub(crate) use crate::OnceCell as OnceLock; + } + // XXX TBD ??? - UPDATE FOR std vs test ??? + // #[cfg(feature = "std")] + #[cfg(any(feature = "std", test))] + extern crate std; + // XXX TBD ??? - UPDATE FOR std vs test ??? + // #[cfg(feature = "std")] + #[cfg(any(feature = "std", test))] + pub(crate) use std::{ + backtrace, env, eprintln, fs, io, path, process, thread, thread_local, + }; + // XXX TBD MOVE THIS - ??? + // XXX TODO ADD NOTE - IMPORTING error from std, if possible, to AVOID IMPACT on CORE MSRV + // XXX TBD CONSIDER UPDATING CORE MSRV - expected to impact Firefox - found these references: + // - https://github.com/gfx-rs/wgpu/pull/6003 + // - https://searchfox.org/mozilla-central/source/python/mozboot/mozboot/util.py + // - https://firefox-source-docs.mozilla.org/writing-rust-code/update-policy.html + // XXX TBD ??? - UPDATE FOR std vs test ??? + // #[cfg(feature = "std")] + #[cfg(any(feature = "std", test))] + pub(crate) use std::error; + // XXX TODO ADD NOTE - EXPECTED TO IMPACT CORE MSRV for no-std + #[cfg(not(any(feature = "std", test)))] + pub(crate) use core::error; + } +} + +use alias::*; + #[test] fn test_lcd() { assert_eq!(get_lowest_common_denom(2, 2), 2); diff --git a/wgpu-core/src/lock/observing.rs b/wgpu-core/src/lock/observing.rs index c530a56539..b8bbf04f81 100644 --- a/wgpu-core/src/lock/observing.rs +++ b/wgpu-core/src/lock/observing.rs @@ -28,6 +28,7 @@ //! //! [`lock/rank.rs`]: ../../../src/wgpu_core/lock/rank.rs.html +use crate::alias::*; use crate::FastHashSet; use super::rank::{LockRank, LockRankSet}; diff --git a/wgpu-core/src/lock/ranked.rs b/wgpu-core/src/lock/ranked.rs index c3aedb1b08..7bdeb648c9 100644 --- a/wgpu-core/src/lock/ranked.rs +++ b/wgpu-core/src/lock/ranked.rs @@ -55,6 +55,8 @@ //! //! [`lock::rank`]: crate::lock::rank +use crate::alias::*; + use super::rank::LockRank; use std::{cell::Cell, panic::Location}; @@ -80,10 +82,14 @@ pub struct MutexGuard<'a, T> { saved: LockStateGuard, } +#[cfg(feature = "std")] thread_local! { static LOCK_STATE: Cell = const { Cell::new(LockState::INITIAL) }; } +#[cfg(not(feature = "std"))] +static LOCK_STATE: parking_lot::Mutex = parking_lot::Mutex::new(LockState::INITIAL); + /// Per-thread state for the deadlock checker. #[derive(Debug, Copy, Clone)] struct LockState { @@ -123,6 +129,9 @@ impl Drop for LockStateGuard { } } +// XXX TBD I wonder if we should refactor the functions below to improve separation of std vs no-std code ??? + +// XXX TODO UPDATE COMMENTS FOR std vs no-std /// Check and record the acquisition of a lock with `new_rank`. /// /// Check that acquiring a lock with `new_rank` is permitted at this point, and @@ -130,7 +139,11 @@ impl Drop for LockStateGuard { /// /// Return the `LockState` that must be restored when this thread is released. fn acquire(new_rank: LockRank, location: &'static Location<'static>) -> LockState { + #[cfg(feature = "std")] let state = LOCK_STATE.get(); + #[cfg(not(feature = "std"))] + let mut state = LOCK_STATE.lock(); + // Initially, it's fine to acquire any lock. So we only // need to check when `last_acquired` is `Some`. if let Some((ref last_rank, ref last_location)) = state.last_acquired { @@ -148,20 +161,40 @@ fn acquire(new_rank: LockRank, location: &'static Location<'static>) -> LockStat last_rank.bit.member_name(), ); } - LOCK_STATE.set(LockState { + + let new_state = LockState { last_acquired: Some((new_rank, location)), depth: state.depth + 1, - }); - state + }; + + #[cfg(feature = "std")] + LOCK_STATE.set(new_state); + #[cfg(not(feature = "std"))] + { + *state = new_state + } + + #[cfg(feature = "std")] + return state; + #[cfg(not(feature = "std"))] + *state } +// XXX TBD UPDATE COMMENTS FOR std vs no-std - ??? /// Record the release of a lock whose saved state was `saved`. /// /// Check that locks are being acquired in stacking order, and update the /// per-thread state accordingly. fn release(saved: LockState) { + #[cfg(feature = "std")] let prior = LOCK_STATE.replace(saved); + #[cfg(not(feature = "std"))] + { + *(LOCK_STATE.lock()) = saved + } + + #[cfg(feature = "std")] // Although Rust allows mutex guards to be dropped in any // order, this analysis requires that locks be acquired and // released in stack order: the next lock to be released must be @@ -310,6 +343,7 @@ impl<'a, T> std::ops::DerefMut for RwLockWriteGuard<'a, T> { /// Locks can be acquired in the order indicated by their ranks. #[test] +#[cfg(feature = "std")] // XXX TBD ??? / XXX TODO XXX fn permitted() { use super::rank; @@ -321,6 +355,7 @@ fn permitted() { } /// Locks can only be acquired in the order indicated by their ranks. +#[cfg(feature = "std")] // XXX TBD ??? / XXX TODO FIX BEHAVIOR OR FIX TEST for no-std #[test] #[should_panic(expected = "Locking pawn after locking rook")] fn forbidden_unrelated() { @@ -338,6 +373,7 @@ fn forbidden_unrelated() { /// These two locks *could* be acquired in this order, but only if other locks /// are acquired in between them. Skipping ranks isn't allowed. #[test] +#[cfg(feature = "std")] // XXX TBD ??? / XXX TODO FIX BEHAVIOR OR FIX TEST for no-std #[should_panic(expected = "Locking knight after locking pawn")] fn forbidden_skip() { use super::rank; @@ -351,6 +387,7 @@ fn forbidden_skip() { /// Locks can be acquired and released in a stack-like order. #[test] +#[cfg(feature = "std")] // XXX TBD ??? / XXX TODO FIX BEHAVIOR OR FIX TEST for no-std fn stack_like() { use super::rank; @@ -369,6 +406,7 @@ fn stack_like() { /// Locks can only be acquired and released in a stack-like order. #[test] +#[cfg(feature = "std")] // XXX TBD ??? / XXX TODO FIX BEHAVIOR OR FIX TEST for no-std #[should_panic(expected = "Lock not released in stacking order")] fn non_stack_like() { use super::rank; diff --git a/wgpu-core/src/lock/vanilla.rs b/wgpu-core/src/lock/vanilla.rs index 9a35b6d9d8..31772c24da 100644 --- a/wgpu-core/src/lock/vanilla.rs +++ b/wgpu-core/src/lock/vanilla.rs @@ -3,6 +3,8 @@ //! These definitions are used when no particular lock instrumentation //! Cargo feature is selected. +use crate::alias::*; + /// A plain wrapper around [`parking_lot::Mutex`]. /// /// This is just like [`parking_lot::Mutex`], except that our [`new`] diff --git a/wgpu-core/src/pipeline.rs b/wgpu-core/src/pipeline.rs index 32e2378029..8370d23646 100644 --- a/wgpu-core/src/pipeline.rs +++ b/wgpu-core/src/pipeline.rs @@ -1,5 +1,6 @@ pub use crate::pipeline_cache::PipelineCacheValidationError; use crate::{ + alias::*, binding_model::{CreateBindGroupLayoutError, CreatePipelineLayoutError, PipelineLayout}, command::ColorAttachmentError, device::{Device, DeviceError, MissingDownlevelFlags, MissingFeatures, RenderPassContext}, diff --git a/wgpu-core/src/pipeline_cache.rs b/wgpu-core/src/pipeline_cache.rs index e506d2cd5b..5fbdcfde97 100644 --- a/wgpu-core/src/pipeline_cache.rs +++ b/wgpu-core/src/pipeline_cache.rs @@ -1,3 +1,5 @@ +use crate::alias::*; + use std::mem::size_of; use thiserror::Error; @@ -297,6 +299,8 @@ impl<'a> Writer<'a> { #[cfg(test)] mod tests { + use crate::alias::*; + use wgt::AdapterInfo; use crate::pipeline_cache::{PipelineCacheValidationError as E, HEADER_LENGTH}; diff --git a/wgpu-core/src/pool.rs b/wgpu-core/src/pool.rs index 375b36c32e..0267b7c143 100644 --- a/wgpu-core/src/pool.rs +++ b/wgpu-core/src/pool.rs @@ -6,6 +6,7 @@ use std::{ use hashbrown::{hash_map::Entry, HashMap}; use once_cell::sync::OnceCell; +use crate::alias::*; use crate::lock::{rank, Mutex}; use crate::FastHashMap; @@ -107,6 +108,7 @@ impl ResourcePool { #[cfg(test)] mod tests { + use crate::alias::*; use std::sync::{ atomic::{AtomicU32, Ordering}, Barrier, diff --git a/wgpu-core/src/present.rs b/wgpu-core/src/present.rs index f1b01a1a21..ac36fd8c13 100644 --- a/wgpu-core/src/present.rs +++ b/wgpu-core/src/present.rs @@ -9,6 +9,8 @@ When this texture is presented, we remove it from the device tracker as well as extract it from the hub. !*/ +use crate::alias::*; + use std::{mem::ManuallyDrop, sync::Arc}; #[cfg(feature = "trace")] diff --git a/wgpu-core/src/ray_tracing.rs b/wgpu-core/src/ray_tracing.rs index fe6a1f7f6a..b8a407b376 100644 --- a/wgpu-core/src/ray_tracing.rs +++ b/wgpu-core/src/ray_tracing.rs @@ -8,6 +8,7 @@ // - ([non performance] extract function in build (rust function extraction with guards is a pain)) use crate::{ + alias::*, command::CommandEncoderError, device::{DeviceError, MissingFeatures}, id::{BlasId, BufferId, TlasId}, diff --git a/wgpu-core/src/registry.rs b/wgpu-core/src/registry.rs index b3349235e9..a06f0d5eb8 100644 --- a/wgpu-core/src/registry.rs +++ b/wgpu-core/src/registry.rs @@ -1,6 +1,7 @@ use std::{mem::size_of, sync::Arc}; use crate::{ + alias::*, id::Id, identity::IdentityManager, lock::{rank, RwLock, RwLockReadGuard, RwLockWriteGuard}, @@ -128,7 +129,7 @@ impl Registry { mod tests { use std::sync::Arc; - use crate::{id::Marker, resource::ResourceType, storage::StorageItem}; + use crate::{alias::*, id::Marker, resource::ResourceType, storage::StorageItem}; use super::Registry; struct TestData; diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index 9c2252e665..90ea3ffac7 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -1,6 +1,7 @@ #[cfg(feature = "trace")] use crate::device::trace; use crate::{ + alias::*, binding_model::BindGroup, device::{ queue, resource::DeferredDestroy, BufferMapPendingClosure, Device, DeviceError, diff --git a/wgpu-core/src/scratch.rs b/wgpu-core/src/scratch.rs index dcd2d28fb4..ef2556004d 100644 --- a/wgpu-core/src/scratch.rs +++ b/wgpu-core/src/scratch.rs @@ -1,3 +1,4 @@ +use crate::alias::*; use crate::device::{Device, DeviceError}; use crate::resource_log; use hal::BufferUses; diff --git a/wgpu-core/src/snatch.rs b/wgpu-core/src/snatch.rs index 0d57f41fcc..e8496e6afa 100644 --- a/wgpu-core/src/snatch.rs +++ b/wgpu-core/src/snatch.rs @@ -1,11 +1,14 @@ #![allow(unused)] +use crate::alias::*; use crate::lock::{RwLock, RwLockReadGuard, RwLockWriteGuard}; +#[cfg(feature = "std")] +use std::backtrace::Backtrace; +#[cfg(all(feature = "std", debug_assertions))] +use std::thread; use std::{ - backtrace::Backtrace, cell::{Cell, RefCell, UnsafeCell}, panic::{self, Location}, - thread, }; use crate::lock::rank; @@ -70,20 +73,25 @@ unsafe impl Sync for Snatchable {} struct LockTrace { purpose: &'static str, caller: &'static Location<'static>, + #[cfg(feature = "std")] backtrace: Backtrace, } impl std::fmt::Display for LockTrace { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + #[cfg(feature = "std")] + let backtrace_info = &self.backtrace; + #[cfg(not(feature = "std"))] + let backtrace_info = ""; write!( f, "a {} lock at {}\n{}", - self.purpose, self.caller, self.backtrace + self.purpose, self.caller, backtrace_info ) } } -#[cfg(debug_assertions)] +#[cfg(all(feature = "std", debug_assertions))] impl LockTrace { #[track_caller] fn enter(purpose: &'static str) { @@ -111,12 +119,13 @@ impl LockTrace { } } -#[cfg(not(debug_assertions))] +#[cfg(not(all(feature = "std", debug_assertions)))] impl LockTrace { fn enter(purpose: &'static str) {} fn exit() {} } +#[cfg(feature = "std")] thread_local! { static SNATCH_LOCK_TRACE: Cell> = const { Cell::new(None) }; } diff --git a/wgpu-core/src/storage.rs b/wgpu-core/src/storage.rs index c2ab9faa76..adde2bae98 100644 --- a/wgpu-core/src/storage.rs +++ b/wgpu-core/src/storage.rs @@ -1,3 +1,5 @@ +use crate::alias::*; + use std::sync::Arc; use crate::id::{Id, Marker}; diff --git a/wgpu-core/src/track/buffer.rs b/wgpu-core/src/track/buffer.rs index cfd166070d..41f6486f43 100644 --- a/wgpu-core/src/track/buffer.rs +++ b/wgpu-core/src/track/buffer.rs @@ -4,6 +4,8 @@ //! a 16 bit bitflag of buffer usages. Because there is only ever //! one subresource, they have no selector. +use crate::alias::*; + use std::sync::{Arc, Weak}; use super::{PendingTransition, TrackerIndex}; diff --git a/wgpu-core/src/track/metadata.rs b/wgpu-core/src/track/metadata.rs index 8f03caf7b0..a65b1623e1 100644 --- a/wgpu-core/src/track/metadata.rs +++ b/wgpu-core/src/track/metadata.rs @@ -1,5 +1,7 @@ //! The `ResourceMetadata` type. +use crate::alias::*; + use bit_vec::BitVec; use wgt::strict_assert; diff --git a/wgpu-core/src/track/mod.rs b/wgpu-core/src/track/mod.rs index a0b91be5e6..864344c074 100644 --- a/wgpu-core/src/track/mod.rs +++ b/wgpu-core/src/track/mod.rs @@ -102,6 +102,7 @@ mod stateless; mod texture; use crate::{ + alias::*, binding_model, command, lock::{rank, Mutex}, pipeline, diff --git a/wgpu-core/src/track/range.rs b/wgpu-core/src/track/range.rs index ee67732787..a70fad7d89 100644 --- a/wgpu-core/src/track/range.rs +++ b/wgpu-core/src/track/range.rs @@ -2,6 +2,8 @@ //TODO: consider getting rid of it. use smallvec::SmallVec; +use crate::alias::*; + use std::{fmt::Debug, iter, ops::Range}; /// Structure that keeps track of a I -> T mapping, diff --git a/wgpu-core/src/track/stateless.rs b/wgpu-core/src/track/stateless.rs index 975a850f36..8be26172a7 100644 --- a/wgpu-core/src/track/stateless.rs +++ b/wgpu-core/src/track/stateless.rs @@ -1,3 +1,5 @@ +use crate::alias::*; + use std::slice::Iter; use std::sync::Arc; diff --git a/wgpu-core/src/track/texture.rs b/wgpu-core/src/track/texture.rs index 0a9a5f5489..cabcb95da9 100644 --- a/wgpu-core/src/track/texture.rs +++ b/wgpu-core/src/track/texture.rs @@ -20,6 +20,7 @@ use super::{range::RangedStates, PendingTransition, PendingTransitionList}; use crate::{ + alias::*, resource::{Texture, TextureInner, TextureView, Trackable}, snatch::SnatchGuard, track::{ diff --git a/wgpu-core/src/validation.rs b/wgpu-core/src/validation.rs index 17c42ecf4e..aa6498c145 100644 --- a/wgpu-core/src/validation.rs +++ b/wgpu-core/src/validation.rs @@ -1,4 +1,4 @@ -use crate::{device::bgl, resource::InvalidResourceError, FastHashMap, FastHashSet}; +use crate::{alias::*, device::bgl, resource::InvalidResourceError, FastHashMap, FastHashSet}; use arrayvec::ArrayVec; use hashbrown::hash_map::Entry; use std::fmt; diff --git a/wgpu-core/src/weak_vec.rs b/wgpu-core/src/weak_vec.rs index e00cc9e599..95a2573a36 100644 --- a/wgpu-core/src/weak_vec.rs +++ b/wgpu-core/src/weak_vec.rs @@ -1,5 +1,7 @@ //! Module containing the [`WeakVec`] API. +use crate::alias::*; + use std::sync::Weak; /// An optimized container for `Weak` references of `T` that minimizes reallocations by @@ -45,6 +47,8 @@ impl WeakVec { } pub(crate) struct WeakVecIter { + // XXX TODO CLEANUP WARNING(S) & REMOVE ALLOW(S) + #[allow(unused_qualifications)] inner: std::vec::IntoIter>, }