Blender V4.5
types_int3.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#include "util/types_base.h"
8
10
11#ifndef __KERNEL_NATIVE_VECTOR_TYPES__
12struct ccl_try_align(16) int3
13{
14# ifdef __KERNEL_GPU__
15 /* Compact structure on the GPU. */
16 int x, y, z;
17# else
18 /* SIMD aligned structure for CPU. */
19# ifdef __KERNEL_SSE__
20 union {
21 __m128i m128;
22 struct {
23 int x, y, z, w;
24 };
25 };
26
27 __forceinline int3() = default;
28 __forceinline int3(const int3 &a) = default;
29 __forceinline explicit int3(const __m128i &a) : m128(a) {}
30
31 __forceinline operator const __m128i &() const
32 {
33 return m128;
34 }
35
36 __forceinline operator __m128i &()
37 {
38 return m128;
39 }
40
42 {
43 m128 = a.m128;
44 return *this;
45 }
46# else /* __KERNEL_SSE__ */
47 int x, y, z, w;
48# endif /* __KERNEL_SSE__ */
49# endif
50
51# ifndef __KERNEL_GPU__
52 __forceinline int operator[](int i) const
53 {
54 util_assert(i >= 0);
55 util_assert(i < 3);
56 return *(&x + i);
57 }
58
59 __forceinline int &operator[](int i)
60 {
61 util_assert(i >= 0);
62 util_assert(i < 3);
63 return *(&x + i);
64 }
65# endif
66};
67
68ccl_device_inline int3 make_int3(const int x, const int y, int z)
69{
70# if defined(__KERNEL_GPU__)
71 return {x, y, z};
72# elif defined(__KERNEL_SSE__)
73 return int3(_mm_set_epi32(0, z, y, x));
74# else
75 return {x, y, z, 0};
76# endif
77}
78
79#endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */
80
82{
83#if defined(__KERNEL_GPU__)
84 return make_int3(i, i, i);
85#elif defined(__KERNEL_SSE__)
86 return int3(_mm_set1_epi32(i));
87#else
88 return {i, i, i, i};
89#endif
90}
91
92ccl_device_inline void print_int3(const ccl_private char *label, const int3 a)
93{
94#ifdef __KERNEL_PRINTF__
95 printf("%s: %d %d %d\n", label, a.x, a.y, a.z);
96#endif
97}
98
99#if defined(__KERNEL_METAL__)
100/* Metal has native packed_int3. */
101#elif defined(__KERNEL_CUDA__) || defined(__KERNEL_ONEAPI__)
102/* CUDA and oneAPI int3 are already packed. */
103typedef int3 packed_int3;
104#else
105/* HIP int3 is not packed (https://github.com/ROCm-Developer-Tools/HIP/issues/706). */
107 int x, y, z;
108
110
111 ccl_device_inline_method packed_int3(const int px, const int py, const int pz)
112 : x(px), y(py), z(pz){};
113
114 ccl_device_inline_method packed_int3(const int3 &a) : x(a.x), y(a.y), z(a.z) {}
115
117 {
118 return make_int3(x, y, z);
119 }
120
122 {
123 x = a.x;
124 y = a.y;
125 z = a.z;
126 return *this;
127 }
128
129# ifndef __KERNEL_GPU__
131 {
132 util_assert(i < 3);
133 return *(&x + i);
134 }
135
137 {
138 util_assert(i < 3);
139 return *(&x + i);
140 }
141# endif
142};
143
144static_assert(sizeof(packed_int3) == 12, "packed_int3 expected to be exactly 12 bytes");
145#endif
146
148{
149 packed_int3 a = {x, y, z};
150 return a;
151}
152
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
#define util_assert(statement)
#define ccl_private
#define ccl_device_inline
#define ccl_try_align(...)
#define ccl_device_inline_method
#define __forceinline
#define CCL_NAMESPACE_END
VecBase< int, 3 > int3
#define printf(...)
ccl_device_inline_method packed_int3 & operator=(const int3 &a)
Definition types_int3.h:121
ccl_device_inline_method packed_int3(const int3 &a)
Definition types_int3.h:114
ccl_device_inline_method packed_int3(const int px, const int py, const int pz)
Definition types_int3.h:111
__forceinline int & operator[](int i)
Definition types_int3.h:136
__forceinline int operator[](int i) const
Definition types_int3.h:130
ccl_device_inline_method packed_int3()=default
i
Definition text_draw.cc:230
ccl_device_inline int3 make_int3(const int x, const int y, int z)
Definition types_int3.h:68
ccl_device_inline void print_int3(const ccl_private char *label, const int3 a)
Definition types_int3.h:92
ccl_device_inline packed_int3 make_packed_int3(const int x, const int y, int z)
Definition types_int3.h:147