Must a Vulkan pipeline be recreate when changing the size of the window?

…衆ロ難τιáo~ 提交于 2019-12-11 06:05:32

问题


As shown at https://vulkan-tutorial.com/code/23_texture_image.cpp: Calling createGraphicsPipeline() to recreate the Pipeline when changing the window size, the dimensions are set in the code below.

VkViewport viewport = {};
viewport.x = 0.0f;
viewport.y = 0.0f;
viewport.width = (float) swapChainExtent.width;
viewport.height = (float) swapChainExtent.height;
viewport.minDepth = 0.0f;
viewport.maxDepth = 1.0f;

VkRect2D scissor = {};
scissor.offset = {0, 0};
scissor.extent = swapChainExtent;

VkPipelineViewportStateCreateInfo viewportState = {};
viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
viewportState.viewportCount = 1;
viewportState.pViewports = &viewport;
viewportState.scissorCount = 1;
viewportState.pScissors = &scissor;

If the scene contains lots of materials, changing the window size will recreate all materials, which is very time consuming. Can I modify their VkRect2D and VkViewport directly without recreate the pipeline?


回答1:


You'd have to make the scissor and viewport dynamic state in all the pipelines where they will depend on the window size. To do this:

  1. Fill in VkGraphicsPipelineCreateInfo::pDynamicState with VK_DYNAMIC_STATE_VIEWPORT and VK_DYNAMIC_STATE_SCISSOR in VkPipelineDynamicStateCreateInfo::pDynamicStates.

  2. After binding a pipeline with dynamic viewport and scissor state, call vkCmdSetViewport and vkCmdSetScissor to set the current viewport and scissor. You don't have to call these again after every binding each pipeline, only for the first dynamic-state pipeline in a command buffer, and after a dynamic-state pipeline if the previous pipeline didn't use dynamic state.



来源:https://stackoverflow.com/questions/57950008/must-a-vulkan-pipeline-be-recreate-when-changing-the-size-of-the-window

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!