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