From de93f63065006f726fe2c5739a76f86ac365a1c9 Mon Sep 17 00:00:00 2001 From: Michael Parkin-White Date: Fri, 21 Apr 2023 17:18:57 +0100 Subject: [PATCH] Metal: Resolve high memory pressure on EEVEE render When EEVEE is rendering multiple samples via eevee_draw_scene, the command submission and in-flight memory pressure would grow until all samples completed, due to lack of intermediate flushing of GPU work and memory. This patch adds a command flush and memory clear for this case which occurs with high TAA sample counts during saving, similar to the process in EEVEE_render_draw. Authored by Apple: Michael Parkin-White --- source/blender/draw/engines/eevee/eevee_engine.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/source/blender/draw/engines/eevee/eevee_engine.c b/source/blender/draw/engines/eevee/eevee_engine.c index 9afd398c8b4..9a3215eeb97 100644 --- a/source/blender/draw/engines/eevee/eevee_engine.c +++ b/source/blender/draw/engines/eevee/eevee_engine.c @@ -19,6 +19,8 @@ #include "DNA_world_types.h" +#include "GPU_context.h" + #include "IMB_imbuf.h" #include "eevee_private.h" @@ -348,6 +350,16 @@ static void eevee_draw_scene(void *vedata) EEVEE_temporal_sampling_reset(vedata); stl->effects->ssr_was_valid_double_buffer = stl->g_data->valid_double_buffer; } + + /* Perform render step between samples to allow flushing of freed temporary GPUBackend + * resources. This prevents the GPU backend accumulating a high amount of in-flight memory when + * performing renders using eevee_draw_scene. e.g. During file thumbnail generation. */ + if (loop_len > 2) { + if (GPU_backend_get_type() == GPU_BACKEND_METAL) { + GPU_flush(); + GPU_render_step(); + } + } } if ((stl->g_data->render_passes & EEVEE_RENDER_PASS_COMBINED) != 0) { -- 2.30.2