Skip to content

Commit

Permalink
Guide users towards linking the loader directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith committed Jul 31, 2021
1 parent 2d5b686 commit 14bec37
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ let pool = device.create_command_pool(&pool_create_info).unwrap();

### Optional linking

The default `linked` cargo feature will link your binary with the Vulkan loader directly and expose the infallible `EntryLinked`.
If your application can handle Vulkan being missing at runtime, you can instead enable the `loaded` feature to dynamically load Vulkan with `Entry`.
The default `linked` cargo feature will link your binary with the Vulkan loader directly and expose the infallible `Entry`.
If your application can handle Vulkan being missing at runtime, you can instead enable the `loaded` feature to dynamically load Vulkan with `RuntimeLoadedEntry`.

## Example
You can find the examples [here](https://github.com/MaikKlein/ash/tree/master/examples).
Expand Down
12 changes: 6 additions & 6 deletions ash/src/entry_libloading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ impl From<MissingEntryPoint> for LoadingError {

/// Loads functions from an entry point found at runtime
///
/// Prefer [`EntryLinked`](crate::EntryLinked) in code that would would otherwise panic on
/// [`Entry::new`] failing.
/// Prefer [`Entry`](crate::Entry) in code that would would otherwise panic on
/// [`RuntimeLoadedEntry::new`] failing.
#[cfg_attr(docsrs, doc(cfg(feature = "loaded")))]
pub type Entry = EntryCustom<Arc<Library>>;
pub type RuntimeLoadedEntry = EntryCustom<Arc<Library>>;

impl Entry {
impl RuntimeLoadedEntry {
/// Load default Vulkan library for the current platform
///
/// # Safety
Expand All @@ -81,7 +81,7 @@ impl Entry {
/// let instance = unsafe { entry.create_instance(&create_info, None)? };
/// # Ok(()) }
/// ```
pub unsafe fn new() -> Result<Entry, LoadingError> {
pub unsafe fn new() -> Result<Self, LoadingError> {
Self::with_library(LIB_PATH)
}

Expand All @@ -90,7 +90,7 @@ impl Entry {
/// # Safety
/// `dlopen`ing native libraries is inherently unsafe. The safety guidelines
/// for [`Library::new`] and [`Library::get`] apply here.
pub unsafe fn with_library(path: impl AsRef<OsStr>) -> Result<Entry, LoadingError> {
pub unsafe fn with_library(path: impl AsRef<OsStr>) -> Result<Self, LoadingError> {
let lib = Library::new(path)
.map_err(LoadingError::LibraryLoadFailure)
.map(Arc::new)?;
Expand Down
8 changes: 4 additions & 4 deletions ash/src/entry_linked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ pub struct Linked;

/// Loads functions from an entry point linked at compile time
///
/// Prefer this over [`Entry`](crate::Entry) in code that would otherwise panic on
/// [`Entry::new`](crate::Entry::new) failing.
/// Prefer this over [`RuntimeLoadedEntry`](crate::RuntimeLoadedEntry) in code that would otherwise
/// panic on [`RuntimeLoadedEntry::new`](crate::Entry::new) failing.
#[cfg_attr(docsrs, doc(cfg(feature = "linked")))]
pub type EntryLinked = EntryCustom<Linked>;
pub type Entry = EntryCustom<Linked>;

impl EntryLinked {
impl Entry {
pub fn new() -> Self {
// Sound because we're linking to Vulkan, which provides a vkGetInstanceProcAddr that has
// defined behavior in this use.
Expand Down
14 changes: 7 additions & 7 deletions ash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
//! ```
//!
//! ## Getting started
//! Load the Vulkan library at the default location using [`Entry::new()`][EntryCustom<_>::new()],
//! or at a custom location using [`Entry::with_library("path/to/vulkan")`][EntryCustom<_>::with_library()].
//! These loaders use [`libloading`]. If you wish to perform function loading yourself
//! call [`EntryCustom::new_custom()`] with a closure turning function names
//! into function pointers.
//!
//! Load the Vulkan library linked at compile time using [`Entry::new`](EntryCustom<Linked>::new),
//! or at load it at runtime using `RuntimeLoadedEntry`, which uses `libloading`. If you wish to
//! perform function loading yourself call [`EntryCustom::new_custom()`] with a closure turning
//! function names into function pointers.
pub use crate::device::Device;
pub use crate::entry::{EntryCustom, InstanceError};
#[cfg(feature = "loaded")]
pub use crate::entry_libloading::{Entry, LoadingError};
pub use crate::entry_libloading::{LoadingError, RuntimeLoadedEntry};
#[cfg(feature = "linked")]
pub use crate::entry_linked::EntryLinked;
pub use crate::entry_linked::Entry;
pub use crate::instance::Instance;

mod device;
Expand Down
2 changes: 1 addition & 1 deletion examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ash::extensions::{
};

use ash::vk;
use ash::EntryLinked;
use ash::Entry;
pub use ash::{Device, EntryCustom, Instance};
use std::borrow::Cow;
use std::cell::RefCell;
Expand Down

0 comments on commit 14bec37

Please sign in to comment.