use alloc::{sync::Arc, vec::Vec}; use core::sync::atomic::Ordering; use parking_lot::RwLock;
use glow::HasContext;
usecrate::AtomicFenceValue;
#[derive(Debug)] struct GLFence { // Since a fence can be `Copy`ed, there can exist some // cases where a fence could be destroyed while something // else is still using it. Therefore, while a function is // using this fence (and doesn't keep pending read locked), // it should clone the `Arc` to show it needs this to // stay alive. // // The arc should not be kept after a function has finished
sync: Arc<glow::Fence>,
value: crate::FenceValue,
}
for gl_fence in pending.iter() { if gl_fence.value <= max_value { // We already know this was good, no need to check again continue;
} // We have pending `read` locked, so we shouldn't have to clone it. let status = unsafe { gl.get_sync_status(*gl_fence.sync) }; if status == glow::SIGNALED {
max_value = gl_fence.value;
} else { // Anything after the first unsignalled is guaranteed to also be unsignalled break;
}
}
// Track the latest value, to save ourselves some querying later self.last_completed.fetch_max(max_value, Ordering::AcqRel);
let latest = self.get_latest(gl); letmut pending = self.pending.write();
pending.retain_mut(|gl_fence| { if gl_fence.value > latest { true
} elseiflet Some(fence) = Arc::get_mut(&mut gl_fence.sync) { unsafe {
gl.delete_sync(*fence);
} false
} else { // Another function is currently using this value. In general, these should finish // very quickly (for wait because the fence should already be signaled, an all // others are just fast), but submit should be very fast, so we shouldn't block on // this. true
}
});
}
for gl_fence inself.pending.into_inner() { unsafe {
gl.delete_sync(
Arc::into_inner(gl_fence.sync)
.expect("A function has failed to drop all its references to this"),
);
}
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.