目录
Mip-map Generation
prepare
- loadAssets: 加载模型和纹理
- loadTexture: mip map设置
- level: texture.mipLevels = floor(log2(std::max(texture.width, texture.height))) + 1;
- stagingBuffer的创建:
- vkCreateBuffer - vkGetBufferMemoryRequirements - vkAllocateMemory - vkBindBufferMemory
- vkMapMemory - memcpy - vkUnmapMemory
- 创建image: vkCreateImage - vkGetImageMemoryRequirements - vkAllocateMemory - vkBindImageMemory
- createCommandBuffer
- 0 level mipmap
- vkCmdCopyBufferToImage - insertImageMemoryBarrier - flushCommandBuffer
- vkFreeMemory - vkDestroyBuffer
- mipmap
- createCommandBuffer
- loop
- insertImageMemoryBarrier
- vkCmdBlitImage
- insertImageMemoryBarrier
- insertImageMemoryBarrier
- flushCommandBuffer
- vkCreateSampler: 三组,0 未使用mipmap,1 使用mipmap, 3 使用anisotropic filtering的mipmap
- vkCreateImageView
- loadTexture: mip map设置
- prepareUniformBuffers
- updateUniformBuffers
- setupDescriptorSetLayout
- preparePipelines:
- vkCreateGraphicsPipelines
- setupDescriptorPool
- setupDescriptorSet
- 这是设置samplerDescriptors,将三组Sampler写入
- buildCommandBuffers
render
- draw
- updateUniformBuffers
shader
- texture(sampler2D(textureColor, samplers[inSamplerIndex]), inUV, inLodBias)
- 从samplers数组中根据index分别渲染不同类型的结果
小结
本节主要讲mipmap的生成方式,重点是如何使用 Sampler array进行渲染。
Capturing Screenshots
prepare
- 重写OnUpdateUIOverlay方法,获取截帧事件
- saveScreenshot
- vkCreateImage:用于存储当前帧
- vkGetImageMemoryRequirements- vkAllocateMemory- vkBindImageMemory
- createCommandBuffer
- insertImageMemoryBarrier: image与目标layout绑定
- insertImageMemoryBarrier:swapchain与源绑定
- vkCmdBlitImage:从源向目标写数据
- insertImageMemoryBarrier:目标与image解绑,并恢复到与 general layout绑定
- insertImageMemoryBarrier:源与swapchain解绑,并恢复到与 present layout绑定
- flushCommandBuffer
- vkGetImageSubresourceLayout: 获取图像数据
- vkMapMemory
- std::ofstream file: 写如硬盘
- vkUnmapMemory
- vkFreeMemory
- vkDestroyImage
- saveScreenshot
- loadAssets: 加载模型
- prepareUniformBuffers
- updateUniformBuffers
- setupDescriptorSetLayout
- preparePipelines:
- vkCreateGraphicsPipelines
- setupDescriptorPool
- setupDescriptorSet
- 这是设置samplerDescriptors,将三组Sampler写入
- buildCommandBuffers
render
- draw
shader
- Blinn-Phong模型
小结
本节主要讲截帧方法,重点是如何使用insertImageMemoryBarrier对缓冲区数据进行操作,应用场景非常多。
Order Independent Transparency
prepare
- loadAssets: 加载模型
- prepareUniformBuffers
- updateUniformBuffers
- prepareGeometryPass
- VkSubpassDescription
- Geometry render pass doesn’t need any output attachment
- vkCreateRenderPass
- vkCreateFramebuffer
- createBuffer:创建GeometrySBO使用的buffer
- Using the device memory will be best but I will use the host visible buffer to make this example simple
- memcpy:
- vkCreateImage:创建纹理用于保存索引
- vkGetImageMemoryRequirements-vkAllocateMemory-vkBindImageMemory
- vkCreateImageView
- createBuffer:创建LinkedListSBO使用的buffer
- vkAllocateCommandBuffers-
- vkBeginCommandBuffer
- vkCmdPipelineBarrier
- vkQueueSubmit
- vkQueueWaitIdle
- setupDescriptorSetLayout: 将prepareGeometryPass中创建的buffer绑定到fs阶段
- descriptorSetLayoutBinding
- vkCreatePipelineLayout:多创建一个几何PASS阶段PipelineLayout
- vkCreateDescriptorSetLayout:将几何PASS用到的资源写入
- preparePipelines: 这里需要创建几何PASS的Pipeline
- vkCreateGraphicsPipelines:几何PASS
- vkCreateGraphicsPipelines:FS
- setupDescriptorPool
- 这里新增了两个pool
- VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
- VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
- 这里新增了两个pool
- setupDescriptorSet
- 这里也是两个阶段,一个是几何PASS, 一个是FS
- vkAllocateDescriptorSets: 几何PASS
- Binding 0: RenderPassUBO
- Binding 2: GeometrySBO
- Binding 3: headIndexImage
- LinkedListSBO
- vkUpdateDescriptorSets
- vkAllocateDescriptorSets: FS
- Binding 0: headIndexImage
- Binding 1: LinkedListSBO
- vkUpdateDescriptorSets
- buildCommandBuffers: 这里涉及到透明材质渲染流程,之后需要仔细阅读
- loop
- vkBeginCommandBuffer
- vkCmdSetViewport
- vkCmdSetScissor
- vkCmdClearColorImage
- Begin the geometry render pass
- vkCmdBeginRenderPass
- vkCmdBindPipeline
- bindBuffers(drawCmdBuffers[i]):绑定渲染结果的buffer
- vkCmdBindDescriptorSets
- vkCmdPushConstants:画sphere, 绑定objectData,用于保存场地数据
- vkCmdPushConstants:画cube
- vkCmdEndRenderPass
- vkCmdPipelineBarrier:确保几何PASS完成
- vkCmdBeginRenderPass:渲染pass
- vkCmdBindPipeline
- vkCmdBindDescriptorSets
- vkCmdDraw
- vkCmdEndRenderPass
- loop
- updateUniformBuffers:不理解为什么在这里更新
render
- draw:每次渲染需要清理 geometry pass data
- memset(geometryPass.geometry.mapped, 0, sizeof(uint32_t));
shader
- 几何PASS阶段
- VS: 正常操作,准备资源
- FS:
- layout (set = 0, binding = 1) buffer GeometrySBO: 发现一个buffer绑定项, 之前没用过
- 将结果写入buffer(LinkedListSBO)
- 渲染阶段
- VS: 正常操作,准备资源
- FS:
- layout (set = 0, binding = 1) buffer LinkedListSBO: 绑定buffer
- layout (set = 0, binding = 0, r32ui) uniform uimage2D headIndexImage:uimage2D 没用过
- imageLoad(headIndexImage, ivec2(gl_FragCoord.xy))
析构
- destroyGeometryPass:析构的时候需要清理GeometryPass资源
小结
本节主要讲无规则透明度渲染方法,没有接触的内容很多。多pass共享buffer资源的操作、uimage2D的使用。以后回来多关注一下。