Fix descriptor set leak

This commit is contained in:
Dzmitry Malyshau 2018-06-24 22:27:10 -04:00
parent efb6e9ad62
commit 1e3541c8a4
5 changed files with 49 additions and 26 deletions

10
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#f2f7c5da11bceba534d6c6e7ed831286b0fc3f07" source = "git+https://github.com/gfx-rs/gfx#4306768fd37b94277dcccaeb6fd128a693068e98"
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#f2f7c5da11bceba534d6c6e7ed831286b0fc3f07" source = "git+https://github.com/gfx-rs/gfx#4306768fd37b94277dcccaeb6fd128a693068e98"
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,7 +297,7 @@ 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#f2f7c5da11bceba534d6c6e7ed831286b0fc3f07" source = "git+https://github.com/gfx-rs/gfx#4306768fd37b94277dcccaeb6fd128a693068e98"
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)",
@ -320,7 +320,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#f2f7c5da11bceba534d6c6e7ed831286b0fc3f07" source = "git+https://github.com/gfx-rs/gfx#4306768fd37b94277dcccaeb6fd128a693068e98"
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)",
@ -338,7 +338,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#f2f7c5da11bceba534d6c6e7ed831286b0fc3f07" source = "git+https://github.com/gfx-rs/gfx#4306768fd37b94277dcccaeb6fd128a693068e98"
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

@ -12,6 +12,7 @@ DEQP_DIR=$(CTS_DIR)/build/external/vulkancts/modules/vulkan/
DEQP=cd $(DEQP_DIR) && RUST_LOG=debug LD_LIBRARY_PATH=$(FULL_LIBRARY_PATH) ./deqp-vk DEQP=cd $(DEQP_DIR) && RUST_LOG=debug LD_LIBRARY_PATH=$(FULL_LIBRARY_PATH) ./deqp-vk
DOTA_DIR=../dota2/bin/osx64 DOTA_DIR=../dota2/bin/osx64
DOTA_EXE=$(DOTA_DIR)/dota2.app/Contents/MacOS/dota2 DOTA_EXE=$(DOTA_DIR)/dota2.app/Contents/MacOS/dota2
DOTA_PARAMS=-vulkan_disable_occlusion_queries -vulkan_scene_system_job_cost 2
RUST_BACKTRACE:=1 RUST_BACKTRACE:=1
BACKEND:=gl BACKEND:=gl
@ -45,7 +46,7 @@ FULL_LIBRARY_PATH=$(CURDIR)/target/debug
LIBRARY=target/debug/libportability.$(LIB_EXTENSION) LIBRARY=target/debug/libportability.$(LIB_EXTENSION)
LIBRARY_FAST=target/release/libportability.$(LIB_EXTENSION) LIBRARY_FAST=target/release/libportability.$(LIB_EXTENSION)
.PHONY: all rebuild debug release debug-version release-version binding run cts clean cherry dota-debug dota-release .PHONY: all rebuild debug release version-debug version-release binding run cts clean cherry dota-debug dota-release
all: $(TARGET) all: $(TARGET)
@ -57,17 +58,17 @@ debug:
release: $(LIBRARY_FAST) release: $(LIBRARY_FAST)
debug-version: version-debug:
cargo rustc --manifest-path libportability/Cargo.toml --features $(BACKEND),portability-gfx/env_logger -- -Clink-arg="-current_version 1.0.0" -Clink-arg="-compatibility_version 1.0.0" cargo rustc --manifest-path libportability/Cargo.toml --features $(BACKEND),portability-gfx/env_logger -- -Clink-arg="-current_version 1.0.0" -Clink-arg="-compatibility_version 1.0.0"
release-version: version-release:
cargo rustc --release --manifest-path libportability/Cargo.toml --features $(BACKEND) -- -Clink-arg="-current_version 1.0.0" -Clink-arg="-compatibility_version 1.0.0" cargo rustc --release --manifest-path libportability/Cargo.toml --features $(BACKEND) -- -Clink-arg="-current_version 1.0.0" -Clink-arg="-compatibility_version 1.0.0"
dota-debug: debug-version dota-debug: version-debug $(DOTA_EXE)
DYLD_LIBRARY_PATH=`pwd`/target/debug:`pwd`/$(DOTA_DIR) $(DOTA_EXE) DYLD_LIBRARY_PATH=`pwd`/target/debug:`pwd`/$(DOTA_DIR) $(DOTA_EXE) $(DOTA_PARAMS)
dota-release: release-version dota-release: version-release $(DOTA_EXE)
DYLD_LIBRARY_PATH=`pwd`/target/release:`pwd`/$(DOTA_DIR) $(DOTA_EXE) DYLD_LIBRARY_PATH=`pwd`/target/release:`pwd`/$(DOTA_DIR) $(DOTA_EXE) $(DOTA_PARAMS)
binding: $(BINDING) binding: $(BINDING)

View file

@ -549,7 +549,7 @@ pub fn map_front_face(face: VkFrontFace) -> pso::FrontFace {
} }
} }
pub fn map_primitive_topology(topology: VkPrimitiveTopology, patch_size: PatchSize) -> Option<hal::Primitive> { pub fn map_primitive_topology(topology: VkPrimitiveTopology, patch_size: PatchSize) -> Option<Primitive> {
use super::VkPrimitiveTopology::*; use super::VkPrimitiveTopology::*;
Some(match topology { Some(match topology {

View file

@ -2360,9 +2360,6 @@ pub extern "C" fn gfxCreateDescriptorPool(
pDescriptorPool: *mut VkDescriptorPool, pDescriptorPool: *mut VkDescriptorPool,
) -> VkResult { ) -> VkResult {
let info = unsafe { &*pCreateInfo }; let info = unsafe { &*pCreateInfo };
if info.flags != 0 {
warn!("gfxCreateDescriptorPool flags are not supported: 0x{:x}", info.flags);
}
let pool_sizes = unsafe { let pool_sizes = unsafe {
slice::from_raw_parts(info.pPoolSizes, info.poolSizeCount as _) slice::from_raw_parts(info.pPoolSizes, info.poolSizeCount as _)
@ -2378,8 +2375,15 @@ pub extern "C" fn gfxCreateDescriptorPool(
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let pool = gpu.device let pool = super::DescriptorPool {
.create_descriptor_pool(info.maxSets as _, &ranges); raw: gpu.device
.create_descriptor_pool(info.maxSets as _, &ranges),
sets: if info.flags & VkDescriptorPoolCreateFlagBits::VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT as u32 != 0 {
None
} else {
Some(Vec::new())
},
};
unsafe { *pDescriptorPool = Handle::new(pool); } unsafe { *pDescriptorPool = Handle::new(pool); }
VkResult::VK_SUCCESS VkResult::VK_SUCCESS
@ -2391,7 +2395,12 @@ pub extern "C" fn gfxDestroyDescriptorPool(
_pAllocator: *const VkAllocationCallbacks, _pAllocator: *const VkAllocationCallbacks,
) { ) {
if let Some(pool) = descriptorPool.unbox() { if let Some(pool) = descriptorPool.unbox() {
gpu.device.destroy_descriptor_pool(pool); gpu.device.destroy_descriptor_pool(pool.raw);
if let Some(sets) = pool.sets {
for set in sets {
let _ = set.unbox();
}
}
} }
} }
#[inline] #[inline]
@ -2400,7 +2409,12 @@ pub extern "C" fn gfxResetDescriptorPool(
mut descriptorPool: VkDescriptorPool, mut descriptorPool: VkDescriptorPool,
_flags: VkDescriptorPoolResetFlags, _flags: VkDescriptorPoolResetFlags,
) -> VkResult { ) -> VkResult {
descriptorPool.reset(); descriptorPool.raw.reset();
if let Some(ref mut sets) = descriptorPool.sets {
for set in sets.drain(..) {
let _ = set.unbox();
}
}
VkResult::VK_SUCCESS VkResult::VK_SUCCESS
} }
#[inline] #[inline]
@ -2419,7 +2433,7 @@ pub extern "C" fn gfxAllocateDescriptorSets(
.iter() .iter()
.map(|layout| &**layout); .map(|layout| &**layout);
let descriptor_sets = pool.allocate_sets(layouts); let descriptor_sets = pool.raw.allocate_sets(layouts);
let sets = unsafe { let sets = unsafe {
slice::from_raw_parts_mut(pDescriptorSets, info.descriptorSetCount as _) slice::from_raw_parts_mut(pDescriptorSets, info.descriptorSetCount as _)
}; };
@ -2434,6 +2448,9 @@ pub extern "C" fn gfxAllocateDescriptorSets(
pso::AllocationError::FragmentedPool => VkResult::VK_ERROR_FRAGMENTED_POOL, pso::AllocationError::FragmentedPool => VkResult::VK_ERROR_FRAGMENTED_POOL,
}, },
}; };
if let Some(ref mut local_sets) = pool.sets {
local_sets.push(*set);
}
} }
VkResult::VK_SUCCESS VkResult::VK_SUCCESS
@ -2448,8 +2465,9 @@ pub extern "C" fn gfxFreeDescriptorSets(
let descriptor_sets = unsafe { let descriptor_sets = unsafe {
slice::from_raw_parts(pDescriptorSets, descriptorSetCount as _) slice::from_raw_parts(pDescriptorSets, descriptorSetCount as _)
}; };
assert!(descriptorPool.sets.is_none());
descriptorPool.free_sets( descriptorPool.raw.free_sets(
&descriptor_sets &descriptor_sets
.into_iter() .into_iter()
.filter_map(|set| set.unbox()) .filter_map(|set| set.unbox())
@ -3812,9 +3830,8 @@ pub extern "C" fn gfxGetPhysicalDeviceSurfacePresentModesKHR(
pPresentModeCount: *mut u32, pPresentModeCount: *mut u32,
pPresentModes: *mut VkPresentModeKHR, pPresentModes: *mut VkPresentModeKHR,
) -> VkResult { ) -> VkResult {
let present_modes = surface let (_, _, present_modes) = surface
.compatibility(&adapter.physical_device) .compatibility(&adapter.physical_device);
.2;
let num_present_modes = present_modes.len(); let num_present_modes = present_modes.len();

View file

@ -45,7 +45,7 @@ pub type VkCommandBuffer = DispatchHandle<<B as hal::Backend>::CommandBuffer>;
pub type VkDeviceMemory = Handle<<B as hal::Backend>::Memory>; pub type VkDeviceMemory = Handle<<B as hal::Backend>::Memory>;
pub type VkDescriptorSetLayout = Handle<<B as hal::Backend>::DescriptorSetLayout>; pub type VkDescriptorSetLayout = Handle<<B as hal::Backend>::DescriptorSetLayout>;
pub type VkPipelineLayout = Handle<<B as hal::Backend>::PipelineLayout>; pub type VkPipelineLayout = Handle<<B as hal::Backend>::PipelineLayout>;
pub type VkDescriptorPool = Handle<<B as hal::Backend>::DescriptorPool>; pub type VkDescriptorPool = Handle<DescriptorPool<B>>;
pub type VkDescriptorSet = Handle<<B as hal::Backend>::DescriptorSet>; pub type VkDescriptorSet = Handle<<B as hal::Backend>::DescriptorSet>;
pub type VkSampler = Handle<<B as hal::Backend>::Sampler>; pub type VkSampler = Handle<<B as hal::Backend>::Sampler>;
pub type VkBufferView = Handle<<B as hal::Backend>::BufferView>; pub type VkBufferView = Handle<<B as hal::Backend>::BufferView>;
@ -78,6 +78,11 @@ pub struct Gpu<B: hal::Backend> {
capturing: *mut (), capturing: *mut (),
} }
pub struct DescriptorPool<B: hal::Backend> {
raw: B::DescriptorPool,
sets: Option<Vec<VkDescriptorSet>>,
}
pub enum Pipeline<B: hal::Backend> { pub enum Pipeline<B: hal::Backend> {
Graphics(B::GraphicsPipeline), Graphics(B::GraphicsPipeline),
Compute(B::ComputePipeline), Compute(B::ComputePipeline),