Now loads vulkan globally
This commit is contained in:
parent
582948d192
commit
7edf08fe94
5 changed files with 32 additions and 20 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -1,7 +1,8 @@
|
|||
[root]
|
||||
name = "ash"
|
||||
version = "0.1.1"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sharedlib 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
|
|
@ -7,7 +7,9 @@ license = "MIT"
|
|||
repository = "https://github.com/MaikKlein/ash"
|
||||
readme = "README.md"
|
||||
keywords = ["vulkan", "graphic"]
|
||||
documentation = "https://docs.rs/ash"
|
||||
|
||||
[dependencies]
|
||||
shared_library = "0.1.5"
|
||||
sharedlib = "6.0.0"
|
||||
lazy_static = "0.2.1"
|
||||
|
|
5
examples/triangle/Cargo.lock
generated
5
examples/triangle/Cargo.lock
generated
|
@ -2,14 +2,15 @@
|
|||
name = "example"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ash 0.1.1",
|
||||
"ash 0.2.0",
|
||||
"glfw 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ash"
|
||||
version = "0.1.1"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sharedlib 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
|
40
src/entry.rs
40
src/entry.rs
|
@ -5,6 +5,10 @@ use vk;
|
|||
use instance::Instance;
|
||||
use shared_library::dynamic_library::DynamicLibrary;
|
||||
use std::path::Path;
|
||||
use std::cell::UnsafeCell;
|
||||
use std::sync::{Once, ONCE_INIT};
|
||||
use std::sync::atomic::AtomicPtr;
|
||||
|
||||
#[cfg(windows)]
|
||||
fn get_path() -> &'static Path {
|
||||
Path::new("vulkan-1.dll")
|
||||
|
@ -20,9 +24,12 @@ fn get_path() -> &'static Path {
|
|||
Path::new("libvulkan.so")
|
||||
}
|
||||
|
||||
lazy_static!{
|
||||
static ref VK_LIB: Result<DynamicLibrary, String> = DynamicLibrary::open(Some(get_path()));
|
||||
}
|
||||
|
||||
|
||||
pub struct Entry {
|
||||
lib: DynamicLibrary,
|
||||
pub static_fn: vk::StaticFn,
|
||||
pub entry_fn: vk::EntryFn,
|
||||
}
|
||||
|
@ -41,31 +48,30 @@ pub enum InstanceError {
|
|||
}
|
||||
|
||||
impl Entry {
|
||||
pub fn load_vulkan_path(path: &Path) -> Result<Entry, LoadingError> {
|
||||
let lib =
|
||||
DynamicLibrary::open(Some(path)).map_err(|err| LoadingError::LibraryLoadFailure(err))?;
|
||||
let static_fn = vk::StaticFn::load(|name| unsafe {
|
||||
let name = name.to_str().unwrap();
|
||||
let f = match lib.symbol(name) {
|
||||
Ok(s) => s,
|
||||
Err(_) => ptr::null(),
|
||||
};
|
||||
f
|
||||
}).map_err(|err| LoadingError::StaticLoadError(err))?;
|
||||
pub fn load_vulkan() -> Result<Entry, LoadingError> {
|
||||
let static_fn = match *VK_LIB {
|
||||
Ok(ref lib) => {
|
||||
let static_fn = vk::StaticFn::load(|name| unsafe {
|
||||
let name = name.to_str().unwrap();
|
||||
let f = match lib.symbol(name) {
|
||||
Ok(s) => s,
|
||||
Err(_) => ptr::null(),
|
||||
};
|
||||
f
|
||||
}).map_err(|err| LoadingError::StaticLoadError(err))?;
|
||||
Ok(static_fn)
|
||||
}
|
||||
Err(ref err) => Err(LoadingError::LibraryLoadFailure(err.clone())),
|
||||
}?;
|
||||
let entry_fn = vk::EntryFn::load(|name| unsafe {
|
||||
mem::transmute(static_fn.get_instance_proc_addr(ptr::null_mut(), name.as_ptr()))
|
||||
}).map_err(|err| LoadingError::EntryLoadError(err))?;
|
||||
Ok(Entry {
|
||||
lib: lib,
|
||||
static_fn: static_fn,
|
||||
entry_fn: entry_fn,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn load_vulkan() -> Result<Entry, LoadingError> {
|
||||
Entry::load_vulkan_path(get_path())
|
||||
}
|
||||
|
||||
pub fn create_instance(&self,
|
||||
create_info: &vk::InstanceCreateInfo)
|
||||
-> Result<Instance, InstanceError> {
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
extern crate shared_library;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
pub mod instance;
|
||||
pub mod device;
|
||||
|
|
Loading…
Add table
Reference in a new issue