#![cfg_attr(not(feature = "Implements"), allow(dead_code))]
use vk::*;
#[cfg(feature = "Implements")] use VkHandle;
#[cfg(feature = "Implements")] use {VkResultHandler, VkResultBox};
pub struct Fence(pub VkFence, ::Device);
pub struct Semaphore(pub VkSemaphore, ::Device);
pub struct Event(pub VkEvent, ::Device);
#[cfg(feature = "Implements")] DeviceChildCommonDrop!{
for Fence[vkDestroyFence], Semaphore[vkDestroySemaphore], Event[vkDestroyEvent]
}
impl ::VkHandle for Fence { type Handle = VkFence; fn native_ptr(&self) -> VkFence { self.0 } }
impl ::VkHandle for Semaphore { type Handle = VkSemaphore; fn native_ptr(&self) -> VkSemaphore { self.0 } }
impl ::VkHandle for Event { type Handle = VkEvent; fn native_ptr(&self) -> VkEvent { self.0 } }
impl ::DeviceChild for Fence { fn device(&self) -> &::Device { &self.1 } }
impl ::DeviceChild for Semaphore { fn device(&self) -> &::Device { &self.1 } }
impl ::DeviceChild for Event { fn device(&self) -> &::Device { &self.1 } }
#[cfg(feature = "Implements")]
impl Fence
{
pub fn new(device: &::Device, signaled: bool) -> ::Result<Self>
{
let mut h = VK_NULL_HANDLE as _;
let flags = if signaled { ::vk::VK_FENCE_CREATE_SIGNALED_BIT } else { 0 };
unsafe { vkCreateFence(device.native_ptr(), &VkFenceCreateInfo { flags, .. Default::default() }, ::std::ptr::null(), &mut h) }
.into_result().map(|_| Fence(h, device.clone()))
}
}
#[cfg(feature = "Implements")]
impl Semaphore
{
pub fn new(device: &::Device) -> ::Result<Self>
{
let mut h = VK_NULL_HANDLE as _;
unsafe { vkCreateSemaphore(device.native_ptr(), &Default::default(), ::std::ptr::null(), &mut h) }
.into_result().map(|_| Semaphore(h, device.clone()))
}
}
#[cfg(feature = "Implements")]
impl Event
{
pub fn new(device: &::Device) -> ::Result<Self>
{
let mut h = VK_NULL_HANDLE as _;
unsafe { vkCreateEvent(device.native_ptr(), &Default::default(), ::std::ptr::null(), &mut h) }
.into_result().map(|_| Event(h, device.clone()))
}
}
#[cfg(feature = "Implements")]
impl Fence
{
pub fn wait_multiple(objects: &[&Self], wait_all: bool, timeout: Option<u64>) -> ::Result<bool>
{
let objects_ptr = objects.iter().map(|x| x.0).collect::<Vec<_>>();
let vr = unsafe { ::vk::vkWaitForFences(objects[0].1.native_ptr(), objects_ptr.len() as _, objects_ptr.as_ptr(), wait_all as _, timeout.unwrap_or(::std::u64::MAX)) };
match vr { ::vk::VK_SUCCESS => Ok(false), ::vk::VK_TIMEOUT => Ok(true), _ => Err(VkResultBox(vr)) }
}
pub fn wait_timeout(&self, timeout: u64) -> ::Result<bool>
{
let vr = unsafe { ::vk::vkWaitForFences(self.1.native_ptr(), 1, &self.0, false as _, timeout) };
match vr { ::vk::VK_SUCCESS => Ok(false), ::vk::VK_TIMEOUT => Ok(true), _ => Err(VkResultBox(vr)) }
}
pub fn reset_multiple(objects: &[&Self]) -> ::Result<()>
{
let objects_ptr = objects.iter().map(|x| x.0).collect::<Vec<_>>();
unsafe { ::vk::vkResetFences(objects[0].1.native_ptr(), objects_ptr.len() as _, objects_ptr.as_ptr()) }.into_result()
}
pub fn reset(&self) -> ::Result<()> { unsafe { ::vk::vkResetFences(self.1.native_ptr(), 1, &self.0) }.into_result() }
}
#[cfg(feature = "Implements")]
impl Event
{
pub fn set(&self) -> ::Result<()> { unsafe { ::vk::vkSetEvent(self.1.native_ptr(), self.0) }.into_result() }
pub fn reset(&self) -> ::Result<()> { unsafe { ::vk::vkResetEvent(self.1.native_ptr(), self.0) }.into_result() }
}
#[cfg(feature = "Implements")]
pub trait Status
{
fn status(&self) -> ::Result<bool>;
}
#[cfg(feature = "Implements")]
impl Status for Fence
{
fn status(&self) -> ::Result<bool>
{
let vr = unsafe { ::vk::vkGetFenceStatus(self.1.native_ptr(), self.0) };
match vr { ::vk::VK_SUCCESS => Ok(true), ::vk::VK_NOT_READY => Ok(false), _ => Err(VkResultBox(vr)) }
}
}
#[cfg(feature = "Implements")]
impl Status for Event
{
fn status(&self) -> ::Result<bool>
{
let vr = unsafe { ::vk::vkGetEventStatus(self.1.native_ptr(), self.0) };
match vr { ::vk::VK_EVENT_SET => Ok(true), ::vk::VK_EVENT_RESET => Ok(false), _ => Err(VkResultBox(vr)) }
}
}
#[cfg(feature = "Implements")]
impl ::Waitable for Fence
{
fn wait(&self) -> ::Result<()> { self.wait_timeout(::std::u64::MAX).map(|_| ()) }
}
unsafe impl Send for Fence {}
unsafe impl Sync for Fence {}