• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2014-2018 Khronos Group. This work is licensed under a
2// Creative Commons Attribution 4.0 International License; see
3// http://creativecommons.org/licenses/by/4.0/
4
5== WSI Swapchain
6
7[open,refpage='VkSwapchainKHR',desc='Opaque handle to a swapchain object',type='handles']
8--
9
10A swapchain object (a.k.a.
11swapchain) provides the ability to present rendering results to a surface.
12Swapchain objects are represented by sname:VkSwapchainKHR handles:
13
14include::../../api/handles/VkSwapchainKHR.txt[]
15
16A swapchain is an abstraction for an array of presentable images that are
17associated with a surface.
18The presentable images are represented by sname:VkImage objects created by
19the platform.
20One image (which can: be an array image for multiview/stereoscopic-3D
21surfaces) is displayed at a time, but multiple images can: be queued for
22presentation.
23An application renders to the image, and then queues the image for
24presentation to the surface.
25
26A native window cannot: be associated with more than one non-retired
27swapchain at a time.
28Further, swapchains cannot: be created for native windows that have a
29non-Vulkan graphics API surface associated with them.
30
31[NOTE]
32.Note
33====
34The presentation engine is an abstraction for the platform's compositor or
35display engine.
36
37The presentation engine may: be synchronous or asynchronous with respect to
38the application and/or logical device.
39
40Some implementations may: use the device's graphics queue or dedicated
41presentation hardware to perform presentation.
42====
43
44The presentable images of a swapchain are owned by the presentation engine.
45An application can: acquire use of a presentable image from the presentation
46engine.
47Use of a presentable image must: occur only after the image is returned by
48fname:vkAcquireNextImageKHR, and before it is presented by
49fname:vkQueuePresentKHR.
50This includes transitioning the image layout and rendering commands.
51
52An application can: acquire use of a presentable image with
53fname:vkAcquireNextImageKHR.
54After acquiring a presentable image and before modifying it, the application
55must: use a synchronization primitive to ensure that the presentation engine
56has finished reading from the image.
57The application can: then transition the image's layout, queue rendering
58commands to it, etc.
59Finally, the application presents the image with fname:vkQueuePresentKHR,
60which releases the acquisition of the image.
61
62The presentation engine controls the order in which presentable images are
63acquired for use by the application.
64
65[NOTE]
66.Note
67====
68This allows the platform to handle situations which require out-of-order
69return of images after presentation.
70At the same time, it allows the application to generate command buffers
71referencing all of the images in the swapchain at initialization time,
72rather than in its main loop.
73====
74
75--
76
77How this all works is described below.
78
79ifdef::VK_KHR_shared_presentable_image[]
80include::../VK_KHR_shared_presentable_image/wsi.txt[]
81endif::VK_KHR_shared_presentable_image[]
82
83[open,refpage='vkCreateSwapchainKHR',desc='Create a swapchain',type='protos']
84--
85
86To create a swapchain, call:
87
88include::../../api/protos/vkCreateSwapchainKHR.txt[]
89
90  * pname:device is the device to create the swapchain for.
91  * pname:pCreateInfo is a pointer to an instance of the
92    slink:VkSwapchainCreateInfoKHR structure specifying the parameters of
93    the created swapchain.
94  * pname:pAllocator is the allocator used for host memory allocated for the
95    swapchain object when there is no more specific allocator available (see
96    <<memory-allocation,Memory Allocation>>).
97  * pname:pSwapchain is a pointer to a slink:VkSwapchainKHR handle in which
98    the created swapchain object will be returned.
99
100include::../../validity/protos/vkCreateSwapchainKHR.txt[]
101--
102
103[open,refpage='VkSwapchainCreateInfoKHR',desc='Structure specifying parameters of a newly created swapchain object',type='structs']
104--
105
106The sname:VkSwapchainCreateInfoKHR structure is defined as:
107
108include::../../api/structs/VkSwapchainCreateInfoKHR.txt[]
109
110  * pname:sType is the type of this structure.
111  * pname:pNext is `NULL` or a pointer to an extension-specific structure.
112  * pname:flags is a bitmask of elink:VkSwapchainCreateFlagBitsKHR
113    indicating parameters of the swapchain creation.
114  * pname:surface is the surface onto which the swapchain will present
115    images.
116    If the creation succeeds, the swapchain becomes associated with
117    pname:surface.
118  * pname:minImageCount is the minimum number of presentable images that the
119    application needs.
120    The implementation will either create the swapchain with at least that
121    many images, or it will fail to create the swapchain.
122  * pname:imageFormat is a elink:VkFormat value specifying the format the
123    swapchain image(s) will be created with.
124  * pname:imageColorSpace is a slink:VkColorSpaceKHR value specifying the
125    way the swapchain interprets image data.
126  * pname:imageExtent is the size (in pixels) of the swapchain image(s).
127    The behavior is platform-dependent if the image extent does not match
128    the surface's pname:currentExtent as returned by
129    fname:vkGetPhysicalDeviceSurfaceCapabilitiesKHR.
130
131[NOTE]
132.Note
133====
134On some platforms, it is normal that pname:maxImageExtent may: become `(0,
1350)`, for example when the window is minimized.
136In such a case, it is not possible to create a swapchain due to the Valid
137Usage requirements.
138====
139
140  * pname:imageArrayLayers is the number of views in a multiview/stereo
141    surface.
142    For non-stereoscopic-3D applications, this value is 1.
143  * pname:imageUsage is a bitmask of elink:VkImageUsageFlagBits describing
144    the intended usage of the (acquired) swapchain images.
145  * pname:imageSharingMode is the sharing mode used for the image(s) of the
146    swapchain.
147  * pname:queueFamilyIndexCount is the number of queue families having
148    access to the image(s) of the swapchain when pname:imageSharingMode is
149    ename:VK_SHARING_MODE_CONCURRENT.
150  * pname:pQueueFamilyIndices is an array of queue family indices having
151    access to the images(s) of the swapchain when pname:imageSharingMode is
152    ename:VK_SHARING_MODE_CONCURRENT.
153  * pname:preTransform is a elink:VkSurfaceTransformFlagBitsKHR value
154    describing the transform, relative to the presentation engine's natural
155    orientation, applied to the image content prior to presentation.
156    If it does not match the pname:currentTransform value returned by
157    fname:vkGetPhysicalDeviceSurfaceCapabilitiesKHR, the presentation engine
158    will transform the image content as part of the presentation operation.
159  * pname:compositeAlpha is a elink:VkCompositeAlphaFlagBitsKHR value
160    indicating the alpha compositing mode to use when this surface is
161    composited together with other surfaces on certain window systems.
162  * pname:presentMode is the presentation mode the swapchain will use.
163    A swapchain's present mode determines how incoming present requests will
164    be processed and queued internally.
165  * pname:clipped specifies whether the Vulkan implementation is allowed to
166    discard rendering operations that affect regions of the surface that are
167    not visible.
168  ** If set to ename:VK_TRUE, the presentable images associated with the
169     swapchain may: not own all of their pixels.
170     Pixels in the presentable images that correspond to regions of the
171     target surface obscured by another window on the desktop, or subject to
172     some other clipping mechanism will have undefined content when read
173     back.
174     Pixel shaders may: not execute for these pixels, and thus any side
175     effects they would have had will not occur.
176     ename:VK_TRUE value does not guarantee any clipping will occur, but
177     allows more optimal presentation methods to be used on some platforms.
178  ** If set to ename:VK_FALSE, presentable images associated with the
179     swapchain will own all of the pixels they contain.
180
181[NOTE]
182.Note
183====
184Applications should: set this value to ename:VK_TRUE if they do not expect
185to read back the content of presentable images before presenting them or
186after reacquiring them, and if their pixel shaders do not have any side
187effects that require them to run for all pixels in the presentable image.
188====
189
190  * pname:oldSwapchain is dlink:VK_NULL_HANDLE, or the existing non-retired
191    swapchain currently associated with pname:surface.
192    Providing a valid pname:oldSwapchain may: aid in the resource reuse, and
193    also allows the application to still present any images that are already
194    acquired from it.
195
196Upon calling fname:vkCreateSwapchainKHR with an pname:oldSwapchain that is
197not dlink:VK_NULL_HANDLE, pname:oldSwapchain is retired -- even if creation
198of the new swapchain fails.
199The new swapchain is created in the non-retired state whether or not
200pname:oldSwapchain is dlink:VK_NULL_HANDLE.
201
202Upon calling fname:vkCreateSwapchainKHR with an pname:oldSwapchain that is
203not dlink:VK_NULL_HANDLE, any images from pname:oldSwapchain that are not
204acquired by the application may: be freed by the implementation, which may:
205occur even if creation of the new swapchain fails.
206The application can: destroy pname:oldSwapchain to free all memory
207associated with pname:oldSwapchain.
208
209[NOTE]
210.Note
211====
212Multiple retired swapchains can: be associated with the same
213sname:VkSurfaceKHR through multiple uses of sname:oldSwapchain that
214outnumber calls to flink:vkDestroySwapchainKHR.
215
216After sname:oldSwapchain is retired, the application can: pass to
217flink:vkQueuePresentKHR any images it had already acquired from
218sname:oldSwapchain.
219E.g., an application may present an image from the old swapchain before an
220image from the new swapchain is ready to be presented.
221As usual, flink:vkQueuePresentKHR may: fail if sname:oldSwapchain has
222entered a state that causes ename:VK_ERROR_OUT_OF_DATE_KHR to be returned.
223
224ifdef::VK_KHR_shared_presentable_image[]
225The application can: continue to use a shared presentable image obtained
226from pname:oldSwapchain until a presentable image is acquired from the new
227swapchain, as long as it has not entered a state that causes it to return
228ename:VK_ERROR_OUT_OF_DATE_KHR.
229endif::VK_KHR_shared_presentable_image[]
230====
231
232.Valid Usage
233****
234  * [[VUID-VkSwapchainCreateInfoKHR-surface-01270]]
235    pname:surface must: be a surface that is supported by the device as
236    determined using fname:vkGetPhysicalDeviceSurfaceSupportKHR
237  * [[VUID-VkSwapchainCreateInfoKHR-minImageCount-01271]]
238    pname:minImageCount must: be greater than or equal to the value returned
239    in the pname:minImageCount member of the sname:VkSurfaceCapabilitiesKHR
240    structure returned by fname:vkGetPhysicalDeviceSurfaceCapabilitiesKHR
241    for the surface
242  * [[VUID-VkSwapchainCreateInfoKHR-minImageCount-01272]]
243    pname:minImageCount must: be less than or equal to the value returned in
244    the pname:maxImageCount member of the sname:VkSurfaceCapabilitiesKHR
245    structure returned by fname:vkGetPhysicalDeviceSurfaceCapabilitiesKHR
246    for the surface if the returned pname:maxImageCount is not zero
247ifdef::VK_KHR_shared_presentable_image[]
248  * [[VUID-VkSwapchainCreateInfoKHR-minImageCount-01383]]
249    pname:minImageCount must: be `1` if pname:presentMode is either
250    ename:VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR or
251    ename:VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR
252endif::VK_KHR_shared_presentable_image[]
253  * [[VUID-VkSwapchainCreateInfoKHR-imageFormat-01273]]
254    pname:imageFormat and pname:imageColorSpace must: match the pname:format
255    and pname:colorSpace members, respectively, of one of the
256    sname:VkSurfaceFormatKHR structures returned by
257    fname:vkGetPhysicalDeviceSurfaceFormatsKHR for the surface
258  * [[VUID-VkSwapchainCreateInfoKHR-imageExtent-01274]]
259    pname:imageExtent must: be between pname:minImageExtent and
260    pname:maxImageExtent, inclusive, where pname:minImageExtent and
261    pname:maxImageExtent are members of the sname:VkSurfaceCapabilitiesKHR
262    structure returned by fname:vkGetPhysicalDeviceSurfaceCapabilitiesKHR
263    for the surface
264  * [[VUID-VkSwapchainCreateInfoKHR-imageExtent-01689]]
265    pname:imageExtent members pname:width and pname:height must: both be
266    non-zero
267  * [[VUID-VkSwapchainCreateInfoKHR-imageArrayLayers-01275]]
268    pname:imageArrayLayers must: be greater than `0` and less than or equal
269    to the pname:maxImageArrayLayers member of the
270    sname:VkSurfaceCapabilitiesKHR structure returned by
271    fname:vkGetPhysicalDeviceSurfaceCapabilitiesKHR for the surface
272ifndef::VK_KHR_shared_presentable_image[]
273  * [[VUID-VkSwapchainCreateInfoKHR-imageUsage-01276]]
274    pname:imageUsage must: be a subset of the supported usage flags present
275    in the pname:supportedUsageFlags member of the
276    sname:VkSurfaceCapabilitiesKHR structure returned by
277    fname:vkGetPhysicalDeviceSurfaceCapabilitiesKHR for the surface
278endif::VK_KHR_shared_presentable_image[]
279ifdef::VK_KHR_shared_presentable_image[]
280  * [[VUID-VkSwapchainCreateInfoKHR-presentMode-01427]]
281    If pname:presentMode is ename:VK_PRESENT_MODE_IMMEDIATE_KHR,
282    ename:VK_PRESENT_MODE_MAILBOX_KHR, ename:VK_PRESENT_MODE_FIFO_KHR or
283    ename:VK_PRESENT_MODE_FIFO_RELAXED_KHR, pname:imageUsage must: be a
284    subset of the supported usage flags present in the
285    pname:supportedUsageFlags member of the slink:VkSurfaceCapabilitiesKHR
286    structure returned by flink:vkGetPhysicalDeviceSurfaceCapabilitiesKHR
287    for pname:surface
288  * [[VUID-VkSwapchainCreateInfoKHR-imageUsage-01384]]
289    If pname:presentMode is ename:VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR
290    or ename:VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR, pname:imageUsage
291    must: be a subset of the supported usage flags present in the
292    pname:sharedPresentSupportedUsageFlags member of the
293    slink:VkSharedPresentSurfaceCapabilitiesKHR structure returned by
294    flink:vkGetPhysicalDeviceSurfaceCapabilities2KHR for pname:surface
295endif::VK_KHR_shared_presentable_image[]
296  * [[VUID-VkSwapchainCreateInfoKHR-imageSharingMode-01277]]
297    If pname:imageSharingMode is ename:VK_SHARING_MODE_CONCURRENT,
298    pname:pQueueFamilyIndices must: be a valid pointer to an array of
299    pname:queueFamilyIndexCount basetype:uint32_t values
300  * [[VUID-VkSwapchainCreateInfoKHR-imageSharingMode-01278]]
301    If pname:imageSharingMode is ename:VK_SHARING_MODE_CONCURRENT,
302    pname:queueFamilyIndexCount must: be greater than `1`
303ifndef::VK_VERSION_1_1,VK_KHR_get_physical_device_properties2[]
304  * [[VUID-VkSwapchainCreateInfoKHR-imageSharingMode-01393]]
305    If pname:imageSharingMode is ename:VK_SHARING_MODE_CONCURRENT, each
306    element of pname:pQueueFamilyIndices must: be unique and must: be less
307    than pname:pQueueFamilyPropertyCount returned by
308    flink:vkGetPhysicalDeviceQueueFamilyProperties for the
309    pname:physicalDevice that was used to create pname:device
310endif::VK_VERSION_1_1,VK_KHR_get_physical_device_properties2[]
311ifdef::VK_VERSION_1_1,VK_KHR_get_physical_device_properties2[]
312  * [[VUID-VkSwapchainCreateInfoKHR-imageSharingMode-01428]]
313    If pname:imageSharingMode is ename:VK_SHARING_MODE_CONCURRENT, each
314    element of pname:pQueueFamilyIndices must: be unique and must: be less
315    than pname:pQueueFamilyPropertyCount returned by either
316    flink:vkGetPhysicalDeviceQueueFamilyProperties or
317    flink:vkGetPhysicalDeviceQueueFamilyProperties2 for the
318    pname:physicalDevice that was used to create pname:device
319endif::VK_VERSION_1_1,VK_KHR_get_physical_device_properties2[]
320  * [[VUID-VkSwapchainCreateInfoKHR-preTransform-01279]]
321    pname:preTransform must: be one of the bits present in the
322    pname:supportedTransforms member of the sname:VkSurfaceCapabilitiesKHR
323    structure returned by fname:vkGetPhysicalDeviceSurfaceCapabilitiesKHR
324    for the surface
325  * [[VUID-VkSwapchainCreateInfoKHR-compositeAlpha-01280]]
326    pname:compositeAlpha must: be one of the bits present in the
327    pname:supportedCompositeAlpha member of the
328    sname:VkSurfaceCapabilitiesKHR structure returned by
329    fname:vkGetPhysicalDeviceSurfaceCapabilitiesKHR for the surface
330  * [[VUID-VkSwapchainCreateInfoKHR-presentMode-01281]]
331    pname:presentMode must: be one of the elink:VkPresentModeKHR values
332    returned by fname:vkGetPhysicalDeviceSurfacePresentModesKHR for the
333    surface
334ifdef::VK_VERSION_1_1,VK_KHR_device_group[]
335  * [[VUID-VkSwapchainCreateInfoKHR-physicalDeviceCount-01429]]
336    If the logical device was created with
337    slink:VkDeviceGroupDeviceCreateInfo::pname:physicalDeviceCount equal to
338    1, pname:flags must: not contain
339    ename:VK_SWAPCHAIN_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT_KHR
340endif::VK_VERSION_1_1,VK_KHR_device_group[]
341  * [[VUID-VkSwapchainCreateInfoKHR-oldSwapchain-01933]]
342    If pname:oldSwapchain is not dlink:VK_NULL_HANDLE, pname:oldSwapchain
343    must: be a non-retired swapchain associated with native window referred
344    to by pname:surface
345  * [[VUID-VkSwapchainCreateInfoKHR-imageFormat-01778]]
346    pname:imageFormat, pname:imageUsage, pname:imageExtent, and
347    pname:imageArrayLayers must: be supported for ename:VK_IMAGE_TYPE_2D
348    ename:VK_IMAGE_TILING_OPTIMAL images as reported by
349    flink:vkGetPhysicalDeviceImageFormatProperties.
350****
351
352include::../../validity/structs/VkSwapchainCreateInfoKHR.txt[]
353--
354
355[open,refpage='VkSwapchainCreateFlagBitsKHR',desc='Bitmask controlling swapchain creation',type='enums']
356--
357
358Bits which can: be set in slink:VkSwapchainCreateInfoKHR::pname:flags,
359specifying parameters of swapchain creation, are:
360
361include::../../api/enums/VkSwapchainCreateFlagBitsKHR.txt[]
362
363ifdef::VK_VERSION_1_1,VK_KHR_device_group[]
364  * ename:VK_SWAPCHAIN_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT_KHR specifies
365    that images created from the swapchain (i.e. with the pname:swapchain
366    member of slink:VkImageSwapchainCreateInfoKHR set to this swapchain's
367    handle) must: use ename:VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT.
368endif::VK_VERSION_1_1,VK_KHR_device_group[]
369ifdef::VK_VERSION_1_1[]
370  * ename:VK_SWAPCHAIN_CREATE_PROTECTED_BIT_KHR specifies that images
371    created from the swapchain are protected images.
372endif::VK_VERSION_1_1[]
373
374--
375
376[open,refpage='VkSwapchainCreateFlagsKHR',desc='Bitmask of VkSwapchainCreateFlagBitsKHR',type='enums']
377--
378include::../../api/flags/VkSwapchainCreateFlagsKHR.txt[]
379
380sname:VkSwapchainCreateFlagsKHR is a bitmask type for setting a mask of zero
381or more slink:VkSwapchainCreateFlagBitsKHR.
382--
383
384ifdef::VK_VERSION_1_1,VK_KHR_device_group[]
385
386[open,refpage='VkDeviceGroupSwapchainCreateInfoKHR',desc='Structure specifying parameters of a newly created swapchain object',type='structs']
387--
388
389If the pname:pNext chain of slink:VkSwapchainCreateInfoKHR includes a
390sname:VkDeviceGroupSwapchainCreateInfoKHR structure, then that structure
391includes a set of device group present modes that the swapchain can: be used
392with.
393
394The sname:VkDeviceGroupSwapchainCreateInfoKHR structure is defined as:
395
396include::../../api/structs/VkDeviceGroupSwapchainCreateInfoKHR.txt[]
397
398  * pname:sType is the type of this structure.
399  * pname:pNext is `NULL` or a pointer to an extension-specific structure.
400  * pname:modes is a bitfield of modes that the swapchain can: be used with.
401
402If this structure is not present, pname:modes is considered to be
403ename:VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR.
404
405include::../../validity/structs/VkDeviceGroupSwapchainCreateInfoKHR.txt[]
406--
407
408endif::VK_VERSION_1_1,VK_KHR_device_group[]
409
410ifdef::VK_EXT_display_control[]
411include::../VK_EXT_display_control/swapchain_counters.txt[]
412endif::VK_EXT_display_control[]
413
414As mentioned above, if fname:vkCreateSwapchainKHR succeeds, it will return a
415handle to a swapchain that contains an array of at least pname:minImageCount
416presentable images.
417
418While acquired by the application, presentable images can: be used in any
419way that equivalent non-presentable images can: be used.
420A presentable image is equivalent to a non-presentable image created with
421the following sname:VkImageCreateInfo parameters:
422
423[[swapchain-wsi-image-create-info]]
424[options="header"]
425|====
426| sname:VkImageCreateInfo Field | Value
427ifndef::VK_VERSION_1_1,VK_KHR_device_group[]
428| pname:flags                   | 0
429endif::VK_VERSION_1_1,VK_KHR_device_group[]
430ifdef::VK_VERSION_1_1,VK_KHR_device_group[]
431| pname:flags |
432ifdef::VK_VERSION_1_1,VK_KHR_device_group[]
433ename:VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT is set if ename:VK_SWAPCHAIN_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT_KHR is set
434
435endif::VK_VERSION_1_1,VK_KHR_device_group[]
436ifdef::VK_VERSION_1_1[]
437ename:VK_IMAGE_CREATE_PROTECTED_BIT is set if ename:VK_SWAPCHAIN_CREATE_PROTECTED_BIT_KHR is set
438
439endif::VK_VERSION_1_1[]
440all other bits are unset
441endif::VK_VERSION_1_1,VK_KHR_device_group[]
442| pname:imageType               | ename:VK_IMAGE_TYPE_2D
443| pname:format                  | `pCreateInfo->imageFormat`
444| pname:extent                  | `{pCreateInfo->imageExtent.width, pCreateInfo->imageExtent.height, 1}`
445| pname:mipLevels               | 1
446| pname:arrayLayers             | `pCreateInfo->imageArrayLayers`
447| pname:samples                 | ename:VK_SAMPLE_COUNT_1_BIT
448| pname:tiling                  | ename:VK_IMAGE_TILING_OPTIMAL
449| pname:usage                   | `pCreateInfo->imageUsage`
450| pname:sharingMode             | `pCreateInfo->imageSharingMode`
451| pname:queueFamilyIndexCount   | `pCreateInfo->queueFamilyIndexCount`
452| pname:pQueueFamilyIndices     | `pCreateInfo->pQueueFamilyIndices`
453| pname:initialLayout           | ename:VK_IMAGE_LAYOUT_UNDEFINED
454|====
455
456The pname:surface must: not be destroyed until after the swapchain is
457destroyed.
458
459If pname:oldSwapchain is dlink:VK_NULL_HANDLE, and the native window
460referred to by pname:surface is already associated with a Vulkan swapchain,
461ename:VK_ERROR_NATIVE_WINDOW_IN_USE_KHR must: be returned.
462
463If the native window referred to by pname:surface is already associated with
464a non-Vulkan graphics API surface, ename:VK_ERROR_NATIVE_WINDOW_IN_USE_KHR
465must: be returned.
466
467The native window referred to by pname:surface must: not become associated
468with a non-Vulkan graphics API surface before all associated Vulkan
469swapchains have been destroyed.
470
471Like core functions, several WSI functions, including
472fname:vkCreateSwapchainKHR return ename:VK_ERROR_DEVICE_LOST if the logical
473device was lost.
474See <<devsandqueues-lost-device,Lost Device>>.
475As with most core objects, sname:VkSwapchainKHR is a child of the device and
476is affected by the lost state; it must: be destroyed before destroying the
477sname:VkDevice.
478However, sname:VkSurfaceKHR is not a child of any sname:VkDevice and is not
479otherwise affected by the lost device.
480After successfully recreating a sname:VkDevice, the same sname:VkSurfaceKHR
481can: be used to create a new sname:VkSwapchainKHR, provided the previous one
482was destroyed.
483
484[NOTE]
485.Note
486====
487As mentioned in <<devsandqueues-lost-device,Lost Device>>, after a lost
488device event, the sname:VkPhysicalDevice may: also be lost.
489If other sname:VkPhysicalDevice are available, they can: be used together
490with the same sname:VkSurfaceKHR to create the new sname:VkSwapchainKHR,
491however the application must: query the surface capabilities again, because
492they may: differ on a per-physical device basis.
493====
494
495[open,refpage='vkDestroySwapchainKHR',desc='Destroy a swapchain object',type='protos']
496--
497
498To destroy a swapchain object call:
499
500include::../../api/protos/vkDestroySwapchainKHR.txt[]
501
502  * pname:device is the slink:VkDevice associated with pname:swapchain.
503  * pname:swapchain is the swapchain to destroy.
504  * pname:pAllocator is the allocator used for host memory allocated for the
505    swapchain object when there is no more specific allocator available (see
506    <<memory-allocation,Memory Allocation>>).
507
508The application must: not destroy a swapchain until after completion of all
509outstanding operations on images that were acquired from the swapchain.
510pname:swapchain and all associated sname:VkImage handles are destroyed, and
511must: not be acquired or used any more by the application.
512The memory of each sname:VkImage will only be freed after that image is no
513longer used by the presentation engine.
514For example, if one image of the swapchain is being displayed in a window,
515the memory for that image may: not be freed until the window is destroyed,
516or another swapchain is created for the window.
517Destroying the swapchain does not invalidate the parent sname:VkSurfaceKHR,
518and a new swapchain can: be created with it.
519
520ifdef::VK_KHR_display_swapchain[]
521include::../VK_KHR_display_swapchain/destroy_swapchain_interactions.txt[]
522endif::VK_KHR_display_swapchain[]
523
524.Valid Usage
525****
526  * [[VUID-vkDestroySwapchainKHR-swapchain-01282]]
527    All uses of presentable images acquired from pname:swapchain must: have
528    completed execution
529  * [[VUID-vkDestroySwapchainKHR-swapchain-01283]]
530    If sname:VkAllocationCallbacks were provided when pname:swapchain was
531    created, a compatible set of callbacks must: be provided here
532  * [[VUID-vkDestroySwapchainKHR-swapchain-01284]]
533    If no sname:VkAllocationCallbacks were provided when pname:swapchain was
534    created, pname:pAllocator must: be `NULL`
535****
536
537include::../../validity/protos/vkDestroySwapchainKHR.txt[]
538--
539
540ifdef::VK_KHR_display_swapchain[]
541include::../VK_KHR_display_swapchain/create_shared_swapchains.txt[]
542endif::VK_KHR_display_swapchain[]
543
544[open,refpage='vkGetSwapchainImagesKHR',desc='Obtain the array of presentable images associated with a swapchain',type='protos']
545--
546
547To obtain the array of presentable images associated with a swapchain, call:
548
549include::../../api/protos/vkGetSwapchainImagesKHR.txt[]
550
551  * pname:device is the device associated with pname:swapchain.
552  * pname:swapchain is the swapchain to query.
553  * pname:pSwapchainImageCount is a pointer to an integer related to the
554    number of presentable images available or queried, as described below.
555  * pname:pSwapchainImages is either `NULL` or a pointer to an array of
556    sname:VkImage handles.
557
558If pname:pSwapchainImages is `NULL`, then the number of presentable images
559for pname:swapchain is returned in pname:pSwapchainImageCount.
560Otherwise, pname:pSwapchainImageCount must: point to a variable set by the
561user to the number of elements in the pname:pSwapchainImages array, and on
562return the variable is overwritten with the number of structures actually
563written to pname:pSwapchainImages.
564If the value of pname:pSwapchainImageCount is less than the number of
565presentable images for pname:swapchain, at most pname:pSwapchainImageCount
566structures will be written.
567If pname:pSwapchainImageCount is smaller than the number of presentable
568images for pname:swapchain, ename:VK_INCOMPLETE will be returned instead of
569ename:VK_SUCCESS to indicate that not all the available values were
570returned.
571
572include::../../validity/protos/vkGetSwapchainImagesKHR.txt[]
573--
574
575[NOTE]
576.Note
577====
578By knowing all presentable images used in the swapchain, the application
579can: create command buffers that reference these images prior to entering
580its main rendering loop.
581====
582
583The implementation will have already allocated and bound the memory backing
584the sname:VkImages returned by fname:vkGetSwapchainImagesKHR.
585The memory for each image will not alias with the memory for other images or
586with any sname:VkDeviceMemory object.
587As such, performing any operation affecting the binding of memory to a
588presentable image results in undefined behavior.
589All presentable images are initially in the ename:VK_IMAGE_LAYOUT_UNDEFINED
590layout, thus before using presentable images, the application must:
591transition them to a valid layout for the intended use.
592
593Further, the lifetime of presentable images is controlled by the
594implementation so destroying a presentable image with flink:vkDestroyImage
595results in undefined behavior.
596See flink:vkDestroySwapchainKHR for further details on the lifetime of
597presentable images.
598
599ifdef::VK_VERSION_1_1,VK_KHR_device_group[]
600
601Images can: also be created by using flink:vkCreateImage with
602slink:VkImageSwapchainCreateInfoKHR and bound to swapchain memory using
603flink:vkBindImageMemory2KHR with slink:VkBindImageMemorySwapchainInfoKHR.
604These images can: be used anywhere swapchain images are used, and are useful
605in logical devices with multiple physical devices to create peer memory
606bindings of swapchain memory.
607These images and bindings have no effect on what memory is presented.
608Unlike images retrieved from fname:vkGetSwapchainImagesKHR, these images
609must: be destroyed with flink:vkDestroyImage.
610
611endif::VK_VERSION_1_1,VK_KHR_device_group[]
612
613[open,refpage='vkAcquireNextImageKHR',desc='Retrieve the index of the next available presentable image',type='protos']
614--
615
616To acquire an available presentable image to use, and retrieve the index of
617that image, call:
618
619include::../../api/protos/vkAcquireNextImageKHR.txt[]
620
621  * pname:device is the device associated with pname:swapchain.
622  * pname:swapchain is the non-retired swapchain from which an image is
623    being acquired.
624  * pname:timeout specifies how long the function waits, in nanoseconds, if
625    no image is available.
626  * pname:semaphore is dlink:VK_NULL_HANDLE or a semaphore to signal.
627  * pname:fence is dlink:VK_NULL_HANDLE or a fence to signal.
628  * pname:pImageIndex is a pointer to a code:uint32_t that is set to the
629    index of the next image to use (i.e. an index into the array of images
630    returned by fname:vkGetSwapchainImagesKHR).
631
632.Valid Usage
633****
634  * [[VUID-vkAcquireNextImageKHR-swapchain-01285]]
635    pname:swapchain must: not be in the retired state
636  * [[VUID-vkAcquireNextImageKHR-semaphore-01286]]
637    If pname:semaphore is not dlink:VK_NULL_HANDLE it must: be unsignaled
638  * [[VUID-vkAcquireNextImageKHR-semaphore-01779]]
639    If pname:semaphore is not dlink:VK_NULL_HANDLE it must: not have any
640    uncompleted signal or wait operations pending
641  * [[VUID-vkAcquireNextImageKHR-fence-01287]]
642    If pname:fence is not dlink:VK_NULL_HANDLE it must: be unsignaled and
643    must: not be associated with any other queue command that has not yet
644    completed execution on that queue
645  * [[VUID-vkAcquireNextImageKHR-semaphore-01780]]
646    pname:semaphore and pname:fence must: not both be equal to
647    dlink:VK_NULL_HANDLE
648  * [[VUID-vkAcquireNextImageKHR-swapchain-01802]]
649    If the number of currently acquired images is greater than the
650    difference between the number of images in pname:swapchain and the value
651    of slink:VkSurfaceCapabilitiesKHR::pname:minImageCount as returned by a
652    call to flink:vkGetPhysicalDeviceSurfaceCapabilities2KHR with the
653    pname:surface used to create pname:swapchain, pname:timeout must: not be
654    ename:UINT64_MAX
655****
656
657include::../../validity/protos/vkAcquireNextImageKHR.txt[]
658--
659
660When successful, fname:vkAcquireNextImageKHR acquires a presentable image
661from pname:swapchain that an application can: use, and sets
662pname:pImageIndex to the index of that image within the swapchain.
663The presentation engine may: not have finished reading from the image at the
664time it is acquired, so the application must: use pname:semaphore and/or
665pname:fence to ensure that the image layout and contents are not modified
666until the presentation engine reads have completed.
667The order in which images are acquired is implementation-dependent, and may:
668be different than the order the images were presented.
669
670If pname:timeout is zero, then fname:vkAcquireNextImageKHR does not wait,
671and will either successfully acquire an image, or fail and return
672ename:VK_NOT_READY if no image is available.
673
674If the specified timeout period expires before an image is acquired,
675fname:vkAcquireNextImageKHR returns ename:VK_TIMEOUT.
676If pname:timeout is ename:UINT64_MAX, the timeout period is treated as
677infinite, and fname:vkAcquireNextImageKHR will block until an image is
678acquired or an error occurs.
679
680An image will eventually be acquired if the number of images that the
681application has currently acquired (but not yet presented) is less than or
682equal to the difference between the number of images in pname:swapchain and
683the value of slink:VkSurfaceCapabilitiesKHR::pname:minImageCount.
684If the number of currently acquired images is greater than this,
685fname:vkAcquireNextImage should: not be called; if it is, pname:timeout
686must: not be ename:UINT64_MAX.
687
688If an image is acquired successfully, fname:vkAcquireNextImage must: either
689return ename:VK_SUCCESS, or ename:VK_SUBOPTIMAL_KHR if the swapchain no
690longer matches the surface properties exactly, but can: still be used for
691presentation.
692
693[NOTE]
694.Note
695====
696This may: happen, for example, if the platform surface has been resized but
697the platform is able to scale the presented images to the new size to
698produce valid surface updates.
699It is up to the application to decide whether it prefers to continue using
700the current swapchain in this state, or to re-create the swapchain to better
701match the platform surface properties.
702====
703
704If the swapchain images no longer match native surface properties, either
705ename:VK_SUBOPTIMAL_KHR or ename:VK_ERROR_OUT_OF_DATE_KHR must: be returned.
706If ename:VK_ERROR_OUT_OF_DATE_KHR is returned, no image is acquired and
707attempts to present previously acquired images to the swapchain will also
708fail with ename:VK_ERROR_OUT_OF_DATE_KHR.
709Applications need to create a new swapchain for the surface to continue
710presenting if ename:VK_ERROR_OUT_OF_DATE_KHR is returned.
711
712If device loss occurs (see <<devsandqueues-lost-device,Lost Device>>) before
713the timeout has expired, fname:vkAcquireNextImageKHR must: return in finite
714time with either one of the allowed success codes, or
715ename:VK_ERROR_DEVICE_LOST.
716
717If pname:semaphore is not dlink:VK_NULL_HANDLE, the semaphore must: be
718unsignaled, with no signal or wait operations pending.
719It will become signaled when the application can: use the image.
720
721[NOTE]
722.Note
723====
724Use of pname:semaphore allows rendering operations to be recorded and
725submitted before the presentation engine has completed its use of the image.
726====
727
728If pname:fence is not equal to dlink:VK_NULL_HANDLE, the fence must: be
729unsignaled, with no signal operations pending.
730It will become signaled when the application can: use the image.
731
732[NOTE]
733.Note
734====
735Applications should: not rely on fname:vkAcquireNextImageKHR blocking in
736order to meter their rendering speed.
737The implementation may: return from this function immediately regardless of
738how many presentation requests are queued, and regardless of when queued
739presentation requests will complete relative to the call.
740Instead, applications can: use pname:fence to meter their frame generation
741work to match the presentation rate.
742====
743
744An application must: wait until either the pname:semaphore or pname:fence is
745signaled before accessing the image's data.
746
747[NOTE]
748.Note
749====
750When the presentable image will be accessed by some stage [eq]#S#, the
751recommended idiom for ensuring correct synchronization is:
752
753  * The slink:VkSubmitInfo used to submit the image layout transition for
754    execution includes fname:vkAcquireNextImageKHR::pname:semaphore in its
755    pname:pWaitSemaphores member, with the corresponding element of
756    pname:pWaitDstStageMask including [eq]#S#.
757  * The <<synchronization, synchronization command>> that performs any
758    necessary image layout transition includes [eq]#S# in both the
759    pname:srcStageMask and pname:dstStageMask.
760====
761
762After a successful return, the image indicated by pname:pImageIndex and its
763data will be unmodified compared to when it was presented.
764
765[NOTE]
766.Note
767====
768Exclusive ownership of presentable images corresponding to a swapchain
769created with ename:VK_SHARING_MODE_EXCLUSIVE as defined in
770<<resources-sharing,Resource Sharing>> is not altered by a call to
771fname:vkAcquireNextImageKHR.
772That means upon the first acquisition from such a swapchain presentable
773images are not owned by any queue family, while at subsequent acquisitions
774the presentable images remain owned by the queue family the image was
775previously presented on.
776====
777
778The possible return values for fname:vkAcquireNextImageKHR depend on the
779pname:timeout provided:
780
781  * ename:VK_SUCCESS is returned if an image became available.
782  * ename:VK_ERROR_SURFACE_LOST_KHR if the surface becomes no longer
783    available.
784  * ename:VK_NOT_READY is returned if pname:timeout is zero and no image was
785    available.
786  * ename:VK_TIMEOUT is returned if pname:timeout is greater than zero and
787    less than `UINT64_MAX`, and no image became available within the time
788    allowed.
789  * ename:VK_SUBOPTIMAL_KHR is returned if an image became available, and
790    the swapchain no longer matches the surface properties exactly, but can:
791    still be used to present to the surface successfully.
792
793[NOTE]
794.Note
795====
796This may: happen, for example, if the platform surface has been resized but
797the platform is able to scale the presented images to the new size to
798produce valid surface updates.
799It is up to the application to decide whether it prefers to continue using
800the current swapchain indefinitely or temporarily in this state, or to
801re-create the swapchain to better match the platform surface properties.
802====
803
804  * ename:VK_ERROR_OUT_OF_DATE_KHR is returned if the surface has changed in
805    such a way that it is no longer compatible with the swapchain, and
806    further presentation requests using the swapchain will fail.
807    Applications must: query the new surface properties and recreate their
808    swapchain if they wish to continue presenting to the surface.
809
810If the native surface and presented image sizes no longer match,
811presentation may: fail.
812If presentation does succeed, parts of the native surface may: be undefined,
813parts of the presented image may: have been clipped before presentation,
814and/or the image may: have been scaled (uniformly or not uniformly) before
815presentation.
816It is the application's responsibility to detect surface size changes and
817react appropriately.
818If presentation fails because of a mismatch in the surface and presented
819image sizes, a ename:VK_ERROR_OUT_OF_DATE_KHR error will be returned.
820
821ifdef::VK_VERSION_1_1,VK_KHR_device_group[]
822
823[open,refpage='vkAcquireNextImage2KHR',desc='Retrieve the index of the next available presentable image',type='protos']
824--
825
826To acquire an available presentable image to use, and retrieve the index of
827that image, call:
828
829include::../../api/protos/vkAcquireNextImage2KHR.txt[]
830
831  * pname:device is the device associated with pname:swapchain.
832  * pname:pAcquireInfo is a pointer to a structure of type
833    slink:VkAcquireNextImageInfoKHR containing parameters of the acquire.
834  * pname:pImageIndex is a pointer to a code:uint32_t that is set to the
835    index of the next image to use.
836
837.Valid Usage
838****
839  * [[VUID-vkAcquireNextImage2KHR-swapchain-01803]]
840    If the number of currently acquired images is greater than the
841    difference between the number of images in the pname:swapchain member of
842    pname:pAcquireInfo and the value of
843    slink:VkSurfaceCapabilitiesKHR::pname:minImageCount as returned by a
844    call to flink:vkGetPhysicalDeviceSurfaceCapabilities2KHR with the
845    pname:surface used to create pname:swapchain, the pname:timeout member
846    of pname:pAcquireInfo must: not be ename:UINT64_MAX
847****
848
849include::../../validity/protos/vkAcquireNextImage2KHR.txt[]
850--
851
852[open,refpage='VkAcquireNextImageInfoKHR',desc='Structure specifying parameters of the acquire',type='structs']
853--
854
855The sname:VkAcquireNextImageInfoKHR structure is defined as:
856
857include::../../api/structs/VkAcquireNextImageInfoKHR.txt[]
858
859  * pname:sType is the type of this structure.
860  * pname:pNext is `NULL` or a pointer to an extension-specific structure.
861  * pname:swapchain is a non-retired swapchain from which an image is
862    acquired.
863  * pname:timeout specifies how long the function waits, in nanoseconds, if
864    no image is available.
865  * pname:semaphore is code:VK_NULL_HANDLE or a semaphore to signal.
866  * pname:fence is code:VK_NULL_HANDLE or a fence to signal.
867  * pname:deviceMask is a mask of physical devices for which the swapchain
868    image will be ready to use when the semaphore or fence is signaled.
869
870If flink:vkAcquireNextImageKHR is used, the device mask is considered to
871include all physical devices in the logical device.
872
873[NOTE]
874.Note
875====
876flink:vkAcquireNextImage2KHR signals at most one semaphore, even if the
877application requests waiting for multiple physical devices to be ready via
878the pname:deviceMask.
879However, only a single physical device can: wait on that semaphore, since
880the semaphore becomes unsignaled when the wait succeeds.
881For other physical devices to wait for the image to be ready, it is
882necessary for the application to submit semaphore signal operation(s) to
883that first physical device to signal additional semaphore(s) after the wait
884succeeds, which the other physical device(s) can: wait upon.
885====
886
887.Valid Usage
888****
889  * [[VUID-VkAcquireNextImageInfoKHR-swapchain-01675]]
890    pname:swapchain must: not be in the retired state
891  * [[VUID-VkAcquireNextImageInfoKHR-semaphore-01288]]
892    If pname:semaphore is not dlink:VK_NULL_HANDLE it must: be unsignaled
893  * [[VUID-VkAcquireNextImageInfoKHR-semaphore-01781]]
894    If pname:semaphore is not dlink:VK_NULL_HANDLE it must: not have any
895    uncompleted signal or wait operations pending
896  * [[VUID-VkAcquireNextImageInfoKHR-fence-01289]]
897    If pname:fence is not dlink:VK_NULL_HANDLE it must: be unsignaled and
898    must: not be associated with any other queue command that has not yet
899    completed execution on that queue
900  * [[VUID-VkAcquireNextImageInfoKHR-semaphore-01782]]
901    pname:semaphore and pname:fence must: not both be equal to
902    dlink:VK_NULL_HANDLE
903  * [[VUID-VkAcquireNextImageInfoKHR-deviceMask-01290]]
904    pname:deviceMask must: be a valid device mask
905  * [[VUID-VkAcquireNextImageInfoKHR-deviceMask-01291]]
906    pname:deviceMask must: not be zero
907  * [[VUID-VkAcquireNextImageInfoKHR-semaphore-01804]]
908    pname:semaphore and pname:fence must: not both be equal to
909    dlink:VK_NULL_HANDLE.
910****
911
912include::../../validity/structs/VkAcquireNextImageInfoKHR.txt[]
913--
914
915endif::VK_VERSION_1_1,VK_KHR_device_group[]
916
917[open,refpage='vkQueuePresentKHR',desc='Queue an image for presentation',type='protos']
918--
919
920After queueing all rendering commands and transitioning the image to the
921correct layout, to queue an image for presentation, call:
922
923include::../../api/protos/vkQueuePresentKHR.txt[]
924
925  * pname:queue is a queue that is capable of presentation to the target
926    surface's platform on the same device as the image's swapchain.
927  * pname:pPresentInfo is a pointer to an instance of the
928    slink:VkPresentInfoKHR structure specifying the parameters of the
929    presentation.
930
931.Note
932[NOTE]
933====
934There is no requirement for an application to present images in the same
935order that they were acquired - applications can arbitrarily present any
936image that is currently acquired.
937====
938
939.Valid Usage
940****
941  * [[VUID-vkQueuePresentKHR-pSwapchains-01292]]
942    Each element of pname:pSwapchains member of pname:pPresentInfo must: be
943    a swapchain that is created for a surface for which presentation is
944    supported from pname:queue as determined using a call to
945    fname:vkGetPhysicalDeviceSurfaceSupportKHR
946ifdef::VK_KHR_display_swapchain[]
947  * [[VUID-vkQueuePresentKHR-pSwapchains-01293]]
948    If more than one member of pname:pSwapchains was created from a display
949    surface, all display surfaces referenced that refer to the same display
950    must: use the same display mode
951endif::VK_KHR_display_swapchain[]
952  * [[VUID-vkQueuePresentKHR-pWaitSemaphores-01294]]
953    When a semaphore unsignal operation defined by the elements of the
954    pname:pWaitSemaphores member of pname:pPresentInfo executes on
955    pname:queue, no other queue must: be waiting on the same semaphore.
956  * [[VUID-vkQueuePresentKHR-pWaitSemaphores-01295]]
957    All elements of the pname:pWaitSemaphores member of pname:pPresentInfo
958    must: be semaphores that are signaled, or have
959    <<synchronization-semaphores-signaling, semaphore signal operations>>
960    previously submitted for execution.
961****
962
963Any writes to memory backing the images referenced by the
964pname:pImageIndices and pname:pSwapchains members of pname:pPresentInfo,
965that are available before flink:vkQueuePresentKHR is executed, are
966automatically made visible to the read access performed by the presentation
967engine.
968This automatic visibility operation for an image happens-after the semaphore
969signal operation, and happens-before the presentation engine accesses the
970image.
971
972Queueing an image for presentation defines a set of _queue operations_,
973including waiting on the semaphores and submitting a presentation request to
974the presentation engine.
975However, the scope of this set of queue operations does not include the
976actual processing of the image by the presentation engine.
977
978If fname:vkQueuePresentKHR fails to enqueue the corresponding set of queue
979operations, it may: return ename:VK_ERROR_OUT_OF_HOST_MEMORY or
980ename:VK_ERROR_OUT_OF_DEVICE_MEMORY.
981If it does, the implementation must: ensure that the state and contents of
982any resources or synchronization primitives referenced is unaffected by the
983call or its failure.
984
985If fname:vkQueuePresentKHR fails in such a way that the implementation is
986unable to make that guarantee, the implementation must: return
987ename:VK_ERROR_DEVICE_LOST.
988
989However, if the presentation request is rejected by the presentation engine
990with an error ename:VK_ERROR_OUT_OF_DATE_KHR or
991ename:VK_ERROR_SURFACE_LOST_KHR, the set of queue operations are still
992considered to be enqueued and thus any semaphore to be waited on gets
993unsignaled when the corresponding queue operation is complete.
994
995include::../../validity/protos/vkQueuePresentKHR.txt[]
996--
997
998[open,refpage='VkPresentInfoKHR',desc='Structure describing parameters of a queue presentation',type='structs']
999--
1000
1001The sname:VkPresentInfoKHR structure is defined as:
1002
1003include::../../api/structs/VkPresentInfoKHR.txt[]
1004
1005  * pname:sType is the type of this structure.
1006  * pname:pNext is `NULL` or a pointer to an extension-specific structure.
1007  * pname:waitSemaphoreCount is the number of semaphores to wait for before
1008    issuing the present request.
1009    The number may: be zero.
1010  * pname:pWaitSemaphores, if not `NULL`, is an array of slink:VkSemaphore
1011    objects with pname:waitSemaphoreCount entries, and specifies the
1012    semaphores to wait for before issuing the present request.
1013  * pname:swapchainCount is the number of swapchains being presented to by
1014    this command.
1015  * pname:pSwapchains is an array of slink:VkSwapchainKHR objects with
1016    pname:swapchainCount entries.
1017    A given swapchain must: not appear in this list more than once.
1018  * pname:pImageIndices is an array of indices into the array of each
1019    swapchain's presentable images, with pname:swapchainCount entries.
1020    Each entry in this array identifies the image to present on the
1021    corresponding entry in the pname:pSwapchains array.
1022  * pname:pResults is an array of elink:VkResult typed elements with
1023    pname:swapchainCount entries.
1024    Applications that do not need per-swapchain results can: use `NULL` for
1025    pname:pResults.
1026    If non-`NULL`, each entry in pname:pResults will be set to the
1027    elink:VkResult for presenting the swapchain corresponding to the same
1028    index in pname:pSwapchains.
1029
1030Before an application can: present an image, the image's layout must: be
1031transitioned to the ename:VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
1032ifdef::VK_KHR_shared_presentable_image[]
1033layout, or for a shared presentable image the
1034ename:VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR
1035endif::VK_KHR_shared_presentable_image[]
1036layout.
1037
1038.Note
1039[NOTE]
1040====
1041When transitioning the image to
1042ifdef::VK_KHR_shared_presentable_image[]
1043ename:VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR or
1044endif::VK_KHR_shared_presentable_image[]
1045ename:VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, there is no need to delay subsequent
1046processing, or perform any visibility operations (as flink:vkQueuePresentKHR
1047performs automatic visibility operations).
1048To achieve this, the pname:dstAccessMask member of the
1049slink:VkImageMemoryBarrier should: be set to `0`, and the pname:dstStageMask
1050parameter should: be set to ename:VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT.
1051====
1052
1053.Valid Usage
1054****
1055ifndef::VK_KHR_shared_presentable_image[]
1056  * [[VUID-VkPresentInfoKHR-pImageIndices-01296]]
1057    Each element of pname:pImageIndices must: be the index of a presentable
1058    image acquired from the swapchain specified by the corresponding element
1059    of the pname:pSwapchains array, and the presented image subresource
1060    must: be in the ename:VK_IMAGE_LAYOUT_PRESENT_SRC_KHR layout at the time
1061    the operation is executed on a sname:VkDevice
1062endif::VK_KHR_shared_presentable_image[]
1063ifdef::VK_KHR_shared_presentable_image[]
1064  * [[VUID-VkPresentInfoKHR-pImageIndices-01430]]
1065    Each element of pname:pImageIndices must: be the index of a presentable
1066    image acquired from the swapchain specified by the corresponding element
1067    of the pname:pSwapchains array, and the presented image subresource
1068    must: be in the ename:VK_IMAGE_LAYOUT_PRESENT_SRC_KHR or
1069    ename:VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR layout at the time the
1070    operation is executed on a sname:VkDevice
1071endif::VK_KHR_shared_presentable_image[]
1072****
1073
1074include::../../validity/structs/VkPresentInfoKHR.txt[]
1075--
1076
1077ifdef::VK_KHR_incremental_present[]
1078include::../VK_KHR_incremental_present/wsi.txt[]
1079endif::VK_KHR_incremental_present[]
1080
1081ifdef::VK_KHR_display_swapchain[]
1082include::../VK_KHR_display_swapchain/display_swapchain_present.txt[]
1083endif::VK_KHR_display_swapchain[]
1084
1085ifdef::VK_VERSION_1_1,VK_KHR_device_group[]
1086
1087[open,refpage='VkDeviceGroupPresentInfoKHR',desc='Mode and mask controlling which physical devices\' images are presented',type='structs']
1088--
1089
1090If the pname:pNext chain of slink:VkPresentInfoKHR includes a
1091sname:VkDeviceGroupPresentInfoKHR structure, then that structure includes an
1092array of device masks and a device group present mode.
1093
1094The sname:VkDeviceGroupPresentInfoKHR structure is defined as:
1095
1096include::../../api/structs/VkDeviceGroupPresentInfoKHR.txt[]
1097
1098  * pname:sType is the type of this structure.
1099  * pname:pNext is `NULL` or a pointer to an extension-specific structure.
1100  * pname:swapchainCount is zero or the number of elements in
1101    pname:pDeviceMasks.
1102  * pname:pDeviceMasks is an array of device masks, one for each element of
1103    slink:VkPresentInfoKHR::pSwapchains.
1104  * pname:mode is the device group present mode that will be used for this
1105    present.
1106
1107If pname:mode is ename:VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR, then each
1108element of pname:pDeviceMasks selects which instance of the swapchain image
1109is presented.
1110Each element of pname:pDeviceMasks must: have exactly one bit set, and the
1111corresponding physical device must: have a presentation engine as reported
1112by slink:VkDeviceGroupPresentCapabilitiesKHR.
1113
1114If pname:mode is ename:VK_DEVICE_GROUP_PRESENT_MODE_REMOTE_BIT_KHR, then
1115each element of pname:pDeviceMasks selects which instance of the swapchain
1116image is presented.
1117Each element of pname:pDeviceMasks must: have exactly one bit set, and some
1118physical device in the logical device must: include that bit in its
1119slink:VkDeviceGroupPresentCapabilitiesKHR::pname:presentMask.
1120
1121If pname:mode is ename:VK_DEVICE_GROUP_PRESENT_MODE_SUM_BIT_KHR, then each
1122element of pname:pDeviceMasks selects which instances of the swapchain image
1123are component-wise summed and the sum of those images is presented.
1124If the sum in any component is outside the representable range, the value of
1125that component is undefined.
1126Each element of pname:pDeviceMasks must: have a value for which all set bits
1127are set in one of the elements of
1128slink:VkDeviceGroupPresentCapabilitiesKHR::pname:presentMask.
1129
1130If pname:mode is
1131ename:VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_MULTI_DEVICE_BIT_KHR, then each
1132element of pname:pDeviceMasks selects which instance(s) of the swapchain
1133images are presented.
1134For each bit set in each element of pname:pDeviceMasks, the corresponding
1135physical device must: have a presentation engine as reported by
1136slink:VkDeviceGroupPresentCapabilitiesKHR.
1137
1138If sname:VkDeviceGroupPresentInfoKHR is not provided or pname:swapchainCount
1139is zero then the masks are considered to be `1`.
1140If sname:VkDeviceGroupPresentInfoKHR is not provided, pname:mode is
1141considered to be ename:VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR.
1142
1143.Valid Usage
1144****
1145  * [[VUID-VkDeviceGroupPresentInfoKHR-swapchainCount-01297]]
1146    pname:swapchainCount must: equal `0` or
1147    slink:VkPresentInfoKHR::pname:swapchainCount
1148  * [[VUID-VkDeviceGroupPresentInfoKHR-mode-01298]]
1149    If pname:mode is ename:VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR, then
1150    each element of pname:pDeviceMasks must: have exactly one bit set, and
1151    the corresponding element of
1152    slink:VkDeviceGroupPresentCapabilitiesKHR::pname:presentMask must: be
1153    non-zero
1154  * [[VUID-VkDeviceGroupPresentInfoKHR-mode-01299]]
1155    If pname:mode is ename:VK_DEVICE_GROUP_PRESENT_MODE_REMOTE_BIT_KHR, then
1156    each element of pname:pDeviceMasks must: have exactly one bit set, and
1157    some physical device in the logical device must: include that bit in its
1158    slink:VkDeviceGroupPresentCapabilitiesKHR::pname:presentMask.
1159  * [[VUID-VkDeviceGroupPresentInfoKHR-mode-01300]]
1160    If pname:mode is ename:VK_DEVICE_GROUP_PRESENT_MODE_SUM_BIT_KHR, then
1161    each element of pname:pDeviceMasks must: have a value for which all set
1162    bits are set in one of the elements of
1163    slink:VkDeviceGroupPresentCapabilitiesKHR::pname:presentMask
1164  * [[VUID-VkDeviceGroupPresentInfoKHR-mode-01301]]
1165    If pname:mode is
1166    ename:VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_MULTI_DEVICE_BIT_KHR, then for
1167    each bit set in each element of pname:pDeviceMasks, the corresponding
1168    element of slink:VkDeviceGroupPresentCapabilitiesKHR::pname:presentMask
1169    must: be non-zero
1170  * [[VUID-VkDeviceGroupPresentInfoKHR-pDeviceMasks-01302]]
1171    The value of each element of pname:pDeviceMasks must: be equal to the
1172    device mask passed in slink:VkAcquireNextImageInfoKHR::pname:deviceMask
1173    when the image index was last acquired
1174  * [[VUID-VkDeviceGroupPresentInfoKHR-mode-01303]]
1175    pname:mode must: have exactly one bit set, and that bit must: have been
1176    included in slink:VkDeviceGroupSwapchainCreateInfoKHR::pname:modes
1177****
1178
1179include::../../validity/structs/VkDeviceGroupPresentInfoKHR.txt[]
1180--
1181
1182endif::VK_VERSION_1_1,VK_KHR_device_group[]
1183
1184ifdef::VK_GOOGLE_display_timing[]
1185include::../VK_GOOGLE_display_timing/PresentTimeInfo.txt[]
1186endif::VK_GOOGLE_display_timing[]
1187
1188fname:vkQueuePresentKHR, releases the acquisition of the images referenced
1189by pname:imageIndices.
1190The queue family corresponding to the queue fname:vkQueuePresentKHR is
1191executed on must: have ownership of the presented images as defined in
1192<<resources-sharing,Resource Sharing>>.
1193fname:vkQueuePresentKHR does not alter the queue family ownership, but the
1194presented images must: not be used again before they have been reacquired
1195using fname:vkAcquireNextImageKHR.
1196
1197The processing of the presentation happens in issue order with other queue
1198operations, but semaphores have to be used to ensure that prior rendering
1199and other commands in the specified queue complete before the presentation
1200begins.
1201The presentation command itself does not delay processing of subsequent
1202commands on the queue, however, presentation requests sent to a particular
1203queue are always performed in order.
1204Exact presentation timing is controlled by the semantics of the presentation
1205engine and native platform in use.
1206
1207ifdef::VK_KHR_display_swapchain[]
1208include::../VK_KHR_display_swapchain/queue_present_interactions.txt[]
1209endif::VK_KHR_display_swapchain[]
1210
1211The result codes ename:VK_ERROR_OUT_OF_DATE_KHR and ename:VK_SUBOPTIMAL_KHR
1212have the same meaning when returned by fname:vkQueuePresentKHR as they do
1213when returned by fname:vkAcquireNextImageKHR.
1214If multiple swapchains are presented, the result code is determined applying
1215the following rules in order:
1216
1217  * If the device is lost, ename:VK_ERROR_DEVICE_LOST is returned.
1218  * If any of the target surfaces are no longer available the error
1219    ename:VK_ERROR_SURFACE_LOST_KHR is returned.
1220  * If any of the presents would have a result of
1221    ename:VK_ERROR_OUT_OF_DATE_KHR if issued separately then
1222    ename:VK_ERROR_OUT_OF_DATE_KHR is returned.
1223  * If any of the presents would have a result of ename:VK_SUBOPTIMAL_KHR if
1224    issued separately then ename:VK_SUBOPTIMAL_KHR is returned.
1225  * Otherwise ename:VK_SUCCESS is returned.
1226
1227Presentation is a read-only operation that will not affect the content of
1228the presentable images.
1229Upon reacquiring the image and transitioning it away from the
1230ename:VK_IMAGE_LAYOUT_PRESENT_SRC_KHR layout, the contents will be the same
1231as they were prior to transitioning the image to the present source layout
1232and presenting it.
1233However, if a mechanism other than Vulkan is used to modify the platform
1234window associated with the swapchain, the content of all presentable images
1235in the swapchain becomes undefined.
1236
1237[NOTE]
1238.Note
1239====
1240The application can: continue to present any acquired images from a retired
1241swapchain as long as the swapchain has not entered a state that causes
1242flink:vkQueuePresentKHR to return ename:VK_ERROR_OUT_OF_DATE_KHR.
1243====
1244
1245ifdef::VK_EXT_hdr_metadata[]
1246include::../VK_EXT_hdr_metadata.txt[]
1247endif::VK_EXT_hdr_metadata[]
1248