use std::sync::{Arc, Mutex};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TransferDirection {
CpuToGpu,
GpuToCpu,
Bidirectional,
}
pub struct CpuGpuBarrier {
frame: Arc<Mutex<u64>>,
gpu_fence: Arc<Mutex<Option<GpuFence>>>,
}
struct GpuFence {
value: u64,
signaled: bool,
}
impl CpuGpuBarrier {
pub fn new() -> Self {
Self {
frame: Arc::new(Mutex::new(0)),
gpu_fence: Arc::new(Mutex::new(None)),
}
}
pub fn signal_cpu_complete(&self) {
let mut frame = self.frame.lock().unwrap();
*frame += 1;
}
pub fn signal_gpu_complete(&self, frame_value: u64) {
let mut fence = self.gpu_fence.lock().unwrap();
*fence = Some(GpuFence {
value: frame_value,
signaled: true,
});
}
pub fn wait_current_frame(&self) {
let frame = *self.frame.lock().unwrap();
let fence = self.gpu_fence.lock().unwrap();
if let Some(ref f) = *fence {
if f.value >= frame && f.signaled {
}
}
}
pub fn current_frame(&self) -> u64 {
*self.frame.lock().unwrap()
}
}
impl Default for CpuGpuBarrier {
fn default() -> Self {
Self::new()
}
}