From 4cbf8cfcf198034994b07f4372d09c6da8ad94dd Mon Sep 17 00:00:00 2001 From: Reece Date: Sun, 31 Jul 2022 21:39:55 -0400 Subject: [PATCH] Fix opening of renderdoc lib (#2930) * Fix opening renderdoc lib Renderdoc needs to not be opened by us, but instead open the existing copy. Unfortunately this requires OS specific flags for opening, plus `libloading` doesn't have full API coverage currently. * Added changelog entry for #2930 * Hide RTLD_NOLOAD behind a cfg for unix Co-authored-by: ABuffSeagull --- CHANGELOG.md | 1 + wgpu-hal/src/auxil/renderdoc.rs | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 793fc9405..e4a2bd1f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ the same every time it is rendered, we now warn if it is missing. #### General - Improve the validation and error reporting of buffer mappings by @nical in [#2848](https://github.com/gfx-rs/wgpu/pull/2848) +- Fixed opening of RenderDoc library by @abuffseagull in [#2930](https://github.com/gfx-rs/wgpu/pull/2930) ### Changes diff --git a/wgpu-hal/src/auxil/renderdoc.rs b/wgpu-hal/src/auxil/renderdoc.rs index cbe3c1908..712eac418 100644 --- a/wgpu-hal/src/auxil/renderdoc.rs +++ b/wgpu-hal/src/auxil/renderdoc.rs @@ -28,6 +28,10 @@ pub enum RenderDoc { }, } +// TODO: replace with libloading API once supported +#[cfg(unix)] +const RTLD_NOLOAD: i32 = 0x4; + impl RenderDoc { pub unsafe fn new() -> Self { type GetApiFn = unsafe extern "C" fn(version: u32, out: *mut *mut ffi::c_void) -> i32; @@ -39,7 +43,20 @@ impl RenderDoc { #[cfg(target_os = "android")] let renderdoc_filename = "libVkLayer_GLES_RenderDoc.so"; - let renderdoc_lib = match libloading::Library::new(renderdoc_filename) { + #[cfg(unix)] + let renderdoc_result: Result = + libloading::os::unix::Library::open( + Some(renderdoc_filename), + libloading::os::unix::RTLD_NOW | RTLD_NOLOAD, + ) + .map(|lib| lib.into()); + + #[cfg(windows)] + let renderdoc_result: Result = + libloading::os::windows::Library::open_already_loaded(renderdoc_filename) + .map(|lib| lib.into()); + + let renderdoc_lib = match renderdoc_result { Ok(lib) => lib, Err(e) => { return RenderDoc::NotAvailable {