如何处理可呈现的图像的布局?[英] How to deal with the layouts of presentable images?

本文是小编为大家收集整理的关于如何处理可呈现的图像的布局?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

VK_IMAGE_LAYOUT_UNDEFINED以VK_IMAGE_LAYOUT_UNDEFINED的形式开始,但在出现一次后将是VK_IMAGE_LAYOUT_PRESENT_SRC_KHR.

创建vkSwapchain后,许多示例都会立即将所有vkImages过渡到VK_IMAGE_LAYOUT_PRESENT_SRC_KHR.这使他们可以将VK_IMAGE_LAYOUT_PRESENT_SRC_KHR用于oldLayout. in swapchain is of Swapchain is of Swapchain is of Swapchain is of Swapchain is of Swapchain is of Swapchain不允许.

仅在图像由vkAcquireNextImageKHR返回图像之后,并且在由vkQueuePresentKHR提出之前才能使用. 这包括过渡图像布局和渲染命令.

我有什么选择正确处理Swapchain图像布局?

推荐答案

有3个选项.从最佳到最差的订购(IMO):

  1. 只需将renderpass中附件的初始layout设置为VK_IMAGE_LAYOUT_UNDEFINED或每次从VK_IMAGE_LAYOUT_UNDEFINED过渡. 这是允许的和和 您不在乎图像中仍在的数据.大多数情况下,您无论如何都会清除或完全覆盖图像.

    有效用法 [vkimagememorybarrier]
    [...]

    • oldlayout必须为VK_IMAGE_LAYOUT_UNDEFINED,VK_IMAGE_LAYOUT_PREINITIALIZED或受屏障影响的图像区域的当前布局
  2. 记录命令buffer时已经通过管道已经通过管道了,并相应地选择oldLayout.

  3. 在创建Swapchain之后进行过渡,但使用vkAcquireNextImageKHR和vkQueuePresentKHR来确保应用程序在过渡时拥有图像.无法保证您获得图像的顺序,因此可能永远不会返回一个图像.

其他推荐答案

我一直在尝试第四个选项,但是关于其有效性的一些输入将很有用.创建Swapchain时,图像在VK_IMAGE_LAYOUT_UNDEFINED中,对我来说似乎表明它们都可以在应用程序中使用,因为它们需要VK_IMAGE_LAYOUT_PRESENT_SRC_KHR进行演示,因此不应显示或排队.我在规格中没有发现任何可以保证这一点的东西.

规格说,如果需要,我们可以从Swapchain获取多个图像:

如果Swapchain具有足够的图像,则应用程序可以获取多个图像,而无需介入vkqueuepresentkhr.应用程序可以以与获取的顺序不同的顺序显示图像.

使用上面的结论,我刚刚称为vkAcquireNextImageKHR以获取Swapchain的所有图像,并立即更改了所有图像.之后,我介绍了所有这些,可以说是将它们带入系统.

从某种意义上说,所有图像都是由Swapchain交给我的,但是再说一次,我不能保证所有图像在创建Swapchain后实际上可以立即获得.

本文地址:https://www.itbaoku.cn/post/2091200.html

问题描述

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.

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.

Use of a presentable image must occur only after the image is returned by vkAcquireNextImageKHR, and before it is presented by vkQueuePresentKHR. This includes transitioning the image layout and rendering commands.

What are my options to deal with the swapchain image layouts correctly?

推荐答案

There are 3 options. Ordered from best to worst (IMO):

  1. Simply set the initialLayout of the attachment in the renderPass to VK_IMAGE_LAYOUT_UNDEFINED or transition from VK_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.

    valid Usage [of VkImageMemoryBarrier]
    [...]

    • oldLayout must be VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_PREINITIALIZED or the current layout of the image region affected by the barrier
  2. Keep track of which images have been through the pipeline already and select the oldLayout accordingly when recording the commandBuffer.

  3. 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.

其他推荐答案

I've been trying a fourth option but some input on its validity would be useful. When creating the swapchain the images are in VK_IMAGE_LAYOUT_UNDEFINED, which to me seems to indicate that they're all available to the application because they need VK_IMAGE_LAYOUT_PRESENT_SRC_KHR for presentation and so shouldn't be displayed or in queue. I didn't find anything in the spec that would guarantee this however.

The spec says that we can acquire multiple images from the swapchain if we want:

If a swapchain has enough presentable images, applications can acquire multiple images without an intervening vkQueuePresentKHR. Applications can present images in a different order than the order in which they were acquired.

Using the conclusion above I just called vkAcquireNextImageKHR to get every image of the swapchain and changed layout on all of them at once. After that I presented all of them to get them into the system so to speak.

It seems to work in the sense that all images are handed to me by the swapchain, but then again, I found no guarantee that all of them can actually be acquired immediately after creating the swapchain.