Blender V5.3
kernel_arch_impl.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5/* Templated common implementation part of all CPU kernels.
6 *
7 * The idea is that particular `.cpp` files sets needed optimization flags and
8 * simply includes this file without worry of copying actual implementation over.
9 */
10
11#pragma once
12
13// clang-format off
15
16#ifndef KERNEL_STUB
17# include "kernel/globals.h"
18
19# include "kernel/util/image.h"
20
24
28
31# include "kernel/film/read.h"
33
34# include "kernel/bake/bake.h"
35
36#else
37# define STUB_ASSERT(arch, name) \
38 assert(!(#name " kernel stub for architecture " #arch " was called!"))
39#endif /* KERNEL_STUB */
40// clang-format on
41
43
44/* --------------------------------------------------------------------
45 * Integrator.
46 */
47
48#ifdef KERNEL_STUB
49# define KERNEL_INVOKE(name, ...) (STUB_ASSERT(KERNEL_ARCH, name), 0)
50#else
51# define KERNEL_INVOKE(name, ...) integrator_##name(__VA_ARGS__)
52#endif
53
54/* TODO: Either use something like get_work_pixel(), or simplify tile which is passed here, so
55 * that it does not contain unused fields. */
56#define DEFINE_INTEGRATOR_INIT_KERNEL(name) \
57 bool KERNEL_FUNCTION_FULL_NAME(integrator_##name)(const ThreadKernelGlobalsCPU *kg, \
58 IntegratorStateCPU *state, \
59 KernelWorkTile *tile, \
60 ccl_global float *render_buffer) \
61 { \
62 (void)kg; \
63 (void)state; \
64 (void)tile; \
65 (void)render_buffer; \
66 return KERNEL_INVOKE( \
67 name, kg, state, tile, render_buffer, tile->x, tile->y, tile->start_sample); \
68 }
69
70#define DEFINE_INTEGRATOR_SHADE_KERNEL(name) \
71 void KERNEL_FUNCTION_FULL_NAME(integrator_##name)(const ThreadKernelGlobalsCPU *kg, \
72 IntegratorStateCPU *state, \
73 ccl_global float *render_buffer) \
74 { \
75 (void)kg; \
76 (void)state; \
77 (void)render_buffer; \
78 KERNEL_INVOKE(name, kg, state, render_buffer); \
79 }
80
81DEFINE_INTEGRATOR_INIT_KERNEL(init_from_camera)
84
85/* --------------------------------------------------------------------
86 * Shader evaluation.
87 */
88
90 const KernelShaderEvalInput *input,
91 float *output,
92 const int offset)
93{
94#ifdef KERNEL_STUB
96 (void)kg;
97 (void)input;
98 (void)output;
99 (void)offset;
100#else
101 uint cache_miss_unused = false;
102 kernel_displace_evaluate(kg, input, output, &cache_miss_unused, offset);
103#endif
104}
105
107 const KernelShaderEvalInput *input,
108 float *output,
109 const int offset)
110{
111#ifdef KERNEL_STUB
113 (void)kg;
114 (void)input;
115 (void)output;
116 (void)offset;
117#else
118 uint cache_miss_unused = false;
119 kernel_background_evaluate(kg, input, output, &cache_miss_unused, offset);
120#endif
121}
122
124 const ThreadKernelGlobalsCPU *kg,
125 const KernelShaderEvalInput *input,
126 float *output,
127 const int offset)
128{
129#ifdef KERNEL_STUB
131 (void)kg;
132 (void)input;
133 (void)output;
134 (void)offset;
135#else
136 uint cache_miss_unused = false;
137 kernel_curve_shadow_transparency_evaluate(kg, input, output, &cache_miss_unused, offset);
138#endif
139}
140
142 const KernelShaderEvalInput *input,
143 float *output,
144 const int offset)
145{
146#ifdef KERNEL_STUB
148 (void)kg;
149 (void)input;
150 (void)output;
151 (void)offset;
152#else
153 uint cache_miss_unused = false;
154 kernel_volume_density_evaluate(kg, input, output, &cache_miss_unused, offset);
155#endif
156}
157
158/* --------------------------------------------------------------------
159 * Adaptive sampling.
160 */
161
163 const ThreadKernelGlobalsCPU *kg,
165 const int x,
166 const int y,
167 const float threshold,
168 const int reset,
169 const int offset,
170 const int stride)
171{
172#ifdef KERNEL_STUB
174 (void)kg;
175 (void)render_buffer;
176 (void)x;
177 (void)y;
178 (void)threshold;
179 (void)reset;
180 (void)offset;
181 (void)stride;
182 return false;
183#else
185 kg, render_buffer, x, y, threshold, reset, offset, stride);
186#endif
187}
188
191 const int y,
192 const int start_x,
193 const int width,
194 const int offset,
195 const int stride)
196{
197#ifdef KERNEL_STUB
199 (void)kg;
200 (void)render_buffer;
201 (void)y;
202 (void)start_x;
203 (void)width;
204 (void)offset;
205 (void)stride;
206#else
207 film_adaptive_sampling_filter_x(kg, render_buffer, y, start_x, width, offset, stride);
208#endif
209}
210
213 const int x,
214 const int start_y,
215 const int height,
216 const int offset,
217 const int stride)
218{
219#ifdef KERNEL_STUB
221 (void)kg;
222 (void)render_buffer;
223 (void)x;
224 (void)start_y;
225 (void)height;
226 (void)offset;
227 (void)stride;
228#else
229 film_adaptive_sampling_filter_y(kg, render_buffer, x, start_y, height, offset, stride);
230#endif
231}
232
233/* --------------------------------------------------------------------
234 * Cryptomatte.
235 */
236
239 const int pixel_index)
240{
241#ifdef KERNEL_STUB
243 (void)kg;
244 (void)render_buffer;
245 (void)pixel_index;
246#else
247 film_cryptomatte_post(kg, render_buffer, pixel_index);
248#endif
249}
250
251/* --------------------------------------------------------------------
252 * Volume Scattering Probability Guiding.
253 */
254
257 const int y,
258 const int center_x,
259 const int min_x,
260 const int max_x,
261 const int offset,
262 const int stride)
263{
264#ifdef KERNEL_STUB
266 (void)kg;
267 (void)render_buffer;
268 (void)y;
269 (void)center_x;
270 (void)min_x;
271 (void)max_x;
272 (void)offset;
273 (void)stride;
274#else
275 volume_guiding_filter_x(kg, render_buffer, y, center_x, min_x, max_x, offset, stride);
276#endif
277}
278
281 const int x,
282 const int min_y,
283 const int max_y,
284 const int offset,
285 const int stride)
286{
287#ifdef KERNEL_STUB
289 (void)kg;
290 (void)render_buffer;
291 (void)x;
292 (void)min_y;
293 (void)max_y;
294 (void)offset;
295 (void)stride;
296#else
297 volume_guiding_filter_y(kg, render_buffer, x, min_y, max_y, offset, stride);
298#endif
299}
300
301/* --------------------------------------------------------------------
302 * Film Convert.
303 */
304
305#ifdef KERNEL_STUB
306
307# define KERNEL_FILM_CONVERT_FUNCTION(name, is_float) \
308 void KERNEL_FUNCTION_FULL_NAME(film_convert_##name)(const KernelFilmConvert *kfilm_convert, \
309 const float *buffer, \
310 float *pixel, \
311 const int width, \
312 const int buffer_stride, \
313 const int pixel_stride) \
314 { \
315 STUB_ASSERT(KERNEL_ARCH, film_convert_##name); \
316 (void)kfilm_convert; \
317 (void)buffer; \
318 (void)pixel; \
319 (void)width; \
320 (void)buffer_stride; \
321 (void)pixel_stride; \
322 } \
323 void KERNEL_FUNCTION_FULL_NAME(film_convert_half_rgba_##name)( \
324 const KernelFilmConvert *kfilm_convert, \
325 const float *buffer, \
326 half4 *pixel, \
327 const int width, \
328 const int buffer_stride) \
329 { \
330 STUB_ASSERT(KERNEL_ARCH, film_convert_##name); \
331 (void)kfilm_convert; \
332 (void)buffer; \
333 (void)pixel; \
334 (void)width; \
335 (void)buffer_stride; \
336 }
337
338#else
339
340# define KERNEL_FILM_CONVERT_FUNCTION(name, is_float) \
341 void KERNEL_FUNCTION_FULL_NAME(film_convert_##name)(const KernelFilmConvert *kfilm_convert, \
342 const float *buffer, \
343 float *pixel, \
344 const int width, \
345 const int buffer_stride, \
346 const int pixel_stride) \
347 { \
348 for (int i = 0; i < width; i++, buffer += buffer_stride, pixel += pixel_stride) { \
349 film_get_pass_pixel_##name(kfilm_convert, buffer, pixel); \
350 } \
351 } \
352 void KERNEL_FUNCTION_FULL_NAME(film_convert_half_rgba_##name)( \
353 const KernelFilmConvert *kfilm_convert, \
354 const float *buffer, \
355 half4 *pixel, \
356 const int width, \
357 const int buffer_stride) \
358 { \
359 for (int i = 0; i < width; i++, buffer += buffer_stride, pixel++) { \
360 float pixel_rgba[4] = {0.0f, 0.0f, 0.0f, 1.0f}; \
361 film_get_pass_pixel_##name(kfilm_convert, buffer, pixel_rgba); \
362 if (is_float) { \
363 pixel_rgba[1] = pixel_rgba[0]; \
364 pixel_rgba[2] = pixel_rgba[0]; \
365 } \
366 film_apply_pass_pixel_overlays_rgba(kfilm_convert, buffer, pixel_rgba); \
367 *pixel = float4_to_half4_display( \
368 make_float4(pixel_rgba[0], pixel_rgba[1], pixel_rgba[2], pixel_rgba[3])); \
369 } \
370 }
371
372#endif
373
376KERNEL_FILM_CONVERT_FUNCTION(sample_count, true)
377KERNEL_FILM_CONVERT_FUNCTION(volume_majorant, true)
379
380KERNEL_FILM_CONVERT_FUNCTION(light_path, false)
383
384KERNEL_FILM_CONVERT_FUNCTION(motion, false)
385KERNEL_FILM_CONVERT_FUNCTION(cryptomatte, false)
386KERNEL_FILM_CONVERT_FUNCTION(shadow_catcher, false)
387KERNEL_FILM_CONVERT_FUNCTION(shadow_catcher_matte_with_shadow, false)
388KERNEL_FILM_CONVERT_FUNCTION(combined, false)
390
391#undef KERNEL_FILM_CONVERT_FUNCTION
392
393#undef KERNEL_INVOKE
394#undef DEFINE_INTEGRATOR_SHADE_KERNEL
395#undef DEFINE_INTEGRATOR_INIT_KERNEL
396
397#undef KERNEL_STUB
398#undef STUB_ASSERT
399#undef KERNEL_ARCH
400
#define output
void reset()
ccl_device_inline void film_cryptomatte_post(KernelGlobals kg, ccl_global float *render_buffer, const int pixel_index)
#define ccl_global
#define KERNEL_FILM_CONVERT_FUNCTION(name)
#define CCL_NAMESPACE_END
ccl_device void kernel_volume_density_evaluate(KernelGlobals kg, ccl_global const KernelShaderEvalInput *input, ccl_global float *output, ccl_global uint *cache_miss, const int offset)
ccl_device void kernel_background_evaluate(KernelGlobals kg, const ccl_global KernelShaderEvalInput *input, ccl_global float *output, ccl_global uint *cache_miss, const int offset)
ccl_device void kernel_curve_shadow_transparency_evaluate(KernelGlobals kg, const ccl_global KernelShaderEvalInput *input, ccl_global float *output, ccl_global uint *cache_miss, const int offset)
CCL_NAMESPACE_BEGIN ccl_device void kernel_displace_evaluate(KernelGlobals kg, const ccl_global KernelShaderEvalInput *input, ccl_global float *output, ccl_global uint *cache_miss, const int offset)
#define KERNEL_ARCH
#define KERNEL_FUNCTION_FULL_NAME(name)
ccl_gpu_kernel_postfix ccl_global KernelWorkTile const int ccl_global float * render_buffer
ccl_device void film_adaptive_sampling_filter_y(KernelGlobals kg, ccl_global float *render_buffer, const int x, const int start_y, const int height, const int offset, const int stride)
ccl_device void film_adaptive_sampling_filter_x(KernelGlobals kg, ccl_global float *render_buffer, const int y, const int start_x, const int width, const int offset, const int stride)
ccl_device bool film_adaptive_sampling_convergence_check(KernelGlobals kg, ccl_global float *render_buffer, const int x, const int y, const float threshold, const int reset, const int offset, const int stride)
void KERNEL_FUNCTION_FULL_NAME volume_guiding_filter_x(const ThreadKernelGlobalsCPU *kg, ccl_global float *render_buffer, const int y, const int center_x, const int min_x, const int max_x, const int offset, int stride)
void KERNEL_FUNCTION_FULL_NAME volume_guiding_filter_y(const ThreadKernelGlobalsCPU *kg, ccl_global float *render_buffer, const int x, const int center_y, const int height, const int offset, int stride)
void KERNEL_FUNCTION_FULL_NAME shader_eval_background(const ThreadKernelGlobalsCPU *kg, const KernelShaderEvalInput *input, float *output, const int offset)
bool KERNEL_FUNCTION_FULL_NAME adaptive_sampling_convergence_check(const ThreadKernelGlobalsCPU *kg, ccl_global float *render_buffer, const int x, const int y, const float threshold, const int reset, const int offset, int stride)
void KERNEL_FUNCTION_FULL_NAME cryptomatte_postprocess(const ThreadKernelGlobalsCPU *kg, ccl_global float *render_buffer, int pixel_index)
void KERNEL_FUNCTION_FULL_NAME shader_eval_displace(const ThreadKernelGlobalsCPU *kg, const KernelShaderEvalInput *input, float *output, const int offset)
void KERNEL_FUNCTION_FULL_NAME adaptive_sampling_filter_x(const ThreadKernelGlobalsCPU *kg, ccl_global float *render_buffer, const int y, const int start_x, const int width, const int offset, int stride)
void KERNEL_FUNCTION_FULL_NAME adaptive_sampling_filter_y(const ThreadKernelGlobalsCPU *kg, ccl_global float *render_buffer, const int x, const int start_y, const int height, const int offset, int stride)
void KERNEL_FUNCTION_FULL_NAME shader_eval_curve_shadow_transparency(const ThreadKernelGlobalsCPU *kg, const KernelShaderEvalInput *input, float *output, const int offset)
void KERNEL_FUNCTION_FULL_NAME shader_eval_volume_density(const ThreadKernelGlobalsCPU *kg, const KernelShaderEvalInput *input, float *output, const int offset)
#define DEFINE_INTEGRATOR_INIT_KERNEL(name)
#define DEFINE_INTEGRATOR_SHADE_KERNEL(name)