From 6e0ce965bf20885db805be1a08d2e51800cc46bc Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 5 Jun 2018 12:57:17 -0400 Subject: [PATCH 1/2] Cleaner destruction of events and query pools --- Cargo.lock | 8 ++++---- Makefile | 2 +- libportability-gfx/src/conv.rs | 2 ++ libportability-gfx/src/impls.rs | 24 ++++++++++++++---------- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2a1abd3..c4a569c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -252,7 +252,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "gfx-backend-dx12" version = "0.1.0" -source = "git+https://github.com/gfx-rs/gfx#91ec6303fded63498b01e4a55e8ebe6768d3c2cc" +source = "git+https://github.com/gfx-rs/gfx#505e8057803d8cc0302b5fdcfe7ae807b8f3b8cf" 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)", @@ -268,7 +268,7 @@ dependencies = [ [[package]] name = "gfx-backend-metal" version = "0.1.0" -source = "git+https://github.com/gfx-rs/gfx#91ec6303fded63498b01e4a55e8ebe6768d3c2cc" +source = "git+https://github.com/gfx-rs/gfx#505e8057803d8cc0302b5fdcfe7ae807b8f3b8cf" 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)", @@ -290,7 +290,7 @@ dependencies = [ [[package]] name = "gfx-backend-vulkan" version = "0.1.0" -source = "git+https://github.com/gfx-rs/gfx#91ec6303fded63498b01e4a55e8ebe6768d3c2cc" +source = "git+https://github.com/gfx-rs/gfx#505e8057803d8cc0302b5fdcfe7ae807b8f3b8cf" 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)", @@ -308,7 +308,7 @@ dependencies = [ [[package]] name = "gfx-hal" version = "0.1.0" -source = "git+https://github.com/gfx-rs/gfx#91ec6303fded63498b01e4a55e8ebe6768d3c2cc" +source = "git+https://github.com/gfx-rs/gfx#505e8057803d8cc0302b5fdcfe7ae807b8f3b8cf" 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/Makefile b/Makefile index ab576ea..4352ab9 100644 --- a/Makefile +++ b/Makefile @@ -104,4 +104,4 @@ clean: cargo clean cherry: $(TARGET) - cd $(CHERRY_DIR) && RUST_LOG=warn LD_LIBRARY_PATH=$(FULL_LIBRARY_PATH) go run server.go + cd $(CHERRY_DIR) && rm -f Cherry.db && RUST_LOG=warn LD_LIBRARY_PATH=$(FULL_LIBRARY_PATH) go run server.go diff --git a/libportability-gfx/src/conv.rs b/libportability-gfx/src/conv.rs index d7b3b2a..b47a3b0 100644 --- a/libportability-gfx/src/conv.rs +++ b/libportability-gfx/src/conv.rs @@ -12,6 +12,8 @@ pub fn limits_from_hal(limits: Limits) -> VkPhysicalDeviceLimits { maxImageDimension2D: limits.max_texture_size as _, maxImageDimension3D: limits.max_texture_size as _, maxImageDimensionCube: limits.max_texture_size as _, + maxFramebufferWidth: limits.max_texture_size as _, //TODO + maxFramebufferHeight: limits.max_texture_size as _, //TODO maxTexelBufferElements: limits.max_texture_size as _, //TODO maxTessellationPatchSize: limits.max_patch_size as _, maxViewports: limits.max_viewports as _, diff --git a/libportability-gfx/src/impls.rs b/libportability-gfx/src/impls.rs index 3787a23..754f87b 100644 --- a/libportability-gfx/src/impls.rs +++ b/libportability-gfx/src/impls.rs @@ -10,9 +10,7 @@ use hal::command::RawCommandBuffer; use hal::queue::RawCommandQueue; use std::ffi::{CStr, CString}; -use std::mem; -#[cfg(feature = "renderdoc")] -use std::ptr; +use std::{mem, ptr}; #[cfg(feature = "renderdoc")] use std::os::raw::c_void; @@ -596,11 +594,12 @@ pub extern "C" fn gfxCreateDevice( #[inline] pub extern "C" fn gfxDestroyDevice(gpu: VkDevice, _pAllocator: *const VkAllocationCallbacks) { // release all the owned command queues - if let Some(mut d) = gpu.unbox() { + if let Some(d) = gpu.unbox() { #[cfg(feature = "renderdoc")] { use renderdoc::api::RenderDocV100; let device = gpu.capturing as *mut c_void; + let mut d = d; d.renderdoc.end_frame_capture(device as *mut _, ptr::null()); } @@ -1142,10 +1141,12 @@ pub extern "C" fn gfxCreateEvent( #[inline] pub extern "C" fn gfxDestroyEvent( _gpu: VkDevice, - _event: VkEvent, + event: VkEvent, _pAllocator: *const VkAllocationCallbacks, ) { - unimplemented!() + if event != ptr::null_mut() { + unimplemented!() + } } #[inline] pub extern "C" fn gfxGetEventStatus(_gpu: VkDevice, _event: VkEvent) -> VkResult { @@ -1172,10 +1173,12 @@ pub extern "C" fn gfxCreateQueryPool( #[inline] pub extern "C" fn gfxDestroyQueryPool( _gpu: VkDevice, - _queryPool: VkQueryPool, + queryPool: VkQueryPool, _pAllocator: *const VkAllocationCallbacks, ) { - unimplemented!() + if queryPool != ptr::null_mut() { + unimplemented!() + } } #[inline] pub extern "C" fn gfxGetQueryPoolResults( @@ -2540,9 +2543,10 @@ pub extern "C" fn gfxDestroyRenderPass( pub extern "C" fn gfxGetRenderAreaGranularity( _gpu: VkDevice, _renderPass: VkRenderPass, - _pGranularity: *mut VkExtent2D, + pGranularity: *mut VkExtent2D, ) { - unimplemented!() + let granularity = VkExtent2D { width: 1, height: 1 }; //TODO? + unsafe { *pGranularity = granularity }; } #[inline] From f89c417b8947c3350b020cdc1340e647cf206db4 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 5 Jun 2018 13:42:34 -0400 Subject: [PATCH 2/2] Compute PSO creation refactor --- libportability-gfx/src/impls.rs | 120 +++++++++++++++++--------------- 1 file changed, 62 insertions(+), 58 deletions(-) diff --git a/libportability-gfx/src/impls.rs b/libportability-gfx/src/impls.rs index 754f87b..8d454ba 100644 --- a/libportability-gfx/src/impls.rs +++ b/libportability-gfx/src/impls.rs @@ -594,16 +594,15 @@ pub extern "C" fn gfxCreateDevice( #[inline] pub extern "C" fn gfxDestroyDevice(gpu: VkDevice, _pAllocator: *const VkAllocationCallbacks) { // release all the owned command queues - if let Some(d) = gpu.unbox() { + if let Some(mut d) = gpu.unbox() { #[cfg(feature = "renderdoc")] { use renderdoc::api::RenderDocV100; let device = gpu.capturing as *mut c_void; - let mut d = d; d.renderdoc.end_frame_capture(device as *mut _, ptr::null()); } - for (_, family) in d.queues { + for (_, family) in d.queues.drain() { for queue in family { let _ = queue.unbox(); } @@ -1487,7 +1486,7 @@ pub extern "C" fn gfxCreateGraphicsPipelines( .pSpecializationInfo .as_ref() .map(conv::map_specialization_info) - .unwrap_or(vec![]) + .unwrap_or_default() }; shader_stages.push(( @@ -1866,69 +1865,74 @@ pub extern "C" fn gfxCreateComputePipelines( slice::from_raw_parts(pCreateInfos, createInfoCount as _) }; - let mut shader_stages = Vec::with_capacity(infos.len()); - // Collect all information which we will borrow later. Need to work around // the borrow checker here. // TODO: try to refactor it once we have a more generic API - for info in infos { - let name = unsafe { CStr::from_ptr(info.stage.pName).to_owned() }; - let specialization = unsafe { info.stage - .pSpecializationInfo - .as_ref() - .map(conv::map_specialization_info) - .unwrap_or(vec![]) - }; + let shader_stages = infos + .iter() + .map(|info| { + let name = unsafe { CStr::from_ptr(info.stage.pName).to_owned() }; + let specialization = unsafe { info.stage + .pSpecializationInfo + .as_ref() + .map(conv::map_specialization_info) + .unwrap_or_default() + }; - shader_stages.push(( - name.into_string().unwrap(), - specialization, - )); - } + ( + name.into_string().unwrap(), + specialization, + ) + }) + .collect::>(); - let descs = infos.into_iter().zip(&shader_stages).map(|(info, &(ref entry, ref specialization))| { - let shader = pso::EntryPoint { - entry, - module: &*info.stage.module, - specialization, - }; - let layout = &*info.layout; + let descs = infos + .into_iter() + .zip(&shader_stages) + .map(|(info, &(ref entry, ref specialization))| { + let shader = pso::EntryPoint { + entry, + module: &*info.stage.module, + specialization, + }; + let layout = &*info.layout; - let flags = { - let mut flags = pso::PipelineCreationFlags::empty(); + let flags = { + let mut flags = pso::PipelineCreationFlags::empty(); - if info.flags & VkPipelineCreateFlagBits::VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT as u32 != 0 { - flags |= pso::PipelineCreationFlags::DISABLE_OPTIMIZATION; - } - if info.flags & VkPipelineCreateFlagBits::VK_PIPELINE_CREATE_ALLOW_DERIVATIVES_BIT as u32 != 0 { - flags |= pso::PipelineCreationFlags::ALLOW_DERIVATIVES; - } - - flags - }; - - let parent = { - let is_derivative = info.flags & VkPipelineCreateFlagBits::VK_PIPELINE_CREATE_DERIVATIVE_BIT as u32 != 0; - - if let Some(base_pso) = info.basePipelineHandle.as_ref() { - match *base_pso { - Pipeline::Graphics(_) => panic!("Base pipeline handle must be a compute pipeline"), - Pipeline::Compute(ref pso) => pso::BasePipeline::Pipeline(pso), + if info.flags & VkPipelineCreateFlagBits::VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT as u32 != 0 { + flags |= pso::PipelineCreationFlags::DISABLE_OPTIMIZATION; + } + if info.flags & VkPipelineCreateFlagBits::VK_PIPELINE_CREATE_ALLOW_DERIVATIVES_BIT as u32 != 0 { + flags |= pso::PipelineCreationFlags::ALLOW_DERIVATIVES; } - } else if is_derivative && info.basePipelineIndex > 0 { - pso::BasePipeline::Index(info.basePipelineIndex as _) - } else { - pso::BasePipeline::None // TODO - } - }; - pso::ComputePipelineDesc { - shader, - layout, - flags, - parent, - } - }).collect::>(); + flags + }; + + let parent = { + let is_derivative = info.flags & VkPipelineCreateFlagBits::VK_PIPELINE_CREATE_DERIVATIVE_BIT as u32 != 0; + + if let Some(base_pso) = info.basePipelineHandle.as_ref() { + match *base_pso { + Pipeline::Graphics(_) => panic!("Base pipeline handle must be a compute pipeline"), + Pipeline::Compute(ref pso) => pso::BasePipeline::Pipeline(pso), + } + } else if is_derivative && info.basePipelineIndex > 0 { + pso::BasePipeline::Index(info.basePipelineIndex as _) + } else { + pso::BasePipeline::None // TODO + } + }; + + pso::ComputePipelineDesc { + shader, + layout, + flags, + parent, + } + }) + .collect::>(); let pipelines = gpu.device.create_compute_pipelines(&descs);