Blender V4.3
types_float3.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#pragma once
6
7#ifndef __UTIL_TYPES_H__
8# error "Do not include this file directly, include util/types.h instead."
9#endif
10
12
13#ifndef __KERNEL_NATIVE_VECTOR_TYPES__
14# ifdef __KERNEL_ONEAPI__
15/* Define float3 as packed for oneAPI. */
16struct float3
17# else
18struct ccl_try_align(16) float3
19# endif
20{
21# ifdef __KERNEL_GPU__
22 /* Compact structure for GPU. */
23 float x, y, z;
24# else
25 /* SIMD aligned structure for CPU. */
26# ifdef __KERNEL_SSE__
27 union {
28 __m128 m128;
29 struct {
30 float x, y, z, w;
31 };
32 };
33# else
34 float x, y, z, w;
35# endif
36# endif
37
38# ifdef __KERNEL_SSE__
39 /* Convenient constructors and operators for SIMD, otherwise default is enough. */
41 __forceinline float3(const float3 &a);
42 __forceinline explicit float3(const __m128 &a);
43
44 __forceinline operator const __m128 &() const;
45 __forceinline operator __m128 &();
46
48# endif
49
50# ifndef __KERNEL_GPU__
51 __forceinline float operator[](int i) const;
52 __forceinline float &operator[](int i);
53# endif
54};
55
56ccl_device_inline float3 make_float3(float x, float y, float z);
57#endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */
58
60ccl_device_inline void print_float3(ccl_private const char *label, const float3 a);
61
62/* Smaller float3 for storage. For math operations this must be converted to float3, so that on the
63 * CPU SIMD instructions can be used. */
64#if defined(__KERNEL_METAL__)
65/* Metal has native packed_float3. */
66#elif defined(__KERNEL_CUDA__) || defined(__KERNEL_HIP__) || defined(__KERNEL_ONEAPI__)
67/* CUDA, HIP and oneAPI float3 are already packed. */
68typedef float3 packed_float3;
69#else
72
73 ccl_device_inline_method packed_float3(const float3 &a) : x(a.x), y(a.y), z(a.z) {}
74
76 {
77 return make_float3(x, y, z);
78 }
79
81 {
82 x = a.x;
83 y = a.y;
84 z = a.z;
85 return *this;
86 }
87
88 float x, y, z;
89};
90#endif
91
92static_assert(sizeof(packed_float3) == 12, "packed_float3 expected to be exactly 12 bytes");
93
blender::float3 packed_float3
btGeneric6DofConstraint & operator=(btGeneric6DofConstraint &other)
SIMD_FORCE_INLINE btVector3 & operator[](int i)
Get a mutable reference to a row of the matrix as a vector.
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
const char * label
#define ccl_private
#define ccl_device_inline
#define CCL_NAMESPACE_END
#define ccl_device_inline_method
#define ccl_try_align(...)
#define __forceinline
float z
Definition sky_float3.h:27
float3()=default
float y
Definition sky_float3.h:27
float x
Definition sky_float3.h:27
ccl_device_inline_method packed_float3(const float3 &a)
ccl_device_inline_method packed_float3 & operator=(const float3 &a)
ccl_device_inline_method packed_float3()
ccl_device_inline void print_float3(ccl_private const char *label, const float3 a)
ccl_device_inline float3 make_float3(float x, float y, float z)