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