1// Reduced set of intrinsics that are available to public SkSL (RuntimeEffect and Interpreter) 2 3// See "The OpenGL ES Shading Language, Section 8" 4 5// 8.1 : Angle and Trigonometry Functions 6$genType radians($genType degrees); 7$genHType radians($genHType degrees); 8$genType degrees($genType radians); 9$genHType degrees($genHType radians); 10 11$genType sin($genType angle); 12$genHType sin($genHType angle); 13$genType cos($genType angle); 14$genHType cos($genHType angle); 15$genType tan($genType angle); 16$genHType tan($genHType angle); 17 18$genType asin($genType x); 19$genHType asin($genHType x); 20$genType acos($genType x); 21$genHType acos($genHType x); 22$genType atan($genType y, $genType x); 23$genHType atan($genHType y, $genHType x); 24$genType atan($genType y_over_x); 25$genHType atan($genHType y_over_x); 26 27// 8.1 : Angle and Trigonometry Functions (GLSL ES 3.0) 28$es3 $genType sinh($genType x); 29$es3 $genHType sinh($genHType x); 30$es3 $genType cosh($genType x); 31$es3 $genHType cosh($genHType x); 32$es3 $genType tanh($genType x); 33$es3 $genHType tanh($genHType x); 34$es3 $genType asinh($genType x); 35$es3 $genHType asinh($genHType x); 36$es3 $genType acosh($genType x); 37$es3 $genHType acosh($genHType x); 38$es3 $genType atanh($genType x); 39$es3 $genHType atanh($genHType x); 40 41// 8.2 : Exponential Functions 42$genType pow($genType x, $genType y); 43$genHType pow($genHType x, $genHType y); 44$genType exp($genType x); 45$genHType exp($genHType x); 46$genType log($genType x); 47$genHType log($genHType x); 48$genType exp2($genType x); 49$genHType exp2($genHType x); 50$genType log2($genType x); 51$genHType log2($genHType x); 52 53$genType sqrt($genType x); 54$genHType sqrt($genHType x); 55$genType inversesqrt($genType x); 56$genHType inversesqrt($genHType x); 57 58// 8.3 : Common Functions 59$genType abs($genType x); 60$genHType abs($genHType x); 61$genType sign($genType x); 62$genHType sign($genHType x); 63$genType floor($genType x); 64$genHType floor($genHType x); 65$genType ceil($genType x); 66$genHType ceil($genHType x); 67$genType fract($genType x); 68$genHType fract($genHType x); 69$genType mod($genType x, float y); 70$genType mod($genType x, $genType y); 71$genHType mod($genHType x, half y); 72$genHType mod($genHType x, $genHType y); 73 74$genType min($genType x, $genType y); 75$genType min($genType x, float y); 76$genHType min($genHType x, $genHType y); 77$genHType min($genHType x, half y); 78$genType max($genType x, $genType y); 79$genType max($genType x, float y); 80$genHType max($genHType x, $genHType y); 81$genHType max($genHType x, half y); 82$genType clamp($genType x, $genType minVal, $genType maxVal); 83$genType clamp($genType x, float minVal, float maxVal); 84$genHType clamp($genHType x, $genHType minVal, $genHType maxVal); 85$genHType clamp($genHType x, half minVal, half maxVal); 86$genType saturate($genType x); // SkSL extension 87$genHType saturate($genHType x); // SkSL extension 88$genType mix($genType x, $genType y, $genType a); 89$genType mix($genType x, $genType y, float a); 90$genHType mix($genHType x, $genHType y, $genHType a); 91$genHType mix($genHType x, $genHType y, half a); 92$genType step($genType edge, $genType x); 93$genType step(float edge, $genType x); 94$genHType step($genHType edge, $genHType x); 95$genHType step(half edge, $genHType x); 96$genType smoothstep($genType edge0, $genType edge1, $genType x); 97$genType smoothstep(float edge0, float edge1, $genType x); 98$genHType smoothstep($genHType edge0, $genHType edge1, $genHType x); 99$genHType smoothstep(half edge0, half edge1, $genHType x); 100 101// 8.3 : Common Functions (GLSL ES 3.0) 102$es3 $genIType floatBitsToInt ($genType value); 103$es3 $genUType floatBitsToUint($genType value); 104$es3 $genType intBitsToFloat ($genIType value); 105$es3 $genType uintBitsToFloat($genUType value); 106$es3 $genType trunc($genType x); 107$es3 $genHType trunc($genHType x); 108$es3 $genType round($genType x); 109$es3 $genHType round($genHType x); 110$es3 $genType roundEven($genType x); 111$es3 $genHType roundEven($genHType x); 112$es3 $genIType min($genIType x, $genIType y); 113$es3 $genIType min($genIType x, int y); 114$es3 $genIType max($genIType x, $genIType y); 115$es3 $genIType max($genIType x, int y); 116$es3 $genIType clamp($genIType x, $genIType minVal, $genIType maxVal); 117$es3 $genIType clamp($genIType x, int minVal, int maxVal); 118$es3 $genUType clamp($genUType x, $genUType minVal, $genUType maxVal); 119$es3 $genUType clamp($genUType x, uint minVal, uint maxVal); 120$es3 $genType mix($genType x, $genType y, $genBType a); 121$es3 $genHType mix($genHType x, $genHType y, $genBType a); 122 123// 8.3 : Common Functions (GLSL ES 3.0) -- cannot be used in constant-expressions 124$es3 $genBType isnan($genType x); 125$es3 $genBType isnan($genHType x); 126$es3 $genBType isinf($genType x); 127$es3 $genBType isinf($genHType x); 128$es3 $genType modf($genType x, out $genType i); 129$es3 $genHType modf($genHType x, out $genHType i); 130 131// 8.4 : Floating-Point Pack and Unpack Functions (GLSL ES 3.0) 132$es3 uint packUnorm2x16(float2 v); 133$es3 float2 unpackUnorm2x16(uint p); 134 135// 8.5 : Geometric Functions 136float length($genType x); 137half length($genHType x); 138float distance($genType p0, $genType p1); 139half distance($genHType p0, $genHType p1); 140float dot($genType x, $genType y); 141half dot($genHType x, $genHType y); 142float3 cross(float3 x, float3 y); 143half3 cross(half3 x, half3 y); 144$genType normalize($genType x); 145$genHType normalize($genHType x); 146$genType faceforward($genType N, $genType I, $genType Nref); 147$genHType faceforward($genHType N, $genHType I, $genHType Nref); 148$genType reflect($genType I, $genType N); 149$genHType reflect($genHType I, $genHType N); 150$genType refract($genType I, $genType N, float eta); 151$genHType refract($genHType I, $genHType N, half eta); 152 153// 8.6 : Matrix Functions 154$squareMat matrixCompMult($squareMat x, $squareMat y); 155$squareHMat matrixCompMult($squareHMat x, $squareHMat y); 156$es3 $mat matrixCompMult($mat x, $mat y); 157$es3 $hmat matrixCompMult($hmat x, $hmat y); 158 159// 8.6 : Matrix Functions (GLSL 1.4, poly-filled by SkSL as needed) 160$squareMat inverse($squareMat m); 161$squareHMat inverse($squareHMat m); 162 163// 8.6 : Matrix Functions (GLSL ES 3.0) 164$es3 float determinant($squareMat m); 165$es3 half determinant($squareHMat m); 166$es3 $squareMat transpose($squareMat m); 167$es3 $squareHMat transpose($squareHMat m); 168$es3 float2x3 transpose(float3x2 m); 169$es3 half2x3 transpose(half3x2 m); 170$es3 float2x4 transpose(float4x2 m); 171$es3 half2x4 transpose(half4x2 m); 172$es3 float3x2 transpose(float2x3 m); 173$es3 half3x2 transpose(half2x3 m); 174$es3 float3x4 transpose(float4x3 m); 175$es3 half3x4 transpose(half4x3 m); 176$es3 float4x2 transpose(float2x4 m); 177$es3 half4x2 transpose(half2x4 m); 178$es3 float4x3 transpose(float3x4 m); 179$es3 half4x3 transpose(half3x4 m); 180$es3 $squareMat outerProduct($vec c, $vec r); 181$es3 $squareHMat outerProduct($hvec c, $hvec r); 182$es3 float2x3 outerProduct(float3 c, float2 r); 183$es3 half2x3 outerProduct(half3 c, half2 r); 184$es3 float3x2 outerProduct(float2 c, float3 r); 185$es3 half3x2 outerProduct(half2 c, half3 r); 186$es3 float2x4 outerProduct(float4 c, float2 r); 187$es3 half2x4 outerProduct(half4 c, half2 r); 188$es3 float4x2 outerProduct(float2 c, float4 r); 189$es3 half4x2 outerProduct(half2 c, half4 r); 190$es3 float3x4 outerProduct(float4 c, float3 r); 191$es3 half3x4 outerProduct(half4 c, half3 r); 192$es3 float4x3 outerProduct(float3 c, float4 r); 193$es3 half4x3 outerProduct(half3 c, half4 r); 194 195// 8.7 : Vector Relational Functions 196$bvec lessThan($vec x, $vec y); 197$bvec lessThan($hvec x, $hvec y); 198$bvec lessThan($ivec x, $ivec y); 199$bvec lessThanEqual($vec x, $vec y); 200$bvec lessThanEqual($hvec x, $hvec y); 201$bvec lessThanEqual($ivec x, $ivec y); 202$bvec greaterThan($vec x, $vec y); 203$bvec greaterThan($hvec x, $hvec y); 204$bvec greaterThan($ivec x, $ivec y); 205$bvec greaterThanEqual($vec x, $vec y); 206$bvec greaterThanEqual($hvec x, $hvec y); 207$bvec greaterThanEqual($ivec x, $ivec y); 208$bvec equal($vec x, $vec y); 209$bvec equal($hvec x, $hvec y); 210$bvec equal($ivec x, $ivec y); 211$bvec equal($bvec x, $bvec y); 212$bvec notEqual($vec x, $vec y); 213$bvec notEqual($hvec x, $hvec y); 214$bvec notEqual($ivec x, $ivec y); 215$bvec notEqual($bvec x, $bvec y); 216 217bool any($bvec x); 218bool all($bvec x); 219$bvec not($bvec x); 220 221// 8.9 : Fragment Processing Functions (GLSL ES 3.0) 222$es3 $genType dFdx($genType p); 223$es3 $genType dFdy($genType p); 224$es3 $genHType dFdx($genHType p); 225$es3 $genHType dFdy($genHType p); 226$es3 $genType fwidth($genType p); 227$es3 $genHType fwidth($genHType p); 228 229 230// SkSL intrinsics that are not part of GLSL: 231// The max() guards against division by zero when the incoming color is transparent black 232half4 unpremul(half4 color) { return half4 (color.rgb / max(color.a, 0.0001), color.a); } 233float4 unpremul(float4 color) { return float4(color.rgb / max(color.a, 0.0001), color.a); } 234 235// SkSL intrinsics that reflect Skia's C++ object model: 236half4 $eval(float2 coords, shader s); 237half4 $eval(half4 color, colorFilter f); 238half4 $eval(half4 src, half4 dst, blender b); 239