From eecb8671826184a604c95f811dd75ac85e1ec156 Mon Sep 17 00:00:00 2001 From: Jason Fielder Date: Fri, 21 Apr 2023 18:24:30 +0200 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 Pull Request: https://projects.blender.org/blender/blender/pulls/107221 --- 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 48d00011681..efcfee4ea8d 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) {