MCPcopy Create free account
hub / github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator / CreateSwapchain

Function CreateSwapchain

src/VulkanSample.cpp:945–1404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

943}
944
945static void CreateSwapchain()
946{
947 // Query surface formats.
948
949 ERR_GUARD_VULKAN( vkGetPhysicalDeviceSurfaceCapabilitiesKHR(g_hPhysicalDevice, g_hSurface, &g_SurfaceCapabilities) );
950
951 uint32_t formatCount = 0;
952 ERR_GUARD_VULKAN( vkGetPhysicalDeviceSurfaceFormatsKHR(g_hPhysicalDevice, g_hSurface, &formatCount, nullptr) );
953 g_SurfaceFormats.resize(formatCount);
954 ERR_GUARD_VULKAN( vkGetPhysicalDeviceSurfaceFormatsKHR(g_hPhysicalDevice, g_hSurface, &formatCount, g_SurfaceFormats.data()) );
955
956 uint32_t presentModeCount = 0;
957 ERR_GUARD_VULKAN( vkGetPhysicalDeviceSurfacePresentModesKHR(g_hPhysicalDevice, g_hSurface, &presentModeCount, nullptr) );
958 g_PresentModes.resize(presentModeCount);
959 ERR_GUARD_VULKAN( vkGetPhysicalDeviceSurfacePresentModesKHR(g_hPhysicalDevice, g_hSurface, &presentModeCount, g_PresentModes.data()) );
960
961 // Create swap chain
962
963 g_SurfaceFormat = ChooseSurfaceFormat();
964 VkPresentModeKHR presentMode = ChooseSwapPresentMode();
965 g_Extent = ChooseSwapExtent();
966
967 g_SwapchainImageCount = g_SurfaceCapabilities.minImageCount + 1;
968 if((g_SurfaceCapabilities.maxImageCount > 0) &&
969 (g_SwapchainImageCount > g_SurfaceCapabilities.maxImageCount))
970 {
971 g_SwapchainImageCount = g_SurfaceCapabilities.maxImageCount;
972 }
973
974 VkSwapchainCreateInfoKHR swapChainInfo = { VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR };
975 swapChainInfo.surface = g_hSurface;
976 swapChainInfo.minImageCount = g_SwapchainImageCount;
977 swapChainInfo.imageFormat = g_SurfaceFormat.format;
978 swapChainInfo.imageColorSpace = g_SurfaceFormat.colorSpace;
979 swapChainInfo.imageExtent = g_Extent;
980 swapChainInfo.imageArrayLayers = 1;
981 swapChainInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
982 swapChainInfo.preTransform = g_SurfaceCapabilities.currentTransform;
983 swapChainInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
984 swapChainInfo.presentMode = presentMode;
985 swapChainInfo.clipped = VK_TRUE;
986 swapChainInfo.oldSwapchain = g_hSwapchain;
987
988 uint32_t queueFamilyIndices[] = { g_GraphicsQueueFamilyIndex, g_PresentQueueFamilyIndex };
989 if(g_PresentQueueFamilyIndex != g_GraphicsQueueFamilyIndex)
990 {
991 swapChainInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
992 swapChainInfo.queueFamilyIndexCount = 2;
993 swapChainInfo.pQueueFamilyIndices = queueFamilyIndices;
994 }
995 else
996 {
997 swapChainInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
998 }
999
1000 VkSwapchainKHR hNewSwapchain = VK_NULL_HANDLE;
1001 ERR_GUARD_VULKAN( vkCreateSwapchainKHR(g_hDevice, &swapChainInfo, g_Allocs, &hNewSwapchain) );
1002 if(g_hSwapchain != VK_NULL_HANDLE)

Callers 2

InitializeApplicationFunction · 0.85
RecreateSwapChainFunction · 0.85

Calls 11

ChooseSurfaceFormatFunction · 0.85
ChooseSwapPresentModeFunction · 0.85
ChooseSwapExtentFunction · 0.85
SetDebugUtilsObjectNameFunction · 0.85
FindDepthFormatFunction · 0.85
vmaCreateImageFunction · 0.85
LoadShaderFunction · 0.85
resizeMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected