Skip to content

Commit

Permalink
Merge branch 'trunk' into small-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
atlv24 authored Apr 25, 2024
2 parents 97b2097 + a364e56 commit fa93fc8
Show file tree
Hide file tree
Showing 11 changed files with 356 additions and 119 deletions.
8 changes: 5 additions & 3 deletions wgpu-core/src/device/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{
id::{self, AdapterId, DeviceId, QueueId, SurfaceId},
init_tracker::TextureInitTracker,
instance::{self, Adapter, Surface},
lock::{rank, RwLock},
pipeline, present,
resource::{self, BufferAccessResult},
resource::{BufferAccessError, BufferMapOperation, CreateBufferError, Resource},
Expand All @@ -20,7 +21,6 @@ use crate::{

use arrayvec::ArrayVec;
use hal::Device as _;
use parking_lot::RwLock;

use wgt::{BufferAddress, TextureFormat};

Expand Down Expand Up @@ -643,8 +643,10 @@ impl Global {
texture.hal_usage |= hal::TextureUses::COPY_DST;
}

texture.initialization_status =
RwLock::new(TextureInitTracker::new(desc.mip_level_count, 0));
texture.initialization_status = RwLock::new(
rank::TEXTURE_INITIALIZATION_STATUS,
TextureInitTracker::new(desc.mip_level_count, 0),
);

let (id, resource) = fid.assign(Arc::new(texture));
api_log!("Device::create_texture({desc:?}) -> {id:?}");
Expand Down
27 changes: 16 additions & 11 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
TextureInitTracker, TextureInitTrackerAction,
},
instance::Adapter,
lock::{rank, Mutex, MutexGuard},
lock::{rank, Mutex, MutexGuard, RwLock},
pipeline,
pool::ResourcePool,
registry::Registry,
Expand All @@ -42,7 +42,6 @@ use crate::{
use arrayvec::ArrayVec;
use hal::{CommandEncoder as _, Device as _};
use once_cell::sync::OnceCell;
use parking_lot::RwLock;

use smallvec::SmallVec;
use thiserror::Error;
Expand Down Expand Up @@ -272,8 +271,8 @@ impl<A: HalApi> Device<A> {
info: ResourceInfo::new("<device>", None),
command_allocator,
active_submission_index: AtomicU64::new(0),
fence: RwLock::new(Some(fence)),
snatchable_lock: unsafe { SnatchLock::new() },
fence: RwLock::new(rank::DEVICE_FENCE, Some(fence)),
snatchable_lock: unsafe { SnatchLock::new(rank::DEVICE_SNATCHABLE_LOCK) },
valid: AtomicBool::new(true),
trackers: Mutex::new(rank::DEVICE_TRACKERS, Tracker::new()),
tracker_indices: TrackerIndexAllocators::new(),
Expand Down Expand Up @@ -656,7 +655,10 @@ impl<A: HalApi> Device<A> {
device: self.clone(),
usage: desc.usage,
size: desc.size,
initialization_status: RwLock::new(BufferInitTracker::new(aligned_size)),
initialization_status: RwLock::new(
rank::BUFFER_INITIALIZATION_STATUS,
BufferInitTracker::new(aligned_size),
),
sync_mapped_writes: Mutex::new(rank::BUFFER_SYNC_MAPPED_WRITES, None),
map_state: Mutex::new(rank::BUFFER_MAP_STATE, resource::BufferMapState::Idle),
info: ResourceInfo::new(
Expand All @@ -683,10 +685,10 @@ impl<A: HalApi> Device<A> {
desc: desc.map_label(|_| ()),
hal_usage,
format_features,
initialization_status: RwLock::new(TextureInitTracker::new(
desc.mip_level_count,
desc.array_layer_count(),
)),
initialization_status: RwLock::new(
rank::TEXTURE_INITIALIZATION_STATUS,
TextureInitTracker::new(desc.mip_level_count, desc.array_layer_count()),
),
full_range: TextureSelector {
mips: 0..desc.mip_level_count,
layers: 0..desc.array_layer_count(),
Expand All @@ -695,7 +697,7 @@ impl<A: HalApi> Device<A> {
desc.label.borrow_or_default(),
Some(self.tracker_indices.textures.clone()),
),
clear_mode: RwLock::new(clear_mode),
clear_mode: RwLock::new(rank::TEXTURE_CLEAR_MODE, clear_mode),
views: Mutex::new(rank::TEXTURE_VIEWS, Vec::new()),
bind_groups: Mutex::new(rank::TEXTURE_BIND_GROUPS, Vec::new()),
}
Expand All @@ -713,7 +715,10 @@ impl<A: HalApi> Device<A> {
device: self.clone(),
usage: desc.usage,
size: desc.size,
initialization_status: RwLock::new(BufferInitTracker::new(0)),
initialization_status: RwLock::new(
rank::BUFFER_INITIALIZATION_STATUS,
BufferInitTracker::new(0),
),
sync_mapped_writes: Mutex::new(rank::BUFFER_SYNC_MAPPED_WRITES, None),
map_state: Mutex::new(rank::BUFFER_MAP_STATE, resource::BufferMapState::Idle),
info: ResourceInfo::new(
Expand Down
4 changes: 2 additions & 2 deletions wgpu-core/src/lock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mod ranked;
mod vanilla;

#[cfg(wgpu_validate_locks)]
pub use ranked::{Mutex, MutexGuard};
pub use ranked::{Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard};

#[cfg(not(wgpu_validate_locks))]
pub use vanilla::{Mutex, MutexGuard};
pub use vanilla::{Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard};
99 changes: 63 additions & 36 deletions wgpu-core/src/lock/rank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ macro_rules! define_lock_ranks {
{
$(
$( #[ $attr:meta ] )*
rank $name:ident $member:literal followed by { $( $follower:ident ),* $(,)? };
rank $name:ident $member:literal followed by { $( $follower:ident ),* $(,)? }
)*
} => {
// An enum that assigns a unique number to each rank.
Expand All @@ -55,9 +55,9 @@ macro_rules! define_lock_ranks {
bitflags::bitflags! {
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
/// A bitflags type representing a set of lock ranks.
pub struct LockRankSet: u32 {
pub struct LockRankSet: u64 {
$(
const $name = 1 << (LockRankNumber:: $name as u32);
const $name = 1 << (LockRankNumber:: $name as u64);
)*
}
}
Expand Down Expand Up @@ -87,57 +87,84 @@ macro_rules! define_lock_ranks {
}

define_lock_ranks! {
rank DEVICE_TEMP_SUSPECTED "Device::temp_suspected" followed by {
SHARED_TRACKER_INDEX_ALLOCATOR_INNER,
COMMAND_BUFFER_DATA,
DEVICE_TRACKERS,
}
rank COMMAND_BUFFER_DATA "CommandBuffer::data" followed by {
DEVICE_SNATCHABLE_LOCK,
DEVICE_USAGE_SCOPES,
SHARED_TRACKER_INDEX_ALLOCATOR_INNER,
BUFFER_BIND_GROUP_STATE_BUFFERS,
TEXTURE_BIND_GROUP_STATE_TEXTURES,
BUFFER_MAP_STATE,
STATELESS_BIND_GROUP_STATE_RESOURCES,
};
rank STAGING_BUFFER_RAW "StagingBuffer::raw" followed by { };
rank COMMAND_ALLOCATOR_FREE_ENCODERS "CommandAllocator::free_encoders" followed by {
}
rank DEVICE_SNATCHABLE_LOCK "Device::snatchable_lock" followed by {
SHARED_TRACKER_INDEX_ALLOCATOR_INNER,
};
rank DEVICE_TRACKERS "Device::trackers" followed by { };
rank DEVICE_LIFE_TRACKER "Device::life_tracker" followed by {
COMMAND_ALLOCATOR_FREE_ENCODERS,
DEVICE_TRACE,
BUFFER_MAP_STATE,
BUFFER_BIND_GROUP_STATE_BUFFERS,
TEXTURE_BIND_GROUP_STATE_TEXTURES,
STATELESS_BIND_GROUP_STATE_RESOURCES,
// Uncomment this to see an interesting cycle.
// DEVICE_TEMP_SUSPECTED,
};
rank DEVICE_TEMP_SUSPECTED "Device::temp_suspected" followed by {
// COMMAND_BUFFER_DATA,
}
rank BUFFER_MAP_STATE "Buffer::map_state" followed by {
DEVICE_PENDING_WRITES,
SHARED_TRACKER_INDEX_ALLOCATOR_INNER,
COMMAND_BUFFER_DATA,
DEVICE_TRACKERS,
};
DEVICE_TRACE,
}
rank DEVICE_PENDING_WRITES "Device::pending_writes" followed by {
COMMAND_ALLOCATOR_FREE_ENCODERS,
SHARED_TRACKER_INDEX_ALLOCATOR_INNER,
DEVICE_LIFE_TRACKER,
};
rank DEVICE_DEFERRED_DESTROY "Device::deferred_destroy" followed by { };
}
rank DEVICE_LIFE_TRACKER "Device::life_tracker" followed by {
COMMAND_ALLOCATOR_FREE_ENCODERS,
// Uncomment this to see an interesting cycle.
// DEVICE_TEMP_SUSPECTED,
DEVICE_TRACE,
}
rank COMMAND_ALLOCATOR_FREE_ENCODERS "CommandAllocator::free_encoders" followed by {
SHARED_TRACKER_INDEX_ALLOCATOR_INNER,
}

rank BUFFER_BIND_GROUPS "Buffer::bind_groups" followed by { }
rank BUFFER_BIND_GROUP_STATE_BUFFERS "BufferBindGroupState::buffers" followed by { }
rank BUFFER_INITIALIZATION_STATUS "Buffer::initialization_status" followed by { }
rank BUFFER_SYNC_MAPPED_WRITES "Buffer::sync_mapped_writes" followed by { }
rank DEVICE_DEFERRED_DESTROY "Device::deferred_destroy" followed by { }
rank DEVICE_FENCE "Device::fence" followed by { }
#[allow(dead_code)]
rank DEVICE_TRACE "Device::trace" followed by { };
rank DEVICE_USAGE_SCOPES "Device::usage_scopes" followed by { };
rank BUFFER_SYNC_MAPPED_WRITES "Buffer::sync_mapped_writes" followed by { };
rank BUFFER_MAP_STATE "Buffer::map_state" followed by { DEVICE_PENDING_WRITES };
rank BUFFER_BIND_GROUPS "Buffer::bind_groups" followed by { };
rank TEXTURE_VIEWS "Texture::views" followed by { };
rank TEXTURE_BIND_GROUPS "Texture::bind_groups" followed by { };
rank IDENTITY_MANAGER_VALUES "IdentityManager::values" followed by { };
rank RESOURCE_POOL_INNER "ResourcePool::inner" followed by { };
rank BUFFER_BIND_GROUP_STATE_BUFFERS "BufferBindGroupState::buffers" followed by { };
rank STATELESS_BIND_GROUP_STATE_RESOURCES "StatelessBindGroupState::resources" followed by { };
rank TEXTURE_BIND_GROUP_STATE_TEXTURES "TextureBindGroupState::textures" followed by { };
rank SHARED_TRACKER_INDEX_ALLOCATOR_INNER "SharedTrackerIndexAllocator::inner" followed by { };
rank SURFACE_PRESENTATION "Surface::presentation" followed by { };
rank DEVICE_TRACE "Device::trace" followed by { }
rank DEVICE_TRACKERS "Device::trackers" followed by { }
rank DEVICE_USAGE_SCOPES "Device::usage_scopes" followed by { }
rank IDENTITY_MANAGER_VALUES "IdentityManager::values" followed by { }
rank REGISTRY_STORAGE "Registry::storage" followed by { }
rank RENDER_BUNDLE_SCOPE_BUFFERS "RenderBundleScope::buffers" followed by { }
rank RENDER_BUNDLE_SCOPE_TEXTURES "RenderBundleScope::textures" followed by { }
rank RENDER_BUNDLE_SCOPE_BIND_GROUPS "RenderBundleScope::bind_groups" followed by { }
rank RENDER_BUNDLE_SCOPE_RENDER_PIPELINES "RenderBundleScope::render_pipelines" followed by { }
rank RENDER_BUNDLE_SCOPE_QUERY_SETS "RenderBundleScope::query_sets" followed by { }
rank RESOURCE_POOL_INNER "ResourcePool::inner" followed by { }
rank SHARED_TRACKER_INDEX_ALLOCATOR_INNER "SharedTrackerIndexAllocator::inner" followed by { }
rank STAGING_BUFFER_RAW "StagingBuffer::raw" followed by { }
rank STATELESS_BIND_GROUP_STATE_RESOURCES "StatelessBindGroupState::resources" followed by { }
rank SURFACE_PRESENTATION "Surface::presentation" followed by { }
rank TEXTURE_BIND_GROUPS "Texture::bind_groups" followed by { }
rank TEXTURE_BIND_GROUP_STATE_TEXTURES "TextureBindGroupState::textures" followed by { }
rank TEXTURE_INITIALIZATION_STATUS "Texture::initialization_status" followed by { }
rank TEXTURE_CLEAR_MODE "Texture::clear_mode" followed by { }
rank TEXTURE_VIEWS "Texture::views" followed by { }

#[cfg(test)]
rank PAWN "pawn" followed by { ROOK, BISHOP };
rank PAWN "pawn" followed by { ROOK, BISHOP }
#[cfg(test)]
rank ROOK "rook" followed by { KNIGHT };
rank ROOK "rook" followed by { KNIGHT }
#[cfg(test)]
rank KNIGHT "knight" followed by { };
rank KNIGHT "knight" followed by { }
#[cfg(test)]
rank BISHOP "bishop" followed by { };
rank BISHOP "bishop" followed by { }
}
Loading

0 comments on commit fa93fc8

Please sign in to comment.