Skip to content

Commit 4be6417

Browse files
Merge #2221
2221: Support using RTLD_NEXT r=kvark a=ZeGentzy Signed-off-by: Hal Gentz <zegentzy@protonmail.com> Depends on: ash-rs/ash#77 (comment) PR checklist: - [ ] `make` succeeds (on *nix) - [ ] `make reftests` succeeds - [x] tested examples with the following backends: vulkan on archlinux Co-authored-by: Hal Gentz <zegentzy@protonmail.com>
2 parents 308dd39 + c586e32 commit 4be6417

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/backend/vulkan/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ workspace = "../../.."
1313

1414
[features]
1515
default = ["winit"]
16+
use-rtld-next = ["shared_library"]
1617

1718
[lib]
1819
name = "gfx_backend_vulkan"
@@ -21,8 +22,8 @@ name = "gfx_backend_vulkan"
2122
byteorder = "1"
2223
log = { version = "0.4", features = ["release_max_level_error"] }
2324
lazy_static = "1"
24-
shared_library = "0.1"
25-
ash = "0.24.3"
25+
shared_library = { version = "0.1.9", optional = true }
26+
ash = "0.24.4"
2627
gfx-hal = { path = "../../hal", version = "0.1" }
2728
smallvec = "0.6"
2829
winit = { version = "0.16", optional = true }

src/backend/vulkan/src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ extern crate gfx_hal as hal;
77
#[macro_use]
88
extern crate lazy_static;
99
extern crate smallvec;
10+
#[cfg(feature = "use-rtld-next")]
11+
extern crate shared_library;
1012

1113
#[cfg(windows)]
1214
extern crate winapi;
@@ -20,6 +22,7 @@ extern crate xcb;
2022
#[cfg(feature = "glsl-to-spirv")]
2123
extern crate glsl_to_spirv;
2224

25+
#[cfg(not(feature = "use-rtld-next"))]
2326
use ash::{Entry, LoadingError};
2427
use ash::extensions as ext;
2528
use ash::version::{EntryV1_0, DeviceV1_0, InstanceV1_0, V1_0};
@@ -34,6 +37,11 @@ use std::borrow::Borrow;
3437
use std::ffi::{CStr, CString};
3538
use std::sync::Arc;
3639

40+
#[cfg(feature = "use-rtld-next")]
41+
use shared_library::dynamic_library::{DynamicLibrary, SpecialHandles};
42+
#[cfg(feature = "use-rtld-next")]
43+
use ash::{EntryCustom, LoadingError};
44+
3745
mod command;
3846
mod conv;
3947
mod device;
@@ -66,11 +74,25 @@ const SURFACE_EXTENSIONS: &'static [&'static str] = &[
6674
vk::VK_KHR_WIN32_SURFACE_EXTENSION_NAME,
6775
];
6876

77+
#[cfg(not(feature = "use-rtld-next"))]
6978
lazy_static! {
7079
// Entry function pointers
7180
pub static ref VK_ENTRY: Result<Entry<V1_0>, LoadingError> = Entry::new();
7281
}
7382

83+
#[cfg(feature = "use-rtld-next")]
84+
lazy_static! {
85+
// Entry function pointers
86+
pub static ref VK_ENTRY: Result<EntryCustom<V1_0, ()>, LoadingError>
87+
= EntryCustom::new_custom(
88+
|| Ok(()),
89+
|_, name| unsafe {
90+
DynamicLibrary::symbol_special(SpecialHandles::Next, &*name.to_string_lossy())
91+
.unwrap_or(ptr::null_mut())
92+
}
93+
);
94+
}
95+
7496
pub struct RawInstance(pub ash::Instance<V1_0>, Option<(ext::DebugReport, vk::DebugReportCallbackEXT)>);
7597
impl Drop for RawInstance {
7698
fn drop(&mut self) {

0 commit comments

Comments
 (0)