vulkan实践篇

大致流程图:

值得注意的是:

Vulkan是一个发展中的渲染API库,为了保持蓬勃的发展,vulkan给很多api提供了可扩展的pNext以便将来扩展。

Instance

用来连接应用程序与vulkan库的桥梁。设置变量引擎名称,版本号,库api版本号。

提供了扩展用的接口,比如validation layers与其他api交互比如glfw。其中扩展的功能使用layer来封装的。

There were formerly two different types of validation layers in Vulkan: instance and device specific. The idea was that instance layers would only check calls related to global Vulkan objects like instances, and device specific layers would only check calls related to a specific GPU. Device specific layers have now been deprecated, which means that instance validation layers apply to all Vulkan calls. The specification document still recommends that you enable validation layers at device level as well for compatibility, which is required by some implementations.

其中基础扩展分为:

·基础层属性扩展:

Vulan提供的基础扩展功能

VulkanRHI::vkEnumerateInstanceExtensionProperties(LayerName, &Count, nullptr)

·其他Layer属性扩展

先获取其他layer层

VulkanRHI::vkEnumerateInstanceLayerProperties(&InstanceLayerCount, nullptr)

接着获取每层的属性扩展:

除了第一个是基础层灭有名称,其他的都有了。

PysicalDev && Device

前者可以有多个后者,或者成为逻辑设备,Device生产出Queue,同事Queue有影响PysicalDev 的选择。

vkGetDeviceQueue(logDevice, indices.graphicsFamily.value(), 0, &graphicsQueue);//一个quequefamily可以有多个queque,获取第一个queque

旧版本Device也可以有扩展,为了兼容也需要设置一下。

Window surface

Vulkan 不直接提供与平台窗口交互功能。影响device选择。应该再instance创建后确定。Vulkan只提供了抽象的对象VkSurfaceKHR surface;

Swapchain

一个队列的图片,需要呈现到窗口上。把画面发送呈现到屏幕上。

设置 图片格式

控制显示方式

控制显示在屏幕上的像素大小

控制显示用的图像数量

控制队列队列的共享状态

它的主要作用commandbuffer 需要获取绘制的图像,绘制完毕后需要显示图像。

VkCommand

Vulkan把执行的每一步骤,通过命令的形式,放到一个队列里面,其中包括:包括开始渲染pass,绑定管线,绑定descriptorsets,设置viewport,绘制图元命令等,所有发送给GPU的命令记录在commandbuffer()里面。Commandbuffer有一个启始状态,

调用vkBeginCommandBuffer表示状态就绪。接着通过 vkCmdXXXXX函数把命令放进去,最后调用vkEndComamndBuffer()表示命令已经记录完毕,开始进入执行状态,执行状态是开始往GPU上传命令,通过调用vkQueueSubmit()来实现。vkQueueSubmit可以接收多个command buffers。一旦命令提交到GPU上去后,什么时候执行完毕是不确定的,如果这个时候对提交的命令进行修改仍然是有效的,那么要注意了,防止本地修改出现意想不到的情况。

Renderpasses

告诉vulkan framebuffer里面渲染的时候需要什么,需要神马样子的,多少color和depth buffer,采样的时候采多少样本,他们在渲染的时候如何操作的。

Vulkan 中所有的命令都发生在renderpass中,renderpass 包含了要渲染的图形的状态。它存在的意义就是让驱动了解你要渲染的图形的状态。Renderpass 渲染到Framebuffer中,Framebuffer连接着渲染的图像。因此renderpass要在framebuffer之前创建。

Subpass

Famebuffer

正式绘制:

成功显示:

漏写

submitInfo.waitSemaphoreCount = 1;

Semaphores

GPU中执行,用于同步queqe操作

Fences

Cpu上执行,用来等待gpu执行完毕。

CPU 内存:

For a more concrete example, consider a standard PC setup with a discrete GPU. The device has its own local RAM, but the discrete GPU can also access CPU memory. So a Vulkan device will have two heaps: one of them will be local, the other non-local.

Host coherent 内存:没有被cache的内存。

Host visible 内存:没有被cache的内存。可以被vkMapMemory 映射的内存.

Memory that is host-coherent and host-visible would represent memory that either:

Is not cached by the CPU, and therefore the GPU sees the memory as it is. This also means that CPU writes and reads tend to be slow.

The GPU can directly access the CPU's caches, to one degree or another.

Usually, #2 happens when the GPU is on-die with the CPU. Which would also mean that this would be device-local memory. Since you've said that it isn't device-local, odds are good that it is simply not cached. It may use write-combining (which improves the efficiency of sequential writes), but CPU writes otherwise are delivered as they are. Given that the memory does not seem to include "cached" in its description, I'd say #1 is the most likely.

Note that just because you don't need to explicitly flush memory does not change the fact that you still need a dependency between the CPU operation writing that data and the GPU command(s) that read it. This would generally be some from of event with a memory dependency.

Optization vs linear layout:

The reason GPUs like image tiling to be "OPTIMAL" is for texel filtering. Consider a simple linear filter, the resulting value will have four texels contributing from a 2×2 quad. If the texels were in "LINEAR" tiling, the two texels on the lower row (i.e. at y+1) would be very far away in memory from the two texels on the upper row. In "OPTIMAL" tiling texel addresses are closer based on x and y distance.

CPU往GPU传送数据的时候,之所有需要map 一下,是因为灭有办法直接让指针指向gpu中内存,只能先映射出一块区域表示对应gpu中内存,然后通过指针往这块映射的内存中填充数据。

Descriptor set

是为了让shader自由访问外部资源。比如buffer或者image。

为什么需要它,因为当需要往gpu里面传送 一个数组或者图片,用指针指向一个buffer,时候push constant无法做到。

表示 descriptor set 的机构Descriptset layout需要传送给piepline layout,告诉它,desciptor set长相

属性:

Descriptorsetlayout :hold 长相,放入 pipline当中。

VkDescriptorSet :hold 数据buffer。

具体使用的方法:

vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, object.material->pipelineLayout, 0, 1, &get_current_frame().globalDescriptor, 0, nullptr);

发表回复

相关推荐

川麻開局打法淺談

“ 會打麻將的人,在碼好牌的時刻就已經構思好瞭胡哪張牌瞭。” 上次的文章主要講瞭一些我自己打牌的一個思路,不迷信運氣,...

· 26分钟前

厲害!新西蘭小黑本,全球排第5名!免簽187個……

你手上的小黑本能帶你去全球哪些地方呢?全球第5!可免簽187個國傢和地區。▼今年第三季度,亨利護照指數(Henley Passport In...

· 30分钟前

Bio-Share 工艺验证 | 生物制药的工艺性能确认(PPQ)

随着工艺验证进入QbD时代,FDA的新工艺验证指南将工艺验证分为三个阶段,今天我们要讲述的工艺性能确认(PPQ)是阶段2(工艺 ...

· 1小时前

安全可靠,租房就選巴樂兔

最近看瞭很多租房分享,安全性是大傢提到最多的一個問題,這個安全不僅是包含房子本身硬件條件上的安全,還包括小區環境以及...

· 1小时前

老爺車 古董車歷史著名品牌介紹 ——福特(FORD)(二)

上期我們講瞭關於福特這個品牌的創始人——亨利·福特的故事,今天我們就來講講一個福特品牌中不可或缺的車系,也是在福特汽車的...

· 1小时前