mirror of
https://github.com/italicsjenga/portability.git
synced 2024-11-22 15:01:31 +11:00
Debug Handle tracker
This commit is contained in:
parent
cdaaf5c60a
commit
9c1c1b7851
|
@ -52,3 +52,4 @@ script:
|
||||||
- if [[ $TRAVIS_RUST_VERSION == "nightly" && $TRAVIS_BRANCH == "staging" ]]; then exit; fi
|
- if [[ $TRAVIS_RUST_VERSION == "nightly" && $TRAVIS_BRANCH == "staging" ]]; then exit; fi
|
||||||
- export PATH=$PATH:$HOME/deps/bin
|
- export PATH=$PATH:$HOME/deps/bin
|
||||||
- make
|
- make
|
||||||
|
- if [[ $TRAVIS_RUST_VERSION == "nightly" ]]; then make debug release; fi
|
||||||
|
|
17
Cargo.lock
generated
17
Cargo.lock
generated
|
@ -215,14 +215,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
[[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#1083ce9ab7f320a746668c06e79964f2514b745c"
|
source = "git+https://github.com/gfx-rs/gfx#0fe18fa91300a63267e6e19cb3b0f77ca734ea2d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"wio 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -231,7 +231,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#1083ce9ab7f320a746668c06e79964f2514b745c"
|
source = "git+https://github.com/gfx-rs/gfx#0fe18fa91300a63267e6e19cb3b0f77ca734ea2d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"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.14.0 (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)",
|
"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)",
|
"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)",
|
"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)",
|
"winit 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[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#1083ce9ab7f320a746668c06e79964f2514b745c"
|
source = "git+https://github.com/gfx-rs/gfx#0fe18fa91300a63267e6e19cb3b0f77ca734ea2d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ash 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -268,7 +269,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#1083ce9ab7f320a746668c06e79964f2514b745c"
|
source = "git+https://github.com/gfx-rs/gfx#0fe18fa91300a63267e6e19cb3b0f77ca734ea2d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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]]
|
[[package]]
|
||||||
name = "spirv_cross"
|
name = "spirv_cross"
|
||||||
version = "0.7.4"
|
version = "0.8.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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 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 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 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.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 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"
|
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
|
||||||
|
|
3
Makefile
3
Makefile
|
@ -45,6 +45,9 @@ LIBRARY_FAST=target/release/libportability.$(LIB_EXTENSION)
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
|
debug:
|
||||||
|
cargo build --manifest-path libportability/Cargo.toml --features "$(BACKEND) debug"
|
||||||
|
|
||||||
release: $(LIBRARY_FAST)
|
release: $(LIBRARY_FAST)
|
||||||
|
|
||||||
binding: $(BINDING)
|
binding: $(BINDING)
|
||||||
|
|
|
@ -13,7 +13,7 @@ name = "portability_gfx"
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
dispatch = []
|
dispatch = []
|
||||||
#default = ["env_logger"] # uncomment for debugging
|
nightly = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lazy_static = "1.0"
|
lazy_static = "1.0"
|
||||||
|
|
|
@ -1,13 +1,38 @@
|
||||||
use VK_NULL_HANDLE;
|
use VK_NULL_HANDLE;
|
||||||
use std::{borrow, cmp, fmt, ops};
|
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)]
|
#[repr(C)]
|
||||||
pub struct Handle<T>(*mut T);
|
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 {
|
pub fn new(value: T) -> Self {
|
||||||
let ptr = Box::into_raw(Box::new(value));
|
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)
|
Handle(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +44,10 @@ impl<T> Handle<T> {
|
||||||
if self.0 == VK_NULL_HANDLE as *mut T {
|
if self.0 == VK_NULL_HANDLE as *mut T {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
|
{
|
||||||
|
REGISTRY.lock().unwrap().remove(&(self.0 as _)).unwrap();
|
||||||
|
}
|
||||||
Some(*unsafe { Box::from_raw(self.0) })
|
Some(*unsafe { Box::from_raw(self.0) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,10 @@ pub extern "C" fn gfxDestroyInstance(
|
||||||
instance: VkInstance,
|
instance: VkInstance,
|
||||||
_pAllocator: *const VkAllocationCallbacks,
|
_pAllocator: *const VkAllocationCallbacks,
|
||||||
) {
|
) {
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
|
{
|
||||||
|
Handle::report_leaks();
|
||||||
|
}
|
||||||
for adapter in instance.unbox().unwrap().adapters {
|
for adapter in instance.unbox().unwrap().adapters {
|
||||||
let _ = adapter.unbox();
|
let _ = adapter.unbox();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
#![allow(non_upper_case_globals)]
|
#![allow(non_upper_case_globals)]
|
||||||
#![allow(improper_ctypes)] //TEMP: buggy Rustc FFI analysis
|
#![allow(improper_ctypes)] //TEMP: buggy Rustc FFI analysis
|
||||||
|
#![cfg_attr(feature = "nightly", feature(core_intrinsics))]
|
||||||
|
|
||||||
extern crate gfx_hal as hal;
|
extern crate gfx_hal as hal;
|
||||||
#[cfg(feature = "gfx-backend-dx12")]
|
#[cfg(feature = "gfx-backend-dx12")]
|
||||||
|
|
|
@ -13,6 +13,7 @@ crate-type = ["cdylib"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
|
debug = ["portability-gfx/env_logger", "portability-gfx/nightly"]
|
||||||
dx12 = ["portability-gfx/gfx-backend-dx12"]
|
dx12 = ["portability-gfx/gfx-backend-dx12"]
|
||||||
metal = ["portability-gfx/gfx-backend-metal"]
|
metal = ["portability-gfx/gfx-backend-metal"]
|
||||||
vulkan = ["portability-gfx/gfx-backend-vulkan"]
|
vulkan = ["portability-gfx/gfx-backend-vulkan"]
|
||||||
|
|
Loading…
Reference in a new issue