Vulkan SDK 之 Depth Buffer

深度缓冲是可选的,比如渲染一个3D的立方体的时候,就需要用到深度缓冲。Swapchain就算有多个images,此时深度缓冲区也只需要一个。vkCreateSwapchainKHR 会创建所有需要的images, 深度缓冲的image需要你手动创建和分配内存,流程如下:

 

Create the depth buffer image object
Allocate the depth buffer device memory
Bind the memory to the image object
Create the depth buffer image view

Create the Depth Buffer Image Object

1、vkCreateImage仅仅是创建一个image对象,并不分配任何内存;

Allocate the Memory for the Depth Buffer

1、对于同样的image object ,不同显卡所需要分配的内存是不一样的,需要通过vkGetImageMemoryRequirement获取image对象所需的内存;

2、vkAllocateMemory 来分配内存,具体内存的分配策略,可以从vulkan spec里面进行了解。

Bind the Memory to the Depth Buffer

vkBindImageMemory(info.device, info.depth.image, info.depth.mem, 0);


Create the Image View

 

posted on 2020-02-06 14:43  KHacker  阅读(298)  评论(0编辑  收藏  举报