Skip to content

Commit

Permalink
renderer_vulkan: Fix deadlock when resizing the SDL window
Browse files Browse the repository at this point in the history
 Commit 400da1a add ability to handle recreation of the swapchain which
fix black screen under XWayland. Unfortunately, that commit doesn't
account for rapid swapchain recreation caused by resizing window.

 This commit aim to solve that issue by delay resetting the frame's
present done fence until after we know for sure we will be submitting
work with it.
  • Loading branch information
ngoquang2708 committed Dec 25, 2024
1 parent a89c29c commit 814f6aa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
18 changes: 6 additions & 12 deletions src/video_core/renderer_vulkan/vk_presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,15 +628,14 @@ Frame* Presenter::PrepareFrameInternal(VideoCore::ImageId image_id, bool is_eop)
}

void Presenter::Present(Frame* frame) {
// Recreate the swapchain if the window was resized.
if (window.GetWidth() != swapchain.GetExtent().width ||
window.GetHeight() != swapchain.GetExtent().height) {
// Recreate the swapchain if the window was resized or failed to acquire next image.
while (window.GetWidth() != swapchain.GetExtent().width ||
window.GetHeight() != swapchain.GetExtent().height || !swapchain.AcquireNextImage()) {
swapchain.Recreate(window.GetWidth(), window.GetHeight());
}

if (!swapchain.AcquireNextImage()) {
swapchain.Recreate(window.GetWidth(), window.GetHeight());
}
// Reset fence for queue submission.
instance.GetDevice().resetFences(frame->present_done);

ImGui::Core::NewFrame();

Expand Down Expand Up @@ -733,9 +732,7 @@ void Presenter::Present(Frame* frame) {

// Present to swapchain.
std::scoped_lock submit_lock{Scheduler::submit_mutex};
if (!swapchain.Present()) {
swapchain.Recreate(window.GetWidth(), window.GetHeight());
}
swapchain.Present();

// Free the frame for reuse
std::scoped_lock fl{free_mutex};
Expand Down Expand Up @@ -776,9 +773,6 @@ Frame* Presenter::GetRenderFrame() {
}
}

// Reset fence for next queue submission.
device.resetFences(frame->present_done);

// If the window dimensions changed, recreate this frame
if (frame->width != window.GetWidth() || frame->height != window.GetHeight()) {
RecreateFrame(frame, window.GetWidth(), window.GetHeight());
Expand Down
4 changes: 1 addition & 3 deletions src/video_core/renderer_vulkan/vk_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ bool Swapchain::AcquireNextImage() {
return !needs_recreation;
}

bool Swapchain::Present() {
void Swapchain::Present() {

const vk::PresentInfoKHR present_info = {
.waitSemaphoreCount = 1,
Expand All @@ -131,8 +131,6 @@ bool Swapchain::Present() {
}

frame_index = (frame_index + 1) % image_count;

return !needs_recreation;
}

void Swapchain::FindPresentFormat() {
Expand Down
2 changes: 1 addition & 1 deletion src/video_core/renderer_vulkan/vk_swapchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Swapchain {
bool AcquireNextImage();

/// Presents the current image and move to the next one
bool Present();
void Present();

vk::SurfaceKHR GetSurface() const {
return surface;
Expand Down

0 comments on commit 814f6aa

Please sign in to comment.