Skip to content

Commit

Permalink
Fix opening of renderdoc lib (#2930)
Browse files Browse the repository at this point in the history
* 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 <reecevanatta@hey.com>
  • Loading branch information
ABuffSeagull and ABuffSeagull authored Aug 1, 2022
1 parent a05c8dc commit 4cbf8cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 18 additions & 1 deletion wgpu-hal/src/auxil/renderdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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::Library, libloading::Error> =
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::Library, libloading::Error> =
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 {
Expand Down

0 comments on commit 4cbf8cf

Please sign in to comment.