| 943 | } |
| 944 | |
| 945 | static 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) |
no test coverage detected