Blender V4.3
buffers.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#ifndef __BUFFERS_H__
6#define __BUFFERS_H__
7
8#include "device/memory.h"
9#include "graph/node.h"
10#include "scene/pass.h"
11
12#include "kernel/types.h"
13
14#include "util/half.h"
15#include "util/string.h"
16#include "util/thread.h"
17#include "util/types.h"
18
20
21class Device;
22struct DeviceDrawParams;
23struct float4;
24
25/* NOTE: Is not a real scene node. Using Node API for ease of (de)serialization. */
26class BufferPass : public Node {
27 public:
29
32 ustring name;
33 bool include_albedo = false;
34 ustring lightgroup;
35
36 int offset = -1;
37
38 BufferPass();
39 explicit BufferPass(const Pass *scene_pass);
40
41 BufferPass(BufferPass &&other) noexcept = default;
42 BufferPass(const BufferPass &other) = default;
43
44 BufferPass &operator=(BufferPass &&other) = default;
45 BufferPass &operator=(const BufferPass &other) = default;
46
47 ~BufferPass() = default;
48
49 PassInfo get_info() const;
50
51 inline bool operator==(const BufferPass &other) const
52 {
53 return type == other.type && mode == other.mode && name == other.name &&
54 include_albedo == other.include_albedo && lightgroup == other.lightgroup &&
55 offset == other.offset;
56 }
57 inline bool operator!=(const BufferPass &other) const
58 {
59 return !(*this == other);
60 }
61};
62
63/* Buffer Parameters
64 * Size of render buffer and how it fits in the full image (border render). */
65
66/* NOTE: Is not a real scene node. Using Node API for ease of (de)serialization. */
67class BufferParams : public Node {
68 public:
70
71 /* Width/height of the physical buffer. */
72 int width = 0;
73 int height = 0;
74
75 /* Windows defines which part of the buffers is visible. The part outside of the window is
76 * considered an `overscan`.
77 *
78 * Window X and Y are relative to the position of the buffer in the full buffer. */
79 int window_x = 0;
80 int window_y = 0;
81 int window_width = 0;
83
84 /* Offset into and width/height of the full buffer. */
85 int full_x = 0;
86 int full_y = 0;
87 int full_width = 0;
88 int full_height = 0;
89
90 /* Runtime fields, only valid after `update_passes()` or `update_offset_stride()`. */
91 int offset = -1, stride = -1;
92
93 /* Runtime fields, only valid after `update_passes()`. */
94 int pass_stride = -1;
95
96 /* Properties which are used for accessing buffer pixels outside of scene graph. */
98 ustring layer;
99 ustring view;
100 int samples = 0;
101 float exposure = 1.0f;
104
105 BufferParams();
106
107 BufferParams(BufferParams &&other) noexcept = default;
108 BufferParams(const BufferParams &other) = default;
109
111 BufferParams &operator=(const BufferParams &other) = default;
112
113 ~BufferParams() = default;
114
115 /* Pre-calculate all fields which depends on the passes.
116 *
117 * When the scene passes are given, the buffer passes will be created from them and stored in
118 * this params, and then params are updated for those passes.
119 * The `update_passes()` without parameters updates offsets and strides which are stored outside
120 * of the passes. */
121 void update_passes();
122 void update_passes(const vector<Pass *> &scene_passes);
123
124 /* Returns PASS_UNUSED if there is no such pass in the buffer. */
125 int get_pass_offset(PassType type, PassMode mode = PassMode::NOISY) const;
126
127 /* Returns nullptr if pass with given name does not exist. */
128 const BufferPass *find_pass(string_view name) const;
129 const BufferPass *find_pass(PassType type, PassMode mode = PassMode::NOISY) const;
130
131 /* Get display pass from its name.
132 * Will do special logic to replace combined pass with shadow catcher matte. */
134 const BufferPass *get_actual_display_pass(const BufferPass *pass) const;
135
137
138 bool modified(const BufferParams &other) const;
139
140 protected:
141 void reset_pass_offset();
142
143 /* Multiplied by 2 to be able to store noisy and denoised pass types. */
144 static constexpr int kNumPassOffsets = PASS_NUM * 2;
145
146 /* Indexed by an index derived from pass type and mode, indicates offset of the corresponding
147 * pass in the buffer.
148 * If there are multiple passes with same type and mode contains lowest offset of all of them. */
150};
151
152/* Render Buffers */
153
155 public:
156 /* buffer parameters */
158
159 /* float buffer */
161
162 explicit RenderBuffers(Device *device);
164
165 void reset(const BufferParams &params);
166 void zero();
167
168 bool copy_from_device();
169 void copy_to_device();
170};
171
172/* Copy denoised passes form source to destination.
173 *
174 * Buffer parameters are provided explicitly, allowing to copy pixels between render buffers which
175 * content corresponds to a render result at a non-unit resolution divider.
176 *
177 * `src_offset` allows to offset source pixel index which is used when a fraction of the source
178 * buffer is to be copied.
179 *
180 * Copy happens of the number of pixels in the destination. */
182 const BufferParams &dst_params,
183 const RenderBuffers *src,
184 const BufferParams &src_params,
185 const size_t src_offset = 0);
186
188
189#endif /* __BUFFERS_H__ */
void reset()
clear internal cached data and reset random seed
void render_buffers_host_copy_denoised(RenderBuffers *dst, const BufferParams &dst_params, const RenderBuffers *src, const BufferParams &src_params, const size_t src_offset=0)
Definition buffers.cpp:307
ustring view
Definition buffers.h:99
int pass_stride
Definition buffers.h:94
ustring layer
Definition buffers.h:98
int full_width
Definition buffers.h:87
int pass_offset_[kNumPassOffsets]
Definition buffers.h:149
bool use_approximate_shadow_catcher
Definition buffers.h:102
BufferParams & operator=(BufferParams &&other)=default
vector< BufferPass > passes
Definition buffers.h:97
~BufferParams()=default
static constexpr int kNumPassOffsets
Definition buffers.h:144
int get_pass_offset(PassType type, PassMode mode=PassMode::NOISY) const
Definition buffers.cpp:167
int window_y
Definition buffers.h:80
void update_offset_stride()
Definition buffers.cpp:221
BufferParams(const BufferParams &other)=default
bool modified(const BufferParams &other) const
Definition buffers.cpp:227
int full_height
Definition buffers.h:88
int window_height
Definition buffers.h:82
int window_width
Definition buffers.h:81
void reset_pass_offset()
Definition buffers.cpp:160
NODE_DECLARE int width
Definition buffers.h:72
const BufferPass * find_pass(string_view name) const
Definition buffers.cpp:177
BufferParams & operator=(const BufferParams &other)=default
const BufferPass * get_actual_display_pass(PassType type, PassMode mode=PassMode::NOISY) const
Definition buffers.cpp:199
int window_x
Definition buffers.h:79
bool use_transparent_background
Definition buffers.h:103
BufferParams(BufferParams &&other) noexcept=default
void update_passes()
Definition buffers.cpp:120
ustring name
Definition buffers.h:32
bool operator==(const BufferPass &other) const
Definition buffers.h:51
bool include_albedo
Definition buffers.h:33
BufferPass & operator=(BufferPass &&other)=default
~BufferPass()=default
PassInfo get_info() const
Definition buffers.cpp:72
BufferPass(BufferPass &&other) noexcept=default
BufferPass(const BufferPass &other)=default
BufferPass & operator=(const BufferPass &other)=default
ustring lightgroup
Definition buffers.h:34
bool operator!=(const BufferPass &other) const
Definition buffers.h:57
Definition pass.h:49
device_vector< float > buffer
Definition buffers.h:160
BufferParams params
Definition buffers.h:157
bool copy_from_device()
Definition buffers.cpp:289
void copy_to_device()
Definition buffers.cpp:302
RenderBuffers(Device *device)
Definition buffers.cpp:267
#define CCL_NAMESPACE_END
PassType
@ PASS_NUM
@ PASS_NONE
VecBase< float, 4 > float4
#define NODE_DECLARE
Definition node_type.h:142
PassMode
Definition pass.h:20