1 type Instance = 2 val object : VkInstance 3 val messenger : DebugUtilsMessengerExt 4 val physical_device : VkPhysicalDevice 5 val device : VkDevice 6 val graphics_queue : VkQueue 7 val graphics_queue_family_index : u32 8 val command_pool : VkCommandPool 9 val max_msaa_samples : SampleCountFlags 10 val depth_format : VkFormat 11 val limits : PhysicalDeviceLimits 12 13 def discard = 14 vk/device_wait_idle device 15 vk/destroy_command_pool device command_pool null 16 vk/destroy_device device null 17 object.destroy_messenger messenger 18 vk/destroy_instance object null 19 20 object VkInstance = 21 def create = 22 os@ windows 23 24 let enabled_extension_names = ["VK_EXT_debug_report" 25 "VK_EXT_debug_utils" 26 "VK_KHR_surface" 27 "VK_KHR_win32_surface"] 28 let enabled_layer_names = [] 29 30 os@ mac 31 32 let enabled_extension_names = ["VK_EXT_debug_report" 33 "VK_EXT_debug_utils" 34 "VK_KHR_surface" 35 "VK_MVK_macos_surface"] 36 let enabled_layer_names = [] 37 38 os@ other 39 40 let enabled_extension_names = ["VK_EXT_debug_report" 41 "VK_EXT_debug_utils" 42 "VK_KHR_surface" 43 "VK_KHR_xcb_surface" 44 "VK_KHR_xlib_surface"] 45 let enabled_layer_names = ["VK_LAYER_KHRONOS_validation"] 46 47 endos@ 48 49 let application_info = ApplicationInfo 50 type = StructureType/ApplicationInfo 51 next = null 52 application_name = null 53 application_version = 0 54 engine_name = null 55 engine_version = 0 56 api_version = 4194304 57 58 let messenger_create_info = vulkan/messenger/create_info 59 let instance_create_info = InstanceCreateInfo 60 type = StructureType/InstanceCreateInfo 61 next = messenger_create_info@ptr 62 flags = InstanceCreateFlags@zero 63 application_info = application_info@ptr 64 enabled_layer_count = enabled_layer_names.size 65 enabled_layer_names = enabled_layer_names.as_ptr 66 enabled_extension_count = enabled_extension_names.size 67 enabled_extension_names = enabled_extension_names.as_ptr 68 69 let mut instance = null 70 vk/create_instance instance_create_info@ptr null instance@mut_ptr 71 72 instance 73 74 type VkInstance 75 def pick_physical_device = 76 let mut count = 0 77 vk/enumerate_physical_devices self count@mut_ptr null 78 79 let mut physical_devices = Array count 80 vk/enumerate_physical_devices self count@mut_ptr 81 physical_devices.as_mut_ptr 82 83 let physical_device = physical_devices[0] 84 physical_devices.discard 85 86 physical_device 87 88 object Instance = 89 def create = 90 let object = VkInstance.create 91 let messenger = object.create_messenger 92 let physical_device = object.pick_physical_device 93 let limits = physical_device.get_properties.limits 94 let max_msaa_samples = physical_device.get_max_usable_sample_count 95 let depth_format = physical_device.find_depth_format 96 97 let graphics_queue_family_index = 98 physical_device.get_graphics_queue_family_index 99 100 let (device, graphics_queue) = VkDevice.create physical_device 101 graphics_queue_family_index 102 let command_pool = CommandPool.create device 103 graphics_queue_family_index 104 105 Instance =object =messenger =physical_device =device =graphics_queue 106 =graphics_queue_family_index =command_pool =max_msaa_samples 107 =depth_format =limits 108