Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add is_signaled to FenceSignalFuture #1910

Merged
merged 1 commit into from
Jun 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions vulkano/src/command_buffer/submit/queue_submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,14 @@ mod tests {
let (device, queue) = gfx_dev_and_queue!();

let fence = Fence::new(device.clone(), Default::default()).unwrap();
assert!(!fence.ready().unwrap());
assert!(!fence.is_signaled().unwrap());

let mut builder = SubmitCommandBufferBuilder::new();
builder.set_fence_signal(&fence);

builder.submit(&queue).unwrap();
fence.wait(Some(Duration::from_secs(5))).unwrap();
assert!(fence.ready().unwrap());
assert!(fence.is_signaled().unwrap());
}
}

Expand Down
28 changes: 14 additions & 14 deletions vulkano/src/sync/fence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct Fence {
// If true, we know that the `Fence` is signaled. If false, we don't know.
// This variable exists so that we don't need to call `vkGetFenceStatus` or `vkWaitForFences`
// multiple times.
signaled: AtomicBool,
is_signaled: AtomicBool,

// Indicates whether this fence was taken from the fence pool.
// If true, will be put back into fence pool on drop.
Expand Down Expand Up @@ -76,7 +76,7 @@ impl Fence {
Ok(Fence {
handle,
device,
signaled: AtomicBool::new(signaled),
is_signaled: AtomicBool::new(signaled),
must_put_in_pool: false,
})
}
Expand Down Expand Up @@ -104,7 +104,7 @@ impl Fence {
Fence {
handle,
device,
signaled: AtomicBool::new(false),
is_signaled: AtomicBool::new(false),
must_put_in_pool: true,
}
}
Expand All @@ -121,9 +121,9 @@ impl Fence {

/// Returns true if the fence is signaled.
#[inline]
pub fn ready(&self) -> Result<bool, OomError> {
pub fn is_signaled(&self) -> Result<bool, OomError> {
unsafe {
if self.signaled.load(Ordering::Relaxed) {
if self.is_signaled.load(Ordering::Relaxed) {
return Ok(true);
}

Expand All @@ -134,7 +134,7 @@ impl Fence {
))?;
match result {
Success::Success => {
self.signaled.store(true, Ordering::Relaxed);
self.is_signaled.store(true, Ordering::Relaxed);
Ok(true)
}
Success::NotReady => Ok(false),
Expand All @@ -150,7 +150,7 @@ impl Fence {
/// If you pass a duration of 0, then the function will return without blocking.
pub fn wait(&self, timeout: Option<Duration>) -> Result<(), FenceWaitError> {
unsafe {
if self.signaled.load(Ordering::Relaxed) {
if self.is_signaled.load(Ordering::Relaxed) {
return Ok(());
}

Expand All @@ -174,7 +174,7 @@ impl Fence {

match r {
Success::Success => {
self.signaled.store(true, Ordering::Relaxed);
self.is_signaled.store(true, Ordering::Relaxed);
Ok(())
}
Success::Timeout => Err(FenceWaitError::Timeout),
Expand Down Expand Up @@ -207,7 +207,7 @@ impl Fence {
),
};

if fence.signaled.load(Ordering::Relaxed) {
if fence.is_signaled.load(Ordering::Relaxed) {
None
} else {
Some(fence.handle)
Expand Down Expand Up @@ -258,7 +258,7 @@ impl Fence {
1,
&self.handle,
))?;
self.signaled.store(false, Ordering::Relaxed);
self.is_signaled.store(false, Ordering::Relaxed);
Ok(())
}
}
Expand Down Expand Up @@ -288,7 +288,7 @@ impl Fence {
),
};

fence.signaled.store(false, Ordering::Relaxed);
fence.is_signaled.store(false, Ordering::Relaxed);
fence.handle
})
.collect();
Expand Down Expand Up @@ -438,7 +438,7 @@ mod tests {
let (device, _) = gfx_dev_and_queue!();

let fence = Fence::new(device.clone(), Default::default()).unwrap();
assert!(!fence.ready().unwrap());
assert!(!fence.is_signaled().unwrap());
}

#[test]
Expand All @@ -453,7 +453,7 @@ mod tests {
},
)
.unwrap();
assert!(fence.ready().unwrap());
assert!(fence.is_signaled().unwrap());
}

#[test]
Expand Down Expand Up @@ -484,7 +484,7 @@ mod tests {
)
.unwrap();
fence.reset().unwrap();
assert!(!fence.ready().unwrap());
assert!(!fence.is_signaled().unwrap());
}

#[test]
Expand Down
15 changes: 14 additions & 1 deletion vulkano/src/sync/future/fence_signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
device::{Device, DeviceOwned, Queue},
image::{sys::UnsafeImage, ImageLayout},
sync::{AccessFlags, Fence, PipelineStages},
DeviceSize,
DeviceSize, OomError,
};
use parking_lot::{Mutex, MutexGuard};
use std::{mem::replace, ops::Range, sync::Arc, time::Duration};
Expand Down Expand Up @@ -120,6 +120,19 @@ impl<F> FenceSignalFuture<F>
where
F: GpuFuture,
{
/// Returns true if the fence is signaled by the GPU.
pub fn is_signaled(&self) -> Result<bool, OomError> {
let state = self.state.lock();

match &*state {
FenceSignalFutureState::Pending(_, fence)
| FenceSignalFutureState::PartiallyFlushed(_, fence)
| FenceSignalFutureState::Flushed(_, fence) => fence.is_signaled(),
FenceSignalFutureState::Cleaned => Ok(true),
FenceSignalFutureState::Poisoned => unreachable!(),
}
}

/// Blocks the current thread until the fence is signaled by the GPU. Performs a flush if
/// necessary.
///
Expand Down