| 110 | } |
| 111 | |
| 112 | VkResult UpdateSwapChain(PhysicalDevice* physicalDevice, LogicalDevice* logicalDevice, |
| 113 | uint32_t* wantedWidth, uint32_t* wantedHeight, |
| 114 | bool wantVSync, SwapChainCapabilities& capabilities, SwapChain* swapChain) |
| 115 | { |
| 116 | VkSwapchainKHR vk_old_swap_chain = swapChain->m_SwapChain; |
| 117 | uint64_t old_last_present_id = swapChain->m_LastPresentId; |
| 118 | VkDevice vk_device = logicalDevice->m_Device; |
| 119 | VkPhysicalDevice vk_physical_device = physicalDevice->m_Device; |
| 120 | VkPresentModeKHR vk_present_mode = VK_PRESENT_MODE_FIFO_KHR; |
| 121 | |
| 122 | if (!wantVSync) |
| 123 | { |
| 124 | for (uint32_t i=0; i < capabilities.m_PresentModes.Size(); i++) |
| 125 | { |
| 126 | VkPresentModeKHR vk_present_mode_candidate = capabilities.m_PresentModes[i]; |
| 127 | |
| 128 | if (vk_present_mode_candidate == VK_PRESENT_MODE_MAILBOX_KHR) |
| 129 | { |
| 130 | vk_present_mode = vk_present_mode_candidate; |
| 131 | break; |
| 132 | } |
| 133 | else if (vk_present_mode_candidate == VK_PRESENT_MODE_IMMEDIATE_KHR) |
| 134 | { |
| 135 | vk_present_mode = vk_present_mode_candidate; |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | VkExtent2D vk_current_extent = capabilities.m_SurfaceCapabilities.currentExtent; |
| 141 | VkExtent2D vk_extent = {}; |
| 142 | |
| 143 | if (vk_current_extent.width == 0xFFFFFFFF || vk_current_extent.height == 0xFFFFFFFF) |
| 144 | { |
| 145 | // Clamp swap buffer extent to our wanted width / height. |
| 146 | vk_extent.width = *wantedWidth; |
| 147 | vk_extent.height = *wantedHeight; |
| 148 | } |
| 149 | else |
| 150 | { |
| 151 | vk_extent = vk_current_extent; |
| 152 | *wantedWidth = vk_extent.width; |
| 153 | *wantedHeight = vk_extent.height; |
| 154 | } |
| 155 | |
| 156 | // From the docs: |
| 157 | // ============== |
| 158 | // minImageCount: the minimum number of images the specified device supports for a swapchain created for the surface, and will be at least one. |
| 159 | // maxImageCount: the maximum number of images the specified device supports for a swapchain created for the surface, |
| 160 | // and will be either 0, or greater than or equal to minImageCount. A value of 0 means that there is no limit on the number of images, |
| 161 | // though there may be limits related to the total amount of memory used by presentable images. |
| 162 | |
| 163 | // The +1 here is to add a little bit of headroom, from vulkan-tutorial.com: |
| 164 | // "we may sometimes have to wait on the driver to complete internal operations |
| 165 | // before we can acquire another image to render to" |
| 166 | uint32_t swap_chain_image_count = capabilities.m_SurfaceCapabilities.minImageCount + 1; |
| 167 | |
| 168 | if (capabilities.m_SurfaceCapabilities.maxImageCount > 0) |
| 169 | { |
no test coverage detected