diff options
Diffstat (limited to 'third_party/rust/wgpu-core/src/resource.rs')
-rw-r--r-- | third_party/rust/wgpu-core/src/resource.rs | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/third_party/rust/wgpu-core/src/resource.rs b/third_party/rust/wgpu-core/src/resource.rs index de5d1868a3..aca077caab 100644 --- a/third_party/rust/wgpu-core/src/resource.rs +++ b/third_party/rust/wgpu-core/src/resource.rs @@ -9,11 +9,10 @@ use crate::{ global::Global, hal_api::HalApi, id::{AdapterId, BufferId, DeviceId, Id, Marker, SurfaceId, TextureId}, - identity::IdentityManager, init_tracker::{BufferInitTracker, TextureInitTracker}, resource, resource_log, snatch::{ExclusiveSnatchGuard, SnatchGuard, Snatchable}, - track::TextureSelector, + track::{SharedTrackerIndexAllocator, TextureSelector, TrackerIndex}, validation::MissingBufferUsageError, Label, SubmissionIndex, }; @@ -31,7 +30,7 @@ use std::{ ops::Range, ptr::NonNull, sync::{ - atomic::{AtomicBool, AtomicUsize, Ordering}, + atomic::{AtomicUsize, Ordering}, Arc, Weak, }, }; @@ -58,7 +57,8 @@ use std::{ #[derive(Debug)] pub struct ResourceInfo<T: Resource> { id: Option<Id<T::Marker>>, - identity: Option<Arc<IdentityManager<T::Marker>>>, + tracker_index: TrackerIndex, + tracker_indices: Option<Arc<SharedTrackerIndexAllocator>>, /// The index of the last queue submission in which the resource /// was used. /// @@ -74,19 +74,26 @@ pub struct ResourceInfo<T: Resource> { impl<T: Resource> Drop for ResourceInfo<T> { fn drop(&mut self) { - if let Some(identity) = self.identity.as_ref() { - let id = self.id.as_ref().unwrap(); - identity.free(*id); + if let Some(indices) = &self.tracker_indices { + indices.free(self.tracker_index); } } } impl<T: Resource> ResourceInfo<T> { #[allow(unused_variables)] - pub(crate) fn new(label: &str) -> Self { + pub(crate) fn new( + label: &str, + tracker_indices: Option<Arc<SharedTrackerIndexAllocator>>, + ) -> Self { + let tracker_index = tracker_indices + .as_ref() + .map(|indices| indices.alloc()) + .unwrap_or(TrackerIndex::INVALID); Self { id: None, - identity: None, + tracker_index, + tracker_indices, submission_index: AtomicUsize::new(0), label: label.to_string(), } @@ -111,9 +118,13 @@ impl<T: Resource> ResourceInfo<T> { self.id.unwrap() } - pub(crate) fn set_id(&mut self, id: Id<T::Marker>, identity: &Arc<IdentityManager<T::Marker>>) { + pub(crate) fn tracker_index(&self) -> TrackerIndex { + debug_assert!(self.tracker_index != TrackerIndex::INVALID); + self.tracker_index + } + + pub(crate) fn set_id(&mut self, id: Id<T::Marker>) { self.id = Some(id); - self.identity = Some(identity.clone()); } /// Record that this resource will be used by the queue submission with the @@ -551,6 +562,7 @@ impl<A: HalApi> Buffer<A> { device: Arc::clone(&self.device), submission_index: self.info.submission_index(), id: self.info.id.unwrap(), + tracker_index: self.info.tracker_index(), label: self.info.label.clone(), bind_groups, })) @@ -611,6 +623,7 @@ pub struct DestroyedBuffer<A: HalApi> { device: Arc<Device<A>>, label: String, pub(crate) id: BufferId, + pub(crate) tracker_index: TrackerIndex, pub(crate) submission_index: u64, bind_groups: Vec<Weak<BindGroup<A>>>, } @@ -717,7 +730,6 @@ pub(crate) enum TextureInner<A: HalApi> { Surface { raw: Option<A::SurfaceTexture>, parent_id: SurfaceId, - has_work: AtomicBool, }, } @@ -886,6 +898,7 @@ impl<A: HalApi> Texture<A> { views, bind_groups, device: Arc::clone(&self.device), + tracker_index: self.info.tracker_index(), submission_index: self.info.submission_index(), id: self.info.id.unwrap(), label: self.info.label.clone(), @@ -1003,6 +1016,7 @@ pub struct DestroyedTexture<A: HalApi> { device: Arc<Device<A>>, label: String, pub(crate) id: TextureId, + pub(crate) tracker_index: TrackerIndex, pub(crate) submission_index: u64, } |