[Bf-blender-cvs] [329f704] master: Cycles: Move utility atomics function to util_atomic.h

Sergey Sharybin noreply at git.blender.org
Thu May 21 13:13:14 CEST 2015


Commit: 329f7046011fa23387649d68d5d2b26629f1d32d
Author: Sergey Sharybin
Date:   Thu May 21 15:48:50 2015 +0500
Branches: master
https://developer.blender.org/rB329f7046011fa23387649d68d5d2b26629f1d32d

Cycles: Move utility atomics function to util_atomic.h

No functional changes, just better to keep all atomic function in a single place,
they might become handy later.

===================================================================

M	SConstruct
M	intern/cycles/kernel/CMakeLists.txt
M	intern/cycles/kernel/kernel_split.h
M	intern/cycles/util/util_atomic.h

===================================================================

diff --git a/SConstruct b/SConstruct
index 6cf3874..c5e1d66 100644
--- a/SConstruct
+++ b/SConstruct
@@ -1028,6 +1028,7 @@ if env['OURPLATFORM']!='darwin':
             source.remove('shaders')
             source.remove('osl')
             source=['intern/cycles/kernel/'+s for s in source]
+            source.append('intern/cycles/util/util_atomic.h')
             source.append('intern/cycles/util/util_color.h')
             source.append('intern/cycles/util/util_half.h')
             source.append('intern/cycles/util/util_math.h')
diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt
index 13eb5ca..3e16c4b 100644
--- a/intern/cycles/kernel/CMakeLists.txt
+++ b/intern/cycles/kernel/CMakeLists.txt
@@ -154,6 +154,7 @@ set(SRC_GEOM_HEADERS
 )
 
 set(SRC_UTIL_HEADERS
+	../util/util_atomic.h
 	../util/util_color.h
 	../util/util_half.h
 	../util/util_math.h
diff --git a/intern/cycles/kernel/kernel_split.h b/intern/cycles/kernel/kernel_split.h
index eb386c2..52baf68 100644
--- a/intern/cycles/kernel/kernel_split.h
+++ b/intern/cycles/kernel/kernel_split.h
@@ -22,28 +22,7 @@
 #include "kernel_types.h"
 #include "kernel_globals.h"
 
-/* atomic_add_float function should be defined prior to its usage in kernel_passes.h */
-#if defined(__SPLIT_KERNEL__) && defined(__WORK_STEALING__)
-/* Utility functions for float atomics */
-/* float atomics impl credits : http://suhorukov.blogspot.in/2011/12/opencl-11-atomic-operations-on-floating.html */
-ccl_device_inline void atomic_add_float(volatile ccl_global float *source, const float operand) {
-	union {
-		unsigned int intVal;
-		float floatVal;
-
-	} newVal;
-	union {
-		unsigned int intVal;
-		float floatVal;
-
-	} prevVal;
-	do {
-		prevVal.floatVal = *source;
-		newVal.floatVal = prevVal.floatVal + operand;
-
-	} while (atomic_cmpxchg((volatile ccl_global unsigned int *)source, prevVal.intVal, newVal.intVal) != prevVal.intVal);
-}
-#endif // __SPLIT_KERNEL__ && __WORK_STEALING__
+#include "util_atomic.h"
 
 #ifdef __OSL__
 #include "osl_shader.h"
diff --git a/intern/cycles/util/util_atomic.h b/intern/cycles/util/util_atomic.h
index fa0d35e..85a82d3 100644
--- a/intern/cycles/util/util_atomic.h
+++ b/intern/cycles/util/util_atomic.h
@@ -17,6 +17,8 @@
 #ifndef __UTIL_ATOMIC_H__
 #define __UTIL_ATOMIC_H__
 
+#ifndef __KERNEL_GPU__
+
 /* Using atomic ops header from Blender. */
 #include "atomic_ops.h"
 
@@ -30,4 +32,34 @@ ATOMIC_INLINE void atomic_update_max_z(size_t *maximum_value, size_t value)
 	}
 }
 
+#else  /* __KERNEL_GPU__ */
+
+#ifdef __KERNEL_OPENCL__
+
+/* Float atomics implementation credits:
+ *   http://suhorukov.blogspot.in/2011/12/opencl-11-atomic-operations-on-floating.html
+ */
+ccl_device_inline void atomic_add_float(volatile ccl_global float *source,
+                                        const float operand)
+{
+	union {
+		unsigned int int_value;
+		float float_value;
+	} new_value;
+	union {
+		unsigned int int_value;
+		float float_value;
+	} prev_value;
+	do {
+		prev_value.float_value = *source;
+		new_value.float_value = prev_value.float_value + operand;
+	} while (atomic_cmpxchg((volatile ccl_global unsigned int *)source,
+	                        prev_value.int_value,
+	                        new_value.int_value) != prev_value.int_value);
+}
+
+#endif  /* __KERNEL_OPENCL__ */
+
+#endif  /* __KERNEL_GPU__ */
+
 #endif /* __UTIL_ATOMIC_H__ */




More information about the Bf-blender-cvs mailing list