mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 23:04:07 +00:00
Avoid AtomicU64 for it not being portable
This commit is contained in:
parent
cc91b38301
commit
37288a657f
@ -17,7 +17,7 @@ use hal::Device as _;
|
||||
use parking_lot::Mutex;
|
||||
use thiserror::Error;
|
||||
|
||||
use std::{mem, sync::atomic::Ordering};
|
||||
use std::mem;
|
||||
|
||||
/// A struct that keeps lists of resources that are no longer needed by the user.
|
||||
#[derive(Debug, Default)]
|
||||
@ -367,7 +367,7 @@ impl<A: HalApi> LifetimeTracker<A> {
|
||||
if let Some(res) = hub.bind_groups.unregister_locked(id.0, &mut *guard) {
|
||||
self.suspected_resources.add_trackers(&res.used);
|
||||
|
||||
let submit_index = res.life_guard.submission_index.load(Ordering::Acquire);
|
||||
let submit_index = res.life_guard.life_count();
|
||||
self.active
|
||||
.iter_mut()
|
||||
.find(|a| a.index == submit_index)
|
||||
@ -393,7 +393,7 @@ impl<A: HalApi> LifetimeTracker<A> {
|
||||
|
||||
if let Some(res) = hub.texture_views.unregister_locked(id.0, &mut *guard) {
|
||||
self.suspected_resources.textures.push(res.parent_id.value);
|
||||
let submit_index = res.life_guard.submission_index.load(Ordering::Acquire);
|
||||
let submit_index = res.life_guard.life_count();
|
||||
self.active
|
||||
.iter_mut()
|
||||
.find(|a| a.index == submit_index)
|
||||
@ -418,7 +418,7 @@ impl<A: HalApi> LifetimeTracker<A> {
|
||||
}
|
||||
|
||||
if let Some(res) = hub.textures.unregister_locked(id.0, &mut *guard) {
|
||||
let submit_index = res.life_guard.submission_index.load(Ordering::Acquire);
|
||||
let submit_index = res.life_guard.life_count();
|
||||
let raw = match res.inner {
|
||||
resource::TextureInner::Native { raw: Some(raw) } => raw,
|
||||
_ => continue,
|
||||
@ -446,7 +446,7 @@ impl<A: HalApi> LifetimeTracker<A> {
|
||||
}
|
||||
|
||||
if let Some(res) = hub.samplers.unregister_locked(id.0, &mut *guard) {
|
||||
let submit_index = res.life_guard.submission_index.load(Ordering::Acquire);
|
||||
let submit_index = res.life_guard.life_count();
|
||||
self.active
|
||||
.iter_mut()
|
||||
.find(|a| a.index == submit_index)
|
||||
@ -471,7 +471,7 @@ impl<A: HalApi> LifetimeTracker<A> {
|
||||
log::debug!("Buffer {:?} is detached", id);
|
||||
|
||||
if let Some(res) = hub.buffers.unregister_locked(id.0, &mut *guard) {
|
||||
let submit_index = res.life_guard.submission_index.load(Ordering::Acquire);
|
||||
let submit_index = res.life_guard.life_count();
|
||||
if let resource::BufferMapState::Init { stage_buffer, .. } = res.map_state {
|
||||
self.free_resources.buffers.push(stage_buffer);
|
||||
}
|
||||
@ -498,7 +498,7 @@ impl<A: HalApi> LifetimeTracker<A> {
|
||||
}
|
||||
|
||||
if let Some(res) = hub.compute_pipelines.unregister_locked(id.0, &mut *guard) {
|
||||
let submit_index = res.life_guard.submission_index.load(Ordering::Acquire);
|
||||
let submit_index = res.life_guard.life_count();
|
||||
self.active
|
||||
.iter_mut()
|
||||
.find(|a| a.index == submit_index)
|
||||
@ -522,7 +522,7 @@ impl<A: HalApi> LifetimeTracker<A> {
|
||||
}
|
||||
|
||||
if let Some(res) = hub.render_pipelines.unregister_locked(id.0, &mut *guard) {
|
||||
let submit_index = res.life_guard.submission_index.load(Ordering::Acquire);
|
||||
let submit_index = res.life_guard.life_count();
|
||||
self.active
|
||||
.iter_mut()
|
||||
.find(|a| a.index == submit_index)
|
||||
@ -588,7 +588,7 @@ impl<A: HalApi> LifetimeTracker<A> {
|
||||
// #[cfg(feature = "trace")]
|
||||
// trace.map(|t| t.lock().add(trace::Action::DestroyComputePipeline(id.0)));
|
||||
if let Some(res) = hub.query_sets.unregister_locked(id.0, &mut *guard) {
|
||||
let submit_index = res.life_guard.submission_index.load(Ordering::Acquire);
|
||||
let submit_index = res.life_guard.life_count();
|
||||
self.active
|
||||
.iter_mut()
|
||||
.find(|a| a.index == submit_index)
|
||||
@ -615,7 +615,7 @@ impl<A: HalApi> LifetimeTracker<A> {
|
||||
let resource_id = stored.value;
|
||||
let buf = &buffer_guard[resource_id];
|
||||
|
||||
let submit_index = buf.life_guard.submission_index.load(Ordering::Acquire);
|
||||
let submit_index = buf.life_guard.life_count();
|
||||
log::trace!(
|
||||
"Mapping of {:?} at submission {:?} gets assigned to active {:?}",
|
||||
resource_id,
|
||||
|
@ -19,7 +19,7 @@ use smallvec::SmallVec;
|
||||
use thiserror::Error;
|
||||
use wgt::{BufferAddress, TextureFormat, TextureViewDimension};
|
||||
|
||||
use std::{borrow::Cow, iter, marker::PhantomData, mem, ops::Range, ptr, sync::atomic::Ordering};
|
||||
use std::{borrow::Cow, iter, marker::PhantomData, mem, ops::Range, ptr};
|
||||
|
||||
mod life;
|
||||
pub mod queue;
|
||||
@ -2812,7 +2812,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let last_submission = {
|
||||
let (buffer_guard, _) = hub.buffers.write(&mut token);
|
||||
match buffer_guard.get(buffer_id) {
|
||||
Ok(buffer) => buffer.life_guard.submission_index.load(Ordering::Acquire),
|
||||
Ok(buffer) => buffer.life_guard.life_count(),
|
||||
Err(_) => return Ok(()),
|
||||
}
|
||||
};
|
||||
@ -2964,7 +2964,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
if device.pending_writes.dst_buffers.contains(&buffer_id) {
|
||||
device.pending_writes.temp_resources.push(temp);
|
||||
} else {
|
||||
let last_submit_index = buffer.life_guard.submission_index.load(Ordering::Acquire);
|
||||
let last_submit_index = buffer.life_guard.life_count();
|
||||
drop(buffer_guard);
|
||||
device
|
||||
.lock_life(&mut token)
|
||||
@ -2986,8 +2986,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
match buffer_guard.get_mut(buffer_id) {
|
||||
Ok(buffer) => {
|
||||
let ref_count = buffer.life_guard.ref_count.take().unwrap();
|
||||
let last_submit_index =
|
||||
buffer.life_guard.submission_index.load(Ordering::Acquire);
|
||||
let last_submit_index = buffer.life_guard.life_count();
|
||||
(ref_count, last_submit_index, buffer.device_id.value)
|
||||
}
|
||||
Err(InvalidId) => {
|
||||
@ -3170,8 +3169,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
if device.pending_writes.dst_textures.contains(&texture_id) {
|
||||
device.pending_writes.temp_resources.push(temp);
|
||||
} else {
|
||||
let last_submit_index =
|
||||
texture.life_guard.submission_index.load(Ordering::Acquire);
|
||||
let last_submit_index = texture.life_guard.life_count();
|
||||
drop(texture_guard);
|
||||
device
|
||||
.lock_life(&mut token)
|
||||
@ -3195,8 +3193,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
match texture_guard.get_mut(texture_id) {
|
||||
Ok(texture) => {
|
||||
let ref_count = texture.life_guard.ref_count.take().unwrap();
|
||||
let last_submit_index =
|
||||
texture.life_guard.submission_index.load(Ordering::Acquire);
|
||||
let last_submit_index = texture.life_guard.life_count();
|
||||
(ref_count, last_submit_index, texture.device_id.value)
|
||||
}
|
||||
Err(InvalidId) => {
|
||||
@ -3303,8 +3300,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
match texture_view_guard.get_mut(texture_view_id) {
|
||||
Ok(view) => {
|
||||
let _ref_count = view.life_guard.ref_count.take();
|
||||
let last_submit_index =
|
||||
view.life_guard.submission_index.load(Ordering::Acquire);
|
||||
let last_submit_index = view.life_guard.life_count();
|
||||
let device_id = texture_guard[view.parent_id.value].device_id.value;
|
||||
(last_submit_index, device_id)
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ mod validation;
|
||||
|
||||
pub use hal::api;
|
||||
|
||||
use atomic::{AtomicU64, AtomicUsize, Ordering};
|
||||
use atomic::{AtomicUsize, Ordering};
|
||||
|
||||
use std::{borrow::Cow, os::raw::c_char, ptr, sync::atomic};
|
||||
|
||||
@ -147,7 +147,7 @@ impl Drop for MultiRefCount {
|
||||
#[derive(Debug)]
|
||||
pub struct LifeGuard {
|
||||
ref_count: Option<RefCount>,
|
||||
submission_index: AtomicU64,
|
||||
submission_index: AtomicUsize,
|
||||
#[cfg(debug_assertions)]
|
||||
pub(crate) label: String,
|
||||
}
|
||||
@ -158,7 +158,7 @@ impl LifeGuard {
|
||||
let bx = Box::new(AtomicUsize::new(1));
|
||||
Self {
|
||||
ref_count: ptr::NonNull::new(Box::into_raw(bx)).map(RefCount),
|
||||
submission_index: AtomicU64::new(0),
|
||||
submission_index: AtomicUsize::new(0),
|
||||
#[cfg(debug_assertions)]
|
||||
label: label.to_string(),
|
||||
}
|
||||
@ -170,9 +170,14 @@ impl LifeGuard {
|
||||
|
||||
/// Returns `true` if the resource is still needed by the user.
|
||||
fn use_at(&self, submit_index: SubmissionIndex) -> bool {
|
||||
self.submission_index.store(submit_index, Ordering::Release);
|
||||
self.submission_index
|
||||
.store(submit_index as _, Ordering::Release);
|
||||
self.ref_count.is_some()
|
||||
}
|
||||
|
||||
fn life_count(&self) -> SubmissionIndex {
|
||||
self.submission_index.load(Ordering::Acquire) as _
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
Loading…
Reference in New Issue
Block a user