kronos_compute/implementation/
instance.rs1use crate::sys::*;
4use crate::core::*;
5use crate::ffi::*;
6
7#[no_mangle]
14pub unsafe extern "C" fn vkCreateInstance(
15 pCreateInfo: *const VkInstanceCreateInfo,
16 pAllocator: *const VkAllocationCallbacks,
17 pInstance: *mut VkInstance,
18) -> VkResult {
19 if pCreateInfo.is_null() || pInstance.is_null() {
21 return VkResult::ErrorInitializationFailed;
22 }
23
24 if let Some(icd) = super::icd_loader::get_icd() {
26 if let Some(create_instance_fn) = icd.create_instance {
27 let result = create_instance_fn(pCreateInfo, pAllocator, pInstance);
28
29 if result == VkResult::Success {
31 if let Ok(mut icd_mut) = super::icd_loader::ICD_LOADER.lock() {
32 if let Some(icd) = icd_mut.as_mut() {
33 let _ = super::icd_loader::load_instance_functions(icd, *pInstance);
34 }
35 }
36 }
37
38 return result;
39 }
40 }
41
42 VkResult::ErrorInitializationFailed
44}
45
46#[no_mangle]
52pub unsafe extern "C" fn vkDestroyInstance(
53 instance: VkInstance,
54 pAllocator: *const VkAllocationCallbacks,
55) {
56 if instance.is_null() {
57 return;
58 }
59
60 if let Some(icd) = super::forward::get_icd_if_enabled() {
62 if let Some(destroy_instance) = icd.destroy_instance {
63 destroy_instance(instance, pAllocator);
64 }
65 }
66}
67
68#[no_mangle]
74pub unsafe extern "C" fn vkEnumeratePhysicalDevices(
75 instance: VkInstance,
76 pPhysicalDeviceCount: *mut u32,
77 pPhysicalDevices: *mut VkPhysicalDevice,
78) -> VkResult {
79 if instance.is_null() || pPhysicalDeviceCount.is_null() {
80 return VkResult::ErrorInitializationFailed;
81 }
82
83 if let Some(icd) = super::forward::get_icd_if_enabled() {
85 if let Some(enumerate_physical_devices) = icd.enumerate_physical_devices {
86 return enumerate_physical_devices(instance, pPhysicalDeviceCount, pPhysicalDevices);
87 } else {
88 log::warn!("ICD loaded but enumerate_physical_devices function pointer is null");
89 }
90 } else {
91 log::warn!("No ICD available for enumerate_physical_devices");
92 }
93
94 VkResult::ErrorInitializationFailed
96}
97
98#[no_mangle]
103pub unsafe extern "C" fn vkGetPhysicalDeviceProperties(
104 physicalDevice: VkPhysicalDevice,
105 pProperties: *mut VkPhysicalDeviceProperties,
106) {
107 if physicalDevice.is_null() || pProperties.is_null() {
108 return;
109 }
110
111 if let Some(icd) = super::forward::get_icd_if_enabled() {
113 if let Some(get_physical_device_properties) = icd.get_physical_device_properties {
114 get_physical_device_properties(physicalDevice, pProperties);
115 }
116 }
117}
118
119#[no_mangle]
124pub unsafe extern "C" fn vkGetPhysicalDeviceMemoryProperties(
125 physicalDevice: VkPhysicalDevice,
126 pMemoryProperties: *mut VkPhysicalDeviceMemoryProperties,
127) {
128 if physicalDevice.is_null() || pMemoryProperties.is_null() {
129 return;
130 }
131
132 if let Some(icd) = super::forward::get_icd_if_enabled() {
134 if let Some(get_physical_device_memory_properties) = icd.get_physical_device_memory_properties {
135 get_physical_device_memory_properties(physicalDevice, pMemoryProperties);
136 }
137 }
138}
139
140#[no_mangle]
142pub unsafe extern "C" fn vkGetPhysicalDeviceQueueFamilyProperties(
143 physicalDevice: VkPhysicalDevice,
144 pQueueFamilyPropertyCount: *mut u32,
145 pQueueFamilyProperties: *mut VkQueueFamilyProperties,
146) {
147 if physicalDevice.is_null() || pQueueFamilyPropertyCount.is_null() {
148 return;
149 }
150
151 if let Some(icd) = super::forward::get_icd_if_enabled() {
153 if let Some(get_physical_device_queue_family_properties) = icd.get_physical_device_queue_family_properties {
154 get_physical_device_queue_family_properties(physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties);
155 }
156 }
157}