Blender V5.0
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() ||
47 if (pass->mode == PassMode::DENOISED && !has_denoised_result) {
48 pass = buffer_params.find_pass(pass->type);
49 if (pass == nullptr) {
50 /* Happens when denoised result pass is requested but is never written by the kernel. */
51 return false;
52 }
53 }
54
55 pass = buffer_params.get_actual_display_pass(pass);
56 if (pass == nullptr) {
57 /* Happens when interactive session changes display pass but render
58 * buffer does not contain it yet. */
59 return false;
60 }
61
62 const float exposure = buffer_params.exposure;
63 const int num_samples = path_trace_.get_num_render_tile_samples();
64
65 PassAccessor::PassAccessInfo pass_access_info(*pass);
68 pass_access_info.use_approximate_shadow_catcher && !buffer_params.use_transparent_background;
69
70 const PassAccessorCPU pass_accessor(pass_access_info, exposure, num_samples);
71 const PassAccessor::Destination destination(pixels, num_channels);
72
73 return path_trace_.get_render_tile_pixels(pass_accessor, destination);
74}
75
76bool PathTraceTile::set_pass_pixels(const string_view pass_name,
77 const int num_channels,
78 const float *pixels) const
79{
80 /* NOTE: The code relies on a fact that session is fully update and no scene/buffer modification
81 * is happening while this function runs. */
82
83 const BufferParams &buffer_params = path_trace_.get_render_tile_params();
84 const BufferPass *pass = buffer_params.find_pass(pass_name);
85 if (!pass) {
86 return false;
87 }
88 if (pass->offset == PASS_UNUSED) {
89 /* Happens when attempting to set pixels of a pass with compositing when baking. */
90 return false;
91 }
92
93 const float exposure = buffer_params.exposure;
94 const int num_samples = 1;
95
96 const PassAccessor::PassAccessInfo pass_access_info(*pass);
97 PassAccessorCPU pass_accessor(pass_access_info, exposure, num_samples);
98 const PassAccessor::Source source(pixels, num_channels);
99
100 return path_trace_.set_render_tile_pixels(pass_accessor, source);
101}
102
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:174
const BufferPass * get_actual_display_pass(PassType type, PassMode mode=PassMode::NOISY) const
Definition buffers.cpp:196
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
bool is_volume_guiding_pass(const PassType pass_type)
Definition pass.cpp:474
@ DENOISED
Definition pass.h:22