您的位置:首页 > 其它

vulkan spec中的一些概念

2017-07-07 16:36 218 查看
本文来自于vulkan spec1.0的阅读笔记

1.Instance & device

1).Instance用于Vulkan Application 里面保存当前的状态信息而使用的, VkInstance是一切 Vulkan 函数

 的源头,一个进程拥有一个VkInstance, 只可用于查询 GPU 信息,即VkPhysicalDevice的properties and features,etc.

2).Device object是对应于和物理设备之间的逻辑连接,每个Application必须要创建一个

 logical device用于对physical device 即GPU进行操作,它类似于 OpenGL 中的 context,

3).Creating a logical device also creates the queues associated with that device

4).一个VkInstance可以有多个VkPhysicalDevice,一个VkPhysicalDevice可以有多个VkDevice。在Vulkan1.0,跨GPU的调用还未实现(将来会)

5).大概的初始化调用就像是这样:vkCreateInstance() → vkEnumeratePhysicalDevices() → vkEnumerateDeviceExtensionProperties

2.device queue

-queue是和device关联在一起的,不能跨device使用,可以通过device创建queue family

-queue封装了图形、计算、直接内存访问功能,独立调度、异步等调度操作

-queue在vkCreateDevice的时候创建,通过VkDeviceCreateInfo.pQueueCreateInfos指定创建queue的类型和数量,使用时通过vkGetDeviceQueue获取queue的handle


3.Instance --> GPU --> Device


-Instance表示具体的Vulkan应用实例。在一个应用程序中可以创建多个实例,这些实例之间相互独立,互不干扰。

-当调用API创建Vulkan实例的时候,Vulkan SDK内部会经loader查找可用的GPU设备。

-创建Vulkan实例需要两个输入信息:应用程序的信息,内存分配回调函数

-Vulkan通过用户输入的内存分配器来分配内存

4.vulkan loader

1).Finds driver and dispatches API calls. loader包括Validation layer, debug layer etc. tracing loader不属于vk sdk. 每个ICD有自己的实现.

2).Vulkan is an Explicit API, No validation or error checking  is done inside a Vulkan driver. Any errors in how Vulkan is used often result in a crash. This project provides standard validation layers that can be enabled to ease development by helping developers
verify their applications correctly use the Vulkan API.

3).Validation layers是可选支持,如果enable的话需要在vkCreateInstance()入参里填充validation layers名称集合

4)Validation layers可以随意的嵌入到Vulkan驱动程序中,他是对vulkan driver的一层封装,如果有必要你也可以包含debug功能,以下示例代码是一个函数中应用Validation layers的具体实现:
VkResult vkCreateInstance(VkInstanceCreateInfo* pCreateInfo,VkAllocationCallbacks* pAllocator,VkInstance* instance) {

    if (pCreateInfo == nullptr || instance == nullptr) {

        log("Null pointer passed to required parameter!");

        return VK_ERROR_INITIALIZATION_FAILED;

    }

    return real_vkCreateInstance(pCreateInfo, pAllocator, instance);

}

5.RenderPass

-Render Pass表示一帧的某个阶段,包含了绘制过程中的很多信息,包括:

 subpass和color attachment,depth stencil attachment 

 Layout和framebuffer attachment的类型

 Render Pass在开始和结束的时候该做什么

 Render Pass影响framebuffer的区域-分块渲染和延迟渲染需要的信息

 Describes the beginning and end of rendering to a framebuffer

-Render passes operate in conjunction with framebuffers

-Framebuffers and graphics pipelines are created based on a specific renderpass object

-app 以subpass为单位记录renderpass的command,在调用beginRenderPass之后,iterating over the subpasses to record commands for that subpass, and then ending the render pass instance

1).RenderPass:a construct that collects all color, depth and stencil attachments and operations modifying them. 
render pass also describes the dependencies between these attachments.

2).Subpass:consists of drawing operations that use (more or less) the same attachments.
each of these drawing operations may read from some  input attachments and render into some other (color, depth, stencil) attachments. 

6. image & image views 

-In Vulkan, we don’t operate on images themselves. Images are not accessed directly.  For this purpose, image views are used. 

-Image views represent images, they “wrap” images and provide additional data for them.
-Before we can create a framebuffer, we must create image views.

-用vkGetSwapchainImagesKHR来获取swapchain中的image,然后用vkCreateImageView来创建imageview,后面的内容中imageview会被作为颜色attachments与渲染管线配合使用

-imageview被作为attachments的作参数用来创建framebuffer:vkCreateFramebuffer

7.Shader Module

Shader module was created from shader source code. It contains shader code and entrypoints used in pipeline. 

Which was needed by shaderStages in creating a pipeline.

shader module包含shader code和该shader在pipeline中的入口

该module会被用来创建shader stage,然后再创建pipeline

shader stage指定pipeline要完成哪些shader运算

8.Command pools 

-opaque objects that command buffer memory is allocated from

9.descriptor

-A descriptor is an opaque data structure representing a shader resource such as a buffer view, image view, sampler, or combined image sampler.

-Vulkan资源都用descriptor表示, descriptor分成descriptor set,descriptor set从descriptor pool分配。

-每个descriptor set都有个layout布局,布局是在pipeline创建的时候确定的。layout在descriptor set 和pipeline之间共享,并且必须匹配。

-pipeline可以切换使用相同layout的descriptor set。多个不同layout的set可以组成链在一个pipeline中使用。

-Once allocated, descriptor sets can be updated with a combination of write and copy operations


10.vkQueuePresentKHR 


-calling vkQueuePresentKHR will result in Vulkan sending wl_surface.commit requests to the underlying wl_surface of each VkSwapchainKHR objects eferenced by pPresentInfo

-vkAcquireNextImageKHR is only called once, to obtain the presentable image This presentable image is then shared between the application and compositor

-vkQueuePresentKHR used as trigger call for new content

11.swapChain

-provides the ability to present rendering results to a surface

-an abstraction f
c500
or an array of presentable images that are associated with a surface

-app renders to the image, and then queues the image for presentation to the surface

-One image (which can be an array image for multiview/stereoscopic-3D surfaces) is displayed at a time

-A native window cannot be associated with more than one swapchain at a time

12.others

1).创建renderpass的时候,需要创建subpass和AttachmentDescription

2).创建VkFramebuffer的时候,需要绑定VkRenderPass,vkCmdBeginRenderPass的时候需要指定刚才创建的VkFramebuffer

3).shader通过vkCreateShaderModule创建,之后通过VkGraphicsPipelineCreateInfo传给vkCreateGraphicsPipelines来创建pipeline

4).texture通过vkCreateImage创建,tex_memory=vkAllocateMemory创建一块memory然后绑定到texture
addr=vkMapMemory(tex_memory),之后,host端即可写入addr来输入texture数据

13.buffer & image

-Vulkan supports two primary resource types: Buffers, Images

-Buffers are unformatted array of bytes,often used for:Index/Vertex Buffers

-Images contain format information and can be multidimensional:Textures,Render Targets: Color and Depth-Stencil

-VkBuffer must be bound to a single VkDeviceMemory object before used

14.Pipeline Cache

-Result of the pipeline construction can be re-used between pipelines

-Can be stored out to disk and re-used next time you run the application

15.Command buffers and submission

-Work is explicitly recorded to and submitted from a VkCommandBuffer.

-A VkCommandBuffer isn't created directly, it is allocated from a VkCommandPool. This allows for better threading behaviour since command buffers and command pools must be externally synchronised. You can have a pool per thread and vkAllocateCommandBuffers()/vkFreeCommandBuffers()
command buffers from it without heavy locking.

-Command buffers are submitted to a VkQueue.  A VkPhysicalDevice  can report a number of queue families.

-multiple queues must be synchronised against each other as they can run out of order or in parallel to each other.

-You can vkQueueSubmit several command buffers at once to the queue and they will be executed in turn. 

16.Binding Model

-Each shader stage has its own namespace, so pixel shader texture binding 0 is not vertex shader texture binding0.

-Each resource type is namespaced apart, so constant buffer binding 0 is definitely not the same as texture binding0.

-Resources are individually bound and unbound to slots 

-In Vulkan, the base binding unit is a descriptor. A descriptor is an opaque representation that stores 'one bind'. This  could be an image, a sampler, a uniform/constant buffer

-Descriptors aren't bound individually, they are bound in blocks in a VkDescriptorSet which each have a particular VkDescriptorSetLayout. The VkDescriptorSetLayout describes the types of the individual bindings in each VkDescriptorSet.

<The easiest way I find to think about this is consider VkDescriptorSetLayout as being like a C struct type - it describes some members, each member having an opaque type (constant buffer, load/store image, etc). The VkDescriptorSet is a specific instance of
that type - and each member in the VkDescriptorSet is a binding you can update with whichever resource you want it to contain>

17.Synchronisation

-if you try to use the same VkQueue on two different threads

-Vulkan has VkEvent, VkSemaphore and VkFence which can be used for efficient CPU-GPU and GPU-GPU synchronisation.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  vulkan