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