Blender V5.3
pass_accessor_gpu.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "device/queue.h"
6
8
9#include "session/buffers.h"
10
12
14 const PassAccessInfo &pass_access_info,
15 const float exposure,
16 const int num_samples)
17 : PassAccessor(pass_access_info, exposure, num_samples), queue_(queue)
18{
19}
20
21/* --------------------------------------------------------------------
22 * Kernel execution.
23 */
24
26 const RenderBuffers *render_buffers,
27 const BufferParams &buffer_params,
28 const Destination &destination) const
29{
30 KernelFilmConvert kfilm_convert;
31 init_kernel_film_convert(&kfilm_convert, buffer_params, destination);
32
33 const int work_size = buffer_params.window_width * buffer_params.window_height;
34 if (!work_size) {
35 return;
36 }
37
38 const int destination_stride = destination.stride != 0 ? destination.stride :
39 buffer_params.window_width;
40
41 const int offset = buffer_params.window_x * buffer_params.pass_stride +
42 buffer_params.window_y * buffer_params.stride * buffer_params.pass_stride;
43
45 if (destination.d_pixels) {
46 DCHECK_EQ(destination.stride, 0) << "Custom stride for float destination is not implemented.";
47
48 const DeviceKernelArguments args(&kfilm_convert,
49 &destination.d_pixels,
50 &render_buffers->buffer.device_pointer,
51 &work_size,
52 &buffer_params.window_width,
53 &offset,
54 &buffer_params.stride,
55 &destination.pixel_offset,
56 &destination.offset,
57 &destination_stride);
58
59 queue_->enqueue(kernel, work_size, args);
60 }
61 if (destination.d_pixels_half_rgba) {
62 const DeviceKernel kernel_half_float = static_cast<DeviceKernel>(kernel + 1);
63
64 const DeviceKernelArguments args(&kfilm_convert,
65 &destination.d_pixels_half_rgba,
66 &render_buffers->buffer.device_pointer,
67 &work_size,
68 &buffer_params.window_width,
69 &offset,
70 &buffer_params.stride,
71 &destination.offset,
72 &destination_stride);
73
74 queue_->enqueue(kernel_half_float, work_size, args);
75 }
76
78}
79
80/* --------------------------------------------------------------------
81 * Pass accessors.
82 */
83
84#define DEFINE_PASS_ACCESSOR(pass, kernel_pass) \
85 void PassAccessorGPU::get_pass_##pass(const RenderBuffers *render_buffers, \
86 const BufferParams &buffer_params, \
87 const Destination &destination) const \
88 { \
89 run_film_convert_kernels( \
90 DEVICE_KERNEL_FILM_CONVERT_##kernel_pass, render_buffers, buffer_params, destination); \
91 }
92
93/* Float (scalar) passes. */
96DEFINE_PASS_ACCESSOR(volume_majorant, VOLUME_MAJORANT);
97DEFINE_PASS_ACCESSOR(sample_count, SAMPLE_COUNT);
99
100/* Float3 passes. */
101DEFINE_PASS_ACCESSOR(light_path, LIGHT_PATH);
104
105/* Float4 passes. */
106DEFINE_PASS_ACCESSOR(motion, MOTION);
107DEFINE_PASS_ACCESSOR(cryptomatte, CRYPTOMATTE);
108DEFINE_PASS_ACCESSOR(shadow_catcher, SHADOW_CATCHER);
109DEFINE_PASS_ACCESSOR(shadow_catcher_matte_with_shadow, SHADOW_CATCHER_MATTE_WITH_SHADOW);
110DEFINE_PASS_ACCESSOR(combined, COMBINED);
112
113#undef DEFINE_PASS_ACCESSOR
114
int pass_stride
Definition buffers.h:92
int window_y
Definition buffers.h:78
int window_height
Definition buffers.h:80
int window_width
Definition buffers.h:79
int window_x
Definition buffers.h:77
virtual bool enqueue(DeviceKernel kernel, const int work_size, const DeviceKernelArguments &args)=0
virtual void init_execution()=0
virtual bool synchronize()=0
PassAccessorGPU(DeviceQueue *queue, const PassAccessInfo &pass_access_info, const float exposure, int num_samples)
DeviceQueue * queue_
void run_film_convert_kernels(DeviceKernel kernel, const RenderBuffers *render_buffers, const BufferParams &buffer_params, const Destination &destination) const
PassAccessor(const PassAccessInfo &pass_access_info, const float exposure, const int num_samples)
virtual void init_kernel_film_convert(KernelFilmConvert *kfilm_convert, const BufferParams &buffer_params, const Destination &destination) const
device_vector< float > buffer
Definition buffers.h:158
nullptr FLOAT
#define CCL_NAMESPACE_END
ccl_gpu_kernel_postfix const ccl_global int ccl_global float const int work_size
DeviceKernel
#define DCHECK_EQ(a, b)
Definition log.h:144
#define DEFINE_PASS_ACCESSOR(pass)