From b0a032e2eb0a63fd0514fa1b4c907c053384de22 Mon Sep 17 00:00:00 2001 From: Jason Fielder Date: Fri, 27 Oct 2023 15:13:49 +0200 Subject: [PATCH] Fix: EEVEE export CMDBuf out of memory in Metal Previous commit 9333336a73f9e116771a52a2caa96455ea345c71 broke export rendering in Metal due to the command submission not being flushed between samples. This would lead to ghosting in export images due to memory synchronization issues and GPU scheduling dependency graph problems. The in-flight memory could also get extremely high if exporting high numbers of samples due to all commands being enqueued within a single submission. Patch resolves this by flushing for each render frame sample and ensuring intermediate in-flight memory remains controlled. Authored by Apple: Michael Parkin-White Pull Request: https://projects.blender.org/blender/blender/pulls/114174 --- source/blender/draw/engines/eevee/eevee_render.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/source/blender/draw/engines/eevee/eevee_render.cc b/source/blender/draw/engines/eevee/eevee_render.cc index c5e498c1437..fc1422ea45f 100644 --- a/source/blender/draw/engines/eevee/eevee_render.cc +++ b/source/blender/draw/engines/eevee/eevee_render.cc @@ -663,6 +663,16 @@ void EEVEE_render_draw(EEVEE_Data *vedata, RenderEngine *engine, RenderLayer *rl /* Perform render step between samples to allow * flushing of freed GPUBackend resources. */ GPU_render_step(); + if (GPU_type_matches_ex(GPU_DEVICE_ANY, GPU_OS_ANY, GPU_DRIVER_ANY, GPU_BACKEND_METAL)) { + if (render_samples > 0 && ((render_samples % 64) == 0)) { + /* Allow GPU to sync with CPU to prevent overly large command submissions being in-flight + * simultaneously. Reduces total in-flight memory required for rendering. */ + GPU_finish(); + } + else { + GPU_flush(); + } + } RE_engine_update_progress(engine, float(render_samples++) / float(tot_sample)); }