use crate::sys::*;
use crate::core::*;
use crate::ffi::*;
#[no_mangle]
pub unsafe extern "C" fn vkCreateInstance(
pCreateInfo: *const VkInstanceCreateInfo,
pAllocator: *const VkAllocationCallbacks,
pInstance: *mut VkInstance,
) -> VkResult {
if pCreateInfo.is_null() || pInstance.is_null() {
return VkResult::ErrorInitializationFailed;
}
if let Some(icd) = super::icd_loader::get_icd() {
if let Some(create_instance_fn) = icd.create_instance {
let result = create_instance_fn(pCreateInfo, pAllocator, pInstance);
if result == VkResult::Success {
if let Ok(mut icd_mut) = super::icd_loader::ICD_LOADER.lock() {
if let Some(icd) = icd_mut.as_mut() {
let _ = super::icd_loader::load_instance_functions(icd, *pInstance);
}
}
}
return result;
}
}
VkResult::ErrorInitializationFailed
}
#[no_mangle]
pub unsafe extern "C" fn vkDestroyInstance(
instance: VkInstance,
pAllocator: *const VkAllocationCallbacks,
) {
if instance.is_null() {
return;
}
if let Some(icd) = super::forward::get_icd_if_enabled() {
if let Some(destroy_instance) = icd.destroy_instance {
destroy_instance(instance, pAllocator);
}
}
}
#[no_mangle]
pub unsafe extern "C" fn vkEnumeratePhysicalDevices(
instance: VkInstance,
pPhysicalDeviceCount: *mut u32,
pPhysicalDevices: *mut VkPhysicalDevice,
) -> VkResult {
if instance.is_null() || pPhysicalDeviceCount.is_null() {
return VkResult::ErrorInitializationFailed;
}
if let Some(icd) = super::forward::get_icd_if_enabled() {
if let Some(enumerate_physical_devices) = icd.enumerate_physical_devices {
return enumerate_physical_devices(instance, pPhysicalDeviceCount, pPhysicalDevices);
} else {
log::warn!("ICD loaded but enumerate_physical_devices function pointer is null");
}
} else {
log::warn!("No ICD available for enumerate_physical_devices");
}
VkResult::ErrorInitializationFailed
}
#[no_mangle]
pub unsafe extern "C" fn vkGetPhysicalDeviceProperties(
physicalDevice: VkPhysicalDevice,
pProperties: *mut VkPhysicalDeviceProperties,
) {
if physicalDevice.is_null() || pProperties.is_null() {
return;
}
if let Some(icd) = super::forward::get_icd_if_enabled() {
if let Some(get_physical_device_properties) = icd.get_physical_device_properties {
get_physical_device_properties(physicalDevice, pProperties);
}
}
}
#[no_mangle]
pub unsafe extern "C" fn vkGetPhysicalDeviceMemoryProperties(
physicalDevice: VkPhysicalDevice,
pMemoryProperties: *mut VkPhysicalDeviceMemoryProperties,
) {
if physicalDevice.is_null() || pMemoryProperties.is_null() {
return;
}
if let Some(icd) = super::forward::get_icd_if_enabled() {
if let Some(get_physical_device_memory_properties) = icd.get_physical_device_memory_properties {
get_physical_device_memory_properties(physicalDevice, pMemoryProperties);
}
}
}
#[no_mangle]
pub unsafe extern "C" fn vkGetPhysicalDeviceQueueFamilyProperties(
physicalDevice: VkPhysicalDevice,
pQueueFamilyPropertyCount: *mut u32,
pQueueFamilyProperties: *mut VkQueueFamilyProperties,
) {
if physicalDevice.is_null() || pQueueFamilyPropertyCount.is_null() {
return;
}
if let Some(icd) = super::forward::get_icd_if_enabled() {
if let Some(get_physical_device_queue_family_properties) = icd.get_physical_device_queue_family_properties {
get_physical_device_queue_family_properties(physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties);
}
}
}