Blender V5.3
types_float4.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#include "util/types_float3.h"
9#include "util/types_int4.h"
10
12
13#ifndef __KERNEL_NATIVE_VECTOR_TYPES__
14struct int4;
15
16struct ccl_try_align(16) float4 {
17# ifdef __KERNEL_SSE__
18 union {
19 __m128 m128;
20 struct {
21 float x, y, z, w;
22 };
23 };
24
25 __forceinline float4() = default;
26 __forceinline float4(const float4 &a) = default;
27 __forceinline explicit float4(const __m128 &a) : m128(a) {}
28
29 __forceinline operator const __m128 &() const
30 {
31 return m128;
32 }
33 __forceinline operator __m128 &()
34 {
35 return m128;
36 }
37
39 {
40 m128 = a.m128;
41 return *this;
42 }
43
44# else /* __KERNEL_SSE__ */
45 float x, y, z, w;
46# endif /* __KERNEL_SSE__ */
47
48# ifndef __KERNEL_GPU__
49 __forceinline float operator[](int i) const
50 {
51 util_assert(i >= 0);
52 util_assert(i < 4);
53 return *(&x + i);
54 }
55 __forceinline float &operator[](int i)
56 {
57 util_assert(i >= 0);
58 util_assert(i < 4);
59 return *(&x + i);
60 }
61# endif
62};
63
64ccl_device_inline float4 make_float4(const float x, const float y, float z, const float w)
65{
66# ifdef __KERNEL_SSE__
67 return float4(_mm_set_ps(w, z, y, x));
68# else
69 return {x, y, z, w};
70# endif
71}
72
73#endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */
74
76{
77#ifdef __KERNEL_SSE__
78 return float4(_mm_set1_ps(f));
79#else
80 return make_float4(f, f, f, f);
81#endif
82}
83
85{
86 return make_float4(a.x, a.y, a.z, b);
87}
88
90{
91 return make_float4(a.x, a.y, a.z, 1.0f);
92}
93
95{
96 return make_float4(a.x, a.y, a.z, 1.0f);
97}
98
100{
101#ifdef __KERNEL_SSE__
102 return float4(_mm_cvtepi32_ps(i.m128));
103#else
104 return make_float4((float)i.x, (float)i.y, (float)i.z, (float)i.w);
105#endif
106}
107
109{
110 return make_float3(a.x, a.y, a.z);
111}
112
114{
115#ifdef __KERNEL_SSE__
116 return int4(_mm_cvtps_epi32(f.m128));
117#else
118 return make_int4((int)f.x, (int)f.y, (int)f.z, (int)f.w);
119#endif
120}
121
122#if defined __METAL_PRINTF__
123# define print_float4(label, a) \
124 metal::os_log_default.log_debug(label ": %.8f %.8f %.8f %.8f", (a).x, (a).y, (a).z, (a).w)
125#else
126ccl_device_inline void print_float4(const ccl_private char *label, const float4 a)
127{
128# ifdef __KERNEL_PRINTF__
129 printf("%s: %.8f %.8f %.8f %.8f\n", label, (double)a.x, (double)a.y, (double)a.z, (double)a.w);
130# endif
131}
132#endif
133
134/* Packed float4.
135 *
136 * float4 type with no alignment requirements.
137 * It does not support any mathematical operations, only conversion to float4. */
138
139#if defined(__KERNEL_METAL__)
140/* Metal has native packed_float4. */
141#else
143 packed_float4() = default;
144
145 ccl_device_inline_method packed_float4(const float4 a) : x(a.x), y(a.y), z(a.z), w(a.w) {}
146
148 {
149 return make_float4(x, y, z, w);
150 }
151
153 {
154 x = a.x;
155 y = a.y;
156 z = a.z;
157 w = a.w;
158 return *this;
159 }
160
161 float x, y, z, w;
162};
163#endif
164
165static_assert(alignof(packed_float4) == alignof(float),
166 "packed_float4 expected to have the same alignment as float");
167static_assert(sizeof(packed_float4) == 16, "packed_float4 expected to be exactly 16 bytes");
168
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 printf
#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
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
ccl_device_forceinline int4 make_int4(const int x, const int y, const int z, const int w)
VecBase< float, 4 > float4
#define make_float4
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136
float y
Definition sky_math.h:225
float z
Definition sky_math.h:225
float x
Definition sky_math.h:225
float w
Definition sky_math.h:225
ccl_device_inline_method packed_float4(const float4 a)
packed_float4()=default
ccl_device_inline_method packed_float4 & operator=(const float4 &a)
ccl_device_inline dual4 make_homogeneous(const dual3 a)
Definition types_dual.h:177
ccl_device_inline void print_float4(const ccl_private char *label, const float4 a)
ccl_device_inline float4 make_float4(const float x, const float y, float z, const float w)