Revert changes if got an error during descriptor set allocation

This commit is contained in:
Dzmitry Malyshau 2018-07-02 20:27:38 -04:00
parent 2db11c607e
commit f8b35fba0f
2 changed files with 36 additions and 19 deletions

11
Cargo.lock generated
View file

@ -265,7 +265,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "gfx-backend-dx11" name = "gfx-backend-dx11"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/gfx-rs/gfx#ee7ae15b09363580fd81b8538e53890231e46bf3" source = "git+https://github.com/gfx-rs/gfx#da53237ac20aa6ca823ca743f555f859808c6486"
dependencies = [ dependencies = [
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "derivative 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -281,7 +281,7 @@ dependencies = [
[[package]] [[package]]
name = "gfx-backend-dx12" name = "gfx-backend-dx12"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/gfx-rs/gfx#ee7ae15b09363580fd81b8538e53890231e46bf3" source = "git+https://github.com/gfx-rs/gfx#da53237ac20aa6ca823ca743f555f859808c6486"
dependencies = [ dependencies = [
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "derivative 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -297,14 +297,13 @@ dependencies = [
[[package]] [[package]]
name = "gfx-backend-metal" name = "gfx-backend-metal"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/gfx-rs/gfx#ee7ae15b09363580fd81b8538e53890231e46bf3" source = "git+https://github.com/gfx-rs/gfx#da53237ac20aa6ca823ca743f555f859808c6486"
dependencies = [ dependencies = [
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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-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)", "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)", "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)", "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)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -318,7 +317,7 @@ dependencies = [
[[package]] [[package]]
name = "gfx-backend-vulkan" name = "gfx-backend-vulkan"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/gfx-rs/gfx#ee7ae15b09363580fd81b8538e53890231e46bf3" source = "git+https://github.com/gfx-rs/gfx#da53237ac20aa6ca823ca743f555f859808c6486"
dependencies = [ dependencies = [
"ash 0.24.3 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -336,7 +335,7 @@ dependencies = [
[[package]] [[package]]
name = "gfx-hal" name = "gfx-hal"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/gfx-rs/gfx#ee7ae15b09363580fd81b8538e53890231e46bf3" source = "git+https://github.com/gfx-rs/gfx#da53237ac20aa6ca823ca743f555f859808c6486"
dependencies = [ dependencies = [
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -956,7 +956,7 @@ pub extern "C" fn gfxQueueSubmit(
let stages = slice::from_raw_parts(submission.pWaitDstStageMask, submission.waitSemaphoreCount as _); let stages = slice::from_raw_parts(submission.pWaitDstStageMask, submission.waitSemaphoreCount as _);
stages.into_iter() stages.into_iter()
.zip(semaphores.into_iter()) .zip(semaphores)
.map(|(stage, semaphore)| (&**semaphore, conv::map_pipeline_stage_flags(*stage))) .map(|(stage, semaphore)| (&**semaphore, conv::map_pipeline_stage_flags(*stage)))
.collect::<Vec<_>>() .collect::<Vec<_>>()
}; };
@ -2415,23 +2415,41 @@ pub extern "C" fn gfxAllocateDescriptorSets(
let sets = unsafe { let sets = unsafe {
slice::from_raw_parts_mut(pDescriptorSets, info.descriptorSetCount as _) slice::from_raw_parts_mut(pDescriptorSets, info.descriptorSetCount as _)
}; };
for (set, raw_set) in sets.iter_mut().zip(descriptor_sets.into_iter()) { let mut result = VkResult::VK_SUCCESS;
*set = match raw_set { assert_eq!(descriptor_sets.len(), info.descriptorSetCount as usize);
Ok(set) => Handle::new(set),
Err(e) => return match e { for (i, raw_set) in descriptor_sets.into_iter().enumerate() {
pso::AllocationError::OutOfHostMemory => VkResult::VK_ERROR_OUT_OF_HOST_MEMORY, match raw_set {
pso::AllocationError::OutOfDeviceMemory => VkResult::VK_ERROR_OUT_OF_DEVICE_MEMORY, Ok(set) => {
pso::AllocationError::OutOfPoolMemory => VkResult::VK_ERROR_OUT_OF_POOL_MEMORY_KHR, sets[i] = Handle::new(set);
pso::AllocationError::IncompatibleLayout => VkResult::VK_ERROR_DEVICE_LOST, }
pso::AllocationError::FragmentedPool => VkResult::VK_ERROR_FRAGMENTED_POOL, 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 { if let Some(ref mut local_sets) = pool.sets {
local_sets.push(*set); local_sets.extend_from_slice(sets);
} }
} }
VkResult::VK_SUCCESS result
} }
#[inline] #[inline]
pub extern "C" fn gfxFreeDescriptorSets( pub extern "C" fn gfxFreeDescriptorSets(