From 36a3ff07ce9e0730e9394240a10251cd5ec8f531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Sun, 22 Sep 2024 20:19:21 +0200 Subject: [PATCH 01/38] Experiment with C++ stubs --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh new file mode 100644 index 00000000000..7d00073759e --- /dev/null +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -0,0 +1,151 @@ +/* SPDX-FileCopyrightText: 2024 Blender Authors + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +#include + +#define BLI_ENABLE_IF(condition) typename std::enable_if_t<(condition)> * = nullptr +#define BLI_ENABLE_IF_VEC(_size, _test) int S = _size, BLI_ENABLE_IF((S _test)) + +template= 3, bool at_least_vec4 = Size >= 4> +struct swizzle { + T x; + T y; + std::enable_if_t z; + std::enable_if_t w; +}; + +template= 3, bool at_least_vec4 = Size >= 4> +struct VecBase : swizzle { + + using swizzleT_vec2 = swizzle; + using swizzleT_vec3 = swizzle; + using swizzleT_vec4 = swizzle; + + using swizzle2_vec3 = std::enable_if_t; + using swizzle3_vec3 = std::enable_if_t; + using swizzle4_vec3 = std::enable_if_t; + + using swizzle2_vec4 = std::enable_if_t; + using swizzle3_vec4 = std::enable_if_t; + using swizzle4_vec4 = std::enable_if_t; + + union { + swizzleT_vec2 xx, xy, yx, yy; + swizzleT_vec3 xxx, xxy, xyx, xyy, yxx, yxy, yyx, yyy; + swizzleT_vec4 xxxx, xxxy, xxyx, xxyy, xyxx, xyxy, xyyx, xyyy, yxxx, yxxy, yxyx, yxyy, yyxx, + yyxy, yyyx, yyyy; + + swizzle2_vec3 xz, yz, zx, zy, zz, zw; + swizzle3_vec3 xxz, xyz, xzx, xzy, xzz, yxz, yyz, yzx, yzy, yzz, zxx, zxy, zxz, zyx, zyy, zyz, + zzx, zzy, zzz; + swizzle4_vec3 xxxz, xxyz, xxzx, xxzy, xxzz, xyxz, xyyz, xyzx, xyzy, xyzz, xzxx, xzxy, xzxz, + xzyx, xzyy, xzyz, xzzx, xzzy, xzzz, yxxz, yxyz, yxzx, yxzy, yxzz, yyxz, yyyz, yyzx, yyzy, + yyzz, yzxx, yzxy, yzxz, yzyx, yzyy, yzyz, yzzx, yzzy, yzzz, zxxx, zxxy, zxxz, zxyx, zxyy, + zxyz, zxzx, zxzy, zxzz, zyxx, zyxy, zyxz, zyyx, zyyy, zyyz, zyzx, zyzy, zyzz, zzxx, zzxy, + zzxz, zzyx, zzyy, zzyz, zzzx, zzzy, zzzz; + + swizzle2_vec4 xw, yw, wx, wy, wz, ww; + swizzle3_vec4 xxw, xyw, xzw, xwx, xwy, xwz, xww, yxw, yyw, yzw, ywx, ywy, ywz, yww, zxw, zyw, + zzw, zwx, zwy, zwz, zww, wxx, wxy, wxz, wxw, wyx, wyy, wyz, wyw, wzx, wzy, wzz, wzw, wwx, + wwy, wwz, www; + swizzle4_vec4 xxxw, xxyw, xxzw, xxwx, xxwy, xxwz, xxww, xyxw, xyyw, xyzw, xywx, xywy, xywz, + xyww, xzxw, xzyw, xzzw, xzwx, xzwy, xzwz, xzww, xwxx, xwxy, xwxz, xwxw, xwyx, xwyy, xwyz, + xwyw, xwzx, xwzy, xwzz, xwzw, xwwx, xwwy, xwwz, xwww, yxxw, yxyw, yxzw, yxwx, yxwy, yxwz, + yxww, yyxw, yyyw, yyzw, yywx, yywy, yywz, yyww, yzxw, yzyw, yzzw, yzwx, yzwy, yzwz, yzww, + ywxx, ywxy, ywxz, ywxw, ywyx, ywyy, ywyz, ywyw, ywzx, ywzy, ywzz, ywzw, ywwx, ywwy, ywwz, + ywww, zxxw, zxyw, zxzw, zxwx, zxwy, zxwz, zxww, zyxw, zyyw, zyzw, zywx, zywy, zywz, zyww, + zzxw, zzyw, zzzw, zzwx, zzwy, zzwz, zzww, zwxx, zwxy, zwxz, zwxw, zwyx, zwyy, zwyz, zwyw, + zwzx, zwzy, zwzz, zwzw, zwwx, zwwy, zwwz, zwww, wxxx, wxxy, wxxz, wxxw, wxyx, wxyy, wxyz, + wxyw, wxzx, wxzy, wxzz, wxzw, wxwx, wxwy, wxwz, wxww, wyxx, wyxy, wyxz, wyxw, wyyx, wyyy, + wyyz, wyyw, wyzx, wyzy, wyzz, wyzw, wywx, wywy, wywz, wyww, wzxx, wzxy, wzxz, wzxw, wzyx, + wzyy, wzyz, wzyw, wzzx, wzzy, wzzz, wzzw, wzwx, wzwy, wzwz, wzww, wwxx, wwxy, wwxz, wwxw, + wwyx, wwyy, wwyz, wwyw, wwzx, wwzy, wwzz, wwzw, wwwx, wwwy, wwwz, wwww; + }; + + VecBase() {} + VecBase(const VecBase &) {} + + VecBase(T) {} + VecBase(const swizzle &) {} + + template VecBase(T, T) {} + template VecBase(T, T, T) {} + template VecBase(T, T, T, T) {} + + template VecBase(swizzle, T) {} + template VecBase(T, swizzle) {} + + template VecBase(swizzle, T, T) {} + template VecBase(T, swizzle, T) {} + template VecBase(T, T, swizzle) {} + template VecBase(swizzle, swizzle) {} + template VecBase(swizzle, T) {} + template VecBase(T, swizzle) {} + + T operator[](int) {} +}; + +template VecBase operator+(swizzle a, swizzle b) {} +template VecBase operator-(swizzle a, swizzle b) {} +template VecBase operator/(swizzle a, swizzle b) {} +template VecBase operator*(swizzle a, swizzle b) {} + +template VecBase operator+(swizzle a, T b) {} +template VecBase operator-(swizzle a, T b) {} +template VecBase operator/(swizzle a, T b) {} +template VecBase operator*(swizzle a, T b) {} + +template VecBase operator+(T a, swizzle b) {} +template VecBase operator-(T a, swizzle b) {} +template VecBase operator/(T a, swizzle b) {} +template VecBase operator*(T a, swizzle b) {} + +/* Needed to support double literals. */ +template VecBase operator+(swizzle a, double b) {} +template VecBase operator-(swizzle a, double b) {} +template VecBase operator/(swizzle a, double b) {} +template VecBase operator*(swizzle a, double b) {} + +template VecBase operator+(double a, swizzle b) {} +template VecBase operator-(double a, swizzle b) {} +template VecBase operator/(double a, swizzle b) {} +template VecBase operator*(double a, swizzle b) {} + +#define BLI_INT_OP template))> +BLI_INT_OP VecBase operator%(swizzle a, swizzle b) {} +BLI_INT_OP VecBase operator&(swizzle a, swizzle b) {} +BLI_INT_OP VecBase operator|(swizzle a, swizzle b) {} +BLI_INT_OP VecBase operator^(swizzle a, swizzle b) {} + +BLI_INT_OP VecBase operator%(swizzle a, T b) {} +BLI_INT_OP VecBase operator&(swizzle a, T b) {} +BLI_INT_OP VecBase operator|(swizzle a, T b) {} +BLI_INT_OP VecBase operator^(swizzle a, T b) {} + +BLI_INT_OP VecBase operator%(T a, swizzle b) {} +BLI_INT_OP VecBase operator&(T a, swizzle b) {} +BLI_INT_OP VecBase operator|(T a, swizzle b) {} +BLI_INT_OP VecBase operator^(T a, swizzle b) {} + +using uint = unsigned int; + +using float2 = VecBase; +using float3 = VecBase; +using float4 = VecBase; + +using uint2 = VecBase; +using uint3 = VecBase; +using uint4 = VecBase; + +using int2 = VecBase; +using int3 = VecBase; +using int4 = VecBase; + +using vec2 = float2; +using vec3 = float3; +using vec4 = float4; + +#define inout +#define in +#define out -- 2.30.2 From 3cfff3249a666acb41d33a19fe5626846ea49dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Mon, 23 Sep 2024 08:44:12 +0200 Subject: [PATCH 02/38] Cleanup template and dependency, support recursive swizzle --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 238 +++++++++--------- 1 file changed, 125 insertions(+), 113 deletions(-) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index 7d00073759e..479f275843b 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -7,132 +7,144 @@ #define BLI_ENABLE_IF(condition) typename std::enable_if_t<(condition)> * = nullptr #define BLI_ENABLE_IF_VEC(_size, _test) int S = _size, BLI_ENABLE_IF((S _test)) -template= 3, bool at_least_vec4 = Size >= 4> -struct swizzle { - T x; - T y; - std::enable_if_t z; - std::enable_if_t w; -}; - -template= 3, bool at_least_vec4 = Size >= 4> -struct VecBase : swizzle { - - using swizzleT_vec2 = swizzle; - using swizzleT_vec3 = swizzle; - using swizzleT_vec4 = swizzle; - - using swizzle2_vec3 = std::enable_if_t; - using swizzle3_vec3 = std::enable_if_t; - using swizzle4_vec3 = std::enable_if_t; - - using swizzle2_vec4 = std::enable_if_t; - using swizzle3_vec4 = std::enable_if_t; - using swizzle4_vec4 = std::enable_if_t; - - union { - swizzleT_vec2 xx, xy, yx, yy; - swizzleT_vec3 xxx, xxy, xyx, xyy, yxx, yxy, yyx, yyy; - swizzleT_vec4 xxxx, xxxy, xxyx, xxyy, xyxx, xyxy, xyyx, xyyy, yxxx, yxxy, yxyx, yxyy, yyxx, - yyxy, yyyx, yyyy; - - swizzle2_vec3 xz, yz, zx, zy, zz, zw; - swizzle3_vec3 xxz, xyz, xzx, xzy, xzz, yxz, yyz, yzx, yzy, yzz, zxx, zxy, zxz, zyx, zyy, zyz, - zzx, zzy, zzz; - swizzle4_vec3 xxxz, xxyz, xxzx, xxzy, xxzz, xyxz, xyyz, xyzx, xyzy, xyzz, xzxx, xzxy, xzxz, - xzyx, xzyy, xzyz, xzzx, xzzy, xzzz, yxxz, yxyz, yxzx, yxzy, yxzz, yyxz, yyyz, yyzx, yyzy, - yyzz, yzxx, yzxy, yzxz, yzyx, yzyy, yzyz, yzzx, yzzy, yzzz, zxxx, zxxy, zxxz, zxyx, zxyy, - zxyz, zxzx, zxzy, zxzz, zyxx, zyxy, zyxz, zyyx, zyyy, zyyz, zyzx, zyzy, zyzz, zzxx, zzxy, - zzxz, zzyx, zzyy, zzyz, zzzx, zzzy, zzzz; - - swizzle2_vec4 xw, yw, wx, wy, wz, ww; - swizzle3_vec4 xxw, xyw, xzw, xwx, xwy, xwz, xww, yxw, yyw, yzw, ywx, ywy, ywz, yww, zxw, zyw, - zzw, zwx, zwy, zwz, zww, wxx, wxy, wxz, wxw, wyx, wyy, wyz, wyw, wzx, wzy, wzz, wzw, wwx, - wwy, wwz, www; - swizzle4_vec4 xxxw, xxyw, xxzw, xxwx, xxwy, xxwz, xxww, xyxw, xyyw, xyzw, xywx, xywy, xywz, - xyww, xzxw, xzyw, xzzw, xzwx, xzwy, xzwz, xzww, xwxx, xwxy, xwxz, xwxw, xwyx, xwyy, xwyz, - xwyw, xwzx, xwzy, xwzz, xwzw, xwwx, xwwy, xwwz, xwww, yxxw, yxyw, yxzw, yxwx, yxwy, yxwz, - yxww, yyxw, yyyw, yyzw, yywx, yywy, yywz, yyww, yzxw, yzyw, yzzw, yzwx, yzwy, yzwz, yzww, - ywxx, ywxy, ywxz, ywxw, ywyx, ywyy, ywyz, ywyw, ywzx, ywzy, ywzz, ywzw, ywwx, ywwy, ywwz, - ywww, zxxw, zxyw, zxzw, zxwx, zxwy, zxwz, zxww, zyxw, zyyw, zyzw, zywx, zywy, zywz, zyww, - zzxw, zzyw, zzzw, zzwx, zzwy, zzwz, zzww, zwxx, zwxy, zwxz, zwxw, zwyx, zwyy, zwyz, zwyw, - zwzx, zwzy, zwzz, zwzw, zwwx, zwwy, zwwz, zwww, wxxx, wxxy, wxxz, wxxw, wxyx, wxyy, wxyz, - wxyw, wxzx, wxzy, wxzz, wxzw, wxwx, wxwy, wxwz, wxww, wyxx, wyxy, wyxz, wyxw, wyyx, wyyy, - wyyz, wyyw, wyzx, wyzy, wyzz, wyzw, wywx, wywy, wywz, wyww, wzxx, wzxy, wzxz, wzxw, wzyx, - wzyy, wzyz, wzyw, wzzx, wzzy, wzzz, wzzw, wzwx, wzwy, wzwz, wzww, wwxx, wwxy, wwxz, wwxw, - wwyx, wwyy, wwyz, wwyw, wwzx, wwzy, wwzz, wwzw, wwwx, wwwy, wwwz, wwww; - }; - - VecBase() {} - VecBase(const VecBase &) {} - - VecBase(T) {} - VecBase(const swizzle &) {} - - template VecBase(T, T) {} - template VecBase(T, T, T) {} - template VecBase(T, T, T, T) {} - - template VecBase(swizzle, T) {} - template VecBase(T, swizzle) {} - - template VecBase(swizzle, T, T) {} - template VecBase(T, swizzle, T) {} - template VecBase(T, T, swizzle) {} - template VecBase(swizzle, swizzle) {} - template VecBase(swizzle, T) {} - template VecBase(T, swizzle) {} - +template struct VecOp { T operator[](int) {} + + VecOp operator+() const {} + VecOp operator-() const {} + + VecOp operator+(VecOp b) const {} + VecOp operator-(VecOp b) const {} + VecOp operator/(VecOp b) const {} + VecOp operator*(VecOp b) const {} + + VecOp operator+=(VecOp b) const {} + VecOp operator-=(VecOp b) const {} + VecOp operator/=(VecOp b) const {} + VecOp operator*=(VecOp b) const {} + + VecOp operator+(T b) const {} + VecOp operator-(T b) const {} + VecOp operator/(T b) const {} + VecOp operator*(T b) const {} + + VecOp operator+=(T b) const {} + VecOp operator-=(T b) const {} + VecOp operator/=(T b) const {} + VecOp operator*=(T b) const {} + + friend VecOp operator+(T a, VecOp b) {} + friend VecOp operator-(T a, VecOp b) {} + friend VecOp operator/(T a, VecOp b) {} + friend VecOp operator*(T a, VecOp b) {} + +#define BLI_INT_OP(_T) template))> + + BLI_INT_OP(T) VecOp operator%(VecOp b) {} + BLI_INT_OP(T) VecOp operator&(VecOp b) {} + BLI_INT_OP(T) VecOp operator|(VecOp b) {} + BLI_INT_OP(T) VecOp operator^(VecOp b) {} + + BLI_INT_OP(T) VecOp operator%=(VecOp b) {} + BLI_INT_OP(T) VecOp operator&=(VecOp b) {} + BLI_INT_OP(T) VecOp operator|=(VecOp b) {} + BLI_INT_OP(T) VecOp operator^=(VecOp b) {} + + BLI_INT_OP(T) VecOp operator%(T b) {} + BLI_INT_OP(T) VecOp operator&(T b) {} + BLI_INT_OP(T) VecOp operator|(T b) {} + BLI_INT_OP(T) VecOp operator^(T b) {} + + BLI_INT_OP(T) VecOp operator%=(T b) {} + BLI_INT_OP(T) VecOp operator&=(T b) {} + BLI_INT_OP(T) VecOp operator|=(T b) {} + BLI_INT_OP(T) VecOp operator^=(T b) {} + + BLI_INT_OP(T) friend VecOp operator%(T a, VecOp b) {} + BLI_INT_OP(T) friend VecOp operator&(T a, VecOp b) {} + BLI_INT_OP(T) friend VecOp operator|(T a, VecOp b) {} + BLI_INT_OP(T) friend VecOp operator^(T a, VecOp b) {} }; -template VecBase operator+(swizzle a, swizzle b) {} -template VecBase operator-(swizzle a, swizzle b) {} -template VecBase operator/(swizzle a, swizzle b) {} -template VecBase operator*(swizzle a, swizzle b) {} +template struct VecBase {}; -template VecBase operator+(swizzle a, T b) {} -template VecBase operator-(swizzle a, T b) {} -template VecBase operator/(swizzle a, T b) {} -template VecBase operator*(swizzle a, T b) {} +template struct VecSwizzle2 { + static VecBase xx, xy, yx, yy; + static VecBase xxx, xxy, xyx, xyy, yxx, yxy, yyx, yyy; + static VecBase xxxx, xxxy, xxyx, xxyy, xyxx, xyxy, xyyx, xyyy, yxxx, yxxy, yxyx, yxyy, + yyxx, yyxy, yyyx, yyyy; +}; -template VecBase operator+(T a, swizzle b) {} -template VecBase operator-(T a, swizzle b) {} -template VecBase operator/(T a, swizzle b) {} -template VecBase operator*(T a, swizzle b) {} +template struct VecSwizzle3 : VecSwizzle2 { + static VecBase xz, yz, zx, zy, zz, zw; + static VecBase xxz, xyz, xzx, xzy, xzz, yxz, yyz, yzx, yzy, yzz, zxx, zxy, zxz, zyx, zyy, + zyz, zzx, zzy, zzz; + static VecBase xxxz, xxyz, xxzx, xxzy, xxzz, xyxz, xyyz, xyzx, xyzy, xyzz, xzxx, xzxy, + xzxz, xzyx, xzyy, xzyz, xzzx, xzzy, xzzz, yxxz, yxyz, yxzx, yxzy, yxzz, yyxz, yyyz, yyzx, + yyzy, yyzz, yzxx, yzxy, yzxz, yzyx, yzyy, yzyz, yzzx, yzzy, yzzz, zxxx, zxxy, zxxz, zxyx, + zxyy, zxyz, zxzx, zxzy, zxzz, zyxx, zyxy, zyxz, zyyx, zyyy, zyyz, zyzx, zyzy, zyzz, zzxx, + zzxy, zzxz, zzyx, zzyy, zzyz, zzzx, zzzy, zzzz; +}; -/* Needed to support double literals. */ -template VecBase operator+(swizzle a, double b) {} -template VecBase operator-(swizzle a, double b) {} -template VecBase operator/(swizzle a, double b) {} -template VecBase operator*(swizzle a, double b) {} +template struct VecSwizzle4 : VecSwizzle3 { + static VecBase xw, yw, wx, wy, wz, ww; + static VecBase xxw, xyw, xzw, xwx, xwy, xwz, xww, yxw, yyw, yzw, ywx, ywy, ywz, yww, zxw, + zyw, zzw, zwx, zwy, zwz, zww, wxx, wxy, wxz, wxw, wyx, wyy, wyz, wyw, wzx, wzy, wzz, wzw, + wwx, wwy, wwz, www; + static VecBase xxxw, xxyw, xxzw, xxwx, xxwy, xxwz, xxww, xyxw, xyyw, xyzw, xywx, xywy, + xywz, xyww, xzxw, xzyw, xzzw, xzwx, xzwy, xzwz, xzww, xwxx, xwxy, xwxz, xwxw, xwyx, xwyy, + xwyz, xwyw, xwzx, xwzy, xwzz, xwzw, xwwx, xwwy, xwwz, xwww, yxxw, yxyw, yxzw, yxwx, yxwy, + yxwz, yxww, yyxw, yyyw, yyzw, yywx, yywy, yywz, yyww, yzxw, yzyw, yzzw, yzwx, yzwy, yzwz, + yzww, ywxx, ywxy, ywxz, ywxw, ywyx, ywyy, ywyz, ywyw, ywzx, ywzy, ywzz, ywzw, ywwx, ywwy, + ywwz, ywww, zxxw, zxyw, zxzw, zxwx, zxwy, zxwz, zxww, zyxw, zyyw, zyzw, zywx, zywy, zywz, + zyww, zzxw, zzyw, zzzw, zzwx, zzwy, zzwz, zzww, zwxx, zwxy, zwxz, zwxw, zwyx, zwyy, zwyz, + zwyw, zwzx, zwzy, zwzz, zwzw, zwwx, zwwy, zwwz, zwww, wxxx, wxxy, wxxz, wxxw, wxyx, wxyy, + wxyz, wxyw, wxzx, wxzy, wxzz, wxzw, wxwx, wxwy, wxwz, wxww, wyxx, wyxy, wyxz, wyxw, wyyx, + wyyy, wyyz, wyyw, wyzx, wyzy, wyzz, wyzw, wywx, wywy, wywz, wyww, wzxx, wzxy, wzxz, wzxw, + wzyx, wzyy, wzyz, wzyw, wzzx, wzzy, wzzz, wzzw, wzwx, wzwy, wzwz, wzww, wwxx, wwxy, wwxz, + wwxw, wwyx, wwyy, wwyz, wwyw, wwzx, wwzy, wwzz, wwzw, wwwx, wwwy, wwwz, wwww; +}; -template VecBase operator+(double a, swizzle b) {} -template VecBase operator-(double a, swizzle b) {} -template VecBase operator/(double a, swizzle b) {} -template VecBase operator*(double a, swizzle b) {} +template struct VecBase : VecOp, VecSwizzle2 { + T x, y; -#define BLI_INT_OP template))> -BLI_INT_OP VecBase operator%(swizzle a, swizzle b) {} -BLI_INT_OP VecBase operator&(swizzle a, swizzle b) {} -BLI_INT_OP VecBase operator|(swizzle a, swizzle b) {} -BLI_INT_OP VecBase operator^(swizzle a, swizzle b) {} + VecBase() = default; + VecBase(VecOp) {} + explicit VecBase(T) {} + explicit VecBase(T, T) {} +}; -BLI_INT_OP VecBase operator%(swizzle a, T b) {} -BLI_INT_OP VecBase operator&(swizzle a, T b) {} -BLI_INT_OP VecBase operator|(swizzle a, T b) {} -BLI_INT_OP VecBase operator^(swizzle a, T b) {} +template struct VecBase : VecOp, VecSwizzle3 { + T x, y, z; -BLI_INT_OP VecBase operator%(T a, swizzle b) {} -BLI_INT_OP VecBase operator&(T a, swizzle b) {} -BLI_INT_OP VecBase operator|(T a, swizzle b) {} -BLI_INT_OP VecBase operator^(T a, swizzle b) {} + VecBase() = default; + VecBase(VecOp) {} + explicit VecBase(T) {} + explicit VecBase(T, T, T) {} + explicit VecBase(VecBase, T) {} + explicit VecBase(T, VecBase) {} +}; + +template struct VecBase : VecOp, VecSwizzle4 { + T x, y, z, w; + + VecBase() = default; + VecBase(VecOp) {} + explicit VecBase(T) {} + explicit VecBase(T, T, T, T) {} + explicit VecBase(VecBase, T, T) {} + explicit VecBase(T, VecBase, T) {} + explicit VecBase(T, T, VecBase) {} + explicit VecBase(VecBase, VecBase) {} + explicit VecBase(VecBase, T) {} + explicit VecBase(T, VecBase) {} +}; using uint = unsigned int; -using float2 = VecBase; -using float3 = VecBase; -using float4 = VecBase; +using float2 = VecBase; +using float3 = VecBase; +using float4 = VecBase; using uint2 = VecBase; using uint3 = VecBase; -- 2.30.2 From 554b83ee52ef280376a77115b151418644a2540f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Mon, 23 Sep 2024 08:46:40 +0200 Subject: [PATCH 03/38] Cleanup macros --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index 479f275843b..eaee47a1c85 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -4,9 +4,6 @@ #include -#define BLI_ENABLE_IF(condition) typename std::enable_if_t<(condition)> * = nullptr -#define BLI_ENABLE_IF_VEC(_size, _test) int S = _size, BLI_ENABLE_IF((S _test)) - template struct VecOp { T operator[](int) {} @@ -38,32 +35,35 @@ template struct VecOp { friend VecOp operator/(T a, VecOp b) {} friend VecOp operator*(T a, VecOp b) {} -#define BLI_INT_OP(_T) template))> +#define INT_OP \ + template> * = nullptr> - BLI_INT_OP(T) VecOp operator%(VecOp b) {} - BLI_INT_OP(T) VecOp operator&(VecOp b) {} - BLI_INT_OP(T) VecOp operator|(VecOp b) {} - BLI_INT_OP(T) VecOp operator^(VecOp b) {} + INT_OP VecOp operator%(VecOp b) {} + INT_OP VecOp operator&(VecOp b) {} + INT_OP VecOp operator|(VecOp b) {} + INT_OP VecOp operator^(VecOp b) {} - BLI_INT_OP(T) VecOp operator%=(VecOp b) {} - BLI_INT_OP(T) VecOp operator&=(VecOp b) {} - BLI_INT_OP(T) VecOp operator|=(VecOp b) {} - BLI_INT_OP(T) VecOp operator^=(VecOp b) {} + INT_OP VecOp operator%=(VecOp b) {} + INT_OP VecOp operator&=(VecOp b) {} + INT_OP VecOp operator|=(VecOp b) {} + INT_OP VecOp operator^=(VecOp b) {} - BLI_INT_OP(T) VecOp operator%(T b) {} - BLI_INT_OP(T) VecOp operator&(T b) {} - BLI_INT_OP(T) VecOp operator|(T b) {} - BLI_INT_OP(T) VecOp operator^(T b) {} + INT_OP VecOp operator%(T b) {} + INT_OP VecOp operator&(T b) {} + INT_OP VecOp operator|(T b) {} + INT_OP VecOp operator^(T b) {} - BLI_INT_OP(T) VecOp operator%=(T b) {} - BLI_INT_OP(T) VecOp operator&=(T b) {} - BLI_INT_OP(T) VecOp operator|=(T b) {} - BLI_INT_OP(T) VecOp operator^=(T b) {} + INT_OP VecOp operator%=(T b) {} + INT_OP VecOp operator&=(T b) {} + INT_OP VecOp operator|=(T b) {} + INT_OP VecOp operator^=(T b) {} - BLI_INT_OP(T) friend VecOp operator%(T a, VecOp b) {} - BLI_INT_OP(T) friend VecOp operator&(T a, VecOp b) {} - BLI_INT_OP(T) friend VecOp operator|(T a, VecOp b) {} - BLI_INT_OP(T) friend VecOp operator^(T a, VecOp b) {} + INT_OP friend VecOp operator%(T a, VecOp b) {} + INT_OP friend VecOp operator&(T a, VecOp b) {} + INT_OP friend VecOp operator|(T a, VecOp b) {} + INT_OP friend VecOp operator^(T a, VecOp b) {} + +#undef INT_OP }; template struct VecBase {}; -- 2.30.2 From e67be951bbb46529bd59a7f08b6c287182cf8b37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Mon, 23 Sep 2024 11:21:21 +0200 Subject: [PATCH 04/38] Fix typo --- source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index eaee47a1c85..104974b0b87 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -114,7 +114,7 @@ template struct VecBase : VecOp, VecSwizzle2 { explicit VecBase(T, T) {} }; -template struct VecBase : VecOp, VecSwizzle3 { +template struct VecBase : VecOp, VecSwizzle3 { T x, y, z; VecBase() = default; @@ -125,7 +125,7 @@ template struct VecBase : VecOp, VecSwizzle3 { explicit VecBase(T, VecBase) {} }; -template struct VecBase : VecOp, VecSwizzle4 { +template struct VecBase : VecOp, VecSwizzle4 { T x, y, z, w; VecBase() = default; -- 2.30.2 From f74f36b32e5e3544ba96d3d78d1dc19c9bd14dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Mon, 23 Sep 2024 11:21:53 +0200 Subject: [PATCH 05/38] Add 1 component vector with auto cast --- source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index 104974b0b87..00d226c374f 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -105,6 +105,14 @@ template struct VecSwizzle4 : VecSwizzle3 { wwxw, wwyx, wwyy, wwyz, wwyw, wwzx, wwzy, wwzz, wwzw, wwwx, wwwy, wwwz, wwww; }; +template struct VecBase { + T x; + + VecBase() = default; + VecBase(VecOp) {} + operator T() const {} +}; + template struct VecBase : VecOp, VecSwizzle2 { T x, y; -- 2.30.2 From cb7624eeef7472274b62d6e207684cf922e83d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Mon, 23 Sep 2024 11:23:24 +0200 Subject: [PATCH 06/38] Add texture stubs --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index 00d226c374f..aa5df4ecd7f 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -169,3 +169,62 @@ using vec4 = float4; #define inout #define in #define out + +template using Vec4 = VecBase; +template using VecInt = VecBase; +template using VecFlt = VecBase; + +template struct SamplerBase { + static constexpr int coord_dim = Dimensions + int(Cube) + int(Array); + static constexpr int deriv_dim = Dimensions + int(Cube); + static constexpr int extent_dim = Dimensions + int(Array); + + using int_coord_type = VecBase; + using flt_coord_type = VecBase; + using derivative_type = VecBase; + using data_vec_type = VecBase; + using size_vec_type = VecBase; +}; + +#define TEX_TEMPLATE \ + template + +TEX_TEMPLATE SizeVec textureSize(T, int) {} +TEX_TEMPLATE DataVec texelFetch(T, IntCoord, int) {} +TEX_TEMPLATE DataVec texelFetchOffset(T, IntCoord, int, IntCoord) {} +TEX_TEMPLATE DataVec texture(T, FltCoord) {} +TEX_TEMPLATE DataVec textureGather(T, FltCoord) {} +TEX_TEMPLATE DataVec textureGrad(T, FltCoord, DerivVec, DerivVec) {} +TEX_TEMPLATE DataVec textureLod(T, FltCoord, double) {} + +#undef TEX_TEMPLATE + +using sampler1D = SamplerBase; +using sampler2D = SamplerBase; +using sampler3D = SamplerBase; +using isampler1D = SamplerBase; +using isampler2D = SamplerBase; +using isampler3D = SamplerBase; +using usampler1D = SamplerBase; +using usampler2D = SamplerBase; +using usampler3D = SamplerBase; + +using sampler1DArray = SamplerBase; +using sampler2DArray = SamplerBase; +using isampler1DArray = SamplerBase; +using isampler2DArray = SamplerBase; +using usampler1DArray = SamplerBase; +using usampler2DArray = SamplerBase; + +using samplerCube = SamplerBase; +using isamplerCube = SamplerBase; +using usamplerCube = SamplerBase; + +using samplerCubeArray = SamplerBase; +using isamplerCubeArray = SamplerBase; +using usamplerCubeArray = SamplerBase; -- 2.30.2 From fcd3772baffe97e1e6e31b07a28a245d6eecc821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Mon, 23 Sep 2024 11:45:31 +0200 Subject: [PATCH 07/38] Int vectors alias --- source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index aa5df4ecd7f..3b651d8895c 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -166,6 +166,14 @@ using vec2 = float2; using vec3 = float3; using vec4 = float4; +using ivec2 = int2; +using ivec3 = int3; +using ivec4 = int4; + +using uvec2 = uint2; +using uvec3 = uint3; +using uvec4 = uint4; + #define inout #define in #define out -- 2.30.2 From 01c1a2e60f04169877e63706f467d5d0eb649eb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Mon, 23 Sep 2024 11:45:40 +0200 Subject: [PATCH 08/38] image stubs --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index 3b651d8895c..e4ad5b24e65 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -236,3 +236,53 @@ using usamplerCube = SamplerBase; using samplerCubeArray = SamplerBase; using isamplerCubeArray = SamplerBase; using usamplerCubeArray = SamplerBase; + +template struct ImageBase { + static constexpr int coord_dim = Dimensions + int(Cube) + int(Array); + static constexpr int deriv_dim = Dimensions + int(Cube); + static constexpr int extent_dim = Dimensions + int(Array); + + using int_coord_type = VecBase; + using data_vec_type = VecBase; + using size_vec_type = VecBase; +}; + +#define IMG_TEMPLATE \ + template + +IMG_TEMPLATE SizeVec imageSize(T) {} +IMG_TEMPLATE DataVec imageLoad(T, IntCoord) {} +IMG_TEMPLATE void imageStore(T, IntCoord, DataVec) {} +IMG_TEMPLATE void imageFence(T) {} +#define imageLoadFast imageLoad +#define imageStoreFast imageStore + +#undef IMG_TEMPLATE + +using sampler1D = SamplerBase; +using sampler2D = SamplerBase; +using sampler3D = SamplerBase; +using isampler1D = SamplerBase; +using isampler2D = SamplerBase; +using isampler3D = SamplerBase; +using usampler1D = SamplerBase; +using usampler2D = SamplerBase; +using usampler3D = SamplerBase; + +using sampler1DArray = SamplerBase; +using sampler2DArray = SamplerBase; +using isampler1DArray = SamplerBase; +using isampler2DArray = SamplerBase; +using usampler1DArray = SamplerBase; +using usampler2DArray = SamplerBase; + +using samplerCube = SamplerBase; +using isamplerCube = SamplerBase; +using usamplerCube = SamplerBase; + +using samplerCubeArray = SamplerBase; +using isamplerCubeArray = SamplerBase; +using usamplerCubeArray = SamplerBase; -- 2.30.2 From 4568437b044aa4db743473d8ee614dbf9847a9b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Mon, 23 Sep 2024 12:25:22 +0200 Subject: [PATCH 09/38] Add vector explicit casts --- source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index e4ad5b24e65..1f099781a45 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -110,6 +110,7 @@ template struct VecBase { VecBase() = default; VecBase(VecOp) {} + template explicit VecBase(VecBase) {} operator T() const {} }; @@ -118,6 +119,7 @@ template struct VecBase : VecOp, VecSwizzle2 { VecBase() = default; VecBase(VecOp) {} + template explicit VecBase(VecBase) {} explicit VecBase(T) {} explicit VecBase(T, T) {} }; @@ -127,6 +129,7 @@ template struct VecBase : VecOp, VecSwizzle3 { VecBase() = default; VecBase(VecOp) {} + template explicit VecBase(VecBase) {} explicit VecBase(T) {} explicit VecBase(T, T, T) {} explicit VecBase(VecBase, T) {} @@ -138,6 +141,7 @@ template struct VecBase : VecOp, VecSwizzle4 { VecBase() = default; VecBase(VecOp) {} + template explicit VecBase(VecBase) {} explicit VecBase(T) {} explicit VecBase(T, T, T, T) {} explicit VecBase(VecBase, T, T) {} -- 2.30.2 From 0738573cfc70024eb9d257d58758aeb7d2ad5b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Mon, 23 Sep 2024 12:59:11 +0200 Subject: [PATCH 10/38] Boolean vectors --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index 1f099781a45..b3973006aba 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -152,6 +152,47 @@ template struct VecBase : VecOp, VecSwizzle4 { explicit VecBase(T, VecBase) {} }; +/* Boolean vectors do not have operators and are not convertible from other types. */ + +template<> struct VecBase { + bool x; + + VecBase() = default; + operator bool() const {} +}; + +template<> struct VecBase : VecSwizzle2 { + bool x, y; + + VecBase() = default; + explicit VecBase(bool) {} + explicit VecBase(bool, bool) {} +}; + +template<> struct VecBase : VecSwizzle3 { + bool x, y, z; + + VecBase() = default; + explicit VecBase(bool) {} + explicit VecBase(bool, bool, bool) {} + explicit VecBase(VecBase, bool) {} + explicit VecBase(bool, VecBase) {} +}; + +template<> struct VecBase : VecSwizzle4 { + bool x, y, z, w; + + VecBase() = default; + explicit VecBase(bool) {} + explicit VecBase(bool, bool, bool, bool) {} + explicit VecBase(VecBase, bool, bool) {} + explicit VecBase(bool, VecBase, bool) {} + explicit VecBase(bool, bool, VecBase) {} + explicit VecBase(VecBase, VecBase) {} + explicit VecBase(VecBase, bool) {} + explicit VecBase(bool, VecBase) {} +}; + using uint = unsigned int; using float2 = VecBase; @@ -166,6 +207,10 @@ using int2 = VecBase; using int3 = VecBase; using int4 = VecBase; +using bool2 = VecBase; +using bool3 = VecBase; +using bool4 = VecBase; + using vec2 = float2; using vec3 = float3; using vec4 = float4; @@ -178,6 +223,22 @@ using uvec2 = uint2; using uvec3 = uint3; using uvec4 = uint4; +using bvec2 = bool2; +using bvec3 = bool3; +using bvec4 = bool4; + +template VecBase greaterThan(VecBase, VecBase) {} +template VecBase lessThan(VecBase, VecBase) {} +template VecBase lessThanEqual(VecBase, VecBase) {} +template VecBase greaterThanEqual(VecBase, VecBase) {} +template VecBase equal(VecBase, VecBase) {} +template VecBase notEqual(VecBase, VecBase) {} +template bool any(VecBase) {} +template bool all(VecBase) {} +/* `not` is a C++ keyword. Use dirty macro to allow this. */ +template VecBase not_impl(VecBase) {} +#define not not_impl + #define inout #define in #define out -- 2.30.2 From f3759f717c496fee3ac1bd9383aa7b1ed8181f84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Mon, 23 Sep 2024 16:48:15 +0200 Subject: [PATCH 11/38] Simplify vector ops and remove vec1 --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 109 ++++++++---------- 1 file changed, 46 insertions(+), 63 deletions(-) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index b3973006aba..b5d8f7896e2 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -4,70 +4,72 @@ #include +template struct VecBase {}; + template struct VecOp { + using VecT = VecBase; + T operator[](int) {} - VecOp operator+() const {} - VecOp operator-() const {} + VecT operator+() const {} + VecT operator-() const {} - VecOp operator+(VecOp b) const {} - VecOp operator-(VecOp b) const {} - VecOp operator/(VecOp b) const {} - VecOp operator*(VecOp b) const {} + VecT operator+(VecT b) const {} + VecT operator-(VecT b) const {} + VecT operator/(VecT b) const {} + VecT operator*(VecT b) const {} - VecOp operator+=(VecOp b) const {} - VecOp operator-=(VecOp b) const {} - VecOp operator/=(VecOp b) const {} - VecOp operator*=(VecOp b) const {} + VecT operator+=(VecT b) const {} + VecT operator-=(VecT b) const {} + VecT operator/=(VecT b) const {} + VecT operator*=(VecT b) const {} - VecOp operator+(T b) const {} - VecOp operator-(T b) const {} - VecOp operator/(T b) const {} - VecOp operator*(T b) const {} + VecT operator+(T b) const {} + VecT operator-(T b) const {} + VecT operator/(T b) const {} + VecT operator*(T b) const {} - VecOp operator+=(T b) const {} - VecOp operator-=(T b) const {} - VecOp operator/=(T b) const {} - VecOp operator*=(T b) const {} + VecT operator+=(T b) const {} + VecT operator-=(T b) const {} + VecT operator/=(T b) const {} + VecT operator*=(T b) const {} - friend VecOp operator+(T a, VecOp b) {} - friend VecOp operator-(T a, VecOp b) {} - friend VecOp operator/(T a, VecOp b) {} - friend VecOp operator*(T a, VecOp b) {} + friend VecT operator+(T a, VecT b) {} + friend VecT operator-(T a, VecT b) {} + friend VecT operator/(T a, VecT b) {} + friend VecT operator*(T a, VecT b) {} #define INT_OP \ template> * = nullptr> - INT_OP VecOp operator%(VecOp b) {} - INT_OP VecOp operator&(VecOp b) {} - INT_OP VecOp operator|(VecOp b) {} - INT_OP VecOp operator^(VecOp b) {} + INT_OP VecT operator%(VecT b) {} + INT_OP VecT operator&(VecT b) {} + INT_OP VecT operator|(VecT b) {} + INT_OP VecT operator^(VecT b) {} - INT_OP VecOp operator%=(VecOp b) {} - INT_OP VecOp operator&=(VecOp b) {} - INT_OP VecOp operator|=(VecOp b) {} - INT_OP VecOp operator^=(VecOp b) {} + INT_OP VecT operator%=(VecT b) {} + INT_OP VecT operator&=(VecT b) {} + INT_OP VecT operator|=(VecT b) {} + INT_OP VecT operator^=(VecT b) {} - INT_OP VecOp operator%(T b) {} - INT_OP VecOp operator&(T b) {} - INT_OP VecOp operator|(T b) {} - INT_OP VecOp operator^(T b) {} + INT_OP VecT operator%(T b) {} + INT_OP VecT operator&(T b) {} + INT_OP VecT operator|(T b) {} + INT_OP VecT operator^(T b) {} - INT_OP VecOp operator%=(T b) {} - INT_OP VecOp operator&=(T b) {} - INT_OP VecOp operator|=(T b) {} - INT_OP VecOp operator^=(T b) {} + INT_OP VecT operator%=(T b) {} + INT_OP VecT operator&=(T b) {} + INT_OP VecT operator|=(T b) {} + INT_OP VecT operator^=(T b) {} - INT_OP friend VecOp operator%(T a, VecOp b) {} - INT_OP friend VecOp operator&(T a, VecOp b) {} - INT_OP friend VecOp operator|(T a, VecOp b) {} - INT_OP friend VecOp operator^(T a, VecOp b) {} + INT_OP friend VecT operator%(T a, VecT b) {} + INT_OP friend VecT operator&(T a, VecT b) {} + INT_OP friend VecT operator|(T a, VecT b) {} + INT_OP friend VecT operator^(T a, VecT b) {} #undef INT_OP }; -template struct VecBase {}; - template struct VecSwizzle2 { static VecBase xx, xy, yx, yy; static VecBase xxx, xxy, xyx, xyy, yxx, yxy, yyx, yyy; @@ -105,20 +107,10 @@ template struct VecSwizzle4 : VecSwizzle3 { wwxw, wwyx, wwyy, wwyz, wwyw, wwzx, wwzy, wwzz, wwzw, wwwx, wwwy, wwwz, wwww; }; -template struct VecBase { - T x; - - VecBase() = default; - VecBase(VecOp) {} - template explicit VecBase(VecBase) {} - operator T() const {} -}; - template struct VecBase : VecOp, VecSwizzle2 { T x, y; VecBase() = default; - VecBase(VecOp) {} template explicit VecBase(VecBase) {} explicit VecBase(T) {} explicit VecBase(T, T) {} @@ -128,7 +120,6 @@ template struct VecBase : VecOp, VecSwizzle3 { T x, y, z; VecBase() = default; - VecBase(VecOp) {} template explicit VecBase(VecBase) {} explicit VecBase(T) {} explicit VecBase(T, T, T) {} @@ -140,7 +131,6 @@ template struct VecBase : VecOp, VecSwizzle4 { T x, y, z, w; VecBase() = default; - VecBase(VecOp) {} template explicit VecBase(VecBase) {} explicit VecBase(T) {} explicit VecBase(T, T, T, T) {} @@ -154,13 +144,6 @@ template struct VecBase : VecOp, VecSwizzle4 { /* Boolean vectors do not have operators and are not convertible from other types. */ -template<> struct VecBase { - bool x; - - VecBase() = default; - operator bool() const {} -}; - template<> struct VecBase : VecSwizzle2 { bool x, y; -- 2.30.2 From 552be099cbbf616a3f905f8adc78f0aa73ef40ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Mon, 23 Sep 2024 16:48:48 +0200 Subject: [PATCH 12/38] Add optional bias to texture function --- source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index b5d8f7896e2..2ae42b481c3 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -253,7 +253,7 @@ template stru TEX_TEMPLATE SizeVec textureSize(T, int) {} TEX_TEMPLATE DataVec texelFetch(T, IntCoord, int) {} TEX_TEMPLATE DataVec texelFetchOffset(T, IntCoord, int, IntCoord) {} -TEX_TEMPLATE DataVec texture(T, FltCoord) {} +TEX_TEMPLATE DataVec texture(T, FltCoord, double bias = 0.0) {} TEX_TEMPLATE DataVec textureGather(T, FltCoord) {} TEX_TEMPLATE DataVec textureGrad(T, FltCoord, DerivVec, DerivVec) {} TEX_TEMPLATE DataVec textureLod(T, FltCoord, double) {} -- 2.30.2 From d917537e2c19466bfce9346899f3cd787ab68ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Mon, 23 Sep 2024 16:49:04 +0200 Subject: [PATCH 13/38] Builtin functions --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index 2ae42b481c3..d9d6908cdcc 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -334,3 +334,124 @@ using usamplerCube = SamplerBase; using samplerCubeArray = SamplerBase; using isamplerCubeArray = SamplerBase; using usamplerCubeArray = SamplerBase; + +template VecBase bitCount(VecBase) {} +template VecBase bitCount(VecBase) {} +template VecBase bitfieldExtract(VecBase, int, int) {} +template VecBase bitfieldExtract(VecBase, int, int) {} +template VecBase bitfieldInsert(VecBase, VecBase, int, int) {} +template VecBase bitfieldInsert(VecBase, VecBase, int, int) {} +template VecBase bitfieldReverse(VecBase) {} +template VecBase bitfieldReverse(VecBase) {} +int bitCount(int) {} +int bitCount(uint) {} +int bitfieldExtract(int) {} +int bitfieldExtract(uint) {} +int bitfieldInsert(int) {} +int bitfieldInsert(uint) {} +int bitfieldReverse(int) {} +int bitfieldReverse(uint) {} + +template VecBase findLSB(VecBase) {} +template VecBase findLSB(VecBase) {} +template VecBase findMSB(VecBase) {} +template VecBase findMSB(VecBase) {} +int findMSB(int) {} +int findMSB(uint) {} + +/* Math Functions. */ +template T abs(T) {} +template T clamp(T, T, T) {} +template T max(T, T) {} +template T min(T, T) {} +template T sign(T, T) {} +template T clamp(T, U, U) {} +template T max(T, U) {} +template T min(T, U) {} +/* TODO(fclem): These should be restricted to floats. */ +template T ceil(T) {} +template T exp(T) {} +template T exp2(T) {} +template T floor(T) {} +template T fma(T, T, T) {} +template T fract(T) {} +template T frexp(T, T) {} +template T inversesqrt(T) {} +template T isinf(T) {} +template T isnan(T) {} +template T log(T) {} +template T log2(T) {} +template T mod(T, double); +template T mod(T, T); +template T modf(T, T); +template T pow(T, T) {} +template T round(T) {} +template T smoothstep(T, T, T) {} +template T sqrt(T) {} +template T step(T) {} +template T trunc(T) {} +template T ldexp(T, U) {} + +template T acos(T) {} +template T acosh(T) {} +template T asin(T) {} +template T asinh(T) {} +template T atan(T, T) {} +template T atan(T) {} +template T atanh(T) {} +template T cos(T) {} +template T cosh(T) {} +template T sin(T) {} +template T sinh(T) {} +template T tan(T) {} +template T tanh(T) {} + +template T degrees(T) {} +template T radians(T) {} + +/* Declared explicitely to avoid type errors. */ +double mix(double, double, double) {} +template VecBase mix(VecBase, VecBase, double) {} +template VecBase mix(VecBase, VecBase, VecBase) {} + +VecBase cross(VecBase, VecBase) {} +template float dot(VecBase, VecBase) {} +template float distance(VecBase, VecBase) {} +template float length(VecBase) {} +template VecBase normalize(VecBase) {} + +template VecBase floatBitsToInt(VecBase) {} +template VecBase floatBitsToUint(VecBase) {} +template VecBase intBitsToFloat(VecBase) {} +template VecBase uintBitsToFloat(VecBase) {} +int floatBitsToInt(double) {} +uint floatBitsToUint(double) {} +double intBitsToFloat(int) {} +double uintBitsToFloat(uint) {} + +template T dFdx(T) {} +template T dFdy(T) {} +template T fwidth(T) {} + +/* Geometric functions. */ +template float faceforward(VecBase, VecBase, VecBase) {} +template float reflect(VecBase, VecBase) {} +template float refract(VecBase, VecBase, double) {} + +/* Packing functions. */ +uint packHalf2x16(float2) {} +uint packUnorm2x16(float2) {} +uint packSnorm2x16(float2) {} +uint packUnorm4x8(float4) {} +uint packSnorm4x8(float4) {} +float2 unpackHalf2x16(uint) {} +float2 unpackUnorm2x16(uint) {} +float2 unpackSnorm2x16(uint) {} +float4 unpackUnorm4x8(uint) {} +float4 unpackSnorm4x8(uint) {} + +#if 0 /* TODO Matrices */ +template float determinant(MatBase) {} +template MatBase inverse(MatBase) {} +template MatBase transpose(MatBase) {} +#endif -- 2.30.2 From ddc4e33fbcccd0046ded7ef04225ff67a23ef012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Mon, 23 Sep 2024 17:14:03 +0200 Subject: [PATCH 14/38] Add color swizzle --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 46 +++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index d9d6908cdcc..dd14017f99a 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -77,6 +77,13 @@ template struct VecSwizzle2 { yyxx, yyxy, yyyx, yyyy; }; +template struct ColSwizzle2 { + static VecBase rr, rg, gr, gg; + static VecBase rrr, rrg, rgr, rgg, grr, grg, ggr, ggg; + static VecBase rrrr, rrrg, rrgr, rrgg, rgrr, rgrg, rggr, rggg, grrr, grrg, grgr, grgg, + ggrr, ggrg, gggr, gggg; +}; + template struct VecSwizzle3 : VecSwizzle2 { static VecBase xz, yz, zx, zy, zz, zw; static VecBase xxz, xyz, xzx, xzy, xzz, yxz, yyz, yzx, yzy, yzz, zxx, zxy, zxz, zyx, zyy, @@ -88,6 +95,17 @@ template struct VecSwizzle3 : VecSwizzle2 { zzxy, zzxz, zzyx, zzyy, zzyz, zzzx, zzzy, zzzz; }; +template struct ColSwizzle3 : ColSwizzle2 { + static VecBase rb, gb, br, bg, bb, bw; + static VecBase rrb, rgb, rbr, rbg, rbb, grb, ggb, gbr, gbg, gbb, brr, brg, brb, bgr, bgg, + bgb, bbr, bbg, bbb; + static VecBase rrrb, rrgb, rrbr, rrbg, rrbb, rgrb, rggb, rgbr, rgbg, rgbb, rbrr, rbrg, + rbrb, rbgr, rbgg, rbgb, rbbr, rbbg, rbbb, grrb, grgb, grbr, grbg, grbb, ggrb, gggb, ggbr, + ggbg, ggbb, gbrr, gbrg, gbrb, gbgr, gbgg, gbgb, gbbr, gbbg, gbbb, brrr, brrg, brrb, brgr, + brgg, brgb, brbr, brbg, brbb, bgrr, bgrg, bgrb, bggr, bggg, bggb, bgbr, bgbg, bgbb, bbrr, + bbrg, bbrb, bbgr, bbgg, bbgb, bbbr, bbbg, bbbb; +}; + template struct VecSwizzle4 : VecSwizzle3 { static VecBase xw, yw, wx, wy, wz, ww; static VecBase xxw, xyw, xzw, xwx, xwy, xwz, xww, yxw, yyw, yzw, ywx, ywy, ywz, yww, zxw, @@ -107,8 +125,28 @@ template struct VecSwizzle4 : VecSwizzle3 { wwxw, wwyx, wwyy, wwyz, wwyw, wwzx, wwzy, wwzz, wwzw, wwwx, wwwy, wwwz, wwww; }; -template struct VecBase : VecOp, VecSwizzle2 { +template struct ColSwizzle4 : ColSwizzle3 { + static VecBase ra, ga, ar, ag, ab, aa; + static VecBase rra, rga, rba, rar, rag, rab, raa, gra, gga, gba, gar, gag, gab, gaa, bra, + bga, bba, bar, bag, bab, baa, arr, arg, arb, ara, agr, agg, agb, aga, abr, abg, abb, aba, + aar, aag, aab, aaa; + static VecBase rrra, rrga, rrba, rrar, rrag, rrab, rraa, rgra, rgga, rgba, rgar, rgag, + rgab, rgaa, rbra, rbga, rbba, rbar, rbag, rbab, rbaa, rarr, rarg, rarb, rara, ragr, ragg, + ragb, raga, rabr, rabg, rabb, raba, raar, raag, raab, raaa, grra, grga, grba, grar, grag, + grab, graa, ggra, ggga, ggba, ggar, ggag, ggab, ggaa, gbra, gbga, gbba, gbar, gbag, gbab, + gbaa, garr, garg, garb, gara, gagr, gagg, gagb, gaga, gabr, gabg, gabb, gaba, gaar, gaag, + gaab, gaaa, brra, brga, brba, brar, brag, brab, braa, bgra, bgga, bgba, bgar, bgag, bgab, + bgaa, bbra, bbga, bbba, bbar, bbag, bbab, bbaa, barr, barg, barb, bara, bagr, bagg, bagb, + baga, babr, babg, babb, baba, baar, baag, baab, baaa, arrr, arrg, arrb, arra, argr, argg, + argb, arga, arbr, arbg, arbb, arba, arar, arag, arab, araa, agrr, agrg, agrb, agra, aggr, + aggg, aggb, agga, agbr, agbg, agbb, agba, agar, agag, agab, agaa, abrr, abrg, abrb, abra, + abgr, abgg, abgb, abga, abbr, abbg, abbb, abba, abar, abag, abab, abaa, aarr, aarg, aarb, + aara, aagr, aagg, aagb, aaga, aabr, aabg, aabb, aaba, aaar, aaag, aaab, aaaa; +}; + +template struct VecBase : VecOp, VecSwizzle2, ColSwizzle2 { T x, y; + T r, g; VecBase() = default; template explicit VecBase(VecBase) {} @@ -116,8 +154,9 @@ template struct VecBase : VecOp, VecSwizzle2 { explicit VecBase(T, T) {} }; -template struct VecBase : VecOp, VecSwizzle3 { +template struct VecBase : VecOp, VecSwizzle3, ColSwizzle3 { T x, y, z; + T r, g, b; VecBase() = default; template explicit VecBase(VecBase) {} @@ -127,8 +166,9 @@ template struct VecBase : VecOp, VecSwizzle3 { explicit VecBase(T, VecBase) {} }; -template struct VecBase : VecOp, VecSwizzle4 { +template struct VecBase : VecOp, VecSwizzle4, ColSwizzle4 { T x, y, z, w; + T r, g, b, a; VecBase() = default; template explicit VecBase(VecBase) {} -- 2.30.2 From ae91a46e37ad8dd857953a8bd9ea1393d17aa350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Mon, 23 Sep 2024 17:20:43 +0200 Subject: [PATCH 15/38] Add builtin and keywords --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index dd14017f99a..91362c0601a 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -495,3 +495,26 @@ template float determinant(MatBase) {} template MatBase inverse(MatBase) {} template MatBase transpose(MatBase) {} #endif + +/* Vertex Shader Special Variables. */ +const int gl_VertexID; +const int gl_InstanceID; +const int gl_BaseVertex; +const int gl_BaseInstance; +float4 gl_Position; +float gl_PointSize; +/* Fragment Shader Special Variables. */ +const float4 gl_FragCoord; +const bool gl_FrontFacing; +const float2 gl_PointCoord; +const int gl_PrimitiveID; +float gl_FragDepth; +/* Read-only in Fragment Shader and write-only in vertex shader. */ +float gl_ClipDistance[]; +float gl_CullDistance[]; +/* Use GPU variant as they can be emulated. */ +int gpu_Layer; +int gpu_ViewportIndex; + +/* Keywords. */ +void discard; -- 2.30.2 From 4592d2f6c6eb6917cd8a6af74484930f701de109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Mon, 23 Sep 2024 18:08:00 +0200 Subject: [PATCH 16/38] Remove vector ops argument names --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 80 +++++++++---------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index 91362c0601a..b0530388c5a 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -14,58 +14,58 @@ template struct VecOp { VecT operator+() const {} VecT operator-() const {} - VecT operator+(VecT b) const {} - VecT operator-(VecT b) const {} - VecT operator/(VecT b) const {} - VecT operator*(VecT b) const {} + VecT operator+(VecT) const {} + VecT operator-(VecT) const {} + VecT operator/(VecT) const {} + VecT operator*(VecT) const {} - VecT operator+=(VecT b) const {} - VecT operator-=(VecT b) const {} - VecT operator/=(VecT b) const {} - VecT operator*=(VecT b) const {} + VecT operator+=(VecT) const {} + VecT operator-=(VecT) const {} + VecT operator/=(VecT) const {} + VecT operator*=(VecT) const {} - VecT operator+(T b) const {} - VecT operator-(T b) const {} - VecT operator/(T b) const {} - VecT operator*(T b) const {} + VecT operator+(T) const {} + VecT operator-(T) const {} + VecT operator/(T) const {} + VecT operator*(T) const {} - VecT operator+=(T b) const {} - VecT operator-=(T b) const {} - VecT operator/=(T b) const {} - VecT operator*=(T b) const {} + VecT operator+=(T) const {} + VecT operator-=(T) const {} + VecT operator/=(T) const {} + VecT operator*=(T) const {} - friend VecT operator+(T a, VecT b) {} - friend VecT operator-(T a, VecT b) {} - friend VecT operator/(T a, VecT b) {} - friend VecT operator*(T a, VecT b) {} + friend VecT operator+(T, VecT) {} + friend VecT operator-(T, VecT) {} + friend VecT operator/(T, VecT) {} + friend VecT operator*(T, VecT) {} #define INT_OP \ template> * = nullptr> - INT_OP VecT operator%(VecT b) {} - INT_OP VecT operator&(VecT b) {} - INT_OP VecT operator|(VecT b) {} - INT_OP VecT operator^(VecT b) {} + INT_OP VecT operator%(VecT) const {} + INT_OP VecT operator&(VecT) const {} + INT_OP VecT operator|(VecT) const {} + INT_OP VecT operator^(VecT) const {} - INT_OP VecT operator%=(VecT b) {} - INT_OP VecT operator&=(VecT b) {} - INT_OP VecT operator|=(VecT b) {} - INT_OP VecT operator^=(VecT b) {} + INT_OP VecT operator%=(VecT) const {} + INT_OP VecT operator&=(VecT) const {} + INT_OP VecT operator|=(VecT) const {} + INT_OP VecT operator^=(VecT) const {} - INT_OP VecT operator%(T b) {} - INT_OP VecT operator&(T b) {} - INT_OP VecT operator|(T b) {} - INT_OP VecT operator^(T b) {} + INT_OP VecT operator%(T) const {} + INT_OP VecT operator&(T) const {} + INT_OP VecT operator|(T) const {} + INT_OP VecT operator^(T) const {} - INT_OP VecT operator%=(T b) {} - INT_OP VecT operator&=(T b) {} - INT_OP VecT operator|=(T b) {} - INT_OP VecT operator^=(T b) {} + INT_OP VecT operator%=(T) const {} + INT_OP VecT operator&=(T) const {} + INT_OP VecT operator|=(T) const {} + INT_OP VecT operator^=(T) const {} - INT_OP friend VecT operator%(T a, VecT b) {} - INT_OP friend VecT operator&(T a, VecT b) {} - INT_OP friend VecT operator|(T a, VecT b) {} - INT_OP friend VecT operator^(T a, VecT b) {} + INT_OP friend VecT operator%(T, VecT) {} + INT_OP friend VecT operator&(T, VecT) {} + INT_OP friend VecT operator|(T, VecT) {} + INT_OP friend VecT operator^(T, VecT) {} #undef INT_OP }; -- 2.30.2 From 4f48b6fa601c04be8d3949c14447bde0db720495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Mon, 23 Sep 2024 18:08:21 +0200 Subject: [PATCH 17/38] Matrices --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 80 +++++++++++++++++-- 1 file changed, 74 insertions(+), 6 deletions(-) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index b0530388c5a..ef4817ed024 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -9,7 +9,7 @@ template struct VecBase {}; template struct VecOp { using VecT = VecBase; - T operator[](int) {} + T &operator[](int) {} VecT operator+() const {} VecT operator-() const {} @@ -250,6 +250,76 @@ using bvec2 = bool2; using bvec3 = bool3; using bvec4 = bool4; +template struct MatBase {}; + +template struct MatOp { + using MatT = MatBase; + using ColT = VecBase; + using RowT = VecBase; + + ColT &operator[](int) {} + + MatT operator*(MatT) const {} + + friend ColT operator*(RowT, MatT) {} + friend RowT operator*(MatT, ColT) {} +}; + +template struct MatBase<2, R> : MatOp<2, R> { + using T = double; + using ColT = VecBase; + ColT x, y; + + MatBase() = default; + explicit MatBase(T) {} + explicit MatBase(ColT, ColT) {} + template explicit MatBase(const MatBase &) {} +}; + +template struct MatBase<3, R> : MatOp<3, R> { + using ColT = VecBase; + ColT x, y, z; + + MatBase() = default; + explicit MatBase(double) {} + explicit MatBase(ColT, ColT, ColT) {} + template explicit MatBase(const MatBase &) {} +}; + +template struct MatBase<4, R> : MatOp<4, R> { + using ColT = VecBase; + ColT x, y, z, w; + + MatBase() = default; + explicit MatBase(double) {} + explicit MatBase(ColT, ColT, ColT, ColT) {} + template explicit MatBase(const MatBase &) {} +}; + +using float2x2 = MatBase<2, 2>; +using float2x3 = MatBase<2, 3>; +using float2x4 = MatBase<2, 4>; +using float3x2 = MatBase<3, 2>; +using float3x3 = MatBase<3, 3>; +using float3x4 = MatBase<3, 4>; +using float4x2 = MatBase<4, 2>; +using float4x3 = MatBase<4, 3>; +using float4x4 = MatBase<4, 4>; + +using mat2x2 = float2x2; +using mat2x3 = float2x3; +using mat2x4 = float2x4; +using mat3x2 = float3x2; +using mat3x3 = float3x3; +using mat3x4 = float3x4; +using mat4x2 = float4x2; +using mat4x3 = float4x3; +using mat4x4 = float4x4; + +using mat2 = float2x2; +using mat3 = float3x3; +using mat4 = float4x4; + template VecBase greaterThan(VecBase, VecBase) {} template VecBase lessThan(VecBase, VecBase) {} template VecBase lessThanEqual(VecBase, VecBase) {} @@ -490,11 +560,9 @@ float2 unpackSnorm2x16(uint) {} float4 unpackUnorm4x8(uint) {} float4 unpackSnorm4x8(uint) {} -#if 0 /* TODO Matrices */ -template float determinant(MatBase) {} -template MatBase inverse(MatBase) {} -template MatBase transpose(MatBase) {} -#endif +template float determinant(MatBase) {} +template MatBase inverse(MatBase) {} +template MatBase transpose(MatBase) {} /* Vertex Shader Special Variables. */ const int gl_VertexID; -- 2.30.2 From 88fb3cdf1de0ca89bc82ed85330c865dbf827139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Mon, 23 Sep 2024 18:08:29 +0200 Subject: [PATCH 18/38] Some missing functions --- source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index ef4817ed024..9276ac6037c 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -524,6 +524,8 @@ double mix(double, double, double) {} template VecBase mix(VecBase, VecBase, double) {} template VecBase mix(VecBase, VecBase, VecBase) {} +#define select(A, B, C) mix(A, B, C) + VecBase cross(VecBase, VecBase) {} template float dot(VecBase, VecBase) {} template float distance(VecBase, VecBase) {} @@ -586,3 +588,8 @@ int gpu_ViewportIndex; /* Keywords. */ void discard; + +/* TODO(fclem): Should be in a lib instead of being impemented by each backend. */ +bool is_zero(vec2 A) {} +bool is_zero(vec3 A) {} +bool is_zero(vec4 A) {} -- 2.30.2 From 04a22845e98ea8520f9aa1d64fee83e5a65f3b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Mon, 23 Sep 2024 18:13:04 +0200 Subject: [PATCH 19/38] Remove unused parameters --- source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index 9276ac6037c..a2cbe8b6c30 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -590,6 +590,6 @@ int gpu_ViewportIndex; void discard; /* TODO(fclem): Should be in a lib instead of being impemented by each backend. */ -bool is_zero(vec2 A) {} -bool is_zero(vec3 A) {} -bool is_zero(vec4 A) {} +bool is_zero(vec2) {} +bool is_zero(vec3) {} +bool is_zero(vec4) {} -- 2.30.2 From e73430e3593edbec153b98ab0cb23d61093b2000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Mon, 23 Sep 2024 19:07:35 +0200 Subject: [PATCH 20/38] Add array syntax compatibility --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 20 +++++++++++++++++++ .../gpu/shaders/metal/mtl_shader_defines.msl | 20 +++++++++++++++++++ .../shaders/opengl/glsl_shader_defines.glsl | 18 +++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index a2cbe8b6c30..476568b30ac 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -593,3 +593,23 @@ void discard; bool is_zero(vec2) {} bool is_zero(vec3) {} bool is_zero(vec4) {} + +/* Array syntax compatibility. */ +/* clang-format off */ +#define float_array(...) { __VA_ARGS__ } +#define float2_array(...) { __VA_ARGS__ } +#define float3_array(...) { __VA_ARGS__ } +#define float4_array(...) { __VA_ARGS__ } +#define int_array(...) { __VA_ARGS__ } +#define int2_array(...) { __VA_ARGS__ } +#define int3_array(...) { __VA_ARGS__ } +#define int4_array(...) { __VA_ARGS__ } +#define uint_array(...) { __VA_ARGS__ } +#define uint2_array(...) { __VA_ARGS__ } +#define uint3_array(...) { __VA_ARGS__ } +#define uint4_array(...) { __VA_ARGS__ } +#define bool_array(...) { __VA_ARGS__ } +#define bool2_array(...) { __VA_ARGS__ } +#define bool3_array(...) { __VA_ARGS__ } +#define bool4_array(...) { __VA_ARGS__ } +/* clang-format on */ diff --git a/source/blender/gpu/shaders/metal/mtl_shader_defines.msl b/source/blender/gpu/shaders/metal/mtl_shader_defines.msl index f605da8baa5..961fb63ad30 100644 --- a/source/blender/gpu/shaders/metal/mtl_shader_defines.msl +++ b/source/blender/gpu/shaders/metal/mtl_shader_defines.msl @@ -2529,3 +2529,23 @@ mat3x4 MAT3x4(mat2 m) #define MAT2 MAT2x2 #define MAT3 MAT3x3 #define MAT4 MAT4x4 + +/* Array syntax compatibility. */ +/* clang-format off */ +#define float_array(...) { __VA_ARGS__ } +#define float2_array(...) { __VA_ARGS__ } +#define float3_array(...) { __VA_ARGS__ } +#define float4_array(...) { __VA_ARGS__ } +#define int_array(...) { __VA_ARGS__ } +#define int2_array(...) { __VA_ARGS__ } +#define int3_array(...) { __VA_ARGS__ } +#define int4_array(...) { __VA_ARGS__ } +#define uint_array(...) { __VA_ARGS__ } +#define uint2_array(...) { __VA_ARGS__ } +#define uint3_array(...) { __VA_ARGS__ } +#define uint4_array(...) { __VA_ARGS__ } +#define bool_array(...) { __VA_ARGS__ } +#define bool2_array(...) { __VA_ARGS__ } +#define bool3_array(...) { __VA_ARGS__ } +#define bool4_array(...) { __VA_ARGS__ } +/* clang-format on */ diff --git a/source/blender/gpu/shaders/opengl/glsl_shader_defines.glsl b/source/blender/gpu/shaders/opengl/glsl_shader_defines.glsl index 29413d63605..9f10b4ba88d 100644 --- a/source/blender/gpu/shaders/opengl/glsl_shader_defines.glsl +++ b/source/blender/gpu/shaders/opengl/glsl_shader_defines.glsl @@ -103,3 +103,21 @@ bool is_zero(vec4 A) { return all(equal(A, vec4(0.0))); } + +/* Array syntax compatibility. */ +#define float_array float[] +#define float2_array vec2[] +#define float3_array vec3[] +#define float4_array vec4[] +#define int_array int[] +#define int2_array int2[] +#define int3_array int3[] +#define int4_array int4[] +#define uint_array uint[] +#define uint2_array uint2[] +#define uint3_array uint3[] +#define uint4_array uint4[] +#define bool_array bool[] +#define bool2_array bool2[] +#define bool3_array bool3[] +#define bool4_array bool4[] -- 2.30.2 From 20d11b10e4b08448ca9833de786e7dc367b4570a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Tue, 24 Sep 2024 11:41:40 +0200 Subject: [PATCH 21/38] Guard against GLSL / MSL include --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 56 ++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index 476568b30ac..8a44e6a2210 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -2,7 +2,11 @@ * * SPDX-License-Identifier: GPL-2.0-or-later */ -#include +#pragma once + +#if defined(__cplusplus) && !defined(GPU_SHADER) + +# include template struct VecBase {}; @@ -39,8 +43,8 @@ template struct VecOp { friend VecT operator/(T, VecT) {} friend VecT operator*(T, VecT) {} -#define INT_OP \ - template> * = nullptr> +# define INT_OP \ + template> * = nullptr> INT_OP VecT operator%(VecT) const {} INT_OP VecT operator&(VecT) const {} @@ -67,7 +71,7 @@ template struct VecOp { INT_OP friend VecT operator|(T, VecT) {} INT_OP friend VecT operator^(T, VecT) {} -#undef INT_OP +# undef INT_OP }; template struct VecSwizzle2 { @@ -330,11 +334,11 @@ template bool any(VecBase) {} template bool all(VecBase) {} /* `not` is a C++ keyword. Use dirty macro to allow this. */ template VecBase not_impl(VecBase) {} -#define not not_impl +# define not not_impl -#define inout -#define in -#define out +# define inout +# define in +# define out template using Vec4 = VecBase; template using VecInt = VecBase; @@ -352,13 +356,13 @@ template stru using size_vec_type = VecBase; }; -#define TEX_TEMPLATE \ - template +# define TEX_TEMPLATE \ + template TEX_TEMPLATE SizeVec textureSize(T, int) {} TEX_TEMPLATE DataVec texelFetch(T, IntCoord, int) {} @@ -368,7 +372,7 @@ TEX_TEMPLATE DataVec textureGather(T, FltCoord) {} TEX_TEMPLATE DataVec textureGrad(T, FltCoord, DerivVec, DerivVec) {} TEX_TEMPLATE DataVec textureLod(T, FltCoord, double) {} -#undef TEX_TEMPLATE +# undef TEX_TEMPLATE using sampler1D = SamplerBase; using sampler2D = SamplerBase; @@ -405,20 +409,20 @@ template struct ImageBase { using size_vec_type = VecBase; }; -#define IMG_TEMPLATE \ - template +# define IMG_TEMPLATE \ + template IMG_TEMPLATE SizeVec imageSize(T) {} IMG_TEMPLATE DataVec imageLoad(T, IntCoord) {} IMG_TEMPLATE void imageStore(T, IntCoord, DataVec) {} IMG_TEMPLATE void imageFence(T) {} -#define imageLoadFast imageLoad -#define imageStoreFast imageStore +# define imageLoadFast imageLoad +# define imageStoreFast imageStore -#undef IMG_TEMPLATE +# undef IMG_TEMPLATE using sampler1D = SamplerBase; using sampler2D = SamplerBase; @@ -524,7 +528,7 @@ double mix(double, double, double) {} template VecBase mix(VecBase, VecBase, double) {} template VecBase mix(VecBase, VecBase, VecBase) {} -#define select(A, B, C) mix(A, B, C) +# define select(A, B, C) mix(A, B, C) VecBase cross(VecBase, VecBase) {} template float dot(VecBase, VecBase) {} @@ -613,3 +617,5 @@ bool is_zero(vec4) {} #define bool3_array(...) { __VA_ARGS__ } #define bool4_array(...) { __VA_ARGS__ } /* clang-format on */ + +#endif -- 2.30.2 From 9d0552039105948159416cb90357411a8e47ce69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Tue, 24 Sep 2024 12:23:06 +0200 Subject: [PATCH 22/38] Add sections, add documentation, fix integer ops, fix image types --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 161 ++++++++++++------ 1 file changed, 109 insertions(+), 52 deletions(-) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index 8a44e6a2210..cb19cfde3d4 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -2,12 +2,32 @@ * * SPDX-License-Identifier: GPL-2.0-or-later */ +/** + * GLSL to C++ stubs. + * + * The goal of this header is to make the GLSL source file compile using a modern C++ compiler. + * This allows for linting and IDE functionalities to work. + * + * This is why the implementation of each function is not needed. + * + * Some of the features of GLSL are omitted by design. They are either: + * - not needed (e.g. per component matrix multiplication) + * - against our code-style (e.g. stpq swizzle) + * - unsupported by our Metal Shading Language layer (e.g. mixed vector-scalar matrix constructor). + * + * IMPORTANT: Please ask the module team if you need some feature that are not listed in this file. + */ + #pragma once -#if defined(__cplusplus) && !defined(GPU_SHADER) +#ifndef GPU_SHADER # include +/* -------------------------------------------------------------------- */ +/** \name Vector Types + * \{ */ + template struct VecBase {}; template struct VecOp { @@ -44,7 +64,7 @@ template struct VecOp { friend VecT operator*(T, VecT) {} # define INT_OP \ - template> * = nullptr> + template> * = nullptr> INT_OP VecT operator%(VecT) const {} INT_OP VecT operator&(VecT) const {} @@ -254,6 +274,12 @@ using bvec2 = bool2; using bvec3 = bool3; using bvec4 = bool4; +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Matrix Types + * \{ */ + template struct MatBase {}; template struct MatOp { @@ -324,25 +350,11 @@ using mat2 = float2x2; using mat3 = float3x3; using mat4 = float4x4; -template VecBase greaterThan(VecBase, VecBase) {} -template VecBase lessThan(VecBase, VecBase) {} -template VecBase lessThanEqual(VecBase, VecBase) {} -template VecBase greaterThanEqual(VecBase, VecBase) {} -template VecBase equal(VecBase, VecBase) {} -template VecBase notEqual(VecBase, VecBase) {} -template bool any(VecBase) {} -template bool all(VecBase) {} -/* `not` is a C++ keyword. Use dirty macro to allow this. */ -template VecBase not_impl(VecBase) {} -# define not not_impl +/** \} */ -# define inout -# define in -# define out - -template using Vec4 = VecBase; -template using VecInt = VecBase; -template using VecFlt = VecBase; +/* -------------------------------------------------------------------- */ +/** \name Sampler Types + * \{ */ template struct SamplerBase { static constexpr int coord_dim = Dimensions + int(Cube) + int(Array); @@ -399,14 +411,18 @@ using samplerCubeArray = SamplerBase; using isamplerCubeArray = SamplerBase; using usamplerCubeArray = SamplerBase; +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Image Types + * \{ */ + template struct ImageBase { - static constexpr int coord_dim = Dimensions + int(Cube) + int(Array); - static constexpr int deriv_dim = Dimensions + int(Cube); - static constexpr int extent_dim = Dimensions + int(Array); + static constexpr int coord_dim = Dimensions + int(Array); using int_coord_type = VecBase; using data_vec_type = VecBase; - using size_vec_type = VecBase; + using size_vec_type = VecBase; }; # define IMG_TEMPLATE \ @@ -424,30 +440,42 @@ IMG_TEMPLATE void imageFence(T) {} # undef IMG_TEMPLATE -using sampler1D = SamplerBase; -using sampler2D = SamplerBase; -using sampler3D = SamplerBase; -using isampler1D = SamplerBase; -using isampler2D = SamplerBase; -using isampler3D = SamplerBase; -using usampler1D = SamplerBase; -using usampler2D = SamplerBase; -using usampler3D = SamplerBase; +using image1D = ImageBase; +using image2D = ImageBase; +using image3D = ImageBase; +using iimage1D = ImageBase; +using iimage2D = ImageBase; +using iimage3D = ImageBase; +using uimage1D = ImageBase; +using uimage2D = ImageBase; +using uimage3D = ImageBase; -using sampler1DArray = SamplerBase; -using sampler2DArray = SamplerBase; -using isampler1DArray = SamplerBase; -using isampler2DArray = SamplerBase; -using usampler1DArray = SamplerBase; -using usampler2DArray = SamplerBase; +using image1DArray = ImageBase; +using image2DArray = ImageBase; +using iimage1DArray = ImageBase; +using iimage2DArray = ImageBase; +using uimage1DArray = ImageBase; +using uimage2DArray = ImageBase; -using samplerCube = SamplerBase; -using isamplerCube = SamplerBase; -using usamplerCube = SamplerBase; +/* Forbid Cube and cube arrays. Bind them as 3D textures instead. */ -using samplerCubeArray = SamplerBase; -using isamplerCubeArray = SamplerBase; -using usamplerCubeArray = SamplerBase; +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Builtin Functions + * \{ */ + +template VecBase greaterThan(VecBase, VecBase) {} +template VecBase lessThan(VecBase, VecBase) {} +template VecBase lessThanEqual(VecBase, VecBase) {} +template VecBase greaterThanEqual(VecBase, VecBase) {} +template VecBase equal(VecBase, VecBase) {} +template VecBase notEqual(VecBase, VecBase) {} +template bool any(VecBase) {} +template bool all(VecBase) {} +/* `not` is a C++ keyword. Use dirty macro to allow this. */ +template VecBase not_impl(VecBase) {} +# define not not_impl template VecBase bitCount(VecBase) {} template VecBase bitCount(VecBase) {} @@ -566,10 +594,22 @@ float2 unpackSnorm2x16(uint) {} float4 unpackUnorm4x8(uint) {} float4 unpackSnorm4x8(uint) {} +/* Matrices functions. */ template float determinant(MatBase) {} template MatBase inverse(MatBase) {} template MatBase transpose(MatBase) {} +/* TODO(fclem): Should be in a lib instead of being impemented by each backend. */ +bool is_zero(vec2) {} +bool is_zero(vec3) {} +bool is_zero(vec4) {} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Special Variables + * \{ */ + /* Vertex Shader Special Variables. */ const int gl_VertexID; const int gl_InstanceID; @@ -585,18 +625,33 @@ const int gl_PrimitiveID; float gl_FragDepth; /* Read-only in Fragment Shader and write-only in vertex shader. */ float gl_ClipDistance[]; -float gl_CullDistance[]; -/* Use GPU variant as they can be emulated. */ +/* Note: Use GPU variant as they might be emulated. */ int gpu_Layer; int gpu_ViewportIndex; -/* Keywords. */ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Keywords + * \{ */ + +/* Note: Cannot easily mutate them. Pass every by copy for now. */ + +/* Pass argument by reference. */ +# define inout +/* Pass argument by reference but only write to it. Its initial value is undefined. */ +# define out +/* Pass argument by copy (default). */ +# define in + +/* Cannot easily mutate them. Pass every by copy for now. */ void discard; -/* TODO(fclem): Should be in a lib instead of being impemented by each backend. */ -bool is_zero(vec2) {} -bool is_zero(vec3) {} -bool is_zero(vec4) {} +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Compatibility + * \{ */ /* Array syntax compatibility. */ /* clang-format off */ @@ -618,4 +673,6 @@ bool is_zero(vec4) {} #define bool4_array(...) { __VA_ARGS__ } /* clang-format on */ +/** \} */ + #endif -- 2.30.2 From ede38b7d98716cf88d7e54d61bbe422c2f73d43c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Tue, 24 Sep 2024 12:31:16 +0200 Subject: [PATCH 23/38] Matrix scalar constructors, more documentation --- source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index cb19cfde3d4..dc1a2fbf502 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -8,7 +8,12 @@ * The goal of this header is to make the GLSL source file compile using a modern C++ compiler. * This allows for linting and IDE functionalities to work. * - * This is why the implementation of each function is not needed. + * This is why the implementation of each function is not needed. However, we make sure that type + * casting is always explicit. This is because implicit casts are not always supported on all + * implementations. + * + * Float types are set to double to accept float literals without trailing f and avoid casting + * issues. * * Some of the features of GLSL are omitted by design. They are either: * - not needed (e.g. per component matrix multiplication) @@ -302,26 +307,31 @@ template struct MatBase<2, R> : MatOp<2, R> { MatBase() = default; explicit MatBase(T) {} + explicit MatBase(T, T, T, T) {} explicit MatBase(ColT, ColT) {} template explicit MatBase(const MatBase &) {} }; template struct MatBase<3, R> : MatOp<3, R> { + using T = double; using ColT = VecBase; ColT x, y, z; MatBase() = default; - explicit MatBase(double) {} + explicit MatBase(T) {} + explicit MatBase(T, T, T, T, T, T, T, T, T) {} explicit MatBase(ColT, ColT, ColT) {} template explicit MatBase(const MatBase &) {} }; template struct MatBase<4, R> : MatOp<4, R> { + using T = double; using ColT = VecBase; ColT x, y, z, w; MatBase() = default; - explicit MatBase(double) {} + explicit MatBase(T) {} + explicit MatBase(T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) {} explicit MatBase(ColT, ColT, ColT, ColT) {} template explicit MatBase(const MatBase &) {} }; -- 2.30.2 From 3745cc45552e7a4714440c10257b7a4a8ab2cc97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Tue, 24 Sep 2024 12:50:55 +0200 Subject: [PATCH 24/38] Add atomic functions --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index dc1a2fbf502..0be1fef74ff 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -448,6 +448,14 @@ IMG_TEMPLATE void imageFence(T) {} # define imageLoadFast imageLoad # define imageStoreFast imageStore +IMG_TEMPLATE uint imageAtomicAdd(T, IntCoord, uint); +IMG_TEMPLATE uint imageAtomicMin(T, IntCoord, uint); +IMG_TEMPLATE uint imageAtomicMax(T, IntCoord, uint); +IMG_TEMPLATE uint imageAtomicAnd(T, IntCoord, uint); +IMG_TEMPLATE uint imageAtomicXor(T, IntCoord, uint); +IMG_TEMPLATE uint imageAtomicExchange(T, IntCoord, uint); +IMG_TEMPLATE uint imageAtomicCompSwap(T, IntCoord, uint, uint); + # undef IMG_TEMPLATE using image1D = ImageBase; @@ -583,6 +591,7 @@ uint floatBitsToUint(double) {} double intBitsToFloat(int) {} double uintBitsToFloat(uint) {} +/* Derivative functions. */ template T dFdx(T) {} template T dFdy(T) {} template T fwidth(T) {} @@ -592,6 +601,24 @@ template float faceforward(VecBase, VecBase, VecB template float reflect(VecBase, VecBase) {} template float refract(VecBase, VecBase, double) {} +/* Atomic operations. */ +int atomicAdd(int &, int); +int atomicAnd(int &, int); +int atomicOr(int &, int); +int atomicXor(int &, int); +int atomicMin(int &, int); +int atomicMax(int &, int); +int atomicExchange(int &, int); +int atomicCompSwap(int &, int, int); +uint atomicAdd(uint &, uint); +uint atomicAnd(uint &, uint); +uint atomicOr(uint &, uint); +uint atomicXor(uint &, uint); +uint atomicMin(uint &, uint); +uint atomicMax(uint &, uint); +uint atomicExchange(uint &, uint); +uint atomicCompSwap(uint &, uint, uint); + /* Packing functions. */ uint packHalf2x16(float2) {} uint packUnorm2x16(float2) {} -- 2.30.2 From 0f7c26c72ad4316b9608ef2b4f3f094012f3ebca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Tue, 24 Sep 2024 12:56:52 +0200 Subject: [PATCH 25/38] Add usage documentation --- source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index 0be1fef74ff..fafe9d29344 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -8,6 +8,9 @@ * The goal of this header is to make the GLSL source file compile using a modern C++ compiler. * This allows for linting and IDE functionalities to work. * + * This file can be included inside any GLSL file to make the GLSL syntax to work. Then your IDE + * must to be configured to associate .glsl files to C++ so that the C++ linter does the analysis. + * * This is why the implementation of each function is not needed. However, we make sure that type * casting is always explicit. This is because implicit casts are not always supported on all * implementations. -- 2.30.2 From bfc53ec21496a3960cd23cf9ca65638758d4ee4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Tue, 24 Sep 2024 13:02:37 +0200 Subject: [PATCH 26/38] Fix sign --- source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index fafe9d29344..a237d89882b 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -527,7 +527,7 @@ template T abs(T) {} template T clamp(T, T, T) {} template T max(T, T) {} template T min(T, T) {} -template T sign(T, T) {} +template T sign(T) {} template T clamp(T, U, U) {} template T max(T, U) {} template T min(T, U) {} -- 2.30.2 From 9066c90b3ef59e0d0a27a9cb9759b96b629ec314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Tue, 24 Sep 2024 13:26:05 +0200 Subject: [PATCH 27/38] Fix a few errors on some compilers --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index a237d89882b..dcfdf354cd9 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -312,7 +312,7 @@ template struct MatBase<2, R> : MatOp<2, R> { explicit MatBase(T) {} explicit MatBase(T, T, T, T) {} explicit MatBase(ColT, ColT) {} - template explicit MatBase(const MatBase &) {} + template explicit MatBase(const MatBase &) {} }; template struct MatBase<3, R> : MatOp<3, R> { @@ -605,22 +605,22 @@ template float reflect(VecBase, VecBase) {} template float refract(VecBase, VecBase, double) {} /* Atomic operations. */ -int atomicAdd(int &, int); -int atomicAnd(int &, int); -int atomicOr(int &, int); -int atomicXor(int &, int); -int atomicMin(int &, int); -int atomicMax(int &, int); -int atomicExchange(int &, int); -int atomicCompSwap(int &, int, int); -uint atomicAdd(uint &, uint); -uint atomicAnd(uint &, uint); -uint atomicOr(uint &, uint); -uint atomicXor(uint &, uint); -uint atomicMin(uint &, uint); -uint atomicMax(uint &, uint); -uint atomicExchange(uint &, uint); -uint atomicCompSwap(uint &, uint, uint); +int atomicAdd(int &, int) {} +int atomicAnd(int &, int) {} +int atomicOr(int &, int) {} +int atomicXor(int &, int) {} +int atomicMin(int &, int) {} +int atomicMax(int &, int) {} +int atomicExchange(int &, int) {} +int atomicCompSwap(int &, int, int) {} +uint atomicAdd(uint &, uint) {} +uint atomicAnd(uint &, uint) {} +uint atomicOr(uint &, uint) {} +uint atomicXor(uint &, uint) {} +uint atomicMin(uint &, uint) {} +uint atomicMax(uint &, uint) {} +uint atomicExchange(uint &, uint) {} +uint atomicCompSwap(uint &, uint, uint) {} /* Packing functions. */ uint packHalf2x16(float2) {} @@ -651,23 +651,23 @@ bool is_zero(vec4) {} * \{ */ /* Vertex Shader Special Variables. */ -const int gl_VertexID; -const int gl_InstanceID; -const int gl_BaseVertex; -const int gl_BaseInstance; -float4 gl_Position; -float gl_PointSize; +const int gl_VertexID = 0; +const int gl_InstanceID = 0; +const int gl_BaseVertex = 0; +const int gl_BaseInstance = 0; +float4 gl_Position = float4(0); +double gl_PointSize = 0; /* Fragment Shader Special Variables. */ -const float4 gl_FragCoord; -const bool gl_FrontFacing; -const float2 gl_PointCoord; -const int gl_PrimitiveID; -float gl_FragDepth; +const float4 gl_FragCoord = float4(0); +const bool gl_FrontFacing = true; +const float2 gl_PointCoord = float2(0); +const int gl_PrimitiveID = 0; +float gl_FragDepth = 0; /* Read-only in Fragment Shader and write-only in vertex shader. */ -float gl_ClipDistance[]; +float gl_ClipDistance[6] = {0}; /* Note: Use GPU variant as they might be emulated. */ -int gpu_Layer; -int gpu_ViewportIndex; +int gpu_Layer = 0; +int gpu_ViewportIndex = 0; /** \} */ @@ -684,8 +684,8 @@ int gpu_ViewportIndex; /* Pass argument by copy (default). */ # define in -/* Cannot easily mutate them. Pass every by copy for now. */ -void discard; +/* Discards the output of the current fragment shader invocation and halts its execution. */ +# define discard /** \} */ -- 2.30.2 From fc233a2501890846be58cd8dfb89e648ac66e9e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Tue, 24 Sep 2024 13:51:21 +0200 Subject: [PATCH 28/38] Compiler compatibility --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 265 +++++++++--------- 1 file changed, 136 insertions(+), 129 deletions(-) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index dcfdf354cd9..a8c6060cd4a 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -486,163 +486,170 @@ using uimage2DArray = ImageBase; /** \name Builtin Functions * \{ */ -template VecBase greaterThan(VecBase, VecBase) {} -template VecBase lessThan(VecBase, VecBase) {} -template VecBase lessThanEqual(VecBase, VecBase) {} -template VecBase greaterThanEqual(VecBase, VecBase) {} -template VecBase equal(VecBase, VecBase) {} -template VecBase notEqual(VecBase, VecBase) {} -template bool any(VecBase) {} -template bool all(VecBase) {} -/* `not` is a C++ keyword. Use dirty macro to allow this. */ -template VecBase not_impl(VecBase) {} -# define not not_impl +/* Some compilers complain about lack of return values. Keep it short. */ +# define RET \ + { \ + return {}; \ + } -template VecBase bitCount(VecBase) {} -template VecBase bitCount(VecBase) {} -template VecBase bitfieldExtract(VecBase, int, int) {} -template VecBase bitfieldExtract(VecBase, int, int) {} -template VecBase bitfieldInsert(VecBase, VecBase, int, int) {} -template VecBase bitfieldInsert(VecBase, VecBase, int, int) {} -template VecBase bitfieldReverse(VecBase) {} -template VecBase bitfieldReverse(VecBase) {} -int bitCount(int) {} -int bitCount(uint) {} -int bitfieldExtract(int) {} -int bitfieldExtract(uint) {} -int bitfieldInsert(int) {} -int bitfieldInsert(uint) {} -int bitfieldReverse(int) {} -int bitfieldReverse(uint) {} +template VecBase greaterThan(VecBase, VecBase) RET; +template VecBase lessThan(VecBase, VecBase) RET; +template VecBase lessThanEqual(VecBase, VecBase) RET; +template VecBase greaterThanEqual(VecBase, VecBase) RET; +template VecBase equal(VecBase, VecBase) RET; +template VecBase notEqual(VecBase, VecBase) RET; +template bool any(VecBase) RET; +template bool all(VecBase) RET; +/* `not` is a C++ keyword that aliases the `!` operator. Simply overload it. */ +template VecBase operator!(VecBase) RET; -template VecBase findLSB(VecBase) {} -template VecBase findLSB(VecBase) {} -template VecBase findMSB(VecBase) {} -template VecBase findMSB(VecBase) {} -int findMSB(int) {} -int findMSB(uint) {} +template VecBase bitCount(VecBase) RET; +template VecBase bitCount(VecBase) RET; +template VecBase bitfieldExtract(VecBase, int, int) RET; +template VecBase bitfieldExtract(VecBase, int, int) RET; +template VecBase bitfieldInsert(VecBase, VecBase, int, int) RET; +template VecBase bitfieldInsert(VecBase, VecBase, int, int) RET; +template VecBase bitfieldReverse(VecBase) RET; +template VecBase bitfieldReverse(VecBase) RET; +int bitCount(int) RET; +int bitCount(uint) RET; +int bitfieldExtract(int) RET; +int bitfieldExtract(uint) RET; +int bitfieldInsert(int) RET; +int bitfieldInsert(uint) RET; +int bitfieldReverse(int) RET; +int bitfieldReverse(uint) RET; + +template VecBase findLSB(VecBase) RET; +template VecBase findLSB(VecBase) RET; +template VecBase findMSB(VecBase) RET; +template VecBase findMSB(VecBase) RET; +int findMSB(int) RET; +int findMSB(uint) RET; /* Math Functions. */ -template T abs(T) {} -template T clamp(T, T, T) {} -template T max(T, T) {} -template T min(T, T) {} -template T sign(T) {} -template T clamp(T, U, U) {} -template T max(T, U) {} -template T min(T, U) {} +template T abs(T) RET; +template T clamp(T, T, T) RET; +template T max(T, T) RET; +template T min(T, T) RET; +template T sign(T) RET; +template T clamp(T, U, U) RET; +template T max(T, U) RET; +template T min(T, U) RET; /* TODO(fclem): These should be restricted to floats. */ -template T ceil(T) {} -template T exp(T) {} -template T exp2(T) {} -template T floor(T) {} -template T fma(T, T, T) {} -template T fract(T) {} -template T frexp(T, T) {} -template T inversesqrt(T) {} -template T isinf(T) {} -template T isnan(T) {} -template T log(T) {} -template T log2(T) {} +template T ceil(T) RET; +template T exp(T) RET; +template T exp2(T) RET; +template T floor(T) RET; +template T fma(T, T, T) RET; +template T fract(T) RET; +template T frexp(T, T) RET; +template T inversesqrt(T) RET; +template T isinf(T) RET; +template T isnan(T) RET; +template T log(T) RET; +template T log2(T) RET; template T mod(T, double); template T mod(T, T); template T modf(T, T); -template T pow(T, T) {} -template T round(T) {} -template T smoothstep(T, T, T) {} -template T sqrt(T) {} -template T step(T) {} -template T trunc(T) {} -template T ldexp(T, U) {} +template T pow(T, T) RET; +template T round(T) RET; +template T smoothstep(T, T, T) RET; +template T sqrt(T) RET; +template T step(T) RET; +template T trunc(T) RET; +template T ldexp(T, U) RET; -template T acos(T) {} -template T acosh(T) {} -template T asin(T) {} -template T asinh(T) {} -template T atan(T, T) {} -template T atan(T) {} -template T atanh(T) {} -template T cos(T) {} -template T cosh(T) {} -template T sin(T) {} -template T sinh(T) {} -template T tan(T) {} -template T tanh(T) {} +template T acos(T) RET; +template T acosh(T) RET; +template T asin(T) RET; +template T asinh(T) RET; +template T atan(T, T) RET; +template T atan(T) RET; +template T atanh(T) RET; +template T cos(T) RET; +template T cosh(T) RET; +template T sin(T) RET; +template T sinh(T) RET; +template T tan(T) RET; +template T tanh(T) RET; -template T degrees(T) {} -template T radians(T) {} +template T degrees(T) RET; +template T radians(T) RET; /* Declared explicitely to avoid type errors. */ -double mix(double, double, double) {} -template VecBase mix(VecBase, VecBase, double) {} -template VecBase mix(VecBase, VecBase, VecBase) {} +double mix(double, double, double) RET; +template VecBase mix(VecBase, VecBase, double) RET; +template VecBase mix(VecBase, VecBase, VecBase) RET; # define select(A, B, C) mix(A, B, C) -VecBase cross(VecBase, VecBase) {} -template float dot(VecBase, VecBase) {} -template float distance(VecBase, VecBase) {} -template float length(VecBase) {} -template VecBase normalize(VecBase) {} +VecBase cross(VecBase, VecBase) RET; +template float dot(VecBase, VecBase) RET; +template float distance(VecBase, VecBase) RET; +template float length(VecBase) RET; +template VecBase normalize(VecBase) RET; -template VecBase floatBitsToInt(VecBase) {} -template VecBase floatBitsToUint(VecBase) {} -template VecBase intBitsToFloat(VecBase) {} -template VecBase uintBitsToFloat(VecBase) {} -int floatBitsToInt(double) {} -uint floatBitsToUint(double) {} -double intBitsToFloat(int) {} -double uintBitsToFloat(uint) {} +template VecBase floatBitsToInt(VecBase) RET; +template VecBase floatBitsToUint(VecBase) RET; +template VecBase intBitsToFloat(VecBase) RET; +template VecBase uintBitsToFloat(VecBase) RET; +int floatBitsToInt(double) RET; +uint floatBitsToUint(double) RET; +double intBitsToFloat(int) RET; +double uintBitsToFloat(uint) RET; /* Derivative functions. */ -template T dFdx(T) {} -template T dFdy(T) {} -template T fwidth(T) {} +template T dFdx(T) RET; +template T dFdy(T) RET; +template T fwidth(T) RET; /* Geometric functions. */ -template float faceforward(VecBase, VecBase, VecBase) {} -template float reflect(VecBase, VecBase) {} -template float refract(VecBase, VecBase, double) {} +template float faceforward(VecBase, VecBase, VecBase) RET; +template float reflect(VecBase, VecBase) RET; +template float refract(VecBase, VecBase, double) RET; /* Atomic operations. */ -int atomicAdd(int &, int) {} -int atomicAnd(int &, int) {} -int atomicOr(int &, int) {} -int atomicXor(int &, int) {} -int atomicMin(int &, int) {} -int atomicMax(int &, int) {} -int atomicExchange(int &, int) {} -int atomicCompSwap(int &, int, int) {} -uint atomicAdd(uint &, uint) {} -uint atomicAnd(uint &, uint) {} -uint atomicOr(uint &, uint) {} -uint atomicXor(uint &, uint) {} -uint atomicMin(uint &, uint) {} -uint atomicMax(uint &, uint) {} -uint atomicExchange(uint &, uint) {} -uint atomicCompSwap(uint &, uint, uint) {} +int atomicAdd(int &, int) RET; +int atomicAnd(int &, int) RET; +int atomicOr(int &, int) RET; +int atomicXor(int &, int) RET; +int atomicMin(int &, int) RET; +int atomicMax(int &, int) RET; +int atomicExchange(int &, int) RET; +int atomicCompSwap(int &, int, int) RET; +uint atomicAdd(uint &, uint) RET; +uint atomicAnd(uint &, uint) RET; +uint atomicOr(uint &, uint) RET; +uint atomicXor(uint &, uint) RET; +uint atomicMin(uint &, uint) RET; +uint atomicMax(uint &, uint) RET; +uint atomicExchange(uint &, uint) RET; +uint atomicCompSwap(uint &, uint, uint) RET; /* Packing functions. */ -uint packHalf2x16(float2) {} -uint packUnorm2x16(float2) {} -uint packSnorm2x16(float2) {} -uint packUnorm4x8(float4) {} -uint packSnorm4x8(float4) {} -float2 unpackHalf2x16(uint) {} -float2 unpackUnorm2x16(uint) {} -float2 unpackSnorm2x16(uint) {} -float4 unpackUnorm4x8(uint) {} -float4 unpackSnorm4x8(uint) {} +uint packHalf2x16(float2) RET; +uint packUnorm2x16(float2) RET; +uint packSnorm2x16(float2) RET; +uint packUnorm4x8(float4) RET; +uint packSnorm4x8(float4) RET; +float2 unpackHalf2x16(uint) RET; +float2 unpackUnorm2x16(uint) RET; +float2 unpackSnorm2x16(uint) RET; +float4 unpackUnorm4x8(uint) RET; +float4 unpackSnorm4x8(uint) RET; /* Matrices functions. */ -template float determinant(MatBase) {} -template MatBase inverse(MatBase) {} -template MatBase transpose(MatBase) {} +template float determinant(MatBase) RET; +template MatBase inverse(MatBase) RET; +template MatBase transpose(MatBase) RET; /* TODO(fclem): Should be in a lib instead of being impemented by each backend. */ -bool is_zero(vec2) {} -bool is_zero(vec3) {} -bool is_zero(vec4) {} +bool is_zero(vec2) RET; +bool is_zero(vec3) RET; +bool is_zero(vec4) RET; + +# undef RET /** \} */ -- 2.30.2 From fc0b9efd5e979a506cfa260fcac3a14a8dc7887f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Wed, 25 Sep 2024 10:52:49 +0200 Subject: [PATCH 29/38] Compute shader builtins --- source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index a8c6060cd4a..bcc2c1e0db2 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -676,6 +676,15 @@ float gl_ClipDistance[6] = {0}; int gpu_Layer = 0; int gpu_ViewportIndex = 0; +/* Compute Shader Special Variables */ + +const uint3 gl_NumWorkGroups; +constexpr uint3 gl_WorkGroupSize; +const uint3 gl_WorkGroupID; +const uint3 gl_LocalInvocationID; +const uint3 gl_GlobalInvocationID; +const uint gl_LocalInvocationIndex; + /** \} */ /* -------------------------------------------------------------------- */ -- 2.30.2 From 684cdd792d3d15b3a896b68da84e5d33ee711687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Wed, 25 Sep 2024 10:57:43 +0200 Subject: [PATCH 30/38] Put namespaces for special variables --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index bcc2c1e0db2..a849e6a845b 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -657,26 +657,34 @@ bool is_zero(vec4) RET; /** \name Special Variables * \{ */ -/* Vertex Shader Special Variables. */ +namespace gl_VertexShader { + const int gl_VertexID = 0; const int gl_InstanceID = 0; const int gl_BaseVertex = 0; const int gl_BaseInstance = 0; float4 gl_Position = float4(0); double gl_PointSize = 0; -/* Fragment Shader Special Variables. */ +float gl_ClipDistance[6] = {0}; +int gpu_Layer = 0; +int gpu_ViewportIndex = 0; + +} // namespace gl_VertexShader + +namespace gl_FragmentShader { + const float4 gl_FragCoord = float4(0); const bool gl_FrontFacing = true; const float2 gl_PointCoord = float2(0); const int gl_PrimitiveID = 0; float gl_FragDepth = 0; -/* Read-only in Fragment Shader and write-only in vertex shader. */ -float gl_ClipDistance[6] = {0}; -/* Note: Use GPU variant as they might be emulated. */ -int gpu_Layer = 0; -int gpu_ViewportIndex = 0; +const float gl_ClipDistance[6] = {0}; +const int gpu_Layer = 0; +const int gpu_ViewportIndex = 0; -/* Compute Shader Special Variables */ +} // namespace gl_FragmentShader + +namespace gl_ComputeShader { const uint3 gl_NumWorkGroups; constexpr uint3 gl_WorkGroupSize; @@ -685,6 +693,8 @@ const uint3 gl_LocalInvocationID; const uint3 gl_GlobalInvocationID; const uint gl_LocalInvocationIndex; +} // namespace gl_ComputeShader + /** \} */ /* -------------------------------------------------------------------- */ -- 2.30.2 From 9f191c31f55ec564852e3566f95d4318dabab6b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Wed, 25 Sep 2024 12:16:07 +0200 Subject: [PATCH 31/38] Add compute shader functions --- source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index a849e6a845b..db38143d5ef 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -599,10 +599,12 @@ uint floatBitsToUint(double) RET; double intBitsToFloat(int) RET; double uintBitsToFloat(uint) RET; +namespace gl_FragmentShader { /* Derivative functions. */ template T dFdx(T) RET; template T dFdy(T) RET; template T fwidth(T) RET; +} // namespace gl_FragmentShader /* Geometric functions. */ template float faceforward(VecBase, VecBase, VecBase) RET; @@ -713,6 +715,15 @@ const uint gl_LocalInvocationIndex; /* Discards the output of the current fragment shader invocation and halts its execution. */ # define discard +namespace gl_ComputeShader { +void barrier() {} +void memoryBarrier() {} +void memoryBarrierShared() {} +void memoryBarrierImage() {} +void memoryBarrierBuffer() {} +void groupMemoryBarrier() {} +} // namespace gl_ComputeShader + /** \} */ /* -------------------------------------------------------------------- */ -- 2.30.2 From df5444967870728c0c73872d99be58efda67a88a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Thu, 26 Sep 2024 16:13:33 +0200 Subject: [PATCH 32/38] Add shared keyword --- source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index db38143d5ef..a65f8a59e21 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -715,6 +715,9 @@ const uint gl_LocalInvocationIndex; /* Discards the output of the current fragment shader invocation and halts its execution. */ # define discard +/* Decorate a variable in global scope that is common to all threads in a threadgroup. */ +# define shared + namespace gl_ComputeShader { void barrier() {} void memoryBarrier() {} -- 2.30.2 From 3017a7d6b645a6cbba9864c21ea0ff1a35af7dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Thu, 26 Sep 2024 16:25:46 +0200 Subject: [PATCH 33/38] Use references for swizzle (GCC compatible) and use single line. --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 86 +++++++------------ 1 file changed, 30 insertions(+), 56 deletions(-) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index a65f8a59e21..08d63cd6ae0 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -103,77 +103,51 @@ template struct VecOp { }; template struct VecSwizzle2 { - static VecBase xx, xy, yx, yy; - static VecBase xxx, xxy, xyx, xyy, yxx, yxy, yyx, yyy; - static VecBase xxxx, xxxy, xxyx, xxyy, xyxx, xyxy, xyyx, xyyy, yxxx, yxxy, yxyx, yxyy, - yyxx, yyxy, yyyx, yyyy; + /* clang-format off */ + static VecBase &xx, &xy, &yx, &yy; + static VecBase &xxx, &xxy, &xyx, &xyy, &yxx, &yxy, &yyx, &yyy; + static VecBase &xxxx, &xxxy, &xxyx, &xxyy, &xyxx, &xyxy, &xyyx, &xyyy, &yxxx, &yxxy, &yxyx, &yxyy, &yyxx, &yyxy, &yyyx, &yyyy; + /* clang-format on */ }; template struct ColSwizzle2 { - static VecBase rr, rg, gr, gg; - static VecBase rrr, rrg, rgr, rgg, grr, grg, ggr, ggg; - static VecBase rrrr, rrrg, rrgr, rrgg, rgrr, rgrg, rggr, rggg, grrr, grrg, grgr, grgg, - ggrr, ggrg, gggr, gggg; + /* clang-format off */ + static VecBase &rr, &rg, &gr, ≫ + static VecBase &rrr, &rrg, &rgr, &rgg, &grr, &grg, &ggr, ⋙ + static VecBase &rrrr, &rrrg, &rrgr, &rrgg, &rgrr, &rgrg, &rggr, &rggg, &grrr, &grrg, &grgr, &grgg, &ggrr, &ggrg, &gggr, &gggg; + /* clang-format on */ }; template struct VecSwizzle3 : VecSwizzle2 { - static VecBase xz, yz, zx, zy, zz, zw; - static VecBase xxz, xyz, xzx, xzy, xzz, yxz, yyz, yzx, yzy, yzz, zxx, zxy, zxz, zyx, zyy, - zyz, zzx, zzy, zzz; - static VecBase xxxz, xxyz, xxzx, xxzy, xxzz, xyxz, xyyz, xyzx, xyzy, xyzz, xzxx, xzxy, - xzxz, xzyx, xzyy, xzyz, xzzx, xzzy, xzzz, yxxz, yxyz, yxzx, yxzy, yxzz, yyxz, yyyz, yyzx, - yyzy, yyzz, yzxx, yzxy, yzxz, yzyx, yzyy, yzyz, yzzx, yzzy, yzzz, zxxx, zxxy, zxxz, zxyx, - zxyy, zxyz, zxzx, zxzy, zxzz, zyxx, zyxy, zyxz, zyyx, zyyy, zyyz, zyzx, zyzy, zyzz, zzxx, - zzxy, zzxz, zzyx, zzyy, zzyz, zzzx, zzzy, zzzz; + /* clang-format off */ + static VecBase &xz, &yz, &zx, &zy, &zz, &zw; + static VecBase &xxz, &xyz, &xzx, &xzy, &xzz, &yxz, &yyz, &yzx, &yzy, &yzz, &zxx, &zxy, &zxz, &zyx, &zyy, &zyz, &zzx, &zzy, &zzz; + static VecBase &xxxz, &xxyz, &xxzx, &xxzy, &xxzz, &xyxz, &xyyz, &xyzx, &xyzy, &xyzz, &xzxx, &xzxy, &xzxz, &xzyx, &xzyy, &xzyz, &xzzx, &xzzy, &xzzz, &yxxz, &yxyz, &yxzx, &yxzy, &yxzz, &yyxz, &yyyz, &yyzx, &yyzy, &yyzz, &yzxx, &yzxy, &yzxz, &yzyx, &yzyy, &yzyz, &yzzx, &yzzy, &yzzz, &zxxx, &zxxy, &zxxz, &zxyx, &zxyy, &zxyz, &zxzx, &zxzy, &zxzz, &zyxx, &zyxy, &zyxz, &zyyx, &zyyy, &zyyz, &zyzx, &zyzy, &zyzz, &zzxx, &zzxy, &zzxz, &zzyx, &zzyy, &zzyz, &zzzx, &zzzy, &zzzz; + /* clang-format on */ }; template struct ColSwizzle3 : ColSwizzle2 { - static VecBase rb, gb, br, bg, bb, bw; - static VecBase rrb, rgb, rbr, rbg, rbb, grb, ggb, gbr, gbg, gbb, brr, brg, brb, bgr, bgg, - bgb, bbr, bbg, bbb; - static VecBase rrrb, rrgb, rrbr, rrbg, rrbb, rgrb, rggb, rgbr, rgbg, rgbb, rbrr, rbrg, - rbrb, rbgr, rbgg, rbgb, rbbr, rbbg, rbbb, grrb, grgb, grbr, grbg, grbb, ggrb, gggb, ggbr, - ggbg, ggbb, gbrr, gbrg, gbrb, gbgr, gbgg, gbgb, gbbr, gbbg, gbbb, brrr, brrg, brrb, brgr, - brgg, brgb, brbr, brbg, brbb, bgrr, bgrg, bgrb, bggr, bggg, bggb, bgbr, bgbg, bgbb, bbrr, - bbrg, bbrb, bbgr, bbgg, bbgb, bbbr, bbbg, bbbb; + /* clang-format off */ + static VecBase &rb, &gb, &br, &bg, &bb, &bw; + static VecBase &rrb, &rgb, &rbr, &rbg, &rbb, &grb, &ggb, &gbr, &gbg, &gbb, &brr, &brg, &brb, &bgr, &bgg, &bgb, &bbr, &bbg, &bbb; + static VecBase &rrrb, &rrgb, &rrbr, &rrbg, &rrbb, &rgrb, &rggb, &rgbr, &rgbg, &rgbb, &rbrr, &rbrg, &rbrb, &rbgr, &rbgg, &rbgb, &rbbr, &rbbg, &rbbb, &grrb, &grgb, &grbr, &grbg, &grbb, &ggrb, &gggb, &ggbr, &ggbg, &ggbb, &gbrr, &gbrg, &gbrb, &gbgr, &gbgg, &gbgb, &gbbr, &gbbg, &gbbb, &brrr, &brrg, &brrb, &brgr, &brgg, &brgb, &brbr, &brbg, &brbb, &bgrr, &bgrg, &bgrb, &bggr, &bggg, &bggb, &bgbr, &bgbg, &bgbb, &bbrr, &bbrg, &bbrb, &bbgr, &bbgg, &bbgb, &bbbr, &bbbg, &bbbb; + /* clang-format on */ }; template struct VecSwizzle4 : VecSwizzle3 { - static VecBase xw, yw, wx, wy, wz, ww; - static VecBase xxw, xyw, xzw, xwx, xwy, xwz, xww, yxw, yyw, yzw, ywx, ywy, ywz, yww, zxw, - zyw, zzw, zwx, zwy, zwz, zww, wxx, wxy, wxz, wxw, wyx, wyy, wyz, wyw, wzx, wzy, wzz, wzw, - wwx, wwy, wwz, www; - static VecBase xxxw, xxyw, xxzw, xxwx, xxwy, xxwz, xxww, xyxw, xyyw, xyzw, xywx, xywy, - xywz, xyww, xzxw, xzyw, xzzw, xzwx, xzwy, xzwz, xzww, xwxx, xwxy, xwxz, xwxw, xwyx, xwyy, - xwyz, xwyw, xwzx, xwzy, xwzz, xwzw, xwwx, xwwy, xwwz, xwww, yxxw, yxyw, yxzw, yxwx, yxwy, - yxwz, yxww, yyxw, yyyw, yyzw, yywx, yywy, yywz, yyww, yzxw, yzyw, yzzw, yzwx, yzwy, yzwz, - yzww, ywxx, ywxy, ywxz, ywxw, ywyx, ywyy, ywyz, ywyw, ywzx, ywzy, ywzz, ywzw, ywwx, ywwy, - ywwz, ywww, zxxw, zxyw, zxzw, zxwx, zxwy, zxwz, zxww, zyxw, zyyw, zyzw, zywx, zywy, zywz, - zyww, zzxw, zzyw, zzzw, zzwx, zzwy, zzwz, zzww, zwxx, zwxy, zwxz, zwxw, zwyx, zwyy, zwyz, - zwyw, zwzx, zwzy, zwzz, zwzw, zwwx, zwwy, zwwz, zwww, wxxx, wxxy, wxxz, wxxw, wxyx, wxyy, - wxyz, wxyw, wxzx, wxzy, wxzz, wxzw, wxwx, wxwy, wxwz, wxww, wyxx, wyxy, wyxz, wyxw, wyyx, - wyyy, wyyz, wyyw, wyzx, wyzy, wyzz, wyzw, wywx, wywy, wywz, wyww, wzxx, wzxy, wzxz, wzxw, - wzyx, wzyy, wzyz, wzyw, wzzx, wzzy, wzzz, wzzw, wzwx, wzwy, wzwz, wzww, wwxx, wwxy, wwxz, - wwxw, wwyx, wwyy, wwyz, wwyw, wwzx, wwzy, wwzz, wwzw, wwwx, wwwy, wwwz, wwww; + /* clang-format off */ + static VecBase &xw, &yw, &wx, &wy, &wz, &ww; + static VecBase &xxw, &xyw, &xzw, &xwx, &xwy, &xwz, &xww, &yxw, &yyw, &yzw, &ywx, &ywy, &ywz, &yww, &zxw, &zyw, &zzw, &zwx, &zwy, &zwz, &zww, &wxx, &wxy, &wxz, &wxw, &wyx, &wyy, &wyz, &wyw, &wzx, &wzy, &wzz, &wzw, &wwx, &wwy, &wwz, &www; + static VecBase &xxxw, &xxyw, &xxzw, &xxwx, &xxwy, &xxwz, &xxww, &xyxw, &xyyw, &xyzw, &xywx, &xywy, &xywz, &xyww, &xzxw, &xzyw, &xzzw, &xzwx, &xzwy, &xzwz, &xzww, &xwxx, &xwxy, &xwxz, &xwxw, &xwyx, &xwyy, &xwyz, &xwyw, &xwzx, &xwzy, &xwzz, &xwzw, &xwwx, &xwwy, &xwwz, &xwww, &yxxw, &yxyw, &yxzw, &yxwx, &yxwy, &yxwz, &yxww, &yyxw, &yyyw, &yyzw, &yywx, &yywy, &yywz, &yyww, &yzxw, &yzyw, &yzzw, &yzwx, &yzwy, &yzwz, &yzww, &ywxx, &ywxy, &ywxz, &ywxw, &ywyx, &ywyy, &ywyz, &ywyw, &ywzx, &ywzy, &ywzz, &ywzw, &ywwx, &ywwy, &ywwz, &ywww, &zxxw, &zxyw, &zxzw, &zxwx, &zxwy, &zxwz, &zxww, &zyxw, &zyyw, &zyzw, &zywx, &zywy, &zywz, &zyww, &zzxw, &zzyw, &zzzw, &zzwx, &zzwy, &zzwz, &zzww, &zwxx, &zwxy, &zwxz, &zwxw, &zwyx, &zwyy, &zwyz, &zwyw, &zwzx, &zwzy, &zwzz, &zwzw, &zwwx, &zwwy, &zwwz, &zwww, &wxxx, &wxxy, &wxxz, &wxxw, &wxyx, &wxyy, &wxyz, &wxyw, &wxzx, &wxzy, &wxzz, &wxzw, &wxwx, &wxwy, &wxwz, &wxww, &wyxx, &wyxy, &wyxz, &wyxw, &wyyx, &wyyy, &wyyz, &wyyw, &wyzx, &wyzy, &wyzz, &wyzw, &wywx, &wywy, &wywz, &wyww, &wzxx, &wzxy, &wzxz, &wzxw, &wzyx, &wzyy, &wzyz, &wzyw, &wzzx, &wzzy, &wzzz, &wzzw, &wzwx, &wzwy, &wzwz, &wzww, &wwxx, &wwxy, &wwxz, &wwxw, &wwyx, &wwyy, &wwyz, &wwyw, &wwzx, &wwzy, &wwzz, &wwzw, &wwwx, &wwwy, &wwwz, &wwww; + /* clang-format on */ }; template struct ColSwizzle4 : ColSwizzle3 { - static VecBase ra, ga, ar, ag, ab, aa; - static VecBase rra, rga, rba, rar, rag, rab, raa, gra, gga, gba, gar, gag, gab, gaa, bra, - bga, bba, bar, bag, bab, baa, arr, arg, arb, ara, agr, agg, agb, aga, abr, abg, abb, aba, - aar, aag, aab, aaa; - static VecBase rrra, rrga, rrba, rrar, rrag, rrab, rraa, rgra, rgga, rgba, rgar, rgag, - rgab, rgaa, rbra, rbga, rbba, rbar, rbag, rbab, rbaa, rarr, rarg, rarb, rara, ragr, ragg, - ragb, raga, rabr, rabg, rabb, raba, raar, raag, raab, raaa, grra, grga, grba, grar, grag, - grab, graa, ggra, ggga, ggba, ggar, ggag, ggab, ggaa, gbra, gbga, gbba, gbar, gbag, gbab, - gbaa, garr, garg, garb, gara, gagr, gagg, gagb, gaga, gabr, gabg, gabb, gaba, gaar, gaag, - gaab, gaaa, brra, brga, brba, brar, brag, brab, braa, bgra, bgga, bgba, bgar, bgag, bgab, - bgaa, bbra, bbga, bbba, bbar, bbag, bbab, bbaa, barr, barg, barb, bara, bagr, bagg, bagb, - baga, babr, babg, babb, baba, baar, baag, baab, baaa, arrr, arrg, arrb, arra, argr, argg, - argb, arga, arbr, arbg, arbb, arba, arar, arag, arab, araa, agrr, agrg, agrb, agra, aggr, - aggg, aggb, agga, agbr, agbg, agbb, agba, agar, agag, agab, agaa, abrr, abrg, abrb, abra, - abgr, abgg, abgb, abga, abbr, abbg, abbb, abba, abar, abag, abab, abaa, aarr, aarg, aarb, - aara, aagr, aagg, aagb, aaga, aabr, aabg, aabb, aaba, aaar, aaag, aaab, aaaa; + /* clang-format off */ + static VecBase &ra, &ga, &ar, &ag, &ab, &aa; + static VecBase &rra, &rga, &rba, &rar, &rag, &rab, &raa, &gra, &gga, &gba, &gar, &gag, &gab, &gaa, &bra, &bga, &bba, &bar, &bag, &bab, &baa, &arr, &arg, &arb, &ara, &agr, &agg, &agb, &aga, &abr, &abg, &abb, &aba, &aar, &aag, &aab, &aaa; + static VecBase &rrra, &rrga, &rrba, &rrar, &rrag, &rrab, &rraa, &rgra, &rgga, &rgba, &rgar, &rgag, &rgab, &rgaa, &rbra, &rbga, &rbba, &rbar, &rbag, &rbab, &rbaa, &rarr, &rarg, &rarb, &rara, &ragr, &ragg, &ragb, &raga, &rabr, &rabg, &rabb, &raba, &raar, &raag, &raab, &raaa, &grra, &grga, &grba, &grar, &grag, &grab, &graa, &ggra, &ggga, &ggba, &ggar, &ggag, &ggab, &ggaa, &gbra, &gbga, &gbba, &gbar, &gbag, &gbab, &gbaa, &garr, &garg, &garb, &gara, &gagr, &gagg, &gagb, &gaga, &gabr, &gabg, &gabb, &gaba, &gaar, &gaag, &gaab, &gaaa, &brra, &brga, &brba, &brar, &brag, &brab, &braa, &bgra, &bgga, &bgba, &bgar, &bgag, &bgab, &bgaa, &bbra, &bbga, &bbba, &bbar, &bbag, &bbab, &bbaa, &barr, &barg, &barb, &bara, &bagr, &bagg, &bagb, &baga, &babr, &babg, &babb, &baba, &baar, &baag, &baab, &baaa, &arrr, &arrg, &arrb, &arra, &argr, &argg, &argb, &arga, &arbr, &arbg, &arbb, &arba, &arar, &arag, &arab, &araa, &agrr, &agrg, &agrb, &agra, &aggr, &aggg, &aggb, &agga, &agbr, &agbg, &agbb, &agba, &agar, &agag, &agab, &agaa, &abrr, &abrg, &abrb, &abra, &abgr, &abgg, &abgb, &abga, &abbr, &abbg, &abbb, &abba, &abar, &abag, &abab, &abaa, &aarr, &aarg, &aarb, &aara, &aagr, &aagg, &aagb, &aaga, &aabr, &aabg, &aabb, &aaba, &aaar, &aaag, &aaab, &aaaa; + /* clang-format on */ }; template struct VecBase : VecOp, VecSwizzle2, ColSwizzle2 { -- 2.30.2 From 9e8c2a9fe7579931a68abc6a75d5d53e302a7a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Thu, 26 Sep 2024 16:34:37 +0200 Subject: [PATCH 34/38] Remove GPU_SHADER guard as it won't get included for shader anymore --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 66 +++++++++---------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index 08d63cd6ae0..cd18d4e4c2d 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -28,9 +28,7 @@ #pragma once -#ifndef GPU_SHADER - -# include +#include /* -------------------------------------------------------------------- */ /** \name Vector Types @@ -71,8 +69,8 @@ template struct VecOp { friend VecT operator/(T, VecT) {} friend VecT operator*(T, VecT) {} -# define INT_OP \ - template> * = nullptr> +#define INT_OP \ + template> * = nullptr> INT_OP VecT operator%(VecT) const {} INT_OP VecT operator&(VecT) const {} @@ -99,7 +97,7 @@ template struct VecOp { INT_OP friend VecT operator|(T, VecT) {} INT_OP friend VecT operator^(T, VecT) {} -# undef INT_OP +#undef INT_OP }; template struct VecSwizzle2 { @@ -355,13 +353,13 @@ template stru using size_vec_type = VecBase; }; -# define TEX_TEMPLATE \ - template +#define TEX_TEMPLATE \ + template TEX_TEMPLATE SizeVec textureSize(T, int) {} TEX_TEMPLATE DataVec texelFetch(T, IntCoord, int) {} @@ -371,7 +369,7 @@ TEX_TEMPLATE DataVec textureGather(T, FltCoord) {} TEX_TEMPLATE DataVec textureGrad(T, FltCoord, DerivVec, DerivVec) {} TEX_TEMPLATE DataVec textureLod(T, FltCoord, double) {} -# undef TEX_TEMPLATE +#undef TEX_TEMPLATE using sampler1D = SamplerBase; using sampler2D = SamplerBase; @@ -412,18 +410,18 @@ template struct ImageBase { using size_vec_type = VecBase; }; -# define IMG_TEMPLATE \ - template +#define IMG_TEMPLATE \ + template IMG_TEMPLATE SizeVec imageSize(T) {} IMG_TEMPLATE DataVec imageLoad(T, IntCoord) {} IMG_TEMPLATE void imageStore(T, IntCoord, DataVec) {} IMG_TEMPLATE void imageFence(T) {} -# define imageLoadFast imageLoad -# define imageStoreFast imageStore +#define imageLoadFast imageLoad +#define imageStoreFast imageStore IMG_TEMPLATE uint imageAtomicAdd(T, IntCoord, uint); IMG_TEMPLATE uint imageAtomicMin(T, IntCoord, uint); @@ -433,7 +431,7 @@ IMG_TEMPLATE uint imageAtomicXor(T, IntCoord, uint); IMG_TEMPLATE uint imageAtomicExchange(T, IntCoord, uint); IMG_TEMPLATE uint imageAtomicCompSwap(T, IntCoord, uint, uint); -# undef IMG_TEMPLATE +#undef IMG_TEMPLATE using image1D = ImageBase; using image2D = ImageBase; @@ -461,10 +459,10 @@ using uimage2DArray = ImageBase; * \{ */ /* Some compilers complain about lack of return values. Keep it short. */ -# define RET \ - { \ - return {}; \ - } +#define RET \ + { \ + return {}; \ + } template VecBase greaterThan(VecBase, VecBase) RET; template VecBase lessThan(VecBase, VecBase) RET; @@ -556,7 +554,7 @@ double mix(double, double, double) RET; template VecBase mix(VecBase, VecBase, double) RET; template VecBase mix(VecBase, VecBase, VecBase) RET; -# define select(A, B, C) mix(A, B, C) +#define select(A, B, C) mix(A, B, C) VecBase cross(VecBase, VecBase) RET; template float dot(VecBase, VecBase) RET; @@ -625,7 +623,7 @@ bool is_zero(vec2) RET; bool is_zero(vec3) RET; bool is_zero(vec4) RET; -# undef RET +#undef RET /** \} */ @@ -680,17 +678,17 @@ const uint gl_LocalInvocationIndex; /* Note: Cannot easily mutate them. Pass every by copy for now. */ /* Pass argument by reference. */ -# define inout +#define inout /* Pass argument by reference but only write to it. Its initial value is undefined. */ -# define out +#define out /* Pass argument by copy (default). */ -# define in +#define in /* Discards the output of the current fragment shader invocation and halts its execution. */ -# define discard +#define discard /* Decorate a variable in global scope that is common to all threads in a threadgroup. */ -# define shared +#define shared namespace gl_ComputeShader { void barrier() {} @@ -728,5 +726,3 @@ void groupMemoryBarrier() {} /* clang-format on */ /** \} */ - -#endif -- 2.30.2 From d00d870cf8513b705d49a865ba19731abd55e77d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Thu, 26 Sep 2024 16:43:34 +0200 Subject: [PATCH 35/38] Add shader shared --- source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index cd18d4e4c2d..8601668b732 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -726,3 +726,13 @@ void groupMemoryBarrier() {} /* clang-format on */ /** \} */ + +/* Include all shader shared files to that custom type definitions are available when create infos + * macros are included. */ +#include "GPU_shader_shared.hh" +#include "draw_common_shader_shared.hh" +#include "draw_shader_shared.hh" +#include "eevee_shader_shared.hh" +#include "overlay_shader_shared.h" +#include "select_shader_shared.hh" +#include "workbench_shader_shared.h" -- 2.30.2 From 052c1fe354910946903b77db46f24e0abc9e57e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Thu, 26 Sep 2024 16:46:30 +0200 Subject: [PATCH 36/38] Remove clang-format off for swizzle --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 76 +++++++++++++------ 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index 8601668b732..e6912269fb1 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -101,51 +101,83 @@ template struct VecOp { }; template struct VecSwizzle2 { - /* clang-format off */ static VecBase &xx, &xy, &yx, &yy; static VecBase &xxx, &xxy, &xyx, &xyy, &yxx, &yxy, &yyx, &yyy; - static VecBase &xxxx, &xxxy, &xxyx, &xxyy, &xyxx, &xyxy, &xyyx, &xyyy, &yxxx, &yxxy, &yxyx, &yxyy, &yyxx, &yyxy, &yyyx, &yyyy; - /* clang-format on */ + static VecBase &xxxx, &xxxy, &xxyx, &xxyy, &xyxx, &xyxy, &xyyx, &xyyy, &yxxx, &yxxy, &yxyx, + &yxyy, &yyxx, &yyxy, &yyyx, &yyyy; }; template struct ColSwizzle2 { - /* clang-format off */ static VecBase &rr, &rg, &gr, ≫ static VecBase &rrr, &rrg, &rgr, &rgg, &grr, &grg, &ggr, ⋙ - static VecBase &rrrr, &rrrg, &rrgr, &rrgg, &rgrr, &rgrg, &rggr, &rggg, &grrr, &grrg, &grgr, &grgg, &ggrr, &ggrg, &gggr, &gggg; - /* clang-format on */ + static VecBase &rrrr, &rrrg, &rrgr, &rrgg, &rgrr, &rgrg, &rggr, &rggg, &grrr, &grrg, &grgr, + &grgg, &ggrr, &ggrg, &gggr, &gggg; }; template struct VecSwizzle3 : VecSwizzle2 { - /* clang-format off */ static VecBase &xz, &yz, &zx, &zy, &zz, &zw; - static VecBase &xxz, &xyz, &xzx, &xzy, &xzz, &yxz, &yyz, &yzx, &yzy, &yzz, &zxx, &zxy, &zxz, &zyx, &zyy, &zyz, &zzx, &zzy, &zzz; - static VecBase &xxxz, &xxyz, &xxzx, &xxzy, &xxzz, &xyxz, &xyyz, &xyzx, &xyzy, &xyzz, &xzxx, &xzxy, &xzxz, &xzyx, &xzyy, &xzyz, &xzzx, &xzzy, &xzzz, &yxxz, &yxyz, &yxzx, &yxzy, &yxzz, &yyxz, &yyyz, &yyzx, &yyzy, &yyzz, &yzxx, &yzxy, &yzxz, &yzyx, &yzyy, &yzyz, &yzzx, &yzzy, &yzzz, &zxxx, &zxxy, &zxxz, &zxyx, &zxyy, &zxyz, &zxzx, &zxzy, &zxzz, &zyxx, &zyxy, &zyxz, &zyyx, &zyyy, &zyyz, &zyzx, &zyzy, &zyzz, &zzxx, &zzxy, &zzxz, &zzyx, &zzyy, &zzyz, &zzzx, &zzzy, &zzzz; - /* clang-format on */ + static VecBase &xxz, &xyz, &xzx, &xzy, &xzz, &yxz, &yyz, &yzx, &yzy, &yzz, &zxx, &zxy, + &zxz, &zyx, &zyy, &zyz, &zzx, &zzy, &zzz; + static VecBase &xxxz, &xxyz, &xxzx, &xxzy, &xxzz, &xyxz, &xyyz, &xyzx, &xyzy, &xyzz, &xzxx, + &xzxy, &xzxz, &xzyx, &xzyy, &xzyz, &xzzx, &xzzy, &xzzz, &yxxz, &yxyz, &yxzx, &yxzy, &yxzz, + &yyxz, &yyyz, &yyzx, &yyzy, &yyzz, &yzxx, &yzxy, &yzxz, &yzyx, &yzyy, &yzyz, &yzzx, &yzzy, + &yzzz, &zxxx, &zxxy, &zxxz, &zxyx, &zxyy, &zxyz, &zxzx, &zxzy, &zxzz, &zyxx, &zyxy, &zyxz, + &zyyx, &zyyy, &zyyz, &zyzx, &zyzy, &zyzz, &zzxx, &zzxy, &zzxz, &zzyx, &zzyy, &zzyz, &zzzx, + &zzzy, &zzzz; }; template struct ColSwizzle3 : ColSwizzle2 { - /* clang-format off */ static VecBase &rb, &gb, &br, &bg, &bb, &bw; - static VecBase &rrb, &rgb, &rbr, &rbg, &rbb, &grb, &ggb, &gbr, &gbg, &gbb, &brr, &brg, &brb, &bgr, &bgg, &bgb, &bbr, &bbg, &bbb; - static VecBase &rrrb, &rrgb, &rrbr, &rrbg, &rrbb, &rgrb, &rggb, &rgbr, &rgbg, &rgbb, &rbrr, &rbrg, &rbrb, &rbgr, &rbgg, &rbgb, &rbbr, &rbbg, &rbbb, &grrb, &grgb, &grbr, &grbg, &grbb, &ggrb, &gggb, &ggbr, &ggbg, &ggbb, &gbrr, &gbrg, &gbrb, &gbgr, &gbgg, &gbgb, &gbbr, &gbbg, &gbbb, &brrr, &brrg, &brrb, &brgr, &brgg, &brgb, &brbr, &brbg, &brbb, &bgrr, &bgrg, &bgrb, &bggr, &bggg, &bggb, &bgbr, &bgbg, &bgbb, &bbrr, &bbrg, &bbrb, &bbgr, &bbgg, &bbgb, &bbbr, &bbbg, &bbbb; - /* clang-format on */ + static VecBase &rrb, &rgb, &rbr, &rbg, &rbb, &grb, &ggb, &gbr, &gbg, &gbb, &brr, &brg, + &brb, &bgr, &bgg, &bgb, &bbr, &bbg, &bbb; + static VecBase &rrrb, &rrgb, &rrbr, &rrbg, &rrbb, &rgrb, &rggb, &rgbr, &rgbg, &rgbb, &rbrr, + &rbrg, &rbrb, &rbgr, &rbgg, &rbgb, &rbbr, &rbbg, &rbbb, &grrb, &grgb, &grbr, &grbg, &grbb, + &ggrb, &gggb, &ggbr, &ggbg, &ggbb, &gbrr, &gbrg, &gbrb, &gbgr, &gbgg, &gbgb, &gbbr, &gbbg, + &gbbb, &brrr, &brrg, &brrb, &brgr, &brgg, &brgb, &brbr, &brbg, &brbb, &bgrr, &bgrg, &bgrb, + &bggr, &bggg, &bggb, &bgbr, &bgbg, &bgbb, &bbrr, &bbrg, &bbrb, &bbgr, &bbgg, &bbgb, &bbbr, + &bbbg, &bbbb; }; template struct VecSwizzle4 : VecSwizzle3 { - /* clang-format off */ static VecBase &xw, &yw, &wx, &wy, &wz, &ww; - static VecBase &xxw, &xyw, &xzw, &xwx, &xwy, &xwz, &xww, &yxw, &yyw, &yzw, &ywx, &ywy, &ywz, &yww, &zxw, &zyw, &zzw, &zwx, &zwy, &zwz, &zww, &wxx, &wxy, &wxz, &wxw, &wyx, &wyy, &wyz, &wyw, &wzx, &wzy, &wzz, &wzw, &wwx, &wwy, &wwz, &www; - static VecBase &xxxw, &xxyw, &xxzw, &xxwx, &xxwy, &xxwz, &xxww, &xyxw, &xyyw, &xyzw, &xywx, &xywy, &xywz, &xyww, &xzxw, &xzyw, &xzzw, &xzwx, &xzwy, &xzwz, &xzww, &xwxx, &xwxy, &xwxz, &xwxw, &xwyx, &xwyy, &xwyz, &xwyw, &xwzx, &xwzy, &xwzz, &xwzw, &xwwx, &xwwy, &xwwz, &xwww, &yxxw, &yxyw, &yxzw, &yxwx, &yxwy, &yxwz, &yxww, &yyxw, &yyyw, &yyzw, &yywx, &yywy, &yywz, &yyww, &yzxw, &yzyw, &yzzw, &yzwx, &yzwy, &yzwz, &yzww, &ywxx, &ywxy, &ywxz, &ywxw, &ywyx, &ywyy, &ywyz, &ywyw, &ywzx, &ywzy, &ywzz, &ywzw, &ywwx, &ywwy, &ywwz, &ywww, &zxxw, &zxyw, &zxzw, &zxwx, &zxwy, &zxwz, &zxww, &zyxw, &zyyw, &zyzw, &zywx, &zywy, &zywz, &zyww, &zzxw, &zzyw, &zzzw, &zzwx, &zzwy, &zzwz, &zzww, &zwxx, &zwxy, &zwxz, &zwxw, &zwyx, &zwyy, &zwyz, &zwyw, &zwzx, &zwzy, &zwzz, &zwzw, &zwwx, &zwwy, &zwwz, &zwww, &wxxx, &wxxy, &wxxz, &wxxw, &wxyx, &wxyy, &wxyz, &wxyw, &wxzx, &wxzy, &wxzz, &wxzw, &wxwx, &wxwy, &wxwz, &wxww, &wyxx, &wyxy, &wyxz, &wyxw, &wyyx, &wyyy, &wyyz, &wyyw, &wyzx, &wyzy, &wyzz, &wyzw, &wywx, &wywy, &wywz, &wyww, &wzxx, &wzxy, &wzxz, &wzxw, &wzyx, &wzyy, &wzyz, &wzyw, &wzzx, &wzzy, &wzzz, &wzzw, &wzwx, &wzwy, &wzwz, &wzww, &wwxx, &wwxy, &wwxz, &wwxw, &wwyx, &wwyy, &wwyz, &wwyw, &wwzx, &wwzy, &wwzz, &wwzw, &wwwx, &wwwy, &wwwz, &wwww; - /* clang-format on */ + static VecBase &xxw, &xyw, &xzw, &xwx, &xwy, &xwz, &xww, &yxw, &yyw, &yzw, &ywx, &ywy, + &ywz, &yww, &zxw, &zyw, &zzw, &zwx, &zwy, &zwz, &zww, &wxx, &wxy, &wxz, &wxw, &wyx, &wyy, + &wyz, &wyw, &wzx, &wzy, &wzz, &wzw, &wwx, &wwy, &wwz, &www; + static VecBase &xxxw, &xxyw, &xxzw, &xxwx, &xxwy, &xxwz, &xxww, &xyxw, &xyyw, &xyzw, &xywx, + &xywy, &xywz, &xyww, &xzxw, &xzyw, &xzzw, &xzwx, &xzwy, &xzwz, &xzww, &xwxx, &xwxy, &xwxz, + &xwxw, &xwyx, &xwyy, &xwyz, &xwyw, &xwzx, &xwzy, &xwzz, &xwzw, &xwwx, &xwwy, &xwwz, &xwww, + &yxxw, &yxyw, &yxzw, &yxwx, &yxwy, &yxwz, &yxww, &yyxw, &yyyw, &yyzw, &yywx, &yywy, &yywz, + &yyww, &yzxw, &yzyw, &yzzw, &yzwx, &yzwy, &yzwz, &yzww, &ywxx, &ywxy, &ywxz, &ywxw, &ywyx, + &ywyy, &ywyz, &ywyw, &ywzx, &ywzy, &ywzz, &ywzw, &ywwx, &ywwy, &ywwz, &ywww, &zxxw, &zxyw, + &zxzw, &zxwx, &zxwy, &zxwz, &zxww, &zyxw, &zyyw, &zyzw, &zywx, &zywy, &zywz, &zyww, &zzxw, + &zzyw, &zzzw, &zzwx, &zzwy, &zzwz, &zzww, &zwxx, &zwxy, &zwxz, &zwxw, &zwyx, &zwyy, &zwyz, + &zwyw, &zwzx, &zwzy, &zwzz, &zwzw, &zwwx, &zwwy, &zwwz, &zwww, &wxxx, &wxxy, &wxxz, &wxxw, + &wxyx, &wxyy, &wxyz, &wxyw, &wxzx, &wxzy, &wxzz, &wxzw, &wxwx, &wxwy, &wxwz, &wxww, &wyxx, + &wyxy, &wyxz, &wyxw, &wyyx, &wyyy, &wyyz, &wyyw, &wyzx, &wyzy, &wyzz, &wyzw, &wywx, &wywy, + &wywz, &wyww, &wzxx, &wzxy, &wzxz, &wzxw, &wzyx, &wzyy, &wzyz, &wzyw, &wzzx, &wzzy, &wzzz, + &wzzw, &wzwx, &wzwy, &wzwz, &wzww, &wwxx, &wwxy, &wwxz, &wwxw, &wwyx, &wwyy, &wwyz, &wwyw, + &wwzx, &wwzy, &wwzz, &wwzw, &wwwx, &wwwy, &wwwz, &wwww; }; template struct ColSwizzle4 : ColSwizzle3 { - /* clang-format off */ static VecBase &ra, &ga, &ar, &ag, &ab, &aa; - static VecBase &rra, &rga, &rba, &rar, &rag, &rab, &raa, &gra, &gga, &gba, &gar, &gag, &gab, &gaa, &bra, &bga, &bba, &bar, &bag, &bab, &baa, &arr, &arg, &arb, &ara, &agr, &agg, &agb, &aga, &abr, &abg, &abb, &aba, &aar, &aag, &aab, &aaa; - static VecBase &rrra, &rrga, &rrba, &rrar, &rrag, &rrab, &rraa, &rgra, &rgga, &rgba, &rgar, &rgag, &rgab, &rgaa, &rbra, &rbga, &rbba, &rbar, &rbag, &rbab, &rbaa, &rarr, &rarg, &rarb, &rara, &ragr, &ragg, &ragb, &raga, &rabr, &rabg, &rabb, &raba, &raar, &raag, &raab, &raaa, &grra, &grga, &grba, &grar, &grag, &grab, &graa, &ggra, &ggga, &ggba, &ggar, &ggag, &ggab, &ggaa, &gbra, &gbga, &gbba, &gbar, &gbag, &gbab, &gbaa, &garr, &garg, &garb, &gara, &gagr, &gagg, &gagb, &gaga, &gabr, &gabg, &gabb, &gaba, &gaar, &gaag, &gaab, &gaaa, &brra, &brga, &brba, &brar, &brag, &brab, &braa, &bgra, &bgga, &bgba, &bgar, &bgag, &bgab, &bgaa, &bbra, &bbga, &bbba, &bbar, &bbag, &bbab, &bbaa, &barr, &barg, &barb, &bara, &bagr, &bagg, &bagb, &baga, &babr, &babg, &babb, &baba, &baar, &baag, &baab, &baaa, &arrr, &arrg, &arrb, &arra, &argr, &argg, &argb, &arga, &arbr, &arbg, &arbb, &arba, &arar, &arag, &arab, &araa, &agrr, &agrg, &agrb, &agra, &aggr, &aggg, &aggb, &agga, &agbr, &agbg, &agbb, &agba, &agar, &agag, &agab, &agaa, &abrr, &abrg, &abrb, &abra, &abgr, &abgg, &abgb, &abga, &abbr, &abbg, &abbb, &abba, &abar, &abag, &abab, &abaa, &aarr, &aarg, &aarb, &aara, &aagr, &aagg, &aagb, &aaga, &aabr, &aabg, &aabb, &aaba, &aaar, &aaag, &aaab, &aaaa; - /* clang-format on */ + static VecBase &rra, &rga, &rba, &rar, &rag, &rab, &raa, &gra, &gga, &gba, &gar, &gag, + &gab, &gaa, &bra, &bga, &bba, &bar, &bag, &bab, &baa, &arr, &arg, &arb, &ara, &agr, &agg, + &agb, &aga, &abr, &abg, &abb, &aba, &aar, &aag, &aab, &aaa; + static VecBase &rrra, &rrga, &rrba, &rrar, &rrag, &rrab, &rraa, &rgra, &rgga, &rgba, &rgar, + &rgag, &rgab, &rgaa, &rbra, &rbga, &rbba, &rbar, &rbag, &rbab, &rbaa, &rarr, &rarg, &rarb, + &rara, &ragr, &ragg, &ragb, &raga, &rabr, &rabg, &rabb, &raba, &raar, &raag, &raab, &raaa, + &grra, &grga, &grba, &grar, &grag, &grab, &graa, &ggra, &ggga, &ggba, &ggar, &ggag, &ggab, + &ggaa, &gbra, &gbga, &gbba, &gbar, &gbag, &gbab, &gbaa, &garr, &garg, &garb, &gara, &gagr, + &gagg, &gagb, &gaga, &gabr, &gabg, &gabb, &gaba, &gaar, &gaag, &gaab, &gaaa, &brra, &brga, + &brba, &brar, &brag, &brab, &braa, &bgra, &bgga, &bgba, &bgar, &bgag, &bgab, &bgaa, &bbra, + &bbga, &bbba, &bbar, &bbag, &bbab, &bbaa, &barr, &barg, &barb, &bara, &bagr, &bagg, &bagb, + &baga, &babr, &babg, &babb, &baba, &baar, &baag, &baab, &baaa, &arrr, &arrg, &arrb, &arra, + &argr, &argg, &argb, &arga, &arbr, &arbg, &arbb, &arba, &arar, &arag, &arab, &araa, &agrr, + &agrg, &agrb, &agra, &aggr, &aggg, &aggb, &agga, &agbr, &agbg, &agbb, &agba, &agar, &agag, + &agab, &agaa, &abrr, &abrg, &abrb, &abra, &abgr, &abgg, &abgb, &abga, &abbr, &abbg, &abbb, + &abba, &abar, &abag, &abab, &abaa, &aarr, &aarg, &aarb, &aara, &aagr, &aagg, &aagb, &aaga, + &aabr, &aabg, &aabb, &aaba, &aaar, &aaag, &aaab, &aaaa; }; template struct VecBase : VecOp, VecSwizzle2, ColSwizzle2 { -- 2.30.2 From e145811e71791401e4c5f6cc2a5fe2cf86d35b7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Thu, 26 Sep 2024 17:04:47 +0200 Subject: [PATCH 37/38] Add shared declarations and avoid GPU_shader_shared_utils to mess with stubs --- source/blender/gpu/GPU_shader_shared_utils.hh | 4 +++- source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/source/blender/gpu/GPU_shader_shared_utils.hh b/source/blender/gpu/GPU_shader_shared_utils.hh index 5fe801e44e1..244d877c57e 100644 --- a/source/blender/gpu/GPU_shader_shared_utils.hh +++ b/source/blender/gpu/GPU_shader_shared_utils.hh @@ -28,7 +28,9 @@ * NOTE: You can use bool type using bool32_t a int boolean type matching the GLSL type. */ -#ifdef GPU_SHADER +#ifdef GLSL_CPP_STUBS +/* Do nothing. */ +#elif defined(GPU_SHADER) /* Silence macros when compiling for shaders. */ # define BLI_STATIC_ASSERT(cond, msg) # define BLI_STATIC_ASSERT_ALIGN(type_, align_) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index e6912269fb1..ddebc382bb3 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -759,8 +759,10 @@ void groupMemoryBarrier() {} /** \} */ +#define GLSL_CPP_STUBS + /* Include all shader shared files to that custom type definitions are available when create infos - * macros are included. */ + * macros are included. Include them here so that only including this file is needed. */ #include "GPU_shader_shared.hh" #include "draw_common_shader_shared.hh" #include "draw_shader_shared.hh" @@ -768,3 +770,6 @@ void groupMemoryBarrier() {} #include "overlay_shader_shared.h" #include "select_shader_shared.hh" #include "workbench_shader_shared.h" + +/* TODO(fclem): Include all create infos here so that they don't need to be individually included + * inside shaders. */ -- 2.30.2 From cc5c7ce829d9f3b204c27b0aca15179c1a78870f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Thu, 26 Sep 2024 21:29:03 +0200 Subject: [PATCH 38/38] Add const correctness to image write functions --- .../blender/gpu/shaders/gpu_glsl_cpp_stubs.hh | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh index ddebc382bb3..7be05bcaf47 100644 --- a/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh +++ b/source/blender/gpu/shaders/gpu_glsl_cpp_stubs.hh @@ -448,20 +448,32 @@ template struct ImageBase { typename DataVec = typename T::data_vec_type, \ typename SizeVec = typename T::size_vec_type> -IMG_TEMPLATE SizeVec imageSize(T) {} -IMG_TEMPLATE DataVec imageLoad(T, IntCoord) {} -IMG_TEMPLATE void imageStore(T, IntCoord, DataVec) {} -IMG_TEMPLATE void imageFence(T) {} +IMG_TEMPLATE SizeVec imageSize(const T &) {} +IMG_TEMPLATE DataVec imageLoad(const T &, IntCoord) {} +IMG_TEMPLATE void imageStore(T &, IntCoord, DataVec) {} +IMG_TEMPLATE void imageFence(T &) {} +/* Cannot write to a read only image. */ +IMG_TEMPLATE void imageStore(const T &, IntCoord, DataVec) = delete; +IMG_TEMPLATE void imageFence(const T &) = delete; + #define imageLoadFast imageLoad #define imageStoreFast imageStore -IMG_TEMPLATE uint imageAtomicAdd(T, IntCoord, uint); -IMG_TEMPLATE uint imageAtomicMin(T, IntCoord, uint); -IMG_TEMPLATE uint imageAtomicMax(T, IntCoord, uint); -IMG_TEMPLATE uint imageAtomicAnd(T, IntCoord, uint); -IMG_TEMPLATE uint imageAtomicXor(T, IntCoord, uint); -IMG_TEMPLATE uint imageAtomicExchange(T, IntCoord, uint); -IMG_TEMPLATE uint imageAtomicCompSwap(T, IntCoord, uint, uint); +IMG_TEMPLATE uint imageAtomicAdd(T &, IntCoord, uint) {} +IMG_TEMPLATE uint imageAtomicMin(T &, IntCoord, uint) {} +IMG_TEMPLATE uint imageAtomicMax(T &, IntCoord, uint) {} +IMG_TEMPLATE uint imageAtomicAnd(T &, IntCoord, uint) {} +IMG_TEMPLATE uint imageAtomicXor(T &, IntCoord, uint) {} +IMG_TEMPLATE uint imageAtomicExchange(T &, IntCoord, uint) {} +IMG_TEMPLATE uint imageAtomicCompSwap(T &, IntCoord, uint, uint) {} +/* Cannot write to a read only image. */ +IMG_TEMPLATE uint imageAtomicAdd(const T &, IntCoord, uint) = delete; +IMG_TEMPLATE uint imageAtomicMin(const T &, IntCoord, uint) = delete; +IMG_TEMPLATE uint imageAtomicMax(const T &, IntCoord, uint) = delete; +IMG_TEMPLATE uint imageAtomicAnd(const T &, IntCoord, uint) = delete; +IMG_TEMPLATE uint imageAtomicXor(const T &, IntCoord, uint) = delete; +IMG_TEMPLATE uint imageAtomicExchange(const T &, IntCoord, uint) = delete; +IMG_TEMPLATE uint imageAtomicCompSwap(const T &, IntCoord, uint, uint) = delete; #undef IMG_TEMPLATE -- 2.30.2