When to use VK_IMAGE_LAYOUT_GENERAL

I don’t understand when it is recommended to use VK_IMAGE_LAYOUT_GENERAL, and not go to the optimal layout for any action that I intend to perform. My current policy is to always go for the optimal layout.

But there is VK_IMAGE_LAYOUT_GENERAL. Perhaps I should use it when I use this layout for a short period of time.

For example, right now I am writing code to create mipmaps using vkCmdBlitImage. When I iterate over the sub-resources that execute the vkCmdBlitImage commands, should I go to VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL when I zoom out to mip and then go to VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL when I get all the last ADAM_ERAYTIM_ERAY_IME_ERIT_ERIT_ERIT_ERIT_ERIM_ERIT__IMER_ERIT_ALT__IMER_ERIT_ALT. It seems that a lot of transitions and maybe generating mips in VK_IMAGE_LAYOUT_GENERAL is better.

I understand that the answer can be measured, but it is difficult to measure on all of my target GPUs (especially because I still have nothing working on Android), so if someone has a decent rule of thumb, it will be much appreciated.

FWIW, I am writing Vulkan code that will run on desktop GPUs and Android, but I mostly care about the performance on the latter.

+5
source share
2 answers

You would use this when:

  • You are lazy
  • You need to map the memory to the host (if you cannot use PREINITIALIZED)
  • When you use an image as several incompatible attachments and you have no choice
  • To save images

(5. Other cases where you have switched too many layouts (and you don’t even need barriers) regarding the work performed on the images. In this case, it is better to take a measurement to confirm GENERAL. Most likely, premature optimization even then.)

PS: You can transfer all mip cards together to TRANSFER_DST with one command in advance, and then only the one you need for SRC. If you have a decent hard drive, it is even better to have them using mip-cards, if this is an option (and, possibly, even the best quality using a complex algorithm).

PS2: Too bad, there is no command to create a mip card. CmdBlit most likely still works under the hood for images smaller than half resolution ....

+5
source

If you are reading from mipmap [n] images to create an mipmap [n + 1] image, then you should use image transfer flags if you want your code to work on all Vulkan implementations and get maximum performance in all implementations, flags can be used GPU to optimize the image for reading or writing.

So, if you want to switch to another provider, use only VK_IMAGE_LAYOUT_GENERAL to set up a handle that uses the final image, not an image that reads or writes.

If you do not want to use many transitions, you can copy from the buffer instead of the image, although you obviously will not get the format conversion, scaling, and filtering that vkCmdBlitImage does for you for free.

Also, be sure to check if the target format supports the BLIT_SRC or BLIT_DST bits. It doesn’t depend on whether you use hyphenation or the general layout for copies.

+2
source

All Articles