Blender V5.0
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
35 const int destination_stride = destination.stride != 0 ? destination.stride :
36 buffer_params.window_width;
37
38 const int offset = buffer_params.window_x * buffer_params.pass_stride +
39 buffer_params.window_y * buffer_params.stride * buffer_params.pass_stride;
40
41 queue_->init_execution();
42 if (destination.d_pixels) {
43 DCHECK_EQ(destination.stride, 0) << "Custom stride for float destination is not implemented.";
44
45 const DeviceKernelArguments args(&kfilm_convert,
46 &destination.d_pixels,
47 &render_buffers->buffer.device_pointer,
48 &work_size,
49 &buffer_params.window_width,
50 &offset,
51 &buffer_params.stride,
52 &destination.pixel_offset,
53 &destination.offset,
54 &destination_stride);
55
56 queue_->enqueue(kernel, work_size, args);
57 }
58 if (destination.d_pixels_half_rgba) {
59 const DeviceKernel kernel_half_float = static_cast<DeviceKernel>(kernel + 1);
60
61 const DeviceKernelArguments args(&kfilm_convert,
62 &destination.d_pixels_half_rgba,
63 &render_buffers->buffer.device_pointer,
64 &work_size,
65 &buffer_params.window_width,
66 &offset,
67 &buffer_params.stride,
68 &destination.offset,
69 &destination_stride);
70
71 queue_->enqueue(kernel_half_float, work_size, args);
72 }
73
74 queue_->synchronize();
75}
76
77/* --------------------------------------------------------------------
78 * Pass accessors.
79 */
80
81#define DEFINE_PASS_ACCESSOR(pass, kernel_pass) \
82 void PassAccessorGPU::get_pass_##pass(const RenderBuffers *render_buffers, \
83 const BufferParams &buffer_params, \
84 const Destination &destination) const \
85 { \
86 run_film_convert_kernels( \
87 DEVICE_KERNEL_FILM_CONVERT_##kernel_pass, render_buffers, buffer_params, destination); \
88 }
89
90/* Float (scalar) passes. */
93DEFINE_PASS_ACCESSOR(volume_majorant, VOLUME_MAJORANT);
94DEFINE_PASS_ACCESSOR(sample_count, SAMPLE_COUNT);
96
97/* Float3 passes. */
98DEFINE_PASS_ACCESSOR(light_path, LIGHT_PATH);
101
102/* Float4 passes. */
103DEFINE_PASS_ACCESSOR(motion, MOTION);
104DEFINE_PASS_ACCESSOR(cryptomatte, CRYPTOMATTE);
105DEFINE_PASS_ACCESSOR(shadow_catcher, SHADOW_CATCHER);
106DEFINE_PASS_ACCESSOR(shadow_catcher_matte_with_shadow, SHADOW_CATCHER_MATTE_WITH_SHADOW);
107DEFINE_PASS_ACCESSOR(combined, COMBINED);
109
110#undef DEFINE_PASS_ACCESSOR
111
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
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, kernel_pass)
@ FLOAT4
@ FLOAT3