Blender  V3.3
path_trace_tile.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2021-2022 Blender Foundation */
3 
7 
8 #include "scene/film.h"
9 #include "scene/pass.h"
10 #include "scene/scene.h"
11 #include "session/buffers.h"
12 
14 
16  : OutputDriver::Tile(path_trace.get_render_tile_offset(),
17  path_trace.get_render_tile_size(),
18  path_trace.get_render_size(),
19  path_trace.get_render_tile_params().layer,
20  path_trace.get_render_tile_params().view),
21  path_trace_(path_trace),
22  copied_from_device_(false)
23 {
24 }
25 
26 bool PathTraceTile::get_pass_pixels(const string_view pass_name,
27  const int num_channels,
28  float *pixels) const
29 {
30  /* NOTE: The code relies on a fact that session is fully update and no scene/buffer modification
31  * is happening while this function runs. */
32 
33  if (!copied_from_device_) {
34  /* Copy from device on demand. */
35  path_trace_.copy_render_tile_from_device();
36  copied_from_device_ = true;
37  }
38 
39  const BufferParams &buffer_params = path_trace_.get_render_tile_params();
40 
41  const BufferPass *pass = buffer_params.find_pass(pass_name);
42  if (pass == nullptr) {
43  return false;
44  }
45 
46  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 
57  const float exposure = buffer_params.exposure;
58  const int num_samples = path_trace_.get_num_render_tile_samples();
59 
60  PassAccessor::PassAccessInfo pass_access_info(*pass);
61  pass_access_info.use_approximate_shadow_catcher = buffer_params.use_approximate_shadow_catcher;
63  pass_access_info.use_approximate_shadow_catcher && !buffer_params.use_transparent_background;
64 
65  const PassAccessorCPU pass_accessor(pass_access_info, exposure, num_samples);
66  const PassAccessor::Destination destination(pixels, num_channels);
67 
68  return path_trace_.get_render_tile_pixels(pass_accessor, destination);
69 }
70 
71 bool PathTraceTile::set_pass_pixels(const string_view pass_name,
72  const int num_channels,
73  const float *pixels) const
74 {
75  /* NOTE: The code relies on a fact that session is fully update and no scene/buffer modification
76  * is happening while this function runs. */
77 
78  const BufferParams &buffer_params = path_trace_.get_render_tile_params();
79  const BufferPass *pass = buffer_params.find_pass(pass_name);
80  if (!pass) {
81  return false;
82  }
83 
84  const float exposure = buffer_params.exposure;
85  const int num_samples = 1;
86 
87  const PassAccessor::PassAccessInfo pass_access_info(*pass);
88  PassAccessorCPU pass_accessor(pass_access_info, exposure, num_samples);
89  PassAccessor::Source source(pixels, num_channels);
90 
91  return path_trace_.set_render_tile_pixels(pass_accessor, source);
92 }
93 
static AppView * view
bool use_approximate_shadow_catcher
Definition: buffers.h:101
float exposure
Definition: buffers.h:100
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
bool use_transparent_background
Definition: buffers.h:102
NODE_DECLARE PassType type
Definition: buffers.h:29
PassMode mode
Definition: buffers.h:30
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()
Definition: path_trace.cpp:909
bool has_denoised_result
Definition: path_trace.h:287
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
Definition: cuda/compat.h:9
ccl_gpu_kernel_postfix ccl_global float int int int int ccl_global const float int int int int int int int int int int int int num_samples