如何处理可呈现图像的布局? [英] How to deal with the layouts of presentable images?
问题描述
可展示的图像从VK_IMAGE_LAYOUT_UNDEFINED
开始,但是在展示一次后将成为VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
.
A presentable image starts out in VK_IMAGE_LAYOUT_UNDEFINED
but will be VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
after they have been presented once.
许多示例在创建vkSwapchain
之后立即将所有vkImages
转换为VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
.这使他们可以将VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
用于oldLayout
. 但是在创建交换链后立即进行过渡是不允许.
A lot of examples do a transition of all vkImages
to VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
immediately after creating the vkSwapchain
. Which allows them to use an VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
for oldLayout
. But doing the transition right after creation of the swapchain is not allowed.
仅在
vkAcquireNextImageKHR
返回图像之后,并且在vkQueuePresentKHR
呈现图像之前,才可以使用可呈现的图像. 这包括转换图像布局和渲染命令.
Use of a presentable image must occur only after the image is returned by
vkAcquireNextImageKHR
, and before it is presented byvkQueuePresentKHR
. This includes transitioning the image layout and rendering commands.
我有哪些正确处理交换链图像布局的选项?
What are my options to deal with the swapchain image layouts correctly?
推荐答案
有3个选项.从最佳到最差(IMO)排序:
There are 3 options. Ordered from best to worst (IMO):
-
只需将renderPass中附件的initialLayout每次设置为
VK_IMAGE_LAYOUT_UNDEFINED
或从VK_IMAGE_LAYOUT_UNDEFINED
过渡. 这是允许的,这意味着您无需担心图像中仍然存在的数据.多数情况下,无论如何,您都会清除或完全覆盖图像.
Simply set the initialLayout of the attachment in the renderPass to
VK_IMAGE_LAYOUT_UNDEFINED
or transition fromVK_IMAGE_LAYOUT_UNDEFINED
every time. This is allowed and will imply that you don't care about the data still in the image. Most often you will be clearing or fully overwriting the image anyway.
有效用法 [属于VkImageMemoryBarrier]
[...]
valid Usage [of VkImageMemoryBarrier]
[...]
- oldLayout必须为
VK_IMAGE_LAYOUT_UNDEFINED
,VK_IMAGE_LAYOUT_PREINITIALIZED
或受栅栏影响的图像区域的当前布局
- oldLayout must be
VK_IMAGE_LAYOUT_UNDEFINED
,VK_IMAGE_LAYOUT_PREINITIALIZED
or the current layout of the image region affected by the barrier
跟踪已通过管道的图像,并在记录commandBuffer时相应地选择oldLayout
.
在创建交换链之后执行转换,但是使用vkAcquireNextImageKHR
和vkQueuePresentKHR
来确保应用程序在转换时拥有映像.无法保证您以什么顺序获得图像,因此有可能一幅图像从不退回.
Do the transitions after creating the swapchain but using vkAcquireNextImageKHR
and vkQueuePresentKHR
to ensure the application owns the image while transitioning. There is no guarantee in which order you get the images So it may be possible one image never gets returned.
这篇关于如何处理可呈现图像的布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!