From e8bcca4bdc947caaca6742cdefc60fb9a4f57e9a Mon Sep 17 00:00:00 2001 From: Jason Fielder Date: Thu, 22 Sep 2022 18:03:29 +0200 Subject: GPU: Ensure rendering operations occur within GPU render boundaries. This is required by the Metal backend to perform flushing of temporary objective-C resources. This is implemented as a global autoreleasepool, and is to ensure consistency such that all rendering operations, whether called via events, or via main loop will be within an autoreleasepool. Authored by Apple: Michael Parkin-White Ref T96261 Reviewed By: fclem Differential Revision: https://developer.blender.org/D15900 --- source/blender/windowmanager/intern/wm_event_system.cc | 8 ++++++++ source/blender/windowmanager/intern/wm_window.c | 4 ++++ 2 files changed, 12 insertions(+) (limited to 'source/blender/windowmanager') diff --git a/source/blender/windowmanager/intern/wm_event_system.cc b/source/blender/windowmanager/intern/wm_event_system.cc index c26696704dd..de01c2080da 100644 --- a/source/blender/windowmanager/intern/wm_event_system.cc +++ b/source/blender/windowmanager/intern/wm_event_system.cc @@ -56,6 +56,8 @@ #include "ED_util.h" #include "ED_view3d.h" +#include "GPU_context.h" + #include "RNA_access.h" #include "UI_interface.h" @@ -484,11 +486,15 @@ static void wm_event_execute_timers(bContext *C) void wm_event_do_notifiers(bContext *C) { + /* Ensure insiude render boundary. */ + GPU_render_begin(); + /* Run the timer before assigning `wm` in the unlikely case a timer loads a file, see T80028. */ wm_event_execute_timers(C); wmWindowManager *wm = CTX_wm_manager(C); if (wm == nullptr) { + GPU_render_end(); return; } @@ -691,6 +697,8 @@ void wm_event_do_notifiers(bContext *C) /* Auto-run warning. */ wm_test_autorun_warning(C); + + GPU_render_end(); } static bool wm_event_always_pass(const wmEvent *event) diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index dea875becb1..8d091a02eb5 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -580,6 +580,7 @@ static void wm_window_ghostwindow_add(wmWindowManager *wm, if (ghostwin) { win->gpuctx = GPU_context_create(ghostwin, NULL); + GPU_render_begin(); /* needed so we can detect the graphics card below */ GPU_init(); @@ -621,6 +622,7 @@ static void wm_window_ghostwindow_add(wmWindowManager *wm, GPU_clear_color(0.55f, 0.55f, 0.55f, 1.0f); // GHOST_SetWindowState(ghostwin, GHOST_kWindowStateModified); + GPU_render_end(); } else { wm_window_set_drawable(wm, prev_windrawable, false); @@ -1504,6 +1506,7 @@ static bool wm_window_timer(const bContext *C) void wm_window_process_events(const bContext *C) { BLI_assert(BLI_thread_is_main()); + GPU_render_begin(); bool has_event = GHOST_ProcessEvents(g_system, false); /* `false` is no wait. */ @@ -1516,6 +1519,7 @@ void wm_window_process_events(const bContext *C) * processing/dispatching but also handling. */ has_event |= wm_xr_events_handle(CTX_wm_manager(C)); #endif + GPU_render_end(); /* When there is no event, sleep 5 milliseconds not to use too much CPU when idle. * -- cgit v1.2.3