Blender  V3.3
write_passes.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #pragma once
5 
6 #ifdef __KERNEL_GPU__
7 # define __ATOMIC_PASS_WRITE__
8 #endif
9 
11 
13 {
14 #ifdef __ATOMIC_PASS_WRITE__
16 #else
17  *buffer += value;
18 #endif
19 }
20 
22  float3 value)
23 {
24 #ifdef __ATOMIC_PASS_WRITE__
25  ccl_global float *buf_x = buffer + 0;
26  ccl_global float *buf_y = buffer + 1;
27  ccl_global float *buf_z = buffer + 2;
28 
29  atomic_add_and_fetch_float(buf_x, value.x);
30  atomic_add_and_fetch_float(buf_y, value.y);
31  atomic_add_and_fetch_float(buf_z, value.z);
32 #else
33  buffer[0] += value.x;
34  buffer[1] += value.y;
35  buffer[2] += value.z;
36 #endif
37 }
38 
40  float4 value)
41 {
42 #ifdef __ATOMIC_PASS_WRITE__
43  ccl_global float *buf_x = buffer + 0;
44  ccl_global float *buf_y = buffer + 1;
45  ccl_global float *buf_z = buffer + 2;
46  ccl_global float *buf_w = buffer + 3;
47 
48  atomic_add_and_fetch_float(buf_x, value.x);
49  atomic_add_and_fetch_float(buf_y, value.y);
50  atomic_add_and_fetch_float(buf_z, value.z);
51  atomic_add_and_fetch_float(buf_w, value.w);
52 #else
53  buffer[0] += value.x;
54  buffer[1] += value.y;
55  buffer[2] += value.z;
56  buffer[3] += value.w;
57 #endif
58 }
59 
61 {
62  return *buffer;
63 }
64 
66 {
67  return make_float3(buffer[0], buffer[1], buffer[2]);
68 }
69 
71 {
72  return make_float4(buffer[0], buffer[1], buffer[2], buffer[3]);
73 }
74 
float float4[4]
#define atomic_add_and_fetch_float(p, x)
Definition: atomic.h:12
#define ccl_restrict
Definition: cuda/compat.h:50
#define ccl_device_inline
Definition: cuda/compat.h:34
#define ccl_global
Definition: cuda/compat.h:43
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
ccl_global float * buffer
#define make_float4(x, y, z, w)
Definition: metal/compat.h:205
#define make_float3(x, y, z)
Definition: metal/compat.h:204
float z
float y
float x
CCL_NAMESPACE_BEGIN ccl_device_inline void kernel_write_pass_float(ccl_global float *ccl_restrict buffer, float value)
Definition: write_passes.h:12
ccl_device_inline float kernel_read_pass_float(ccl_global float *ccl_restrict buffer)
Definition: write_passes.h:60
ccl_device_inline void kernel_write_pass_float3(ccl_global float *ccl_restrict buffer, float3 value)
Definition: write_passes.h:21
ccl_device_inline float3 kernel_read_pass_float3(ccl_global float *ccl_restrict buffer)
Definition: write_passes.h:65
ccl_device_inline float4 kernel_read_pass_float4(ccl_global float *ccl_restrict buffer)
Definition: write_passes.h:70
ccl_device_inline void kernel_write_pass_float4(ccl_global float *ccl_restrict buffer, float4 value)
Definition: write_passes.h:39