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
This commit is contained in:
@@ -591,6 +591,7 @@ static void eevee_lightbake_context_enable(EEVEE_LightBake *lbake)
|
||||
if (GPU_use_main_context_workaround() && !BLI_thread_is_main()) {
|
||||
GPU_context_main_lock();
|
||||
DRW_opengl_context_enable();
|
||||
GPU_render_begin();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -604,10 +605,12 @@ static void eevee_lightbake_context_enable(EEVEE_LightBake *lbake)
|
||||
else {
|
||||
DRW_opengl_context_enable();
|
||||
}
|
||||
GPU_render_begin();
|
||||
}
|
||||
|
||||
static void eevee_lightbake_context_disable(EEVEE_LightBake *lbake)
|
||||
{
|
||||
GPU_render_end();
|
||||
if (GPU_use_main_context_workaround() && !BLI_thread_is_main()) {
|
||||
DRW_opengl_context_disable();
|
||||
GPU_context_main_unlock();
|
||||
|
@@ -29,6 +29,8 @@
|
||||
|
||||
#include "ED_paint.h"
|
||||
|
||||
#include "GPU_context.h"
|
||||
|
||||
#include "workbench_engine.h"
|
||||
#include "workbench_private.h"
|
||||
|
||||
@@ -36,6 +38,7 @@
|
||||
|
||||
void workbench_engine_init(void *ved)
|
||||
{
|
||||
GPU_render_begin();
|
||||
WORKBENCH_Data *vedata = ved;
|
||||
WORKBENCH_StorageList *stl = vedata->stl;
|
||||
WORKBENCH_TextureList *txl = vedata->txl;
|
||||
@@ -64,6 +67,7 @@ void workbench_engine_init(void *ved)
|
||||
workbench_dof_engine_init(vedata);
|
||||
workbench_antialiasing_engine_init(vedata);
|
||||
workbench_volume_engine_init(vedata);
|
||||
GPU_render_end();
|
||||
}
|
||||
|
||||
void workbench_cache_init(void *ved)
|
||||
|
@@ -152,6 +152,7 @@ static void engine_depsgraph_free(RenderEngine *engine)
|
||||
/* Need GPU context since this might free GPU buffers. */
|
||||
const bool use_gpu_context = (engine->type->flag & RE_USE_GPU_CONTEXT);
|
||||
if (use_gpu_context) {
|
||||
GPU_render_begin();
|
||||
DRW_render_context_enable(engine->re);
|
||||
}
|
||||
|
||||
@@ -160,6 +161,7 @@ static void engine_depsgraph_free(RenderEngine *engine)
|
||||
|
||||
if (use_gpu_context) {
|
||||
DRW_render_context_disable(engine->re);
|
||||
GPU_render_end();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -756,6 +758,7 @@ static void engine_depsgraph_init(RenderEngine *engine, ViewLayer *view_layer)
|
||||
/* Need GPU context since this might free GPU buffers. */
|
||||
const bool use_gpu_context = (engine->type->flag & RE_USE_GPU_CONTEXT) && reuse_depsgraph;
|
||||
if (use_gpu_context) {
|
||||
GPU_render_begin();
|
||||
DRW_render_context_enable(engine->re);
|
||||
}
|
||||
|
||||
@@ -763,6 +766,7 @@ static void engine_depsgraph_init(RenderEngine *engine, ViewLayer *view_layer)
|
||||
|
||||
if (use_gpu_context) {
|
||||
DRW_render_context_disable(engine->re);
|
||||
GPU_render_end();
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -935,6 +939,7 @@ static void engine_render_view_layer(Render *re,
|
||||
if (use_engine) {
|
||||
const bool use_gpu_context = (engine->type->flag & RE_USE_GPU_CONTEXT);
|
||||
if (use_gpu_context) {
|
||||
GPU_render_begin();
|
||||
DRW_render_context_enable(engine->re);
|
||||
}
|
||||
|
||||
@@ -950,6 +955,7 @@ static void engine_render_view_layer(Render *re,
|
||||
|
||||
if (use_gpu_context) {
|
||||
DRW_render_context_disable(engine->re);
|
||||
GPU_render_end();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2391,6 +2391,9 @@ void RE_RenderAnim(Render *re,
|
||||
|
||||
void RE_PreviewRender(Render *re, Main *bmain, Scene *sce)
|
||||
{
|
||||
/* Ensure within GPU render boundary. */
|
||||
GPU_render_begin();
|
||||
|
||||
Object *camera;
|
||||
int winx, winy;
|
||||
|
||||
@@ -2411,6 +2414,9 @@ void RE_PreviewRender(Render *re, Main *bmain, Scene *sce)
|
||||
RE_engine_free(re->engine);
|
||||
re->engine = nullptr;
|
||||
}
|
||||
|
||||
/* Close GPU render boundary. */
|
||||
GPU_render_end();
|
||||
}
|
||||
|
||||
/* NOTE: repeated win/disprect calc... solve that nicer, also in compo. */
|
||||
|
@@ -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)
|
||||
|
@@ -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.
|
||||
*
|
||||
|
Reference in New Issue
Block a user