Blender V4.3
COM_compositor.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BLI_threads.h"
6
7#include "BLT_translation.hh"
8
9#include "DNA_userdef_types.h"
10
11#include "BKE_node.hh"
12#include "BKE_node_runtime.hh"
13#include "BKE_scene.hh"
14
15#include "COM_ExecutionSystem.h"
16#include "COM_WorkScheduler.h"
17#include "COM_compositor.hh"
18
19#include "RE_compositor.hh"
20
21static struct {
22 bool is_initialized = false;
25
26/* Make sure node tree has previews.
27 * Don't create previews in advance, this is done when adding preview operations.
28 * Reserved preview size is determined by render output for now. */
30{
31 /* We fit the aspect into COM_PREVIEW_SIZE x COM_PREVIEW_SIZE image to avoid
32 * insane preview resolution, which might even overflow preview dimensions. */
33 const float aspect = render_data->xsch > 0 ?
34 float(render_data->ysch) / float(render_data->xsch) :
35 1.0f;
36 int preview_width, preview_height;
37 if (aspect < 1.0f) {
39 preview_height = int(blender::compositor::COM_PREVIEW_SIZE * aspect);
40 }
41 else {
42 preview_width = int(blender::compositor::COM_PREVIEW_SIZE / aspect);
44 }
45 blender::bke::node_preview_init_tree(node_tree, preview_width, preview_height);
46}
47
49{
50 node_tree->runtime->progress(node_tree->runtime->prh, 0.0);
51 node_tree->runtime->stats_draw(node_tree->runtime->sdh, IFACE_("Compositing"));
52}
53
54void COM_execute(Render *render,
55 RenderData *render_data,
56 Scene *scene,
58 const char *view_name,
61{
62 /* Initialize mutex, TODO: this mutex init is actually not thread safe and
63 * should be done somewhere as part of blender startup, all the other
64 * initializations can be done lazily. */
65 if (!g_compositor.is_initialized) {
67 g_compositor.is_initialized = true;
68 }
69
71
72 if (node_tree->runtime->test_break(node_tree->runtime->tbh)) {
73 /* During editing multiple compositor executions can be triggered.
74 * Make sure this is the most recent one. */
76 return;
77 }
78
81
82 if (scene->r.compositor_device == SCE_COMPOSITOR_DEVICE_GPU ||
83 (USER_EXPERIMENTAL_TEST(&U, enable_new_cpu_compositor) && !scene->r.use_old_cpu_compositor))
84 {
85 /* Realtime compositor. */
87 *render, *scene, *render_data, *node_tree, view_name, render_context, profiler);
88 }
89 else {
90 /* CPU compositor. */
91
92 /* Initialize workscheduler. */
94
95 /* Execute. */
96 const bool is_rendering = render_context != nullptr;
98 render_data, scene, node_tree, is_rendering, view_name, render_context, profiler);
99 system.execute();
100 }
101
103}
104
106{
107 if (g_compositor.is_initialized) {
110 g_compositor.is_initialized = false;
113 }
114}
int BKE_render_num_threads(const RenderData *r)
Definition scene.cc:2850
void BLI_mutex_end(ThreadMutex *mutex)
Definition threads.cc:360
void BLI_mutex_init(ThreadMutex *mutex)
Definition threads.cc:340
void BLI_mutex_lock(ThreadMutex *mutex)
Definition threads.cc:345
void BLI_mutex_unlock(ThreadMutex *mutex)
Definition threads.cc:350
pthread_mutex_t ThreadMutex
Definition BLI_threads.h:83
#define IFACE_(msgid)
static void compositor_reset_node_tree_status(bNodeTree *node_tree)
bool is_initialized
ThreadMutex mutex
void COM_execute(Render *render, RenderData *render_data, Scene *scene, bNodeTree *node_tree, const char *view_name, blender::realtime_compositor::RenderContext *render_context, blender::realtime_compositor::Profiler *profiler)
The main method that is used to execute the compositor tree. It can be executed during editing (blenk...
static void compositor_init_node_previews(const RenderData *render_data, bNodeTree *node_tree)
static struct @170 g_compositor
void COM_deinitialize()
Deinitialize the compositor caches and allocated memory. Use COM_clear_caches to only free the caches...
@ SCE_COMPOSITOR_DEVICE_GPU
#define USER_EXPERIMENTAL_TEST(userdef, member)
unsigned int U
Definition btGjkEpa3.h:78
the ExecutionSystem contains the whole compositor tree.
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
void node_preview_init_tree(bNodeTree *ntree, int xsize, int ysize)
Definition node.cc:3345
constexpr float COM_PREVIEW_SIZE
Definition COM_defines.h:85
void RE_compositor_execute(Render &render, const Scene &scene, const RenderData &render_data, const bNodeTree &node_tree, const char *view_name, blender::realtime_compositor::RenderContext *render_context, blender::realtime_compositor::Profiler *profiler)
static void deinitialize()
deinitialize the WorkScheduler free all allocated resources
static void initialize(int num_cpu_threads)
initialize the WorkScheduler