Skip to content

Commit

Permalink
[hal, core] Introduce wgpu_hal::AtomicFenceValue, and use it.
Browse files Browse the repository at this point in the history
Introduce the new type alias `wgpu_hal::AtomicFenceValue`, which is
the atomic version of `wgpu_hal::FenceValue`. Use this type alias in
`wgpu_core`. Remove `as` conversions made unnecessary since we're not
conflating `usize` with `u64` any more.
  • Loading branch information
jimblandy committed Jul 17, 2024
1 parent a47ed5d commit 2bc328c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
3 changes: 1 addition & 2 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ pub struct Device<A: HalApi> {
label: String,

pub(crate) command_allocator: command::CommandAllocator<A>,
//Note: The submission index here corresponds to the last submission that is done.
pub(crate) active_submission_index: AtomicU64, //SubmissionIndex,
pub(crate) active_submission_index: hal::AtomicFenceValue,
// NOTE: if both are needed, the `snatchable_lock` must be consistently acquired before the
// `fence` lock to avoid deadlocks.
pub(crate) fence: RwLock<Option<A::Fence>>,
Expand Down
14 changes: 5 additions & 9 deletions wgpu-core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ use std::{
mem::{self, ManuallyDrop},
ops::Range,
ptr::NonNull,
sync::{
atomic::{AtomicUsize, Ordering},
Arc, Weak,
},
sync::{atomic::Ordering, Arc, Weak},
};

/// Information about the wgpu-core resource.
Expand Down Expand Up @@ -64,7 +61,7 @@ pub(crate) struct TrackingData {
/// sequentially. Thus, when a queue submission completes, we know any
/// resources used in that submission and any lower-numbered submissions are
/// no longer in use by the GPU.
submission_index: AtomicUsize,
submission_index: hal::AtomicFenceValue,
}

impl Drop for TrackingData {
Expand All @@ -78,7 +75,7 @@ impl TrackingData {
Self {
tracker_index: tracker_indices.alloc(),
tracker_indices,
submission_index: AtomicUsize::new(0),
submission_index: hal::AtomicFenceValue::new(0),
}
}

Expand All @@ -89,12 +86,11 @@ impl TrackingData {
/// Record that this resource will be used by the queue submission with the
/// given index.
pub(crate) fn use_at(&self, submit_index: SubmissionIndex) {
self.submission_index
.store(submit_index as _, Ordering::Release);
self.submission_index.store(submit_index, Ordering::Release);
}

pub(crate) fn submission_index(&self) -> SubmissionIndex {
self.submission_index.load(Ordering::Acquire) as _
self.submission_index.load(Ordering::Acquire)
}
}

Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ pub const QUERY_SIZE: wgt::BufferAddress = 8;
pub type Label<'a> = Option<&'a str>;
pub type MemoryRange = Range<wgt::BufferAddress>;
pub type FenceValue = u64;
pub type AtomicFenceValue = std::sync::atomic::AtomicU64;

/// Drop guard to signal wgpu-hal is no longer using an externally created object.
pub type DropGuard = Box<dyn std::any::Any + Send + Sync>;
Expand Down

0 comments on commit 2bc328c

Please sign in to comment.