Skip to content

Commit

Permalink
Merge pull request #80571 from darksylinc/matias-resize-window-fix
Browse files Browse the repository at this point in the history
Fix validation error when resizing window
  • Loading branch information
akien-mga committed Aug 16, 2023
2 parents 6c3735c + 0b09fdd commit d1b8e9a
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions drivers/vulkan/vulkan_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1704,17 +1704,6 @@ Error VulkanContext::_window_create(DisplayServer::WindowID p_window_id, Display
Error err = _update_swap_chain(&window);
ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE);

VkSemaphoreCreateInfo semaphoreCreateInfo = {
/*sType*/ VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
/*pNext*/ nullptr,
/*flags*/ 0,
};

for (uint32_t i = 0; i < FRAME_LAG; i++) {
VkResult vkerr = vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &window.image_acquired_semaphores[i]);
ERR_FAIL_COND_V(vkerr, ERR_CANT_CREATE);
}

windows[p_window_id] = window;
return OK;
}
Expand Down Expand Up @@ -1764,9 +1753,6 @@ VkFramebuffer VulkanContext::window_get_framebuffer(DisplayServer::WindowID p_wi
void VulkanContext::window_destroy(DisplayServer::WindowID p_window_id) {
ERR_FAIL_COND(!windows.has(p_window_id));
_clean_up_swap_chain(&windows[p_window_id]);
for (uint32_t i = 0; i < FRAME_LAG; i++) {
vkDestroySemaphore(device, windows[p_window_id].image_acquired_semaphores[i], nullptr);
}

vkDestroySurfaceKHR(inst, windows[p_window_id].surface, nullptr);
windows.erase(p_window_id);
Expand Down Expand Up @@ -1796,6 +1782,17 @@ Error VulkanContext::_clean_up_swap_chain(Window *window) {
if (separate_present_queue) {
vkDestroyCommandPool(device, window->present_cmd_pool, nullptr);
}

for (uint32_t i = 0; i < FRAME_LAG; i++) {
// Destroy the semaphores now (we'll re-create it later if we have to).
// We must do this because the semaphore cannot be reused if it's in a signaled state
// (which happens if vkAcquireNextImageKHR returned VK_ERROR_OUT_OF_DATE_KHR or VK_SUBOPTIMAL_KHR)
// The only way to reset it would be to present the swapchain... the one we just destroyed.
// And the API has no way to "unsignal" the semaphore.
vkDestroySemaphore(device, window->image_acquired_semaphores[i], nullptr);
window->image_acquired_semaphores[i] = 0;
}

return OK;
}

Expand Down Expand Up @@ -2179,6 +2176,17 @@ Error VulkanContext::_update_swap_chain(Window *window) {
// Reset current buffer.
window->current_buffer = 0;

VkSemaphoreCreateInfo semaphoreCreateInfo = {
/*sType*/ VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
/*pNext*/ nullptr,
/*flags*/ 0,
};

for (uint32_t i = 0; i < FRAME_LAG; i++) {
VkResult vkerr = vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &window->image_acquired_semaphores[i]);
ERR_FAIL_COND_V(vkerr, ERR_CANT_CREATE);
}

return OK;
}

Expand Down

0 comments on commit d1b8e9a

Please sign in to comment.