From 241416cf8975f52a047b020f9149dd4d031c6d5a Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Mon, 4 Mar 2019 16:48:59 -0500 Subject: [PATCH] better single fences, support dummy submissions --- libportability-gfx/src/impls.rs | 51 ++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/libportability-gfx/src/impls.rs b/libportability-gfx/src/impls.rs index 2f8fd83..10792d0 100644 --- a/libportability-gfx/src/impls.rs +++ b/libportability-gfx/src/impls.rs @@ -1094,6 +1094,23 @@ pub extern "C" fn gfxQueueSubmit( }; unsafe { queue.submit(submission, fence); } } + + // sometimes, all you need is a fence... + if submits.is_empty() { + use std::iter::empty; + let submission = hal::queue::Submission { + command_buffers: empty(), + wait_semaphores: empty(), + signal_semaphores: empty(), + }; + unsafe { + queue.submit::( + submission, + fence.as_ref(), + ) + }; + } + VkResult::VK_SUCCESS } #[inline] @@ -1392,21 +1409,29 @@ pub extern "C" fn gfxWaitForFences( waitAll: VkBool32, timeout: u64, ) -> VkResult { - let fence_slice = unsafe { - slice::from_raw_parts(pFences, fenceCount as _) - }; - let fences = fence_slice - .into_iter() - .map(|fence| &**fence); - - let wait_for = match waitAll { - VK_FALSE => WaitFor::Any, - _ => WaitFor::All, + let result = match fenceCount { + 0 => Ok(true), + 1 => unsafe { + gpu.device.wait_for_fence(&**pFences, timeout) + }, + _ => { + let fence_slice = unsafe { + slice::from_raw_parts(pFences, fenceCount as _) + }; + let fences = fence_slice + .into_iter() + .map(|fence| &**fence); + let wait_for = match waitAll { + VK_FALSE => WaitFor::Any, + _ => WaitFor::All, + }; + unsafe { + gpu.device.wait_for_fences(fences, wait_for, timeout) + } + } }; - match unsafe { - gpu.device.wait_for_fences(fences, wait_for, timeout as _) - } { + match result { Ok(true) => VkResult::VK_SUCCESS, Ok(false) => VkResult::VK_TIMEOUT, Err(hal::device::OomOrDeviceLost::OutOfMemory(oom)) => map_oom(oom),