1// Copyright 2014-2022 The Khronos Group Inc. 2// 3// SPDX-License-Identifier: CC-BY-4.0 4 5== WSI Swapchain 6 7[open,refpage='VkSwapchainKHR',desc='Opaque handle to a swapchain object',type='handles',xrefs='vkQueuePresentKHR'] 8-- 9A swapchain object (a.k.a. 10swapchain) provides the ability to present rendering results to a surface. 11Swapchain objects are represented by sname:VkSwapchainKHR handles: 12 13include::{generated}/api/handles/VkSwapchainKHR.adoc[] 14 15A swapchain is an abstraction for an array of presentable images that are 16associated with a surface. 17The presentable images are represented by sname:VkImage objects created by 18the platform. 19One image (which can: be an array image for multiview/stereoscopic-3D 20surfaces) is displayed at a time, but multiple images can: be queued for 21presentation. 22An application renders to the image, and then queues the image for 23presentation to the surface. 24 25A native window cannot: be associated with more than one non-retired 26swapchain at a time. 27Further, swapchains cannot: be created for native windows that have a 28non-Vulkan graphics API surface associated with them. 29 30[NOTE] 31.Note 32==== 33The presentation engine is an abstraction for the platform's compositor or 34display engine. 35 36The presentation engine may: be synchronous or asynchronous with respect to 37the application and/or logical device. 38 39Some implementations may: use the device's graphics queue or dedicated 40presentation hardware to perform presentation. 41==== 42 43The presentable images of a swapchain are owned by the presentation engine. 44An application can: acquire use of a presentable image from the presentation 45engine. 46Use of a presentable image must: occur only after the image is returned by 47flink:vkAcquireNextImageKHR, and before it is released by 48flink:vkQueuePresentKHR. 49This includes transitioning the image layout and rendering commands. 50 51An application can: acquire use of a presentable image with 52flink:vkAcquireNextImageKHR. 53After acquiring a presentable image and before modifying it, the application 54must: use a synchronization primitive to ensure that the presentation engine 55has finished reading from the image. 56The application can: then transition the image's layout, queue rendering 57commands to it, etc. 58Finally, the application presents the image with flink:vkQueuePresentKHR, 59which releases the acquisition of the image. 60ifdef::VK_EXT_swapchain_maintenance1[] 61The application can: also release the acquisition of the image through 62flink:vkReleaseSwapchainImagesEXT, if the image is not in use by the device, 63and skip the present operation. 64endif::VK_EXT_swapchain_maintenance1[] 65 66The presentation engine controls the order in which presentable images are 67acquired for use by the application. 68 69[NOTE] 70.Note 71==== 72This allows the platform to handle situations which require out-of-order 73return of images after presentation. 74At the same time, it allows the application to generate command buffers 75referencing all of the images in the swapchain at initialization time, 76rather than in its main loop. 77==== 78-- 79 80How this all works is described below. 81 82ifdef::VK_KHR_shared_presentable_image[] 83include::{chapters}/VK_KHR_shared_presentable_image/wsi.adoc[] 84endif::VK_KHR_shared_presentable_image[] 85 86[open,refpage='vkCreateSwapchainKHR',desc='Create a swapchain',type='protos'] 87-- 88To create a swapchain, call: 89 90include::{generated}/api/protos/vkCreateSwapchainKHR.adoc[] 91 92 * pname:device is the device to create the swapchain for. 93 * pname:pCreateInfo is a pointer to a slink:VkSwapchainCreateInfoKHR 94 structure specifying the parameters of the created swapchain. 95 * pname:pAllocator is the allocator used for host memory allocated for the 96 swapchain object when there is no more specific allocator available (see 97 <<memory-allocation,Memory Allocation>>). 98 * pname:pSwapchain is a pointer to a slink:VkSwapchainKHR handle in which 99 the created swapchain object will be returned. 100 101As mentioned above, if fname:vkCreateSwapchainKHR succeeds, it will return a 102handle to a swapchain containing an array of at least 103pname:pCreateInfo->minImageCount presentable images. 104 105While acquired by the application, presentable images can: be used in any 106way that equivalent non-presentable images can: be used. 107A presentable image is equivalent to a non-presentable image created with 108the following slink:VkImageCreateInfo parameters: 109 110[[swapchain-wsi-image-create-info]] 111[options="header"] 112|==== 113| sname:VkImageCreateInfo Field | Value 114ifndef::VK_VERSION_1_1,VK_KHR_device_group,VK_KHR_swapchain_mutable_format[] 115| pname:flags | 0 116endif::VK_VERSION_1_1,VK_KHR_device_group,VK_KHR_swapchain_mutable_format[] 117ifdef::VK_VERSION_1_1,VK_KHR_device_group,VK_KHR_swapchain_mutable_format[] 118| pname:flags | 119ifdef::VK_VERSION_1_1,VK_KHR_device_group[] 120ename:VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT is set if 121ename:VK_SWAPCHAIN_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT_KHR is set 122 123endif::VK_VERSION_1_1,VK_KHR_device_group[] 124ifdef::VK_VERSION_1_1[] 125ename:VK_IMAGE_CREATE_PROTECTED_BIT is set if 126ename:VK_SWAPCHAIN_CREATE_PROTECTED_BIT_KHR is set 127 128endif::VK_VERSION_1_1[] 129ifdef::VK_KHR_swapchain_mutable_format[] 130ename:VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT and 131ename:VK_IMAGE_CREATE_EXTENDED_USAGE_BIT_KHR are both set if 132ename:VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR is set 133 134endif::VK_KHR_swapchain_mutable_format[] 135all other bits are unset 136endif::VK_VERSION_1_1,VK_KHR_device_group,VK_KHR_swapchain_mutable_format[] 137| pname:imageType | ename:VK_IMAGE_TYPE_2D 138| pname:format | pname:pCreateInfo->imageFormat 139| pname:extent | {pname:pCreateInfo->imageExtent.width, pname:pCreateInfo->imageExtent.height, `1`} 140| pname:mipLevels | 1 141| pname:arrayLayers | pname:pCreateInfo->imageArrayLayers 142| pname:samples | ename:VK_SAMPLE_COUNT_1_BIT 143| pname:tiling | ename:VK_IMAGE_TILING_OPTIMAL 144| pname:usage | pname:pCreateInfo->imageUsage 145| pname:sharingMode | pname:pCreateInfo->imageSharingMode 146| pname:queueFamilyIndexCount | pname:pCreateInfo->queueFamilyIndexCount 147| pname:pQueueFamilyIndices | pname:pCreateInfo->pQueueFamilyIndices 148| pname:initialLayout | ename:VK_IMAGE_LAYOUT_UNDEFINED 149|==== 150 151The pname:pCreateInfo->surface must: not be destroyed until after the 152swapchain is destroyed. 153 154If pname:pCreateInfo->oldSwapchain is dlink:VK_NULL_HANDLE, and the native 155window referred to by pname:pCreateInfo->surface is already associated with 156a Vulkan swapchain, ename:VK_ERROR_NATIVE_WINDOW_IN_USE_KHR must: be 157returned. 158 159If the native window referred to by pname:pCreateInfo->surface is already 160associated with a non-Vulkan graphics API surface, 161ename:VK_ERROR_NATIVE_WINDOW_IN_USE_KHR must: be returned. 162 163The native window referred to by pname:pCreateInfo->surface must: not become 164associated with a non-Vulkan graphics API surface before all associated 165Vulkan swapchains have been destroyed. 166 167fname:vkCreateSwapchainKHR will return ename:VK_ERROR_DEVICE_LOST if the 168logical device was lost. 169The sname:VkSwapchainKHR is a child of the pname:device, and must: be 170destroyed before the pname:device. 171However, sname:VkSurfaceKHR is not a child of any sname:VkDevice and is not 172affected by the lost device. 173After successfully recreating a sname:VkDevice, the same sname:VkSurfaceKHR 174can: be used to create a new sname:VkSwapchainKHR, provided the previous one 175was destroyed. 176 177ifdef::VK_EXT_full_screen_exclusive[] 178If the pname:oldSwapchain parameter of pname:pCreateInfo is a valid 179swapchain, which has exclusive full-screen access, that access is released 180from pname:pCreateInfo->oldSwapchain. 181If the command succeeds in this case, the newly created swapchain will 182automatically acquire exclusive full-screen access from 183pname:pCreateInfo->oldSwapchain. 184 185[NOTE] 186.Note 187==== 188This implicit transfer is intended to avoid exiting and entering full-screen 189exclusive mode, which may otherwise cause unwanted visual updates to the 190display. 191==== 192 193In some cases, swapchain creation may: fail if exclusive full-screen mode is 194requested for application control, but for some implementation-specific 195reason exclusive full-screen access is unavailable for the particular 196combination of parameters provided. 197If this occurs, ename:VK_ERROR_INITIALIZATION_FAILED will be returned. 198 199[NOTE] 200.Note 201==== 202In particular, it will fail if the pname:imageExtent member of 203pname:pCreateInfo does not match the extents of the monitor. 204ifdef::VK_KHR_win32_surface[] 205Other reasons for failure may include the app not being set as high-dpi 206aware, or if the physical device and monitor are not compatible in this 207mode. 208endif::VK_KHR_win32_surface[] 209==== 210 211endif::VK_EXT_full_screen_exclusive[] 212 213ifdef::VK_NV_present_barrier[] 214If the pname:pNext chain of slink:VkSwapchainCreateInfoKHR includes a 215slink:VkSwapchainPresentBarrierCreateInfoNV structure, then that structure 216includes additional swapchain creation parameters specific to the present 217barrier. 218Swapchain creation may: fail if the state of the current system restricts 219the usage of the present barrier feature 220slink:VkSurfaceCapabilitiesPresentBarrierNV, or a swapchain itself does not 221satisfy all the required conditions. 222In this scenario ename:VK_ERROR_INITIALIZATION_FAILED is returned. 223endif::VK_NV_present_barrier[] 224 225ifdef::VK_NV_acquire_winrt_display[] 226When the slink:VkSurfaceKHR in slink:VkSwapchainCreateInfoKHR is a display 227surface, then the slink:VkDisplayModeKHR in display surface's 228slink:VkDisplaySurfaceCreateInfoKHR is associated with a particular 229slink:VkDisplayKHR. 230Swapchain creation may: fail if that slink:VkDisplayKHR is not acquired by 231the application. 232In this scenario ename:VK_ERROR_INITIALIZATION_FAILED is returned. 233endif::VK_NV_acquire_winrt_display[] 234 235include::{generated}/validity/protos/vkCreateSwapchainKHR.adoc[] 236-- 237 238[open,refpage='VkSwapchainCreateInfoKHR',desc='Structure specifying parameters of a newly created swapchain object',type='structs'] 239-- 240The sname:VkSwapchainCreateInfoKHR structure is defined as: 241 242include::{generated}/api/structs/VkSwapchainCreateInfoKHR.adoc[] 243 244 * pname:sType is the type of this structure. 245 * pname:pNext is `NULL` or a pointer to a structure extending this 246 structure. 247 * pname:flags is a bitmask of elink:VkSwapchainCreateFlagBitsKHR 248 indicating parameters of the swapchain creation. 249 * pname:surface is the surface onto which the swapchain will present 250 images. 251 If the creation succeeds, the swapchain becomes associated with 252 pname:surface. 253 * pname:minImageCount is the minimum number of presentable images that the 254 application needs. 255 The implementation will either create the swapchain with at least that 256 many images, or it will fail to create the swapchain. 257 * pname:imageFormat is a elink:VkFormat value specifying the format the 258 swapchain image(s) will be created with. 259 * pname:imageColorSpace is a elink:VkColorSpaceKHR value specifying the 260 way the swapchain interprets image data. 261 * pname:imageExtent is the size (in pixels) of the swapchain image(s). 262 The behavior is platform-dependent if the image extent does not match 263 the surface's pname:currentExtent as returned by 264 fname:vkGetPhysicalDeviceSurfaceCapabilitiesKHR. 265+ 266[NOTE] 267.Note 268==== 269On some platforms, it is normal that pname:maxImageExtent may: become `(0, 2700)`, for example when the window is minimized. 271In such a case, it is not possible to create a swapchain due to the Valid 272Usage requirements 273ifdef::VK_EXT_swapchain_maintenance1[] 274, unless scaling is selected through 275slink:VkSwapchainPresentScalingCreateInfoEXT, if supported 276endif::VK_EXT_swapchain_maintenance1[] 277. 278==== 279 * pname:imageArrayLayers is the number of views in a multiview/stereo 280 surface. 281 For non-stereoscopic-3D applications, this value is 1. 282 * pname:imageUsage is a bitmask of elink:VkImageUsageFlagBits describing 283 the intended usage of the (acquired) swapchain images. 284 * pname:imageSharingMode is the sharing mode used for the image(s) of the 285 swapchain. 286 * pname:queueFamilyIndexCount is the number of queue families having 287 access to the image(s) of the swapchain when pname:imageSharingMode is 288 ename:VK_SHARING_MODE_CONCURRENT. 289 * pname:pQueueFamilyIndices is a pointer to an array of queue family 290 indices having access to the images(s) of the swapchain when 291 pname:imageSharingMode is ename:VK_SHARING_MODE_CONCURRENT. 292 * pname:preTransform is a elink:VkSurfaceTransformFlagBitsKHR value 293 describing the transform, relative to the presentation engine's natural 294 orientation, applied to the image content prior to presentation. 295 If it does not match the pname:currentTransform value returned by 296 fname:vkGetPhysicalDeviceSurfaceCapabilitiesKHR, the presentation engine 297 will transform the image content as part of the presentation operation. 298 * pname:compositeAlpha is a elink:VkCompositeAlphaFlagBitsKHR value 299 indicating the alpha compositing mode to use when this surface is 300 composited together with other surfaces on certain window systems. 301 * pname:presentMode is the presentation mode the swapchain will use. 302 A swapchain's present mode determines how incoming present requests will 303 be processed and queued internally. 304 * pname:clipped specifies whether the Vulkan implementation is allowed to 305 discard rendering operations that affect regions of the surface that are 306 not visible. 307 ** If set to ename:VK_TRUE, the presentable images associated with the 308 swapchain may: not own all of their pixels. 309 Pixels in the presentable images that correspond to regions of the 310 target surface obscured by another window on the desktop, or subject to 311 some other clipping mechanism will have undefined: content when read 312 back. 313 Fragment shaders may: not execute for these pixels, and thus any side 314 effects they would have had will not occur. 315 Setting ename:VK_TRUE does not guarantee any clipping will occur, but 316 allows more efficient presentation methods to be used on some 317 platforms. 318 ** If set to ename:VK_FALSE, presentable images associated with the 319 swapchain will own all of the pixels they contain. 320+ 321[NOTE] 322.Note 323==== 324Applications should: set this value to ename:VK_TRUE if they do not expect 325to read back the content of presentable images before presenting them or 326after reacquiring them, and if their fragment shaders do not have any side 327effects that require them to run for all pixels in the presentable image. 328==== 329 * pname:oldSwapchain is dlink:VK_NULL_HANDLE, or the existing non-retired 330 swapchain currently associated with pname:surface. 331 Providing a valid pname:oldSwapchain may: aid in the resource reuse, and 332 also allows the application to still present any images that are already 333 acquired from it. 334 335Upon calling fname:vkCreateSwapchainKHR with an pname:oldSwapchain that is 336not dlink:VK_NULL_HANDLE, pname:oldSwapchain is retired -- even if creation 337of the new swapchain fails. 338The new swapchain is created in the non-retired state whether or not 339pname:oldSwapchain is dlink:VK_NULL_HANDLE. 340 341Upon calling fname:vkCreateSwapchainKHR with an pname:oldSwapchain that is 342not dlink:VK_NULL_HANDLE, any images from pname:oldSwapchain that are not 343acquired by the application may: be freed by the implementation, which may: 344occur even if creation of the new swapchain fails. 345The application can: destroy pname:oldSwapchain to free all memory 346associated with pname:oldSwapchain. 347 348[NOTE] 349.Note 350==== 351Multiple retired swapchains can: be associated with the same 352sname:VkSurfaceKHR through multiple uses of pname:oldSwapchain that 353outnumber calls to flink:vkDestroySwapchainKHR. 354 355After pname:oldSwapchain is retired, the application can: pass to 356flink:vkQueuePresentKHR any images it had already acquired from 357pname:oldSwapchain. 358E.g., an application may present an image from the old swapchain before an 359image from the new swapchain is ready to be presented. 360As usual, flink:vkQueuePresentKHR may: fail if pname:oldSwapchain has 361entered a state that causes ename:VK_ERROR_OUT_OF_DATE_KHR to be returned. 362 363ifdef::VK_KHR_shared_presentable_image[] 364The application can: continue to use a shared presentable image obtained 365from pname:oldSwapchain until a presentable image is acquired from the new 366swapchain, as long as it has not entered a state that causes it to return 367ename:VK_ERROR_OUT_OF_DATE_KHR. 368endif::VK_KHR_shared_presentable_image[] 369==== 370 371.Valid Usage 372**** 373 * [[VUID-VkSwapchainCreateInfoKHR-surface-01270]] 374 pname:surface must: be a surface that is supported by the device as 375 determined using flink:vkGetPhysicalDeviceSurfaceSupportKHR 376ifndef::VK_KHR_shared_presentable_image[] 377 * [[VUID-VkSwapchainCreateInfoKHR-minImageCount-01271]] 378 pname:minImageCount must: be greater than or equal to the value returned 379 in the pname:minImageCount member of the sname:VkSurfaceCapabilitiesKHR 380 structure returned by flink:vkGetPhysicalDeviceSurfaceCapabilitiesKHR 381 for the surface 382endif::VK_KHR_shared_presentable_image[] 383 * [[VUID-VkSwapchainCreateInfoKHR-minImageCount-01272]] 384 pname:minImageCount must: be less than or equal to the value returned in 385 the pname:maxImageCount member of the sname:VkSurfaceCapabilitiesKHR 386 structure returned by fname:vkGetPhysicalDeviceSurfaceCapabilitiesKHR 387 for the surface if the returned pname:maxImageCount is not zero 388ifdef::VK_KHR_shared_presentable_image[] 389 * [[VUID-VkSwapchainCreateInfoKHR-presentMode-02839]] 390 If pname:presentMode is not 391 ename:VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR nor 392 ename:VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR, then 393 pname:minImageCount must: be greater than or equal to the value returned 394 in the pname:minImageCount member of the sname:VkSurfaceCapabilitiesKHR 395 structure returned by flink:vkGetPhysicalDeviceSurfaceCapabilitiesKHR 396 for the surface 397 * [[VUID-VkSwapchainCreateInfoKHR-minImageCount-01383]] 398 pname:minImageCount must: be `1` if pname:presentMode is either 399 ename:VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR or 400 ename:VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR 401endif::VK_KHR_shared_presentable_image[] 402 * [[VUID-VkSwapchainCreateInfoKHR-imageFormat-01273]] 403 pname:imageFormat and pname:imageColorSpace must: match the pname:format 404 and pname:colorSpace members, respectively, of one of the 405 sname:VkSurfaceFormatKHR structures returned by 406 fname:vkGetPhysicalDeviceSurfaceFormatsKHR for the surface 407ifndef::VK_EXT_swapchain_maintenance1[] 408 * [[VUID-VkSwapchainCreateInfoKHR-imageExtent-01274]] 409 pname:imageExtent must: be between pname:minImageExtent and 410 pname:maxImageExtent, inclusive, where pname:minImageExtent and 411 pname:maxImageExtent are members of the sname:VkSurfaceCapabilitiesKHR 412 structure returned by fname:vkGetPhysicalDeviceSurfaceCapabilitiesKHR 413 for the surface 414endif::VK_EXT_swapchain_maintenance1[] 415ifdef::VK_EXT_swapchain_maintenance1[] 416 * [[VUID-VkSwapchainCreateInfoKHR-pNext-07781]] 417 If a slink:VkSwapchainPresentScalingCreateInfoEXT structure was not 418 included in the pname:pNext chain, or it is included and 419 slink:VkSwapchainPresentScalingCreateInfoEXT::pname:scalingBehavior is 420 zero then pname:imageExtent must: be between pname:minImageExtent and 421 pname:maxImageExtent, inclusive, where pname:minImageExtent and 422 pname:maxImageExtent are members of the sname:VkSurfaceCapabilitiesKHR 423 structure returned by fname:vkGetPhysicalDeviceSurfaceCapabilitiesKHR 424 for the surface 425 * [[VUID-VkSwapchainCreateInfoKHR-pNext-07782]] 426 If a slink:VkSwapchainPresentScalingCreateInfoEXT structure was included 427 in the pname:pNext chain and 428 slink:VkSwapchainPresentScalingCreateInfoEXT::pname:scalingBehavior is 429 not zero then pname:imageExtent must: be between 430 pname:minScaledImageExtent and pname:maxScaledImageExtent, inclusive, 431 where pname:minScaledImageExtent and pname:maxScaledImageExtent are 432 members of the sname:VkSurfacePresentScalingCapabilitiesEXT structure 433 returned by fname:vkGetPhysicalDeviceSurfaceCapabilities2KHR for the 434 surface and pname:presentMode 435endif::VK_EXT_swapchain_maintenance1[] 436 * [[VUID-VkSwapchainCreateInfoKHR-imageExtent-01689]] 437 pname:imageExtent members pname:width and pname:height must: both be 438 non-zero 439 * [[VUID-VkSwapchainCreateInfoKHR-imageArrayLayers-01275]] 440 pname:imageArrayLayers must: be greater than `0` and less than or equal 441 to the pname:maxImageArrayLayers member of the 442 sname:VkSurfaceCapabilitiesKHR structure returned by 443 fname:vkGetPhysicalDeviceSurfaceCapabilitiesKHR for the surface 444 * [[VUID-VkSwapchainCreateInfoKHR-presentMode-01427]] 445 If pname:presentMode is ename:VK_PRESENT_MODE_IMMEDIATE_KHR, 446 ename:VK_PRESENT_MODE_MAILBOX_KHR, ename:VK_PRESENT_MODE_FIFO_KHR or 447 ename:VK_PRESENT_MODE_FIFO_RELAXED_KHR, pname:imageUsage must: be a 448 subset of the supported usage flags present in the 449 pname:supportedUsageFlags member of the slink:VkSurfaceCapabilitiesKHR 450 structure returned by flink:vkGetPhysicalDeviceSurfaceCapabilitiesKHR 451 for pname:surface 452ifdef::VK_KHR_shared_presentable_image[] 453 * [[VUID-VkSwapchainCreateInfoKHR-imageUsage-01384]] 454 If pname:presentMode is ename:VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR 455 or ename:VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR, pname:imageUsage 456 must: be a subset of the supported usage flags present in the 457 pname:sharedPresentSupportedUsageFlags member of the 458 slink:VkSharedPresentSurfaceCapabilitiesKHR structure returned by 459 flink:vkGetPhysicalDeviceSurfaceCapabilities2KHR for pname:surface 460endif::VK_KHR_shared_presentable_image[] 461 * [[VUID-VkSwapchainCreateInfoKHR-imageSharingMode-01277]] 462 If pname:imageSharingMode is ename:VK_SHARING_MODE_CONCURRENT, 463 pname:pQueueFamilyIndices must: be a valid pointer to an array of 464 pname:queueFamilyIndexCount code:uint32_t values 465 * [[VUID-VkSwapchainCreateInfoKHR-imageSharingMode-01278]] 466 If pname:imageSharingMode is ename:VK_SHARING_MODE_CONCURRENT, 467 pname:queueFamilyIndexCount must: be greater than `1` 468ifndef::VK_VERSION_1_1,VK_KHR_get_physical_device_properties2[] 469 * [[VUID-VkSwapchainCreateInfoKHR-imageSharingMode-01393]] 470 If pname:imageSharingMode is ename:VK_SHARING_MODE_CONCURRENT, each 471 element of pname:pQueueFamilyIndices must: be unique and must: be less 472 than pname:pQueueFamilyPropertyCount returned by 473 flink:vkGetPhysicalDeviceQueueFamilyProperties for the 474 pname:physicalDevice that was used to create pname:device 475endif::VK_VERSION_1_1,VK_KHR_get_physical_device_properties2[] 476ifdef::VK_VERSION_1_1,VK_KHR_get_physical_device_properties2[] 477 * [[VUID-VkSwapchainCreateInfoKHR-imageSharingMode-01428]] 478 If pname:imageSharingMode is ename:VK_SHARING_MODE_CONCURRENT, each 479 element of pname:pQueueFamilyIndices must: be unique and must: be less 480 than pname:pQueueFamilyPropertyCount returned by either 481 flink:vkGetPhysicalDeviceQueueFamilyProperties or 482 flink:vkGetPhysicalDeviceQueueFamilyProperties2 for the 483 pname:physicalDevice that was used to create pname:device 484endif::VK_VERSION_1_1,VK_KHR_get_physical_device_properties2[] 485 * [[VUID-VkSwapchainCreateInfoKHR-preTransform-01279]] 486 pname:preTransform must: be one of the bits present in the 487 pname:supportedTransforms member of the sname:VkSurfaceCapabilitiesKHR 488 structure returned by fname:vkGetPhysicalDeviceSurfaceCapabilitiesKHR 489 for the surface 490 * [[VUID-VkSwapchainCreateInfoKHR-compositeAlpha-01280]] 491 pname:compositeAlpha must: be one of the bits present in the 492 pname:supportedCompositeAlpha member of the 493 sname:VkSurfaceCapabilitiesKHR structure returned by 494 fname:vkGetPhysicalDeviceSurfaceCapabilitiesKHR for the surface 495 * [[VUID-VkSwapchainCreateInfoKHR-presentMode-01281]] 496 pname:presentMode must: be one of the elink:VkPresentModeKHR values 497 returned by fname:vkGetPhysicalDeviceSurfacePresentModesKHR for the 498 surface 499ifdef::VK_VERSION_1_1,VK_KHR_device_group[] 500 * [[VUID-VkSwapchainCreateInfoKHR-physicalDeviceCount-01429]] 501 If the logical device was created with 502 slink:VkDeviceGroupDeviceCreateInfo::pname:physicalDeviceCount equal to 503 1, pname:flags must: not contain 504 ename:VK_SWAPCHAIN_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT_KHR 505endif::VK_VERSION_1_1,VK_KHR_device_group[] 506 * [[VUID-VkSwapchainCreateInfoKHR-oldSwapchain-01933]] 507 If pname:oldSwapchain is not dlink:VK_NULL_HANDLE, pname:oldSwapchain 508 must: be a non-retired swapchain associated with native window referred 509 to by pname:surface 510 * [[VUID-VkSwapchainCreateInfoKHR-imageFormat-01778]] 511 The <<swapchain-wsi-image-create-info, implied image creation 512 parameters>> of the swapchain must: be supported as reported by 513 flink:vkGetPhysicalDeviceImageFormatProperties 514ifdef::VK_KHR_swapchain_mutable_format[] 515 * [[VUID-VkSwapchainCreateInfoKHR-flags-03168]] 516 If pname:flags contains ename:VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR 517 then the pname:pNext chain must: include a 518 slink:VkImageFormatListCreateInfo structure with a pname:viewFormatCount 519 greater than zero and pname:pViewFormats must: have an element equal to 520 pname:imageFormat 521 * [[VUID-VkSwapchainCreateInfoKHR-pNext-04099]] 522 If a slink:VkImageFormatListCreateInfo structure was included in the 523 pname:pNext chain and 524 slink:VkImageFormatListCreateInfo::pname:viewFormatCount is not zero 525 then all of the formats in 526 slink:VkImageFormatListCreateInfo::pname:pViewFormats must: be 527 compatible with the pname:format as described in the 528 <<formats-compatibility,compatibility table>> 529 * [[VUID-VkSwapchainCreateInfoKHR-flags-04100]] 530 If pname:flags does not contain 531 ename:VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR and the pname:pNext 532 chain include a slink:VkImageFormatListCreateInfo structure then 533 slink:VkImageFormatListCreateInfo::pname:viewFormatCount must: be `0` or 534 `1` 535endif::VK_KHR_swapchain_mutable_format[] 536ifdef::VK_KHR_surface_protected_capabilities[] 537 * [[VUID-VkSwapchainCreateInfoKHR-flags-03187]] 538 If pname:flags contains ename:VK_SWAPCHAIN_CREATE_PROTECTED_BIT_KHR, 539 then sname:VkSurfaceProtectedCapabilitiesKHR::pname:supportsProtected 540 must: be ename:VK_TRUE in the slink:VkSurfaceProtectedCapabilitiesKHR 541 structure returned by flink:vkGetPhysicalDeviceSurfaceCapabilities2KHR 542 for pname:surface 543endif::VK_KHR_surface_protected_capabilities[] 544ifdef::VK_EXT_full_screen_exclusive+VK_KHR_win32_surface[] 545 * [[VUID-VkSwapchainCreateInfoKHR-pNext-02679]] 546 If the pname:pNext chain includes a 547 slink:VkSurfaceFullScreenExclusiveInfoEXT structure with its 548 pname:fullScreenExclusive member set to 549 ename:VK_FULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT, and 550 pname:surface was created using flink:vkCreateWin32SurfaceKHR, a 551 slink:VkSurfaceFullScreenExclusiveWin32InfoEXT structure must: be 552 included in the pname:pNext chain 553endif::VK_EXT_full_screen_exclusive+VK_KHR_win32_surface[] 554ifdef::VK_EXT_image_compression_control[] 555ifndef::VK_EXT_image_compression_control_swapchain[] 556 * [[VUID-VkSwapchainCreateInfoKHR-pNext-06751]] 557 The pname:pNext chain must: not include an 558 slink:VkImageCompressionControlEXT structure 559endif::VK_EXT_image_compression_control_swapchain[] 560ifdef::VK_EXT_image_compression_control_swapchain[] 561 * [[VUID-VkSwapchainCreateInfoKHR-pNext-06752]] 562 If the <<features-imageCompressionControlSwapchain, 563 pname:imageCompressionControlSwapchain>> feature is not enabled, the 564 pname:pNext chain must: not include an 565 slink:VkImageCompressionControlEXT structure 566endif::VK_EXT_image_compression_control_swapchain[] 567endif::VK_EXT_image_compression_control[] 568**** 569 570include::{generated}/validity/structs/VkSwapchainCreateInfoKHR.adoc[] 571-- 572 573[open,refpage='VkSwapchainCreateFlagBitsKHR',desc='Bitmask controlling swapchain creation',type='enums'] 574-- 575Bits which can: be set in slink:VkSwapchainCreateInfoKHR::pname:flags, 576specifying parameters of swapchain creation, are: 577 578include::{generated}/api/enums/VkSwapchainCreateFlagBitsKHR.adoc[] 579 580ifdef::VK_VERSION_1_1,VK_KHR_device_group[] 581 * ename:VK_SWAPCHAIN_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT_KHR specifies 582 that images created from the swapchain (i.e. with the pname:swapchain 583 member of slink:VkImageSwapchainCreateInfoKHR set to this swapchain's 584 handle) must: use ename:VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT. 585endif::VK_VERSION_1_1,VK_KHR_device_group[] 586ifdef::VK_VERSION_1_1[] 587 * ename:VK_SWAPCHAIN_CREATE_PROTECTED_BIT_KHR specifies that images 588 created from the swapchain are protected images. 589endif::VK_VERSION_1_1[] 590ifdef::VK_KHR_swapchain_mutable_format[] 591 * ename:VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR specifies that the 592 images of the swapchain can: be used to create a sname:VkImageView with 593 a different format than what the swapchain was created with. 594 The list of allowed image view formats is specified by adding a 595 slink:VkImageFormatListCreateInfo structure to the pname:pNext chain of 596 slink:VkSwapchainCreateInfoKHR. 597 In addition, this flag also specifies that the swapchain can: be created 598 with usage flags that are not supported for the format the swapchain is 599 created with but are supported for at least one of the allowed image 600 view formats. 601endif::VK_KHR_swapchain_mutable_format[] 602ifdef::VK_EXT_swapchain_maintenance1[] 603 * ename:VK_SWAPCHAIN_CREATE_DEFERRED_MEMORY_ALLOCATION_BIT_EXT specifies 604 that the implementation may: defer allocation of memory associated with 605 each swapchain image until its index is to be returned from 606 flink:vkAcquireNextImageKHR 607ifdef::VK_VERSION_1_1,VK_KHR_device_group[or flink:vkAcquireNextImage2KHR] 608 for the first time. 609endif::VK_EXT_swapchain_maintenance1[] 610-- 611 612[open,refpage='VkSwapchainCreateFlagsKHR',desc='Bitmask of VkSwapchainCreateFlagBitsKHR',type='flags'] 613-- 614include::{generated}/api/flags/VkSwapchainCreateFlagsKHR.adoc[] 615 616tname:VkSwapchainCreateFlagsKHR is a bitmask type for setting a mask of zero 617or more elink:VkSwapchainCreateFlagBitsKHR. 618-- 619 620ifdef::VK_VERSION_1_1,VK_KHR_device_group[] 621[open,refpage='VkDeviceGroupSwapchainCreateInfoKHR',desc='Structure specifying parameters of a newly created swapchain object',type='structs'] 622-- 623If the pname:pNext chain of slink:VkSwapchainCreateInfoKHR includes a 624sname:VkDeviceGroupSwapchainCreateInfoKHR structure, then that structure 625includes a set of device group present modes that the swapchain can: be used 626with. 627 628The sname:VkDeviceGroupSwapchainCreateInfoKHR structure is defined as: 629 630include::{generated}/api/structs/VkDeviceGroupSwapchainCreateInfoKHR.adoc[] 631 632 * pname:sType is the type of this structure. 633 * pname:pNext is `NULL` or a pointer to a structure extending this 634 structure. 635 * pname:modes is a bitfield of modes that the swapchain can: be used with. 636 637If this structure is not present, pname:modes is considered to be 638ename:VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR. 639 640include::{generated}/validity/structs/VkDeviceGroupSwapchainCreateInfoKHR.adoc[] 641-- 642endif::VK_VERSION_1_1,VK_KHR_device_group[] 643 644ifdef::VK_AMD_display_native_hdr[] 645[open,refpage='VkSwapchainDisplayNativeHdrCreateInfoAMD',desc='Structure specifying display native HDR parameters of a newly created swapchain object',type='structs'] 646-- 647If the pname:pNext chain of slink:VkSwapchainCreateInfoKHR includes a 648sname:VkSwapchainDisplayNativeHdrCreateInfoAMD structure, then that 649structure includes additional swapchain creation parameters specific to 650display native HDR support. 651 652The sname:VkSwapchainDisplayNativeHdrCreateInfoAMD structure is defined as: 653 654include::{generated}/api/structs/VkSwapchainDisplayNativeHdrCreateInfoAMD.adoc[] 655 656 * pname:sType is the type of this structure. 657 * pname:pNext is `NULL` or a pointer to a structure extending this 658 structure. 659 * pname:localDimmingEnable specifies whether local dimming is enabled for 660 the swapchain. 661 662If the pname:pNext chain of slink:VkSwapchainCreateInfoKHR does not include 663this structure, the default value for pname:localDimmingEnable is 664ename:VK_TRUE, meaning local dimming is initially enabled for the swapchain. 665 666include::{generated}/validity/structs/VkSwapchainDisplayNativeHdrCreateInfoAMD.adoc[] 667 668.Valid Usage 669**** 670 * [[VUID-VkSwapchainDisplayNativeHdrCreateInfoAMD-localDimmingEnable-04449]] 671 It is only valid to set pname:localDimmingEnable to ename:VK_TRUE if 672 slink:VkDisplayNativeHdrSurfaceCapabilitiesAMD::pname:localDimmingSupport 673 is supported 674**** 675-- 676 677[open,refpage='vkSetLocalDimmingAMD',desc='Set Local Dimming',type='protos'] 678-- 679The local dimming HDR setting may also be changed over the life of a 680swapchain by calling: 681 682include::{generated}/api/protos/vkSetLocalDimmingAMD.adoc[] 683 684 * pname:device is the device associated with pname:swapChain. 685 * pname:swapChain handle to enable local dimming. 686 * pname:localDimmingEnable specifies whether local dimming is enabled for 687 the swapchain. 688 689include::{generated}/validity/protos/vkSetLocalDimmingAMD.adoc[] 690 691.Valid Usage 692**** 693 * [[VUID-vkSetLocalDimmingAMD-localDimmingSupport-04618]] 694 slink:VkDisplayNativeHdrSurfaceCapabilitiesAMD::pname:localDimmingSupport 695 must: be supported 696**** 697-- 698endif::VK_AMD_display_native_hdr[] 699 700ifdef::VK_EXT_full_screen_exclusive[] 701If the pname:pNext chain of slink:VkSwapchainCreateInfoKHR includes a 702slink:VkSurfaceFullScreenExclusiveInfoEXT structure, then that structure 703specifies the application's preferred full-screen presentation behavior. 704If this structure is not present, pname:fullScreenExclusive is considered to 705be ename:VK_FULL_SCREEN_EXCLUSIVE_DEFAULT_EXT. 706endif::VK_EXT_full_screen_exclusive[] 707 708ifdef::VK_EXT_display_control[] 709include::{chapters}/VK_EXT_display_control/swapchain_counters.adoc[] 710endif::VK_EXT_display_control[] 711 712ifdef::VK_EXT_image_compression_control[] 713ifdef::VK_EXT_image_compression_control_swapchain[] 714To specify compression properties for the swapchain images in this 715swapchain, add a slink:VkImageCompressionControlEXT structure to the 716pname:pNext chain of the slink:VkSwapchainCreateInfoKHR structure. 717endif::VK_EXT_image_compression_control_swapchain[] 718endif::VK_EXT_image_compression_control[] 719 720ifdef::VK_EXT_swapchain_maintenance1[] 721include::{chapters}/VK_EXT_swapchain_maintenance1/SwapchainPresentModesCreateInfo.adoc[] 722include::{chapters}/VK_EXT_swapchain_maintenance1/SwapchainPresentScalingCreateInfo.adoc[] 723endif::VK_EXT_swapchain_maintenance1[] 724 725[open,refpage='vkDestroySwapchainKHR',desc='Destroy a swapchain object',type='protos'] 726-- 727To destroy a swapchain object call: 728 729include::{generated}/api/protos/vkDestroySwapchainKHR.adoc[] 730 731 * pname:device is the slink:VkDevice associated with pname:swapchain. 732 * pname:swapchain is the swapchain to destroy. 733 * pname:pAllocator is the allocator used for host memory allocated for the 734 swapchain object when there is no more specific allocator available (see 735 <<memory-allocation,Memory Allocation>>). 736 737The application must: not destroy a swapchain until after completion of all 738outstanding operations on images that were acquired from the swapchain. 739pname:swapchain and all associated sname:VkImage handles are destroyed, and 740must: not be acquired or used any more by the application. 741The memory of each sname:VkImage will only be freed after that image is no 742longer used by the presentation engine. 743For example, if one image of the swapchain is being displayed in a window, 744the memory for that image may: not be freed until the window is destroyed, 745or another swapchain is created for the window. 746Destroying the swapchain does not invalidate the parent sname:VkSurfaceKHR, 747and a new swapchain can: be created with it. 748 749ifdef::VK_KHR_display_swapchain[] 750include::{chapters}/VK_KHR_display_swapchain/destroy_swapchain_interactions.adoc[] 751endif::VK_KHR_display_swapchain[] 752 753ifdef::VK_EXT_full_screen_exclusive[] 754If pname:swapchain has exclusive full-screen access, it is released before 755the swapchain is destroyed. 756endif::VK_EXT_full_screen_exclusive[] 757 758.Valid Usage 759**** 760 * [[VUID-vkDestroySwapchainKHR-swapchain-01282]] 761 All uses of presentable images acquired from pname:swapchain must: have 762 completed execution 763 * [[VUID-vkDestroySwapchainKHR-swapchain-01283]] 764 If sname:VkAllocationCallbacks were provided when pname:swapchain was 765 created, a compatible set of callbacks must: be provided here 766 * [[VUID-vkDestroySwapchainKHR-swapchain-01284]] 767 If no sname:VkAllocationCallbacks were provided when pname:swapchain was 768 created, pname:pAllocator must: be `NULL` 769**** 770 771include::{generated}/validity/protos/vkDestroySwapchainKHR.adoc[] 772-- 773 774ifdef::VK_KHR_display_swapchain[] 775include::{chapters}/VK_KHR_display_swapchain/create_shared_swapchains.adoc[] 776endif::VK_KHR_display_swapchain[] 777 778[open,refpage='vkGetSwapchainImagesKHR',desc='Obtain the array of presentable images associated with a swapchain',type='protos'] 779-- 780To obtain the array of presentable images associated with a swapchain, call: 781 782include::{generated}/api/protos/vkGetSwapchainImagesKHR.adoc[] 783 784 * pname:device is the device associated with pname:swapchain. 785 * pname:swapchain is the swapchain to query. 786 * pname:pSwapchainImageCount is a pointer to an integer related to the 787 number of presentable images available or queried, as described below. 788 * pname:pSwapchainImages is either `NULL` or a pointer to an array of 789 sname:VkImage handles. 790 791If pname:pSwapchainImages is `NULL`, then the number of presentable images 792for pname:swapchain is returned in pname:pSwapchainImageCount. 793Otherwise, pname:pSwapchainImageCount must: point to a variable set by the 794user to the number of elements in the pname:pSwapchainImages array, and on 795return the variable is overwritten with the number of structures actually 796written to pname:pSwapchainImages. 797If the value of pname:pSwapchainImageCount is less than the number of 798presentable images for pname:swapchain, at most pname:pSwapchainImageCount 799structures will be written, and ename:VK_INCOMPLETE will be returned instead 800of ename:VK_SUCCESS, to indicate that not all the available presentable 801images were returned. 802 803include::{generated}/validity/protos/vkGetSwapchainImagesKHR.adoc[] 804-- 805 806[NOTE] 807.Note 808==== 809By knowing all presentable images used in the swapchain, the application can 810create command buffers that reference these images prior to entering its 811main rendering loop. 812ifdef::VK_EXT_swapchain_maintenance1[] 813However, command buffers are not allowed to reference presentable images 814created with ename:VK_SWAPCHAIN_CREATE_DEFERRED_MEMORY_ALLOCATION_BIT_EXT 815until their indices have been returned from flink:vkAcquireNextImageKHR at 816least once. 817endif::VK_EXT_swapchain_maintenance1[] 818==== 819 820Images returned by flink:vkGetSwapchainImagesKHR are fully backed by memory 821before they are passed to the application, as if they are each bound 822completely and contiguously to a single sname:VkDeviceMemory object 823ifdef::VK_EXT_swapchain_maintenance1[] 824, unless the swapchain is created with the 825ename:VK_SWAPCHAIN_CREATE_DEFERRED_MEMORY_ALLOCATION_BIT_EXT flag 826endif::VK_EXT_swapchain_maintenance1[] 827. 828All presentable images are initially in the ename:VK_IMAGE_LAYOUT_UNDEFINED 829layout, thus before using presentable images, the application must: 830transition them to a valid layout for the intended use. 831 832Further, the lifetime of presentable images is controlled by the 833implementation, so applications must: not destroy a presentable image. 834See flink:vkDestroySwapchainKHR for further details on the lifetime of 835presentable images. 836 837ifdef::VK_VERSION_1_1,VK_KHR_device_group[] 838 839Images can: also be created by using flink:vkCreateImage with 840slink:VkImageSwapchainCreateInfoKHR and bound to swapchain memory using 841flink:vkBindImageMemory2 with slink:VkBindImageMemorySwapchainInfoKHR. 842These images can: be used anywhere swapchain images are used, and are useful 843in logical devices with multiple physical devices to create peer memory 844bindings of swapchain memory. 845These images and bindings have no effect on what memory is presented. 846Unlike images retrieved from fname:vkGetSwapchainImagesKHR, these images 847must: be destroyed with flink:vkDestroyImage. 848 849endif::VK_VERSION_1_1,VK_KHR_device_group[] 850 851[open,refpage='vkAcquireNextImageKHR',desc='Retrieve the index of the next available presentable image',type='protos'] 852-- 853To acquire an available presentable image to use, and retrieve the index of 854that image, call: 855 856include::{generated}/api/protos/vkAcquireNextImageKHR.adoc[] 857 858 * pname:device is the device associated with pname:swapchain. 859 * pname:swapchain is the non-retired swapchain from which an image is 860 being acquired. 861 * pname:timeout specifies how long the function waits, in nanoseconds, if 862 no image is available. 863 * pname:semaphore is dlink:VK_NULL_HANDLE or a semaphore to signal. 864 * pname:fence is dlink:VK_NULL_HANDLE or a fence to signal. 865 * pname:pImageIndex is a pointer to a code:uint32_t in which the index of 866 the next image to use (i.e. an index into the array of images returned 867 by fname:vkGetSwapchainImagesKHR) is returned. 868 869ifdef::VK_EXT_swapchain_maintenance1[] 870If the pname:swapchain has been created with the 871ename:VK_SWAPCHAIN_CREATE_DEFERRED_MEMORY_ALLOCATION_BIT_EXT flag, the image 872whose index is returned in pname:pImageIndex will be fully backed by memory 873before this call returns to the application, as if it is bound completely 874and contiguously to a single sname:VkDeviceMemory object. 875endif::VK_EXT_swapchain_maintenance1[] 876 877.Valid Usage 878**** 879 * [[VUID-vkAcquireNextImageKHR-swapchain-01285]] 880 pname:swapchain must: not be in the retired state 881 * [[VUID-vkAcquireNextImageKHR-semaphore-01286]] 882 If pname:semaphore is not dlink:VK_NULL_HANDLE it must: be unsignaled 883 * [[VUID-vkAcquireNextImageKHR-semaphore-01779]] 884 If pname:semaphore is not dlink:VK_NULL_HANDLE it must: not have any 885 uncompleted signal or wait operations pending 886 * [[VUID-vkAcquireNextImageKHR-fence-01287]] 887 If pname:fence is not dlink:VK_NULL_HANDLE it must: be unsignaled and 888 must: not be associated with any other queue command that has not yet 889 completed execution on that queue 890 * [[VUID-vkAcquireNextImageKHR-semaphore-01780]] 891 pname:semaphore and pname:fence must: not both be equal to 892 dlink:VK_NULL_HANDLE 893 * [[VUID-vkAcquireNextImageKHR-surface-07783]] 894 If <<swapchain-acquire-forward-progress,forward progress>> cannot be 895 guaranteed for the pname:surface used to create the pname:swapchain 896 member of pname:pAcquireInfo, the pname:timeout member of 897 pname:pAcquireInfo must: not be code:UINT64_MAX 898ifdef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[] 899 * [[VUID-vkAcquireNextImageKHR-semaphore-03265]] 900 pname:semaphore must: have a elink:VkSemaphoreType of 901 ename:VK_SEMAPHORE_TYPE_BINARY 902endif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[] 903**** 904 905include::{generated}/validity/protos/vkAcquireNextImageKHR.adoc[] 906-- 907 908When successful, fname:vkAcquireNextImageKHR acquires a presentable image 909from pname:swapchain that an application can: use, and sets 910pname:pImageIndex to the index of that image within the swapchain. 911The presentation engine may: not have finished reading from the image at the 912time it is acquired, so the application must: use pname:semaphore and/or 913pname:fence to ensure that the image layout and contents are not modified 914until the presentation engine reads have completed. 915If pname:semaphore is not dlink:VK_NULL_HANDLE, the application may assume 916that, once fname:vkAcquireNextImageKHR returns, the semaphore signal 917operation referenced by pname:semaphore has been submitted for execution. 918The order in which images are acquired is implementation-dependent, and may: 919be different than the order the images were presented. 920 921If pname:timeout is zero, then fname:vkAcquireNextImageKHR does not wait, 922and will either successfully acquire an image, or fail and return 923ename:VK_NOT_READY if no image is available. 924 925If the specified timeout period expires before an image is acquired, 926fname:vkAcquireNextImageKHR returns ename:VK_TIMEOUT. 927If pname:timeout is code:UINT64_MAX, the timeout period is treated as 928infinite, and fname:vkAcquireNextImageKHR will block until an image is 929acquired or an error occurs. 930 931[[swapchain-acquire-forward-progress]] 932Let [eq]#S# be the number of images in pname:swapchain. 933ifndef::VK_EXT_swapchain_maintenance1[] 934Let [eq]#M# be the value of 935slink:VkSurfaceCapabilitiesKHR::pname:minImageCount. 936endif::VK_EXT_swapchain_maintenance1[] 937ifdef::VK_EXT_swapchain_maintenance1[] 938If pname:swapchain is created with 939slink:VkSwapchainPresentModesCreateInfoEXT, let [eq]#M# be the maximum of 940the values in slink:VkSurfaceCapabilitiesKHR::pname:minImageCount when 941queried with each present mode in 942slink:VkSwapchainPresentModesCreateInfoEXT::pname:pPresentModes in 943slink:VkSurfacePresentModeEXT. 944Otherwise, let [eq]#M# be the value of 945slink:VkSurfaceCapabilitiesKHR::pname:minImageCount without a 946slink:VkSurfacePresentModeEXT as part of the query input. 947endif::VK_EXT_swapchain_maintenance1[] 948 949fname:vkAcquireNextImageKHR should: not be called if the number of images 950that the application has currently acquired is greater than [eq]#S-M#. 951If fname:vkAcquireNextImageKHR is called when the number of images that the 952application has currently acquired is less than or equal to [eq]#S-M#, 953fname:vkAcquireNextImageKHR must: return in finite time with an allowed 954ename:VkResult code. 955 956[NOTE] 957.Note 958==== 959Returning a result in finite time guarantees that the implementation cannot 960deadlock an application, or suspend its execution indefinitely with correct 961API usage. 962Acquiring too many images at once may block indefinitely, which is covered 963by valid usage when attempting to use code:UINT64_MAX. 964For example, a scenario here is when a compositor holds on to images which 965are currently being presented, and there are not any vacant images left to 966be acquired. 967==== 968 969If an image is acquired successfully, fname:vkAcquireNextImageKHR must: 970either return ename:VK_SUCCESS or ename:VK_SUBOPTIMAL_KHR. 971The implementation may: return ename:VK_SUBOPTIMAL_KHR if the swapchain no 972longer matches the surface properties exactly, but can: still be used for 973presentation. 974 975[NOTE] 976.Note 977==== 978ename:VK_SUBOPTIMAL_KHR may: happen, for example, if the platform surface 979has been resized but the platform is able to scale the presented images to 980the new size to produce valid surface updates. 981It is up to the application to decide whether it prefers to continue using 982the current swapchain in this state, or to re-create the swapchain to better 983match the platform surface properties. 984==== 985 986If the swapchain images no longer match native surface properties, either 987ename:VK_SUBOPTIMAL_KHR or ename:VK_ERROR_OUT_OF_DATE_KHR must: be returned. 988If ename:VK_ERROR_OUT_OF_DATE_KHR is returned, no image is acquired and 989attempts to present previously acquired images to the swapchain will also 990fail with ename:VK_ERROR_OUT_OF_DATE_KHR. 991Applications need to create a new swapchain for the surface to continue 992presenting if ename:VK_ERROR_OUT_OF_DATE_KHR is returned. 993 994If device loss occurs (see <<devsandqueues-lost-device,Lost Device>>) before 995the timeout has expired, fname:vkAcquireNextImageKHR must: return in finite 996time with either one of the allowed success codes, or 997ename:VK_ERROR_DEVICE_LOST. 998 999If pname:semaphore is not dlink:VK_NULL_HANDLE, the semaphore must: be 1000unsignaled, with no signal or wait operations pending. 1001It will become signaled when the application can: use the image. 1002 1003[NOTE] 1004.Note 1005==== 1006Use of pname:semaphore allows rendering operations to be recorded and 1007submitted before the presentation engine has completed its use of the image. 1008==== 1009 1010If pname:fence is not equal to dlink:VK_NULL_HANDLE, the fence must: be 1011unsignaled, with no signal operations pending. 1012It will become signaled when the application can: use the image. 1013 1014[NOTE] 1015.Note 1016==== 1017Applications should: not rely on fname:vkAcquireNextImageKHR blocking in 1018order to meter their rendering speed. 1019The implementation may: return from this function immediately regardless of 1020how many presentation requests are queued, and regardless of when queued 1021presentation requests will complete relative to the call. 1022Instead, applications can: use pname:fence to meter their frame generation 1023work to match the presentation rate. 1024==== 1025 1026An application must: wait until either the pname:semaphore or pname:fence is 1027signaled before accessing the image's data. 1028 1029[NOTE] 1030.Note 1031==== 1032When the presentable image will be accessed by some stage [eq]#S#, the 1033recommended idiom for ensuring correct synchronization is: 1034 1035 * The slink:VkSubmitInfo used to submit the image layout transition for 1036 execution includes fname:vkAcquireNextImageKHR::pname:semaphore in its 1037 pname:pWaitSemaphores member, with the corresponding element of 1038 pname:pWaitDstStageMask including [eq]#S#. 1039 * The <<synchronization, synchronization command>> that performs any 1040 necessary image layout transition includes [eq]#S# in both the 1041 pname:srcStageMask and pname:dstStageMask. 1042==== 1043 1044After a successful return, the image indicated by pname:pImageIndex and its 1045data will be unmodified compared to when it was presented. 1046 1047[NOTE] 1048.Note 1049==== 1050Exclusive ownership of presentable images corresponding to a swapchain 1051created with ename:VK_SHARING_MODE_EXCLUSIVE as defined in 1052<<resources-sharing,Resource Sharing>> is not altered by a call to 1053fname:vkAcquireNextImageKHR. 1054That means upon the first acquisition from such a swapchain presentable 1055images are not owned by any queue family, while at subsequent acquisitions 1056the presentable images remain owned by the queue family the image was 1057previously presented on. 1058==== 1059 1060The possible return values for fname:vkAcquireNextImageKHR depend on the 1061pname:timeout provided: 1062 1063 * ename:VK_SUCCESS is returned if an image became available. 1064 * ename:VK_ERROR_SURFACE_LOST_KHR is returned if the surface becomes no 1065 longer available. 1066 * ename:VK_NOT_READY is returned if pname:timeout is zero and no image was 1067 available. 1068 * ename:VK_TIMEOUT is returned if pname:timeout is greater than zero and 1069 less than code:UINT64_MAX, and no image became available within the time 1070 allowed. 1071 * ename:VK_SUBOPTIMAL_KHR is returned if an image became available, and 1072 the swapchain no longer matches the surface properties exactly, but can: 1073 still be used to present to the surface successfully. 1074 1075[NOTE] 1076.Note 1077==== 1078This may: happen, for example, if the platform surface has been resized but 1079the platform is able to scale the presented images to the new size to 1080produce valid surface updates. 1081It is up to the application to decide whether it prefers to continue using 1082the current swapchain indefinitely or temporarily in this state, or to 1083re-create the swapchain to better match the platform surface properties. 1084==== 1085 1086 * ename:VK_ERROR_OUT_OF_DATE_KHR is returned if the surface has changed in 1087 such a way that it is no longer compatible with the swapchain, and 1088 further presentation requests using the swapchain will fail. 1089 Applications must: query the new surface properties and recreate their 1090 swapchain if they wish to continue presenting to the surface. 1091 1092If the native surface and presented image sizes no longer match, 1093presentation may: fail 1094ifdef::VK_EXT_swapchain_maintenance1[] 1095unless the swapchain is created with a non-zero value in 1096slink:VkSwapchainPresentScalingCreateInfoEXT::pname:scalingBehavior 1097endif::VK_EXT_swapchain_maintenance1[] 1098. 1099If presentation does succeed, the mapping from the presented image to the 1100native surface is 1101ifdef::VK_EXT_swapchain_maintenance1[] 1102defined by the slink:VkSwapchainPresentScalingCreateInfoEXT structure if 1103provided. 1104Otherwise it is 1105endif::VK_EXT_swapchain_maintenance1[] 1106implementation-defined. 1107It is the application's responsibility to detect surface size changes and 1108react appropriately. 1109If presentation fails because of a mismatch in the surface and presented 1110image sizes, a ename:VK_ERROR_OUT_OF_DATE_KHR error will be returned. 1111 1112[NOTE] 1113.Note 1114==== 1115For example, consider a 4x3 window/surface that gets resized to be 3x4 1116(taller than wider). 1117On some window systems, the portion of the window/surface that was 1118previously and still is visible (the 3x3 part) will contain the same 1119contents as before, while the remaining parts of the window will have 1120undefined: contents. 1121Other window systems may: squash/stretch the image to fill the new window 1122size without any undefined: contents, or apply some other mapping. 1123==== 1124 1125ifdef::VK_VERSION_1_1,VK_KHR_device_group[] 1126[open,refpage='vkAcquireNextImage2KHR',desc='Retrieve the index of the next available presentable image',type='protos'] 1127-- 1128To acquire an available presentable image to use, and retrieve the index of 1129that image, call: 1130 1131include::{generated}/api/protos/vkAcquireNextImage2KHR.adoc[] 1132 1133 * pname:device is the device associated with pname:swapchain. 1134 * pname:pAcquireInfo is a pointer to a slink:VkAcquireNextImageInfoKHR 1135 structure containing parameters of the acquire. 1136 * pname:pImageIndex is a pointer to a code:uint32_t that is set to the 1137 index of the next image to use. 1138 1139ifdef::VK_EXT_swapchain_maintenance1[] 1140If the pname:swapchain has been created with the 1141ename:VK_SWAPCHAIN_CREATE_DEFERRED_MEMORY_ALLOCATION_BIT_EXT flag, the image 1142whose index is returned in pname:pImageIndex will be fully backed by memory 1143before this call returns to the application. 1144endif::VK_EXT_swapchain_maintenance1[] 1145 1146.Valid Usage 1147**** 1148 * [[VUID-vkAcquireNextImage2KHR-surface-07784]] 1149 If <<swapchain-acquire-forward-progress,forward progress>> cannot be 1150 guaranteed for the pname:surface used to create pname:swapchain, the 1151 pname:timeout member of pname:pAcquireInfo must: not be code:UINT64_MAX 1152**** 1153 1154include::{generated}/validity/protos/vkAcquireNextImage2KHR.adoc[] 1155-- 1156 1157[open,refpage='VkAcquireNextImageInfoKHR',desc='Structure specifying parameters of the acquire',type='structs'] 1158-- 1159The sname:VkAcquireNextImageInfoKHR structure is defined as: 1160 1161include::{generated}/api/structs/VkAcquireNextImageInfoKHR.adoc[] 1162 1163 * pname:sType is the type of this structure. 1164 * pname:pNext is `NULL` or a pointer to a structure extending this 1165 structure. 1166 * pname:swapchain is a non-retired swapchain from which an image is 1167 acquired. 1168 * pname:timeout specifies how long the function waits, in nanoseconds, if 1169 no image is available. 1170 * pname:semaphore is dlink:VK_NULL_HANDLE or a semaphore to signal. 1171 * pname:fence is dlink:VK_NULL_HANDLE or a fence to signal. 1172 * pname:deviceMask is a mask of physical devices for which the swapchain 1173 image will be ready to use when the semaphore or fence is signaled. 1174 1175If flink:vkAcquireNextImageKHR is used, the device mask is considered to 1176include all physical devices in the logical device. 1177 1178[NOTE] 1179.Note 1180==== 1181flink:vkAcquireNextImage2KHR signals at most one semaphore, even if the 1182application requests waiting for multiple physical devices to be ready via 1183the pname:deviceMask. 1184However, only a single physical device can: wait on that semaphore, since 1185the semaphore becomes unsignaled when the wait succeeds. 1186For other physical devices to wait for the image to be ready, it is 1187necessary for the application to submit semaphore signal operation(s) to 1188that first physical device to signal additional semaphore(s) after the wait 1189succeeds, which the other physical device(s) can: wait upon. 1190==== 1191 1192.Valid Usage 1193**** 1194 * [[VUID-VkAcquireNextImageInfoKHR-swapchain-01675]] 1195 pname:swapchain must: not be in the retired state 1196 * [[VUID-VkAcquireNextImageInfoKHR-semaphore-01288]] 1197 If pname:semaphore is not dlink:VK_NULL_HANDLE it must: be unsignaled 1198 * [[VUID-VkAcquireNextImageInfoKHR-semaphore-01781]] 1199 If pname:semaphore is not dlink:VK_NULL_HANDLE it must: not have any 1200 uncompleted signal or wait operations pending 1201 * [[VUID-VkAcquireNextImageInfoKHR-fence-01289]] 1202 If pname:fence is not dlink:VK_NULL_HANDLE it must: be unsignaled and 1203 must: not be associated with any other queue command that has not yet 1204 completed execution on that queue 1205 * [[VUID-VkAcquireNextImageInfoKHR-semaphore-01782]] 1206 pname:semaphore and pname:fence must: not both be equal to 1207 dlink:VK_NULL_HANDLE 1208 * [[VUID-VkAcquireNextImageInfoKHR-deviceMask-01290]] 1209 pname:deviceMask must: be a valid device mask 1210 * [[VUID-VkAcquireNextImageInfoKHR-deviceMask-01291]] 1211 pname:deviceMask must: not be zero 1212ifdef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[] 1213 * [[VUID-VkAcquireNextImageInfoKHR-semaphore-03266]] 1214 pname:semaphore must: have a elink:VkSemaphoreType of 1215 ename:VK_SEMAPHORE_TYPE_BINARY 1216endif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[] 1217**** 1218 1219include::{generated}/validity/structs/VkAcquireNextImageInfoKHR.adoc[] 1220-- 1221endif::VK_VERSION_1_1,VK_KHR_device_group[] 1222 1223[open,refpage='vkQueuePresentKHR',desc='Queue an image for presentation',type='protos'] 1224-- 1225After queueing all rendering commands and transitioning the image to the 1226correct layout, to queue an image for presentation, call: 1227 1228include::{generated}/api/protos/vkQueuePresentKHR.adoc[] 1229 1230 * pname:queue is a queue that is capable of presentation to the target 1231 surface's platform on the same device as the image's swapchain. 1232 * pname:pPresentInfo is a pointer to a slink:VkPresentInfoKHR structure 1233 specifying parameters of the presentation. 1234 1235.Note 1236[NOTE] 1237==== 1238There is no requirement for an application to present images in the same 1239order that they were acquired - applications can arbitrarily present any 1240image that is currently acquired. 1241==== 1242 1243.Valid Usage 1244**** 1245 * [[VUID-vkQueuePresentKHR-pSwapchains-01292]] 1246 Each element of pname:pSwapchains member of pname:pPresentInfo must: be 1247 a swapchain that is created for a surface for which presentation is 1248 supported from pname:queue as determined using a call to 1249 fname:vkGetPhysicalDeviceSurfaceSupportKHR 1250ifdef::VK_KHR_display_swapchain[] 1251 * [[VUID-vkQueuePresentKHR-pSwapchains-01293]] 1252 If more than one member of pname:pSwapchains was created from a display 1253 surface, all display surfaces referenced that refer to the same display 1254 must: use the same display mode 1255endif::VK_KHR_display_swapchain[] 1256 * [[VUID-vkQueuePresentKHR-pWaitSemaphores-01294]] 1257 When a semaphore wait operation referring to a binary semaphore defined 1258 by the elements of the pname:pWaitSemaphores member of 1259 pname:pPresentInfo executes on pname:queue, there must: be no other 1260 queues waiting on the same semaphore 1261 * [[VUID-vkQueuePresentKHR-pWaitSemaphores-01295]] 1262 All elements of the pname:pWaitSemaphores member of pname:pPresentInfo 1263 must: be semaphores that are signaled, or have 1264 <<synchronization-semaphores-signaling, semaphore signal operations>> 1265 previously submitted for execution 1266ifdef::VK_VERSION_1_2,VK_KHR_timeline_semaphore[] 1267 * [[VUID-vkQueuePresentKHR-pWaitSemaphores-03267]] 1268 All elements of the pname:pWaitSemaphores member of pname:pPresentInfo 1269 must: be created with a elink:VkSemaphoreType of 1270 ename:VK_SEMAPHORE_TYPE_BINARY 1271 * [[VUID-vkQueuePresentKHR-pWaitSemaphores-03268]] 1272 All elements of the pname:pWaitSemaphores member of pname:pPresentInfo 1273 must: reference a semaphore signal operation that has been submitted for 1274 execution and any semaphore signal operations on which it depends (if 1275 any) must: have also been submitted for execution 1276endif::VK_VERSION_1_2,VK_KHR_timeline_semaphore[] 1277**** 1278 1279Any writes to memory backing the images referenced by the 1280pname:pImageIndices and pname:pSwapchains members of pname:pPresentInfo, 1281that are available before flink:vkQueuePresentKHR is executed, are 1282automatically made visible to the read access performed by the presentation 1283engine. 1284This automatic visibility operation for an image happens-after the semaphore 1285signal operation, and happens-before the presentation engine accesses the 1286image. 1287 1288Queueing an image for presentation defines a set of _queue operations_, 1289including waiting on the semaphores and submitting a presentation request to 1290the presentation engine. 1291However, the scope of this set of queue operations does not include the 1292actual processing of the image by the presentation engine. 1293 1294.Note 1295[NOTE] 1296==== 1297The origin of the native orientation of the surface coordinate system is not 1298specified in the Vulkan specification; it depends on the platform. 1299For most platforms the origin is by default upper-left, meaning the pixel of 1300the presented slink:VkImage at coordinates [eq]#(0,0)# would appear at the 1301upper left pixel of the platform surface (assuming 1302ename:VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR, and the display standing the 1303right way up). 1304==== 1305 1306If fname:vkQueuePresentKHR fails to enqueue the corresponding set of queue 1307operations, it may: return ename:VK_ERROR_OUT_OF_HOST_MEMORY or 1308ename:VK_ERROR_OUT_OF_DEVICE_MEMORY. 1309If it does, the implementation must: ensure that the state and contents of 1310any resources or synchronization primitives referenced is unaffected by the 1311call or its failure. 1312 1313If fname:vkQueuePresentKHR fails in such a way that the implementation is 1314unable to make that guarantee, the implementation must: return 1315ename:VK_ERROR_DEVICE_LOST. 1316 1317However, if the presentation request is rejected by the presentation engine 1318with an error ename:VK_ERROR_OUT_OF_DATE_KHR, 1319ifdef::VK_EXT_full_screen_exclusive[] 1320ename:VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT, 1321endif::VK_EXT_full_screen_exclusive[] 1322or ename:VK_ERROR_SURFACE_LOST_KHR, the set of queue operations are still 1323considered to be enqueued and thus any semaphore wait operation specified in 1324slink:VkPresentInfoKHR will execute when the corresponding queue operation 1325is complete. 1326 1327Calls to fname:vkQueuePresentKHR may: block, but must: return in finite 1328time. 1329 1330ifdef::VK_EXT_full_screen_exclusive[] 1331If any pname:swapchain member of pname:pPresentInfo was created with 1332ename:VK_FULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT, 1333ename:VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT will be returned if that 1334swapchain does not have exclusive full-screen access, possibly for 1335implementation-specific reasons outside of the application's control. 1336endif::VK_EXT_full_screen_exclusive[] 1337 1338include::{generated}/validity/protos/vkQueuePresentKHR.adoc[] 1339-- 1340 1341[open,refpage='VkPresentInfoKHR',desc='Structure describing parameters of a queue presentation',type='structs'] 1342-- 1343The sname:VkPresentInfoKHR structure is defined as: 1344 1345include::{generated}/api/structs/VkPresentInfoKHR.adoc[] 1346 1347 * pname:sType is the type of this structure. 1348 * pname:pNext is `NULL` or a pointer to a structure extending this 1349 structure. 1350 * pname:waitSemaphoreCount is the number of semaphores to wait for before 1351 issuing the present request. 1352 The number may: be zero. 1353 * pname:pWaitSemaphores is `NULL` or a pointer to an array of 1354 slink:VkSemaphore objects with pname:waitSemaphoreCount entries, and 1355 specifies the semaphores to wait for before issuing the present request. 1356 * pname:swapchainCount is the number of swapchains being presented to by 1357 this command. 1358 * pname:pSwapchains is a pointer to an array of slink:VkSwapchainKHR 1359 objects with pname:swapchainCount entries. 1360 A given swapchain must: not appear in this list more than once. 1361 * pname:pImageIndices is a pointer to an array of indices into the array 1362 of each swapchain's presentable images, with pname:swapchainCount 1363 entries. 1364 Each entry in this array identifies the image to present on the 1365 corresponding entry in the pname:pSwapchains array. 1366 * pname:pResults is a pointer to an array of elink:VkResult typed elements 1367 with pname:swapchainCount entries. 1368 Applications that do not need per-swapchain results can: use `NULL` for 1369 pname:pResults. 1370 If non-`NULL`, each entry in pname:pResults will be set to the 1371 elink:VkResult for presenting the swapchain corresponding to the same 1372 index in pname:pSwapchains. 1373 1374Before an application can: present an image, the image's layout must: be 1375transitioned to the ename:VK_IMAGE_LAYOUT_PRESENT_SRC_KHR 1376ifdef::VK_KHR_shared_presentable_image[] 1377layout, or for a shared presentable image the 1378ename:VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR 1379endif::VK_KHR_shared_presentable_image[] 1380layout. 1381 1382.Note 1383[NOTE] 1384==== 1385When transitioning the image to 1386ifdef::VK_KHR_shared_presentable_image[] 1387ename:VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR or 1388endif::VK_KHR_shared_presentable_image[] 1389ename:VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, there is no need to delay subsequent 1390processing, or perform any visibility operations (as flink:vkQueuePresentKHR 1391performs automatic visibility operations). 1392To achieve this, the pname:dstAccessMask member of the 1393slink:VkImageMemoryBarrier should: be set to `0`, and the pname:dstStageMask 1394parameter should: be set to ename:VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT. 1395==== 1396 1397.Valid Usage 1398**** 1399ifndef::VK_KHR_shared_presentable_image[] 1400 * [[VUID-VkPresentInfoKHR-pImageIndices-01296]] 1401 Each element of pname:pImageIndices must: be the index of a presentable 1402 image acquired from the swapchain specified by the corresponding element 1403 of the pname:pSwapchains array, and the presented image subresource 1404 must: be in the ename:VK_IMAGE_LAYOUT_PRESENT_SRC_KHR layout at the time 1405 the operation is executed on a sname:VkDevice 1406endif::VK_KHR_shared_presentable_image[] 1407ifdef::VK_KHR_shared_presentable_image[] 1408 * [[VUID-VkPresentInfoKHR-pImageIndices-01430]] 1409 Each element of pname:pImageIndices must: be the index of a presentable 1410 image acquired from the swapchain specified by the corresponding element 1411 of the pname:pSwapchains array, and the presented image subresource 1412 must: be in the ename:VK_IMAGE_LAYOUT_PRESENT_SRC_KHR or 1413 ename:VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR layout at the time the 1414 operation is executed on a sname:VkDevice 1415endif::VK_KHR_shared_presentable_image[] 1416ifdef::VK_KHR_present_id[] 1417 * [[VUID-VkPresentInfoKHR-pNext-06235]] 1418 If a slink:VkPresentIdKHR structure is included in the pname:pNext 1419 chain, and the <<features-presentId, pname:presentId>> feature is not 1420 enabled, each pname:presentIds entry in that structure must: be NULL 1421endif::VK_KHR_present_id[] 1422**** 1423 1424include::{generated}/validity/structs/VkPresentInfoKHR.adoc[] 1425-- 1426 1427ifdef::VK_KHR_incremental_present[] 1428include::{chapters}/VK_KHR_incremental_present/wsi.adoc[] 1429endif::VK_KHR_incremental_present[] 1430 1431ifdef::VK_KHR_display_swapchain[] 1432include::{chapters}/VK_KHR_display_swapchain/display_swapchain_present.adoc[] 1433endif::VK_KHR_display_swapchain[] 1434 1435ifdef::VK_VERSION_1_1,VK_KHR_device_group[] 1436[open,refpage='VkDeviceGroupPresentInfoKHR',desc='Mode and mask controlling which physical devices\' images are presented',type='structs'] 1437-- 1438If the pname:pNext chain of slink:VkPresentInfoKHR includes a 1439sname:VkDeviceGroupPresentInfoKHR structure, then that structure includes an 1440array of device masks and a device group present mode. 1441 1442The sname:VkDeviceGroupPresentInfoKHR structure is defined as: 1443 1444include::{generated}/api/structs/VkDeviceGroupPresentInfoKHR.adoc[] 1445 1446 * pname:sType is the type of this structure. 1447 * pname:pNext is `NULL` or a pointer to a structure extending this 1448 structure. 1449 * pname:swapchainCount is zero or the number of elements in 1450 pname:pDeviceMasks. 1451 * pname:pDeviceMasks is a pointer to an array of device masks, one for 1452 each element of slink:VkPresentInfoKHR::pname:pSwapchains. 1453 * pname:mode is a elink:VkDeviceGroupPresentModeFlagBitsKHR value 1454 specifying the device group present mode that will be used for this 1455 present. 1456 1457If pname:mode is ename:VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR, then each 1458element of pname:pDeviceMasks selects which instance of the swapchain image 1459is presented. 1460Each element of pname:pDeviceMasks must: have exactly one bit set, and the 1461corresponding physical device must: have a presentation engine as reported 1462by slink:VkDeviceGroupPresentCapabilitiesKHR. 1463 1464If pname:mode is ename:VK_DEVICE_GROUP_PRESENT_MODE_REMOTE_BIT_KHR, then 1465each element of pname:pDeviceMasks selects which instance of the swapchain 1466image is presented. 1467Each element of pname:pDeviceMasks must: have exactly one bit set, and some 1468physical device in the logical device must: include that bit in its 1469slink:VkDeviceGroupPresentCapabilitiesKHR::pname:presentMask. 1470 1471If pname:mode is ename:VK_DEVICE_GROUP_PRESENT_MODE_SUM_BIT_KHR, then each 1472element of pname:pDeviceMasks selects which instances of the swapchain image 1473are component-wise summed and the sum of those images is presented. 1474If the sum in any component is outside the representable range, the value of 1475that component is undefined:. 1476Each element of pname:pDeviceMasks must: have a value for which all set bits 1477are set in one of the elements of 1478slink:VkDeviceGroupPresentCapabilitiesKHR::pname:presentMask. 1479 1480If pname:mode is 1481ename:VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_MULTI_DEVICE_BIT_KHR, then each 1482element of pname:pDeviceMasks selects which instance(s) of the swapchain 1483images are presented. 1484For each bit set in each element of pname:pDeviceMasks, the corresponding 1485physical device must: have a presentation engine as reported by 1486slink:VkDeviceGroupPresentCapabilitiesKHR. 1487 1488If sname:VkDeviceGroupPresentInfoKHR is not provided or pname:swapchainCount 1489is zero then the masks are considered to be `1`. 1490If sname:VkDeviceGroupPresentInfoKHR is not provided, pname:mode is 1491considered to be ename:VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR. 1492 1493.Valid Usage 1494**** 1495 * [[VUID-VkDeviceGroupPresentInfoKHR-swapchainCount-01297]] 1496 pname:swapchainCount must: equal `0` or 1497 slink:VkPresentInfoKHR::pname:swapchainCount 1498 * [[VUID-VkDeviceGroupPresentInfoKHR-mode-01298]] 1499 If pname:mode is ename:VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR, then 1500 each element of pname:pDeviceMasks must: have exactly one bit set, and 1501 the corresponding element of 1502 slink:VkDeviceGroupPresentCapabilitiesKHR::pname:presentMask must: be 1503 non-zero 1504 * [[VUID-VkDeviceGroupPresentInfoKHR-mode-01299]] 1505 If pname:mode is ename:VK_DEVICE_GROUP_PRESENT_MODE_REMOTE_BIT_KHR, then 1506 each element of pname:pDeviceMasks must: have exactly one bit set, and 1507 some physical device in the logical device must: include that bit in its 1508 slink:VkDeviceGroupPresentCapabilitiesKHR::pname:presentMask 1509 * [[VUID-VkDeviceGroupPresentInfoKHR-mode-01300]] 1510 If pname:mode is ename:VK_DEVICE_GROUP_PRESENT_MODE_SUM_BIT_KHR, then 1511 each element of pname:pDeviceMasks must: have a value for which all set 1512 bits are set in one of the elements of 1513 slink:VkDeviceGroupPresentCapabilitiesKHR::pname:presentMask 1514 * [[VUID-VkDeviceGroupPresentInfoKHR-mode-01301]] 1515 If pname:mode is 1516 ename:VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_MULTI_DEVICE_BIT_KHR, then for 1517 each bit set in each element of pname:pDeviceMasks, the corresponding 1518 element of slink:VkDeviceGroupPresentCapabilitiesKHR::pname:presentMask 1519 must: be non-zero 1520 * [[VUID-VkDeviceGroupPresentInfoKHR-pDeviceMasks-01302]] 1521 The value of each element of pname:pDeviceMasks must: be equal to the 1522 device mask passed in slink:VkAcquireNextImageInfoKHR::pname:deviceMask 1523 when the image index was last acquired 1524 * [[VUID-VkDeviceGroupPresentInfoKHR-mode-01303]] 1525 pname:mode must: have exactly one bit set, and that bit must: have been 1526 included in slink:VkDeviceGroupSwapchainCreateInfoKHR::pname:modes 1527**** 1528 1529include::{generated}/validity/structs/VkDeviceGroupPresentInfoKHR.adoc[] 1530-- 1531endif::VK_VERSION_1_1,VK_KHR_device_group[] 1532 1533ifdef::VK_GOOGLE_display_timing[] 1534include::{chapters}/VK_GOOGLE_display_timing/PresentTimeInfo.adoc[] 1535endif::VK_GOOGLE_display_timing[] 1536 1537ifdef::VK_KHR_present_id[] 1538include::{chapters}/VK_KHR_swapchain/PresentId.adoc[] 1539endif::VK_KHR_present_id[] 1540 1541ifdef::VK_GGP_frame_token[] 1542include::{chapters}/VK_GGP_frame_token.adoc[] 1543endif::VK_GGP_frame_token[] 1544 1545ifdef::VK_EXT_swapchain_maintenance1[] 1546include::{chapters}/VK_EXT_swapchain_maintenance1/SwapchainPresentModeInfo.adoc[] 1547include::{chapters}/VK_EXT_swapchain_maintenance1/SwapchainPresentFenceInfo.adoc[] 1548endif::VK_EXT_swapchain_maintenance1[] 1549 1550fname:vkQueuePresentKHR, releases the acquisition of the images referenced 1551by pname:imageIndices. 1552The queue family corresponding to the queue fname:vkQueuePresentKHR is 1553executed on must: have ownership of the presented images as defined in 1554<<resources-sharing,Resource Sharing>>. 1555fname:vkQueuePresentKHR does not alter the queue family ownership, but the 1556presented images must: not be used again before they have been reacquired 1557using fname:vkAcquireNextImageKHR. 1558 1559The processing of the presentation happens in issue order with other queue 1560operations, but semaphores have to be used to ensure that prior rendering 1561and other commands in the specified queue complete before the presentation 1562begins. 1563The presentation command itself does not delay processing of subsequent 1564commands on the queue, however, presentation requests sent to a particular 1565queue are always performed in order. 1566Exact presentation timing is controlled by the semantics of the presentation 1567engine and native platform in use. 1568 1569ifdef::VK_KHR_display_swapchain[] 1570include::{chapters}/VK_KHR_display_swapchain/queue_present_interactions.adoc[] 1571endif::VK_KHR_display_swapchain[] 1572 1573The result codes ename:VK_ERROR_OUT_OF_DATE_KHR and ename:VK_SUBOPTIMAL_KHR 1574have the same meaning when returned by fname:vkQueuePresentKHR as they do 1575when returned by fname:vkAcquireNextImageKHR. 1576If multiple swapchains are presented, the result code is determined applying 1577the following rules in order: 1578 1579 * If the device is lost, ename:VK_ERROR_DEVICE_LOST is returned. 1580 * If any of the target surfaces are no longer available the error 1581 ename:VK_ERROR_SURFACE_LOST_KHR is returned. 1582 * If any of the presents would have a result of 1583 ename:VK_ERROR_OUT_OF_DATE_KHR if issued separately then 1584 ename:VK_ERROR_OUT_OF_DATE_KHR is returned. 1585ifdef::VK_EXT_full_screen_exclusive[] 1586 * If any of the presents would have a result of 1587 ename:VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT if issued separately 1588 then ename:VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT is returned. 1589endif::VK_EXT_full_screen_exclusive[] 1590 * If any of the presents would have a result of ename:VK_SUBOPTIMAL_KHR if 1591 issued separately then ename:VK_SUBOPTIMAL_KHR is returned. 1592 * Otherwise ename:VK_SUCCESS is returned. 1593 1594Presentation is a read-only operation that will not affect the content of 1595the presentable images. 1596Upon reacquiring the image and transitioning it away from the 1597ename:VK_IMAGE_LAYOUT_PRESENT_SRC_KHR layout, the contents will be the same 1598as they were prior to transitioning the image to the present source layout 1599and presenting it. 1600However, if a mechanism other than Vulkan is used to modify the platform 1601window associated with the swapchain, the content of all presentable images 1602in the swapchain becomes undefined:. 1603 1604[NOTE] 1605.Note 1606==== 1607The application can: continue to present any acquired images from a retired 1608swapchain as long as the swapchain has not entered a state that causes 1609flink:vkQueuePresentKHR to return ename:VK_ERROR_OUT_OF_DATE_KHR. 1610==== 1611 1612ifdef::VK_EXT_swapchain_maintenance1[] 1613[open,refpage='vkReleaseSwapchainImagesEXT',desc='Release previously acquired but unused images',type='protos'] 1614-- 1615To release images previously acquired through 1616ifdef::VK_VERSION_1_1,VK_KHR_device_group[flink:vkAcquireNextImage2KHR or] 1617flink:vkAcquireNextImageKHR, call: 1618 1619include::{generated}/api/protos/vkReleaseSwapchainImagesEXT.adoc[] 1620 1621 * pname:device is the device associated with 1622 slink:VkReleaseSwapchainImagesInfoEXT::pname:swapchain. 1623 * pname:pReleaseInfo is a pointer to a 1624 slink:VkReleaseSwapchainImagesInfoEXT structure containing parameters of 1625 the release. 1626 1627Only images that are not in use by the device can: be released. 1628 1629Releasing images is a read-only operation that will not affect the content 1630of the released images. 1631Upon reacquiring the image, the image contents and its layout will be the 1632same as they were prior to releasing it. 1633However, if a mechanism other than Vulkan is used to modify the platform 1634window associated with the swapchain, the content of all presentable images 1635in the swapchain becomes undefined:. 1636 1637.Note 1638[NOTE] 1639==== 1640This functionality is useful during swapchain recreation, where acquired 1641images from the old swapchain can be released instead of presented. 1642==== 1643 1644include::{generated}/validity/protos/vkReleaseSwapchainImagesEXT.adoc[] 1645-- 1646 1647[open,refpage='VkReleaseSwapchainImagesInfoEXT',desc='Structure describing a list of swapchain image indices to be released',type='structs'] 1648-- 1649The sname:VkReleaseSwapchainImagesInfoEXT structure is defined as: 1650 1651include::{generated}/api/structs/VkReleaseSwapchainImagesInfoEXT.adoc[] 1652 1653 * pname:sType is the type of this structure. 1654 * pname:pNext is `NULL` or a pointer to a structure extending this 1655 structure. 1656 * pname:swapchain is a swapchain to which images are being released. 1657 * pname:imageIndexCount is the number of image indices to be released. 1658 * pname:pImageIndices is a pointer to an array of indices into the array 1659 of pname:swapchain's presentable images, with pname:imageIndexCount 1660 entries. 1661 1662.Valid Usage 1663**** 1664 * [[VUID-VkReleaseSwapchainImagesInfoEXT-pImageIndices-07785]] 1665 Each element of pname:pImageIndices must: be the index of a presentable 1666 image acquired from the swapchain specified by pname:swapchain 1667 * [[VUID-VkReleaseSwapchainImagesInfoEXT-pImageIndices-07786]] 1668 All uses of presentable images identified by elements of 1669 pname:pImageIndices must: have completed execution 1670**** 1671 1672include::{generated}/validity/structs/VkReleaseSwapchainImagesInfoEXT.adoc[] 1673-- 1674endif::VK_EXT_swapchain_maintenance1[] 1675 1676ifdef::VK_EXT_hdr_metadata[] 1677include::{chapters}/VK_EXT_hdr_metadata.adoc[] 1678endif::VK_EXT_hdr_metadata[] 1679