Skip to content

Instantly share code, notes, and snippets.

@Jasper-Bekkers
Last active April 29, 2019 11:10
Show Gist options
  • Select an option

  • Save Jasper-Bekkers/beef0d80791834fb3f76e316810206b1 to your computer and use it in GitHub Desktop.

Select an option

Save Jasper-Bekkers/beef0d80791834fb3f76e316810206b1 to your computer and use it in GitHub Desktop.
use ash::{vk, Entry, Instance};
use ash::version::{EntryV1_0, EntryV1_1, InstanceV1_0};
use ash::vk_make_version;
use std::ffi::CString;
use shared_library::dynamic_library::DynamicLibrary;
use std::sync::Arc;
use std::path::Path;
use ash::vk::Handle;
#[cfg(windows)]
const LIB_PATH: &'static str = "vulkan-1.dll";
fn app_init(entry: &ash::Entry) -> Instance {
let app_name = CString::new("Test").unwrap();
let appinfo = vk::ApplicationInfo::builder()
.application_name(&app_name)
.application_version(0)
.engine_name(&app_name)
.engine_version(0)
.api_version(vk_make_version!(1, 1, 0));
let create_info = vk::InstanceCreateInfo::builder()
.application_info(&appinfo)
.enabled_layer_names(&[])
.enabled_extension_names(&[]);
let app_instance: Instance = unsafe {
entry
.create_instance(&create_info, None)
.expect("Instance creation error")
};
app_instance
}
fn lib_init(raw_handle: u64) {
// todo: rely in ash to expose helpers for this?
let vk_lib = DynamicLibrary::open(Some(&Path::new(LIB_PATH)))
.map_err(|err| panic!("Hoi {}", err.clone()))
.map(|dl| Arc::new(dl)).unwrap();
let static_fn = unsafe {
vk::StaticFn::load(|name|
vk_lib
.symbol(&*name.to_string_lossy())
.unwrap()
)
};
let lib_instance = unsafe {
Instance::load(&static_fn, vk::Instance::from_raw(raw_handle))
};
let pdevices = unsafe {
lib_instance
.enumerate_physical_devices()
.expect("Physical device error")
};
println!("{:?}", pdevices);
}
fn lib_init_2(raw_handle: u64) {
let entry = Entry::new().unwrap();
let lib_instance = unsafe {
entry.create_instance_from_raw_handle(raw_handle).unwrap()
};
let pdevices = unsafe {
lib_instance
.enumerate_physical_devices()
.expect("Physical device error")
};
println!("{:?}", pdevices);
}
fn main() {
let entry = Entry::new().unwrap();
let app_instance = app_init(&entry);
let raw_handle = app_instance.handle().as_raw();
dbg!(raw_handle);
lib_init_2(raw_handle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment