Blender V5.0
COM_context.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include <cstdint>
8
9#include "BLI_bounds_types.hh"
11#include "BLI_string_ref.hh"
12
13#include "DNA_scene_types.h"
14
15#include "GPU_shader.hh"
16
17#include "COM_domain.hh"
18#include "COM_meta_data.hh"
19#include "COM_profiler.hh"
20#include "COM_render_context.hh"
21#include "COM_result.hh"
23
24namespace blender::compositor {
25
26/* Enumerates the possible outputs that the compositor can compute. */
27enum class OutputTypes : uint8_t {
28 None = 0,
29 Composite = 1 << 0,
30 Viewer = 1 << 1,
31 FileOutput = 1 << 2,
32 Previews = 1 << 3,
33};
35
36/* ------------------------------------------------------------------------------------------------
37 * Context
38 *
39 * A Context is an abstract class that is implemented by the caller of the evaluator to provide the
40 * necessary data and functionalities for the correct operation of the evaluator. This includes
41 * providing input data like render passes and the active scene, as well as references to the data
42 * where the output of the evaluator will be written. Finally, the class have an instance of a
43 * static resource manager for acquiring cached resources efficiently. */
44class Context {
45 private:
46 /* A static cache manager that can be used to acquire cached resources for the compositor
47 * efficiently. */
48 StaticCacheManager cache_manager_;
49
50 public:
51 /* Get the compositing scene. */
52 virtual const Scene &get_scene() const = 0;
53
54 /* Get the node tree used for compositing. */
55 virtual const bNodeTree &get_node_tree() const = 0;
56
57 /* Returns all output types that should be computed. */
58 virtual OutputTypes needed_outputs() const = 0;
59
60 /* Get the rectangular region representing the area of the input that the compositor will operate
61 * on. Conversely, the compositor will only update the region of the output that corresponds to
62 * the compositing region. In the base case, the compositing region covers the entirety of the
63 * render region. In other cases, the compositing region might be a subset of the render region.
64 * Callers should check the validity of the region through is_valid_compositing_region(), since
65 * the region can be zero sized. */
67
68 /* Get the result where the result of the compositor should be written. */
69 virtual Result get_output(Domain domain) = 0;
70
71 /* Get the result where the result of the compositor viewer should be written, given the domain
72 * of the result to be viewed, its precision, and whether the output is a non-color data image
73 * that should be displayed without view transform. */
74 virtual Result get_viewer_output(Domain domain, bool is_data, ResultPrecision precision) = 0;
75
76 /* Get the result where the given input is stored. */
78
79 /* True if the compositor should use GPU acceleration. */
80 virtual bool use_gpu() const = 0;
81
82 /* Get the result where the given pass is stored. */
83 virtual Result get_pass(const Scene *scene, int view_layer, const char *name);
84
85 /* Get the render settings for compositing. This could be different from scene->r render settings
86 * in case the render size or other settings needs to be overwritten. */
87 virtual const RenderData &get_render_data() const;
88
89 /* Get the name of the view currently being rendered. If the context is not multi-view, return an
90 * empty string. */
91 virtual StringRef get_view_name() const;
92
93 /* Get the precision of the intermediate results of the compositor. */
94 virtual ResultPrecision get_precision() const;
95
96 /* Set an info message. This is called by the compositor evaluator to inform or warn the user
97 * about something, typically an error. The implementation should display the message in an
98 * appropriate place, which can be directly in the UI or just logged to the output stream. */
99 virtual void set_info_message(StringRef message) const;
100
101 /* True if the compositor should treat viewers as composite outputs because it has no concept of
102 * or support for viewers. */
103 virtual bool treat_viewer_as_compositor_output() const;
104
105 /* True if the compositor input/output should use output region/bounds setup in the context. */
107 {
108 return true;
109 }
110
111 /* Populates the given meta data from the render stamp information of the given render pass. */
112 virtual void populate_meta_data_for_pass(const Scene *scene,
113 int view_layer_id,
114 const char *pass_name,
115 MetaData &meta_data) const;
116
117 /* Get a pointer to the render context of this context. A render context stores information about
118 * the current render. It might be null if the compositor is not being evaluated as part of a
119 * render pipeline. */
120 virtual RenderContext *render_context() const;
121
122 /* Get a pointer to the profiler of this context. It might be null if the compositor context does
123 * not support profiling. */
124 virtual Profiler *profiler() const;
125
126 /* Gets called after the evaluation of each compositor operation. See overrides for possible
127 * uses. */
128 virtual void evaluate_operation_post() const;
129
130 /* Returns true if the compositor evaluation is canceled and that the evaluator should stop
131 * executing as soon as possible. */
132 virtual bool is_canceled() const;
133
134 /* Resets the context's internal structures like the cache manager. This should be called before
135 * every evaluation. */
136 void reset();
137
138 /* Get the size of the compositing region. See get_compositing_region(). The output size is
139 * sanitized such that it is at least 1 in both dimensions. However, the developer is expected to
140 * gracefully handled zero sizes regions by checking the is_valid_compositing_region method. */
141 int2 get_compositing_region_size() const;
142
143 /* Returns true if the compositing region has a valid size, that is, has at least one pixel in
144 * both dimensions, returns false otherwise. */
145 bool is_valid_compositing_region() const;
146
147 /* Get the normalized render percentage of the active scene. */
148 float get_render_percentage() const;
149
150 /* Get the current frame number of the active scene. */
151 int get_frame_number() const;
152
153 /* Get the current time in seconds of the active scene. */
154 float get_time() const;
155
156 /* Get the OIDN denoiser quality which should be used if the user doesn't explicitly set
157 * denoising quality on a node. */
158 eCompositorDenoiseQaulity get_denoise_quality() const;
159
160 /* Get a GPU shader with the given info name and precision. */
161 gpu::Shader *get_shader(const char *info_name, ResultPrecision precision);
162
163 /* Get a GPU shader with the given info name and context's precision. */
164 gpu::Shader *get_shader(const char *info_name);
165
166 /* Create a result of the given type and precision. */
167 Result create_result(ResultType type, ResultPrecision precision);
168
169 /* Create a result of the given type using the context's precision. */
170 Result create_result(ResultType type);
171
172 /* Get a reference to the static cache manager of this context. */
173 StaticCacheManager &cache_manager();
174};
175
176} // namespace blender::compositor
#define ENUM_OPERATORS(_type, _max)
eCompositorDenoiseQaulity
void reset()
clear internal cached data and reset random seed
virtual const Scene & get_scene() const =0
virtual bool use_context_bounds_for_input_output() const
virtual void set_info_message(StringRef message) const
virtual bool treat_viewer_as_compositor_output() const
virtual StringRef get_view_name() const
virtual Result get_input(StringRef name)=0
virtual OutputTypes needed_outputs() const =0
virtual Result get_viewer_output(Domain domain, bool is_data, ResultPrecision precision)=0
virtual Result get_output(Domain domain)=0
virtual Result get_pass(const Scene *scene, int view_layer, const char *name)
virtual const RenderData & get_render_data() const
virtual Bounds< int2 > get_compositing_region() const =0
virtual ResultPrecision get_precision() const
virtual const bNodeTree & get_node_tree() const =0
virtual bool use_gpu() const =0
static const char * get_shader(MorphologicalBlurOperation operation)
VecBase< int32_t, 2 > int2
const char * name