Dynamically request all vk functions
This commit is contained in:
parent
b35b12d1dc
commit
6e9f1e7f26
3 changed files with 39 additions and 0 deletions
|
@ -3,6 +3,10 @@ use vulkan_sys::prelude::*;
|
|||
|
||||
static mut DEVICE_FN_HANDLES: Option<VkDeviceHandles> = None;
|
||||
|
||||
pub fn is_device_fns_initialized() -> bool {
|
||||
unsafe { DEVICE_FN_HANDLES.is_some() }
|
||||
}
|
||||
|
||||
pub fn device_fns() -> &'static VkDeviceHandles {
|
||||
unsafe { DEVICE_FN_HANDLES.as_ref().unwrap() }
|
||||
}
|
||||
|
|
|
@ -2,6 +2,10 @@ use vulkan_sys::prelude::*;
|
|||
|
||||
static mut INSTANCE_FN_HANDLES: Option<VkInstanceHandles> = None;
|
||||
|
||||
pub fn is_instance_fns_initialized() -> bool {
|
||||
unsafe { INSTANCE_FN_HANDLES.is_some() }
|
||||
}
|
||||
|
||||
pub fn instance_fns() -> &'static VkInstanceHandles {
|
||||
unsafe { INSTANCE_FN_HANDLES.as_ref().unwrap() }
|
||||
}
|
||||
|
|
31
src/lib.rs
31
src/lib.rs
|
@ -8,6 +8,7 @@ mod instance_handles;
|
|||
mod device_handles;
|
||||
|
||||
use std::{
|
||||
ffi::c_void,
|
||||
fs::{File, OpenOptions},
|
||||
io::Write,
|
||||
mem,
|
||||
|
@ -265,11 +266,41 @@ fn get_function(function_name: *const c_char) -> PFN_vkVoidFunction {
|
|||
_ => (),
|
||||
};
|
||||
|
||||
if let Some(vk_fn) = load_vk_fn(&func_string) {
|
||||
return vk_fn;
|
||||
}
|
||||
|
||||
write_log(format!("\trequested fn: {}", s));
|
||||
write_log(format!("\t-> not found"));
|
||||
Functions::Null.convert()
|
||||
}
|
||||
|
||||
fn load_vk_fn(name: &VkString) -> Option<PFN_vkVoidFunction> {
|
||||
unsafe {
|
||||
if is_instance_fns_initialized() {
|
||||
let instance_fn = instance_fns()
|
||||
.static_functions
|
||||
.vkGetInstanceProcAddr(instance_fns().instance, name.as_ptr());
|
||||
|
||||
if mem::transmute::<PFN_vkVoidFunction, *const c_void>(instance_fn) != ptr::null() {
|
||||
return Some(instance_fn);
|
||||
}
|
||||
}
|
||||
|
||||
if is_device_fns_initialized() {
|
||||
let device_fn = instance_fns()
|
||||
.instance_functions
|
||||
.vkGetDeviceProcAddr(device_fns().device, name.as_ptr());
|
||||
|
||||
if mem::transmute::<PFN_vkVoidFunction, *const c_void>(device_fn) != ptr::null() {
|
||||
return Some(device_fn);
|
||||
}
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
extern "system" fn create_instance(
|
||||
create_info: *const VkInstanceCreateInfo,
|
||||
allocator: *const VkAllocationCallbacks,
|
||||
|
|
Loading…
Reference in a new issue