87: Add support for renderdoc capturing (dx12 only) r=kvark a=msiglreith

Blocked on a new renderdoc-rs release (and merging gfx-rs PR).
Automatically creates a capture when enabling the `portability-gfx/renderdoc` feature. Works only if no swapchain is attached and dx12 only atm.
Primary use case are CTS tests.

Co-authored-by: msiglreith <m.siglreith@gmail.com>
This commit is contained in:
bors[bot] 2018-05-31 21:39:48 +00:00
commit 1af668650f
5 changed files with 93 additions and 7 deletions

55
Cargo.lock generated
View file

@ -252,7 +252,7 @@ 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#e791f711a8e27b22907cd62c91b0848cb6d561d7" source = "git+https://github.com/gfx-rs/gfx#85f76137ebf3de5b287559544209432277d66a66"
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)",
@ -268,7 +268,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#e791f711a8e27b22907cd62c91b0848cb6d561d7" source = "git+https://github.com/gfx-rs/gfx#85f76137ebf3de5b287559544209432277d66a66"
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)",
@ -289,7 +289,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#e791f711a8e27b22907cd62c91b0848cb6d561d7" source = "git+https://github.com/gfx-rs/gfx#85f76137ebf3de5b287559544209432277d66a66"
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)",
@ -307,7 +307,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#e791f711a8e27b22907cd62c91b0848cb6d561d7" source = "git+https://github.com/gfx-rs/gfx#85f76137ebf3de5b287559544209432277d66a66"
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)",
@ -340,6 +340,28 @@ dependencies = [
"gl_generator 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "gl_generator 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "glutin"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"android_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"cgl 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"cocoa 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gl_generator 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)",
"objc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"shared_library 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"wayland-client 0.12.5 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"winit 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"x11-dl 2.17.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "humantime" name = "humantime"
version = "1.1.1" version = "1.1.1"
@ -494,6 +516,14 @@ dependencies = [
"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)",
] ]
[[package]]
name = "osmesa-sys"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"shared_library 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "percent-encoding" name = "percent-encoding"
version = "1.0.1" version = "1.0.1"
@ -522,6 +552,7 @@ dependencies = [
"gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx)", "gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx)",
"lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"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)",
"renderdoc 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -592,6 +623,19 @@ dependencies = [
"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)",
] ]
[[package]]
name = "renderdoc"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"glutin 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"shared_library 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"wio 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "rustc-demangle" name = "rustc-demangle"
version = "0.1.8" version = "0.1.8"
@ -929,6 +973,7 @@ dependencies = [
"checksum gl_generator 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a795170cbd85b5a7baa58d6d7525cae6a03e486859860c220f7ebbbdd379d0a" "checksum gl_generator 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a795170cbd85b5a7baa58d6d7525cae6a03e486859860c220f7ebbbdd379d0a"
"checksum gleam 0.4.34 (registry+https://github.com/rust-lang/crates.io-index)" = "b4e5e2cdcadecdf3886e7808b6a38eae0a48dfe98c5c12b776fc861b80edf4a2" "checksum gleam 0.4.34 (registry+https://github.com/rust-lang/crates.io-index)" = "b4e5e2cdcadecdf3886e7808b6a38eae0a48dfe98c5c12b776fc861b80edf4a2"
"checksum gleam 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "12b793fcf40a23dd372f184c228ab3eb96f88c50bb4fba8319c483aa025a4e45" "checksum gleam 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "12b793fcf40a23dd372f184c228ab3eb96f88c50bb4fba8319c483aa025a4e45"
"checksum glutin 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9caee44b73388b2b4452ab783b13a1af80edb363bfc6e5292bdb2dd990a3171"
"checksum humantime 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0484fda3e7007f2a4a0d9c3a703ca38c71c54c55602ce4660c419fd32e188c9e" "checksum humantime 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0484fda3e7007f2a4a0d9c3a703ca38c71c54c55602ce4660c419fd32e188c9e"
"checksum io-surface 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dd46b8bb9528ad2b433e4be99f949ab7bce7bc46fbe6c54cd556d3d18b5930af" "checksum io-surface 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dd46b8bb9528ad2b433e4be99f949ab7bce7bc46fbe6c54cd556d3d18b5930af"
"checksum itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4833d6978da405305126af4ac88569b5d71ff758581ce5a987dbfa3755f694fc" "checksum itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4833d6978da405305126af4ac88569b5d71ff758581ce5a987dbfa3755f694fc"
@ -948,6 +993,7 @@ dependencies = [
"checksum objc-foundation 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" "checksum objc-foundation 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9"
"checksum objc_exception 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "098cd29a2fa3c230d3463ae069cecccc3fdfd64c0d2496ab5b96f82dab6a00dc" "checksum objc_exception 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "098cd29a2fa3c230d3463ae069cecccc3fdfd64c0d2496ab5b96f82dab6a00dc"
"checksum objc_id 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e4730aa1c64d722db45f7ccc4113a3e2c465d018de6db4d3e7dfe031e8c8a297" "checksum objc_id 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e4730aa1c64d722db45f7ccc4113a3e2c465d018de6db4d3e7dfe031e8c8a297"
"checksum osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "88cfece6e95d2e717e0872a7f53a8684712ad13822a7979bc760b9c77ec0013b"
"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831"
"checksum pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "110d5ee3593dbb73f56294327fe5668bcc997897097cbc76b51e7aed3f52452f" "checksum pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "110d5ee3593dbb73f56294327fe5668bcc997897097cbc76b51e7aed3f52452f"
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
@ -958,6 +1004,7 @@ dependencies = [
"checksum regex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75ecf88252dce580404a22444fc7d626c01815debba56a7f4f536772a5ff19d3" "checksum regex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75ecf88252dce580404a22444fc7d626c01815debba56a7f4f536772a5ff19d3"
"checksum regex-syntax 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8f1ac0f60d675cc6cf13a20ec076568254472551051ad5dd050364d70671bf6b" "checksum regex-syntax 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8f1ac0f60d675cc6cf13a20ec076568254472551051ad5dd050364d70671bf6b"
"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
"checksum renderdoc 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3aee9badfb4078c375d2d0479ed29c9c057b51ade78f94792ba2dcb11f343e7e"
"checksum rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "76d7ba1feafada44f2d38eed812bd2489a03c0f5abb975799251518b68848649" "checksum rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "76d7ba1feafada44f2d38eed812bd2489a03c0f5abb975799251518b68848649"
"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.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03dab98ab5ded3a8b43b2c80751194608d0b2aa0f1d46cf95d1c35e192844aa7" "checksum smallvec 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03dab98ab5ded3a8b43b2c80751194608d0b2aa0f1d46cf95d1c35e192844aa7"

View file

@ -20,3 +20,4 @@ build: false
test_script: test_script:
- cargo build --manifest-path libportability/Cargo.toml --features vulkan - cargo build --manifest-path libportability/Cargo.toml --features vulkan
- cargo build --manifest-path libportability/Cargo.toml --features dx12 - cargo build --manifest-path libportability/Cargo.toml --features dx12
- cargo build --manifest-path libportability-gfx/Cargo.toml --features "gfx-backend-dx12 renderdoc"

View file

@ -23,6 +23,10 @@ log = "0.4"
version = "0.5" version = "0.5"
optional = true optional = true
[dependencies.renderdoc]
version = "0.3"
optional = true
[dependencies.gfx-hal] [dependencies.gfx-hal]
git = "https://github.com/gfx-rs/gfx" git = "https://github.com/gfx-rs/gfx"
#path = "../../gfx/src/hal" #path = "../../gfx/src/hal"

View file

@ -10,7 +10,8 @@ use hal::command::RawCommandBuffer;
use hal::queue::RawCommandQueue; use hal::queue::RawCommandQueue;
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::mem; use std::{mem, ptr};
use std::os::raw::c_void;
use super::*; use super::*;
@ -537,6 +538,12 @@ pub extern "C" fn gfxCreateDevice(
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
#[cfg(feature = "renderdoc")]
let mut renderdoc = {
use renderdoc::RenderDoc;
RenderDoc::new().expect("Failed to init renderdoc")
};
let gpu = adapter.physical_device.open(&request_infos); let gpu = adapter.physical_device.open(&request_infos);
match gpu { match gpu {
@ -555,14 +562,28 @@ pub extern "C" fn gfxCreateDevice(
}) })
.collect(); .collect();
#[cfg(feature = "renderdoc")]
let rd_device = {
use renderdoc::api::RenderDocV100;
let rd_device = unsafe { gpu.device.as_raw() };
renderdoc.start_frame_capture(rd_device, ::std::ptr::null());
rd_device
};
let gpu = Gpu { let gpu = Gpu {
device: gpu.device, device: gpu.device,
queues, queues,
#[cfg(feature = "renderdoc")]
renderdoc,
#[cfg(feature = "renderdoc")]
capturing: rd_device as *mut _,
}; };
unsafe { unsafe {
*pDevice = DispatchHandle::new(gpu); *pDevice = DispatchHandle::new(gpu);
} }
VkResult::VK_SUCCESS VkResult::VK_SUCCESS
} }
Err(err) => conv::map_err_device_creation(err), Err(err) => conv::map_err_device_creation(err),
@ -570,9 +591,16 @@ pub extern "C" fn gfxCreateDevice(
} }
#[inline] #[inline]
pub extern "C" fn gfxDestroyDevice(gpu: VkDevice, _pAllocator: *const VkAllocationCallbacks) { pub extern "C" fn gfxDestroyDevice(mut gpu: VkDevice, _pAllocator: *const VkAllocationCallbacks) {
// release all the owned command queues // release all the owned command queues
if let Some(d) = gpu.unbox() { if let Some(d) = gpu.unbox() {
#[cfg(feature = "renderdoc")]
{
use renderdoc::api::RenderDocV100;
let device = gpu.capturing as *mut c_void;
gpu.renderdoc.end_frame_capture(device as *mut _, ptr::null());
}
for (_, family) in d.queues { for (_, family) in d.queues {
for queue in family { for queue in family {
let _ = queue.unbox(); let _ = queue.unbox();

View file

@ -18,6 +18,8 @@ extern crate lazy_static;
extern crate log; extern crate log;
#[cfg(feature = "env_logger")] #[cfg(feature = "env_logger")]
extern crate env_logger; extern crate env_logger;
#[cfg(feature = "renderdoc")]
extern crate renderdoc;
mod conv; mod conv;
mod handle; mod handle;
@ -66,6 +68,10 @@ pub struct RawInstance {
pub struct Gpu<B: hal::Backend> { pub struct Gpu<B: hal::Backend> {
device: B::Device, device: B::Device,
queues: HashMap<QueueFamilyIndex, Vec<VkQueue>>, queues: HashMap<QueueFamilyIndex, Vec<VkQueue>>,
#[cfg(feature = "renderdoc")]
renderdoc: renderdoc::RenderDoc<renderdoc::V110>,
#[cfg(feature = "renderdoc")]
capturing: *mut (),
} }
pub enum Pipeline<B: hal::Backend> { pub enum Pipeline<B: hal::Backend> {