Skip to content

Commit 2bc328c

Browse files
committed
[hal, core] Introduce wgpu_hal::AtomicFenceValue, and use it.
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.
1 parent a47ed5d commit 2bc328c

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

wgpu-core/src/device/resource.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ pub struct Device<A: HalApi> {
8888
label: String,
8989

9090
pub(crate) command_allocator: command::CommandAllocator<A>,
91-
//Note: The submission index here corresponds to the last submission that is done.
92-
pub(crate) active_submission_index: AtomicU64, //SubmissionIndex,
91+
pub(crate) active_submission_index: hal::AtomicFenceValue,
9392
// NOTE: if both are needed, the `snatchable_lock` must be consistently acquired before the
9493
// `fence` lock to avoid deadlocks.
9594
pub(crate) fence: RwLock<Option<A::Fence>>,

wgpu-core/src/resource.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ use std::{
2828
mem::{self, ManuallyDrop},
2929
ops::Range,
3030
ptr::NonNull,
31-
sync::{
32-
atomic::{AtomicUsize, Ordering},
33-
Arc, Weak,
34-
},
31+
sync::{atomic::Ordering, Arc, Weak},
3532
};
3633

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

7067
impl Drop for TrackingData {
@@ -78,7 +75,7 @@ impl TrackingData {
7875
Self {
7976
tracker_index: tracker_indices.alloc(),
8077
tracker_indices,
81-
submission_index: AtomicUsize::new(0),
78+
submission_index: hal::AtomicFenceValue::new(0),
8279
}
8380
}
8481

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

9692
pub(crate) fn submission_index(&self) -> SubmissionIndex {
97-
self.submission_index.load(Ordering::Acquire) as _
93+
self.submission_index.load(Ordering::Acquire)
9894
}
9995
}
10096

wgpu-hal/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ pub const QUERY_SIZE: wgt::BufferAddress = 8;
294294
pub type Label<'a> = Option<&'a str>;
295295
pub type MemoryRange = Range<wgt::BufferAddress>;
296296
pub type FenceValue = u64;
297+
pub type AtomicFenceValue = std::sync::atomic::AtomicU64;
297298

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

0 commit comments

Comments
 (0)