A range of a VkDeviceMemory
allocation is aliased if it is bound to
multiple resources simultaneously, via vkBindImageMemory
,
vkBindBufferMemory
, or via sparse memory bindings.
A memory range aliased between two images or two buffers is defined to be
the intersection of the memory ranges bound to the two resources.
A memory range aliased between two resources where one is a buffer or a
linear image, and the other is an optimal image, is defined to be the
intersection of the memory ranges bound to the two resources, where each
range is first padded to be aligned to the bufferImageGranularity
.
Applications can alias memory, but use of multiple aliases is subject to
several constraints.
![]() | Note |
---|---|
Memory aliasing can be useful to reduce the total device memory footprint of an application, if some large resources are used for disjoint periods of time. |
When an opaque, non-VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT
image is
bound to an aliased range, all image subresources of the image overlap the
range.
When a linear image is bound to an aliased range, the image subresources
that (according to the image’s advertised layout) include bytes from the
aliased range overlap the range.
When a VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT
image has sparse image
blocks bound to an aliased range, only image subresources including those
sparse image blocks overlap the range, and when the memory bound to the
image’s mip tail overlaps an aliased range all image subresources in the mip
tail overlap the range.
Buffers, and linear image subresources in either the
VK_IMAGE_LAYOUT_PREINITIALIZED
or VK_IMAGE_LAYOUT_GENERAL
layouts, are host-accessible subresources.
That is, the host has a well-defined addressing scheme to interpret the
contents, and thus the layout of the data in memory can be consistently
interpreted across aliases if each of those aliases is a host-accessible
subresource.
Opaque images and linear image subresources in other layouts are not
host-accessible.
If two aliases are both host-accessible, then they interpret the contents of the memory in consistent ways, and data written to one alias can be read by the other alias.
If either of two aliases is not host-accessible, then the aliases interpret the contents of the memory differently, and writes via one alias make the contents of memory partially or completely undefined to the other alias. If the first alias is a host-accessible subresource, then the bytes affected are those written by the memory operations according to its addressing scheme. If the first alias is not host-accessible, then the bytes affected are those overlapped by the image subresources that were written. If the second alias is a host-accessible subresource, the affected bytes become undefined. If the second alias is a not host-accessible, all sparse image blocks (for sparse partially-resident images) or all image subresources (for non-sparse image and fully resident sparse images) that overlap the affected bytes become undefined.
If any image subresources are made undefined due to writes to an alias, then
each of those image subresources must have its layout transitioned from
VK_IMAGE_LAYOUT_UNDEFINED
to a valid layout before it is used, or from
VK_IMAGE_LAYOUT_PREINITIALIZED
if the memory has been written by the
host.
If any sparse blocks of a sparse image have been made undefined, then only
the image subresources containing them must be transitioned.
Use of an overlapping range by two aliases must be separated by a memory dependency using the appropriate access types if at least one of those uses performs writes, whether the aliases interpret memory consistently or not. If buffer or image memory barriers are used, the scope of the barrier must contain the entire range and/or set of image subresources that overlap.
If two aliasing image views are used in the same framebuffer, then the
render pass must declare the attachments using the
VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT
, and
follow the other rules listed in that section.
Access to resources which alias memory from shaders using variables
decorated with Coherent
are not automatically coherent with each other.
![]() | Note |
---|---|
Memory recycled via an application suballocator (i.e. without freeing and reallocating the memory objects) is not substantially different from memory aliasing. However, a suballocator usually waits on a fence before recycling a region of memory, and signaling a fence involves sufficient implicit dependencies to satisfy all the above requirements. |