119 VkSurfaceCapabilitiesKHR surfaceCaps;
120 VkSurfaceFormatKHR *surfaceFormats =
NULL;
121 VkPresentModeKHR *presentModes =
NULL;
122 uint32_t formatCount, presentModesCount;
129 surfaceFormats = (VkSurfaceFormatKHR *)malloc(formatCount *
sizeof(VkSurfaceFormatKHR));
133 if (presentModesCount > 0)
135 presentModes = (VkPresentModeKHR *)malloc(presentModesCount *
sizeof(VkPresentModeKHR));
139 for (
int i = 0;
i < presentModesCount;
i++)
148 VkPresentModeKHR swapPresentMode =
getSwapPresentMode(presentModes, presentModesCount,
vk_vsync->
value > 0 ? VK_PRESENT_MODE_FIFO_KHR : VK_PRESENT_MODE_MAILBOX_KHR);
149 free(surfaceFormats);
152 VkExtent2D extent = surfaceCaps.currentExtent;
153 if(extent.width == UINT32_MAX || extent.height == UINT32_MAX)
155 extent.width =
max(surfaceCaps.minImageExtent.width,
min(surfaceCaps.maxImageExtent.width,
vid.
width));
156 extent.height =
max(surfaceCaps.minImageExtent.height,
min(surfaceCaps.maxImageExtent.height,
vid.
height));
160 uint32_t imageCount =
max(2, surfaceCaps.minImageCount);
161 if (swapPresentMode == VK_PRESENT_MODE_MAILBOX_KHR)
162 imageCount =
max(3, surfaceCaps.minImageCount);
164 if (surfaceCaps.maxImageCount > 0)
165 imageCount =
min(imageCount, surfaceCaps.maxImageCount);
168 VkSwapchainCreateInfoKHR scCreateInfo = {
169 .sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
173 .minImageCount = imageCount,
174 .imageFormat = swapSurfaceFormat.format,
175 .imageColorSpace = swapSurfaceFormat.colorSpace,
176 .imageExtent = extent,
177 .imageArrayLayers = 1,
178 .imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
179 .imageSharingMode = VK_SHARING_MODE_EXCLUSIVE,
180 .queueFamilyIndexCount = 0,
181 .pQueueFamilyIndices =
NULL,
182 .preTransform = surfaceCaps.supportedTransforms & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR ? VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR : surfaceCaps.currentTransform,
184 .presentMode = swapPresentMode,
186 .oldSwapchain = oldSwapchain
192 scCreateInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
193 scCreateInfo.queueFamilyIndexCount = 2;
194 scCreateInfo.pQueueFamilyIndices = queueFamilyIndices;
203 if (res != VK_SUCCESS)
211 if (oldSwapchain != VK_NULL_HANDLE)