Blender V5.3
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_enum_flags.hh"
10#include "BLI_string_ref.hh"
11
12#include "DNA_scene_types.h"
13#include "DNA_sequence_types.h"
14
16
17#include "GPU_shader.hh"
18
19#include "COM_domain.hh"
20#include "COM_meta_data.hh"
21#include "COM_render_context.hh"
22#include "COM_result.hh"
24
25namespace blender {
26struct Main;
27class ComputeContext;
28} // namespace blender
29
31class NodesEvalLog;
32} // namespace blender::nodes::eval_log
33
34namespace blender::compositor {
35
36/* A bit flag of compositor side effect outputs than can be computed. */
38 None = 0,
39 ViewerNode = 1 << 0,
41 NodePreviews = 1 << 2,
42};
43ENUM_OPERATORS(SideEffectOutputTypes)
44
45/* ------------------------------------------------------------------------------------------------
46 * Context
47 *
48 * A Context is an abstract class that is implemented by the caller of the evaluator to provide the
49 * necessary data and functionalities for the correct operation of the evaluator. This includes
50 * providing input data like render passes and the active scene, as well as callbacks to write the
51 * outputs of the compositor. Finally, the class have a reference to a static cache manager and a
52 * compute context cache. */
53class Context {
54 private:
55 /* A static cache manager that can be used to acquire cached resources for the compositor
56 * efficiently. */
57 StaticCacheManager &cache_manager_;
58 /* A compute context cache that can be used to acquire compute contexts throughout the compositor
59 * evaluation. */
60 bke::ComputeContextCache &compute_context_cache_;
61
62 public:
64
65 virtual const Main &get_main() const = 0;
66
67 /* Get the compositing scene. */
68 virtual const Scene &get_scene() const = 0;
69
70 /* Returns the domain that the inputs and outputs of the context will be in. */
71 virtual Domain get_compositing_domain() const = 0;
72
73 /* Write the result of the compositor viewer. */
74 virtual void write_viewer(Result &viewer_result) = 0;
75
76 /* True if the compositor should use GPU acceleration. */
77 virtual bool use_gpu() const = 0;
78
79 /* Returns the side effect output types that needs to be computed. */
81
82 /* Returns the compute context of the active viewer if one exists. */
83 virtual const ComputeContext *viewer_compute_context() const = 0;
84
85 /* Get the strip that the compositing modifier is applied to. */
86 virtual const Strip *get_strip() const;
87
88 /* Get the pass with the given name in the given view layer and scene. Freeing the pass is the
89 * caller's responsibility. */
90 virtual Result get_pass(const Scene *scene, int view_layer, const char *name);
91
92 /* Get the render settings for compositing. This could be different from scene->r render settings
93 * in case the render size or other settings needs to be overwritten. */
94 virtual const RenderData &get_render_data() const;
95
96 /* Get the name of the view currently being rendered. If the context is not multi-view, return an
97 * empty string. */
98 virtual StringRef get_view_name() const;
99
100 /* Get the precision of the intermediate results of the compositor. */
101 virtual ResultPrecision get_precision() const;
102
103 /* Populates the given meta data from the render stamp information of the given render pass. */
104 virtual void populate_meta_data_for_pass(const Scene *scene,
105 int view_layer_id,
106 const char *pass_name,
107 MetaData &meta_data) const;
108
109 /* Get a pointer to the render context of this context. A render context stores information about
110 * the current render. It might be null if the compositor is not being evaluated as part of a
111 * render pipeline. */
112 virtual RenderContext *render_context() const;
113
114 /* Returns true if this context is the viewport compositor, as opposed to the interactive
115 * compositor or a final render. */
116 virtual bool is_viewport() const;
117
118 /* Returns a pointer to a nodes evaluation log of the context, this can be nullptr for context
119 * that does not support logging. */
121
122 /* Gets called after the evaluation of each compositor operation. See overrides for possible
123 * uses. */
124 virtual void evaluate_operation_post() const;
125
126 /* Returns true if the compositor evaluation is canceled and that the evaluator should stop
127 * executing as soon as possible. */
128 virtual bool is_canceled() const;
129
130 /* Get the normalized render percentage of the active scene. */
131 float get_render_percentage() const;
132
133 /* Get the current frame number of the active scene. */
134 int get_frame_number() const;
135
136 /* Get the current time in seconds of the active scene. */
137 float get_time() const;
138
139 /* Get the OIDN denoiser quality which should be used if the user doesn't explicitly set
140 * denoising quality on a node. */
142
143 /* Get a GPU shader with the given info name and precision. */
144 gpu::Shader *get_shader(const char *info_name, ResultPrecision precision);
145
146 /* Get a GPU shader with the given info name and context's precision. */
147 gpu::Shader *get_shader(const char *info_name);
148
149 /* Create a result of the given type and precision. */
151
152 /* Create a result of the given type using the context's precision. */
154
155 /* Get a reference to the static cache manager of this context. */
157
158 /* Get a reference to the compute context cache of this context. */
160};
161
162} // namespace blender::compositor
virtual const Scene & get_scene() const =0
Result create_result(ResultType type, ResultPrecision precision)
eCompositorDenoiseQaulity get_denoise_quality() const
virtual void populate_meta_data_for_pass(const Scene *scene, int view_layer_id, const char *pass_name, MetaData &meta_data) const
virtual const Main & get_main() const =0
Context(StaticCacheManager &cache_manager, bke::ComputeContextCache &compute_context_cache)
virtual StringRef get_view_name() const
virtual SideEffectOutputTypes needed_side_effect_output_types() const =0
bke::ComputeContextCache & compute_context_cache() const
virtual Result get_pass(const Scene *scene, int view_layer, const char *name)
virtual const RenderData & get_render_data() const
virtual Domain get_compositing_domain() const =0
virtual const ComputeContext * viewer_compute_context() const =0
virtual void write_viewer(Result &viewer_result)=0
gpu::Shader * get_shader(const char *info_name, ResultPrecision precision)
virtual ResultPrecision get_precision() const
virtual RenderContext * render_context() const
virtual nodes::eval_log::NodesEvalLog * nodes_evaluation_log() const
virtual const Strip * get_strip() const
virtual bool use_gpu() const =0
ENUM_OPERATORS(Layer::Flags)
BMesh Iterators.
unsigned char uint8_t
Definition BKE_text.h:79