Debug Handle tracker

This commit is contained in:
Dzmitry Malyshau 2018-04-25 12:00:50 -04:00
parent cdaaf5c60a
commit 9c1c1b7851
8 changed files with 50 additions and 10 deletions

View file

@ -52,3 +52,4 @@ script:
- if [[ $TRAVIS_RUST_VERSION == "nightly" && $TRAVIS_BRANCH == "staging" ]]; then exit; fi
- export PATH=$PATH:$HOME/deps/bin
- make
- if [[ $TRAVIS_RUST_VERSION == "nightly" ]]; then make debug release; fi

17
Cargo.lock generated
View file

@ -215,14 +215,14 @@ 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#1083ce9ab7f320a746668c06e79964f2514b745c"
source = "git+https://github.com/gfx-rs/gfx#0fe18fa91300a63267e6e19cb3b0f77ca734ea2d"
dependencies = [
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"derivative 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"spirv_cross 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"spirv_cross 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"winit 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"wio 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -231,7 +231,7 @@ dependencies = [
[[package]]
name = "gfx-backend-metal"
version = "0.1.0"
source = "git+https://github.com/gfx-rs/gfx#1083ce9ab7f320a746668c06e79964f2514b745c"
source = "git+https://github.com/gfx-rs/gfx#0fe18fa91300a63267e6e19cb3b0f77ca734ea2d"
dependencies = [
"block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"cocoa 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -243,14 +243,15 @@ dependencies = [
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"metal-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"objc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"spirv_cross 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"spirv_cross 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winit 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "gfx-backend-vulkan"
version = "0.1.0"
source = "git+https://github.com/gfx-rs/gfx#1083ce9ab7f320a746668c06e79964f2514b745c"
source = "git+https://github.com/gfx-rs/gfx#0fe18fa91300a63267e6e19cb3b0f77ca734ea2d"
dependencies = [
"ash 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -268,7 +269,7 @@ dependencies = [
[[package]]
name = "gfx-hal"
version = "0.1.0"
source = "git+https://github.com/gfx-rs/gfx#1083ce9ab7f320a746668c06e79964f2514b745c"
source = "git+https://github.com/gfx-rs/gfx#0fe18fa91300a63267e6e19cb3b0f77ca734ea2d"
dependencies = [
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -566,7 +567,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "spirv_cross"
version = "0.7.4"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
@ -901,7 +902,7 @@ dependencies = [
"checksum rustc-demangle 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11fb43a206a04116ffd7cfcf9bcb941f8eb6cc7ff667272246b0a1c74259a3cb"
"checksum shared_library 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8254bf098ce4d8d7cc7cc6de438c5488adc5297e5b7ffef88816c0a91bd289c1"
"checksum smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44db0ecb22921ef790d17ae13a3f6d15784183ff5f2a01aa32098c7498d2b4b9"
"checksum spirv_cross 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e0a28a50f7633f82624147f7c9524fe31002fb7e24e897272eb244c61ef74178"
"checksum spirv_cross 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "794a3850a6d16be4a4ea1536ff0f416697a95598e1fe7d926537ac78dc10750c"
"checksum syn 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)" = "58fd09df59565db3399efbba34ba8a2fec1307511ebd245d0061ff9d42691673"
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"

View file

@ -45,6 +45,9 @@ LIBRARY_FAST=target/release/libportability.$(LIB_EXTENSION)
all: $(TARGET)
debug:
cargo build --manifest-path libportability/Cargo.toml --features "$(BACKEND) debug"
release: $(LIBRARY_FAST)
binding: $(BINDING)

View file

@ -13,7 +13,7 @@ name = "portability_gfx"
[features]
default = []
dispatch = []
#default = ["env_logger"] # uncomment for debugging
nightly = []
[dependencies]
lazy_static = "1.0"

View file

@ -1,13 +1,38 @@
use VK_NULL_HANDLE;
use std::{borrow, cmp, fmt, ops};
#[cfg(feature = "nightly")]
use std::collections::HashMap;
#[cfg(feature = "nightly")]
use std::sync::{Arc, Mutex};
#[cfg(feature = "nightly")]
lazy_static! {
static ref REGISTRY: Arc<Mutex<HashMap<usize, &'static str>>> = Arc::new(Mutex::new(HashMap::new()));
}
#[repr(C)]
pub struct Handle<T>(*mut T);
impl<T> Handle<T> {
#[cfg(feature = "nightly")]
impl Handle<()> {
pub fn report_leaks() {
println!("Leaked handles:");
let mut map = REGISTRY.lock().unwrap();
for (_, type_id) in map.drain() {
println!("\t{:?}", type_id);
}
}
}
impl<T: 'static> Handle<T> {
pub fn new(value: T) -> Self {
let ptr = Box::into_raw(Box::new(value));
#[cfg(feature = "nightly")]
{
use std::intrinsics::type_name;
let name = unsafe { type_name::<T>() };
REGISTRY.lock().unwrap().insert(ptr as _, name);
}
Handle(ptr)
}
@ -19,6 +44,10 @@ impl<T> Handle<T> {
if self.0 == VK_NULL_HANDLE as *mut T {
None
} else {
#[cfg(feature = "nightly")]
{
REGISTRY.lock().unwrap().remove(&(self.0 as _)).unwrap();
}
Some(*unsafe { Box::from_raw(self.0) })
}
}

View file

@ -60,6 +60,10 @@ pub extern "C" fn gfxDestroyInstance(
instance: VkInstance,
_pAllocator: *const VkAllocationCallbacks,
) {
#[cfg(feature = "nightly")]
{
Handle::report_leaks();
}
for adapter in instance.unbox().unwrap().adapters {
let _ = adapter.unbox();
}

View file

@ -2,6 +2,7 @@
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
#![allow(improper_ctypes)] //TEMP: buggy Rustc FFI analysis
#![cfg_attr(feature = "nightly", feature(core_intrinsics))]
extern crate gfx_hal as hal;
#[cfg(feature = "gfx-backend-dx12")]

View file

@ -13,6 +13,7 @@ crate-type = ["cdylib"]
[features]
default = []
debug = ["portability-gfx/env_logger", "portability-gfx/nightly"]
dx12 = ["portability-gfx/gfx-backend-dx12"]
metal = ["portability-gfx/gfx-backend-metal"]
vulkan = ["portability-gfx/gfx-backend-vulkan"]