optional OomError for Event, Fence, Semaphore

fixed calls to changed functions
This commit is contained in:
Georg Echterling 2016-04-14 18:57:18 +02:00
parent 39b18ab765
commit 010a4a7174
6 changed files with 103 additions and 20 deletions

View File

@ -1694,7 +1694,9 @@ pub fn submit(me: &InnerCommandBuffer, me_arc: Arc<KeepAlive>,
assert_eq!(queue.device().internal_object(), me.pool.device().internal_object());
assert_eq!(queue.family().id(), me.pool.queue_family().id());
let fence = try!(Fence::new(queue.device()));
// TODO: check if this change is okay (maybe the Arc can be omitted?) - Mixthos
//let fence = try!(Fence::new(queue.device()));
let fence = Arc::new(try!(Fence::raw(queue.device())));
let mut keep_alive_semaphores = SmallVec::<[_; 8]>::new();
let mut post_semaphores_ids = SmallVec::<[_; 8]>::new();
@ -1706,7 +1708,9 @@ pub fn submit(me: &InnerCommandBuffer, me_arc: Arc<KeepAlive>,
// TODO: for now that's not true ^ as semaphores are only used once then destroyed ;
// waiting on https://github.com/KhronosGroup/Vulkan-Docs/issues/155
{
let signalled = try!(Semaphore::new(queue.device()));
// TODO: check if this change is okay (maybe the Arc can be omitted?) - Mixthos
//let signalled = try!(Semaphore::new(queue.device()));
let signalled = Arc::new(try!(Semaphore::raw(queue.device())));
let wait = unsafe { queue.dedicated_semaphore(signalled.clone()) };
if let Some(wait) = wait {
pre_semaphores_ids.push(wait.internal_object());
@ -1723,7 +1727,9 @@ pub fn submit(me: &InnerCommandBuffer, me_arc: Arc<KeepAlive>,
let semaphores_to_signal = {
let mut list = SmallVec::new();
for _ in 0 .. queue_transitions_hint {
let sem = try!(Semaphore::new(queue.device()));
// TODO: check if this change is okay (maybe the Arc can be omitted?) - Mixthos
//let sem = try!(Semaphore::new(queue.device()));
let sem = Arc::new(try!(Semaphore::raw(queue.device())));
post_semaphores_ids.push(sem.internal_object());
keep_alive_semaphores.push(sem.clone());
list.push(sem);
@ -1861,7 +1867,8 @@ pub fn submit(me: &InnerCommandBuffer, me_arc: Arc<KeepAlive>,
let mut infos = SmallVec::<[_; 3]>::new();
if !before_command_buffers.is_empty() {
let semaphore = Semaphore::new(queue.device()).unwrap();
// TODO: Use try!()?
let semaphore = Semaphore::new(queue.device());
let semaphore_id = semaphore.internal_object();
pre_semaphores_stages.push(vk::PIPELINE_STAGE_TOP_OF_PIPE_BIT); // TODO:
pre_semaphores_ids.push(semaphore.internal_object());
@ -1881,7 +1888,8 @@ pub fn submit(me: &InnerCommandBuffer, me_arc: Arc<KeepAlive>,
}
let after_semaphore = if !after_command_buffers.is_empty() {
let semaphore = Semaphore::new(queue.device()).unwrap();
// TODO: Use try!()?
let semaphore = Semaphore::new(queue.device());
let semaphore_id = semaphore.internal_object();
post_semaphores_ids.push(semaphore.internal_object());
keep_alive_semaphores.push(semaphore);

View File

@ -124,7 +124,8 @@ unsafe impl Image for SwapchainImage {
let dependency = mem::replace(&mut guarded.latest_submission, Some(Arc::downgrade(submission)));
let dependency = dependency.and_then(|d| d.upgrade());
let signal = Semaphore::new(submission.queue().device()).unwrap();
// TODO: use try!()?
let signal = Semaphore::new(submission.queue().device());
let wait = self.swapchain.image_semaphore(self.id, signal.clone()).expect("Try to render to a swapchain image that was not acquired first");
if guarded.present_layout {

View File

@ -180,7 +180,9 @@ impl Swapchain {
}
for _ in 0 .. images.len() + 1 {
swapchain.semaphores_pool.push(try!(Semaphore::new(device)));
// TODO: check if this change is okay (maybe the Arc can be omitted?) - Mixthos
//swapchain.semaphores_pool.push(try!(Semaphore::new(device)));
swapchain.semaphores_pool.push(Arc::new(try!(Semaphore::raw(device))));
}
Ok((swapchain, images))

View File

@ -37,7 +37,7 @@ pub struct Event {
impl Event {
/// Builds a new event.
#[inline]
pub fn new(device: &Arc<Device>) -> Result<Arc<Event>, OomError> {
pub fn raw(device: &Arc<Device>) -> Result<Event, OomError> {
let vk = device.pointers();
let event = unsafe {
@ -54,10 +54,21 @@ impl Event {
output
};
Ok(Arc::new(Event {
Ok(Event {
device: device.clone(),
event: Mutex::new(event),
}))
})
}
/// Builds a new event.
///
/// # Panic
///
/// - Panicks if the device or host ran out of memory.
///
#[inline]
pub fn new(device: &Arc<Device>) -> Arc<Event> {
Arc::new(Event::raw(device).unwrap())
}
/// Returns true if the event is signaled.
@ -80,7 +91,7 @@ impl Event {
///
/// If a command buffer is waiting on this event, it is then unblocked.
#[inline]
pub fn set(&self) -> Result<(), OomError> {
pub fn set_raw(&self) -> Result<(), OomError> {
unsafe {
let vk = self.device.pointers();
let event = self.event.lock().unwrap();
@ -89,9 +100,22 @@ impl Event {
}
}
/// Changes the `Event` to the signaled state.
///
/// If a command buffer is waiting on this event, it is then unblocked.
///
/// # Panic
///
/// - Panicks if the device or host ran out of memory.
///
#[inline]
pub fn set(&self) {
self.set_raw().unwrap();
}
/// Changes the `Event` to the unsignaled state.
#[inline]
pub fn reset(&self) -> Result<(), OomError> {
pub fn reset_raw(&self) -> Result<(), OomError> {
unsafe {
let vk = self.device.pointers();
let event = self.event.lock().unwrap();
@ -99,6 +123,17 @@ impl Event {
Ok(())
}
}
/// Changes the `Event` to the unsignaled state.
///
/// # Panic
///
/// - Panicks if the device or host ran out of memory.
///
#[inline]
pub fn reset(&self) {
self.reset_raw().unwrap();
}
}
unsafe impl SynchronizedVulkanObject for Event {

View File

@ -48,21 +48,47 @@ pub struct Fence<D = Arc<Device>> where D: Deref<Target = Device> {
impl<D> Fence<D> where D: Deref<Target = Device> {
/// Builds a new fence.
#[inline]
pub fn new(device: &D) -> Result<Arc<Fence<D>>, OomError>
pub fn raw(device: &D) -> Result<Fence<D>, OomError>
where D: Clone
{
Fence::new_impl(device, false)
}
/// Builds a new fence.
///
/// # Panic
///
/// - Panicks if the device or host ran out of memory.
///
#[inline]
pub fn new(device: &D) -> Arc<Fence<D>>
where D: Clone
{
Arc::new(Fence::raw(device).unwrap())
}
/// Builds a new fence already in the "signaled" state.
#[inline]
pub fn signaled(device: &D) -> Result<Arc<Fence<D>>, OomError>
pub fn signaled_raw(device: &D) -> Result<Fence<D>, OomError>
where D: Clone
{
Fence::new_impl(device, true)
}
fn new_impl(device_ptr: &D, signaled: bool) -> Result<Arc<Fence<D>>, OomError>
/// Builds a new fence already in the "signaled" state.
///
/// # Panic
///
/// - Panicks if the device or host ran out of memory.
///
#[inline]
pub fn signaled(device: &D) -> Arc<Fence<D>>
where D: Clone
{
Arc::new(Fence::signaled_raw(device).unwrap())
}
fn new_impl(device_ptr: &D, signaled: bool) -> Result<Fence<D>, OomError>
where D: Clone
{
let device: &Device = &*device_ptr;
@ -81,12 +107,12 @@ impl<D> Fence<D> where D: Deref<Target = Device> {
output
};
Ok(Arc::new(Fence {
Ok(Fence {
fence: fence,
device: device_ptr.clone(),
device_raw: device.internal_object(),
signaled: AtomicBool::new(signaled),
}))
})
}
/// Returns true if the fence is signaled.

View File

@ -31,7 +31,7 @@ pub struct Semaphore {
impl Semaphore {
/// Builds a new semaphore.
#[inline]
pub fn new(device: &Arc<Device>) -> Result<Arc<Semaphore>, OomError> {
pub fn raw(device: &Arc<Device>) -> Result<Semaphore, OomError> {
let vk = device.pointers();
let semaphore = unsafe {
@ -48,10 +48,21 @@ impl Semaphore {
output
};
Ok(Arc::new(Semaphore {
Ok(Semaphore {
device: device.clone(),
semaphore: semaphore,
}))
})
}
/// Builds a new semaphore.
///
/// # Panic
///
/// - Panicks if the device or host ran out of memory.
///
#[inline]
pub fn new(device: &Arc<Device>) -> Arc<Semaphore> {
Arc::new(Semaphore::raw(device).unwrap())
}
}