[Bf-blender-cvs] [793d2031395] master: Cycles: add math functions for float8

Andrii Symkin noreply at git.blender.org
Mon Jul 25 17:53:25 CEST 2022


Commit: 793d2031395246fb2421d130742e0fe61ab2b29c
Author: Andrii Symkin
Date:   Mon Jul 25 16:55:48 2022 +0200
Branches: master
https://developer.blender.org/rB793d2031395246fb2421d130742e0fe61ab2b29c

Cycles: add math functions for float8

This patch adds required math functions for float8 to make it possible
using float8 instead of float3 for color data.

Differential Revision: https://developer.blender.org/D15525

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

M	intern/cycles/kernel/CMakeLists.txt
M	intern/cycles/util/CMakeLists.txt
M	intern/cycles/util/math.h
A	intern/cycles/util/math_float8.h
M	intern/cycles/util/types_float8.h
M	intern/cycles/util/types_float8_impl.h

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

diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt
index 94632dff200..8ecdac6ee27 100644
--- a/intern/cycles/kernel/CMakeLists.txt
+++ b/intern/cycles/kernel/CMakeLists.txt
@@ -317,6 +317,7 @@ set(SRC_UTIL_HEADERS
   ../util/math_float2.h
   ../util/math_float3.h
   ../util/math_float4.h
+  ../util/math_float8.h
   ../util/math_int2.h
   ../util/math_int3.h
   ../util/math_int4.h
diff --git a/intern/cycles/util/CMakeLists.txt b/intern/cycles/util/CMakeLists.txt
index fddac1dbbcf..9bc9f00e142 100644
--- a/intern/cycles/util/CMakeLists.txt
+++ b/intern/cycles/util/CMakeLists.txt
@@ -63,6 +63,7 @@ set(SRC_HEADERS
   math_float2.h
   math_float3.h
   math_float4.h
+  math_float8.h
   math_int2.h
   math_int3.h
   math_int4.h
diff --git a/intern/cycles/util/math.h b/intern/cycles/util/math.h
index 8360ce05a56..2631304c84b 100644
--- a/intern/cycles/util/math.h
+++ b/intern/cycles/util/math.h
@@ -540,6 +540,7 @@ CCL_NAMESPACE_END
 #include "util/math_float2.h"
 #include "util/math_float3.h"
 #include "util/math_float4.h"
+#include "util/math_float8.h"
 
 #include "util/rect.h"
 
diff --git a/intern/cycles/util/math_float8.h b/intern/cycles/util/math_float8.h
new file mode 100644
index 00000000000..8ed8d56a034
--- /dev/null
+++ b/intern/cycles/util/math_float8.h
@@ -0,0 +1,419 @@
+/* SPDX-License-Identifier: Apache-2.0
+ * Copyright 2022 Blender Foundation */
+
+#ifndef __UTIL_MATH_FLOAT8_H__
+#define __UTIL_MATH_FLOAT8_H__
+
+#ifndef __UTIL_MATH_H__
+#  error "Do not include this file directly, include util/types.h instead."
+#endif
+
+CCL_NAMESPACE_BEGIN
+
+/*******************************************************************************
+ * Declaration.
+ */
+
+ccl_device_inline float8 operator+(const float8 &a, const float8 &b);
+ccl_device_inline float8 operator+(const float8 &a, const float f);
+ccl_device_inline float8 operator+(const float f, const float8 &a);
+
+ccl_device_inline float8 operator-(const float8 &a);
+ccl_device_inline float8 operator-(const float8 &a, const float8 &b);
+ccl_device_inline float8 operator-(const float8 &a, const float f);
+ccl_device_inline float8 operator-(const float f, const float8 &a);
+
+ccl_device_inline float8 operator*(const float8 &a, const float8 &b);
+ccl_device_inline float8 operator*(const float8 &a, const float f);
+ccl_device_inline float8 operator*(const float f, const float8 &a);
+
+ccl_device_inline float8 operator/(const float8 &a, const float8 &b);
+ccl_device_inline float8 operator/(const float8 &a, float f);
+ccl_device_inline float8 operator/(const float f, const float8 &a);
+
+ccl_device_inline float8 operator+=(float8 &a, const float8 &b);
+
+ccl_device_inline float8 operator*=(float8 &a, const float8 &b);
+ccl_device_inline float8 operator*=(float8 &a, float f);
+
+ccl_device_inline float8 operator/=(float8 &a, float f);
+
+ccl_device_inline bool operator==(const float8 &a, const float8 &b);
+
+ccl_device_inline float8 rcp(const float8 &a);
+ccl_device_inline float8 sqrt(const float8 &a);
+ccl_device_inline float8 sqr(const float8 &a);
+ccl_device_inline bool is_zero(const float8 &a);
+ccl_device_inline float average(const float8 &a);
+ccl_device_inline float8 min(const float8 &a, const float8 &b);
+ccl_device_inline float8 max(const float8 &a, const float8 &b);
+ccl_device_inline float8 clamp(const float8 &a, const float8 &mn, const float8 &mx);
+ccl_device_inline float8 fabs(const float8 &a);
+ccl_device_inline float8 mix(const float8 &a, const float8 &b, float t);
+
+ccl_device_inline float8 safe_divide(const float8 a, const float b);
+ccl_device_inline float8 safe_divide(const float8 a, const float8 b);
+
+ccl_device_inline float reduce_min(const float8 &a);
+ccl_device_inline float reduce_max(const float8 &a);
+ccl_device_inline float reduce_add(const float8 &a);
+
+ccl_device_inline float8 saturate(const float8 &a);
+ccl_device_inline bool isequal(const float8 a, const float8 b);
+
+/*******************************************************************************
+ * Definition.
+ */
+
+ccl_device_inline float8 zero_float8()
+{
+#ifdef __KERNEL_AVX2__
+  return float8(_mm256_setzero_ps());
+#else
+  return make_float8(0.0f);
+#endif
+}
+
+ccl_device_inline float8 one_float8()
+{
+  return make_float8(1.0f);
+}
+
+ccl_device_inline float8 operator+(const float8 &a, const float8 &b)
+{
+#ifdef __KERNEL_AVX2__
+  return float8(_mm256_add_ps(a.m256, b.m256));
+#else
+  return make_float8(
+      a.a + b.a, a.b + b.b, a.c + b.c, a.d + b.d, a.e + b.e, a.f + b.f, a.g + b.g, a.h + b.h);
+#endif
+}
+
+ccl_device_inline float8 operator+(const float8 &a, const float f)
+{
+  return a + make_float8(f);
+}
+
+ccl_device_inline float8 operator+(const float f, const float8 &a)
+{
+  return make_float8(f) + a;
+}
+
+ccl_device_inline float8 operator-(const float8 &a)
+{
+#ifdef __KERNEL_AVX2__
+  __m256 mask = _mm256_castsi256_ps(_mm256_set1_epi32(0x80000000));
+  return float8(_mm256_xor_ps(a.m256, mask));
+#else
+  return make_float8(-a.a, -a.b, -a.c, -a.d, -a.e, -a.f, -a.g, -a.h);
+#endif
+}
+
+ccl_device_inline float8 operator-(const float8 &a, const float8 &b)
+{
+#ifdef __KERNEL_AVX2__
+  return float8(_mm256_sub_ps(a.m256, b.m256));
+#else
+  return make_float8(
+      a.a - b.a, a.b - b.b, a.c - b.c, a.d - b.d, a.e - b.e, a.f - b.f, a.g - b.g, a.h - b.h);
+#endif
+}
+
+ccl_device_inline float8 operator-(const float8 &a, const float f)
+{
+  return a - make_float8(f);
+}
+
+ccl_device_inline float8 operator-(const float f, const float8 &a)
+{
+  return make_float8(f) - a;
+}
+
+ccl_device_inline float8 operator*(const float8 &a, const float8 &b)
+{
+#ifdef __KERNEL_AVX2__
+  return float8(_mm256_mul_ps(a.m256, b.m256));
+#else
+  return make_float8(
+      a.a * b.a, a.b * b.b, a.c * b.c, a.d * b.d, a.e * b.e, a.f * b.f, a.g * b.g, a.h * b.h);
+#endif
+}
+
+ccl_device_inline float8 operator*(const float8 &a, const float f)
+{
+  return a * make_float8(f);
+}
+
+ccl_device_inline float8 operator*(const float f, const float8 &a)
+{
+  return make_float8(f) * a;
+}
+
+ccl_device_inline float8 operator/(const float8 &a, const float8 &b)
+{
+#ifdef __KERNEL_AVX2__
+  return float8(_mm256_div_ps(a.m256, b.m256));
+#else
+  return make_float8(
+      a.a / b.a, a.b / b.b, a.c / b.c, a.d / b.d, a.e / b.e, a.f / b.f, a.g / b.g, a.h / b.h);
+#endif
+}
+
+ccl_device_inline float8 operator/(const float8 &a, const float f)
+{
+  return a / make_float8(f);
+}
+
+ccl_device_inline float8 operator/(const float f, const float8 &a)
+{
+  return make_float8(f) / a;
+}
+
+ccl_device_inline float8 operator+=(float8 &a, const float8 &b)
+{
+  return a = a + b;
+}
+
+ccl_device_inline float8 operator-=(float8 &a, const float8 &b)
+{
+  return a = a - b;
+}
+
+ccl_device_inline float8 operator*=(float8 &a, const float8 &b)
+{
+  return a = a * b;
+}
+
+ccl_device_inline float8 operator*=(float8 &a, float f)
+{
+  return a = a * f;
+}
+
+ccl_device_inline float8 operator/=(float8 &a, float f)
+{
+  return a = a / f;
+}
+
+ccl_device_inline bool operator==(const float8 &a, const float8 &b)
+{
+#ifdef __KERNEL_AVX2__
+  return (_mm256_movemask_ps(_mm256_castsi256_ps(
+              _mm256_cmpeq_epi32(_mm256_castps_si256(a.m256), _mm256_castps_si256(b.m256)))) &
+          0b11111111) == 0b11111111;
+#else
+  return (a.a == b.a && a.b == b.b && a.c == b.c && a.d == b.d && a.e == b.e && a.f == b.f &&
+          a.g == b.g && a.h == b.h);
+#endif
+}
+
+ccl_device_inline float8 rcp(const float8 &a)
+{
+#ifdef __KERNEL_AVX2__
+  return float8(_mm256_rcp_ps(a.m256));
+#else
+  return make_float8(1.0f / a.a,
+                     1.0f / a.b,
+                     1.0f / a.c,
+                     1.0f / a.d,
+                     1.0f / a.e,
+                     1.0f / a.f,
+                     1.0f / a.g,
+                     1.0f / a.h);
+#endif
+}
+
+ccl_device_inline float8 sqrt(const float8 &a)
+{
+#ifdef __KERNEL_AVX2__
+  return float8(_mm256_sqrt_ps(a.m256));
+#else
+  return make_float8(sqrtf(a.a),
+                     sqrtf(a.b),
+                     sqrtf(a.c),
+                     sqrtf(a.d),
+                     sqrtf(a.e),
+                     sqrtf(a.f),
+                     sqrtf(a.g),
+                     sqrtf(a.h));
+#endif
+}
+
+ccl_device_inline float8 sqr(const float8 &a)
+{
+  return a * a;
+}
+
+ccl_device_inline bool is_zero(const float8 &a)
+{
+  return a == make_float8(0.0f);
+}
+
+ccl_device_inline float average(const float8 &a)
+{
+  return reduce_add(a) / 8.0f;
+}
+
+ccl_device_inline float8 min(const float8 &a, const float8 &b)
+{
+#ifdef __KERNEL_AVX2__
+  return float8(_mm256_min_ps(a.m256, b.m256));
+#else
+  return make_float8(min(a.a, b.a),
+                     min(a.b, b.b),
+                     min(a.c, b.c),
+                     min(a.d, b.d),
+                     min(a.e, b.e),
+                     min(a.f, b.f),
+                     min(a.g, b.g),
+                     min(a.h, b.h));
+#endif
+}
+
+ccl_device_inline float8 max(const float8 &a, const float8 &b)
+{
+#ifdef __KERNEL_AVX2__
+  return float8(_mm256_max_ps(a.m256, b.m256));
+#else
+  return make_float8(max(a.a, b.a),
+                     max(a.b, b.b),
+                     max(a.c, b.c),
+                     max(a.d, b.d),
+                     max(a.e, b.e),
+                     max(a.f, b.f),
+                     max(a.g, b.g),
+                     max(a.h, b.h));
+#endif
+}
+
+ccl_device_inline float8 clamp(const float8 &a, const float8 &mn, const float8 &mx)
+{
+  return min(max(a, mn), mx);
+}
+
+ccl_device_inline float8 fabs(const float8 &a)
+{
+#ifdef __KERNEL_AVX2__
+  return float8(_mm256_and_ps(a.m256, _mm256_castsi256_ps(_mm256_set1_epi32(0x7fffffff))));
+#else
+  return make_float8(fabsf(a.a),
+                     fabsf(a.b),
+                     fabsf(a.c),
+                     fabsf(a.d),
+                     fabsf(a.e),
+                     fabsf(a.f),
+                     fabsf(a.g),
+                     fabsf(a.h));
+#endif
+}
+
+ccl_device_inline float8 mix(const float8 &a, const float8 &b, float t)
+{
+  return a + t * (b - a);
+}
+
+ccl_device_inline float reduce_min(const float8 &a)
+{
+  return min(min(min(a.a, a.b), min(a.c, a.d)), min(mi

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list