#60

Threaded Rendering: Is it safe to asynchronously call _RenderDrawData from another thread?

Openb1skitopened 11mo ago

Is it safe to call the backend _RenderDrawData function from one thread (e.g. render), while another thread is executing ImGui calls (e.g. UI)?

I assume this is the point of this helper and that it is indeed safe, but it's not explicitly clear (to me, at least) from the usage instructions in imgui_threaded_rendering.h so I wanted to confirm. Or, are we expected to maintain a global ImGui mutex for all multi-threaded access?

I hope this is an appropriate place to post this question - apologies if not.

Activity

1
ocornut11mo ago

I realize this is ambiguous since this helper is a separate repro, but since the question is rather generic it would best be on imgui/ repro. See e.g. https://github.com/ocornut/imgui/issues/8532, https://github.com/ocornut/imgui/issues/1860, https://github.com/ocornut/imgui/issues/3515, https://github.com/ocornut/imgui/issues/8597

The imgui_threaded_rendering.h ensure you have access to a ImDrawData instance that's not used by the other threads/domains, so in theory yes.

However, two things:

  • Default rendering backends are not particularly tested or adjusted for it. So it depends on your renderer backend. Using of multi-contexts usually use their own rendering backend.
  • There's probably an unclosed issue with access to the ImDrawData::Textures array. See https://github.com/ocornut/imgui/issues/8597. Your feedback here would be welcome.