Blender V5.0
gpu_shader_cxx_builtin.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#pragma once
12
15
16/* Some compilers complain about lack of return values. Keep it short. */
17#define RET \
18 { \
19 return {}; \
20 }
21
22/* -------------------------------------------------------------------- */
25
27template<typename T, int D> VecBase<bool, D> lessThan(VecOp<T, D>, VecOp<T, D>) RET;
30template<typename T, int D> VecBase<bool, D> equal(VecOp<T, D>, VecOp<T, D>) RET;
31template<typename T, int D> VecBase<bool, D> notEqual(VecOp<T, D>, VecOp<T, D>) RET;
32template<int D> bool any(VecOp<bool, D>) RET;
33template<int D> bool all(VecOp<bool, D>) RET;
34/* `not` is a C++ keyword that aliases the `!` operator. Simply overload it. */
36
45int bitCount(int) RET;
53
58int findLSB(int) RET;
60int findMSB(int) RET;
62
63/* Math Functions. */
64
65/* NOTE: Declared inside a namespace and exposed behind macros to prevent
66 * errors on VS2019 due to `corecrt_math` conflicting functions. */
67namespace glsl {
68template<typename T> constexpr T abs(T) RET;
69/* TODO(fclem): These should be restricted to floats. */
70template<typename T> constexpr T ceil(T) RET;
71template<typename T> constexpr T exp(T) RET;
72template<typename T> constexpr T exp2(T) RET;
73template<typename T> constexpr T floor(T) RET;
74template<typename T> T fma(T, T, T) RET;
75float fma(float, float, float) RET;
76template<typename T> T frexp(T, T) RET;
77bool isinf(float) RET;
79bool isnan(float) RET;
81template<typename T> constexpr T log(T) RET;
82template<typename T> constexpr T log2(T) RET;
83template<typename T> T modf(T, T);
84template<typename T, typename U> constexpr T pow(T, U) RET;
85template<typename T> constexpr T round(T) RET;
86template<typename T> constexpr T sqrt(T) RET;
87template<typename T> constexpr T trunc(T) RET;
88template<typename T, typename U> T ldexp(T, U) RET;
89
90template<typename T> constexpr T acos(T) RET;
91template<typename T> T acosh(T) RET;
92template<typename T> constexpr T asin(T) RET;
93template<typename T> T asinh(T) RET;
94template<typename T> T atan(T, T) RET;
95template<typename T> T atan(T) RET;
96template<typename T> T atanh(T) RET;
97template<typename T> constexpr T cos(T) RET;
98template<typename T> T cosh(T) RET;
99template<typename T> constexpr T sin(T) RET;
100template<typename T> T sinh(T) RET;
101template<typename T> T tan(T) RET;
102template<typename T> T tanh(T) RET;
103} // namespace glsl
104
105#define abs glsl::abs
106#define ceil glsl::ceil
107#define exp glsl::exp
108#define exp2 glsl::exp2
109#define floor glsl::floor
110#define fma glsl::fma
111#define frexp glsl::frexp
112#define isinf glsl::isinf
113#define isnan glsl::isnan
114#define log glsl::log
115#define log2 glsl::log2
116#define modf glsl::modf
117#define pow glsl::pow
118#define round glsl::round
119#define sqrt glsl::sqrt
120#define trunc glsl::trunc
121#define ldexp glsl::ldexp
122#define acos glsl::acos
123#define acosh glsl::acosh
124#define asin glsl::asin
125#define asinh glsl::asinh
126#define atan glsl::atan
127#define atanh glsl::atanh
128#define cos glsl::cos
129#define cosh glsl::cosh
130#define sin glsl::sin
131#define sinh glsl::sinh
132#define tan glsl::tan
133#define tanh glsl::tanh
134
135template<typename T> constexpr T max(T, T) RET;
136template<typename T> constexpr T min(T, T) RET;
137template<typename T> constexpr T sign(T) RET;
138template<typename T, typename U> constexpr T clamp(T, U, U) RET;
139template<typename T> constexpr T clamp(T, float, float) RET;
140template<typename T, typename U> constexpr T max(T, U) RET;
141template<typename T, typename U> constexpr T min(T, U) RET;
142/* TODO(fclem): These should be restricted to floats. */
143template<typename T> T fract(T) RET;
144template<typename T> constexpr T inversesqrt(T) RET;
145constexpr float mod(float, float) RET;
146template<int D> VecBase<float, D> constexpr mod(VecOp<float, D>, float) RET;
148template<typename T> T smoothstep(T, T, T) RET;
149float step(float, float) RET;
152float smoothstep(float, float, float) RET;
153template<int D> VecBase<float, D> smoothstep(float, float, VecOp<float, D>) RET;
154
155template<typename T> constexpr T degrees(T) RET;
156template<typename T> constexpr T radians(T) RET;
157
158/* Declared explicitly to avoid type errors. */
159float mix(float, float, float) RET;
163
164#define select(A, B, C) mix(A, B, C)
165
167template<int D> float dot(VecOp<float, D>, VecOp<float, D>) RET;
169template<int D> float length(VecOp<float, D>) RET;
171
180
181/* Derivative functions. */
182template<typename T> T gpu_dfdx(T) RET;
183template<typename T> T gpu_dfdy(T) RET;
184template<typename T> T gpu_fwidth(T) RET;
185
186/* Discards the output of the current fragment shader invocation and halts its execution. */
188
189/* Geometric functions. */
191template<typename T, int D> VecBase<T, D> reflect(VecOp<T, D>, VecOp<T, D>) RET;
192template<typename T, int D> VecBase<T, D> refract(VecOp<T, D>, VecOp<T, D>, float) RET;
193
194/* Atomic operations. */
195int atomicAdd(int &, int) RET;
196int atomicAnd(int &, int) RET;
197int atomicOr(int &, int) RET;
198int atomicXor(int &, int) RET;
199int atomicMin(int &, int) RET;
200int atomicMax(int &, int) RET;
201int atomicExchange(int &, int) RET;
202int atomicCompSwap(int &, int, int) RET;
211
212/* Packing functions. */
223
224/* Matrices functions. */
225template<int C, int R> float determinant(MatBase<C, R>) RET;
226template<int C, int R> MatBase<C, R> inverse(MatBase<C, R>) RET;
227template<int C, int R> MatBase<R, C> transpose(MatBase<C, R>) RET;
228
230void barrier() {}
236} // namespace gl_ComputeShader
237
239
240#undef RET
unsigned int uint
#define U
btScalar determinant() const
Return the determinant of the matrix.
SIMD_FORCE_INLINE btScalar length() const
Return the length of the vector.
Definition btVector3.h:257
VecBase< int, D > findMSB(VecOp< int, D >) RET
#define atan
int atomicMin(int &, int) RET
VecBase< bool, D > notEqual(VecOp< T, D >, VecOp< T, D >) RET
float4 unpackSnorm4x8(uint) RET
VecBase< float, D > mix(VecOp< float, D >, VecOp< float, D >, VecOp< float, D >) RET
VecBase< int, D > bitfieldExtract(VecOp< int, D >, int, int) RET
#define tan
T smoothstep(T, T, T) RET
void gpu_discard_fragment()
VecBase< bool, D > greaterThanEqual(VecOp< T, D >, VecOp< T, D >) RET
float2 unpackUnorm2x16(uint) RET
#define log
#define sin
VecBase< int, D > floatBitsToInt(VecOp< float, D >) RET
VecBase< bool, D > lessThanEqual(VecOp< T, D >, VecOp< T, D >) RET
#define exp2
#define round
T fract(T) RET
bool any(VecOp< bool, D >) RET
int atomicMax(int &, int) RET
VecBase< float, D > intBitsToFloat(VecOp< int, D >) RET
int atomicExchange(int &, int) RET
MatBase< C, R > inverse(MatBase< C, R >) RET
uint packUnorm2x16(float2) RET
VecBase< T, D > refract(VecOp< T, D >, VecOp< T, D >, float) RET
#define pow
#define exp
T gpu_dfdx(T) RET
#define acosh
int atomicCompSwap(int &, int, int) RET
VecBase< T, D > reflect(VecOp< T, D >, VecOp< T, D >) RET
#define cos
VecBase< bool, D > greaterThan(VecOp< T, D >, VecOp< T, D >) RET
VecBase< int, D > bitfieldReverse(VecOp< int, D >) RET
VecBase< float, D > normalize(VecOp< float, D >) RET
float4 unpackUnorm4x8(uint) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
uint packSnorm4x8(float4) RET
#define trunc
T gpu_fwidth(T) RET
#define log2
#define cosh
constexpr T sign(T) RET
VecBase< T, D > faceforward(VecOp< T, D >, VecOp< T, D >, VecOp< T, D >) RET
#define modf
constexpr T inversesqrt(T) RET
int atomicAnd(int &, int) RET
#define abs
VecBase< float, D > constexpr mod(VecOp< float, D >, VecOp< float, D >) RET
uint packUnorm4x8(float4) RET
#define floor
#define ceil
int atomicXor(int &, int) RET
VecBase< uint, D > floatBitsToUint(VecOp< float, D >) RET
VecBase< int, D > bitfieldInsert(VecOp< int, D >, VecOp< int, D >, int, int) RET
int atomicAdd(int &, int) RET
bool all(VecOp< bool, D >) RET
#define sinh
#define sqrt
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
MatBase< R, C > transpose(MatBase< C, R >) RET
#define atanh
#define ldexp
VecBase< int, D > bitCount(VecOp< int, D >) RET
T gpu_dfdy(T) RET
VecBase< float, D > uintBitsToFloat(VecOp< uint, D >) RET
#define asin
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
VecBase< bool, D > lessThan(VecOp< T, D >, VecOp< T, D >) RET
#define RET
float2 unpackHalf2x16(uint) RET
constexpr T radians(T) RET
#define frexp
uint packHalf2x16(float2) RET
VecBase< bool, D > equal(VecOp< T, D >, VecOp< T, D >) RET
float2 unpackSnorm2x16(uint) RET
#define tanh
constexpr T clamp(T, U, U) RET
#define acos
VecBase< int, D > findLSB(VecOp< int, D >) RET
uint packSnorm2x16(float2) RET
#define fma
float distance(VecOp< float, D >, VecOp< float, D >) RET
int atomicOr(int &, int) RET
constexpr T degrees(T) RET
VecBase< bool, D > operator!(VecOp< bool, D >) RET
#define asinh
#define T
VecBase< bool, D > isinf(VecOp< float, D >) RET
VecBase< bool, D > isnan(VecOp< float, D >) RET
#define min(a, b)
Definition sort.cc:36
max
Definition text_draw.cc:251