Fix #119211: Masks do not update in GPU compositor

Masks are not updated when edited when using the GPU compositor. That's
because the GPU compositor caches static resources and invalidates them
according to the recalculate flags that the depsgraph flushes to IDs.
The issue is that the flags are not flushed to the evaluated IDs of the
compositor depsgraph, but rather to some other evaluated versions of the
IDs.

To fix this, we make the compositor depsgraph persistent and store it in
the scene runtime. This allows us to reliably track changes to resources
used by the compositor and also reduces the overhead of depsgraph
creation in the compositor job.

Patch originally provided by Sergey.

Fixes #121188.

Pull Request: https://projects.blender.org/blender/blender/pulls/123085
This commit is contained in:
Omar Emara
2024-06-13 07:43:11 +02:00
committed by Omar Emara
parent 0ab1291716
commit 95eb3e13bf
3 changed files with 29 additions and 6 deletions

View File

@@ -8,13 +8,24 @@
#include "BLI_timeit.hh"
#include "BLI_utility_mixins.hh"
struct Depsgraph;
namespace blender::bke {
/* Runtime data specific to the compositing trees. */
struct CompositorRuntime {
class CompositorRuntime {
public:
/* Per-node instance total execution time for the corresponding node, during the last tree
* evaluation. */
Map<bNodeInstanceKey, timeit::Nanoseconds> per_node_execution_time;
/* A dependency graph used for interactive compositing. This is initialized the first time it is
* needed, and then kept persistent for the lifetime of the scene. This is done to allow the
* compositor to track changes to resources its uses as well as reduce the overhead of creating
* the dependency graph every time it executes. */
Depsgraph *preview_depsgraph = nullptr;
~CompositorRuntime();
};
class SceneRuntime : NonCopyable, NonMovable {

View File

@@ -107,8 +107,16 @@
#include "bmesh.hh"
using blender::bke::CompositorRuntime;
using blender::bke::SceneRuntime;
CompositorRuntime::~CompositorRuntime()
{
if (preview_depsgraph) {
DEG_graph_free(preview_depsgraph);
}
}
CurveMapping *BKE_sculpt_default_cavity_curve()
{

View File

@@ -219,9 +219,6 @@ static void compo_freejob(void *cjv)
bke::ntreeFreeTree(cj->localtree);
MEM_freeN(cj->localtree);
}
if (cj->compositor_depsgraph != nullptr) {
DEG_graph_free(cj->compositor_depsgraph);
}
MEM_delete(cj);
}
@@ -235,8 +232,15 @@ static void compo_initjob(void *cjv)
Scene *scene = cj->scene;
ViewLayer *view_layer = cj->view_layer;
cj->compositor_depsgraph = DEG_graph_new(bmain, scene, view_layer, DAG_EVAL_RENDER);
DEG_debug_name_set(cj->compositor_depsgraph, "COMPOSITOR");
bke::CompositorRuntime &compositor_runtime = scene->runtime->compositor;
if (!compositor_runtime.preview_depsgraph) {
compositor_runtime.preview_depsgraph = DEG_graph_new(
bmain, scene, view_layer, DAG_EVAL_RENDER);
DEG_debug_name_set(compositor_runtime.preview_depsgraph, "COMPOSITOR");
}
cj->compositor_depsgraph = compositor_runtime.preview_depsgraph;
DEG_graph_build_for_compositor_preview(cj->compositor_depsgraph, cj->ntree);
/* NOTE: Don't update animation to preserve unkeyed changes, this means can not use