From 2db11c607e24180264729dfa310ebf6a03aa5dfc Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Sat, 30 Jun 2018 23:20:31 -0400 Subject: [PATCH 1/2] Expose VK_KHR_maintenance1 --- libportability-gfx/src/impls.rs | 42 ++++++++++++++++----------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/libportability-gfx/src/impls.rs b/libportability-gfx/src/impls.rs index 1495ab6..e81578e 100644 --- a/libportability-gfx/src/impls.rs +++ b/libportability-gfx/src/impls.rs @@ -771,6 +771,7 @@ static INSTANCE_EXTENSION_NAME_VK_KHR_WIN32_SURFACE: &str = "VK_KHR_win32_surfac #[cfg(target_os="macos")] static INSTANCE_EXTENSION_NAME_VK_MACOS_SURFACE: &str = "VK_MVK_macos_surface"; static DEVICE_EXTENSION_NAME_VK_KHR_SWAPCHAIN: &str = "VK_KHR_swapchain"; +static DEVICE_EXTENSION_NAME_VK_KHR_MAINTENANCE1: &str = "VK_KHR_maintenance1"; lazy_static! { // TODO: Request from backend @@ -802,23 +803,13 @@ lazy_static! { }, ]; - extensions[0] - .extensionName[..VK_KHR_SURFACE_EXTENSION_NAME.len()] - .copy_from_slice(unsafe { - mem::transmute(VK_KHR_SURFACE_EXTENSION_NAME as &[u8]) - }); - #[cfg(target_os="windows")] - extensions[1] - .extensionName[..VK_KHR_WIN32_SURFACE_EXTENSION_NAME.len()] - .copy_from_slice(unsafe { - mem::transmute(VK_KHR_WIN32_SURFACE_EXTENSION_NAME as &[u8]) - }); - #[cfg(target_os = "macos")] - extensions[1] - .extensionName[..VK_MVK_MACOS_SURFACE_EXTENSION_NAME.len()] - .copy_from_slice(unsafe { - mem::transmute(VK_MVK_MACOS_SURFACE_EXTENSION_NAME as &[u8]) - }); + for (&name, extension) in INSTANCE_EXTENSION_NAMES.iter().zip(&mut extensions) { + extension + .extensionName[.. name.len()] + .copy_from_slice(unsafe { + mem::transmute(name.as_bytes()) + }); + } extensions.to_vec() }; @@ -826,6 +817,7 @@ lazy_static! { static ref DEVICE_EXTENSION_NAMES: Vec<&'static str> = { vec![ DEVICE_EXTENSION_NAME_VK_KHR_SWAPCHAIN, + DEVICE_EXTENSION_NAME_VK_KHR_MAINTENANCE1, ] }; @@ -835,13 +827,19 @@ lazy_static! { extensionName: [0; 256], // VK_KHR_SWAPCHAIN_EXTENSION_NAME specVersion: VK_KHR_SWAPCHAIN_SPEC_VERSION, }, + VkExtensionProperties { + extensionName: [0; 256], // VK_KHR_MAINTENANCE1_EXTENSION_NAME + specVersion: VK_KHR_MAINTENANCE1_SPEC_VERSION, + }, ]; - extensions[0] - .extensionName[..VK_KHR_SWAPCHAIN_EXTENSION_NAME.len()] - .copy_from_slice(unsafe { - mem::transmute(VK_KHR_SWAPCHAIN_EXTENSION_NAME as &[u8]) - }); + for (&name, extension) in DEVICE_EXTENSION_NAMES.iter().zip(&mut extensions) { + extension + .extensionName[.. name.len()] + .copy_from_slice(unsafe { + mem::transmute(name.as_bytes()) + }); + } extensions.to_vec() }; From f8b35fba0fc7e324065e6c8473c417ac423e7064 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Mon, 2 Jul 2018 20:27:38 -0400 Subject: [PATCH 2/2] Revert changes if got an error during descriptor set allocation --- Cargo.lock | 11 ++++----- libportability-gfx/src/impls.rs | 44 +++++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 07dce68..84dd8fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -265,7 +265,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "gfx-backend-dx11" version = "0.1.0" -source = "git+https://github.com/gfx-rs/gfx#ee7ae15b09363580fd81b8538e53890231e46bf3" +source = "git+https://github.com/gfx-rs/gfx#da53237ac20aa6ca823ca743f555f859808c6486" dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "derivative 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -281,7 +281,7 @@ dependencies = [ [[package]] name = "gfx-backend-dx12" version = "0.1.0" -source = "git+https://github.com/gfx-rs/gfx#ee7ae15b09363580fd81b8538e53890231e46bf3" +source = "git+https://github.com/gfx-rs/gfx#da53237ac20aa6ca823ca743f555f859808c6486" dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "derivative 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -297,14 +297,13 @@ dependencies = [ [[package]] name = "gfx-backend-metal" version = "0.1.0" -source = "git+https://github.com/gfx-rs/gfx#ee7ae15b09363580fd81b8538e53890231e46bf3" +source = "git+https://github.com/gfx-rs/gfx#da53237ac20aa6ca823ca743f555f859808c6486" dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "cocoa 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "core-graphics 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", - "derivative 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -318,7 +317,7 @@ dependencies = [ [[package]] name = "gfx-backend-vulkan" version = "0.1.0" -source = "git+https://github.com/gfx-rs/gfx#ee7ae15b09363580fd81b8538e53890231e46bf3" +source = "git+https://github.com/gfx-rs/gfx#da53237ac20aa6ca823ca743f555f859808c6486" dependencies = [ "ash 0.24.3 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -336,7 +335,7 @@ dependencies = [ [[package]] name = "gfx-hal" version = "0.1.0" -source = "git+https://github.com/gfx-rs/gfx#ee7ae15b09363580fd81b8538e53890231e46bf3" +source = "git+https://github.com/gfx-rs/gfx#da53237ac20aa6ca823ca743f555f859808c6486" dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/libportability-gfx/src/impls.rs b/libportability-gfx/src/impls.rs index e81578e..d5dca1a 100644 --- a/libportability-gfx/src/impls.rs +++ b/libportability-gfx/src/impls.rs @@ -956,7 +956,7 @@ pub extern "C" fn gfxQueueSubmit( let stages = slice::from_raw_parts(submission.pWaitDstStageMask, submission.waitSemaphoreCount as _); stages.into_iter() - .zip(semaphores.into_iter()) + .zip(semaphores) .map(|(stage, semaphore)| (&**semaphore, conv::map_pipeline_stage_flags(*stage))) .collect::>() }; @@ -2415,23 +2415,41 @@ pub extern "C" fn gfxAllocateDescriptorSets( let sets = unsafe { slice::from_raw_parts_mut(pDescriptorSets, info.descriptorSetCount as _) }; - for (set, raw_set) in sets.iter_mut().zip(descriptor_sets.into_iter()) { - *set = match raw_set { - Ok(set) => Handle::new(set), - Err(e) => return match e { - pso::AllocationError::OutOfHostMemory => VkResult::VK_ERROR_OUT_OF_HOST_MEMORY, - pso::AllocationError::OutOfDeviceMemory => VkResult::VK_ERROR_OUT_OF_DEVICE_MEMORY, - pso::AllocationError::OutOfPoolMemory => VkResult::VK_ERROR_OUT_OF_POOL_MEMORY_KHR, - pso::AllocationError::IncompatibleLayout => VkResult::VK_ERROR_DEVICE_LOST, - pso::AllocationError::FragmentedPool => VkResult::VK_ERROR_FRAGMENTED_POOL, - }, + let mut result = VkResult::VK_SUCCESS; + assert_eq!(descriptor_sets.len(), info.descriptorSetCount as usize); + + for (i, raw_set) in descriptor_sets.into_iter().enumerate() { + match raw_set { + Ok(set) => { + sets[i] = Handle::new(set); + } + Err(e) => { + // revert all the changes! + for set in sets[..i].iter_mut() { + let _ = set.unbox(); + } + for set in sets.iter_mut() { + *set = Handle::null(); + } + result = match e { + pso::AllocationError::OutOfHostMemory => VkResult::VK_ERROR_OUT_OF_HOST_MEMORY, + pso::AllocationError::OutOfDeviceMemory => VkResult::VK_ERROR_OUT_OF_DEVICE_MEMORY, + pso::AllocationError::OutOfPoolMemory => VkResult::VK_ERROR_OUT_OF_POOL_MEMORY_KHR, + pso::AllocationError::IncompatibleLayout => VkResult::VK_ERROR_DEVICE_LOST, + pso::AllocationError::FragmentedPool => VkResult::VK_ERROR_FRAGMENTED_POOL, + }; + break; + } }; + } + + if result == VkResult::VK_SUCCESS { if let Some(ref mut local_sets) = pool.sets { - local_sets.push(*set); + local_sets.extend_from_slice(sets); } } - VkResult::VK_SUCCESS + result } #[inline] pub extern "C" fn gfxFreeDescriptorSets(