简单vulkan程序的API调用步骤总结

本文根据vulkan triangle来总结一下简单vulkan sample的API调用步骤
一.创建instance & device
1.icd_init或者module_init :__attribute__((constructor))
wsi的构造函数,当wsi库被加载的时候执行,先于app的main函数而调用,设置 VK_ICD=libMali.so
2.vkEnumerateInstanceExtensionProperties
get extensions from all ICD,return to app in demo->extension_names= VK_KHR_surface,VK_KHR_wayland_surface,VK_KHR_swapchain,VK_EXT_debug_report
3.vkCreateInstance 
instance类似于opengl中的context,It stores per-application state
当调用API创建Vulkan实例的时候,Vulkan SDK内部会经loader查找可用的GPU设备
4.vkEnumeratePhysicalDevices (loaderAndValidationLayer)
enumerate gpu device and choose one.
5.vkEnumerateDeviceExtensionProperties (loaderAndValidationLayer)
get all extensions from specific gpu device and choose one. get "VK_KHR_surface,VK_KHR_wayland_surface,VK_KHR_swapchain",
and choose VK_KHR_swapchain to app in demo->extension_names=VK_KHR_swapchain
5.vkCreateDevice  vkGetDeviceQueue (loaderAndValidationLayer)
create logic device. 接下来就可以get queue了,queue是和device关联在一起的

二.创建command buffer & swapchain buffer & image
1.vkCreateCommandPool vkAllocateCommandBuffers (loaderAndValidationLayer)
--demo_prepare_buffers buffer都是通过vkCreateImageView来分配
--此处分配的buffer和image是color buffer 为vkCreateFramebuffer准备的
--in demo_prepare_framebuffers:attachments[0] = demo->buffers[i].view;
2.CreateSwapchainKHR --> vk_CreateSwapchainKHR 
icd->create_presentable_image=vkCreateImageFromNativeBuffer
3.fpGetSwapchainImagesKHR --> vk_GetSwapchainImagesKHR 
image 在vk_CreateSwapchainKHR:vk_icd_create_presentable_image中创建
4.vkCreateImageView -->dev_data->device_dispatch_table->CreateImageView(loader)-->vkCreateImageView_driver 

三.创建depth buffer  
--depth buffer也是通过vkCreateImageView来分配,为vkCreateFramebuffer准备的
--attachments[1] = demo->depth.view; in demo_prepare_framebuffers()
1.vkCreateImage
2.vkAllocateMemory
3.vkBindImageMemory
4.demo_set_image_layout
5.vkCreateImageView

四.创建 texture image
--texture也是通过vkCreateImageView来分配,在demo_prepare_descriptor_set中使用
--tex_descs[i].imageView = demo->textures[i].view;
1.vkCreateImage
2.vkAllocateMemory
3.vkBindImageMemory
4.demo_set_image_layout
5.vkCreateImageView

五.prepare vertices
1.vkCreateBuffer
2.vkAllocateMemory  vkMapMemory
3.memcpy 把顶点数据拷贝的map的memory
4.vkBindBufferMemory

六.prepare_descriptor_layout
1.vkCreateDescriptorSetLayout  demo->desc_layout
2.vkCreatePipelineLayout  demo->pipeline_layout

七.create render pass
1.vkCreateRenderPass

八.create pipeline
1.demo_prepare_shader_module-->vkCreateShaderModule  demo_prepare_vs
2.vkCreatePipelineCache  vkCreateGraphicsPipelines

九.prepare descriptor pool and descriptor set
1.vkCreateDescriptorPool  demo->desc_pool
2.vkAllocateDescriptorSets(demo->desc_pool)  (in demo_prepare_descriptor_set)
3.vkUpdateDescriptorSets

十.create framebuffer
vkCreateFramebuffer  传入之前创建的depth image view和buffer image,renderpass

十一.demo_draw
1.vkAcquireNextImageKHR
2.demo_set_image_layout
3.demo_flush_init_cmd
4.demo_draw_build_cmd
5.vkQueueSubmit
6.vkQueuePresentKHR

你可能感兴趣的:(VULKAN)