From 406a2d3ff0379667ff776f8090323830208387ff Mon Sep 17 00:00:00 2001 From: Omar Emara Date: Fri, 26 Jul 2024 19:01:11 +0300 Subject: [PATCH] Fix #125380: Viewport compositor slows complex scenes The viewport compositor slows down complex scenes even if it has very simple setups. That's because it internally computes previews which involves a fair bit of CPU computation, however, those previews are actually never written to the original tree, so previewers weren't really visible so it is effectively redundantly computations. To fix this, we double down on disabling previews for the viewport compositor and avoid any redundant computations in that case. --- source/blender/compositor/realtime_compositor/COM_context.hh | 3 +++ .../compositor/realtime_compositor/intern/node_operation.cc | 2 +- source/blender/draw/engines/compositor/compositor_engine.cc | 5 +++++ source/blender/render/intern/compositor.cc | 5 +++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/source/blender/compositor/realtime_compositor/COM_context.hh b/source/blender/compositor/realtime_compositor/COM_context.hh index 612d8b8c89f..eb487d9e008 100644 --- a/source/blender/compositor/realtime_compositor/COM_context.hh +++ b/source/blender/compositor/realtime_compositor/COM_context.hh @@ -54,6 +54,9 @@ class Context { /* True if the compositor should write file outputs, false otherwise. */ virtual bool use_file_output() const = 0; + /* True if the compositor should compute node previews, false otherwise. */ + virtual bool should_compute_node_previews() const = 0; + /* True if the compositor should write the composite output, otherwise, the compositor is assumed * to not support the composite output and just displays its viewer output. In that case, the * composite output will be used as a fallback viewer if no other viewer exists */ diff --git a/source/blender/compositor/realtime_compositor/intern/node_operation.cc b/source/blender/compositor/realtime_compositor/intern/node_operation.cc index a06efd173c8..7f1e6aefafc 100644 --- a/source/blender/compositor/realtime_compositor/intern/node_operation.cc +++ b/source/blender/compositor/realtime_compositor/intern/node_operation.cc @@ -60,7 +60,7 @@ void NodeOperation::evaluate() void NodeOperation::compute_preview() { - if (is_node_preview_needed(node())) { + if (context().should_compute_node_previews() && is_node_preview_needed(node())) { compute_preview_from_result(context(), node(), *get_preview_result()); } } diff --git a/source/blender/draw/engines/compositor/compositor_engine.cc b/source/blender/draw/engines/compositor/compositor_engine.cc index f8f0ae3dadb..e4c1c29d0cb 100644 --- a/source/blender/draw/engines/compositor/compositor_engine.cc +++ b/source/blender/draw/engines/compositor/compositor_engine.cc @@ -74,6 +74,11 @@ class Context : public realtime_compositor::Context { return false; } + bool should_compute_node_previews() const override + { + return false; + } + /* The viewport compositor doesn't really support the composite output, it only displays the * viewer output in the viewport. Settings this to false will make the compositor use the * composite output as fallback viewer if no other viewer exists. */ diff --git a/source/blender/render/intern/compositor.cc b/source/blender/render/intern/compositor.cc index e1ce71c892e..a7f46585711 100644 --- a/source/blender/render/intern/compositor.cc +++ b/source/blender/render/intern/compositor.cc @@ -198,6 +198,11 @@ class Context : public realtime_compositor::Context { return this->render_context() != nullptr; } + bool should_compute_node_previews() const override + { + return this->render_context() == nullptr; + } + bool use_composite_output() const override { return true;