pkdawson / imgui-godot

Dear ImGui plugin for Godot 4
MIT License
318 stars 18 forks source link

Vulkan errors with "Multi-Threaded" thread model #34

Closed lexika979 closed 1 year ago

lexika979 commented 1 year ago

When using the "Multi-Threaded" thread model in Godot (4.0.3.stable), Vulkan fails to submit its graphics queue and fails to create the swapchain.

OS: Windows 11 22H2, build 22621.1702

Error messages: E 0:00:09:0012 swap_buffers: Vulkan: Cannot submit graphics queue. Error code: VK_ERROR_DEVICE_LOST <C++ Error> Condition "err" is true. Returning: ERR_CANT_CREATE <C++ Source> drivers/vulkan/vulkan_context.cpp:2357 @ swap_buffers()

E 0:00:09:0013 prepare_buffers: Vulkan: Did not create swapchain successfully. Error code: VK_NOT_READY <C++ Error> Condition "err != VK_SUCCESS" is true. Breaking. <C++ Source> drivers/vulkan/vulkan_context.cpp:2280 @ prepare_buffers()

To reproduce, just try to use imgui-godot with the "Multi-Threaded" thread model. (This appears to only happen sometimes, but should be reproduceable after a couple of restarts)

pkdawson commented 1 year ago

Can't reproduce with the demo project, on Windows with the latest NVIDIA drivers. Are you using an AMD or Intel GPU?

I'll have to check out how Godot's multi-threaded rendering works, and see if I can find the problem anyway.

lexika979 commented 1 year ago

I'm on a NVIDIA RTX 3070Ti with latest drivers

lexika979 commented 1 year ago

I'll try to find a 100% reproduceable case

pkdawson commented 1 year ago

Yeah that would be a big help, if you can send me a project where this is reproducible. It probably won't be 100% consistent if this is a race condition.

I have a good idea how to address this, using the frame_pre_draw signal, but it'll require some nontrivial refactoring for thread safety.

pkdawson commented 1 year ago

Found a simple fix on my end - though it will block the main thread until rendering finishes, so I'm also considering more complex solutions for better performance. Might be best to wait until Godot 4.1 and think about how best to exploit its multi-threading features.

But I also found a pretty serious Godot bug in testing, which will just crash the game if you resize the window.

https://github.com/godotengine/godot/issues/64766

I can release my quick fix pretty soon, but it would still frequently crash when using multi-viewports because of that bug.

pkdawson commented 1 year ago

I've got a solution I'm happy with now, with minimal locking. The only real inefficiency is that the ImGui draw data needs to be copied on every frame.

@lexika979 Try out v4.0.0 and let me know how it works https://github.com/pkdawson/imgui-godot/releases/tag/v4.0.0

lexika979 commented 1 year ago

It works! Thank you very much :)