1e5c31af7Sopenharmony_ci// Copyright 2015-2024 The Khronos Group Inc.
2e5c31af7Sopenharmony_ci//
3e5c31af7Sopenharmony_ci// SPDX-License-Identifier: CC-BY-4.0
4e5c31af7Sopenharmony_ci
5e5c31af7Sopenharmony_ci[[sparsememory]]
6e5c31af7Sopenharmony_ci= Sparse Resources
7e5c31af7Sopenharmony_ci
8e5c31af7Sopenharmony_ciAs documented in <<resources-association,Resource Memory Association>>,
9e5c31af7Sopenharmony_cisname:VkBuffer and sname:VkImage resources in Vulkan must: be bound
10e5c31af7Sopenharmony_cicompletely and contiguously to a single sname:VkDeviceMemory object.
11e5c31af7Sopenharmony_ciThis binding must: be done before the resource is used, and the binding is
12e5c31af7Sopenharmony_ciimmutable for the lifetime of the resource.
13e5c31af7Sopenharmony_ci
14e5c31af7Sopenharmony_ci_Sparse resources_ relax these restrictions and provide these additional
15e5c31af7Sopenharmony_cifeatures:
16e5c31af7Sopenharmony_ci
17e5c31af7Sopenharmony_ci  * Sparse resources can: be bound non-contiguously to one or more
18e5c31af7Sopenharmony_ci    sname:VkDeviceMemory allocations.
19e5c31af7Sopenharmony_ci  * Sparse resources can: be re-bound to different memory allocations over
20e5c31af7Sopenharmony_ci    the lifetime of the resource.
21e5c31af7Sopenharmony_ci  * Sparse resources can: have descriptors generated and used orthogonally
22e5c31af7Sopenharmony_ci    with memory binding commands.
23e5c31af7Sopenharmony_ci
24e5c31af7Sopenharmony_ciifdef::VKSC_VERSION_1_0[]
25e5c31af7Sopenharmony_ciSparse resources are not supported in Vulkan SC, due to complexity and the
26e5c31af7Sopenharmony_cinecessity of being able to update page table mappings at runtime <<SCID-8>>.
27e5c31af7Sopenharmony_ciHowever, the sparse resource features, properties, resource creation flags,
28e5c31af7Sopenharmony_ciand definitions have been retained for completeness and compatibility.
29e5c31af7Sopenharmony_ci
30e5c31af7Sopenharmony_ciAll sparse resource <<sparsememory-physicalfeatures,physical device
31e5c31af7Sopenharmony_cifeatures>> must: not be advertised as supported, and the related
32e5c31af7Sopenharmony_ci<<sparsememory-physicalprops,physical device sparse properties>> and
33e5c31af7Sopenharmony_ci<<limits,physical device limits>> must: be reported accordingly.
34e5c31af7Sopenharmony_ci
35e5c31af7Sopenharmony_ciifdef::hidden[]
36e5c31af7Sopenharmony_ci// tag::scremoved[]
37e5c31af7Sopenharmony_ci  * elink:VkStructureType
38e5c31af7Sopenharmony_ci  ** ename:VK_STRUCTURE_TYPE_BIND_SPARSE_INFO <<SCID-8>>
39e5c31af7Sopenharmony_ci  ** ename:VK_STRUCTURE_TYPE_DEVICE_GROUP_BIND_SPARSE_INFO <<SCID-8>>
40e5c31af7Sopenharmony_ci  ** ename:VK_STRUCTURE_TYPE_IMAGE_SPARSE_MEMORY_REQUIREMENTS_INFO_2
41e5c31af7Sopenharmony_ci     <<SCID-8>>
42e5c31af7Sopenharmony_ci  ** ename:VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SPARSE_IMAGE_FORMAT_INFO_2
43e5c31af7Sopenharmony_ci     <<SCID-8>>
44e5c31af7Sopenharmony_ci  ** ename:VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2 <<SCID-8>>
45e5c31af7Sopenharmony_ci  ** ename:VK_STRUCTURE_TYPE_SPARSE_IMAGE_MEMORY_REQUIREMENTS_2 <<SCID-8>>
46e5c31af7Sopenharmony_ci  * sname:VkSparseImageFormatProperties <<SCID-8>>
47e5c31af7Sopenharmony_ci  * ename:VkSparseImageFormatFlagBits <<SCID-8>>
48e5c31af7Sopenharmony_ci  * tname:VkSparseImageFormatFlags <<SCID-8>>
49e5c31af7Sopenharmony_ci  * fname:vkGetPhysicalDeviceSparseImageFormatProperties <<SCID-8>>
50e5c31af7Sopenharmony_ci  * fname:vkGetPhysicalDeviceSparseImageFormatProperties2 <<SCID-8>>
51e5c31af7Sopenharmony_ci  * sname:VkPhysicalDeviceSparseImageFormatInfo2 <<SCID-8>>
52e5c31af7Sopenharmony_ci  * sname:VkSparseImageFormatProperties2 <<SCID-8>>
53e5c31af7Sopenharmony_ci  * sname:VkSparseImageMemoryRequirements <<SCID-8>>
54e5c31af7Sopenharmony_ci  * fname:vkGetImageSparseMemoryRequirements <<SCID-8>>
55e5c31af7Sopenharmony_ci  * fname:vkGetImageSparseMemoryRequirements2 <<SCID-8>>
56e5c31af7Sopenharmony_ci  * sname:VkImageSparseMemoryRequirementsInfo2 <<SCID-8>>
57e5c31af7Sopenharmony_ci  * sname:VkSparseImageMemoryRequirements2 <<SCID-8>>
58e5c31af7Sopenharmony_ci  * sname:VkSparseMemoryBind <<SCID-8>>
59e5c31af7Sopenharmony_ci  * ename:VkSparseMemoryBindFlagBits <<SCID-8>>
60e5c31af7Sopenharmony_ci  * tname:VkSparseMemoryBindFlags <<SCID-8>>
61e5c31af7Sopenharmony_ci  * sname:VkSparseBufferMemoryBindInfo <<SCID-8>>
62e5c31af7Sopenharmony_ci  * sname:VkSparseImageOpaqueMemoryBindInfo <<SCID-8>>
63e5c31af7Sopenharmony_ci  * sname:VkSparseImageMemoryBindInfo <<SCID-8>>
64e5c31af7Sopenharmony_ci  * sname:VkSparseImageMemoryBind <<SCID-8>>
65e5c31af7Sopenharmony_ci  * fname:vkQueueBindSparse <<SCID-8>>
66e5c31af7Sopenharmony_ci  * sname:VkBindSparseInfo <<SCID-8>>
67e5c31af7Sopenharmony_ci  * sname:VkDeviceGroupBindSparseInfo <<SCID-8>>
68e5c31af7Sopenharmony_ci// end::scremoved[]
69e5c31af7Sopenharmony_ciendif::hidden[]
70e5c31af7Sopenharmony_ciendif::VKSC_VERSION_1_0[]
71e5c31af7Sopenharmony_ci
72e5c31af7Sopenharmony_ci[[sparsememory-sparseresourcefeatures]]
73e5c31af7Sopenharmony_ci== Sparse Resource Features
74e5c31af7Sopenharmony_ci
75e5c31af7Sopenharmony_ciSparse resources have several features that must: be enabled explicitly at
76e5c31af7Sopenharmony_ciresource creation time.
77e5c31af7Sopenharmony_ciThe features are enabled by including bits in the pname:flags parameter of
78e5c31af7Sopenharmony_cislink:VkImageCreateInfo or slink:VkBufferCreateInfo.
79e5c31af7Sopenharmony_ciEach feature also has one or more corresponding feature enables specified in
80e5c31af7Sopenharmony_cislink:VkPhysicalDeviceFeatures.
81e5c31af7Sopenharmony_ci
82e5c31af7Sopenharmony_ci  * The <<features-sparseBinding, pname:sparseBinding>> feature is the base,
83e5c31af7Sopenharmony_ci    and provides the following capabilities:
84e5c31af7Sopenharmony_ci
85e5c31af7Sopenharmony_ci  ** Resources can: be bound at some defined (sparse block) granularity.
86e5c31af7Sopenharmony_ci  ** The entire resource must: be bound to memory before use regardless of
87e5c31af7Sopenharmony_ci     regions actually accessed.
88e5c31af7Sopenharmony_ci  ** No specific mapping of image region to memory offset is defined, i.e.
89e5c31af7Sopenharmony_ci     the location that each texel corresponds to in memory is
90e5c31af7Sopenharmony_ci     implementation-dependent.
91e5c31af7Sopenharmony_ci  ** Sparse buffers have a well-defined mapping of buffer range to memory
92e5c31af7Sopenharmony_ci     range, where an offset into a range of the buffer that is bound to a
93e5c31af7Sopenharmony_ci     single contiguous range of memory corresponds to an identical offset
94e5c31af7Sopenharmony_ci     within that range of memory.
95e5c31af7Sopenharmony_ci  ** Requested via the ename:VK_IMAGE_CREATE_SPARSE_BINDING_BIT and
96e5c31af7Sopenharmony_ci     ename:VK_BUFFER_CREATE_SPARSE_BINDING_BIT bits.
97e5c31af7Sopenharmony_ci  ** A sparse image created using ename:VK_IMAGE_CREATE_SPARSE_BINDING_BIT
98e5c31af7Sopenharmony_ci     (but not ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) supports all
99e5c31af7Sopenharmony_ci     formats that non-sparse usage supports, and supports both
100e5c31af7Sopenharmony_ci     ename:VK_IMAGE_TILING_OPTIMAL and ename:VK_IMAGE_TILING_LINEAR tiling.
101e5c31af7Sopenharmony_ci
102e5c31af7Sopenharmony_ci  * _Sparse Residency_ builds on (and requires) the pname:sparseBinding
103e5c31af7Sopenharmony_ci    feature.
104e5c31af7Sopenharmony_ci    It includes the following capabilities:
105e5c31af7Sopenharmony_ci
106e5c31af7Sopenharmony_ci  ** Resources do not have to be completely bound to memory before use on
107e5c31af7Sopenharmony_ci     the device.
108e5c31af7Sopenharmony_ci  ** Images have a prescribed sparse image block layout, allowing specific
109e5c31af7Sopenharmony_ci     rectangular regions of the image to be bound to specific offsets in
110e5c31af7Sopenharmony_ci     memory allocations.
111e5c31af7Sopenharmony_ci  ** Consistency of access to unbound regions of the resource is defined by
112e5c31af7Sopenharmony_ci     the absence or presence of
113e5c31af7Sopenharmony_ci     sname:VkPhysicalDeviceSparseProperties::pname:residencyNonResidentStrict.
114e5c31af7Sopenharmony_ci     If this property is present, accesses to unbound regions of the
115e5c31af7Sopenharmony_ci     resource are well defined and behave as if the data bound is populated
116e5c31af7Sopenharmony_ci     with all zeros; writes are discarded.
117e5c31af7Sopenharmony_ci     When this property is absent, accesses are considered safe, but reads
118e5c31af7Sopenharmony_ci     will return undefined: values.
119e5c31af7Sopenharmony_ci  ** Requested via the ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT and
120e5c31af7Sopenharmony_ci     ename:VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT bits.
121e5c31af7Sopenharmony_ci  ** [[features-sparseResidency]] Sparse residency support is advertised on
122e5c31af7Sopenharmony_ci     a finer grain via the following features:
123e5c31af7Sopenharmony_ci+
124e5c31af7Sopenharmony_ci  *** The <<features-sparseResidencyBuffer, pname:sparseResidencyBuffer>>
125e5c31af7Sopenharmony_ci      feature provides support for creating sname:VkBuffer objects with the
126e5c31af7Sopenharmony_ci      ename:VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT.
127e5c31af7Sopenharmony_ci  *** The <<features-sparseResidencyImage2D, pname:sparseResidencyImage2D>>
128e5c31af7Sopenharmony_ci      feature provides support for creating 2D single-sampled sname:VkImage
129e5c31af7Sopenharmony_ci      objects with ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT.
130e5c31af7Sopenharmony_ci  *** The <<features-sparseResidencyImage3D, pname:sparseResidencyImage3D>>
131e5c31af7Sopenharmony_ci      feature provides support for creating 3D sname:VkImage objects with
132e5c31af7Sopenharmony_ci      ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT.
133e5c31af7Sopenharmony_ci  *** The <<features-sparseResidency2Samples,
134e5c31af7Sopenharmony_ci      pname:sparseResidency2Samples>> feature provides support for creating
135e5c31af7Sopenharmony_ci      2D sname:VkImage objects with 2 samples and
136e5c31af7Sopenharmony_ci      ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT.
137e5c31af7Sopenharmony_ci  *** The <<features-sparseResidency4Samples,
138e5c31af7Sopenharmony_ci      pname:sparseResidency4Samples>> feature provides support for creating
139e5c31af7Sopenharmony_ci      2D sname:VkImage objects with 4 samples and
140e5c31af7Sopenharmony_ci      ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT.
141e5c31af7Sopenharmony_ci  *** The <<features-sparseResidency8Samples,
142e5c31af7Sopenharmony_ci      pname:sparseResidency8Samples>> feature provides support for creating
143e5c31af7Sopenharmony_ci      2D sname:VkImage objects with 8 samples and
144e5c31af7Sopenharmony_ci      ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT.
145e5c31af7Sopenharmony_ci  *** The <<features-sparseResidency16Samples,
146e5c31af7Sopenharmony_ci      pname:sparseResidency16Samples>> feature provides support for creating
147e5c31af7Sopenharmony_ci      2D sname:VkImage objects with 16 samples and
148e5c31af7Sopenharmony_ci      ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT.
149e5c31af7Sopenharmony_ci+
150e5c31af7Sopenharmony_ciImplementations supporting pname:sparseResidencyImage2D are only required:
151e5c31af7Sopenharmony_cito support sparse 2D, single-sampled images.
152e5c31af7Sopenharmony_ciSupport for sparse 3D and MSAA images is optional: and can: be enabled via
153e5c31af7Sopenharmony_cipname:sparseResidencyImage3D, pname:sparseResidency2Samples,
154e5c31af7Sopenharmony_cipname:sparseResidency4Samples, pname:sparseResidency8Samples, and
155e5c31af7Sopenharmony_cipname:sparseResidency16Samples.
156e5c31af7Sopenharmony_ci
157e5c31af7Sopenharmony_ci  ** A sparse image created using ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT
158e5c31af7Sopenharmony_ci     supports all non-compressed color formats with power-of-two element
159e5c31af7Sopenharmony_ci     size that non-sparse usage supports.
160e5c31af7Sopenharmony_ci     Additional formats may: also be supported and can: be queried via
161e5c31af7Sopenharmony_ci     flink:vkGetPhysicalDeviceSparseImageFormatProperties.
162e5c31af7Sopenharmony_ci     ename:VK_IMAGE_TILING_LINEAR tiling is not supported.
163e5c31af7Sopenharmony_ci
164e5c31af7Sopenharmony_ci  * The <<features-sparseResidencyAliased, pname:sparseResidencyAliased>>
165e5c31af7Sopenharmony_ci    feature provides the following capability that can: be enabled per
166e5c31af7Sopenharmony_ci    resource:
167e5c31af7Sopenharmony_ci+
168e5c31af7Sopenharmony_ciAllows physical memory ranges to be shared between multiple locations in the
169e5c31af7Sopenharmony_cisame sparse resource or between multiple sparse resources, with each binding
170e5c31af7Sopenharmony_ciof a memory location observing a consistent interpretation of the memory
171e5c31af7Sopenharmony_cicontents.
172e5c31af7Sopenharmony_ci+
173e5c31af7Sopenharmony_ci--
174e5c31af7Sopenharmony_ciifndef::VKSC_VERSION_1_0[]
175e5c31af7Sopenharmony_ciSee <<sparsememory-sparse-memory-aliasing,Sparse Memory Aliasing>> for more
176e5c31af7Sopenharmony_ciinformation.
177e5c31af7Sopenharmony_ciendif::VKSC_VERSION_1_0[]
178e5c31af7Sopenharmony_ci--
179e5c31af7Sopenharmony_ci
180e5c31af7Sopenharmony_ci
181e5c31af7Sopenharmony_ciifndef::VKSC_VERSION_1_0[]
182e5c31af7Sopenharmony_ci[[sparsememory-fully-resident]]
183e5c31af7Sopenharmony_ci== Sparse Buffers and Fully-Resident Images
184e5c31af7Sopenharmony_ci
185e5c31af7Sopenharmony_ciBoth sname:VkBuffer and sname:VkImage objects created with the
186e5c31af7Sopenharmony_ciename:VK_IMAGE_CREATE_SPARSE_BINDING_BIT or
187e5c31af7Sopenharmony_ciename:VK_BUFFER_CREATE_SPARSE_BINDING_BIT bits can: be thought of as a
188e5c31af7Sopenharmony_cilinear region of address space.
189e5c31af7Sopenharmony_ciIn the sname:VkImage case if ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT is
190e5c31af7Sopenharmony_cinot used, this linear region is entirely opaque, meaning that there is no
191e5c31af7Sopenharmony_ciapplication-visible mapping between texel location and memory offset.
192e5c31af7Sopenharmony_ci
193e5c31af7Sopenharmony_ciUnless ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or
194e5c31af7Sopenharmony_ciename:VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT are also used, the entire
195e5c31af7Sopenharmony_ciresource must: be bound to one or more sname:VkDeviceMemory objects before
196e5c31af7Sopenharmony_ciuse.
197e5c31af7Sopenharmony_ci
198e5c31af7Sopenharmony_ci
199e5c31af7Sopenharmony_ci=== Sparse Buffer and Fully-Resident Image Block Size
200e5c31af7Sopenharmony_ci
201e5c31af7Sopenharmony_ciThe sparse block size in bytes for sparse buffers and fully-resident images
202e5c31af7Sopenharmony_ciis reported as sname:VkMemoryRequirements::pname:alignment.
203e5c31af7Sopenharmony_cipname:alignment represents both the memory alignment requirement and the
204e5c31af7Sopenharmony_cibinding granularity (in bytes) for sparse resources.
205e5c31af7Sopenharmony_ci
206e5c31af7Sopenharmony_ci
207e5c31af7Sopenharmony_ci[[sparsememory-partially-resident-buffers]]
208e5c31af7Sopenharmony_ci== Sparse Partially-Resident Buffers
209e5c31af7Sopenharmony_ci
210e5c31af7Sopenharmony_cisname:VkBuffer objects created with the
211e5c31af7Sopenharmony_ciename:VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT bit allow the buffer to be made
212e5c31af7Sopenharmony_cionly partially resident.
213e5c31af7Sopenharmony_ciPartially resident sname:VkBuffer objects are allocated and bound
214e5c31af7Sopenharmony_ciidentically to sname:VkBuffer objects using only the
215e5c31af7Sopenharmony_ciename:VK_BUFFER_CREATE_SPARSE_BINDING_BIT feature.
216e5c31af7Sopenharmony_ciThe only difference is the ability for some regions of the buffer to be
217e5c31af7Sopenharmony_ciunbound during device use.
218e5c31af7Sopenharmony_ci
219e5c31af7Sopenharmony_ci
220e5c31af7Sopenharmony_ci[[sparsememory-partially-resident-images]]
221e5c31af7Sopenharmony_ci== Sparse Partially-Resident Images
222e5c31af7Sopenharmony_ci
223e5c31af7Sopenharmony_cisname:VkImage objects created with the
224e5c31af7Sopenharmony_ciename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT bit allow specific rectangular
225e5c31af7Sopenharmony_ciregions of the image called sparse image blocks to be bound to specific
226e5c31af7Sopenharmony_ciranges of memory.
227e5c31af7Sopenharmony_ciThis allows the application to manage residency at either image subresource
228e5c31af7Sopenharmony_cior sparse image block granularity.
229e5c31af7Sopenharmony_ciEach image subresource (outside of the <<sparsememory-miptail,mip tail>>)
230e5c31af7Sopenharmony_cistarts on a sparse block boundary and has dimensions that are integer
231e5c31af7Sopenharmony_cimultiples of the corresponding dimensions of the sparse image block.
232e5c31af7Sopenharmony_ci
233e5c31af7Sopenharmony_ci[NOTE]
234e5c31af7Sopenharmony_ci.Note
235e5c31af7Sopenharmony_ci====
236e5c31af7Sopenharmony_ciApplications can: use these types of images to control LOD based on total
237e5c31af7Sopenharmony_cimemory consumption.
238e5c31af7Sopenharmony_ciIf memory pressure becomes an issue the application can: unbind and disable
239e5c31af7Sopenharmony_cispecific mipmap levels of images without having to recreate resources or
240e5c31af7Sopenharmony_cimodify texel data of unaffected levels.
241e5c31af7Sopenharmony_ci
242e5c31af7Sopenharmony_ciThe application can: also use this functionality to access subregions of the
243e5c31af7Sopenharmony_ciimage in a "`megatexture`" fashion.
244e5c31af7Sopenharmony_ciThe application can: create a large image and only populate the region of
245e5c31af7Sopenharmony_cithe image that is currently being used in the scene.
246e5c31af7Sopenharmony_ci====
247e5c31af7Sopenharmony_ci
248e5c31af7Sopenharmony_ci
249e5c31af7Sopenharmony_ci[[sparsememory-accessing-unbound]]
250e5c31af7Sopenharmony_ci=== Accessing Unbound Regions
251e5c31af7Sopenharmony_ci
252e5c31af7Sopenharmony_ciThe following member of sname:VkPhysicalDeviceSparseProperties affects how
253e5c31af7Sopenharmony_cidata in unbound regions of sparse resources are handled by the
254e5c31af7Sopenharmony_ciimplementation:
255e5c31af7Sopenharmony_ci
256e5c31af7Sopenharmony_ci  * pname:residencyNonResidentStrict
257e5c31af7Sopenharmony_ci
258e5c31af7Sopenharmony_ciIf this property is not present, reads of unbound regions of the image will
259e5c31af7Sopenharmony_cireturn undefined: values.
260e5c31af7Sopenharmony_ciBoth reads and writes are still considered _safe_ and will not affect other
261e5c31af7Sopenharmony_ciresources or populated regions of the image.
262e5c31af7Sopenharmony_ci
263e5c31af7Sopenharmony_ciIf this property is present, all reads of unbound regions of the image will
264e5c31af7Sopenharmony_cibehave as if the region was bound to memory populated with all zeros; writes
265e5c31af7Sopenharmony_ciwill be discarded.
266e5c31af7Sopenharmony_ci
267e5c31af7Sopenharmony_ci<<textures,Image operations>> performed on unbound memory may: still alter
268e5c31af7Sopenharmony_cisome component values in the natural way for those accesses, e.g.
269e5c31af7Sopenharmony_cisubstituting a value of one for alpha in formats that do not have an alpha
270e5c31af7Sopenharmony_cicomponent.
271e5c31af7Sopenharmony_ci
272e5c31af7Sopenharmony_ci====
273e5c31af7Sopenharmony_ciExample: Reading the alpha component of an unbacked ename:VK_FORMAT_R8_UNORM
274e5c31af7Sopenharmony_ciimage will return a value of [eq]#1.0f#.
275e5c31af7Sopenharmony_ci====
276e5c31af7Sopenharmony_ci
277e5c31af7Sopenharmony_ciSee <<devsandqueues-physical-device-enumeration,Physical Device
278e5c31af7Sopenharmony_ciEnumeration>> for instructions for retrieving physical device properties.
279e5c31af7Sopenharmony_ci
280e5c31af7Sopenharmony_ciifdef::implementation-guide[]
281e5c31af7Sopenharmony_ci.Implementor's Note
282e5c31af7Sopenharmony_ci****
283e5c31af7Sopenharmony_ciFor implementations that cannot: natively handle access to unbound regions
284e5c31af7Sopenharmony_ciof a resource, the implementation may: allocate and bind memory to the
285e5c31af7Sopenharmony_ciunbound regions.
286e5c31af7Sopenharmony_ciReads and writes to unbound regions will access the implementation-managed
287e5c31af7Sopenharmony_cimemory instead.
288e5c31af7Sopenharmony_ci
289e5c31af7Sopenharmony_ciGiven that the values resulting from reads of unbound regions are undefined:
290e5c31af7Sopenharmony_ciin this scenario, implementations may: use the same physical memory for all
291e5c31af7Sopenharmony_ciunbound regions of multiple resources within the same process.
292e5c31af7Sopenharmony_ci****
293e5c31af7Sopenharmony_ciendif::implementation-guide[]
294e5c31af7Sopenharmony_ci
295e5c31af7Sopenharmony_ci
296e5c31af7Sopenharmony_ci[[sparsememory-miptail]]
297e5c31af7Sopenharmony_ci=== Mip Tail Regions
298e5c31af7Sopenharmony_ci
299e5c31af7Sopenharmony_ciSparse images created using ename:VK_IMAGE_CREATE_SPARSE_BINDING_BIT
300e5c31af7Sopenharmony_ci(without also using ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) have no
301e5c31af7Sopenharmony_cispecific mapping of image region or image subresource to memory offset
302e5c31af7Sopenharmony_cidefined, so the entire image can: be thought of as a linear opaque address
303e5c31af7Sopenharmony_ciregion.
304e5c31af7Sopenharmony_ciHowever, images created with ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT do
305e5c31af7Sopenharmony_cihave a prescribed sparse image block layout, and hence each image
306e5c31af7Sopenharmony_cisubresource must: start on a sparse block boundary.
307e5c31af7Sopenharmony_ciWithin each array layer, the set of mip levels that have a smaller size than
308e5c31af7Sopenharmony_cithe sparse block size in bytes are grouped together into a _mip tail
309e5c31af7Sopenharmony_ciregion_.
310e5c31af7Sopenharmony_ci
311e5c31af7Sopenharmony_ciIf the ename:VK_SPARSE_IMAGE_FORMAT_ALIGNED_MIP_SIZE_BIT flag is present in
312e5c31af7Sopenharmony_cithe pname:flags member of sname:VkSparseImageFormatProperties, for the
313e5c31af7Sopenharmony_ciimage's pname:format, then any mip level which has dimensions that are not
314e5c31af7Sopenharmony_ciinteger multiples of the corresponding dimensions of the sparse image block,
315e5c31af7Sopenharmony_ciand all subsequent mip levels, are also included in the mip tail region.
316e5c31af7Sopenharmony_ci
317e5c31af7Sopenharmony_ciThe following member of sname:VkPhysicalDeviceSparseProperties may: affect
318e5c31af7Sopenharmony_cihow the implementation places mip levels in the mip tail region:
319e5c31af7Sopenharmony_ci
320e5c31af7Sopenharmony_ci  * pname:residencyAlignedMipSize
321e5c31af7Sopenharmony_ci
322e5c31af7Sopenharmony_ciEach mip tail region is bound to memory as an opaque region (i.e. must: be
323e5c31af7Sopenharmony_cibound using a slink:VkSparseImageOpaqueMemoryBindInfo structure) and may: be
324e5c31af7Sopenharmony_ciof a size greater than or equal to the sparse block size in bytes.
325e5c31af7Sopenharmony_ciThis size is guaranteed to be an integer multiple of the sparse block size
326e5c31af7Sopenharmony_ciin bytes.
327e5c31af7Sopenharmony_ci
328e5c31af7Sopenharmony_ciAn implementation may: choose to allow each array-layer's mip tail region to
329e5c31af7Sopenharmony_cibe bound to memory independently or require that all array-layer's mip tail
330e5c31af7Sopenharmony_ciregions be treated as one.
331e5c31af7Sopenharmony_ciThis is dictated by ename:VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT in
332e5c31af7Sopenharmony_cisname:VkSparseImageMemoryRequirements::pname:flags.
333e5c31af7Sopenharmony_ci
334e5c31af7Sopenharmony_ciThe following diagrams depict how
335e5c31af7Sopenharmony_ciename:VK_SPARSE_IMAGE_FORMAT_ALIGNED_MIP_SIZE_BIT and
336e5c31af7Sopenharmony_ciename:VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT alter memory usage and
337e5c31af7Sopenharmony_cirequirements.
338e5c31af7Sopenharmony_ci
339e5c31af7Sopenharmony_ciimage::{images}/sparseimage.svg[align="center",title="Sparse Image",opts="{imageopts}"]
340e5c31af7Sopenharmony_ci
341e5c31af7Sopenharmony_ciIn the absence of ename:VK_SPARSE_IMAGE_FORMAT_ALIGNED_MIP_SIZE_BIT and
342e5c31af7Sopenharmony_ciename:VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT, each array layer contains a
343e5c31af7Sopenharmony_cimip tail region containing texel data for all mip levels smaller than the
344e5c31af7Sopenharmony_cisparse image block in any dimension.
345e5c31af7Sopenharmony_ci
346e5c31af7Sopenharmony_ciMip levels that are as large or larger than a sparse image block in all
347e5c31af7Sopenharmony_cidimensions can: be bound individually.
348e5c31af7Sopenharmony_ciRight-edges and bottom-edges of each level are allowed to have partially
349e5c31af7Sopenharmony_ciused sparse blocks.
350e5c31af7Sopenharmony_ciAny bound partially-used-sparse-blocks must: still have their full sparse
351e5c31af7Sopenharmony_ciblock size in bytes allocated in memory.
352e5c31af7Sopenharmony_ci
353e5c31af7Sopenharmony_ciimage::{images}/sparseimage_singlemiptail.svg[align="center",title="Sparse Image with Single Mip Tail",opts="{imageopts}"]
354e5c31af7Sopenharmony_ci
355e5c31af7Sopenharmony_ciWhen ename:VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT is present all array
356e5c31af7Sopenharmony_cilayers will share a single mip tail region.
357e5c31af7Sopenharmony_ci
358e5c31af7Sopenharmony_ciimage::{images}/sparseimage_alignedmipsize.svg[align="center",title="Sparse Image with Aligned Mip Size",opts="{imageopts}"]
359e5c31af7Sopenharmony_ci
360e5c31af7Sopenharmony_ci[NOTE]
361e5c31af7Sopenharmony_ci.Note
362e5c31af7Sopenharmony_ci====
363e5c31af7Sopenharmony_ciThe mip tail regions are presented here in 2D arrays simply for figure size
364e5c31af7Sopenharmony_cireasons.
365e5c31af7Sopenharmony_ciEach mip tail is logically a single array of sparse blocks with an
366e5c31af7Sopenharmony_ciimplementation-dependent mapping of texels or compressed texel blocks to
367e5c31af7Sopenharmony_cisparse blocks.
368e5c31af7Sopenharmony_ci====
369e5c31af7Sopenharmony_ci
370e5c31af7Sopenharmony_ciWhen ename:VK_SPARSE_IMAGE_FORMAT_ALIGNED_MIP_SIZE_BIT is present the first
371e5c31af7Sopenharmony_cimip level that would contain partially used sparse blocks begins the mip
372e5c31af7Sopenharmony_citail region.
373e5c31af7Sopenharmony_ciThis level and all subsequent levels are placed in the mip tail.
374e5c31af7Sopenharmony_ciOnly the first [eq]#N# mip levels whose dimensions are an exact multiple of
375e5c31af7Sopenharmony_cithe sparse image block dimensions can: be bound and unbound on a sparse
376e5c31af7Sopenharmony_ciblock basis.
377e5c31af7Sopenharmony_ci
378e5c31af7Sopenharmony_ciimage::{images}/sparseimage_alignedmipsize_singlemiptail.svg[align="center",title="Sparse Image with Aligned Mip Size and Single Mip Tail",opts="{imageopts}"]
379e5c31af7Sopenharmony_ci
380e5c31af7Sopenharmony_ci[NOTE]
381e5c31af7Sopenharmony_ci.Note
382e5c31af7Sopenharmony_ci====
383e5c31af7Sopenharmony_ciThe mip tail region is presented here in a 2D array simply for figure size
384e5c31af7Sopenharmony_cireasons.
385e5c31af7Sopenharmony_ciIt is logically a single array of sparse blocks with an
386e5c31af7Sopenharmony_ciimplementation-dependent mapping of texels or compressed texel blocks to
387e5c31af7Sopenharmony_cisparse blocks.
388e5c31af7Sopenharmony_ci====
389e5c31af7Sopenharmony_ci
390e5c31af7Sopenharmony_ciWhen both ename:VK_SPARSE_IMAGE_FORMAT_ALIGNED_MIP_SIZE_BIT and
391e5c31af7Sopenharmony_ciename:VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT are present the constraints
392e5c31af7Sopenharmony_cifrom each of these flags are in effect.
393e5c31af7Sopenharmony_ci
394e5c31af7Sopenharmony_ci
395e5c31af7Sopenharmony_ci[[sparsememory-standard-shapes]]
396e5c31af7Sopenharmony_ci=== Standard Sparse Image Block Shapes
397e5c31af7Sopenharmony_ci
398e5c31af7Sopenharmony_ciStandard sparse image block shapes define a standard set of dimensions for
399e5c31af7Sopenharmony_cisparse image blocks that depend on the format of the image.
400e5c31af7Sopenharmony_ciLayout of texels or compressed texel blocks within a sparse image block is
401e5c31af7Sopenharmony_ciimplementation-dependent.
402e5c31af7Sopenharmony_ciAll currently defined standard sparse image block shapes are 64 KB in size.
403e5c31af7Sopenharmony_ci
404e5c31af7Sopenharmony_ciFor block-compressed formats (e.g. ename:VK_FORMAT_BC5_UNORM_BLOCK), the
405e5c31af7Sopenharmony_citexel size is the size of the compressed texel block (e.g. 128-bit for
406e5c31af7Sopenharmony_cietext:BC5) thus the dimensions of the standard sparse image block shapes
407e5c31af7Sopenharmony_ciapply in terms of compressed texel blocks.
408e5c31af7Sopenharmony_ci
409e5c31af7Sopenharmony_ci[NOTE]
410e5c31af7Sopenharmony_ci.Note
411e5c31af7Sopenharmony_ci====
412e5c31af7Sopenharmony_ciFor block-compressed formats, the dimensions of a sparse image block in
413e5c31af7Sopenharmony_citerms of texels can: be calculated by multiplying the sparse image block
414e5c31af7Sopenharmony_cidimensions by the compressed texel block dimensions.
415e5c31af7Sopenharmony_ci====
416e5c31af7Sopenharmony_ci
417e5c31af7Sopenharmony_ci<<<
418e5c31af7Sopenharmony_ci
419e5c31af7Sopenharmony_ci[[sparsememory-sparseblockshapessingle]]
420e5c31af7Sopenharmony_ci.Standard Sparse Image Block Shapes (Single Sample)
421e5c31af7Sopenharmony_ci[options="header"]
422e5c31af7Sopenharmony_ci|====
423e5c31af7Sopenharmony_ci| TEXEL SIZE (bits) | Block Shape (2D)              | Block Shape (3D)
424e5c31af7Sopenharmony_ci| *8-Bit*           | 256 {times} 256 {times} 1     | 64 {times} 32 {times} 32
425e5c31af7Sopenharmony_ci| *16-Bit*          | 256 {times} 128 {times} 1     | 32 {times} 32 {times} 32
426e5c31af7Sopenharmony_ci| *32-Bit*          | 128 {times} 128 {times} 1     | 32 {times} 32 {times} 16
427e5c31af7Sopenharmony_ci| *64-Bit*          | 128 {times} 64 {times} 1      | 32 {times} 16 {times} 16
428e5c31af7Sopenharmony_ci| *128-Bit*         | 64 {times} 64 {times} 1       | 16 {times} 16 {times} 16
429e5c31af7Sopenharmony_ci|====
430e5c31af7Sopenharmony_ci
431e5c31af7Sopenharmony_ci[[sparsememory-sparseblockshapesmsaa]]
432e5c31af7Sopenharmony_ci.Standard Sparse Image Block Shapes (MSAA)
433e5c31af7Sopenharmony_ci[options="header"]
434e5c31af7Sopenharmony_ci|====
435e5c31af7Sopenharmony_ci| TEXEL SIZE (bits)| Block Shape (2X)            | Block Shape (4X)             | Block Shape (8X)             | Block Shape (16X)
436e5c31af7Sopenharmony_ci| *8-Bit*          | 128 {times} 256 {times} 1   | 128 {times} 128 {times} 1    | 64 {times} 128 {times} 1     | 64 {times} 64 {times} 1
437e5c31af7Sopenharmony_ci| *16-Bit*         | 128 {times} 128 {times} 1   | 128 {times} 64 {times} 1     | 64 {times} 64 {times} 1      | 64 {times} 32 {times} 1
438e5c31af7Sopenharmony_ci| *32-Bit*         | 64 {times} 128 {times} 1    | 64 {times} 64 {times} 1      | 32 {times} 64 {times} 1      | 32 {times} 32 {times} 1
439e5c31af7Sopenharmony_ci| *64-Bit*         | 64 {times} 64 {times} 1     | 64 {times} 32 {times} 1      | 32 {times} 32 {times} 1      | 32 {times} 16 {times} 1
440e5c31af7Sopenharmony_ci| *128-Bit*        | 32 {times} 64 {times} 1     | 32 {times} 32 {times} 1      | 16 {times} 32 {times} 1      | 16 {times} 16 {times} 1
441e5c31af7Sopenharmony_ci|====
442e5c31af7Sopenharmony_ci
443e5c31af7Sopenharmony_ci
444e5c31af7Sopenharmony_ciImplementations that support the standard sparse image block shape for all
445e5c31af7Sopenharmony_ciformats listed in the <<sparsememory-sparseblockshapessingle>> and
446e5c31af7Sopenharmony_ci<<sparsememory-sparseblockshapesmsaa>> tables may: advertise the following
447e5c31af7Sopenharmony_cisname:VkPhysicalDeviceSparseProperties:
448e5c31af7Sopenharmony_ci
449e5c31af7Sopenharmony_ci  * pname:residencyStandard2DBlockShape
450e5c31af7Sopenharmony_ci  * pname:residencyStandard2DMultisampleBlockShape
451e5c31af7Sopenharmony_ci  * pname:residencyStandard3DBlockShape
452e5c31af7Sopenharmony_ci
453e5c31af7Sopenharmony_ciReporting each of these features does _not_ imply that all possible image
454e5c31af7Sopenharmony_citypes are supported as sparse.
455e5c31af7Sopenharmony_ciInstead, this indicates that no supported sparse image of the corresponding
456e5c31af7Sopenharmony_citype will use custom sparse image block dimensions for any formats that have
457e5c31af7Sopenharmony_cia corresponding standard sparse image block shape.
458e5c31af7Sopenharmony_ci
459e5c31af7Sopenharmony_ci
460e5c31af7Sopenharmony_ci[[sparsememory-custom-shapes]]
461e5c31af7Sopenharmony_ci=== Custom Sparse Image Block Shapes
462e5c31af7Sopenharmony_ci
463e5c31af7Sopenharmony_ciAn implementation that does not support a standard image block shape for a
464e5c31af7Sopenharmony_ciparticular sparse partially-resident image may: choose to support a custom
465e5c31af7Sopenharmony_cisparse image block shape for it instead.
466e5c31af7Sopenharmony_ciThe dimensions of such a custom sparse image block shape are reported in
467e5c31af7Sopenharmony_cisname:VkSparseImageFormatProperties::pname:imageGranularity.
468e5c31af7Sopenharmony_ciAs with standard sparse image block shapes, the size in bytes of the custom
469e5c31af7Sopenharmony_cisparse image block shape will be reported in
470e5c31af7Sopenharmony_cisname:VkMemoryRequirements::pname:alignment.
471e5c31af7Sopenharmony_ci
472e5c31af7Sopenharmony_ciCustom sparse image block dimensions are reported through
473e5c31af7Sopenharmony_cifname:vkGetPhysicalDeviceSparseImageFormatProperties and
474e5c31af7Sopenharmony_cifname:vkGetImageSparseMemoryRequirements.
475e5c31af7Sopenharmony_ci
476e5c31af7Sopenharmony_ciAn implementation must: not support both the standard sparse image block
477e5c31af7Sopenharmony_cishape and a custom sparse image block shape for the same image.
478e5c31af7Sopenharmony_ciThe standard sparse image block shape must: be used if it is supported.
479e5c31af7Sopenharmony_ci
480e5c31af7Sopenharmony_ci
481e5c31af7Sopenharmony_ci[[sparsememory-multiaspect]]
482e5c31af7Sopenharmony_ci=== Multiple Aspects
483e5c31af7Sopenharmony_ci
484e5c31af7Sopenharmony_ciPartially resident images are allowed to report separate sparse properties
485e5c31af7Sopenharmony_cifor different aspects of the image.
486e5c31af7Sopenharmony_ciOne example is for depth/stencil images where the implementation separates
487e5c31af7Sopenharmony_cithe depth and stencil data into separate planes.
488e5c31af7Sopenharmony_ciAnother reason for multiple aspects is to allow the application to manage
489e5c31af7Sopenharmony_cimemory allocation for implementation-private _metadata_ associated with the
490e5c31af7Sopenharmony_ciimage.
491e5c31af7Sopenharmony_ciSee the figure below:
492e5c31af7Sopenharmony_ci
493e5c31af7Sopenharmony_ciimage::{images}/sparseimage_multiaspect.svg[align="center",title="Multiple Aspect Sparse Image",opts="{imageopts}"]
494e5c31af7Sopenharmony_ci
495e5c31af7Sopenharmony_ci[NOTE]
496e5c31af7Sopenharmony_ci.Note
497e5c31af7Sopenharmony_ci====
498e5c31af7Sopenharmony_ciThe mip tail regions are presented here in 2D arrays simply for figure size
499e5c31af7Sopenharmony_cireasons.
500e5c31af7Sopenharmony_ciEach mip tail is logically a single array of sparse blocks with an
501e5c31af7Sopenharmony_ciimplementation-dependent mapping of texels or compressed texel blocks to
502e5c31af7Sopenharmony_cisparse blocks.
503e5c31af7Sopenharmony_ci====
504e5c31af7Sopenharmony_ci
505e5c31af7Sopenharmony_ciIn the figure above the depth, stencil, and metadata aspects all have unique
506e5c31af7Sopenharmony_cisparse properties.
507e5c31af7Sopenharmony_ciThe per-texel stencil data is [eq]#{onequarter}# the size of the depth data,
508e5c31af7Sopenharmony_cihence the stencil sparse blocks include [eq]#4 {times}# the number of
509e5c31af7Sopenharmony_citexels.
510e5c31af7Sopenharmony_ciThe sparse block size in bytes for all of the aspects is identical and
511e5c31af7Sopenharmony_cidefined by sname:VkMemoryRequirements::pname:alignment.
512e5c31af7Sopenharmony_ci
513e5c31af7Sopenharmony_ci
514e5c31af7Sopenharmony_ci==== Metadata
515e5c31af7Sopenharmony_ci
516e5c31af7Sopenharmony_ciThe metadata aspect of an image has the following constraints:
517e5c31af7Sopenharmony_ci
518e5c31af7Sopenharmony_ci  * All metadata is reported in the mip tail region of the metadata aspect.
519e5c31af7Sopenharmony_ci  * All metadata must: be bound prior to device use of the sparse image.
520e5c31af7Sopenharmony_ci
521e5c31af7Sopenharmony_ci
522e5c31af7Sopenharmony_ci[[sparsememory-sparse-memory-aliasing]]
523e5c31af7Sopenharmony_ci== Sparse Memory Aliasing
524e5c31af7Sopenharmony_ci
525e5c31af7Sopenharmony_ciBy default sparse resources have the same aliasing rules as non-sparse
526e5c31af7Sopenharmony_ciresources.
527e5c31af7Sopenharmony_ciSee <<resources-memory-aliasing,Memory Aliasing>> for more information.
528e5c31af7Sopenharmony_ci
529e5c31af7Sopenharmony_cisname:VkDevice objects that have the <<features-sparseResidencyAliased,
530e5c31af7Sopenharmony_cipname:sparseResidencyAliased>> feature enabled are able to use the
531e5c31af7Sopenharmony_ciename:VK_BUFFER_CREATE_SPARSE_ALIASED_BIT and
532e5c31af7Sopenharmony_ciename:VK_IMAGE_CREATE_SPARSE_ALIASED_BIT flags for resource creation.
533e5c31af7Sopenharmony_ciThese flags allow resources to access physical memory bound into multiple
534e5c31af7Sopenharmony_cilocations within one or more sparse resources in a _data consistent_
535e5c31af7Sopenharmony_cifashion.
536e5c31af7Sopenharmony_ciThis means that reading physical memory from multiple aliased locations will
537e5c31af7Sopenharmony_cireturn the same value.
538e5c31af7Sopenharmony_ci
539e5c31af7Sopenharmony_ciCare must: be taken when performing a write operation to aliased physical
540e5c31af7Sopenharmony_cimemory.
541e5c31af7Sopenharmony_ciMemory dependencies must: be used to separate writes to one alias from reads
542e5c31af7Sopenharmony_cior writes to another alias.
543e5c31af7Sopenharmony_ciWrites to aliased memory that are not properly guarded against accesses to
544e5c31af7Sopenharmony_cidifferent aliases will have undefined: results for all accesses to the
545e5c31af7Sopenharmony_cialiased memory.
546e5c31af7Sopenharmony_ci
547e5c31af7Sopenharmony_ciApplications that wish to make use of data consistent sparse memory aliasing
548e5c31af7Sopenharmony_cimust: abide by the following guidelines:
549e5c31af7Sopenharmony_ci
550e5c31af7Sopenharmony_ci  * All sparse resources that are bound to aliased physical memory must: be
551e5c31af7Sopenharmony_ci    created with the ename:VK_BUFFER_CREATE_SPARSE_ALIASED_BIT /
552e5c31af7Sopenharmony_ci    ename:VK_IMAGE_CREATE_SPARSE_ALIASED_BIT flag.
553e5c31af7Sopenharmony_ci  * All resources that access aliased physical memory must: interpret the
554e5c31af7Sopenharmony_ci    memory in the same way.
555e5c31af7Sopenharmony_ci    This implies the following:
556e5c31af7Sopenharmony_ci  ** Buffers and images cannot: alias the same physical memory in a data
557e5c31af7Sopenharmony_ci     consistent fashion.
558e5c31af7Sopenharmony_ci     The physical memory ranges must: be used exclusively by buffers or used
559e5c31af7Sopenharmony_ci     exclusively by images for data consistency to be guaranteed.
560e5c31af7Sopenharmony_ci  ** Memory in sparse image mip tail regions cannot: access aliased memory
561e5c31af7Sopenharmony_ci     in a data consistent fashion.
562e5c31af7Sopenharmony_ci  ** Sparse images that alias the same physical memory must: have compatible
563e5c31af7Sopenharmony_ci     formats and be using the same sparse image block shape in order to
564e5c31af7Sopenharmony_ci     access aliased memory in a data consistent fashion.
565e5c31af7Sopenharmony_ci
566e5c31af7Sopenharmony_ciFailure to follow any of the above guidelines will require the application
567e5c31af7Sopenharmony_cito abide by the normal, non-sparse resource <<resources-memory-aliasing,
568e5c31af7Sopenharmony_cialiasing rules>>.
569e5c31af7Sopenharmony_ciIn this case memory cannot: be accessed in a data consistent fashion.
570e5c31af7Sopenharmony_ci
571e5c31af7Sopenharmony_ci[NOTE]
572e5c31af7Sopenharmony_ci.Note
573e5c31af7Sopenharmony_ci====
574e5c31af7Sopenharmony_ciEnabling sparse resource memory aliasing can: be a way to lower physical
575e5c31af7Sopenharmony_cimemory use, but it may: reduce performance on some implementations.
576e5c31af7Sopenharmony_ciAn application developer can: test on their target HW and balance the memory
577e5c31af7Sopenharmony_ci/ performance trade-offs measured.
578e5c31af7Sopenharmony_ci====
579e5c31af7Sopenharmony_ci
580e5c31af7Sopenharmony_ci
581e5c31af7Sopenharmony_ciifdef::implementation-guide[]
582e5c31af7Sopenharmony_ci== Sparse Resource Implementation Guidelines (Informative)
583e5c31af7Sopenharmony_ci
584e5c31af7Sopenharmony_ci****
585e5c31af7Sopenharmony_ciThis section is Informative.
586e5c31af7Sopenharmony_ciIt is included to aid in implementors`' understanding of sparse resources.
587e5c31af7Sopenharmony_ci
588e5c31af7Sopenharmony_ci.Device Virtual Address
589e5c31af7Sopenharmony_ci
590e5c31af7Sopenharmony_ciThe basic pname:sparseBinding feature allows the resource to reserve its own
591e5c31af7Sopenharmony_cidevice virtual address range at resource creation time rather than relying
592e5c31af7Sopenharmony_cion a bind operation to set this.
593e5c31af7Sopenharmony_ciWithout any other creation flags, no other constraints are relaxed compared
594e5c31af7Sopenharmony_cito normal resources.
595e5c31af7Sopenharmony_ciAll pages must: be bound to physical memory before the device accesses the
596e5c31af7Sopenharmony_ciresource.
597e5c31af7Sopenharmony_ci
598e5c31af7Sopenharmony_ciThe <<features-sparseResidency, pname:sparseResidency>> features allow
599e5c31af7Sopenharmony_cisparse resources to be used even when not all pages are bound to memory.
600e5c31af7Sopenharmony_ciImplementations that support access to unbound pages without causing a fault
601e5c31af7Sopenharmony_cimay: support pname:residencyNonResidentStrict.
602e5c31af7Sopenharmony_ci
603e5c31af7Sopenharmony_ciNot faulting on access to unbound pages is not enough to support
604e5c31af7Sopenharmony_cipname:residencyNonResidentStrict.
605e5c31af7Sopenharmony_ciAn implementation must: also guarantee that reads after writes to unbound
606e5c31af7Sopenharmony_ciregions of the resource always return data for the read as if the memory
607e5c31af7Sopenharmony_cicontains zeros.
608e5c31af7Sopenharmony_ciDepending on any caching hierarchy of the implementation this may: not
609e5c31af7Sopenharmony_cialways be possible.
610e5c31af7Sopenharmony_ci
611e5c31af7Sopenharmony_ciAny implementation that does not fault, but does not guarantee correct read
612e5c31af7Sopenharmony_civalues must: not support pname:residencyNonResidentStrict.
613e5c31af7Sopenharmony_ci
614e5c31af7Sopenharmony_ciAny implementation that cannot: access unbound pages without causing a fault
615e5c31af7Sopenharmony_ciwill require the implementation to bind the entire device virtual address
616e5c31af7Sopenharmony_cirange to physical memory.
617e5c31af7Sopenharmony_ciAny pages that the application does not bind to memory may: be bound to one
618e5c31af7Sopenharmony_ci(or more) "`placeholder" physical page(s) allocated by the implementation.
619e5c31af7Sopenharmony_ciGiven the following properties:
620e5c31af7Sopenharmony_ci
621e5c31af7Sopenharmony_ci  * A process must: not access memory from another process
622e5c31af7Sopenharmony_ci  * Reads return undefined: values
623e5c31af7Sopenharmony_ci
624e5c31af7Sopenharmony_ciIt is sufficient for each host process to allocate these placeholder pages
625e5c31af7Sopenharmony_ciand use them for all resources in that process.
626e5c31af7Sopenharmony_ciImplementations may: allocate more often (per instance, per device, or per
627e5c31af7Sopenharmony_ciresource).
628e5c31af7Sopenharmony_ci
629e5c31af7Sopenharmony_ci
630e5c31af7Sopenharmony_ci.Binding Memory
631e5c31af7Sopenharmony_ci
632e5c31af7Sopenharmony_ciThe byte size reported in sname:VkMemoryRequirements::pname:size must: be
633e5c31af7Sopenharmony_cigreater than or equal to the amount of physical memory required: to fully
634e5c31af7Sopenharmony_cipopulate the resource.
635e5c31af7Sopenharmony_ciSome implementations require "`holes`" in the device virtual address range
636e5c31af7Sopenharmony_cithat are never accessed.
637e5c31af7Sopenharmony_ciThese holes may: be included in the pname:size reported for the resource.
638e5c31af7Sopenharmony_ci
639e5c31af7Sopenharmony_ciIncluding or not including the device virtual address holes in the resource
640e5c31af7Sopenharmony_cisize will alter how the implementation provides support for
641e5c31af7Sopenharmony_cisname:VkSparseImageOpaqueMemoryBindInfo.
642e5c31af7Sopenharmony_ciThis operation must: be supported for all sparse images, even ones created
643e5c31af7Sopenharmony_ciwith ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT.
644e5c31af7Sopenharmony_ci
645e5c31af7Sopenharmony_ciifdef::editing-notes[]
646e5c31af7Sopenharmony_ci[NOTE]
647e5c31af7Sopenharmony_ci.editing-note
648e5c31af7Sopenharmony_ci====
649e5c31af7Sopenharmony_ci@ntrevett suggested expanding the NOTE tag below to encompass everything
650e5c31af7Sopenharmony_cifrom "`The cost is...`" in the first bullet point through the current note.
651e5c31af7Sopenharmony_ciTBD.
652e5c31af7Sopenharmony_ci====
653e5c31af7Sopenharmony_ciendif::editing-notes[]
654e5c31af7Sopenharmony_ci
655e5c31af7Sopenharmony_ci  * If the holes are included in the size, this bind function becomes very
656e5c31af7Sopenharmony_ci    easy.
657e5c31af7Sopenharmony_ci    In most cases the pname:resourceOffset is simply a device virtual
658e5c31af7Sopenharmony_ci    address offset and the implementation can easily determine what device
659e5c31af7Sopenharmony_ci    virtual address to bind.
660e5c31af7Sopenharmony_ci    The cost is that the application may: allocate more physical memory for
661e5c31af7Sopenharmony_ci    the resource than it needs.
662e5c31af7Sopenharmony_ci  * If the holes are not included in the size, the application can: allocate
663e5c31af7Sopenharmony_ci    less physical memory than otherwise for the resource.
664e5c31af7Sopenharmony_ci    However, in this case the implementation must: account for the holes
665e5c31af7Sopenharmony_ci    when mapping pname:resourceOffset to the actual device virtual address
666e5c31af7Sopenharmony_ci    intended to be mapped.
667e5c31af7Sopenharmony_ci
668e5c31af7Sopenharmony_ci[NOTE]
669e5c31af7Sopenharmony_ci.Note
670e5c31af7Sopenharmony_ci====
671e5c31af7Sopenharmony_ciIf the application always uses sname:VkSparseImageMemoryBindInfo to bind
672e5c31af7Sopenharmony_cimemory for the non-tail mip levels, any holes that are present in the
673e5c31af7Sopenharmony_ciresource size may: never be bound.
674e5c31af7Sopenharmony_ci
675e5c31af7Sopenharmony_ciSince sname:VkSparseImageMemoryBindInfo uses texel locations to determine
676e5c31af7Sopenharmony_ciwhich device virtual addresses to bind, it is impossible to bind device
677e5c31af7Sopenharmony_civirtual address holes with this operation.
678e5c31af7Sopenharmony_ci====
679e5c31af7Sopenharmony_ci
680e5c31af7Sopenharmony_ci.Binding Metadata Memory
681e5c31af7Sopenharmony_ci
682e5c31af7Sopenharmony_ciAll metadata for sparse images have their own sparse properties and are
683e5c31af7Sopenharmony_ciembedded in the mip tail region for said properties.
684e5c31af7Sopenharmony_ciSee the <<sparsememory-multiaspect,Multiaspect>> section for details.
685e5c31af7Sopenharmony_ci
686e5c31af7Sopenharmony_ciGiven that metadata is in a mip tail region, and the mip tail region must:
687e5c31af7Sopenharmony_cibe reported as contiguous (either globally or per-array-layer), some
688e5c31af7Sopenharmony_ciimplementations will have to resort to complicated offset -> device virtual
689e5c31af7Sopenharmony_ciaddress mapping for handling sname:VkSparseImageOpaqueMemoryBindInfo.
690e5c31af7Sopenharmony_ci
691e5c31af7Sopenharmony_ciTo make this easier on the implementation, the
692e5c31af7Sopenharmony_ciename:VK_SPARSE_MEMORY_BIND_METADATA_BIT explicitly specifies when metadata
693e5c31af7Sopenharmony_ciis bound with sname:VkSparseImageOpaqueMemoryBindInfo.
694e5c31af7Sopenharmony_ciWhen this flag is not present, the pname:resourceOffset may: be treated as a
695e5c31af7Sopenharmony_cistrict device virtual address offset.
696e5c31af7Sopenharmony_ci
697e5c31af7Sopenharmony_ciWhen ename:VK_SPARSE_MEMORY_BIND_METADATA_BIT is present, the
698e5c31af7Sopenharmony_cipname:resourceOffset must: have been derived explicitly from the
699e5c31af7Sopenharmony_cipname:imageMipTailOffset in the sparse resource properties returned for the
700e5c31af7Sopenharmony_cimetadata aspect.
701e5c31af7Sopenharmony_ciBy manipulating the value returned for pname:imageMipTailOffset, the
702e5c31af7Sopenharmony_cipname:resourceOffset does not have to correlate directly to a device virtual
703e5c31af7Sopenharmony_ciaddress offset, and may: instead be whatever value makes it easiest for the
704e5c31af7Sopenharmony_ciimplementation to derive the correct device virtual address.
705e5c31af7Sopenharmony_ci
706e5c31af7Sopenharmony_ci****
707e5c31af7Sopenharmony_ciendif::implementation-guide[]
708e5c31af7Sopenharmony_ciendif::VKSC_VERSION_1_0[]
709e5c31af7Sopenharmony_ci
710e5c31af7Sopenharmony_ci[[sparsememory-resourceapi]]
711e5c31af7Sopenharmony_ci== Sparse Resource API
712e5c31af7Sopenharmony_ci
713e5c31af7Sopenharmony_ciThe APIs related to sparse resources are grouped into the following
714e5c31af7Sopenharmony_cicategories:
715e5c31af7Sopenharmony_ci
716e5c31af7Sopenharmony_ci  * <<sparsememory-physicalfeatures,Physical Device Features>>
717e5c31af7Sopenharmony_ci  * <<sparsememory-physicalprops,Physical Device Sparse Properties>>
718e5c31af7Sopenharmony_ciifndef::VKSC_VERSION_1_0[]
719e5c31af7Sopenharmony_ci  * <<sparsememory-format-props,Sparse Image Format Properties>>
720e5c31af7Sopenharmony_ci  * <<sparsememory-resource-creation,Sparse Resource Creation>>
721e5c31af7Sopenharmony_ci  * <<sparsememory-memory-requirements,Sparse Resource Memory Requirements>>
722e5c31af7Sopenharmony_ci  * <<sparsememory-resource-binding,Binding Resource Memory>>
723e5c31af7Sopenharmony_ciendif::VKSC_VERSION_1_0[]
724e5c31af7Sopenharmony_ci
725e5c31af7Sopenharmony_ci
726e5c31af7Sopenharmony_ci[[sparsememory-physicalfeatures]]
727e5c31af7Sopenharmony_ci=== Physical Device Features
728e5c31af7Sopenharmony_ci
729e5c31af7Sopenharmony_ciSome sparse-resource related features are reported and enabled in
730e5c31af7Sopenharmony_cisname:VkPhysicalDeviceFeatures.
731e5c31af7Sopenharmony_ciThese features must: be supported and enabled on the sname:VkDevice object
732e5c31af7Sopenharmony_cibefore applications can: use them.
733e5c31af7Sopenharmony_ciSee <<features, Physical Device Features>> for information on how to get and
734e5c31af7Sopenharmony_ciset enabled device features, and for more detailed explanations of these
735e5c31af7Sopenharmony_cifeatures.
736e5c31af7Sopenharmony_ci
737e5c31af7Sopenharmony_ci
738e5c31af7Sopenharmony_ci==== Sparse Physical Device Features
739e5c31af7Sopenharmony_ci
740e5c31af7Sopenharmony_ci  * pname:sparseBinding: Support for creating slink:VkBuffer and
741e5c31af7Sopenharmony_ci    sname:VkImage objects with the ename:VK_BUFFER_CREATE_SPARSE_BINDING_BIT
742e5c31af7Sopenharmony_ci    and ename:VK_IMAGE_CREATE_SPARSE_BINDING_BIT flags, respectively.
743e5c31af7Sopenharmony_ci  * pname:sparseResidencyBuffer: Support for creating slink:VkBuffer objects
744e5c31af7Sopenharmony_ci    with the ename:VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT flag.
745e5c31af7Sopenharmony_ci  * pname:sparseResidencyImage2D: Support for creating 2D single-sampled
746e5c31af7Sopenharmony_ci    sname:VkImage objects with ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT.
747e5c31af7Sopenharmony_ci  * pname:sparseResidencyImage3D: Support for creating 3D slink:VkImage
748e5c31af7Sopenharmony_ci    objects with ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT.
749e5c31af7Sopenharmony_ci  * pname:sparseResidency2Samples: Support for creating 2D slink:VkImage
750e5c31af7Sopenharmony_ci    objects with 2 samples and ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT.
751e5c31af7Sopenharmony_ci  * pname:sparseResidency4Samples: Support for creating 2D slink:VkImage
752e5c31af7Sopenharmony_ci    objects with 4 samples and ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT.
753e5c31af7Sopenharmony_ci  * pname:sparseResidency8Samples: Support for creating 2D slink:VkImage
754e5c31af7Sopenharmony_ci    objects with 8 samples and ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT.
755e5c31af7Sopenharmony_ci  * pname:sparseResidency16Samples: Support for creating 2D slink:VkImage
756e5c31af7Sopenharmony_ci    objects with 16 samples and ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT.
757e5c31af7Sopenharmony_ci  * pname:sparseResidencyAliased: Support for creating slink:VkBuffer and
758e5c31af7Sopenharmony_ci    sname:VkImage objects with the ename:VK_BUFFER_CREATE_SPARSE_ALIASED_BIT
759e5c31af7Sopenharmony_ci    and ename:VK_IMAGE_CREATE_SPARSE_ALIASED_BIT flags, respectively.
760e5c31af7Sopenharmony_ci
761e5c31af7Sopenharmony_ci
762e5c31af7Sopenharmony_ci[[sparsememory-physicalprops]]
763e5c31af7Sopenharmony_ci=== Physical Device Sparse Properties
764e5c31af7Sopenharmony_ci
765e5c31af7Sopenharmony_ciSome features of the implementation are not possible to disable, and are
766e5c31af7Sopenharmony_cireported to allow applications to alter their sparse resource usage
767e5c31af7Sopenharmony_ciaccordingly.
768e5c31af7Sopenharmony_ciThese read-only capabilities are reported in the
769e5c31af7Sopenharmony_cislink:VkPhysicalDeviceProperties::pname:sparseProperties member, which is a
770e5c31af7Sopenharmony_cisname:VkPhysicalDeviceSparseProperties structure.
771e5c31af7Sopenharmony_ci
772e5c31af7Sopenharmony_ci[open,refpage='VkPhysicalDeviceSparseProperties',desc='Structure specifying physical device sparse memory properties',type='structs']
773e5c31af7Sopenharmony_ci--
774e5c31af7Sopenharmony_ciThe sname:VkPhysicalDeviceSparseProperties structure is defined as:
775e5c31af7Sopenharmony_ci
776e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkPhysicalDeviceSparseProperties.adoc[]
777e5c31af7Sopenharmony_ci
778e5c31af7Sopenharmony_ci  * pname:residencyStandard2DBlockShape
779e5c31af7Sopenharmony_ciifndef::VKSC_VERSION_1_0[]
780e5c31af7Sopenharmony_ci    is ename:VK_TRUE if the physical device will access all single-sample 2D
781e5c31af7Sopenharmony_ci    sparse resources using the standard sparse image block shapes (based on
782e5c31af7Sopenharmony_ci    image format), as described in the
783e5c31af7Sopenharmony_ci    <<sparsememory-sparseblockshapessingle, Standard Sparse Image Block
784e5c31af7Sopenharmony_ci    Shapes (Single Sample)>> table.
785e5c31af7Sopenharmony_ci    If this property is not supported the value returned in the
786e5c31af7Sopenharmony_ci    pname:imageGranularity member of the sname:VkSparseImageFormatProperties
787e5c31af7Sopenharmony_ci    structure for single-sample 2D images is not required: to match the
788e5c31af7Sopenharmony_ci    standard sparse image block dimensions listed in the table.
789e5c31af7Sopenharmony_ciendif::VKSC_VERSION_1_0[]
790e5c31af7Sopenharmony_ciifdef::VKSC_VERSION_1_0[must: be ename:VK_FALSE in Vulkan SC <<SCID-8>>.]
791e5c31af7Sopenharmony_ci  * pname:residencyStandard2DMultisampleBlockShape
792e5c31af7Sopenharmony_ciifndef::VKSC_VERSION_1_0[]
793e5c31af7Sopenharmony_ci    is ename:VK_TRUE if the physical device will access all multisample 2D
794e5c31af7Sopenharmony_ci    sparse resources using the standard sparse image block shapes (based on
795e5c31af7Sopenharmony_ci    image format), as described in the
796e5c31af7Sopenharmony_ci    <<sparsememory-sparseblockshapesmsaa,Standard Sparse Image Block Shapes
797e5c31af7Sopenharmony_ci    (MSAA)>> table.
798e5c31af7Sopenharmony_ci    If this property is not supported, the value returned in the
799e5c31af7Sopenharmony_ci    pname:imageGranularity member of the sname:VkSparseImageFormatProperties
800e5c31af7Sopenharmony_ci    structure for multisample 2D images is not required: to match the
801e5c31af7Sopenharmony_ci    standard sparse image block dimensions listed in the table.
802e5c31af7Sopenharmony_ciendif::VKSC_VERSION_1_0[]
803e5c31af7Sopenharmony_ciifdef::VKSC_VERSION_1_0[must: be ename:VK_FALSE in Vulkan SC <<SCID-8>>.]
804e5c31af7Sopenharmony_ci  * pname:residencyStandard3DBlockShape
805e5c31af7Sopenharmony_ciifndef::VKSC_VERSION_1_0[]
806e5c31af7Sopenharmony_ci    is ename:VK_TRUE if the physical device will access all 3D sparse
807e5c31af7Sopenharmony_ci    resources using the standard sparse image block shapes (based on image
808e5c31af7Sopenharmony_ci    format), as described in the
809e5c31af7Sopenharmony_ci    <<sparsememory-sparseblockshapessingle,Standard Sparse Image Block
810e5c31af7Sopenharmony_ci    Shapes (Single Sample)>> table.
811e5c31af7Sopenharmony_ci    If this property is not supported, the value returned in the
812e5c31af7Sopenharmony_ci    pname:imageGranularity member of the sname:VkSparseImageFormatProperties
813e5c31af7Sopenharmony_ci    structure for 3D images is not required: to match the standard sparse
814e5c31af7Sopenharmony_ci    image block dimensions listed in the table.
815e5c31af7Sopenharmony_ciendif::VKSC_VERSION_1_0[]
816e5c31af7Sopenharmony_ciifdef::VKSC_VERSION_1_0[must: be ename:VK_FALSE in Vulkan SC <<SCID-8>>.]
817e5c31af7Sopenharmony_ci  * pname:residencyAlignedMipSize
818e5c31af7Sopenharmony_ciifndef::VKSC_VERSION_1_0[]
819e5c31af7Sopenharmony_ci    is ename:VK_TRUE if images with mip level dimensions that are not
820e5c31af7Sopenharmony_ci    integer multiples of the corresponding dimensions of the sparse image
821e5c31af7Sopenharmony_ci    block may: be placed in the mip tail.
822e5c31af7Sopenharmony_ci    If this property is not reported, only mip levels with dimensions
823e5c31af7Sopenharmony_ci    smaller than the pname:imageGranularity member of the
824e5c31af7Sopenharmony_ci    sname:VkSparseImageFormatProperties structure will be placed in the mip
825e5c31af7Sopenharmony_ci    tail.
826e5c31af7Sopenharmony_ci    If this property is reported the implementation is allowed to return
827e5c31af7Sopenharmony_ci    ename:VK_SPARSE_IMAGE_FORMAT_ALIGNED_MIP_SIZE_BIT in the pname:flags
828e5c31af7Sopenharmony_ci    member of sname:VkSparseImageFormatProperties, indicating that mip level
829e5c31af7Sopenharmony_ci    dimensions that are not integer multiples of the corresponding
830e5c31af7Sopenharmony_ci    dimensions of the sparse image block will be placed in the mip tail.
831e5c31af7Sopenharmony_ciendif::VKSC_VERSION_1_0[]
832e5c31af7Sopenharmony_ciifdef::VKSC_VERSION_1_0[must: be ename:VK_FALSE in Vulkan SC <<SCID-8>>.]
833e5c31af7Sopenharmony_ci  * pname:residencyNonResidentStrict
834e5c31af7Sopenharmony_ciifndef::VKSC_VERSION_1_0[]
835e5c31af7Sopenharmony_ci    specifies whether the physical device can: consistently access
836e5c31af7Sopenharmony_ci    non-resident regions of a resource.
837e5c31af7Sopenharmony_ci    If this property is ename:VK_TRUE, access to non-resident regions of
838e5c31af7Sopenharmony_ci    resources will be guaranteed to return values as if the resource was
839e5c31af7Sopenharmony_ci    populated with 0; writes to non-resident regions will be discarded.
840e5c31af7Sopenharmony_ciendif::VKSC_VERSION_1_0[]
841e5c31af7Sopenharmony_ciifdef::VKSC_VERSION_1_0[]
842e5c31af7Sopenharmony_ci    must: be ename:VK_FALSE in Vulkan SC <<SCID-8>>.
843e5c31af7Sopenharmony_ciifdef::hidden[]
844e5c31af7Sopenharmony_ci// tag::scdeviation[]
845e5c31af7Sopenharmony_ci  * slink:VkPhysicalDeviceSparseProperties::pname:residencyStandard2DBlockShape
846e5c31af7Sopenharmony_ci    must: be reported as ename:VK_FALSE <<SCID-8>>.
847e5c31af7Sopenharmony_ci  * slink:VkPhysicalDeviceSparseProperties::pname:residencyStandard2DMultisampleBlockShape
848e5c31af7Sopenharmony_ci    must: be reported as ename:VK_FALSE <<SCID-8>>.
849e5c31af7Sopenharmony_ci  * slink:VkPhysicalDeviceSparseProperties::pname:residencyStandard3DBlockShape
850e5c31af7Sopenharmony_ci    must: be reported as ename:VK_FALSE <<SCID-8>>.
851e5c31af7Sopenharmony_ci  * slink:VkPhysicalDeviceSparseProperties::pname:residencyAlignedMipSize
852e5c31af7Sopenharmony_ci    must: be reported as ename:VK_FALSE <<SCID-8>>.
853e5c31af7Sopenharmony_ci  * slink:VkPhysicalDeviceSparseProperties::pname:residencyNonResidentStrict
854e5c31af7Sopenharmony_ci    must: be reported as ename:VK_FALSE <<SCID-8>>.
855e5c31af7Sopenharmony_ci// end::scdeviation[]
856e5c31af7Sopenharmony_ciendif::hidden[]
857e5c31af7Sopenharmony_ciendif::VKSC_VERSION_1_0[]
858e5c31af7Sopenharmony_ci
859e5c31af7Sopenharmony_ci
860e5c31af7Sopenharmony_ciinclude::{generated}/validity/structs/VkPhysicalDeviceSparseProperties.adoc[]
861e5c31af7Sopenharmony_ci--
862e5c31af7Sopenharmony_ci
863e5c31af7Sopenharmony_ciifndef::VKSC_VERSION_1_0[]
864e5c31af7Sopenharmony_ci
865e5c31af7Sopenharmony_ci[[sparsememory-format-props]]
866e5c31af7Sopenharmony_ci=== Sparse Image Format Properties
867e5c31af7Sopenharmony_ci
868e5c31af7Sopenharmony_ciGiven that certain aspects of sparse image support, including the sparse
869e5c31af7Sopenharmony_ciimage block dimensions, may: be implementation-dependent,
870e5c31af7Sopenharmony_ciflink:vkGetPhysicalDeviceSparseImageFormatProperties can: be used to query
871e5c31af7Sopenharmony_cifor sparse image format properties prior to resource creation.
872e5c31af7Sopenharmony_ciThis command is used to check whether a given set of sparse image parameters
873e5c31af7Sopenharmony_ciis supported and what the sparse image block shape will be.
874e5c31af7Sopenharmony_ci
875e5c31af7Sopenharmony_ci
876e5c31af7Sopenharmony_ci==== Sparse Image Format Properties API
877e5c31af7Sopenharmony_ci
878e5c31af7Sopenharmony_ci[open,refpage='VkSparseImageFormatProperties',desc='Structure specifying sparse image format properties',type='structs']
879e5c31af7Sopenharmony_ci--
880e5c31af7Sopenharmony_ciThe sname:VkSparseImageFormatProperties structure is defined as:
881e5c31af7Sopenharmony_ci
882e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkSparseImageFormatProperties.adoc[]
883e5c31af7Sopenharmony_ci
884e5c31af7Sopenharmony_ci  * pname:aspectMask is a bitmask elink:VkImageAspectFlagBits specifying
885e5c31af7Sopenharmony_ci    which aspects of the image the properties apply to.
886e5c31af7Sopenharmony_ci  * pname:imageGranularity is the width, height, and depth of the sparse
887e5c31af7Sopenharmony_ci    image block in texels or compressed texel blocks.
888e5c31af7Sopenharmony_ci  * pname:flags is a bitmask of elink:VkSparseImageFormatFlagBits specifying
889e5c31af7Sopenharmony_ci    additional information about the sparse resource.
890e5c31af7Sopenharmony_ci
891e5c31af7Sopenharmony_ciinclude::{generated}/validity/structs/VkSparseImageFormatProperties.adoc[]
892e5c31af7Sopenharmony_ci--
893e5c31af7Sopenharmony_ci
894e5c31af7Sopenharmony_ci[open,refpage='VkSparseImageFormatFlagBits',desc='Bitmask specifying additional information about a sparse image resource',type='enums']
895e5c31af7Sopenharmony_ci--
896e5c31af7Sopenharmony_ciBits which may: be set in slink:VkSparseImageFormatProperties::pname:flags,
897e5c31af7Sopenharmony_cispecifying additional information about the sparse resource, are:
898e5c31af7Sopenharmony_ci
899e5c31af7Sopenharmony_ciinclude::{generated}/api/enums/VkSparseImageFormatFlagBits.adoc[]
900e5c31af7Sopenharmony_ci
901e5c31af7Sopenharmony_ci  * ename:VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT specifies that the image
902e5c31af7Sopenharmony_ci    uses a single mip tail region for all array layers.
903e5c31af7Sopenharmony_ci  * ename:VK_SPARSE_IMAGE_FORMAT_ALIGNED_MIP_SIZE_BIT specifies that the
904e5c31af7Sopenharmony_ci    first mip level whose dimensions are not integer multiples of the
905e5c31af7Sopenharmony_ci    corresponding dimensions of the sparse image block begins the mip tail
906e5c31af7Sopenharmony_ci    region.
907e5c31af7Sopenharmony_ci  * ename:VK_SPARSE_IMAGE_FORMAT_NONSTANDARD_BLOCK_SIZE_BIT specifies that
908e5c31af7Sopenharmony_ci    the image uses non-standard sparse image block dimensions, and the
909e5c31af7Sopenharmony_ci    pname:imageGranularity values do not match the standard sparse image
910e5c31af7Sopenharmony_ci    block dimensions for the given format.
911e5c31af7Sopenharmony_ci--
912e5c31af7Sopenharmony_ci
913e5c31af7Sopenharmony_ci[open,refpage='VkSparseImageFormatFlags',desc='Bitmask of VkSparseImageFormatFlagBits',type='flags']
914e5c31af7Sopenharmony_ci--
915e5c31af7Sopenharmony_ciinclude::{generated}/api/flags/VkSparseImageFormatFlags.adoc[]
916e5c31af7Sopenharmony_ci
917e5c31af7Sopenharmony_citname:VkSparseImageFormatFlags is a bitmask type for setting a mask of zero
918e5c31af7Sopenharmony_cior more elink:VkSparseImageFormatFlagBits.
919e5c31af7Sopenharmony_ci--
920e5c31af7Sopenharmony_ci
921e5c31af7Sopenharmony_ci[open,refpage='vkGetPhysicalDeviceSparseImageFormatProperties',desc='Retrieve properties of an image format applied to sparse images',type='protos']
922e5c31af7Sopenharmony_ci--
923e5c31af7Sopenharmony_cifname:vkGetPhysicalDeviceSparseImageFormatProperties returns an array of
924e5c31af7Sopenharmony_cislink:VkSparseImageFormatProperties.
925e5c31af7Sopenharmony_ciEach element will describe properties for one set of image aspects that are
926e5c31af7Sopenharmony_cibound simultaneously in the image.
927e5c31af7Sopenharmony_ciThis is usually one element for each aspect in the image, but for
928e5c31af7Sopenharmony_ciinterleaved depth/stencil images there is only one element describing the
929e5c31af7Sopenharmony_cicombined aspects.
930e5c31af7Sopenharmony_ci
931e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkGetPhysicalDeviceSparseImageFormatProperties.adoc[]
932e5c31af7Sopenharmony_ci
933e5c31af7Sopenharmony_ci  * pname:physicalDevice is the physical device from which to query the
934e5c31af7Sopenharmony_ci    sparse image format properties.
935e5c31af7Sopenharmony_ci  * pname:format is the image format.
936e5c31af7Sopenharmony_ci  * pname:type is the dimensionality of the image.
937e5c31af7Sopenharmony_ci  * pname:samples is a elink:VkSampleCountFlagBits value specifying the
938e5c31af7Sopenharmony_ci    number of samples per texel.
939e5c31af7Sopenharmony_ci  * pname:usage is a bitmask describing the intended usage of the image.
940e5c31af7Sopenharmony_ci  * pname:tiling is the tiling arrangement of the texel blocks in memory.
941e5c31af7Sopenharmony_ci  * pname:pPropertyCount is a pointer to an integer related to the number of
942e5c31af7Sopenharmony_ci    sparse format properties available or queried, as described below.
943e5c31af7Sopenharmony_ci  * pname:pProperties is either `NULL` or a pointer to an array of
944e5c31af7Sopenharmony_ci    slink:VkSparseImageFormatProperties structures.
945e5c31af7Sopenharmony_ci
946e5c31af7Sopenharmony_ciIf pname:pProperties is `NULL`, then the number of sparse format properties
947e5c31af7Sopenharmony_ciavailable is returned in pname:pPropertyCount.
948e5c31af7Sopenharmony_ciOtherwise, pname:pPropertyCount must: point to a variable set by the user to
949e5c31af7Sopenharmony_cithe number of elements in the pname:pProperties array, and on return the
950e5c31af7Sopenharmony_civariable is overwritten with the number of structures actually written to
951e5c31af7Sopenharmony_cipname:pProperties.
952e5c31af7Sopenharmony_ciIf pname:pPropertyCount is less than the number of sparse format properties
953e5c31af7Sopenharmony_ciavailable, at most pname:pPropertyCount structures will be written.
954e5c31af7Sopenharmony_ci
955e5c31af7Sopenharmony_ciIf ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT is not supported for the given
956e5c31af7Sopenharmony_ciarguments, pname:pPropertyCount will be set to zero upon return, and no data
957e5c31af7Sopenharmony_ciwill be written to pname:pProperties.
958e5c31af7Sopenharmony_ci
959e5c31af7Sopenharmony_ciMultiple aspects are returned for depth/stencil images that are implemented
960e5c31af7Sopenharmony_cias separate planes by the implementation.
961e5c31af7Sopenharmony_ciThe depth and stencil data planes each have unique
962e5c31af7Sopenharmony_cisname:VkSparseImageFormatProperties data.
963e5c31af7Sopenharmony_ci
964e5c31af7Sopenharmony_ciDepth/stencil images with depth and stencil data interleaved into a single
965e5c31af7Sopenharmony_ciplane will return a single sname:VkSparseImageFormatProperties structure
966e5c31af7Sopenharmony_ciwith the pname:aspectMask set to ename:VK_IMAGE_ASPECT_DEPTH_BIT |
967e5c31af7Sopenharmony_ciename:VK_IMAGE_ASPECT_STENCIL_BIT.
968e5c31af7Sopenharmony_ci
969e5c31af7Sopenharmony_ci.Valid Usage
970e5c31af7Sopenharmony_ci****
971e5c31af7Sopenharmony_ci  * [[VUID-vkGetPhysicalDeviceSparseImageFormatProperties-samples-01094]]
972e5c31af7Sopenharmony_ci    pname:samples must: be a valid elink:VkSampleCountFlagBits value that is
973e5c31af7Sopenharmony_ci    set in sname:VkImageFormatProperties::pname:sampleCounts returned by
974e5c31af7Sopenharmony_ci    fname:vkGetPhysicalDeviceImageFormatProperties with pname:format,
975e5c31af7Sopenharmony_ci    pname:type, pname:tiling, and pname:usage equal to those in this command
976e5c31af7Sopenharmony_ci    and pname:flags equal to the value that is set in
977e5c31af7Sopenharmony_ci    slink:VkImageCreateInfo::pname:flags when the image is created
978e5c31af7Sopenharmony_ci****
979e5c31af7Sopenharmony_ci
980e5c31af7Sopenharmony_ciinclude::{generated}/validity/protos/vkGetPhysicalDeviceSparseImageFormatProperties.adoc[]
981e5c31af7Sopenharmony_ci--
982e5c31af7Sopenharmony_ci
983e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_get_physical_device_properties2[]
984e5c31af7Sopenharmony_ci[open,refpage='vkGetPhysicalDeviceSparseImageFormatProperties2',desc='Retrieve properties of an image format applied to sparse images',type='protos']
985e5c31af7Sopenharmony_ci--
986e5c31af7Sopenharmony_cifname:vkGetPhysicalDeviceSparseImageFormatProperties2 returns an array of
987e5c31af7Sopenharmony_cislink:VkSparseImageFormatProperties2.
988e5c31af7Sopenharmony_ciEach element will describe properties for one set of image aspects that are
989e5c31af7Sopenharmony_cibound simultaneously in the image.
990e5c31af7Sopenharmony_ciThis is usually one element for each aspect in the image, but for
991e5c31af7Sopenharmony_ciinterleaved depth/stencil images there is only one element describing the
992e5c31af7Sopenharmony_cicombined aspects.
993e5c31af7Sopenharmony_ci
994e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1[]
995e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkGetPhysicalDeviceSparseImageFormatProperties2.adoc[]
996e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1[]
997e5c31af7Sopenharmony_ci
998e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1+VK_KHR_get_physical_device_properties2[or the equivalent command]
999e5c31af7Sopenharmony_ci
1000e5c31af7Sopenharmony_ciifdef::VK_KHR_get_physical_device_properties2[]
1001e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkGetPhysicalDeviceSparseImageFormatProperties2KHR.adoc[]
1002e5c31af7Sopenharmony_ciendif::VK_KHR_get_physical_device_properties2[]
1003e5c31af7Sopenharmony_ci
1004e5c31af7Sopenharmony_ci  * pname:physicalDevice is the physical device from which to query the
1005e5c31af7Sopenharmony_ci    sparse image format properties.
1006e5c31af7Sopenharmony_ci  * pname:pFormatInfo is a pointer to a
1007e5c31af7Sopenharmony_ci    slink:VkPhysicalDeviceSparseImageFormatInfo2 structure containing input
1008e5c31af7Sopenharmony_ci    parameters to the command.
1009e5c31af7Sopenharmony_ci  * pname:pPropertyCount is a pointer to an integer related to the number of
1010e5c31af7Sopenharmony_ci    sparse format properties available or queried, as described below.
1011e5c31af7Sopenharmony_ci  * pname:pProperties is either `NULL` or a pointer to an array of
1012e5c31af7Sopenharmony_ci    slink:VkSparseImageFormatProperties2 structures.
1013e5c31af7Sopenharmony_ci
1014e5c31af7Sopenharmony_cifname:vkGetPhysicalDeviceSparseImageFormatProperties2 behaves identically to
1015e5c31af7Sopenharmony_ciflink:vkGetPhysicalDeviceSparseImageFormatProperties, with the ability to
1016e5c31af7Sopenharmony_cireturn extended information by adding extending structures to the
1017e5c31af7Sopenharmony_cipname:pNext chain of its pname:pProperties parameter.
1018e5c31af7Sopenharmony_ci
1019e5c31af7Sopenharmony_ciinclude::{generated}/validity/protos/vkGetPhysicalDeviceSparseImageFormatProperties2.adoc[]
1020e5c31af7Sopenharmony_ci--
1021e5c31af7Sopenharmony_ci
1022e5c31af7Sopenharmony_ci[open,refpage='VkPhysicalDeviceSparseImageFormatInfo2',desc='Structure specifying sparse image format inputs',type='structs']
1023e5c31af7Sopenharmony_ci--
1024e5c31af7Sopenharmony_ciThe sname:VkPhysicalDeviceSparseImageFormatInfo2 structure is defined as:
1025e5c31af7Sopenharmony_ci
1026e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkPhysicalDeviceSparseImageFormatInfo2.adoc[]
1027e5c31af7Sopenharmony_ci
1028e5c31af7Sopenharmony_ciifdef::VK_KHR_get_physical_device_properties2[]
1029e5c31af7Sopenharmony_cior the equivalent
1030e5c31af7Sopenharmony_ci
1031e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkPhysicalDeviceSparseImageFormatInfo2KHR.adoc[]
1032e5c31af7Sopenharmony_ciendif::VK_KHR_get_physical_device_properties2[]
1033e5c31af7Sopenharmony_ci
1034e5c31af7Sopenharmony_ci  * pname:sType is a elink:VkStructureType value identifying this structure.
1035e5c31af7Sopenharmony_ci  * pname:pNext is `NULL` or a pointer to a structure extending this
1036e5c31af7Sopenharmony_ci    structure.
1037e5c31af7Sopenharmony_ci  * pname:format is the image format.
1038e5c31af7Sopenharmony_ci  * pname:type is the dimensionality of the image.
1039e5c31af7Sopenharmony_ci  * pname:samples is a elink:VkSampleCountFlagBits value specifying the
1040e5c31af7Sopenharmony_ci    number of samples per texel.
1041e5c31af7Sopenharmony_ci  * pname:usage is a bitmask describing the intended usage of the image.
1042e5c31af7Sopenharmony_ci  * pname:tiling is the tiling arrangement of the texel blocks in memory.
1043e5c31af7Sopenharmony_ci
1044e5c31af7Sopenharmony_ci.Valid Usage
1045e5c31af7Sopenharmony_ci****
1046e5c31af7Sopenharmony_ci  * [[VUID-VkPhysicalDeviceSparseImageFormatInfo2-samples-01095]]
1047e5c31af7Sopenharmony_ci    pname:samples must: be a valid elink:VkSampleCountFlagBits value that is
1048e5c31af7Sopenharmony_ci    set in sname:VkImageFormatProperties::pname:sampleCounts returned by
1049e5c31af7Sopenharmony_ci    fname:vkGetPhysicalDeviceImageFormatProperties with pname:format,
1050e5c31af7Sopenharmony_ci    pname:type, pname:tiling, and pname:usage equal to those in this command
1051e5c31af7Sopenharmony_ci    and pname:flags equal to the value that is set in
1052e5c31af7Sopenharmony_ci    slink:VkImageCreateInfo::pname:flags when the image is created
1053e5c31af7Sopenharmony_ci****
1054e5c31af7Sopenharmony_ci
1055e5c31af7Sopenharmony_ciinclude::{generated}/validity/structs/VkPhysicalDeviceSparseImageFormatInfo2.adoc[]
1056e5c31af7Sopenharmony_ci--
1057e5c31af7Sopenharmony_ci
1058e5c31af7Sopenharmony_ci[open,refpage='VkSparseImageFormatProperties2',desc='Structure specifying sparse image format properties',type='structs']
1059e5c31af7Sopenharmony_ci--
1060e5c31af7Sopenharmony_ciThe sname:VkSparseImageFormatProperties2 structure is defined as:
1061e5c31af7Sopenharmony_ci
1062e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkSparseImageFormatProperties2.adoc[]
1063e5c31af7Sopenharmony_ci
1064e5c31af7Sopenharmony_ciifdef::VK_KHR_get_physical_device_properties2[]
1065e5c31af7Sopenharmony_cior the equivalent
1066e5c31af7Sopenharmony_ci
1067e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkSparseImageFormatProperties2KHR.adoc[]
1068e5c31af7Sopenharmony_ciendif::VK_KHR_get_physical_device_properties2[]
1069e5c31af7Sopenharmony_ci
1070e5c31af7Sopenharmony_ci  * pname:sType is a elink:VkStructureType value identifying this structure.
1071e5c31af7Sopenharmony_ci  * pname:pNext is `NULL` or a pointer to a structure extending this
1072e5c31af7Sopenharmony_ci    structure.
1073e5c31af7Sopenharmony_ci  * pname:properties is a slink:VkSparseImageFormatProperties structure
1074e5c31af7Sopenharmony_ci    which is populated with the same values as in
1075e5c31af7Sopenharmony_ci    flink:vkGetPhysicalDeviceSparseImageFormatProperties.
1076e5c31af7Sopenharmony_ci
1077e5c31af7Sopenharmony_ciinclude::{generated}/validity/structs/VkSparseImageFormatProperties2.adoc[]
1078e5c31af7Sopenharmony_ci--
1079e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_get_physical_device_properties2[]
1080e5c31af7Sopenharmony_ci
1081e5c31af7Sopenharmony_ci
1082e5c31af7Sopenharmony_ci[[sparsememory-resource-creation]]
1083e5c31af7Sopenharmony_ci=== Sparse Resource Creation
1084e5c31af7Sopenharmony_ci
1085e5c31af7Sopenharmony_ciSparse resources require that one or more sparse feature flags be specified
1086e5c31af7Sopenharmony_ci(as part of the sname:VkPhysicalDeviceFeatures structure described
1087e5c31af7Sopenharmony_cipreviously in the <<sparsememory-physicalfeatures,Physical Device Features>>
1088e5c31af7Sopenharmony_cisection) when calling flink:vkCreateDevice.
1089e5c31af7Sopenharmony_ciWhen the appropriate device features are enabled, the
1090e5c31af7Sopenharmony_cietext:VK_BUFFER_CREATE_SPARSE_* and etext:VK_IMAGE_CREATE_SPARSE_* flags
1091e5c31af7Sopenharmony_cican: be used.
1092e5c31af7Sopenharmony_ciSee flink:vkCreateBuffer and flink:vkCreateImage for details of the resource
1093e5c31af7Sopenharmony_cicreation APIs.
1094e5c31af7Sopenharmony_ci
1095e5c31af7Sopenharmony_ci[NOTE]
1096e5c31af7Sopenharmony_ci.Note
1097e5c31af7Sopenharmony_ci====
1098e5c31af7Sopenharmony_ciSpecifying ename:VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT or
1099e5c31af7Sopenharmony_ciename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT requires specifying
1100e5c31af7Sopenharmony_ciename:VK_BUFFER_CREATE_SPARSE_BINDING_BIT or
1101e5c31af7Sopenharmony_ciename:VK_IMAGE_CREATE_SPARSE_BINDING_BIT, respectively, as well.
1102e5c31af7Sopenharmony_ciThis means that resources must: be created with the appropriate
1103e5c31af7Sopenharmony_cietext:*_SPARSE_BINDING_BIT to be used with the sparse binding command
1104e5c31af7Sopenharmony_ci(fname:vkQueueBindSparse).
1105e5c31af7Sopenharmony_ci====
1106e5c31af7Sopenharmony_ci
1107e5c31af7Sopenharmony_ci
1108e5c31af7Sopenharmony_ci[[sparsememory-memory-requirements]]
1109e5c31af7Sopenharmony_ci=== Sparse Resource Memory Requirements
1110e5c31af7Sopenharmony_ci
1111e5c31af7Sopenharmony_ciSparse resources have specific memory requirements related to binding sparse
1112e5c31af7Sopenharmony_cimemory.
1113e5c31af7Sopenharmony_ciThese memory requirements are reported differently for sname:VkBuffer
1114e5c31af7Sopenharmony_ciobjects and sname:VkImage objects.
1115e5c31af7Sopenharmony_ci
1116e5c31af7Sopenharmony_ci
1117e5c31af7Sopenharmony_ci[[sparsememory-memory-buffer-fully-resident]]
1118e5c31af7Sopenharmony_ci==== Buffer and Fully-Resident Images
1119e5c31af7Sopenharmony_ci
1120e5c31af7Sopenharmony_ciBuffers (both fully and partially resident) and fully-resident images can:
1121e5c31af7Sopenharmony_cibe bound to memory using only the data from sname:VkMemoryRequirements.
1122e5c31af7Sopenharmony_ciFor all sparse resources the sname:VkMemoryRequirements::pname:alignment
1123e5c31af7Sopenharmony_cimember specifies both the bindable sparse block size in bytes and required:
1124e5c31af7Sopenharmony_cialignment of sname:VkDeviceMemory.
1125e5c31af7Sopenharmony_ci
1126e5c31af7Sopenharmony_ci
1127e5c31af7Sopenharmony_ci[[sparsememory-memory-partially-resident]]
1128e5c31af7Sopenharmony_ci==== Partially Resident Images
1129e5c31af7Sopenharmony_ci
1130e5c31af7Sopenharmony_ciPartially resident images have a different method for binding memory.
1131e5c31af7Sopenharmony_ciAs with buffers and fully resident images, the
1132e5c31af7Sopenharmony_cisname:VkMemoryRequirements::pname:alignment field specifies the bindable
1133e5c31af7Sopenharmony_cisparse block size in bytes for the image.
1134e5c31af7Sopenharmony_ci
1135e5c31af7Sopenharmony_ciRequesting sparse memory requirements for sname:VkImage objects using
1136e5c31af7Sopenharmony_cifname:vkGetImageSparseMemoryRequirements will return an array of one or more
1137e5c31af7Sopenharmony_cisname:VkSparseImageMemoryRequirements structures.
1138e5c31af7Sopenharmony_ciEach structure describes the sparse memory requirements for a group of
1139e5c31af7Sopenharmony_ciaspects of the image.
1140e5c31af7Sopenharmony_ci
1141e5c31af7Sopenharmony_ciThe sparse image must: have been created using the
1142e5c31af7Sopenharmony_ciename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT flag to retrieve valid sparse
1143e5c31af7Sopenharmony_ciimage memory requirements.
1144e5c31af7Sopenharmony_ci
1145e5c31af7Sopenharmony_ci
1146e5c31af7Sopenharmony_ci==== Sparse Image Memory Requirements
1147e5c31af7Sopenharmony_ci
1148e5c31af7Sopenharmony_ci[open,refpage='VkSparseImageMemoryRequirements',desc='Structure specifying sparse image memory requirements',type='structs']
1149e5c31af7Sopenharmony_ci--
1150e5c31af7Sopenharmony_ciThe sname:VkSparseImageMemoryRequirements structure is defined as:
1151e5c31af7Sopenharmony_ci
1152e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkSparseImageMemoryRequirements.adoc[]
1153e5c31af7Sopenharmony_ci
1154e5c31af7Sopenharmony_ci  * pname:formatProperties is a slink:VkSparseImageFormatProperties
1155e5c31af7Sopenharmony_ci    structure specifying properties of the image format.
1156e5c31af7Sopenharmony_ci  * pname:imageMipTailFirstLod is the first mip level at which image
1157e5c31af7Sopenharmony_ci    subresources are included in the mip tail region.
1158e5c31af7Sopenharmony_ci  * pname:imageMipTailSize is the memory size (in bytes) of the mip tail
1159e5c31af7Sopenharmony_ci    region.
1160e5c31af7Sopenharmony_ci    If pname:formatProperties.flags contains
1161e5c31af7Sopenharmony_ci    ename:VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT, this is the size of the
1162e5c31af7Sopenharmony_ci    whole mip tail, otherwise this is the size of the mip tail of a single
1163e5c31af7Sopenharmony_ci    array layer.
1164e5c31af7Sopenharmony_ci    This value is guaranteed to be a multiple of the sparse block size in
1165e5c31af7Sopenharmony_ci    bytes.
1166e5c31af7Sopenharmony_ci  * pname:imageMipTailOffset is the opaque memory offset used with
1167e5c31af7Sopenharmony_ci    slink:VkSparseImageOpaqueMemoryBindInfo to bind the mip tail region(s).
1168e5c31af7Sopenharmony_ci  * pname:imageMipTailStride is the offset stride between each array-layer's
1169e5c31af7Sopenharmony_ci    mip tail, if pname:formatProperties.flags does not contain
1170e5c31af7Sopenharmony_ci    ename:VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT (otherwise the value is
1171e5c31af7Sopenharmony_ci    undefined:).
1172e5c31af7Sopenharmony_ci
1173e5c31af7Sopenharmony_ciinclude::{generated}/validity/structs/VkSparseImageMemoryRequirements.adoc[]
1174e5c31af7Sopenharmony_ci--
1175e5c31af7Sopenharmony_ci
1176e5c31af7Sopenharmony_ci[open,refpage='vkGetImageSparseMemoryRequirements',desc='Query the memory requirements for a sparse image',type='protos']
1177e5c31af7Sopenharmony_ci--
1178e5c31af7Sopenharmony_ciTo query sparse memory requirements for an image, call:
1179e5c31af7Sopenharmony_ci
1180e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkGetImageSparseMemoryRequirements.adoc[]
1181e5c31af7Sopenharmony_ci
1182e5c31af7Sopenharmony_ci  * pname:device is the logical device that owns the image.
1183e5c31af7Sopenharmony_ci  * pname:image is the slink:VkImage object to get the memory requirements
1184e5c31af7Sopenharmony_ci    for.
1185e5c31af7Sopenharmony_ci  * pname:pSparseMemoryRequirementCount is a pointer to an integer related
1186e5c31af7Sopenharmony_ci    to the number of sparse memory requirements available or queried, as
1187e5c31af7Sopenharmony_ci    described below.
1188e5c31af7Sopenharmony_ci  * pname:pSparseMemoryRequirements is either `NULL` or a pointer to an
1189e5c31af7Sopenharmony_ci    array of sname:VkSparseImageMemoryRequirements structures.
1190e5c31af7Sopenharmony_ci
1191e5c31af7Sopenharmony_ciIf pname:pSparseMemoryRequirements is `NULL`, then the number of sparse
1192e5c31af7Sopenharmony_cimemory requirements available is returned in
1193e5c31af7Sopenharmony_cipname:pSparseMemoryRequirementCount.
1194e5c31af7Sopenharmony_ciOtherwise, pname:pSparseMemoryRequirementCount must: point to a variable set
1195e5c31af7Sopenharmony_ciby the user to the number of elements in the pname:pSparseMemoryRequirements
1196e5c31af7Sopenharmony_ciarray, and on return the variable is overwritten with the number of
1197e5c31af7Sopenharmony_cistructures actually written to pname:pSparseMemoryRequirements.
1198e5c31af7Sopenharmony_ciIf pname:pSparseMemoryRequirementCount is less than the number of sparse
1199e5c31af7Sopenharmony_cimemory requirements available, at most pname:pSparseMemoryRequirementCount
1200e5c31af7Sopenharmony_cistructures will be written.
1201e5c31af7Sopenharmony_ci
1202e5c31af7Sopenharmony_ciIf the image was not created with ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT
1203e5c31af7Sopenharmony_cithen pname:pSparseMemoryRequirementCount will be set to zero and
1204e5c31af7Sopenharmony_cipname:pSparseMemoryRequirements will not be written to.
1205e5c31af7Sopenharmony_ci
1206e5c31af7Sopenharmony_ci[NOTE]
1207e5c31af7Sopenharmony_ci.Note
1208e5c31af7Sopenharmony_ci====
1209e5c31af7Sopenharmony_ciIt is legal for an implementation to report a larger value in
1210e5c31af7Sopenharmony_cisname:VkMemoryRequirements::pname:size than would be obtained by adding
1211e5c31af7Sopenharmony_citogether memory sizes for all sname:VkSparseImageMemoryRequirements returned
1212e5c31af7Sopenharmony_ciby fname:vkGetImageSparseMemoryRequirements.
1213e5c31af7Sopenharmony_ciThis may: occur when the implementation requires unused padding in the
1214e5c31af7Sopenharmony_ciaddress range describing the resource.
1215e5c31af7Sopenharmony_ci====
1216e5c31af7Sopenharmony_ci
1217e5c31af7Sopenharmony_ciinclude::{generated}/validity/protos/vkGetImageSparseMemoryRequirements.adoc[]
1218e5c31af7Sopenharmony_ci--
1219e5c31af7Sopenharmony_ci
1220e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_get_memory_requirements2[]
1221e5c31af7Sopenharmony_ci[open,refpage='vkGetImageSparseMemoryRequirements2',desc='Query the memory requirements for a sparse image',type='protos']
1222e5c31af7Sopenharmony_ci--
1223e5c31af7Sopenharmony_ciTo query sparse memory requirements for an image, call:
1224e5c31af7Sopenharmony_ci
1225e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1[]
1226e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkGetImageSparseMemoryRequirements2.adoc[]
1227e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1[]
1228e5c31af7Sopenharmony_ci
1229e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1+VK_KHR_get_memory_requirements2[or the equivalent command]
1230e5c31af7Sopenharmony_ci
1231e5c31af7Sopenharmony_ciifdef::VK_KHR_get_memory_requirements2[]
1232e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkGetImageSparseMemoryRequirements2KHR.adoc[]
1233e5c31af7Sopenharmony_ciendif::VK_KHR_get_memory_requirements2[]
1234e5c31af7Sopenharmony_ci
1235e5c31af7Sopenharmony_ci  * pname:device is the logical device that owns the image.
1236e5c31af7Sopenharmony_ci  * pname:pInfo is a pointer to a sname:VkImageSparseMemoryRequirementsInfo2
1237e5c31af7Sopenharmony_ci    structure containing parameters required for the memory requirements
1238e5c31af7Sopenharmony_ci    query.
1239e5c31af7Sopenharmony_ci  * pname:pSparseMemoryRequirementCount is a pointer to an integer related
1240e5c31af7Sopenharmony_ci    to the number of sparse memory requirements available or queried, as
1241e5c31af7Sopenharmony_ci    described below.
1242e5c31af7Sopenharmony_ci  * pname:pSparseMemoryRequirements is either `NULL` or a pointer to an
1243e5c31af7Sopenharmony_ci    array of sname:VkSparseImageMemoryRequirements2 structures.
1244e5c31af7Sopenharmony_ci
1245e5c31af7Sopenharmony_ciinclude::{generated}/validity/protos/vkGetImageSparseMemoryRequirements2.adoc[]
1246e5c31af7Sopenharmony_ci--
1247e5c31af7Sopenharmony_ci
1248e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_3,VK_KHR_maintenance4[]
1249e5c31af7Sopenharmony_ci[open,refpage='vkGetDeviceImageSparseMemoryRequirements',desc='Query the memory requirements for a sparse image',type='protos',alias='vkGetDeviceImageSparseMemoryRequirementsKHR']
1250e5c31af7Sopenharmony_ci--
1251e5c31af7Sopenharmony_ciTo determine the sparse memory requirements for an image resource without
1252e5c31af7Sopenharmony_cicreating an object, call:
1253e5c31af7Sopenharmony_ci
1254e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_3[]
1255e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkGetDeviceImageSparseMemoryRequirements.adoc[]
1256e5c31af7Sopenharmony_ciendif::VK_VERSION_1_3[]
1257e5c31af7Sopenharmony_ci
1258e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_3+VK_KHR_maintenance4[or the equivalent command]
1259e5c31af7Sopenharmony_ci
1260e5c31af7Sopenharmony_ciifdef::VK_KHR_maintenance4[]
1261e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkGetDeviceImageSparseMemoryRequirementsKHR.adoc[]
1262e5c31af7Sopenharmony_ciendif::VK_KHR_maintenance4[]
1263e5c31af7Sopenharmony_ci
1264e5c31af7Sopenharmony_ci  * pname:device is the logical device intended to own the image.
1265e5c31af7Sopenharmony_ci  * pname:pInfo is a pointer to a slink:VkDeviceImageMemoryRequirements
1266e5c31af7Sopenharmony_ci    structure containing parameters required for the memory requirements
1267e5c31af7Sopenharmony_ci    query.
1268e5c31af7Sopenharmony_ci  * pname:pSparseMemoryRequirementCount is a pointer to an integer related
1269e5c31af7Sopenharmony_ci    to the number of sparse memory requirements available or queried, as
1270e5c31af7Sopenharmony_ci    described below.
1271e5c31af7Sopenharmony_ci  * pname:pSparseMemoryRequirements is either `NULL` or a pointer to an
1272e5c31af7Sopenharmony_ci    array of sname:VkSparseImageMemoryRequirements2 structures.
1273e5c31af7Sopenharmony_ci
1274e5c31af7Sopenharmony_ciinclude::{generated}/validity/protos/vkGetDeviceImageSparseMemoryRequirements.adoc[]
1275e5c31af7Sopenharmony_ci--
1276e5c31af7Sopenharmony_ciendif::VK_VERSION_1_3,VK_KHR_maintenance4[]
1277e5c31af7Sopenharmony_ci
1278e5c31af7Sopenharmony_ci[open,refpage='VkImageSparseMemoryRequirementsInfo2',desc='(None)',type='structs']
1279e5c31af7Sopenharmony_ci--
1280e5c31af7Sopenharmony_ciThe sname:VkImageSparseMemoryRequirementsInfo2 structure is defined as:
1281e5c31af7Sopenharmony_ci
1282e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkImageSparseMemoryRequirementsInfo2.adoc[]
1283e5c31af7Sopenharmony_ci
1284e5c31af7Sopenharmony_ciifdef::VK_KHR_get_memory_requirements2[]
1285e5c31af7Sopenharmony_cior the equivalent
1286e5c31af7Sopenharmony_ci
1287e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkImageSparseMemoryRequirementsInfo2KHR.adoc[]
1288e5c31af7Sopenharmony_ciendif::VK_KHR_get_memory_requirements2[]
1289e5c31af7Sopenharmony_ci
1290e5c31af7Sopenharmony_ci  * pname:sType is a elink:VkStructureType value identifying this structure.
1291e5c31af7Sopenharmony_ci  * pname:pNext is `NULL` or a pointer to a structure extending this
1292e5c31af7Sopenharmony_ci    structure.
1293e5c31af7Sopenharmony_ci  * pname:image is the image to query.
1294e5c31af7Sopenharmony_ci
1295e5c31af7Sopenharmony_ciinclude::{generated}/validity/structs/VkImageSparseMemoryRequirementsInfo2.adoc[]
1296e5c31af7Sopenharmony_ci--
1297e5c31af7Sopenharmony_ci
1298e5c31af7Sopenharmony_ci[open,refpage='VkSparseImageMemoryRequirements2',desc='(None)',type='structs']
1299e5c31af7Sopenharmony_ci--
1300e5c31af7Sopenharmony_ciThe sname:VkSparseImageMemoryRequirements2 structure is defined as:
1301e5c31af7Sopenharmony_ci
1302e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkSparseImageMemoryRequirements2.adoc[]
1303e5c31af7Sopenharmony_ci
1304e5c31af7Sopenharmony_ciifdef::VK_KHR_get_memory_requirements2[]
1305e5c31af7Sopenharmony_cior the equivalent
1306e5c31af7Sopenharmony_ci
1307e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkSparseImageMemoryRequirements2KHR.adoc[]
1308e5c31af7Sopenharmony_ciendif::VK_KHR_get_memory_requirements2[]
1309e5c31af7Sopenharmony_ci
1310e5c31af7Sopenharmony_ci  * pname:sType is a elink:VkStructureType value identifying this structure.
1311e5c31af7Sopenharmony_ci  * pname:pNext is `NULL` or a pointer to a structure extending this
1312e5c31af7Sopenharmony_ci    structure.
1313e5c31af7Sopenharmony_ci  * pname:memoryRequirements is a slink:VkSparseImageMemoryRequirements
1314e5c31af7Sopenharmony_ci    structure describing the memory requirements of the sparse image.
1315e5c31af7Sopenharmony_ci
1316e5c31af7Sopenharmony_ciinclude::{generated}/validity/structs/VkSparseImageMemoryRequirements2.adoc[]
1317e5c31af7Sopenharmony_ci--
1318e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_get_memory_requirements2[]
1319e5c31af7Sopenharmony_ci
1320e5c31af7Sopenharmony_ci
1321e5c31af7Sopenharmony_ci[[sparsememory-resource-binding]]
1322e5c31af7Sopenharmony_ci=== Binding Resource Memory
1323e5c31af7Sopenharmony_ci
1324e5c31af7Sopenharmony_ciNon-sparse resources are backed by a single physical allocation prior to
1325e5c31af7Sopenharmony_cidevice use (via fname:vkBindImageMemory or fname:vkBindBufferMemory), and
1326e5c31af7Sopenharmony_citheir backing must: not be changed.
1327e5c31af7Sopenharmony_ciOn the other hand, sparse resources can: be bound to memory non-contiguously
1328e5c31af7Sopenharmony_ciand these bindings can: be altered during the lifetime of the resource.
1329e5c31af7Sopenharmony_ci
1330e5c31af7Sopenharmony_ciifndef::VKSC_VERSION_1_0[]
1331e5c31af7Sopenharmony_ci
1332e5c31af7Sopenharmony_ci[NOTE]
1333e5c31af7Sopenharmony_ci.Note
1334e5c31af7Sopenharmony_ci====
1335e5c31af7Sopenharmony_ciIt is important to note that freeing a sname:VkDeviceMemory object with
1336e5c31af7Sopenharmony_cifname:vkFreeMemory will not cause resources (or resource regions) bound to
1337e5c31af7Sopenharmony_cithe memory object to become unbound.
1338e5c31af7Sopenharmony_ciApplications must: not access resources bound to memory that has been freed.
1339e5c31af7Sopenharmony_ci====
1340e5c31af7Sopenharmony_ci
1341e5c31af7Sopenharmony_ciendif::VKSC_VERSION_1_0[]
1342e5c31af7Sopenharmony_ci
1343e5c31af7Sopenharmony_ciSparse memory bindings execute on a queue that includes the
1344e5c31af7Sopenharmony_ciename:VK_QUEUE_SPARSE_BINDING_BIT bit.
1345e5c31af7Sopenharmony_ciApplications must: use <<synchronization,synchronization primitives>> to
1346e5c31af7Sopenharmony_ciguarantee that other queues do not access ranges of memory concurrently with
1347e5c31af7Sopenharmony_cia binding change.
1348e5c31af7Sopenharmony_ciApplications can: access other ranges of the same resource while a bind
1349e5c31af7Sopenharmony_cioperation is executing.
1350e5c31af7Sopenharmony_ci
1351e5c31af7Sopenharmony_ci[NOTE]
1352e5c31af7Sopenharmony_ci.Note
1353e5c31af7Sopenharmony_ci====
1354e5c31af7Sopenharmony_ciImplementations must: provide a guarantee that simultaneously binding sparse
1355e5c31af7Sopenharmony_ciblocks while another queue accesses those same sparse blocks via a sparse
1356e5c31af7Sopenharmony_ciresource must: not access memory owned by another process or otherwise
1357e5c31af7Sopenharmony_cicorrupt the system.
1358e5c31af7Sopenharmony_ci====
1359e5c31af7Sopenharmony_ci
1360e5c31af7Sopenharmony_ciWhile some implementations may: include ename:VK_QUEUE_SPARSE_BINDING_BIT
1361e5c31af7Sopenharmony_cisupport in queue families that also include graphics and compute support,
1362e5c31af7Sopenharmony_ciother implementations may: only expose a
1363e5c31af7Sopenharmony_ciename:VK_QUEUE_SPARSE_BINDING_BIT-only queue family.
1364e5c31af7Sopenharmony_ciIn either case, applications must: use <<synchronization,synchronization
1365e5c31af7Sopenharmony_ciprimitives>> to explicitly request any ordering dependencies between sparse
1366e5c31af7Sopenharmony_cimemory binding operations and other graphics/compute/transfer operations, as
1367e5c31af7Sopenharmony_cisparse binding operations are not automatically ordered against command
1368e5c31af7Sopenharmony_cibuffer execution, even within a single queue.
1369e5c31af7Sopenharmony_ci
1370e5c31af7Sopenharmony_ciWhen binding memory explicitly for the ename:VK_IMAGE_ASPECT_METADATA_BIT
1371e5c31af7Sopenharmony_cithe application must: use the ename:VK_SPARSE_MEMORY_BIND_METADATA_BIT in
1372e5c31af7Sopenharmony_cithe sname:VkSparseMemoryBind::pname:flags field when binding memory.
1373e5c31af7Sopenharmony_ciBinding memory for metadata is done the same way as binding memory for the
1374e5c31af7Sopenharmony_cimip tail, with the addition of the ename:VK_SPARSE_MEMORY_BIND_METADATA_BIT
1375e5c31af7Sopenharmony_ciflag.
1376e5c31af7Sopenharmony_ci
1377e5c31af7Sopenharmony_ciBinding the mip tail for any aspect must: only be performed using
1378e5c31af7Sopenharmony_cislink:VkSparseImageOpaqueMemoryBindInfo.
1379e5c31af7Sopenharmony_ciIf pname:formatProperties.flags contains
1380e5c31af7Sopenharmony_ciename:VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT, then it can: be bound with
1381e5c31af7Sopenharmony_cia single slink:VkSparseMemoryBind structure, with pname:resourceOffset =
1382e5c31af7Sopenharmony_cipname:imageMipTailOffset and pname:size = pname:imageMipTailSize.
1383e5c31af7Sopenharmony_ci
1384e5c31af7Sopenharmony_ciIf pname:formatProperties.flags does not contain
1385e5c31af7Sopenharmony_ciename:VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT then the offset for the mip
1386e5c31af7Sopenharmony_citail in each array layer is given as:
1387e5c31af7Sopenharmony_ci
1388e5c31af7Sopenharmony_ci[source,c++]
1389e5c31af7Sopenharmony_ci----
1390e5c31af7Sopenharmony_ciarrayMipTailOffset = imageMipTailOffset + arrayLayer * imageMipTailStride;
1391e5c31af7Sopenharmony_ci----
1392e5c31af7Sopenharmony_ci
1393e5c31af7Sopenharmony_ciand the mip tail can: be bound with code:layerCount slink:VkSparseMemoryBind
1394e5c31af7Sopenharmony_cistructures, each using pname:size = pname:imageMipTailSize and
1395e5c31af7Sopenharmony_cipname:resourceOffset = ptext:arrayMipTailOffset as defined above.
1396e5c31af7Sopenharmony_ci
1397e5c31af7Sopenharmony_ciSparse memory binding is handled by the following APIs and related data
1398e5c31af7Sopenharmony_cistructures.
1399e5c31af7Sopenharmony_ci
1400e5c31af7Sopenharmony_ci
1401e5c31af7Sopenharmony_ci[[sparsemem-memory-binding]]
1402e5c31af7Sopenharmony_ci==== Sparse Memory Binding Functions
1403e5c31af7Sopenharmony_ci
1404e5c31af7Sopenharmony_ci[open,refpage='VkSparseMemoryBind',desc='Structure specifying a sparse memory bind operation',type='structs']
1405e5c31af7Sopenharmony_ci--
1406e5c31af7Sopenharmony_ciThe sname:VkSparseMemoryBind structure is defined as:
1407e5c31af7Sopenharmony_ci
1408e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkSparseMemoryBind.adoc[]
1409e5c31af7Sopenharmony_ci
1410e5c31af7Sopenharmony_ci  * pname:resourceOffset is the offset into the resource.
1411e5c31af7Sopenharmony_ci  * pname:size is the size of the memory region to be bound.
1412e5c31af7Sopenharmony_ci  * pname:memory is the slink:VkDeviceMemory object that the range of the
1413e5c31af7Sopenharmony_ci    resource is bound to.
1414e5c31af7Sopenharmony_ci    If pname:memory is dlink:VK_NULL_HANDLE, the range is unbound.
1415e5c31af7Sopenharmony_ci  * pname:memoryOffset is the offset into the slink:VkDeviceMemory object to
1416e5c31af7Sopenharmony_ci    bind the resource range to.
1417e5c31af7Sopenharmony_ci    If pname:memory is dlink:VK_NULL_HANDLE, this value is ignored.
1418e5c31af7Sopenharmony_ci  * pname:flags is a bitmask of elink:VkSparseMemoryBindFlagBits specifying
1419e5c31af7Sopenharmony_ci    usage of the binding operation.
1420e5c31af7Sopenharmony_ci
1421e5c31af7Sopenharmony_ciThe _binding range_ [eq]#[pname:resourceOffset, pname:resourceOffset {plus}
1422e5c31af7Sopenharmony_cipname:size)# has different constraints based on pname:flags.
1423e5c31af7Sopenharmony_ciIf pname:flags contains ename:VK_SPARSE_MEMORY_BIND_METADATA_BIT, the
1424e5c31af7Sopenharmony_cibinding range must: be within the mip tail region of the metadata aspect.
1425e5c31af7Sopenharmony_ciThis metadata region is defined by:
1426e5c31af7Sopenharmony_ci
1427e5c31af7Sopenharmony_ci  {empty}:: [eq]#metadataRegion = [base, base {plus}
1428e5c31af7Sopenharmony_ci            pname:imageMipTailSize)#
1429e5c31af7Sopenharmony_ci  {empty}:: [eq]#base = pname:imageMipTailOffset {plus}
1430e5c31af7Sopenharmony_ci            pname:imageMipTailStride {times} n#
1431e5c31af7Sopenharmony_ci
1432e5c31af7Sopenharmony_ciand pname:imageMipTailOffset, pname:imageMipTailSize, and
1433e5c31af7Sopenharmony_cipname:imageMipTailStride values are from the
1434e5c31af7Sopenharmony_cislink:VkSparseImageMemoryRequirements corresponding to the metadata aspect
1435e5c31af7Sopenharmony_ciof the image, and [eq]#n# is a valid array layer index for the image,
1436e5c31af7Sopenharmony_ci
1437e5c31af7Sopenharmony_cipname:imageMipTailStride is considered to be zero for aspects where
1438e5c31af7Sopenharmony_cisname:VkSparseImageMemoryRequirements::pname:formatProperties.flags contains
1439e5c31af7Sopenharmony_ciename:VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT.
1440e5c31af7Sopenharmony_ci
1441e5c31af7Sopenharmony_ciIf pname:flags does not contain ename:VK_SPARSE_MEMORY_BIND_METADATA_BIT,
1442e5c31af7Sopenharmony_cithe binding range must: be within the range
1443e5c31af7Sopenharmony_ci[eq]#[0,slink:VkMemoryRequirements::pname:size)#.
1444e5c31af7Sopenharmony_ci
1445e5c31af7Sopenharmony_ci.Valid Usage
1446e5c31af7Sopenharmony_ci****
1447e5c31af7Sopenharmony_ci  * [[VUID-VkSparseMemoryBind-memory-01096]]
1448e5c31af7Sopenharmony_ci    If pname:memory is not dlink:VK_NULL_HANDLE, pname:memory and
1449e5c31af7Sopenharmony_ci    pname:memoryOffset must: match the memory requirements of the resource,
1450e5c31af7Sopenharmony_ci    as described in section <<resources-association>>
1451e5c31af7Sopenharmony_ci  * [[VUID-VkSparseMemoryBind-resourceOffset-09491]]
1452e5c31af7Sopenharmony_ci    If the resource being bound is a sname:VkBuffer, pname:resourceOffset
1453e5c31af7Sopenharmony_ci    and pname:memoryOffset must: be an integer multiple of the
1454e5c31af7Sopenharmony_ci    pname:alignment of the slink:VkMemoryRequirements structure returned
1455e5c31af7Sopenharmony_ci    from a call to flink:vkGetBufferMemoryRequirements with the buffer
1456e5c31af7Sopenharmony_ci    resource
1457e5c31af7Sopenharmony_ci  * [[VUID-VkSparseMemoryBind-resourceOffset-09492]]
1458e5c31af7Sopenharmony_ci    If the resource being bound is a sname:VkImage, pname:resourceOffset and
1459e5c31af7Sopenharmony_ci    pname:memoryOffset must: be an integer multiple of the pname:alignment
1460e5c31af7Sopenharmony_ci    of the slink:VkMemoryRequirements structure returned from a call to
1461e5c31af7Sopenharmony_ci    flink:vkGetImageMemoryRequirements with the image resource
1462e5c31af7Sopenharmony_ci  * [[VUID-VkSparseMemoryBind-memory-01097]]
1463e5c31af7Sopenharmony_ci    If pname:memory is not dlink:VK_NULL_HANDLE, pname:memory must: not have
1464e5c31af7Sopenharmony_ci    been created with a memory type that reports
1465e5c31af7Sopenharmony_ci    ename:VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT bit set
1466e5c31af7Sopenharmony_ci  * [[VUID-VkSparseMemoryBind-size-01098]]
1467e5c31af7Sopenharmony_ci    pname:size must: be greater than `0`
1468e5c31af7Sopenharmony_ci  * [[VUID-VkSparseMemoryBind-resourceOffset-01099]]
1469e5c31af7Sopenharmony_ci    pname:resourceOffset must: be less than the size of the resource
1470e5c31af7Sopenharmony_ci  * [[VUID-VkSparseMemoryBind-size-01100]]
1471e5c31af7Sopenharmony_ci    pname:size must: be less than or equal to the size of the resource minus
1472e5c31af7Sopenharmony_ci    pname:resourceOffset
1473e5c31af7Sopenharmony_ci  * [[VUID-VkSparseMemoryBind-memoryOffset-01101]]
1474e5c31af7Sopenharmony_ci    pname:memoryOffset must: be less than the size of pname:memory
1475e5c31af7Sopenharmony_ci  * [[VUID-VkSparseMemoryBind-size-01102]]
1476e5c31af7Sopenharmony_ci    pname:size must: be less than or equal to the size of pname:memory minus
1477e5c31af7Sopenharmony_ci    pname:memoryOffset
1478e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_external_memory[]
1479e5c31af7Sopenharmony_ci  * [[VUID-VkSparseMemoryBind-memory-02730]]
1480e5c31af7Sopenharmony_ci    If pname:memory was created with
1481e5c31af7Sopenharmony_ci    slink:VkExportMemoryAllocateInfo::pname:handleTypes not equal to `0`, at
1482e5c31af7Sopenharmony_ci    least one handle type it contained must: also have been set in
1483e5c31af7Sopenharmony_ci    slink:VkExternalMemoryBufferCreateInfo::pname:handleTypes or
1484e5c31af7Sopenharmony_ci    slink:VkExternalMemoryImageCreateInfo::pname:handleTypes when the
1485e5c31af7Sopenharmony_ci    resource was created
1486e5c31af7Sopenharmony_ci  * [[VUID-VkSparseMemoryBind-memory-02731]]
1487e5c31af7Sopenharmony_ci    If pname:memory was created by a memory import operation, the external
1488e5c31af7Sopenharmony_ci    handle type of the imported memory must: also have been set in
1489e5c31af7Sopenharmony_ci    slink:VkExternalMemoryBufferCreateInfo::pname:handleTypes or
1490e5c31af7Sopenharmony_ci    slink:VkExternalMemoryImageCreateInfo::pname:handleTypes when the
1491e5c31af7Sopenharmony_ci    resource was created
1492e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_external_memory[]
1493e5c31af7Sopenharmony_ci****
1494e5c31af7Sopenharmony_ci
1495e5c31af7Sopenharmony_ciinclude::{generated}/validity/structs/VkSparseMemoryBind.adoc[]
1496e5c31af7Sopenharmony_ci--
1497e5c31af7Sopenharmony_ci
1498e5c31af7Sopenharmony_ci[open,refpage='VkSparseMemoryBindFlagBits',desc='Bitmask specifying usage of a sparse memory binding operation',type='enums']
1499e5c31af7Sopenharmony_ci--
1500e5c31af7Sopenharmony_ciBits which can: be set in slink:VkSparseMemoryBind::pname:flags, specifying
1501e5c31af7Sopenharmony_ciusage of a sparse memory binding operation, are:
1502e5c31af7Sopenharmony_ci
1503e5c31af7Sopenharmony_ciinclude::{generated}/api/enums/VkSparseMemoryBindFlagBits.adoc[]
1504e5c31af7Sopenharmony_ci
1505e5c31af7Sopenharmony_ci  * ename:VK_SPARSE_MEMORY_BIND_METADATA_BIT specifies that the memory being
1506e5c31af7Sopenharmony_ci    bound is only for the metadata aspect.
1507e5c31af7Sopenharmony_ci--
1508e5c31af7Sopenharmony_ci
1509e5c31af7Sopenharmony_ci[open,refpage='VkSparseMemoryBindFlags',desc='Bitmask of VkSparseMemoryBindFlagBits',type='flags']
1510e5c31af7Sopenharmony_ci--
1511e5c31af7Sopenharmony_ciinclude::{generated}/api/flags/VkSparseMemoryBindFlags.adoc[]
1512e5c31af7Sopenharmony_ci
1513e5c31af7Sopenharmony_citname:VkSparseMemoryBindFlags is a bitmask type for setting a mask of zero
1514e5c31af7Sopenharmony_cior more elink:VkSparseMemoryBindFlagBits.
1515e5c31af7Sopenharmony_ci--
1516e5c31af7Sopenharmony_ci
1517e5c31af7Sopenharmony_ci[open,refpage='VkSparseBufferMemoryBindInfo',desc='Structure specifying a sparse buffer memory bind operation',type='structs']
1518e5c31af7Sopenharmony_ci--
1519e5c31af7Sopenharmony_ciMemory is bound to sname:VkBuffer objects created with the
1520e5c31af7Sopenharmony_ciename:VK_BUFFER_CREATE_SPARSE_BINDING_BIT flag using the following
1521e5c31af7Sopenharmony_cistructure:
1522e5c31af7Sopenharmony_ci
1523e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkSparseBufferMemoryBindInfo.adoc[]
1524e5c31af7Sopenharmony_ci
1525e5c31af7Sopenharmony_ci  * pname:buffer is the slink:VkBuffer object to be bound.
1526e5c31af7Sopenharmony_ci  * pname:bindCount is the number of slink:VkSparseMemoryBind structures in
1527e5c31af7Sopenharmony_ci    the pname:pBinds array.
1528e5c31af7Sopenharmony_ci  * pname:pBinds is a pointer to an array of slink:VkSparseMemoryBind
1529e5c31af7Sopenharmony_ci    structures.
1530e5c31af7Sopenharmony_ci
1531e5c31af7Sopenharmony_ciinclude::{generated}/validity/structs/VkSparseBufferMemoryBindInfo.adoc[]
1532e5c31af7Sopenharmony_ci--
1533e5c31af7Sopenharmony_ci
1534e5c31af7Sopenharmony_ci[open,refpage='VkSparseImageOpaqueMemoryBindInfo',desc='Structure specifying sparse image opaque memory bind information',type='structs']
1535e5c31af7Sopenharmony_ci--
1536e5c31af7Sopenharmony_ciMemory is bound to opaque regions of sname:VkImage objects created with the
1537e5c31af7Sopenharmony_ciename:VK_IMAGE_CREATE_SPARSE_BINDING_BIT flag using the following structure:
1538e5c31af7Sopenharmony_ci
1539e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkSparseImageOpaqueMemoryBindInfo.adoc[]
1540e5c31af7Sopenharmony_ci
1541e5c31af7Sopenharmony_ci  * pname:image is the slink:VkImage object to be bound.
1542e5c31af7Sopenharmony_ci  * pname:bindCount is the number of slink:VkSparseMemoryBind structures in
1543e5c31af7Sopenharmony_ci    the pname:pBinds array.
1544e5c31af7Sopenharmony_ci  * pname:pBinds is a pointer to an array of slink:VkSparseMemoryBind
1545e5c31af7Sopenharmony_ci    structures.
1546e5c31af7Sopenharmony_ci
1547e5c31af7Sopenharmony_ci.Valid Usage
1548e5c31af7Sopenharmony_ci****
1549e5c31af7Sopenharmony_ci  * [[VUID-VkSparseImageOpaqueMemoryBindInfo-pBinds-01103]]
1550e5c31af7Sopenharmony_ci    If the pname:flags member of any element of pname:pBinds contains
1551e5c31af7Sopenharmony_ci    ename:VK_SPARSE_MEMORY_BIND_METADATA_BIT, the binding range defined
1552e5c31af7Sopenharmony_ci    must: be within the mip tail region of the metadata aspect of
1553e5c31af7Sopenharmony_ci    pname:image
1554e5c31af7Sopenharmony_ci****
1555e5c31af7Sopenharmony_ci
1556e5c31af7Sopenharmony_ciinclude::{generated}/validity/structs/VkSparseImageOpaqueMemoryBindInfo.adoc[]
1557e5c31af7Sopenharmony_ci--
1558e5c31af7Sopenharmony_ci
1559e5c31af7Sopenharmony_ci[NOTE]
1560e5c31af7Sopenharmony_ci.Note
1561e5c31af7Sopenharmony_ci====
1562e5c31af7Sopenharmony_ciThis operation is normally used to bind memory to fully-resident sparse
1563e5c31af7Sopenharmony_ciimages or for mip tail regions of partially resident images.
1564e5c31af7Sopenharmony_ciHowever, it can: also be used to bind memory for the entire binding range of
1565e5c31af7Sopenharmony_cipartially resident images.
1566e5c31af7Sopenharmony_ci
1567e5c31af7Sopenharmony_ciIn case pname:flags does not contain
1568e5c31af7Sopenharmony_ciename:VK_SPARSE_MEMORY_BIND_METADATA_BIT, the pname:resourceOffset is in the
1569e5c31af7Sopenharmony_cirange [eq]#[0, slink:VkMemoryRequirements::pname:size)#, This range includes
1570e5c31af7Sopenharmony_cidata from all aspects of the image, including metadata.
1571e5c31af7Sopenharmony_ciFor most implementations this will probably mean that the
1572e5c31af7Sopenharmony_cipname:resourceOffset is a simple device address offset within the resource.
1573e5c31af7Sopenharmony_ciIt is possible for an application to bind a range of memory that includes
1574e5c31af7Sopenharmony_ciboth resource data and metadata.
1575e5c31af7Sopenharmony_ciHowever, the application would not know what part of the image the memory is
1576e5c31af7Sopenharmony_ciused for, or if any range is being used for metadata.
1577e5c31af7Sopenharmony_ci
1578e5c31af7Sopenharmony_ciWhen pname:flags contains ename:VK_SPARSE_MEMORY_BIND_METADATA_BIT, the
1579e5c31af7Sopenharmony_cibinding range specified must: be within the mip tail region of the metadata
1580e5c31af7Sopenharmony_ciaspect.
1581e5c31af7Sopenharmony_ciIn this case the pname:resourceOffset is not required: to be a simple device
1582e5c31af7Sopenharmony_ciaddress offset within the resource.
1583e5c31af7Sopenharmony_ciHowever, it _is_ defined to be within [eq]#[pname:imageMipTailOffset,
1584e5c31af7Sopenharmony_cipname:imageMipTailOffset {plus} pname:imageMipTailSize)# for the metadata
1585e5c31af7Sopenharmony_ciaspect.
1586e5c31af7Sopenharmony_ciSee slink:VkSparseMemoryBind for the full constraints on binding region with
1587e5c31af7Sopenharmony_cithis flag present.
1588e5c31af7Sopenharmony_ci====
1589e5c31af7Sopenharmony_ci
1590e5c31af7Sopenharmony_ciifdef::editing-notes[]
1591e5c31af7Sopenharmony_ci[NOTE]
1592e5c31af7Sopenharmony_ci.editing-note
1593e5c31af7Sopenharmony_ci====
1594e5c31af7Sopenharmony_ci(Jon) The preceding NOTE refers to pname:flags, which is presumably a
1595e5c31af7Sopenharmony_cireference to slink:VkSparseMemoryBind above, even though that is not
1596e5c31af7Sopenharmony_cicontextually clear.
1597e5c31af7Sopenharmony_ci====
1598e5c31af7Sopenharmony_ciendif::editing-notes[]
1599e5c31af7Sopenharmony_ci
1600e5c31af7Sopenharmony_ci[open,refpage='VkSparseImageMemoryBindInfo',desc='Structure specifying sparse image memory bind information',type='structs']
1601e5c31af7Sopenharmony_ci--
1602e5c31af7Sopenharmony_ciMemory can: be bound to sparse image blocks of sname:VkImage objects created
1603e5c31af7Sopenharmony_ciwith the ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT flag using the following
1604e5c31af7Sopenharmony_cistructure:
1605e5c31af7Sopenharmony_ci
1606e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkSparseImageMemoryBindInfo.adoc[]
1607e5c31af7Sopenharmony_ci
1608e5c31af7Sopenharmony_ci  * pname:image is the slink:VkImage object to be bound
1609e5c31af7Sopenharmony_ci  * pname:bindCount is the number of slink:VkSparseImageMemoryBind
1610e5c31af7Sopenharmony_ci    structures in pname:pBinds array
1611e5c31af7Sopenharmony_ci  * pname:pBinds is a pointer to an array of slink:VkSparseImageMemoryBind
1612e5c31af7Sopenharmony_ci    structures
1613e5c31af7Sopenharmony_ci
1614e5c31af7Sopenharmony_ci.Valid Usage
1615e5c31af7Sopenharmony_ci****
1616e5c31af7Sopenharmony_ci  * [[VUID-VkSparseImageMemoryBindInfo-subresource-01722]]
1617e5c31af7Sopenharmony_ci    The pname:subresource.mipLevel member of each element of pname:pBinds
1618e5c31af7Sopenharmony_ci    must: be less than the pname:mipLevels specified in
1619e5c31af7Sopenharmony_ci    slink:VkImageCreateInfo when pname:image was created
1620e5c31af7Sopenharmony_ci  * [[VUID-VkSparseImageMemoryBindInfo-subresource-01723]]
1621e5c31af7Sopenharmony_ci    The pname:subresource.arrayLayer member of each element of pname:pBinds
1622e5c31af7Sopenharmony_ci    must: be less than the pname:arrayLayers specified in
1623e5c31af7Sopenharmony_ci    slink:VkImageCreateInfo when pname:image was created
1624e5c31af7Sopenharmony_ci  * [[VUID-VkSparseImageMemoryBindInfo-image-02901]]
1625e5c31af7Sopenharmony_ci    pname:image must: have been created with
1626e5c31af7Sopenharmony_ci    ename:VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT set
1627e5c31af7Sopenharmony_ci****
1628e5c31af7Sopenharmony_ci
1629e5c31af7Sopenharmony_ciinclude::{generated}/validity/structs/VkSparseImageMemoryBindInfo.adoc[]
1630e5c31af7Sopenharmony_ci--
1631e5c31af7Sopenharmony_ci
1632e5c31af7Sopenharmony_ci[open,refpage='VkSparseImageMemoryBind',desc='Structure specifying sparse image memory bind',type='structs']
1633e5c31af7Sopenharmony_ci--
1634e5c31af7Sopenharmony_ciThe sname:VkSparseImageMemoryBind structure is defined as:
1635e5c31af7Sopenharmony_ci
1636e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkSparseImageMemoryBind.adoc[]
1637e5c31af7Sopenharmony_ci
1638e5c31af7Sopenharmony_ci  * pname:subresource is the image _aspect_ and region of interest in the
1639e5c31af7Sopenharmony_ci    image.
1640e5c31af7Sopenharmony_ci  * pname:offset are the coordinates of the first texel within the image
1641e5c31af7Sopenharmony_ci    subresource to bind.
1642e5c31af7Sopenharmony_ci  * pname:extent is the size in texels of the region within the image
1643e5c31af7Sopenharmony_ci    subresource to bind.
1644e5c31af7Sopenharmony_ci    The extent must: be a multiple of the sparse image block dimensions,
1645e5c31af7Sopenharmony_ci    except when binding sparse image blocks along the edge of an image
1646e5c31af7Sopenharmony_ci    subresource it can: instead be such that any coordinate of
1647e5c31af7Sopenharmony_ci    [eq]#pname:offset {plus} pname:extent# equals the corresponding
1648e5c31af7Sopenharmony_ci    dimensions of the image subresource.
1649e5c31af7Sopenharmony_ci  * pname:memory is the slink:VkDeviceMemory object that the sparse image
1650e5c31af7Sopenharmony_ci    blocks of the image are bound to.
1651e5c31af7Sopenharmony_ci    If pname:memory is dlink:VK_NULL_HANDLE, the sparse image blocks are
1652e5c31af7Sopenharmony_ci    unbound.
1653e5c31af7Sopenharmony_ci  * pname:memoryOffset is an offset into slink:VkDeviceMemory object.
1654e5c31af7Sopenharmony_ci    If pname:memory is dlink:VK_NULL_HANDLE, this value is ignored.
1655e5c31af7Sopenharmony_ci  * pname:flags are sparse memory binding flags.
1656e5c31af7Sopenharmony_ci
1657e5c31af7Sopenharmony_ci.Valid Usage
1658e5c31af7Sopenharmony_ci****
1659e5c31af7Sopenharmony_ci  * [[VUID-VkSparseImageMemoryBind-memory-01104]]
1660e5c31af7Sopenharmony_ci    If the <<features-sparseResidencyAliased, pname:sparseResidencyAliased>>
1661e5c31af7Sopenharmony_ci    feature is not enabled, and if any other resources are bound to ranges
1662e5c31af7Sopenharmony_ci    of pname:memory, the range of pname:memory being bound must: not overlap
1663e5c31af7Sopenharmony_ci    with those bound ranges
1664e5c31af7Sopenharmony_ci  * [[VUID-VkSparseImageMemoryBind-memory-01105]]
1665e5c31af7Sopenharmony_ci    pname:memory and pname:memoryOffset must: match the memory requirements
1666e5c31af7Sopenharmony_ci    of the calling command's pname:image, as described in section
1667e5c31af7Sopenharmony_ci    <<resources-association>>
1668e5c31af7Sopenharmony_ci  * [[VUID-VkSparseImageMemoryBind-subresource-01106]]
1669e5c31af7Sopenharmony_ci    pname:subresource must: be a valid image subresource for pname:image
1670e5c31af7Sopenharmony_ci    (see <<resources-image-views>>)
1671e5c31af7Sopenharmony_ci  * [[VUID-VkSparseImageMemoryBind-offset-01107]]
1672e5c31af7Sopenharmony_ci    pname:offset.x must: be a multiple of the sparse image block width
1673e5c31af7Sopenharmony_ci    (sname:VkSparseImageFormatProperties::pname:imageGranularity.width) of
1674e5c31af7Sopenharmony_ci    the image
1675e5c31af7Sopenharmony_ci  * [[VUID-VkSparseImageMemoryBind-extent-09388]]
1676e5c31af7Sopenharmony_ci    pname:extent.width must: be greater than `0`
1677e5c31af7Sopenharmony_ci  * [[VUID-VkSparseImageMemoryBind-extent-01108]]
1678e5c31af7Sopenharmony_ci    pname:extent.width must: either be a multiple of the sparse image block
1679e5c31af7Sopenharmony_ci    width of the image, or else [eq]#(pname:extent.width {plus}
1680e5c31af7Sopenharmony_ci    pname:offset.x)# must: equal the width of the image subresource
1681e5c31af7Sopenharmony_ci  * [[VUID-VkSparseImageMemoryBind-offset-01109]]
1682e5c31af7Sopenharmony_ci    pname:offset.y must: be a multiple of the sparse image block height
1683e5c31af7Sopenharmony_ci    (sname:VkSparseImageFormatProperties::pname:imageGranularity.height) of
1684e5c31af7Sopenharmony_ci    the image
1685e5c31af7Sopenharmony_ci  * [[VUID-VkSparseImageMemoryBind-extent-09389]]
1686e5c31af7Sopenharmony_ci    pname:extent.height must: be greater than `0`
1687e5c31af7Sopenharmony_ci  * [[VUID-VkSparseImageMemoryBind-extent-01110]]
1688e5c31af7Sopenharmony_ci    pname:extent.height must: either be a multiple of the sparse image block
1689e5c31af7Sopenharmony_ci    height of the image, or else [eq]#(pname:extent.height {plus}
1690e5c31af7Sopenharmony_ci    pname:offset.y)# must: equal the height of the image subresource
1691e5c31af7Sopenharmony_ci  * [[VUID-VkSparseImageMemoryBind-offset-01111]]
1692e5c31af7Sopenharmony_ci    pname:offset.z must: be a multiple of the sparse image block depth
1693e5c31af7Sopenharmony_ci    (sname:VkSparseImageFormatProperties::pname:imageGranularity.depth) of
1694e5c31af7Sopenharmony_ci    the image
1695e5c31af7Sopenharmony_ci  * [[VUID-VkSparseImageMemoryBind-extent-09390]]
1696e5c31af7Sopenharmony_ci    pname:extent.depth must: be greater than `0`
1697e5c31af7Sopenharmony_ci  * [[VUID-VkSparseImageMemoryBind-extent-01112]]
1698e5c31af7Sopenharmony_ci    pname:extent.depth must: either be a multiple of the sparse image block
1699e5c31af7Sopenharmony_ci    depth of the image, or else [eq]#(pname:extent.depth {plus}
1700e5c31af7Sopenharmony_ci    pname:offset.z)# must: equal the depth of the image subresource
1701e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_external_memory[]
1702e5c31af7Sopenharmony_ci  * [[VUID-VkSparseImageMemoryBind-memory-02732]]
1703e5c31af7Sopenharmony_ci    If pname:memory was created with
1704e5c31af7Sopenharmony_ci    slink:VkExportMemoryAllocateInfo::pname:handleTypes not equal to `0`, at
1705e5c31af7Sopenharmony_ci    least one handle type it contained must: also have been set in
1706e5c31af7Sopenharmony_ci    slink:VkExternalMemoryImageCreateInfo::pname:handleTypes when the image
1707e5c31af7Sopenharmony_ci    was created
1708e5c31af7Sopenharmony_ci  * [[VUID-VkSparseImageMemoryBind-memory-02733]]
1709e5c31af7Sopenharmony_ci    If pname:memory was created by a memory import operation, the external
1710e5c31af7Sopenharmony_ci    handle type of the imported memory must: also have been set in
1711e5c31af7Sopenharmony_ci    slink:VkExternalMemoryImageCreateInfo::pname:handleTypes when
1712e5c31af7Sopenharmony_ci    pname:image was created
1713e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_external_memory[]
1714e5c31af7Sopenharmony_ci****
1715e5c31af7Sopenharmony_ci
1716e5c31af7Sopenharmony_ciinclude::{generated}/validity/structs/VkSparseImageMemoryBind.adoc[]
1717e5c31af7Sopenharmony_ci--
1718e5c31af7Sopenharmony_ci
1719e5c31af7Sopenharmony_ci[open,refpage='vkQueueBindSparse',desc='Bind device memory to a sparse resource object',type='protos']
1720e5c31af7Sopenharmony_ci--
1721e5c31af7Sopenharmony_ciTo submit sparse binding operations to a queue, call:
1722e5c31af7Sopenharmony_ci
1723e5c31af7Sopenharmony_ciinclude::{generated}/api/protos/vkQueueBindSparse.adoc[]
1724e5c31af7Sopenharmony_ci
1725e5c31af7Sopenharmony_ci  * pname:queue is the queue that the sparse binding operations will be
1726e5c31af7Sopenharmony_ci    submitted to.
1727e5c31af7Sopenharmony_ci  * pname:bindInfoCount is the number of elements in the pname:pBindInfo
1728e5c31af7Sopenharmony_ci    array.
1729e5c31af7Sopenharmony_ci  * pname:pBindInfo is a pointer to an array of slink:VkBindSparseInfo
1730e5c31af7Sopenharmony_ci    structures, each specifying a sparse binding submission batch.
1731e5c31af7Sopenharmony_ci  * pname:fence is an optional: handle to a fence to be signaled.
1732e5c31af7Sopenharmony_ci    If pname:fence is not dlink:VK_NULL_HANDLE, it defines a
1733e5c31af7Sopenharmony_ci    <<synchronization-fences-signaling, fence signal operation>>.
1734e5c31af7Sopenharmony_ci
1735e5c31af7Sopenharmony_cifname:vkQueueBindSparse is a <<devsandqueues-submission,queue submission
1736e5c31af7Sopenharmony_cicommand>>, with each batch defined by an element of pname:pBindInfo as a
1737e5c31af7Sopenharmony_cislink:VkBindSparseInfo structure.
1738e5c31af7Sopenharmony_ciBatches begin execution in the order they appear in pname:pBindInfo, but
1739e5c31af7Sopenharmony_cimay: complete out of order.
1740e5c31af7Sopenharmony_ci
1741e5c31af7Sopenharmony_ciWithin a batch, a given range of a resource must: not be bound more than
1742e5c31af7Sopenharmony_cionce.
1743e5c31af7Sopenharmony_ciAcross batches, if a range is to be bound to one allocation and offset and
1744e5c31af7Sopenharmony_cithen to another allocation and offset, then the application must: guarantee
1745e5c31af7Sopenharmony_ci(usually using semaphores) that the binding operations are executed in the
1746e5c31af7Sopenharmony_cicorrect order, as well as to order binding operations against the execution
1747e5c31af7Sopenharmony_ciof command buffer submissions.
1748e5c31af7Sopenharmony_ci
1749e5c31af7Sopenharmony_ciAs no operation to flink:vkQueueBindSparse causes any pipeline stage to
1750e5c31af7Sopenharmony_ciaccess memory, synchronization primitives used in this command effectively
1751e5c31af7Sopenharmony_cionly define execution dependencies.
1752e5c31af7Sopenharmony_ci
1753e5c31af7Sopenharmony_ciAdditional information about fence and semaphore operation is described in
1754e5c31af7Sopenharmony_ci<<synchronization, the synchronization chapter>>.
1755e5c31af7Sopenharmony_ci
1756e5c31af7Sopenharmony_ci.Valid Usage
1757e5c31af7Sopenharmony_ci****
1758e5c31af7Sopenharmony_ci  * [[VUID-vkQueueBindSparse-fence-01113]]
1759e5c31af7Sopenharmony_ci    If pname:fence is not dlink:VK_NULL_HANDLE, pname:fence must: be
1760e5c31af7Sopenharmony_ci    unsignaled
1761e5c31af7Sopenharmony_ci  * [[VUID-vkQueueBindSparse-fence-01114]]
1762e5c31af7Sopenharmony_ci    If pname:fence is not dlink:VK_NULL_HANDLE, pname:fence must: not be
1763e5c31af7Sopenharmony_ci    associated with any other queue command that has not yet completed
1764e5c31af7Sopenharmony_ci    execution on that queue
1765e5c31af7Sopenharmony_ci  * [[VUID-vkQueueBindSparse-pSignalSemaphores-01115]]
1766e5c31af7Sopenharmony_ci    Each element of the pname:pSignalSemaphores member of each element of
1767e5c31af7Sopenharmony_ci    pname:pBindInfo must: be unsignaled when the semaphore signal operation
1768e5c31af7Sopenharmony_ci    it defines is executed on the device
1769e5c31af7Sopenharmony_ci  * [[VUID-vkQueueBindSparse-pWaitSemaphores-01116]]
1770e5c31af7Sopenharmony_ci    When a semaphore wait operation referring to a binary semaphore defined
1771e5c31af7Sopenharmony_ci    by any element of the pname:pWaitSemaphores member of any element of
1772e5c31af7Sopenharmony_ci    pname:pBindInfo executes on pname:queue, there must: be no other queues
1773e5c31af7Sopenharmony_ci    waiting on the same semaphore
1774e5c31af7Sopenharmony_ci  * [[VUID-vkQueueBindSparse-pWaitSemaphores-03245]]
1775e5c31af7Sopenharmony_ci    All elements of the pname:pWaitSemaphores member of all elements of
1776e5c31af7Sopenharmony_ci    pname:pBindInfo referring to a semaphore
1777e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
1778e5c31af7Sopenharmony_ci    created with a elink:VkSemaphoreType of ename:VK_SEMAPHORE_TYPE_BINARY
1779e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
1780e5c31af7Sopenharmony_ci    must: reference a semaphore signal operation that has been submitted for
1781e5c31af7Sopenharmony_ci    execution and any <<synchronization-semaphores-signaling, semaphore
1782e5c31af7Sopenharmony_ci    signal operations>> on which it depends must: have also been submitted
1783e5c31af7Sopenharmony_ci    for execution
1784e5c31af7Sopenharmony_ci****
1785e5c31af7Sopenharmony_ci
1786e5c31af7Sopenharmony_ciinclude::{generated}/validity/protos/vkQueueBindSparse.adoc[]
1787e5c31af7Sopenharmony_ci--
1788e5c31af7Sopenharmony_ci
1789e5c31af7Sopenharmony_ci[open,refpage='VkBindSparseInfo',desc='Structure specifying a sparse binding operation',type='structs']
1790e5c31af7Sopenharmony_ci--
1791e5c31af7Sopenharmony_ciThe sname:VkBindSparseInfo structure is defined as:
1792e5c31af7Sopenharmony_ci
1793e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkBindSparseInfo.adoc[]
1794e5c31af7Sopenharmony_ci
1795e5c31af7Sopenharmony_ci  * pname:sType is a elink:VkStructureType value identifying this structure.
1796e5c31af7Sopenharmony_ci  * pname:pNext is `NULL` or a pointer to a structure extending this
1797e5c31af7Sopenharmony_ci    structure.
1798e5c31af7Sopenharmony_ci  * pname:waitSemaphoreCount is the number of semaphores upon which to wait
1799e5c31af7Sopenharmony_ci    before executing the sparse binding operations for the batch.
1800e5c31af7Sopenharmony_ci  * pname:pWaitSemaphores is a pointer to an array of semaphores upon which
1801e5c31af7Sopenharmony_ci    to wait on before the sparse binding operations for this batch begin
1802e5c31af7Sopenharmony_ci    execution.
1803e5c31af7Sopenharmony_ci    If semaphores to wait on are provided, they define a
1804e5c31af7Sopenharmony_ci    <<synchronization-semaphores-waiting, semaphore wait operation>>.
1805e5c31af7Sopenharmony_ci  * pname:bufferBindCount is the number of sparse buffer bindings to perform
1806e5c31af7Sopenharmony_ci    in the batch.
1807e5c31af7Sopenharmony_ci  * pname:pBufferBinds is a pointer to an array of
1808e5c31af7Sopenharmony_ci    slink:VkSparseBufferMemoryBindInfo structures.
1809e5c31af7Sopenharmony_ci  * pname:imageOpaqueBindCount is the number of opaque sparse image bindings
1810e5c31af7Sopenharmony_ci    to perform.
1811e5c31af7Sopenharmony_ci  * pname:pImageOpaqueBinds is a pointer to an array of
1812e5c31af7Sopenharmony_ci    slink:VkSparseImageOpaqueMemoryBindInfo structures, indicating opaque
1813e5c31af7Sopenharmony_ci    sparse image bindings to perform.
1814e5c31af7Sopenharmony_ci  * pname:imageBindCount is the number of sparse image bindings to perform.
1815e5c31af7Sopenharmony_ci  * pname:pImageBinds is a pointer to an array of
1816e5c31af7Sopenharmony_ci    slink:VkSparseImageMemoryBindInfo structures, indicating sparse image
1817e5c31af7Sopenharmony_ci    bindings to perform.
1818e5c31af7Sopenharmony_ci  * pname:signalSemaphoreCount is the number of semaphores to be signaled
1819e5c31af7Sopenharmony_ci    once the sparse binding operations specified by the structure have
1820e5c31af7Sopenharmony_ci    completed execution.
1821e5c31af7Sopenharmony_ci  * pname:pSignalSemaphores is a pointer to an array of semaphores which
1822e5c31af7Sopenharmony_ci    will be signaled when the sparse binding operations for this batch have
1823e5c31af7Sopenharmony_ci    completed execution.
1824e5c31af7Sopenharmony_ci    If semaphores to be signaled are provided, they define a
1825e5c31af7Sopenharmony_ci    <<synchronization-semaphores-signaling, semaphore signal operation>>.
1826e5c31af7Sopenharmony_ci
1827e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
1828e5c31af7Sopenharmony_ci.Valid Usage
1829e5c31af7Sopenharmony_ci****
1830e5c31af7Sopenharmony_ci  * [[VUID-VkBindSparseInfo-pWaitSemaphores-03246]]
1831e5c31af7Sopenharmony_ci    If any element of pname:pWaitSemaphores or pname:pSignalSemaphores was
1832e5c31af7Sopenharmony_ci    created with a elink:VkSemaphoreType of ename:VK_SEMAPHORE_TYPE_TIMELINE
1833e5c31af7Sopenharmony_ci    then the pname:pNext chain must: include a
1834e5c31af7Sopenharmony_ci    slink:VkTimelineSemaphoreSubmitInfo structure
1835e5c31af7Sopenharmony_ci  * [[VUID-VkBindSparseInfo-pNext-03247]]
1836e5c31af7Sopenharmony_ci    If the pname:pNext chain of this structure includes a
1837e5c31af7Sopenharmony_ci    slink:VkTimelineSemaphoreSubmitInfo structure and any element of
1838e5c31af7Sopenharmony_ci    pname:pWaitSemaphores was created with a elink:VkSemaphoreType of
1839e5c31af7Sopenharmony_ci    ename:VK_SEMAPHORE_TYPE_TIMELINE then its pname:waitSemaphoreValueCount
1840e5c31af7Sopenharmony_ci    member must: equal pname:waitSemaphoreCount
1841e5c31af7Sopenharmony_ci  * [[VUID-VkBindSparseInfo-pNext-03248]]
1842e5c31af7Sopenharmony_ci    If the pname:pNext chain of this structure includes a
1843e5c31af7Sopenharmony_ci    slink:VkTimelineSemaphoreSubmitInfo structure and any element of
1844e5c31af7Sopenharmony_ci    pname:pSignalSemaphores was created with a elink:VkSemaphoreType of
1845e5c31af7Sopenharmony_ci    ename:VK_SEMAPHORE_TYPE_TIMELINE then its
1846e5c31af7Sopenharmony_ci    pname:signalSemaphoreValueCount member must: equal
1847e5c31af7Sopenharmony_ci    pname:signalSemaphoreCount
1848e5c31af7Sopenharmony_ci  * [[VUID-VkBindSparseInfo-pSignalSemaphores-03249]]
1849e5c31af7Sopenharmony_ci    For each element of pname:pSignalSemaphores created with a
1850e5c31af7Sopenharmony_ci    elink:VkSemaphoreType of ename:VK_SEMAPHORE_TYPE_TIMELINE the
1851e5c31af7Sopenharmony_ci    corresponding element of
1852e5c31af7Sopenharmony_ci    slink:VkTimelineSemaphoreSubmitInfo::pname:pSignalSemaphoreValues must:
1853e5c31af7Sopenharmony_ci    have a value greater than the current value of the semaphore when the
1854e5c31af7Sopenharmony_ci    <<synchronization-semaphores-signaling,semaphore signal operation>> is
1855e5c31af7Sopenharmony_ci    executed
1856e5c31af7Sopenharmony_ci  * [[VUID-VkBindSparseInfo-pWaitSemaphores-03250]]
1857e5c31af7Sopenharmony_ci    For each element of pname:pWaitSemaphores created with a
1858e5c31af7Sopenharmony_ci    elink:VkSemaphoreType of ename:VK_SEMAPHORE_TYPE_TIMELINE the
1859e5c31af7Sopenharmony_ci    corresponding element of
1860e5c31af7Sopenharmony_ci    slink:VkTimelineSemaphoreSubmitInfo::pname:pWaitSemaphoreValues must:
1861e5c31af7Sopenharmony_ci    have a value which does not differ from the current value of the
1862e5c31af7Sopenharmony_ci    semaphore or from the value of any outstanding semaphore wait or signal
1863e5c31af7Sopenharmony_ci    operation on that semaphore by more than
1864e5c31af7Sopenharmony_ci    <<limits-maxTimelineSemaphoreValueDifference,
1865e5c31af7Sopenharmony_ci    pname:maxTimelineSemaphoreValueDifference>>
1866e5c31af7Sopenharmony_ci  * [[VUID-VkBindSparseInfo-pSignalSemaphores-03251]]
1867e5c31af7Sopenharmony_ci    For each element of pname:pSignalSemaphores created with a
1868e5c31af7Sopenharmony_ci    elink:VkSemaphoreType of ename:VK_SEMAPHORE_TYPE_TIMELINE the
1869e5c31af7Sopenharmony_ci    corresponding element of
1870e5c31af7Sopenharmony_ci    slink:VkTimelineSemaphoreSubmitInfo::pname:pSignalSemaphoreValues must:
1871e5c31af7Sopenharmony_ci    have a value which does not differ from the current value of the
1872e5c31af7Sopenharmony_ci    semaphore or from the value of any outstanding semaphore wait or signal
1873e5c31af7Sopenharmony_ci    operation on that semaphore by more than
1874e5c31af7Sopenharmony_ci    <<limits-maxTimelineSemaphoreValueDifference,
1875e5c31af7Sopenharmony_ci    pname:maxTimelineSemaphoreValueDifference>>
1876e5c31af7Sopenharmony_ci****
1877e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
1878e5c31af7Sopenharmony_ci
1879e5c31af7Sopenharmony_ciinclude::{generated}/validity/structs/VkBindSparseInfo.adoc[]
1880e5c31af7Sopenharmony_ci--
1881e5c31af7Sopenharmony_ci
1882e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
1883e5c31af7Sopenharmony_ciTo specify the values to use when waiting for and signaling semaphores
1884e5c31af7Sopenharmony_cicreated with a elink:VkSemaphoreType of ename:VK_SEMAPHORE_TYPE_TIMELINE,
1885e5c31af7Sopenharmony_ciadd a slink:VkTimelineSemaphoreSubmitInfo structure to the pname:pNext chain
1886e5c31af7Sopenharmony_ciof the slink:VkBindSparseInfo structure.
1887e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[]
1888e5c31af7Sopenharmony_ci
1889e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_device_group[]
1890e5c31af7Sopenharmony_ci[open,refpage='VkDeviceGroupBindSparseInfo',desc='Structure indicating which instances are bound',type='structs']
1891e5c31af7Sopenharmony_ci--
1892e5c31af7Sopenharmony_ciIf the pname:pNext chain of slink:VkBindSparseInfo includes a
1893e5c31af7Sopenharmony_cisname:VkDeviceGroupBindSparseInfo structure, then that structure includes
1894e5c31af7Sopenharmony_cidevice indices specifying which instance of the resources and memory are
1895e5c31af7Sopenharmony_cibound.
1896e5c31af7Sopenharmony_ci
1897e5c31af7Sopenharmony_ciThe sname:VkDeviceGroupBindSparseInfo structure is defined as:
1898e5c31af7Sopenharmony_ci
1899e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkDeviceGroupBindSparseInfo.adoc[]
1900e5c31af7Sopenharmony_ci
1901e5c31af7Sopenharmony_ciifdef::VK_KHR_device_group[]
1902e5c31af7Sopenharmony_cior the equivalent
1903e5c31af7Sopenharmony_ci
1904e5c31af7Sopenharmony_ciinclude::{generated}/api/structs/VkDeviceGroupBindSparseInfoKHR.adoc[]
1905e5c31af7Sopenharmony_ciendif::VK_KHR_device_group[]
1906e5c31af7Sopenharmony_ci
1907e5c31af7Sopenharmony_ci  * pname:sType is a elink:VkStructureType value identifying this structure.
1908e5c31af7Sopenharmony_ci  * pname:pNext is `NULL` or a pointer to a structure extending this
1909e5c31af7Sopenharmony_ci    structure.
1910e5c31af7Sopenharmony_ci  * pname:resourceDeviceIndex is a device index indicating which instance of
1911e5c31af7Sopenharmony_ci    the resource is bound.
1912e5c31af7Sopenharmony_ci  * pname:memoryDeviceIndex is a device index indicating which instance of
1913e5c31af7Sopenharmony_ci    the memory the resource instance is bound to.
1914e5c31af7Sopenharmony_ci
1915e5c31af7Sopenharmony_ciThese device indices apply to all buffer and image memory binds included in
1916e5c31af7Sopenharmony_cithe batch pointing to this structure.
1917e5c31af7Sopenharmony_ciThe semaphore waits and signals for the batch are executed only by the
1918e5c31af7Sopenharmony_ciphysical device specified by the pname:resourceDeviceIndex.
1919e5c31af7Sopenharmony_ci
1920e5c31af7Sopenharmony_ciIf this structure is not present, pname:resourceDeviceIndex and
1921e5c31af7Sopenharmony_cipname:memoryDeviceIndex are assumed to be zero.
1922e5c31af7Sopenharmony_ci
1923e5c31af7Sopenharmony_ci.Valid Usage
1924e5c31af7Sopenharmony_ci****
1925e5c31af7Sopenharmony_ci  * [[VUID-VkDeviceGroupBindSparseInfo-resourceDeviceIndex-01118]]
1926e5c31af7Sopenharmony_ci    pname:resourceDeviceIndex and pname:memoryDeviceIndex must: both be
1927e5c31af7Sopenharmony_ci    valid device indices
1928e5c31af7Sopenharmony_ci  * [[VUID-VkDeviceGroupBindSparseInfo-memoryDeviceIndex-01119]]
1929e5c31af7Sopenharmony_ci    Each memory allocation bound in this batch must: have allocated an
1930e5c31af7Sopenharmony_ci    instance for pname:memoryDeviceIndex
1931e5c31af7Sopenharmony_ci****
1932e5c31af7Sopenharmony_ci
1933e5c31af7Sopenharmony_ciinclude::{generated}/validity/structs/VkDeviceGroupBindSparseInfo.adoc[]
1934e5c31af7Sopenharmony_ci--
1935e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_device_group[]
1936e5c31af7Sopenharmony_ciendif::VKSC_VERSION_1_0[]
1937