/// Creates a new `Loader` by creating a Vulkan instance and device, with the provided physical
/// device index.
Creates a new `Loader` by creating a Vulkan instance and device, with the provided physical
device index.
Creates a new ` Loader ` by creating a Vulkan instance and device with the provided physical device index .
pub fn new(physical_device_index: u32) -> Result<Loader, vk::Result> {
        let entry_points = entry_points();
        let application_info = app_info();
        let instance_info = instance_info(&application_info);
        let mut instance: usize = 0;
        let result = unsafe {
            entry_points.CreateInstance(
                &instance_info,
                std::ptr::null(),
                &mut instance as *mut vk::Instance,
            )
        };
        if result != vk::SUCCESS {
            return Err(result);
        }
        let instance_pointers = instance_pointers(instance);
        let mut device_count: u32 = 0;
        if unsafe {
            instance_pointers.EnumeratePhysicalDevices(
                instance,
                &mut device_count as *mut u32,
                std::ptr::null_mut(),
            )
        } != vk::SUCCESS
        {
            return Err(vk::ERROR_INITIALIZATION_FAILED);
        }
        let mut physical_devices: Vec<vk::PhysicalDevice> = vec![0; device_count as usize];
        if unsafe {
            instance_pointers.EnumeratePhysicalDevices(
                instance,
                &mut device_count as *mut u32,
                physical_devices.as_mut_ptr(),
            )
        } != vk::SUCCESS
        {
            return Err(vk::ERROR_INITIALIZATION_FAILED);
        }
        let physical_device = physical_devices[physical_device_index as usize];
        let mut queue_family_count: u32 = 0;
        unsafe {
            instance_pointers.GetPhysicalDeviceQueueFamilyProperties(
                physical_device,
                &mut queue_family_count as *mut u32,
                std::ptr::null_mut(),
            );
        };
        let mut queue_family_properties =
            Vec::<vk::QueueFamilyProperties>::with_capacity(queue_family_count as usize);
        queue_family_properties.resize_with(queue_family_count as usize, || {
            vk::QueueFamilyProperties {
                queueFlags: 0,
                queueCount: 0,
                timestampValidBits: 0,
                minImageTransferGranularity: vk::Extent3D { width: 0, height: 0, depth: 0 },
            }
        });
        unsafe {
            instance_pointers.GetPhysicalDeviceQueueFamilyProperties(
                physical_device,
                &mut queue_family_count as *mut u32,
                queue_family_properties.as_mut_ptr(),
            );
        };
        let mut queue_family_index = None;
        for (index, queue_family) in queue_family_properties.iter().enumerate() {
            if queue_family.queueFlags & vk::QUEUE_GRAPHICS_BIT != 0 {
                queue_family_index = Some(index);
            }
        }
        if queue_family_index.is_none() {
            return Err(vk::ERROR_INITIALIZATION_FAILED);
        }
        let queue_family_index = queue_family_index.unwrap();
        let queue_create_info = vk::DeviceQueueCreateInfo {
            sType: vk::STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
            pNext: std::ptr::null(),
            flags: 0,
            queueFamilyIndex: queue_family_index as u32,
            queueCount: 1,
            pQueuePriorities: &0.0,
        };
        let extension_name: Vec<u8> = b"VK_FUCHSIA_buffer_collection_x".to_vec();
        let device_extensions = vec![extension_name.as_ptr() as *const i8];
        let device_create_info = vk::DeviceCreateInfo {
            sType: vk::STRUCTURE_TYPE_DEVICE_CREATE_INFO,
            pNext: std::ptr::null(),
            flags: 0,
            queueCreateInfoCount: 1,
            pQueueCreateInfos: &queue_create_info as *const vk::DeviceQueueCreateInfo,
            enabledLayerCount: 0,
            ppEnabledLayerNames: std::ptr::null(),
            enabledExtensionCount: device_extensions.len() as u32,
            ppEnabledExtensionNames: device_extensions.as_ptr(),
            pEnabledFeatures: std::ptr::null(),
        };
        let mut device: usize = 0;
        let result = unsafe {
            instance_pointers.CreateDevice(
                physical_device,
                &device_create_info as *const vk::DeviceCreateInfo,
                std::ptr::null(),
                &mut device as *mut usize,
            )
        };
        if result != vk::SUCCESS {
            return Err(result);
        }
        Ok(Loader {
            instance_pointers,
            _instance: instance,
            _physical_device: physical_device,
            device,
        })
    }
pub fn new ( physical_device_index : u32 ) -> Result < Loader , vk :: Result > { let entry_points = entry_points ( ) ; let application_info = app_info ( ) ; let instance_info = instance_info ( & application_info ) ; let mut instance : usize = 0 ; let result = unsafe { entry_points . CreateInstance ( & instance_info , std :: ptr :: null ( ) , & mut instance as * mut vk :: Instance , ) } ; if result != vk :: SUCCESS { return Err ( result ) ; } let instance_pointers = instance_pointers ( instance ) ; let mut device_count : u32 = 0 ; if unsafe { instance_pointers . EnumeratePhysicalDevices ( instance , & mut device_count as * mut u32 , std :: ptr :: null_mut ( ) , ) } != vk :: SUCCESS { return Err ( vk :: ERROR_INITIALIZATION_FAILED ) ; } let mut physical_devices : Vec < vk :: PhysicalDevice > = vec ! [ 0 device_count as usize ] ; if unsafe { instance_pointers . EnumeratePhysicalDevices ( instance , & mut device_count as * mut u32 , physical_devices . as_mut_ptr ( ) , ) } != vk :: SUCCESS { return Err ( vk :: ERROR_INITIALIZATION_FAILED ) ; } let physical_device = physical_devices [ physical_device_index as usize ] ; let mut queue_family_count : u32 = 0 ; unsafe { instance_pointers . GetPhysicalDeviceQueueFamilyProperties ( physical_device , & mut queue_family_count as * mut u32 , std :: ptr :: null_mut ( ) , ) ; } ; let mut queue_family_properties = Vec :: < vk :: QueueFamilyProperties > :: with_capacity ( queue_family_count as usize ) ; queue_family_properties . resize_with ( queue_family_count as usize , | | { vk :: QueueFamilyProperties { queueFlags : 0 , queueCount : 0 , timestampValidBits : 0 , minImageTransferGranularity : vk :: Extent3D { width : 0 , height : 0 , depth : 0 } , } } ) ; unsafe { instance_pointers . GetPhysicalDeviceQueueFamilyProperties ( physical_device , & mut queue_family_count as * mut u32 , queue_family_properties . as_mut_ptr ( ) , ) ; } ; let mut queue_family_index = None ; for ( index , queue_family ) in queue_family_properties . iter ( ) . enumerate ( ) { if queue_family . queueFlags & vk :: QUEUE_GRAPHICS_BIT != 0 { queue_family_index = Some ( index ) ; } } if queue_family_index . is_none ( ) { return Err ( vk :: ERROR_INITIALIZATION_FAILED ) ; } let queue_family_index = queue_family_index . unwrap ( ) ; let queue_create_info = vk :: DeviceQueueCreateInfo { sType : vk :: STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO , pNext : std :: ptr :: null ( ) , flags : 0 , queueFamilyIndex : queue_family_index as u32 , queueCount : 1 , pQueuePriorities : & 0.0 , } ; let extension_name : Vec < u8 > = b" " . to_vec ( ) ; let device_extensions = vec ! [ extension_name as_ptr ( ) as const i8 ] ; let device_create_info = vk :: DeviceCreateInfo { sType : vk :: STRUCTURE_TYPE_DEVICE_CREATE_INFO , pNext : std :: ptr :: null ( ) , flags : 0 , queueCreateInfoCount : 1 , pQueueCreateInfos : & queue_create_info as * const vk :: DeviceQueueCreateInfo , enabledLayerCount : 0 , ppEnabledLayerNames : std :: ptr :: null ( ) , enabledExtensionCount : device_extensions . len ( ) as u32 , ppEnabledExtensionNames : device_extensions . as_ptr ( ) , pEnabledFeatures : std :: ptr :: null ( ) , } ; let mut device : usize = 0 ; let result = unsafe { instance_pointers . CreateDevice ( physical_device , & device_create_info as * const vk :: DeviceCreateInfo , std :: ptr :: null ( ) , & mut device as * mut usize , ) } ; if result != vk :: SUCCESS { return Err ( result ) ; } Ok ( Loader { instance_pointers , _instance : instance , _physical_device : physical_device , device , } ) }
Creates a new `Loader` by creating a Vulkan instance and device, with the provided physical
device index.
Creates a new ` Loader ` by creating a Vulkan instance and device with the provided physical device index .
physical_device_index
u32