Blender  V3.3
pass_accessor_cpu.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #include "device/device.h"
5 
7 
8 #include "session/buffers.h"
9 
10 #include "util/log.h"
11 #include "util/tbb.h"
12 
13 // clang-format off
16 #include "kernel/types.h"
17 #include "kernel/film/read.h"
18 // clang-format on
19 
21 
22 /* --------------------------------------------------------------------
23  * Kernel processing.
24  */
25 
27  const KernelFilmConvert *kfilm_convert,
28  const RenderBuffers *render_buffers,
29  const BufferParams &buffer_params,
30  const Destination &destination,
31  const CPUKernels::FilmConvertFunction func) const
32 {
33  /* NOTE: No overlays are applied since they are not used for final renders.
34  * Can be supported via some sort of specialization to avoid code duplication. */
35 
36  DCHECK_EQ(destination.stride, 0) << "Custom stride for float destination is not implemented.";
37 
38  const int64_t pass_stride = buffer_params.pass_stride;
39  const int64_t buffer_row_stride = buffer_params.stride * buffer_params.pass_stride;
40 
41  const float *window_data = render_buffers->buffer.data() + buffer_params.window_x * pass_stride +
42  buffer_params.window_y * buffer_row_stride;
43 
44  const int pixel_stride = destination.pixel_stride ? destination.pixel_stride :
45  destination.num_components;
46 
47  parallel_for(0, buffer_params.window_height, [&](int64_t y) {
48  const float *buffer = window_data + y * buffer_row_stride;
49  float *pixel = destination.pixels +
50  (y * buffer_params.width + destination.offset) * pixel_stride;
51  func(kfilm_convert, buffer, pixel, buffer_params.window_width, pass_stride, pixel_stride);
52  });
53 }
54 
56  const KernelFilmConvert *kfilm_convert,
57  const RenderBuffers *render_buffers,
58  const BufferParams &buffer_params,
59  const Destination &destination,
61 {
62  const int64_t pass_stride = buffer_params.pass_stride;
63  const int64_t buffer_row_stride = buffer_params.stride * buffer_params.pass_stride;
64 
65  const float *window_data = render_buffers->buffer.data() + buffer_params.window_x * pass_stride +
66  buffer_params.window_y * buffer_row_stride;
67 
68  half4 *dst_start = destination.pixels_half_rgba + destination.offset;
69  const int destination_stride = destination.stride != 0 ? destination.stride :
70  buffer_params.width;
71 
72  parallel_for(0, buffer_params.window_height, [&](int64_t y) {
73  const float *buffer = window_data + y * buffer_row_stride;
74  half4 *pixel = dst_start + y * destination_stride;
75  func(kfilm_convert, buffer, pixel, buffer_params.window_width, pass_stride);
76  });
77 }
78 
79 /* --------------------------------------------------------------------
80  * Pass accessors.
81  */
82 
83 #define DEFINE_PASS_ACCESSOR(pass) \
84  void PassAccessorCPU::get_pass_##pass(const RenderBuffers *render_buffers, \
85  const BufferParams &buffer_params, \
86  const Destination &destination) const \
87  { \
88  const CPUKernels &kernels = Device::get_cpu_kernels(); \
89  KernelFilmConvert kfilm_convert; \
90  init_kernel_film_convert(&kfilm_convert, buffer_params, destination); \
91 \
92  if (destination.pixels) { \
93  run_get_pass_kernel_processor_float(&kfilm_convert, \
94  render_buffers, \
95  buffer_params, \
96  destination, \
97  kernels.film_convert_##pass); \
98  } \
99 \
100  if (destination.pixels_half_rgba) { \
101  run_get_pass_kernel_processor_half_rgba(&kfilm_convert, \
102  render_buffers, \
103  buffer_params, \
104  destination, \
105  kernels.film_convert_half_rgba_##pass); \
106  } \
107  }
108 
109 /* Float (scalar) passes. */
112 DEFINE_PASS_ACCESSOR(sample_count)
114 
115 /* Float3 passes. */
116 DEFINE_PASS_ACCESSOR(light_path)
117 DEFINE_PASS_ACCESSOR(shadow_catcher)
119 
120 /* Float4 passes. */
121 DEFINE_PASS_ACCESSOR(motion)
122 DEFINE_PASS_ACCESSOR(cryptomatte)
123 DEFINE_PASS_ACCESSOR(shadow_catcher_matte_with_shadow)
124 DEFINE_PASS_ACCESSOR(combined)
126 
127 #undef DEFINE_PASS_ACCESSOR
128 
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
float float4[4]
int pass_stride
Definition: buffers.h:93
int stride
Definition: buffers.h:90
int window_y
Definition: buffers.h:79
int window_height
Definition: buffers.h:81
NODE_DECLARE int width
Definition: buffers.h:71
int window_x
Definition: buffers.h:78
void run_get_pass_kernel_processor_float(const KernelFilmConvert *kfilm_convert, const RenderBuffers *render_buffers, const BufferParams &buffer_params, const Destination &destination, const CPUKernels::FilmConvertFunction func) const
void run_get_pass_kernel_processor_half_rgba(const KernelFilmConvert *kfilm_convert, const RenderBuffers *render_buffers, const BufferParams &buffer_params, const Destination &destination, const CPUKernels::FilmConvertHalfRGBAFunction func) const
device_vector< float > buffer
Definition: buffers.h:159
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
ccl_gpu_kernel_postfix ccl_global float int int int int int int int pass_stride
#define DCHECK_EQ(a, b)
Definition: log.h:64
void parallel_for(IndexRange range, int64_t grain_size, const Function &function)
Definition: BLI_task.hh:51
#define DEFINE_PASS_ACCESSOR(pass)
__int64 int64_t
Definition: stdint.h:89
Definition: half.h:64