use const_cstr::*; use mira::error::MiraError; use mira::loader; use mira::mem::{from_cstring, zeroed_vec}; use mira::vulkan::{VkDevice, VkInstance, VkPhysicalDevice, VkInstanceCreateInfo, VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, PFN_vkCreateInstance, PFN_vkEnumeratePhysicalDevices, PFN_vkEnumerateDeviceExtensionProperties, VkExtensionProperties}; use mira::vulkan_memory_allocator::{VmaAllocator, VmaAllocatorCreateInfo, VmaVulkanFunctions, vmaCreateAllocator}; use mira::vulkan_memory_allocator; fn main() -> Result<(), MiraError> { let layers = vec![const_cstr!("VK_LAYER_KHRONOS_validation").as_ptr()]; let mut instance_info: VkInstanceCreateInfo = unsafe { std::mem::zeroed() }; instance_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; //instance_info.ppEnabledLayerNames = layers.as_ptr(); //instance_info.enabledLayerCount = layers.len() as u32; let mut instance: VkInstance = unsafe { std::mem::zeroed() }; let create_instance: PFN_vkCreateInstance; create_instance = unsafe { loader::instance(std::ptr::null_mut(), const_cstr!("vkCreateInstance"))? }; unsafe { create_instance(&instance_info, std::ptr::null_mut(), &mut instance) }; let enumerate_physical_devices: PFN_vkEnumeratePhysicalDevices; enumerate_physical_devices = unsafe { loader::instance(instance, const_cstr!("vkEnumeratePhysicalDevices"))? }; let mut counter: u32 = 0; unsafe { enumerate_physical_devices(instance, &mut counter, std::ptr::null_mut()) }; let mut devices = unsafe { zeroed_vec::(counter as usize) }; unsafe { enumerate_physical_devices(instance, &mut counter, devices.as_mut_ptr()) }; let enumerate_device_extensions: PFN_vkEnumerateDeviceExtensionProperties; enumerate_device_extensions = unsafe { loader::instance( instance, const_cstr!("vkEnumerateDeviceExtensionProperties"), )? }; for device in devices.into_iter().enumerate() { println!("Device {}", device.0); println!("Extensions"); unsafe { enumerate_device_extensions( device.1, std::ptr::null(), &mut counter, std::ptr::null_mut(), ) }; let mut extensions = unsafe { zeroed_vec::(counter as usize) }; unsafe { enumerate_device_extensions( device.1, std::ptr::null(), &mut counter, extensions.as_mut_ptr(), ) }; for extension in extensions.into_iter().enumerate() { let str = match unsafe { from_cstring(extension.1.extensionName.as_ptr()) } { Ok(str) => str, Err(_) => continue, }; println!("#{} - {}", extension.0, str); } println!("\n"); /* buggy!!! unsafe { let mut allocator = std::mem::zeroed(); let mut create_info: VmaAllocatorCreateInfo = std::mem::zeroed(); create_info.instance = instance as vulkan_memory_allocator::VkInstance; create_info.physicalDevice = device.1 as vulkan_memory_allocator::VkPhysicalDevice; create_info.device = device.1 as vulkan_memory_allocator::VkDevice; #[allow(invalid_value)] let mut vulkan_pointers: VmaVulkanFunctions = std::mem::MaybeUninit::zeroed().assume_init(); vulkan_pointers.vkGetDeviceProcAddr = mira::loader::device_proc_addr()?; vulkan_pointers.vkGetInstanceProcAddr = mira::loader::instance_proc_addr()?; create_info.pVulkanFunctions = &vulkan_pointers; vmaCreateAllocator(&create_info, &mut allocator); }*/ } Ok(()) }