Blender  V2.93
kernel_write_passes.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #if defined(__SPLIT_KERNEL__) || defined(__KERNEL_CUDA__)
18 # define __ATOMIC_PASS_WRITE__
19 #endif
20 
22 
24 {
25  ccl_global float *buf = buffer;
26 #ifdef __ATOMIC_PASS_WRITE__
27  atomic_add_and_fetch_float(buf, value);
28 #else
29  *buf += value;
30 #endif
31 }
32 
34 {
35 #ifdef __ATOMIC_PASS_WRITE__
36  ccl_global float *buf_x = buffer + 0;
37  ccl_global float *buf_y = buffer + 1;
38  ccl_global float *buf_z = buffer + 2;
39 
40  atomic_add_and_fetch_float(buf_x, value.x);
41  atomic_add_and_fetch_float(buf_y, value.y);
42  atomic_add_and_fetch_float(buf_z, value.z);
43 #else
45  *buf += value;
46 #endif
47 }
48 
50 {
51 #ifdef __ATOMIC_PASS_WRITE__
52  ccl_global float *buf_x = buffer + 0;
53  ccl_global float *buf_y = buffer + 1;
54  ccl_global float *buf_z = buffer + 2;
55  ccl_global float *buf_w = buffer + 3;
56 
57  atomic_add_and_fetch_float(buf_x, value.x);
58  atomic_add_and_fetch_float(buf_y, value.y);
59  atomic_add_and_fetch_float(buf_z, value.z);
60  atomic_add_and_fetch_float(buf_w, value.w);
61 #else
62  ccl_global float4 *buf = (ccl_global float4 *)buffer;
63  *buf += value;
64 #endif
65 }
66 
67 #ifdef __DENOISING_FEATURES__
68 ccl_device_inline void kernel_write_pass_float_variance(ccl_global float *buffer, float value)
69 {
71 
72  /* The online one-pass variance update that's used for the megakernel can't easily be implemented
73  * with atomics, so for the split kernel the E[x^2] - 1/N * (E[x])^2 fallback is used. */
74  kernel_write_pass_float(buffer + 1, value * value);
75 }
76 
77 # ifdef __ATOMIC_PASS_WRITE__
78 # define kernel_write_pass_float3_unaligned kernel_write_pass_float3
79 # else
80 ccl_device_inline void kernel_write_pass_float3_unaligned(ccl_global float *buffer, float3 value)
81 {
82  buffer[0] += value.x;
83  buffer[1] += value.y;
84  buffer[2] += value.z;
85 }
86 # endif
87 
88 ccl_device_inline void kernel_write_pass_float3_variance(ccl_global float *buffer, float3 value)
89 {
90  kernel_write_pass_float3_unaligned(buffer, value);
91  kernel_write_pass_float3_unaligned(buffer + 3, value * value);
92 }
93 #endif /* __DENOISING_FEATURES__ */
94 
#define ccl_device_inline
#define ccl_global
#define CCL_NAMESPACE_END
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
ccl_device_inline void kernel_write_pass_float3(ccl_global float *buffer, float3 value)
ccl_device_inline void kernel_write_pass_float4(ccl_global float *buffer, float4 value)
CCL_NAMESPACE_BEGIN ccl_device_inline void kernel_write_pass_float(ccl_global float *buffer, float value)
float z
Definition: sky_float3.h:35
float y
Definition: sky_float3.h:35
float x
Definition: sky_float3.h:35
#define atomic_add_and_fetch_float(p, x)
Definition: util_atomic.h:25