VulkanTutorial icon indicating copy to clipboard operation
VulkanTutorial copied to clipboard

Elaborate on transient attachment bit in multisampling chapter

Open Overv opened this issue 6 years ago • 6 comments

@kondrak Could you add some details about why VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT is used for the color resources? See also this comment.

Overv avatar Jan 06 '19 17:01 Overv

Sure, I'll have a look into it this week.

kondrak avatar Jan 07 '19 19:01 kondrak

@kondrak Would you have time for this soon?

Overv avatar Apr 28 '19 17:04 Overv

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

prideout avatar Aug 14 '20 21:08 prideout

Oh wow, I missed being called out here completely :( I'll try to look into it after I'm back from vacation.

kondrak avatar Aug 15 '20 06:08 kondrak

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.

maltekliemann avatar Oct 28 '20 18:10 maltekliemann