mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
[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.
This commit is contained in:
parent
a47ed5dc1e
commit
2bc328c46f
@ -88,8 +88,7 @@ pub struct Device<A: HalApi> {
|
|||||||
label: String,
|
label: String,
|
||||||
|
|
||||||
pub(crate) command_allocator: command::CommandAllocator<A>,
|
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: hal::AtomicFenceValue,
|
||||||
pub(crate) active_submission_index: AtomicU64, //SubmissionIndex,
|
|
||||||
// NOTE: if both are needed, the `snatchable_lock` must be consistently acquired before the
|
// NOTE: if both are needed, the `snatchable_lock` must be consistently acquired before the
|
||||||
// `fence` lock to avoid deadlocks.
|
// `fence` lock to avoid deadlocks.
|
||||||
pub(crate) fence: RwLock<Option<A::Fence>>,
|
pub(crate) fence: RwLock<Option<A::Fence>>,
|
||||||
|
|||||||
@ -28,10 +28,7 @@ use std::{
|
|||||||
mem::{self, ManuallyDrop},
|
mem::{self, ManuallyDrop},
|
||||||
ops::Range,
|
ops::Range,
|
||||||
ptr::NonNull,
|
ptr::NonNull,
|
||||||
sync::{
|
sync::{atomic::Ordering, Arc, Weak},
|
||||||
atomic::{AtomicUsize, Ordering},
|
|
||||||
Arc, Weak,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Information about the wgpu-core resource.
|
/// Information about the wgpu-core resource.
|
||||||
@ -64,7 +61,7 @@ pub(crate) struct TrackingData {
|
|||||||
/// sequentially. Thus, when a queue submission completes, we know any
|
/// sequentially. Thus, when a queue submission completes, we know any
|
||||||
/// resources used in that submission and any lower-numbered submissions are
|
/// resources used in that submission and any lower-numbered submissions are
|
||||||
/// no longer in use by the GPU.
|
/// no longer in use by the GPU.
|
||||||
submission_index: AtomicUsize,
|
submission_index: hal::AtomicFenceValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for TrackingData {
|
impl Drop for TrackingData {
|
||||||
@ -78,7 +75,7 @@ impl TrackingData {
|
|||||||
Self {
|
Self {
|
||||||
tracker_index: tracker_indices.alloc(),
|
tracker_index: tracker_indices.alloc(),
|
||||||
tracker_indices,
|
tracker_indices,
|
||||||
submission_index: AtomicUsize::new(0),
|
submission_index: hal::AtomicFenceValue::new(0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,12 +86,11 @@ impl TrackingData {
|
|||||||
/// Record that this resource will be used by the queue submission with the
|
/// Record that this resource will be used by the queue submission with the
|
||||||
/// given index.
|
/// given index.
|
||||||
pub(crate) fn use_at(&self, submit_index: SubmissionIndex) {
|
pub(crate) fn use_at(&self, submit_index: SubmissionIndex) {
|
||||||
self.submission_index
|
self.submission_index.store(submit_index, Ordering::Release);
|
||||||
.store(submit_index as _, Ordering::Release);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn submission_index(&self) -> SubmissionIndex {
|
pub(crate) fn submission_index(&self) -> SubmissionIndex {
|
||||||
self.submission_index.load(Ordering::Acquire) as _
|
self.submission_index.load(Ordering::Acquire)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -294,6 +294,7 @@ pub const QUERY_SIZE: wgt::BufferAddress = 8;
|
|||||||
pub type Label<'a> = Option<&'a str>;
|
pub type Label<'a> = Option<&'a str>;
|
||||||
pub type MemoryRange = Range<wgt::BufferAddress>;
|
pub type MemoryRange = Range<wgt::BufferAddress>;
|
||||||
pub type FenceValue = u64;
|
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.
|
/// Drop guard to signal wgpu-hal is no longer using an externally created object.
|
||||||
pub type DropGuard = Box<dyn std::any::Any + Send + Sync>;
|
pub type DropGuard = Box<dyn std::any::Any + Send + Sync>;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user