-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is the preferred pattern in most environments when an application cannot function without Vulkan, as it saves the libloading dependency, eliminates an error case, and makes the Vulkan dependency visible to the OS.
- Loading branch information
Showing
10 changed files
with
75 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fn main() { | ||
#[cfg(feature = "linked")] | ||
{ | ||
println!("cargo:rustc-link-lib=vulkan"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::os::raw::c_char; | ||
|
||
use crate::{entry::EntryCustom, vk}; | ||
|
||
/// Marker type for [`EntryLinked`] | ||
pub struct Linked; | ||
|
||
/// Compile-time function loader | ||
/// | ||
/// Prefer this over [`Entry`](crate::Entry) in code that would otherwise panic on | ||
/// [`Entry::new`](crate::Entry::new) failing. | ||
#[cfg_attr(docsrs, doc(cfg(feature = "linked")))] | ||
pub type EntryLinked = EntryCustom<Linked>; | ||
|
||
impl EntryLinked { | ||
pub fn new() -> Self { | ||
// Sound because we're linking to Vulkan, which provides a vkGetInstanceProcAddr that has | ||
// defined behavior in this use. | ||
unsafe { | ||
Self::from_static_fn( | ||
Linked, | ||
vk::StaticFn { | ||
get_instance_proc_addr: vkGetInstanceProcAddr, | ||
}, | ||
) | ||
} | ||
} | ||
} | ||
|
||
extern "system" { | ||
fn vkGetInstanceProcAddr(instance: vk::Instance, name: *const c_char) | ||
-> vk::PFN_vkVoidFunction; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters