xref: /aosp_15_r20/external/mesa3d/src/intel/vulkan/grl/include/GRLOCLCompatibility.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 //
2 // Copyright (C) 2009-2021 Intel Corporation
3 //
4 // SPDX-License-Identifier: MIT
5 //
6 //
7 
8 #pragma once
9 
10 #ifdef __OPENCL_VERSION__
11 
12 typedef uchar  uint8_t;
13 typedef ushort uint16_t;
14 typedef uint   uint32_t;
15 typedef ulong  uint64_t;
16 typedef char   int8_t;
17 typedef short  int16_t;
18 typedef int    int32_t;
19 typedef long   int64_t;
20 
21 #else
22 
23 #include <stdint.h>
24 
25 typedef uint8_t  uchar;
26 typedef uint16_t ushort;
27 typedef uint32_t uint;
28 typedef uint64_t ulong;
29 
30 #define __constant
31 #define __global
32 
33 typedef struct uint2
34 {
35 #ifdef __cplusplus
uint2uint236     uint2() {};
uint2uint237     uint2( uint ix, uint iy ) : x( ix ), y( iy ) {};
38 #endif
39     uint x;
40     uint y;
41 } uint2;
42 
43 typedef struct uint3
44 {
45 #ifdef __cplusplus
uint3uint346     uint3() {};
uint3uint347     uint3( uint ix, uint iy, uint iz ) : x( ix ), y( iy ), z( iz ) {};
48 #endif
49     uint x;
50     uint y;
51     uint z;
52 } uint3;
53 
54 typedef struct int3
55 {
56     int32_t x;
57     int32_t y;
58     int32_t z;
59 
60 #ifdef __cplusplus
int3int361     int3() {};
int3int362     int3(int32_t ix, int32_t iy, int32_t iz) : x(ix), y(iy), z(iz) {};
63 
64     int3 operator+(const int32_t i) const { return int3(this->x + i, this->y + i, this->z + i); }
65     int3 operator<<(const int32_t i) const { return int3(this->x << i, this->y << i, this->z << i); }
66 #endif
67 } int3;
68 
69 typedef struct int4
70 {
71     int32_t x;
72     int32_t y;
73     int32_t z;
74     int32_t w;
75 
76 #ifdef __cplusplus
int4int477     int4() {};
int4int478     int4(int32_t ix, int32_t iy, int32_t iz, int32_t iw) : x(ix), y(iy), z(iz), w(iw) {};
79 
80     int4 operator+(const int32_t i) const { return int4(this->x + i, this->y + i, this->z + i, this->w + i); }
81     int4 operator-(const int32_t i) const { return int4(this->x - i, this->y - i, this->z - i, this->w - i); }
82     int4 operator<<(const int32_t i) const { return int4(this->x << i, this->y << i, this->z << i, this->w << i); }
83 #endif
84 } int4;
85 
86 typedef struct float3
87 {
88     float x;
89     float y;
90     float z;
91 
92 #ifdef __cplusplus
float3float393     float3(){};
float3float394     float3( float ix, float iy, float iz ) : x(ix), y(iy), z(iz){};
95 
96     float3 operator+( const float3& f3 ) { return float3( this->x + f3.x, this->y + f3.y, this->z + f3.z ); }
97     float3 operator*( const float& f ) { return float3( this->x * f, this->y * f, this->z * f ); }
98     float3 operator*( const float3& f3 ) const { return float3(this->x * f3.x, this->y * f3.y, this->z * f3.z); }
99     float3 operator-() { return float3(-this->x, -this->y, -this->z); }
100     float3 operator-( const float3& f3) { return float3(this->x - f3.x, this->y - f3.y, this->z - f3.z); }
101 #endif
102 } float3;
103 
104 typedef struct float4
105 {
106     float x;
107     float y;
108     float z;
109     float w;
110 
111 #ifdef __cplusplus
float4float4112     float4() {};
float4float4113     float4( float ix, float iy, float iz, float iw ) : x( ix ), y( iy ), z( iz ), w( iw ) {};
114 
115     float4 operator+(const float4& f4) const { return float4(this->x + f4.x, this->y + f4.y, this->z + f4.z, this->w + f4.w); }
116     float4 operator*(const float4& f4) const { return float4(this->x * f4.x, this->y * f4.y, this->z * f4.z, this->w * f4.w); }
117 #endif
118 } float4;
119 
120 #endif /* ! __OPENCL_VERSION__ */
121 
122 
123 #ifndef __cplusplus
124 
125 #define GRL_NAMESPACE_BEGIN(x)
126 #define GRL_NAMESPACE_END(x)
127 #define GRL_OVERLOADABLE __attribute((overloadable))
128 #define GRL_INLINE __attribute__((always_inline)) inline static
129 
130 #   define enum_uint8(name)   \
131         typedef uint8_t name; \
132         enum name##_uint32
133 #   define enum_uint16(name)   \
134         typedef uint16_t name; \
135         enum name##_uint32
136 #   define enum_uint32(name)   \
137         typedef uint32_t name; \
138         enum name##_uint32
139 
140 #define OCL_BYTE_ALIGN(n) __attribute__ ((aligned (n)))
141 #define GRL_STATIC_ASSERT(condition,desc)
142 
143 #else /* C++ */
144 #ifdef __OPENCL_VERSION__
145 #error "OpenCL C++ not supported by this header"
146 #endif
147 
148 #define GRL_NAMESPACE_BEGIN(x) namespace x {
149 #define GRL_NAMESPACE_END(x) }
150 #define GRL_OVERLOADABLE
151 #define GRL_INLINE inline
152 
153 #define enum_uint8(N) enum N : uint8_t
154 #define enum_uint16(N) enum N : uint16_t
155 #define enum_uint32(N) enum N : uint32_t
156 
157 #define OCL_BYTE_ALIGN(n)
158 #define GRL_STATIC_ASSERT(condition,desc) static_assert( condition, desc )
159 
160 #include <cmath>
161 
fmin(float3 a,float3 b)162 inline float3 fmin(float3 a, float3 b)
163 {
164     float3 o = { std::fmin(a.x, b.x), std::fmin(a.y, b.y), std::fmin(a.z, b.z) };
165     return o;
166 }
167 
fmax(float3 a,float3 b)168 inline float3 fmax(float3 a, float3 b)
169 {
170     float3 o = { std::fmax(a.x, b.x), std::fmax(a.y, b.y), std::fmax(a.z, b.z) };
171     return o;
172 }
173 
174 inline float3 operator/(const float3& f3, const float& f) { return float3(f3.x / f, f3.y / f, f3.z / f); }
175 
dot(const float3 & a,const float3 & b)176 inline float dot(const float3& a, const float3& b) {
177     return a.x * b.x + a.y * b.y + a.z * b.z;
178 }
179 
as_float(uint32_t i)180 inline float as_float(uint32_t i)
181 {
182     union { float f; uint32_t i; } fi;
183 
184     fi.i = i;
185     return fi.f;
186 }
187 
as_float3(int3 i3)188 inline float3 as_float3(int3 i3)
189 {
190     float3 o = { as_float(i3.x), as_float(i3.y), as_float(i3.z) };
191     return o;
192 }
193 
as_float4(int4 i4)194 inline float4 as_float4(int4 i4)
195 {
196     float4 o = { as_float(i4.x), as_float(i4.y), as_float(i4.z), as_float(i4.w) };
197     return o;
198 }
199 
convert_float4_rtn(int4 i4)200 inline float4 convert_float4_rtn(int4 i4)
201 {
202     return float4(static_cast<float>(i4.x), static_cast<float>(i4.y), static_cast<float>(i4.z), static_cast<float>(i4.w));
203 }
204 
convert_float4_rtp(int4 i4)205 inline float4 convert_float4_rtp(int4 i4)
206 {
207     return convert_float4_rtn(i4);
208 }
209 
210 #endif
211