Skip to content

Commit

Permalink
Avoid blocking for resize to go through.
Browse files Browse the repository at this point in the history
With DXGI interop this will break since DXGI may block on message loop,
and we don't bother with threaded ML on non-Windows anymore anyway.
  • Loading branch information
Themaister committed Feb 25, 2024
1 parent 2265b69 commit b1d742a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 16 deletions.
15 changes: 1 addition & 14 deletions application/platforms/application_sdl3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,25 +389,12 @@ struct WSIPlatformSDL : GraniteWSIPlatform

void notify_resize(unsigned width_, unsigned height_)
{
uint64_t current_resize_timestamp = swapchain_dimension_update_timestamp;

LOGI("Resize: %u x %u\n", width_, height_);
push_task_to_async_thread([=]() {
resize = true;
width = width_;
height = height_;
});

if (options.threaded)
{
// Give the async thread a chance to catch up with main thread so it can create a new swapchain before
// we invalidate the swapchain again.
// There is a gap when querying swapchain dimensions and when we create the swapchain.
// On most platforms, the query must match the swapchain,
// so if we keep processing OS events, things will get out of sync.
// Need to observe that the async thread updates the swapchain dimensions at least once.
while (current_resize_timestamp == swapchain_dimension_update_timestamp && async_loop_alive)
process_events_main_thread_blocking();
}
}

void notify_current_swapchain_dimensions(unsigned width_, unsigned height_) override
Expand Down
2 changes: 2 additions & 0 deletions vulkan/wsi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ bool WSI::begin_frame()
LOGI("AcquireNextImageKHR is suboptimal, will recreate.\n");
#endif
swapchain_is_suboptimal = true;
LOGW("Swapchain suboptimal.\n");
}

if (result >= 0)
Expand Down Expand Up @@ -576,6 +577,7 @@ bool WSI::begin_frame()
}
else if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT)
{
LOGW("Swapchain out of date.\n");
VK_ASSERT(swapchain_width != 0);
VK_ASSERT(swapchain_height != 0);

Expand Down
2 changes: 0 additions & 2 deletions vulkan/wsi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class WSIPlatform
resize = false;
current_swapchain_width = width;
current_swapchain_height = height;
swapchain_dimension_update_timestamp++;
}

virtual uint32_t get_surface_width() = 0;
Expand Down Expand Up @@ -132,7 +131,6 @@ class WSIPlatform
protected:
unsigned current_swapchain_width = 0;
unsigned current_swapchain_height = 0;
uint64_t swapchain_dimension_update_timestamp = 0;
bool resize = false;

private:
Expand Down

0 comments on commit b1d742a

Please sign in to comment.