Blender V4.5
path_trace_tile.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
8
9#include "scene/pass.h"
10#include "session/buffers.h"
11
13
15 : OutputDriver::Tile(path_trace.get_render_tile_offset(),
16 path_trace.get_render_tile_size(),
17 path_trace.get_render_size(),
18 path_trace.get_render_tile_params().layer,
19 path_trace.get_render_tile_params().view),
20 path_trace_(path_trace),
21 copied_from_device_(false)
22{
23}
24
25bool PathTraceTile::get_pass_pixels(const string_view pass_name,
26 const int num_channels,
27 float *pixels) const
28{
29 /* NOTE: The code relies on a fact that session is fully update and no scene/buffer modification
30 * is happening while this function runs. */
31
32 if (!copied_from_device_) {
33 /* Copy from device on demand. */
34 path_trace_.copy_render_tile_from_device();
35 copied_from_device_ = true;
36 }
37
38 const BufferParams &buffer_params = path_trace_.get_render_tile_params();
39
40 const BufferPass *pass = buffer_params.find_pass(pass_name);
41 if (pass == nullptr) {
42 return false;
43 }
44
45 const bool has_denoised_result = path_trace_.has_denoised_result();
46 if (pass->mode == PassMode::DENOISED && !has_denoised_result) {
47 pass = buffer_params.find_pass(pass->type);
48 if (pass == nullptr) {
49 /* Happens when denoised result pass is requested but is never written by the kernel. */
50 return false;
51 }
52 }
53
54 pass = buffer_params.get_actual_display_pass(pass);
55 if (pass == nullptr) {
56 /* Happens when interactive session changes display pass but render
57 * buffer does not contain it yet. */
58 return false;
59 }
60
61 const float exposure = buffer_params.exposure;
62 const int num_samples = path_trace_.get_num_render_tile_samples();
63
64 PassAccessor::PassAccessInfo pass_access_info(*pass);
67 pass_access_info.use_approximate_shadow_catcher && !buffer_params.use_transparent_background;
68
69 const PassAccessorCPU pass_accessor(pass_access_info, exposure, num_samples);
70 const PassAccessor::Destination destination(pixels, num_channels);
71
72 return path_trace_.get_render_tile_pixels(pass_accessor, destination);
73}
74
75bool PathTraceTile::set_pass_pixels(const string_view pass_name,
76 const int num_channels,
77 const float *pixels) const
78{
79 /* NOTE: The code relies on a fact that session is fully update and no scene/buffer modification
80 * is happening while this function runs. */
81
82 const BufferParams &buffer_params = path_trace_.get_render_tile_params();
83 const BufferPass *pass = buffer_params.find_pass(pass_name);
84 if (!pass) {
85 return false;
86 }
87 if (pass->offset == PASS_UNUSED) {
88 /* Happens when attempting to set pixels of a pass with compositing when baking. */
89 return false;
90 }
91
92 const float exposure = buffer_params.exposure;
93 const int num_samples = 1;
94
95 const PassAccessor::PassAccessInfo pass_access_info(*pass);
96 PassAccessorCPU pass_accessor(pass_access_info, exposure, num_samples);
97 const PassAccessor::Source source(pixels, num_channels);
98
99 return path_trace_.set_render_tile_pixels(pass_accessor, source);
100}
101
bool use_approximate_shadow_catcher
Definition buffers.h:100
float exposure
Definition buffers.h:99
const BufferPass * find_pass(string_view name) const
Definition buffers.cpp:171
const BufferPass * get_actual_display_pass(PassType type, PassMode mode=PassMode::NOISY) const
Definition buffers.cpp:193
bool use_transparent_background
Definition buffers.h:101
int offset
Definition buffers.h:34
NODE_DECLARE PassType type
Definition buffers.h:28
PassMode mode
Definition buffers.h:29
Tile(const int2 offset, const int2 size, const int2 full_size, const string_view layer, const string_view view)
bool set_pass_pixels(const string_view pass_name, const int num_channels, const float *pixels) const override
bool get_pass_pixels(const string_view pass_name, const int num_channels, float *pixels) const override
PathTraceTile(PathTrace &path_trace)
#define PASS_UNUSED
#define CCL_NAMESPACE_END
@ DENOISED
Definition pass.h:22