Class KHRSwapchain
VK_KHR_swapchain extension is the device-level companion to the VK_KHR_surface extension. It introduces VkSwapchainKHR objects, which provide the ability to present rendering results to a surface.
Examples
Note
The example code for the VK_KHR_surface and VK_KHR_swapchain extensions was removed from the appendix after revision 1.0.29. This WSI example code was ported to the cube demo that is shipped with the official Khronos SDK, and is being kept up-to-date in that location (see: https://github.com/KhronosGroup/Vulkan-Tools/blob/main/cube/cube.c).
- Name String
VK_KHR_swapchain- Extension Type
- Device extension
- Registered Extension Number
- 2
- Revision
- 70
- Extension and Version Dependencies
VK_KHR_surface- API Interactions
- Interacts with VK_VERSION_1_1
- Contact
- James Jones cubanismo
- Ian Elliott ianelliottus
Other Extension Metadata
- Last Modified Date
- 2017-10-06
- IP Status
- No known IP claims.
- Interactions and External Dependencies
- Interacts with Vulkan 1.1
- Contributors
- Patrick Doane, Blizzard
- Ian Elliott, LunarG
- Jesse Hall, Google
- Mathias Heyer, NVIDIA
- James Jones, NVIDIA
- David Mao, AMD
- Norbert Nopper, Freescale
- Alon Or-bach, Samsung
- Daniel Rakos, AMD
- Graham Sellers, AMD
- Jeff Vigil, Qualcomm
- Chia-I Wu, LunarG
- Faith Ekstrand, Intel
- Matthaeus G. Chajdas, AMD
- Ray Smith, ARM
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intVkDeviceGroupPresentModeFlagBitsKHR - Bitmask specifying supported device group present modesstatic final intVkDeviceGroupPresentModeFlagBitsKHR - Bitmask specifying supported device group present modesstatic final intVkDeviceGroupPresentModeFlagBitsKHR - Bitmask specifying supported device group present modesstatic final intVkDeviceGroupPresentModeFlagBitsKHR - Bitmask specifying supported device group present modesstatic final intExtendsVkResult.static final intExtendsVkImageLayout.static final StringThe extension name.static final intThe extension specification version.static final intExtendsVkObjectType.static final intExtendsVkStructureType.static final intExtendsVkStructureType.static final intExtendsVkStructureType.static final intExtendsVkStructureType.static final intExtendsVkStructureType.static final intExtendsVkStructureType.static final intExtendsVkStructureType.static final intExtendsVkStructureType.static final intExtendsVkResult.static final intExtendsVkSwapchainCreateFlagBitsKHR.static final intExtendsVkSwapchainCreateFlagBitsKHR. -
Method Summary
Modifier and TypeMethodDescriptionstatic intnvkAcquireNextImage2KHR(org.lwjgl.vulkan.VkDevice device, long pAcquireInfo, long pImageIndex) Unsafe version of:AcquireNextImage2KHRstatic intnvkAcquireNextImageKHR(org.lwjgl.vulkan.VkDevice device, long swapchain, long timeout, long semaphore, long fence, long pImageIndex) Unsafe version of:AcquireNextImageKHRstatic intnvkCreateSwapchainKHR(org.lwjgl.vulkan.VkDevice device, long pCreateInfo, long pAllocator, long pSwapchain) Unsafe version of:CreateSwapchainKHRstatic voidnvkDestroySwapchainKHR(org.lwjgl.vulkan.VkDevice device, long swapchain, long pAllocator) Unsafe version of:DestroySwapchainKHRstatic intnvkGetDeviceGroupPresentCapabilitiesKHR(org.lwjgl.vulkan.VkDevice device, long pDeviceGroupPresentCapabilities) Unsafe version of:GetDeviceGroupPresentCapabilitiesKHRstatic intnvkGetDeviceGroupSurfacePresentModesKHR(org.lwjgl.vulkan.VkDevice device, long surface, long pModes) Unsafe version of:GetDeviceGroupSurfacePresentModesKHRstatic intnvkGetPhysicalDevicePresentRectanglesKHR(org.lwjgl.vulkan.VkPhysicalDevice physicalDevice, long surface, long pRectCount, long pRects) Unsafe version of:GetPhysicalDevicePresentRectanglesKHRstatic intnvkGetSwapchainImagesKHR(org.lwjgl.vulkan.VkDevice device, long swapchain, long pSwapchainImageCount, long pSwapchainImages) Unsafe version of:GetSwapchainImagesKHRstatic intnvkQueuePresentKHR(org.lwjgl.vulkan.VkQueue queue, long pPresentInfo) Unsafe version of:QueuePresentKHRstatic intvkAcquireNextImage2KHR(org.lwjgl.vulkan.VkDevice device, VkAcquireNextImageInfoKHR pAcquireInfo, int[] pImageIndex) Array version of:AcquireNextImage2KHRstatic intvkAcquireNextImage2KHR(org.lwjgl.vulkan.VkDevice device, VkAcquireNextImageInfoKHR pAcquireInfo, IntBuffer pImageIndex) Retrieve the index of the next available presentable image.static intvkAcquireNextImageKHR(org.lwjgl.vulkan.VkDevice device, long swapchain, long timeout, long semaphore, long fence, int[] pImageIndex) Array version of:AcquireNextImageKHRstatic intvkAcquireNextImageKHR(org.lwjgl.vulkan.VkDevice device, long swapchain, long timeout, long semaphore, long fence, IntBuffer pImageIndex) Retrieve the index of the next available presentable image.static intvkCreateSwapchainKHR(org.lwjgl.vulkan.VkDevice device, VkSwapchainCreateInfoKHR pCreateInfo, @Nullable VkAllocationCallbacks pAllocator, long[] pSwapchain) Array version of:CreateSwapchainKHRstatic intvkCreateSwapchainKHR(org.lwjgl.vulkan.VkDevice device, VkSwapchainCreateInfoKHR pCreateInfo, @Nullable VkAllocationCallbacks pAllocator, LongBuffer pSwapchain) Create a swapchain.static voidvkDestroySwapchainKHR(org.lwjgl.vulkan.VkDevice device, long swapchain, @Nullable VkAllocationCallbacks pAllocator) Destroy a swapchain object.static intvkGetDeviceGroupPresentCapabilitiesKHR(org.lwjgl.vulkan.VkDevice device, VkDeviceGroupPresentCapabilitiesKHR pDeviceGroupPresentCapabilities) Query present capabilities from other physical devices.static intvkGetDeviceGroupSurfacePresentModesKHR(org.lwjgl.vulkan.VkDevice device, long surface, int[] pModes) Array version of:GetDeviceGroupSurfacePresentModesKHRstatic intvkGetDeviceGroupSurfacePresentModesKHR(org.lwjgl.vulkan.VkDevice device, long surface, IntBuffer pModes) Query present capabilities for a surface.static intvkGetPhysicalDevicePresentRectanglesKHR(org.lwjgl.vulkan.VkPhysicalDevice physicalDevice, long surface, int[] pRectCount, @Nullable VkRect2D.Buffer pRects) Array version of:GetPhysicalDevicePresentRectanglesKHRstatic intvkGetPhysicalDevicePresentRectanglesKHR(org.lwjgl.vulkan.VkPhysicalDevice physicalDevice, long surface, IntBuffer pRectCount, @Nullable VkRect2D.Buffer pRects) Query present rectangles for a surface on a physical device.static intvkGetSwapchainImagesKHR(org.lwjgl.vulkan.VkDevice device, long swapchain, int[] pSwapchainImageCount, long @Nullable [] pSwapchainImages) Array version of:GetSwapchainImagesKHRstatic intvkGetSwapchainImagesKHR(org.lwjgl.vulkan.VkDevice device, long swapchain, IntBuffer pSwapchainImageCount, @Nullable LongBuffer pSwapchainImages) Obtain the array of presentable images associated with a swapchain.static intvkQueuePresentKHR(org.lwjgl.vulkan.VkQueue queue, VkPresentInfoKHR pPresentInfo) Queue an image for presentation.
-
Field Details
-
VK_KHR_SWAPCHAIN_SPEC_VERSION
public static final int VK_KHR_SWAPCHAIN_SPEC_VERSIONThe extension specification version.- See Also:
-
VK_KHR_SWAPCHAIN_EXTENSION_NAME
The extension name.- See Also:
-
VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR
public static final int VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHRExtendsVkStructureType.Enum values:
- See Also:
-
VK_STRUCTURE_TYPE_PRESENT_INFO_KHR
public static final int VK_STRUCTURE_TYPE_PRESENT_INFO_KHRExtendsVkStructureType.Enum values:
- See Also:
-
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
public static final int VK_IMAGE_LAYOUT_PRESENT_SRC_KHRExtendsVkImageLayout.- See Also:
-
VK_SUBOPTIMAL_KHR
public static final int VK_SUBOPTIMAL_KHR- See Also:
-
VK_ERROR_OUT_OF_DATE_KHR
public static final int VK_ERROR_OUT_OF_DATE_KHR- See Also:
-
VK_OBJECT_TYPE_SWAPCHAIN_KHR
public static final int VK_OBJECT_TYPE_SWAPCHAIN_KHRExtendsVkObjectType.- See Also:
-
VK_STRUCTURE_TYPE_DEVICE_GROUP_PRESENT_CAPABILITIES_KHR
public static final int VK_STRUCTURE_TYPE_DEVICE_GROUP_PRESENT_CAPABILITIES_KHRExtendsVkStructureType.Enum values:
- See Also:
-
VK_STRUCTURE_TYPE_IMAGE_SWAPCHAIN_CREATE_INFO_KHR
public static final int VK_STRUCTURE_TYPE_IMAGE_SWAPCHAIN_CREATE_INFO_KHRExtendsVkStructureType.Enum values:
- See Also:
-
VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_SWAPCHAIN_INFO_KHR
public static final int VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_SWAPCHAIN_INFO_KHRExtendsVkStructureType.Enum values:
- See Also:
-
VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR
public static final int VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHRExtendsVkStructureType.Enum values:
- See Also:
-
VK_STRUCTURE_TYPE_DEVICE_GROUP_PRESENT_INFO_KHR
public static final int VK_STRUCTURE_TYPE_DEVICE_GROUP_PRESENT_INFO_KHRExtendsVkStructureType.Enum values:
- See Also:
-
VK_STRUCTURE_TYPE_DEVICE_GROUP_SWAPCHAIN_CREATE_INFO_KHR
public static final int VK_STRUCTURE_TYPE_DEVICE_GROUP_SWAPCHAIN_CREATE_INFO_KHRExtendsVkStructureType.Enum values:
- See Also:
-
VK_SWAPCHAIN_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT_KHR
public static final int VK_SWAPCHAIN_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT_KHRExtendsVkSwapchainCreateFlagBitsKHR.Enum values:
- See Also:
-
VK_SWAPCHAIN_CREATE_PROTECTED_BIT_KHR
public static final int VK_SWAPCHAIN_CREATE_PROTECTED_BIT_KHRExtendsVkSwapchainCreateFlagBitsKHR.Enum values:
- See Also:
-
VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
public static final int VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHRVkDeviceGroupPresentModeFlagBitsKHR - Bitmask specifying supported device group present modesDescription
DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHRspecifies that any physical device with a presentation engine can present its own swapchain images.DEVICE_GROUP_PRESENT_MODE_REMOTE_BIT_KHRspecifies that any physical device with a presentation engine can present swapchain images from any physical device in itspresentMask.DEVICE_GROUP_PRESENT_MODE_SUM_BIT_KHRspecifies that any physical device with a presentation engine can present the sum of swapchain images from any physical devices in itspresentMask.DEVICE_GROUP_PRESENT_MODE_LOCAL_MULTI_DEVICE_BIT_KHRspecifies that multiple physical devices with a presentation engine can each present their own swapchain images.
See Also
- See Also:
-
VK_DEVICE_GROUP_PRESENT_MODE_REMOTE_BIT_KHR
public static final int VK_DEVICE_GROUP_PRESENT_MODE_REMOTE_BIT_KHRVkDeviceGroupPresentModeFlagBitsKHR - Bitmask specifying supported device group present modesDescription
DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHRspecifies that any physical device with a presentation engine can present its own swapchain images.DEVICE_GROUP_PRESENT_MODE_REMOTE_BIT_KHRspecifies that any physical device with a presentation engine can present swapchain images from any physical device in itspresentMask.DEVICE_GROUP_PRESENT_MODE_SUM_BIT_KHRspecifies that any physical device with a presentation engine can present the sum of swapchain images from any physical devices in itspresentMask.DEVICE_GROUP_PRESENT_MODE_LOCAL_MULTI_DEVICE_BIT_KHRspecifies that multiple physical devices with a presentation engine can each present their own swapchain images.
See Also
- See Also:
-
VK_DEVICE_GROUP_PRESENT_MODE_SUM_BIT_KHR
public static final int VK_DEVICE_GROUP_PRESENT_MODE_SUM_BIT_KHRVkDeviceGroupPresentModeFlagBitsKHR - Bitmask specifying supported device group present modesDescription
DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHRspecifies that any physical device with a presentation engine can present its own swapchain images.DEVICE_GROUP_PRESENT_MODE_REMOTE_BIT_KHRspecifies that any physical device with a presentation engine can present swapchain images from any physical device in itspresentMask.DEVICE_GROUP_PRESENT_MODE_SUM_BIT_KHRspecifies that any physical device with a presentation engine can present the sum of swapchain images from any physical devices in itspresentMask.DEVICE_GROUP_PRESENT_MODE_LOCAL_MULTI_DEVICE_BIT_KHRspecifies that multiple physical devices with a presentation engine can each present their own swapchain images.
See Also
- See Also:
-
VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_MULTI_DEVICE_BIT_KHR
public static final int VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_MULTI_DEVICE_BIT_KHRVkDeviceGroupPresentModeFlagBitsKHR - Bitmask specifying supported device group present modesDescription
DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHRspecifies that any physical device with a presentation engine can present its own swapchain images.DEVICE_GROUP_PRESENT_MODE_REMOTE_BIT_KHRspecifies that any physical device with a presentation engine can present swapchain images from any physical device in itspresentMask.DEVICE_GROUP_PRESENT_MODE_SUM_BIT_KHRspecifies that any physical device with a presentation engine can present the sum of swapchain images from any physical devices in itspresentMask.DEVICE_GROUP_PRESENT_MODE_LOCAL_MULTI_DEVICE_BIT_KHRspecifies that multiple physical devices with a presentation engine can each present their own swapchain images.
See Also
- See Also:
-
-
Method Details
-
nvkCreateSwapchainKHR
public static int nvkCreateSwapchainKHR(org.lwjgl.vulkan.VkDevice device, long pCreateInfo, long pAllocator, long pSwapchain) Unsafe version of:CreateSwapchainKHR -
vkCreateSwapchainKHR
public static int vkCreateSwapchainKHR(org.lwjgl.vulkan.VkDevice device, VkSwapchainCreateInfoKHR pCreateInfo, @Nullable VkAllocationCallbacks pAllocator, LongBuffer pSwapchain) Create a swapchain.C Specification
To create a swapchain, call:
VkResult vkCreateSwapchainKHR( VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain);Description
As mentioned above, if
vkCreateSwapchainKHRsucceeds, it will return a handle to a swapchain containing an array of at leastpCreateInfo→minImageCountpresentable images.While acquired by the application, presentable images can be used in any way that equivalent non-presentable images can be used. A presentable image is equivalent to a non-presentable image created with the following
VkImageCreateInfoparameters:VkImageCreateInfoFieldValue flagsIMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BITis set ifSWAPCHAIN_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT_KHRis setIMAGE_CREATE_PROTECTED_BITis set ifSWAPCHAIN_CREATE_PROTECTED_BIT_KHRis setIMAGE_CREATE_MUTABLE_FORMAT_BITandIMAGE_CREATE_EXTENDED_USAGE_BIT_KHRare both set ifSWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHRis set all other bits are unsetimageTypeIMAGE_TYPE_2DformatpCreateInfo→imageFormatextent{ pCreateInfo→imageExtent.width,pCreateInfo→imageExtent.height, 1}mipLevels1 arrayLayerspCreateInfo→imageArrayLayerssamplesSAMPLE_COUNT_1_BITtilingIMAGE_TILING_OPTIMALusagepCreateInfo→imageUsagesharingModepCreateInfo→imageSharingModequeueFamilyIndexCountpCreateInfo→queueFamilyIndexCountpQueueFamilyIndicespCreateInfo→pQueueFamilyIndicesinitialLayoutIMAGE_LAYOUT_UNDEFINEDThe
pCreateInfo→surfacemust not be destroyed until after the swapchain is destroyed.If
oldSwapchainisNULL_HANDLE, and the native window referred to bypCreateInfo→surfaceis already associated with a Vulkan swapchain,ERROR_NATIVE_WINDOW_IN_USE_KHRmust be returned.If the native window referred to by
pCreateInfo→surfaceis already associated with a non-Vulkan graphics API surface,ERROR_NATIVE_WINDOW_IN_USE_KHRmust be returned.The native window referred to by
pCreateInfo→surfacemust not become associated with a non-Vulkan graphics API surface before all associated Vulkan swapchains have been destroyed.vkCreateSwapchainKHRwill returnERROR_DEVICE_LOSTif the logical device was lost. TheVkSwapchainKHRis a child of thedevice, and must be destroyed before thedevice. However,VkSurfaceKHRis not a child of anyVkDeviceand is not affected by the lost device. After successfully recreating aVkDevice, the sameVkSurfaceKHRcan be used to create a newVkSwapchainKHR, provided the previous one was destroyed.If the
oldSwapchainparameter ofpCreateInfois a valid swapchain, which has exclusive full-screen access, that access is released frompCreateInfo→oldSwapchain. If the command succeeds in this case, the newly created swapchain will automatically acquire exclusive full-screen access frompCreateInfo→oldSwapchain.Note
This implicit transfer is intended to avoid exiting and entering full-screen exclusive mode, which may otherwise cause unwanted visual updates to the display.
In some cases, swapchain creation may fail if exclusive full-screen mode is requested for application control, but for some implementation-specific reason exclusive full-screen access is unavailable for the particular combination of parameters provided. If this occurs,
ERROR_INITIALIZATION_FAILEDwill be returned.Note
In particular, it will fail if the
imageExtentmember ofpCreateInfodoes not match the extents of the monitor. Other reasons for failure may include the application not being set as high-dpi aware, or if the physical device and monitor are not compatible in this mode.If the
pNextchain ofVkSwapchainCreateInfoKHRincludes aVkSwapchainPresentBarrierCreateInfoNVstructure, then that structure includes additional swapchain creation parameters specific to the present barrier. Swapchain creation may fail if the state of the current system restricts the usage of the present barrier featureVkSurfaceCapabilitiesPresentBarrierNV, or a swapchain itself does not satisfy all the required conditions. In this scenarioERROR_INITIALIZATION_FAILEDis returned.When the
VkSurfaceKHRinVkSwapchainCreateInfoKHRis a display surface, then theVkDisplayModeKHRin display surface’sVkDisplaySurfaceCreateInfoKHRis associated with a particularVkDisplayKHR. Swapchain creation may fail if thatVkDisplayKHRis not acquired by the application. In this scenarioERROR_INITIALIZATION_FAILEDis returned.Valid Usage (Implicit)
devicemust be a validVkDevicehandlepCreateInfomust be a valid pointer to a validVkSwapchainCreateInfoKHRstructure- If
pAllocatoris notNULL,pAllocatormust be a valid pointer to a validVkAllocationCallbacksstructure pSwapchainmust be a valid pointer to aVkSwapchainKHRhandle
Host Synchronization
- Host access to
pCreateInfo→surfacemust be externally synchronized - Host access to
pCreateInfo→oldSwapchainmust be externally synchronized
Return Codes
- On success, this command returns
- On failure, this command returns
See Also
- Parameters:
device- the device to create the swapchain for.pCreateInfo- a pointer to aVkSwapchainCreateInfoKHRstructure specifying the parameters of the created swapchain.pAllocator- the allocator used for host memory allocated for the swapchain object when there is no more specific allocator available (see Memory Allocation).pSwapchain- a pointer to aVkSwapchainKHRhandle in which the created swapchain object will be returned.
-
nvkDestroySwapchainKHR
public static void nvkDestroySwapchainKHR(org.lwjgl.vulkan.VkDevice device, long swapchain, long pAllocator) Unsafe version of:DestroySwapchainKHR -
vkDestroySwapchainKHR
public static void vkDestroySwapchainKHR(org.lwjgl.vulkan.VkDevice device, long swapchain, @Nullable VkAllocationCallbacks pAllocator) Destroy a swapchain object.C Specification
To destroy a swapchain object call:
void vkDestroySwapchainKHR( VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks* pAllocator);Description
The application must not destroy a swapchain until after completion of all outstanding operations on images that were acquired from the swapchain.
swapchainand all associatedVkImagehandles are destroyed, and must not be acquired or used any more by the application. The memory of eachVkImagewill only be freed after that image is no longer used by the presentation engine. For example, if one image of the swapchain is being displayed in a window, the memory for that image may not be freed until the window is destroyed, or another swapchain is created for the window. Destroying the swapchain does not invalidate the parentVkSurfaceKHR, and a new swapchain can be created with it.When a swapchain associated with a display surface is destroyed, if the image most recently presented to the display surface is from the swapchain being destroyed, then either any display resources modified by presenting images from any swapchain associated with the display surface must be reverted by the implementation to their state prior to the first present performed on one of these swapchains, or such resources must be left in their current state.
If
swapchainhas exclusive full-screen access, it is released before the swapchain is destroyed.Valid Usage
- All uses of presentable images acquired from
swapchainmust have completed execution - If
VkAllocationCallbackswere provided whenswapchainwas created, a compatible set of callbacks must be provided here - If no
VkAllocationCallbackswere provided whenswapchainwas created,pAllocatormust beNULL
Valid Usage (Implicit)
devicemust be a validVkDevicehandle- If
swapchainis notNULL_HANDLE,swapchainmust be a validVkSwapchainKHRhandle - If
pAllocatoris notNULL,pAllocatormust be a valid pointer to a validVkAllocationCallbacksstructure - If
swapchainis a valid handle, it must have been created, allocated, or retrieved fromdevice
Host Synchronization
- Host access to
swapchainmust be externally synchronized
See Also
- Parameters:
device- theVkDeviceassociated withswapchain.swapchain- the swapchain to destroy.pAllocator- the allocator used for host memory allocated for the swapchain object when there is no more specific allocator available (see Memory Allocation).
- All uses of presentable images acquired from
-
nvkGetSwapchainImagesKHR
public static int nvkGetSwapchainImagesKHR(org.lwjgl.vulkan.VkDevice device, long swapchain, long pSwapchainImageCount, long pSwapchainImages) Unsafe version of:GetSwapchainImagesKHR- Parameters:
pSwapchainImageCount- a pointer to an integer related to the number of presentable images available or queried, as described below.
-
vkGetSwapchainImagesKHR
public static int vkGetSwapchainImagesKHR(org.lwjgl.vulkan.VkDevice device, long swapchain, IntBuffer pSwapchainImageCount, @Nullable LongBuffer pSwapchainImages) Obtain the array of presentable images associated with a swapchain.C Specification
To obtain the array of presentable images associated with a swapchain, call:
VkResult vkGetSwapchainImagesKHR( VkDevice device, VkSwapchainKHR swapchain, uint32_t* pSwapchainImageCount, VkImage* pSwapchainImages);Description
If
pSwapchainImagesisNULL, then the number of presentable images forswapchainis returned inpSwapchainImageCount. Otherwise,pSwapchainImageCountmust point to a variable set by the application to the number of elements in thepSwapchainImagesarray, and on return the variable is overwritten with the number of structures actually written topSwapchainImages. If the value ofpSwapchainImageCountis less than the number of presentable images forswapchain, at mostpSwapchainImageCountstructures will be written, andINCOMPLETEwill be returned instead ofSUCCESS, to indicate that not all the available presentable images were returned.Valid Usage (Implicit)
devicemust be a validVkDevicehandleswapchainmust be a validVkSwapchainKHRhandlepSwapchainImageCountmust be a valid pointer to auint32_tvalue- If the value referenced by
pSwapchainImageCountis not 0, andpSwapchainImagesis notNULL,pSwapchainImagesmust be a valid pointer to an array ofpSwapchainImageCountVkImagehandles swapchainmust have been created, allocated, or retrieved fromdevice
Return Codes
- On success, this command returns
- On failure, this command returns
- Parameters:
device- the device associated withswapchain.swapchain- the swapchain to query.pSwapchainImageCount- a pointer to an integer related to the number of presentable images available or queried, as described below.pSwapchainImages- eitherNULLor a pointer to an array ofVkImagehandles.
-
nvkAcquireNextImageKHR
public static int nvkAcquireNextImageKHR(org.lwjgl.vulkan.VkDevice device, long swapchain, long timeout, long semaphore, long fence, long pImageIndex) Unsafe version of:AcquireNextImageKHR -
vkAcquireNextImageKHR
public static int vkAcquireNextImageKHR(org.lwjgl.vulkan.VkDevice device, long swapchain, long timeout, long semaphore, long fence, IntBuffer pImageIndex) Retrieve the index of the next available presentable image.C Specification
To acquire an available presentable image to use, and retrieve the index of that image, call:
VkResult vkAcquireNextImageKHR( VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, VkSemaphore semaphore, VkFence fence, uint32_t* pImageIndex);Description
If the
swapchainhas been created with theSWAPCHAIN_CREATE_DEFERRED_MEMORY_ALLOCATION_BIT_EXTflag, the image whose index is returned inpImageIndexwill be fully backed by memory before this call returns to the application, as if it is bound completely and contiguously to a singleVkDeviceMemoryobject.Valid Usage
swapchainmust not be in the retired state- If
semaphoreis notNULL_HANDLE, it must be unsignaled - If
semaphoreis notNULL_HANDLE, it must not have any uncompleted signal or wait operations pending - If
fenceis notNULL_HANDLE,fencemust be unsignaled - If
fenceis notNULL_HANDLE,fencemust not be associated with any other queue command that has not yet completed execution on that queue semaphoreandfencemust not both be equal toNULL_HANDLE- If forward progress cannot be guaranteed for the
surfaceused to create theswapchainmember ofpAcquireInfo,timeoutmust not beUINT64_MAX semaphoremust have aVkSemaphoreTypeofSEMAPHORE_TYPE_BINARY
Valid Usage (Implicit)
devicemust be a validVkDevicehandleswapchainmust be a validVkSwapchainKHRhandle- If
semaphoreis notNULL_HANDLE,semaphoremust be a validVkSemaphorehandle - If
fenceis notNULL_HANDLE,fencemust be a validVkFencehandle pImageIndexmust be a valid pointer to auint32_tvalueswapchainmust have been created, allocated, or retrieved fromdevice- If
semaphoreis a valid handle, it must have been created, allocated, or retrieved fromdevice - If
fenceis a valid handle, it must have been created, allocated, or retrieved fromdevice
Host Synchronization
- Host access to
swapchainmust be externally synchronized - Host access to
semaphoremust be externally synchronized - Host access to
fencemust be externally synchronized
Return Codes
- On success, this command returns
- On failure, this command returns
- Parameters:
device- the device associated withswapchain.swapchain- the non-retired swapchain from which an image is being acquired.timeout- specifies how long the function waits, in nanoseconds, if no image is available.semaphore-NULL_HANDLEor a semaphore to signal.fence-NULL_HANDLEor a fence to signal.pImageIndex- a pointer to auint32_tin which the index of the next image to use (i.e. an index into the array of images returned byvkGetSwapchainImagesKHR) is returned.
-
nvkQueuePresentKHR
public static int nvkQueuePresentKHR(org.lwjgl.vulkan.VkQueue queue, long pPresentInfo) Unsafe version of:QueuePresentKHR -
vkQueuePresentKHR
Queue an image for presentation.C Specification
After queueing all rendering commands and transitioning the image to the correct layout, to queue an image for presentation, call:
VkResult vkQueuePresentKHR( VkQueue queue, const VkPresentInfoKHR* pPresentInfo);Description
Note
There is no requirement for an application to present images in the same order that they were acquired - applications can arbitrarily present any image that is currently acquired.
Note
The origin of the native orientation of the surface coordinate system is not specified in the Vulkan specification; it depends on the platform. For most platforms the origin is by default upper-left, meaning the pixel of the presented
VkImageat coordinates(0,0)would appear at the upper left pixel of the platform surface (assumingSURFACE_TRANSFORM_IDENTITY_BIT_KHR, and the display standing the right way up).The result codes
ERROR_OUT_OF_DATE_KHRandSUBOPTIMAL_KHRhave the same meaning when returned byvkQueuePresentKHRas they do when returned byvkAcquireNextImageKHR. If anyswapchainmember ofpPresentInfowas created withFULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT,ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXTwill be returned if that swapchain does not have exclusive full-screen access, possibly for implementation-specific reasons outside of the application’s control. If multiple swapchains are presented, the result code is determined by applying the following rules in order:- If the device is lost,
ERROR_DEVICE_LOSTis returned. - If any of the target surfaces are no longer available the error
ERROR_SURFACE_LOST_KHRis returned. - If any of the presents would have a result of
ERROR_OUT_OF_DATE_KHRif issued separately thenERROR_OUT_OF_DATE_KHRis returned. - If any of the presents would have a result of
ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXTif issued separately thenERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXTis returned. - If any of the presents would have a result of
SUBOPTIMAL_KHRif issued separately thenSUBOPTIMAL_KHRis returned. - Otherwise
SUCCESSis returned.
Any writes to memory backing the images referenced by the
pImageIndicesandpSwapchainsmembers ofpPresentInfo, that are available beforeQueuePresentKHRis executed, are automatically made visible to the read access performed by the presentation engine. This automatic visibility operation for an image happens-after the semaphore signal operation, and happens-before the presentation engine accesses the image.Presentation is a read-only operation that will not affect the content of the presentable images. Upon reacquiring the image and transitioning it away from the
IMAGE_LAYOUT_PRESENT_SRC_KHRlayout, the contents will be the same as they were prior to transitioning the image to the present source layout and presenting it. However, if a mechanism other than Vulkan is used to modify the platform window associated with the swapchain, the content of all presentable images in the swapchain becomes undefined.Calls to
vkQueuePresentKHRmay block, but must return in finite time. The processing of the presentation happens in issue order with other queue operations, but semaphores must be used to ensure that prior rendering and other commands in the specified queue complete before the presentation begins. The presentation command itself does not delay processing of subsequent commands on the queue. However, presentation requests sent to a particular queue are always performed in order. Exact presentation timing is controlled by the semantics of the presentation engine and native platform in use.If an image is presented to a swapchain created from a display surface, the mode of the associated display will be updated, if necessary, to match the mode specified when creating the display surface. The mode switch and presentation of the specified image will be performed as one atomic operation.
Queueing an image for presentation defines a set of queue operations, including waiting on the semaphores and submitting a presentation request to the presentation engine. However, the scope of this set of queue operations does not include the actual processing of the image by the presentation engine.
If
vkQueuePresentKHRfails to enqueue the corresponding set of queue operations, it may returnERROR_OUT_OF_HOST_MEMORYorERROR_OUT_OF_DEVICE_MEMORY. If it does, the implementation must ensure that the state and contents of any resources or synchronization primitives referenced is unaffected by the call or its failure.If
vkQueuePresentKHRfails in such a way that the implementation is unable to make that guarantee, the implementation must returnERROR_DEVICE_LOST.However, if the presentation request is rejected by the presentation engine with an error
ERROR_OUT_OF_DATE_KHR,ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT, orERROR_SURFACE_LOST_KHR, the set of queue operations are still considered to be enqueued and thus any semaphore wait operation specified inVkPresentInfoKHRwill execute when the corresponding queue operation is complete.vkQueuePresentKHRreleases the acquisition of the images referenced byimageIndices. The queue family corresponding to the queuevkQueuePresentKHRis executed on must have ownership of the presented images as defined in Resource Sharing.vkQueuePresentKHRdoes not alter the queue family ownership, but the presented images must not be used again before they have been reacquired usingvkAcquireNextImageKHR.Note
The application can continue to present any acquired images from a retired swapchain as long as the swapchain has not entered a state that causes
QueuePresentKHRto returnERROR_OUT_OF_DATE_KHR.Valid Usage
- Each element of
pSwapchainsmember ofpPresentInfomust be a swapchain that is created for a surface for which presentation is supported fromqueueas determined using a call tovkGetPhysicalDeviceSurfaceSupportKHR - If more than one member of
pSwapchainswas created from a display surface, all display surfaces referenced that refer to the same display must use the same display mode - If more than one member of
pSwapchainswas created from a display surface, all display surfaces referenced that refer to the same display must use the samestereoType - When a semaphore wait operation referring to a binary semaphore defined by the elements of the
pWaitSemaphoresmember ofpPresentInfoexecutes onqueue, there must be no other queues waiting on the same semaphore - All elements of the
pWaitSemaphoresmember ofpPresentInfomust be created with aVkSemaphoreTypeofSEMAPHORE_TYPE_BINARY - All elements of the
pWaitSemaphoresmember ofpPresentInfomust reference a semaphore signal operation that has been submitted for execution and any semaphore signal operations on which it depends must have also been submitted for execution
Valid Usage (Implicit)
queuemust be a validVkQueuehandlepPresentInfomust be a valid pointer to a validVkPresentInfoKHRstructure
Host Synchronization
- Host access to
queuemust be externally synchronized - Host access to
pPresentInfo→pWaitSemaphores[] must be externally synchronized - Host access to
pPresentInfo→pSwapchains[] must be externally synchronized
Command Properties
Command Buffer Levels Render Pass Scope Video Coding Scope Supported Queue Types Command Type - - - Any - Return Codes
- On success, this command returns
- On failure, this command returns
See Also
- Parameters:
queue- a queue that is capable of presentation to the target surface’s platform on the same device as the image’s swapchain.pPresentInfo- a pointer to aVkPresentInfoKHRstructure specifying parameters of the presentation.
- If the device is lost,
-
nvkGetDeviceGroupPresentCapabilitiesKHR
public static int nvkGetDeviceGroupPresentCapabilitiesKHR(org.lwjgl.vulkan.VkDevice device, long pDeviceGroupPresentCapabilities) Unsafe version of:GetDeviceGroupPresentCapabilitiesKHR -
vkGetDeviceGroupPresentCapabilitiesKHR
public static int vkGetDeviceGroupPresentCapabilitiesKHR(org.lwjgl.vulkan.VkDevice device, VkDeviceGroupPresentCapabilitiesKHR pDeviceGroupPresentCapabilities) Query present capabilities from other physical devices.C Specification
A logical device that represents multiple physical devices may support presenting from images on more than one physical device, or combining images from multiple physical devices.
To query these capabilities, call:
VkResult vkGetDeviceGroupPresentCapabilitiesKHR( VkDevice device, VkDeviceGroupPresentCapabilitiesKHR* pDeviceGroupPresentCapabilities);Valid Usage (Implicit)
devicemust be a validVkDevicehandlepDeviceGroupPresentCapabilitiesmust be a valid pointer to aVkDeviceGroupPresentCapabilitiesKHRstructure
Return Codes
- On success, this command returns
- On failure, this command returns
See Also
- Parameters:
device- the logical device.pDeviceGroupPresentCapabilities- a pointer to aVkDeviceGroupPresentCapabilitiesKHRstructure in which the device’s capabilities are returned.
-
nvkGetDeviceGroupSurfacePresentModesKHR
public static int nvkGetDeviceGroupSurfacePresentModesKHR(org.lwjgl.vulkan.VkDevice device, long surface, long pModes) Unsafe version of:GetDeviceGroupSurfacePresentModesKHR -
vkGetDeviceGroupSurfacePresentModesKHR
public static int vkGetDeviceGroupSurfacePresentModesKHR(org.lwjgl.vulkan.VkDevice device, long surface, IntBuffer pModes) Query present capabilities for a surface.C Specification
Some surfaces may not be capable of using all the device group present modes.
To query the supported device group present modes for a particular surface, call:
VkResult vkGetDeviceGroupSurfacePresentModesKHR( VkDevice device, VkSurfaceKHR surface, VkDeviceGroupPresentModeFlagsKHR* pModes);Description
The modes returned by this command are not invariant, and may change in response to the surface being moved, resized, or occluded. These modes must be a subset of the modes returned by
GetDeviceGroupPresentCapabilitiesKHR.Valid Usage
surfacemust be supported by all physical devices associated withdevice, as reported byGetPhysicalDeviceSurfaceSupportKHRor an equivalent platform-specific mechanism
Valid Usage (Implicit)
devicemust be a validVkDevicehandlesurfacemust be a validVkSurfaceKHRhandlepModesmust be a valid pointer to aVkDeviceGroupPresentModeFlagsKHRvalue- Both of
device, andsurfacemust have been created, allocated, or retrieved from the sameVkInstance
Host Synchronization
- Host access to
surfacemust be externally synchronized
Return Codes
- On success, this command returns
- On failure, this command returns
- Parameters:
device- the logical device.surface- the surface.pModes- a pointer to aVkDeviceGroupPresentModeFlagsKHRin which the supported device group present modes for the surface are returned.
-
nvkGetPhysicalDevicePresentRectanglesKHR
public static int nvkGetPhysicalDevicePresentRectanglesKHR(org.lwjgl.vulkan.VkPhysicalDevice physicalDevice, long surface, long pRectCount, long pRects) Unsafe version of:GetPhysicalDevicePresentRectanglesKHR- Parameters:
pRectCount- a pointer to an integer related to the number of rectangles available or queried, as described below.
-
vkGetPhysicalDevicePresentRectanglesKHR
public static int vkGetPhysicalDevicePresentRectanglesKHR(org.lwjgl.vulkan.VkPhysicalDevice physicalDevice, long surface, IntBuffer pRectCount, @Nullable VkRect2D.Buffer pRects) Query present rectangles for a surface on a physical device.C Specification
When using
DEVICE_GROUP_PRESENT_MODE_LOCAL_MULTI_DEVICE_BIT_KHR, the application may need to know which regions of the surface are used when presenting locally on each physical device. Presentation of swapchain images to this surface need only have valid contents in the regions returned by this command.To query a set of rectangles used in presentation on the physical device, call:
VkResult vkGetPhysicalDevicePresentRectanglesKHR( VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t* pRectCount, VkRect2D* pRects);Description
If
pRectsisNULL, then the number of rectangles used when presenting the givensurfaceis returned inpRectCount. Otherwise,pRectCountmust point to a variable set by the application to the number of elements in thepRectsarray, and on return the variable is overwritten with the number of structures actually written topRects. If the value ofpRectCountis less than the number of rectangles, at mostpRectCountstructures will be written, andINCOMPLETEwill be returned instead ofSUCCESS, to indicate that not all the available rectangles were returned.The values returned by this command are not invariant, and may change in response to the surface being moved, resized, or occluded.
The rectangles returned by this command must not overlap.
Valid Usage
surfacemust be a validVkSurfaceKHRhandlesurfacemust be supported byphysicalDevice, as reported byGetPhysicalDeviceSurfaceSupportKHRor an equivalent platform-specific mechanism
Valid Usage (Implicit)
physicalDevicemust be a validVkPhysicalDevicehandlesurfacemust be a validVkSurfaceKHRhandlepRectCountmust be a valid pointer to auint32_tvalue- If the value referenced by
pRectCountis not 0, andpRectsis notNULL,pRectsmust be a valid pointer to an array ofpRectCountVkRect2Dstructures - Both of
physicalDevice, andsurfacemust have been created, allocated, or retrieved from the sameVkInstance
Host Synchronization
- Host access to
surfacemust be externally synchronized
Return Codes
- On success, this command returns
- On failure, this command returns
See Also
- Parameters:
physicalDevice- the physical device.surface- the surface.pRectCount- a pointer to an integer related to the number of rectangles available or queried, as described below.pRects- eitherNULLor a pointer to an array ofVkRect2Dstructures.
-
nvkAcquireNextImage2KHR
public static int nvkAcquireNextImage2KHR(org.lwjgl.vulkan.VkDevice device, long pAcquireInfo, long pImageIndex) Unsafe version of:AcquireNextImage2KHR -
vkAcquireNextImage2KHR
public static int vkAcquireNextImage2KHR(org.lwjgl.vulkan.VkDevice device, VkAcquireNextImageInfoKHR pAcquireInfo, IntBuffer pImageIndex) Retrieve the index of the next available presentable image.C Specification
To acquire an available presentable image to use, and retrieve the index of that image, call:
VkResult vkAcquireNextImage2KHR( VkDevice device, const VkAcquireNextImageInfoKHR* pAcquireInfo, uint32_t* pImageIndex);Description
If the
swapchainhas been created with theSWAPCHAIN_CREATE_DEFERRED_MEMORY_ALLOCATION_BIT_EXTflag, the image whose index is returned inpImageIndexwill be fully backed by memory before this call returns to the application.Valid Usage
- If forward progress cannot be guaranteed for the
surfaceused to createswapchain, thetimeoutmember ofpAcquireInfomust not beUINT64_MAX
Valid Usage (Implicit)
devicemust be a validVkDevicehandlepAcquireInfomust be a valid pointer to a validVkAcquireNextImageInfoKHRstructurepImageIndexmust be a valid pointer to auint32_tvalue
Return Codes
- On success, this command returns
- On failure, this command returns
See Also
- Parameters:
device- the device associated withswapchain.pAcquireInfo- a pointer to aVkAcquireNextImageInfoKHRstructure containing parameters of the acquire.pImageIndex- a pointer to auint32_tvalue specifying the index of the next image to use.
- If forward progress cannot be guaranteed for the
-
vkCreateSwapchainKHR
public static int vkCreateSwapchainKHR(org.lwjgl.vulkan.VkDevice device, VkSwapchainCreateInfoKHR pCreateInfo, @Nullable VkAllocationCallbacks pAllocator, long[] pSwapchain) Array version of:CreateSwapchainKHR -
vkGetSwapchainImagesKHR
public static int vkGetSwapchainImagesKHR(org.lwjgl.vulkan.VkDevice device, long swapchain, int[] pSwapchainImageCount, long @Nullable [] pSwapchainImages) Array version of:GetSwapchainImagesKHR -
vkAcquireNextImageKHR
public static int vkAcquireNextImageKHR(org.lwjgl.vulkan.VkDevice device, long swapchain, long timeout, long semaphore, long fence, int[] pImageIndex) Array version of:AcquireNextImageKHR -
vkGetDeviceGroupSurfacePresentModesKHR
public static int vkGetDeviceGroupSurfacePresentModesKHR(org.lwjgl.vulkan.VkDevice device, long surface, int[] pModes) Array version of:GetDeviceGroupSurfacePresentModesKHR -
vkGetPhysicalDevicePresentRectanglesKHR
public static int vkGetPhysicalDevicePresentRectanglesKHR(org.lwjgl.vulkan.VkPhysicalDevice physicalDevice, long surface, int[] pRectCount, @Nullable VkRect2D.Buffer pRects) Array version of:GetPhysicalDevicePresentRectanglesKHR -
vkAcquireNextImage2KHR
public static int vkAcquireNextImage2KHR(org.lwjgl.vulkan.VkDevice device, VkAcquireNextImageInfoKHR pAcquireInfo, int[] pImageIndex) Array version of:AcquireNextImage2KHR
-