VulkanTutorial
VulkanTutorial copied to clipboard
Elaborate on transient attachment bit in multisampling chapter
@kondrak Could you add some details about why VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT is used for the color resources? See also this comment.
Sure, I'll have a look into it this week.
@kondrak Would you have time for this soon?
I think it's not necessary to use TRANSIENT unless the image memory is allocated with VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT, as described near the end of the following article:
https://developer.arm.com/solutions/graphics-and-gaming/developer-guides/learn-the-basics/understanding-render-passes/multi-sample-anti-aliasing
According to the spec:
VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT specifies that the memory bound to this image will have been allocated with the VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT (see https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#memory for more detail). This bit can be set for any image that can be used to create a VkImageView suitable for use as a color, resolve, depth/stencil, or input attachment.
See also:
https://arm-software.github.io/vulkan-sdk/multisampling.html
Oh wow, I missed being called out here completely :( I'll try to look into it after I'm back from vacation.
As @prideout mentioned, using VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT combined with VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT memory is correct. The idea is that lazy memory allocation prevents
allocations for the multisample color attachment, which is only used as a temporary during the render pass, and therefore remains on-chip instead of stored in device memory.
So what really seems to be missing from the tutorial is passing the VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT memory hint to createImage in createColorResoures. I think the same change could be applied to the depth attachment (for the same reasons). Maybe @kondrak can confirm?
Furthermore, the storeOp for the MSAA attachment must be set to DONT_CARE. Otherwise the lazy allocation won't be of much use. Also note that VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT is not always available.
Edit: See Lazily Allocated Memory.