Rendering on a separate thread with a resizable window

My window handling code for Win32 / X11 / Cocoa lives in the main thread, and all my Vulkan code is compartmentalized into the rendering thread. The only place this causes problems is with window resizing. The main thread is capable of resizing a window while the rendering thread is in the middle of a render. I can generate validation layer errors in Vulkan that says something like “the swap chain image size does not match device window size” or something like that.

The application is a 3D game engine that is intended for use both as a real-time game engine and as a 3D rendering system embedded in a GUI application. It will run in both real-time and event-driven apps with multiple 3D viewports in a resizable window.

I’ve tried many things but have encountered the following problems:

  • WM_WINDOWPOSCHANGING / WM_WINDOWPOSCHANGED don’t actually seem to occur in pairs, so it’s difficult to use those to toggle a mutex.
  • There seems to be no LInux equivalent to the above events.

At this point I am leaning towards implementing a multithreaded “game” mode that does not support resizable windows, along with a single-threaded application mode that does support resizable windows. Before I give up on this, can anyone advise me otherwise? Am I trying to do something no sane person would do or is there a known common solution to this problem?

I’ve got this working in a multithreaded mode for games and a single-threaded mode for desktop applications. This actually works pretty nicely, because a desktop application usually has a resizable window but a game with a resizable window is something I can live without. Also, a multithreaded renderer has a higher framerate but also has increased latency. Framerates don’t matter for an event-driven desktop application, but latency does, because this affects how quickly the application responds to mouse input.

So the whole thing works out rather well.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.