From cfe1f11ad3c232c9b93075a5eb1f59a5e38b0108 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Wed, 11 Apr 2018 21:32:58 -0400 Subject: [PATCH] Update gfx-rs, Linux numbers, properly release device references --- README.md | 8 ++++---- libportability-gfx/src/impls.rs | 32 ++++++++++++++++++++++---------- libportability-gfx/src/lib.rs | 1 + 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index dfa8c56..ffd4506 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,10 @@ This is a prototype library implementing [Vulkan Portability Initiative](https:/ ## Vulkan CTS coverage | gfx-rs Backend | Total cases | Pass | Fail | Quality warning | Compatibility warning | Not supported | Resource error | Internal error | Timeout | Crash | -| -------------- | -- | -- | -- | - | - | - | - | - | - | - | -| *Vulkan* | 3742 | 1393 | 101 | 0 | 0 | 2248 | 0 | 0 | 0 | 0 | -| *DX12* | 3563 | 1243 | 73 | 0 | 0 | 2247 | 0 | 0 | 0 | 0 | -| *Metal* | 3710 | 1260 | 66 | 0 | 0 | 2384 | 0 | 0 | 0 | 0 | +| -------- | ---- | ---- | --- | -- | - | ---- | - | - | - | - | +| *Vulkan* | 3914 | 1516 | 120 | 30 | 0 | 2248 | 0 | 0 | 0 | 0 | +| *DX12* | 3563 | 1243 | 73 | 0 | 0 | 2247 | 0 | 0 | 0 | 0 | +| *Metal* | 3710 | 1260 | 66 | 0 | 0 | 2384 | 0 | 0 | 0 | 0 | Currently stopping with: > Unable to create Vulkan instance: VkError(ErrorIncompatibleDriver) diff --git a/libportability-gfx/src/impls.rs b/libportability-gfx/src/impls.rs index 1ef1cd6..c0c493d 100644 --- a/libportability-gfx/src/impls.rs +++ b/libportability-gfx/src/impls.rs @@ -548,8 +548,13 @@ pub extern "C" fn gfxCreateDevice( } #[inline] -pub extern "C" fn gfxDestroyDevice(device: VkDevice, _pAllocator: *const VkAllocationCallbacks) { - let _ = device.unwrap(); //TODO? +pub extern "C" fn gfxDestroyDevice(gpu: VkDevice, _pAllocator: *const VkAllocationCallbacks) { + // release all the owned command queues + for (_, family) in gpu.unwrap().queues { + for queue in family { + let _ = queue.unwrap(); + } + } } lazy_static! { @@ -1876,7 +1881,16 @@ pub extern "C" fn gfxAllocateDescriptorSets( slice::from_raw_parts_mut(pDescriptorSets, info.descriptorSetCount as _) }; for (set, raw_set) in sets.iter_mut().zip(descriptor_sets.into_iter()) { - *set = Handle::new(raw_set); + *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, + }, + }; } VkResult::VK_SUCCESS @@ -2304,17 +2318,15 @@ pub extern "C" fn gfxAllocateCommandBuffers( #[inline] pub extern "C" fn gfxFreeCommandBuffers( _gpu: VkDevice, - commandPool: VkCommandPool, + mut commandPool: VkCommandPool, commandBufferCount: u32, pCommandBuffers: *const VkCommandBuffer, ) { - // TODO: - /* - let buffer_slice = unsafe { slice::from_raw_parts(pCommandBuffers, commandBufferCount as _) }; - let buffers = buffer_slice.iter().map(|buffer| *buffer.unwrap()).collect(); - + let slice = unsafe { + slice::from_raw_parts(pCommandBuffers, commandBufferCount as _) + }; + let buffers = slice.iter().map(|buffer| *buffer.unwrap()).collect(); unsafe { commandPool.free(buffers) }; - */ } #[inline] diff --git a/libportability-gfx/src/lib.rs b/libportability-gfx/src/lib.rs index 5acbad7..5170b98 100644 --- a/libportability-gfx/src/lib.rs +++ b/libportability-gfx/src/lib.rs @@ -38,6 +38,7 @@ pub struct RawInstance { pub backend: back::Instance, pub adapters: Vec, } + pub type VkInstance = Handle; pub type VkDevice = DispatchHandle>; pub type VkQueue = DispatchHandle<::CommandQueue>;