目录
Conditional Rendering
prepare
- loadAssets:加载模型(有很多部件组成)\
- prepareConditionalRendering: 条件渲染重点设置
- vkCmdBeginConditionalRenderingEXT
- 加载扩展
- vkCmdEndConditionalRenderingEXT
-
- 加载扩展
-
- 创建 Conditional Rendering 使用的缓冲区, 条件数值类型为32 bits,如果为零,则放弃渲染命名.
- createBuffer: std::vector<int32_t> conditionalVisibility;
- loop: 初始化条件为true
- conditionalVisibility[i] = 1;
- updateConditionalBuffer
- memcpy : 复制数据
- vkCmdBeginConditionalRenderingEXT
- prepareUniformBuffers
- createBuffer
- updateUniformBuffers
- setupDescriptorSets
- vkCreateDescriptorPool
- vkCreatePipelineLayout
- vkAllocateDescriptorSets
- writeDescriptorSet
- vkUpdateDescriptorSets
- setupDescriptorSetLayout
- descriptorSetLayoutBinding
- vkCreateDescriptorSetLayout
- vkCreatePipelineLayout
- preparePipelines
-vkCreateGraphicsPipelines - buildCommandBuffers
- loop
- vkBeginCommandBuffer
- vkCmdBeginRenderPass
- vkCmdSetViewport
- vkCmdSetScissor
- vkCmdBindDescriptorSets
- vkCmdBindPipeline
- vkCmdBindVertexBuffers
- vkCmdBindIndexBuffer
- renderNode: 本节重点, 设置条件渲染和常量
- loop mesh
- vkCmdBindDescriptorSets
- vkCmdPushConstants
- Setup the conditional rendering
- VkConditionalRenderingBeginInfoEXT
- vkCmdBeginConditionalRenderingEXT
- vkCmdDrawIndexed
- vkCmdEndConditionalRenderingEXT
- loop mesh
- drawUI
- vkCmdEndRenderPass
- vkEndCommandBuffer
- 重写 OnUpdateUIOverlay
- 修改conditionalVisibility[i] 的值
- updateConditionalBuffer 即可
- loop
render
- draw
- prepareFrame
- vkQueueSubmit
- submitFrame
- updateUniformBuffers
shader
- 正常渲染模型即可, 注意常量的使用
小结
本节主要讲 Conditional Rendering 扩展使用方法。 该参数在prepare中初始化, 在渲染循环中更新.
Debug Markers
接口弃用, 暂时忽略, 后期补充
Negative Viewport Height
prepare
- loadAssets:加载两张贴图, 创建两个y值相反的四边形
- setupDescriptors
- descriptorSetLayoutBinding
- vkCreateDescriptorSetLayout
- vkCreatePipelineLayout
- vkCreateDescriptorPool
- vkAllocateDescriptorSets
- writeDescriptorSet
- vkUpdateDescriptorSets
- preparePipelines
-vkCreateGraphicsPipelines - buildCommandBuffers
- loop
- vkBeginCommandBuffer
- vkCmdBeginRenderPass
- Viewport setup: 本节重点
- VkViewport viewport{}
- if negativeViewport
- yes
- viewport.y = (float)height - offsety;
- viewport.height = -(float)height;
- no
- viewport.y = offsety;
- viewport.height = (float)height;
- yes
- vkCmdSetViewport
- vkCmdSetScissor
- vkCmdBindDescriptorSets
- vkCmdBindIndexBuffer
- vkCmdBindVertexBuffers
- vkCmdDrawIndexed
- vkCmdBindDescriptorSets
- vkCmdBindIndexBuffer
- vkCmdDrawIndexed
- drawUI
- vkCmdEndRenderPass
- vkEndCommandBuffer
- 重写 OnUpdateUIOverlay
- 根据界面选择渲染方式重写创建commandbuffer和pipeline
- buildCommandBuffers
- preparePipelines
- 根据界面选择渲染方式重写创建commandbuffer和pipeline
- loop
render
- draw
- prepareFrame
- vkQueueSubmit
- submitFrame
shader
- 正常渲染模型即可
小结
本节主要讲兼容其他渲染管线的设置方法, 实际开发中经常遇到这种情况, vulkan建议的处理方式是, 重新创建commandbuffer 和 pipeline.
Variable Rate Shading
prepare
- loadAssets:加载场景资源
- 开启ShadingRate扩展
- vkCmdBindShadingRateImageNV
- vkGetDeviceProcAddr
- vkGetPhysicalDeviceProperties2
- vkCmdBindShadingRateImageNV
- prepareShadingRateImage: 本節重點
- 着色率图像大小取决于着色率纹理大小
- kExtent3D imageExtent
- vkCreateImage
- vkGetImageMemoryRequirements
- vkAllocateMemory
- vkBindImageMemory
- vkCreateImageView
- 使用尽可能低的着色速率填充图案
- memset(shadingRatePatternData, val, bufferSize)
- 创建一个向外降低采样率的圆形图案
- std::map<float, VkShadingRatePaletteEntryNV> patternLookup
- vkCreateBuffer: stagingBuffer
- vkGetBufferMemoryRequirements
- vkAllocateMemory
- vkBindBufferMemory
- vkMapMemory
- memcpy
- vkUnmapMemory
- delete[] shadingRatePatternData
- Upload
- createCommandBuffer
- vkCmdPipelineBarrier
- vkCmdCopyBufferToImage
- vkCmdPipelineBarrier
- flushCommandBuffer
- vkFreeMemory
- vkDestroyBuffer
- prepareUniformBuffers
- updateUniformBuffers
- setupDescriptors
- descriptorSetLayoutBinding
- vkCreateDescriptorSetLayout
- vkCreatePipelineLayout
- vkCreateDescriptorPool
- vkAllocateDescriptorSets
- writeDescriptorSet
- vkUpdateDescriptorSets
- preparePipelines
- SpecializationData: 一個特殊的常量
- specializationMapEntry:alphaMask
- specializationMapEntry:alphaMaskCutoff
- shaderStages[1].pSpecializationInfo = &specializationInfo
- Create pipeline without shading rate
- vkCreateGraphicsPipelines
- vkCreateGraphicsPipelines
- Create pipeline with shading rate enabled: 本節重點
- const std::vector shadingRatePaletteEntries
- VkShadingRatePaletteNV
- VkPipelineViewportShadingRateImageStateCreateInfoNV
- vkCreateGraphicsPipelines
- vkCreateGraphicsPipelines
- SpecializationData: 一個特殊的常量
- buildCommandBuffers
- loop
- vkBeginCommandBuffer
- vkCmdBeginRenderPass
- vkCmdSetViewport
- vkCmdSetScissor
- vkCmdBindDescriptorSets
- Bind the image that contains the shading rate patterns
- vkCmdBindShadingRateImageNV
- Render the scene: enableShadingRate選擇pipeline
- vkCmdBindPipeline
- draw
- vkCmdBindPipeline
- draw
- drawUI
- vkCmdEndRenderPass
- vkEndCommandBuffer
- 重写 OnUpdateUIOverlay
- buildCommandBuffers
- loop
render
- renderFrame
- prepareFrame
- vkQueueSubmit
- submitFrame
- updateUniformBuffers
shader
- VS: 正常渲染
- FS:
- 開啓采樣率擴展
- #extension GL_NV_shading_rate_image : require
- 常量的獲取
- layout (constant_id = 0) const bool ALPHA_MASK = false;
- layout (constant_id = 1) const float ALPHA_MASK_CUTOFF = 0.0f;
- gl_FragmentSizeNV:读取以像素为单位的有效片段大小
- 開啓采樣率擴展
小结
本节主要讲Variable Rate Shading 设置方法, 自己的翻译可能不是很恰当, 但是感觉网络上的翻译也不是太合适, 这是一个近几年提出的概念. 从本节程序上看, 开启采样率扩展能提高渲染的性能. 同时渲染结果的质量会变差. 毕竟这有点像可控降采样.