summaryrefslogtreecommitdiffstats
path: root/third_party/rust/wgpu-core/src/track
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/wgpu-core/src/track')
-rw-r--r--third_party/rust/wgpu-core/src/track/buffer.rs24
-rw-r--r--third_party/rust/wgpu-core/src/track/metadata.rs10
-rw-r--r--third_party/rust/wgpu-core/src/track/mod.rs45
-rw-r--r--third_party/rust/wgpu-core/src/track/stateless.rs22
-rw-r--r--third_party/rust/wgpu-core/src/track/texture.rs4
5 files changed, 76 insertions, 29 deletions
diff --git a/third_party/rust/wgpu-core/src/track/buffer.rs b/third_party/rust/wgpu-core/src/track/buffer.rs
index 6cf1fdda6f..9a52a53253 100644
--- a/third_party/rust/wgpu-core/src/track/buffer.rs
+++ b/third_party/rust/wgpu-core/src/track/buffer.rs
@@ -11,6 +11,7 @@ use super::{PendingTransition, ResourceTracker, TrackerIndex};
use crate::{
hal_api::HalApi,
id::BufferId,
+ lock::{rank, Mutex},
resource::{Buffer, Resource},
snatch::SnatchGuard,
storage::Storage,
@@ -20,7 +21,6 @@ use crate::{
},
};
use hal::{BufferBarrier, BufferUses};
-use parking_lot::Mutex;
use wgt::{strict_assert, strict_assert_eq};
impl ResourceUses for BufferUses {
@@ -51,7 +51,7 @@ pub(crate) struct BufferBindGroupState<A: HalApi> {
impl<A: HalApi> BufferBindGroupState<A> {
pub fn new() -> Self {
Self {
- buffers: Mutex::new(Vec::new()),
+ buffers: Mutex::new(rank::BUFFER_BIND_GROUP_STATE_BUFFERS, Vec::new()),
_phantom: PhantomData,
}
@@ -245,6 +245,22 @@ impl<A: HalApi> BufferUsageScope<A> {
.get(id)
.map_err(|_| UsageConflict::BufferInvalid { id })?;
+ self.insert_merge_single(buffer.clone(), new_state)
+ .map(|_| buffer)
+ }
+
+ /// Merge a single state into the UsageScope, using an already resolved buffer.
+ ///
+ /// If the resulting state is invalid, returns a usage
+ /// conflict with the details of the invalid state.
+ ///
+ /// If the ID is higher than the length of internal vectors,
+ /// the vectors will be extended. A call to set_size is not needed.
+ pub fn insert_merge_single(
+ &mut self,
+ buffer: Arc<Buffer<A>>,
+ new_state: BufferUses,
+ ) -> Result<(), UsageConflict> {
let index = buffer.info.tracker_index().as_usize();
self.allow_index(index);
@@ -260,12 +276,12 @@ impl<A: HalApi> BufferUsageScope<A> {
index,
BufferStateProvider::Direct { state: new_state },
ResourceMetadataProvider::Direct {
- resource: Cow::Owned(buffer.clone()),
+ resource: Cow::Owned(buffer),
},
)?;
}
- Ok(buffer)
+ Ok(())
}
}
diff --git a/third_party/rust/wgpu-core/src/track/metadata.rs b/third_party/rust/wgpu-core/src/track/metadata.rs
index 3e71e0e084..d6e8d6f906 100644
--- a/third_party/rust/wgpu-core/src/track/metadata.rs
+++ b/third_party/rust/wgpu-core/src/track/metadata.rs
@@ -87,16 +87,18 @@ impl<T: Resource> ResourceMetadata<T> {
/// Add the resource with the given index, epoch, and reference count to the
/// set.
///
+ /// Returns a reference to the newly inserted resource.
+ /// (This allows avoiding a clone/reference count increase in many cases.)
+ ///
/// # Safety
///
/// The given `index` must be in bounds for this `ResourceMetadata`'s
/// existing tables. See `tracker_assert_in_bounds`.
#[inline(always)]
- pub(super) unsafe fn insert(&mut self, index: usize, resource: Arc<T>) {
+ pub(super) unsafe fn insert(&mut self, index: usize, resource: Arc<T>) -> &Arc<T> {
self.owned.set(index, true);
- unsafe {
- *self.resources.get_unchecked_mut(index) = Some(resource);
- }
+ let resource_dst = unsafe { self.resources.get_unchecked_mut(index) };
+ resource_dst.insert(resource)
}
/// Get the resource with the given index.
diff --git a/third_party/rust/wgpu-core/src/track/mod.rs b/third_party/rust/wgpu-core/src/track/mod.rs
index 374dfe7493..cc20b2a01c 100644
--- a/third_party/rust/wgpu-core/src/track/mod.rs
+++ b/third_party/rust/wgpu-core/src/track/mod.rs
@@ -102,10 +102,14 @@ mod stateless;
mod texture;
use crate::{
- binding_model, command, conv, hal_api::HalApi, id, pipeline, resource, snatch::SnatchGuard,
+ binding_model, command, conv,
+ hal_api::HalApi,
+ id,
+ lock::{rank, Mutex, RwLock},
+ pipeline, resource,
+ snatch::SnatchGuard,
};
-use parking_lot::{Mutex, RwLock};
use std::{fmt, ops, sync::Arc};
use thiserror::Error;
@@ -136,7 +140,8 @@ impl TrackerIndex {
/// of a certain type. This index is separate from the resource ID for various reasons:
/// - There can be multiple resource IDs pointing the the same resource.
/// - IDs of dead handles can be recycled while resources are internally held alive (and tracked).
-/// - The plan is to remove IDs in the long run (https://github.com/gfx-rs/wgpu/issues/5121).
+/// - The plan is to remove IDs in the long run
+/// ([#5121](https://github.com/gfx-rs/wgpu/issues/5121)).
/// In order to produce these tracker indices, there is a shared TrackerIndexAllocator
/// per resource type. Indices have the same lifetime as the internal resource they
/// are associated to (alloc happens when creating the resource and free is called when
@@ -190,7 +195,10 @@ pub(crate) struct SharedTrackerIndexAllocator {
impl SharedTrackerIndexAllocator {
pub fn new() -> Self {
SharedTrackerIndexAllocator {
- inner: Mutex::new(TrackerIndexAllocator::new()),
+ inner: Mutex::new(
+ rank::SHARED_TRACKER_INDEX_ALLOCATOR_INNER,
+ TrackerIndexAllocator::new(),
+ ),
}
}
@@ -480,11 +488,26 @@ impl<A: HalApi> RenderBundleScope<A> {
/// Create the render bundle scope and pull the maximum IDs from the hubs.
pub fn new() -> Self {
Self {
- buffers: RwLock::new(BufferUsageScope::default()),
- textures: RwLock::new(TextureUsageScope::default()),
- bind_groups: RwLock::new(StatelessTracker::new()),
- render_pipelines: RwLock::new(StatelessTracker::new()),
- query_sets: RwLock::new(StatelessTracker::new()),
+ buffers: RwLock::new(
+ rank::RENDER_BUNDLE_SCOPE_BUFFERS,
+ BufferUsageScope::default(),
+ ),
+ textures: RwLock::new(
+ rank::RENDER_BUNDLE_SCOPE_TEXTURES,
+ TextureUsageScope::default(),
+ ),
+ bind_groups: RwLock::new(
+ rank::RENDER_BUNDLE_SCOPE_BIND_GROUPS,
+ StatelessTracker::new(),
+ ),
+ render_pipelines: RwLock::new(
+ rank::RENDER_BUNDLE_SCOPE_RENDER_PIPELINES,
+ StatelessTracker::new(),
+ ),
+ query_sets: RwLock::new(
+ rank::RENDER_BUNDLE_SCOPE_QUERY_SETS,
+ StatelessTracker::new(),
+ ),
}
}
@@ -639,8 +662,8 @@ impl<A: HalApi> Tracker<A> {
///
/// If a transition is needed to get the resources into the needed
/// state, those transitions are stored within the tracker. A
- /// subsequent call to [`BufferTracker::drain`] or
- /// [`TextureTracker::drain`] is needed to get those transitions.
+ /// subsequent call to [`BufferTracker::drain_transitions`] or
+ /// [`TextureTracker::drain_transitions`] is needed to get those transitions.
///
/// This is a really funky method used by Compute Passes to generate
/// barriers after a call to dispatch without needing to iterate
diff --git a/third_party/rust/wgpu-core/src/track/stateless.rs b/third_party/rust/wgpu-core/src/track/stateless.rs
index 00225f2305..25ffc027ee 100644
--- a/third_party/rust/wgpu-core/src/track/stateless.rs
+++ b/third_party/rust/wgpu-core/src/track/stateless.rs
@@ -6,9 +6,14 @@
use std::sync::Arc;
-use parking_lot::Mutex;
-
-use crate::{id::Id, resource::Resource, resource_log, storage::Storage, track::ResourceMetadata};
+use crate::{
+ id::Id,
+ lock::{rank, Mutex},
+ resource::Resource,
+ resource_log,
+ storage::Storage,
+ track::ResourceMetadata,
+};
use super::{ResourceTracker, TrackerIndex};
@@ -24,7 +29,7 @@ pub(crate) struct StatelessBindGroupSate<T: Resource> {
impl<T: Resource> StatelessBindGroupSate<T> {
pub fn new() -> Self {
Self {
- resources: Mutex::new(Vec::new()),
+ resources: Mutex::new(rank::STATELESS_BIND_GROUP_STATE_RESOURCES, Vec::new()),
}
}
@@ -153,16 +158,17 @@ impl<T: Resource> StatelessTracker<T> {
///
/// If the ID is higher than the length of internal vectors,
/// the vectors will be extended. A call to set_size is not needed.
- pub fn insert_single(&mut self, resource: Arc<T>) {
+ ///
+ /// Returns a reference to the newly inserted resource.
+ /// (This allows avoiding a clone/reference count increase in many cases.)
+ pub fn insert_single(&mut self, resource: Arc<T>) -> &Arc<T> {
let index = resource.as_info().tracker_index().as_usize();
self.allow_index(index);
self.tracker_assert_in_bounds(index);
- unsafe {
- self.metadata.insert(index, resource);
- }
+ unsafe { self.metadata.insert(index, resource) }
}
/// Adds the given resource to the tracker.
diff --git a/third_party/rust/wgpu-core/src/track/texture.rs b/third_party/rust/wgpu-core/src/track/texture.rs
index 3cf95ff38a..51ed72a18d 100644
--- a/third_party/rust/wgpu-core/src/track/texture.rs
+++ b/third_party/rust/wgpu-core/src/track/texture.rs
@@ -24,6 +24,7 @@ use super::{
};
use crate::{
hal_api::HalApi,
+ lock::{rank, Mutex},
resource::{Resource, Texture, TextureInner},
snatch::SnatchGuard,
track::{
@@ -36,7 +37,6 @@ use hal::TextureUses;
use arrayvec::ArrayVec;
use naga::FastHashMap;
-use parking_lot::Mutex;
use wgt::{strict_assert, strict_assert_eq};
use std::{borrow::Cow, iter, marker::PhantomData, ops::Range, sync::Arc, vec::Drain};
@@ -164,7 +164,7 @@ pub(crate) struct TextureBindGroupState<A: HalApi> {
impl<A: HalApi> TextureBindGroupState<A> {
pub fn new() -> Self {
Self {
- textures: Mutex::new(Vec::new()),
+ textures: Mutex::new(rank::TEXTURE_BIND_GROUP_STATE_TEXTURES, Vec::new()),
}
}