08/15/2020
管道动态状态
**不需要重新创建管道,就可以改变之前已经设置好的状态。**直接使用命令缓冲区里的命令在运行时改变,而不是通过用不同的对象。许愿在管道阶段设置动态状态,VkGraphicsPipelineCreateInfo的成员pDyanmicState做到。
VkPipelineViewportStateCreateInfo pipelineViewportStateCreateInfo {
};
pipelineViewportStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
pipelineViewportStateCreateInfo.viewportCount = 1;
pipelineViewportStateCreateInfo.scissorCount = 1;
std::vector<VkDynamicState> dynamicStateEnables = {
VK_DYNAMIC_STATE_VIEWPORT, //设置动态状态 视口矩阵
VK_DYNAMIC_STATE_SCISSOR, //裁剪矩阵
VK_DYNAMIC_STATE_LINE_WIDTH, //线段宽度
};
//动态状态的描述信息
VkPipelineDynamicStateCreateInfo dynamicState = pipelineDynamicStateCreateInfo(dynamicStateEnables);
inline VkPipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(
const std::vector<VkDynamicState>& pDynamicStates,
VkPipelineDynamicStateCreateFlags flags = 0)
{
VkPipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo{
};
pipelineDynamicStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
pipelineDynamicStateCreateInfo.pDynamicStates = pDynamicStates.data();
pipelineDynamicStateCreateInfo.dynamicStateCount = static_cast<uint32_t>(pDynamicStates.size());
pipelineDynamicStateCreateInfo.flags = flags;
return pipelineDynamicStateCreateInfo;
}
最后在命令缓冲区阶段可以更改动态状态。
管道绑定
VkGraphicsPipelineCreateInfo pipeline;
pipelineCI.pDynamicState = &dynamicState;
创建多个管道:派生法
创建三个管道,分别对应三个不同的视口,并在绑定命令时候做出改变。
首先声明三个管道,分别是:
- phong 正常光线
- wireframe 线框模式
- toon
struct {
VkPipeline phong;
VkPipeline wireframe;
VkPipeline toon;
} pipelines;
void preparePipelines()
{
VkGraphicsPipelineCreateInfo pipelineCreateInfo {
};
pipelineCreateInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
pipelineCreateInfo