John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1 | // |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 2 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // |
| 8 | // Create strings that declare built-in definitions, add built-ins that |
| 9 | // cannot be expressed in the files, and establish mappings between |
| 10 | // built-in functions and operators. |
| 11 | // |
| 12 | |
Nicolas Capens | cc863da | 2015-01-21 15:50:55 -0500 | [diff] [blame] | 13 | #include "Initialize.h" |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 14 | |
Nicolas Capens | cc863da | 2015-01-21 15:50:55 -0500 | [diff] [blame] | 15 | #include "intermediate.h" |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 16 | |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 17 | void InsertBuiltInFunctions(GLenum type, const ShBuiltInResources &resources, TSymbolTable &symbolTable) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 18 | { |
Nicolas Capens | 70da3d4 | 2015-02-18 16:58:10 -0500 | [diff] [blame] | 19 | TType *float1 = new TType(EbtFloat); |
| 20 | TType *float2 = new TType(EbtFloat, 2); |
| 21 | TType *float3 = new TType(EbtFloat, 3); |
| 22 | TType *float4 = new TType(EbtFloat, 4); |
Nicolas Capens | 8fa9d23 | 2015-02-19 15:53:16 -0500 | [diff] [blame] | 23 | TType *genType = new TType(EbtGenType); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 24 | |
Alexis Hetu | 2205c20 | 2015-04-16 10:38:41 -0400 | [diff] [blame^] | 25 | TType *int1 = new TType(EbtInt); |
| 26 | TType *uint1 = new TType(EbtUInt); |
| 27 | TType *genIType = new TType(EbtGenIType); |
| 28 | TType *genUType = new TType(EbtGenUType); |
| 29 | TType *genBType = new TType(EbtGenBType); |
| 30 | |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 31 | // |
| 32 | // Angle and Trigonometric Functions. |
| 33 | // |
Nicolas Capens | 33cda11 | 2015-02-24 17:35:47 -0500 | [diff] [blame] | 34 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpRadians, genType, "radians", genType); |
| 35 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpDegrees, genType, "degrees", genType); |
| 36 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSin, genType, "sin", genType); |
| 37 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpCos, genType, "cos", genType); |
| 38 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpTan, genType, "tan", genType); |
| 39 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAsin, genType, "asin", genType); |
| 40 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAcos, genType, "acos", genType); |
| 41 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAtan, genType, "atan", genType, genType); |
| 42 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAtan, genType, "atan", genType); |
Alexis Hetu | 2205c20 | 2015-04-16 10:38:41 -0400 | [diff] [blame^] | 43 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpSinh, genType, "sinh", genType); |
| 44 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpCosh, genType, "cosh", genType); |
| 45 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTanh, genType, "tanh", genType); |
| 46 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAsinh, genType, "asinh", genType); |
| 47 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAcosh, genType, "acosh", genType); |
| 48 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAtanh, genType, "atanh", genType); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 49 | |
| 50 | // |
| 51 | // Exponential Functions. |
| 52 | // |
Nicolas Capens | 33cda11 | 2015-02-24 17:35:47 -0500 | [diff] [blame] | 53 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpPow, genType, "pow", genType, genType); |
| 54 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpExp, genType, "exp", genType); |
| 55 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLog, genType, "log", genType); |
| 56 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpExp2, genType, "exp2", genType); |
| 57 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLog2, genType, "log2", genType); |
| 58 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSqrt, genType, "sqrt", genType); |
| 59 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpInverseSqrt, genType, "inversesqrt", genType); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 60 | |
| 61 | // |
| 62 | // Common Functions. |
| 63 | // |
Nicolas Capens | 33cda11 | 2015-02-24 17:35:47 -0500 | [diff] [blame] | 64 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAbs, genType, "abs", genType); |
Alexis Hetu | 2205c20 | 2015-04-16 10:38:41 -0400 | [diff] [blame^] | 65 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAbs, genIType, "abs", genIType); |
Nicolas Capens | 33cda11 | 2015-02-24 17:35:47 -0500 | [diff] [blame] | 66 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSign, genType, "sign", genType); |
Alexis Hetu | 2205c20 | 2015-04-16 10:38:41 -0400 | [diff] [blame^] | 67 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpSign, genIType, "sign", genIType); |
Nicolas Capens | 33cda11 | 2015-02-24 17:35:47 -0500 | [diff] [blame] | 68 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpFloor, genType, "floor", genType); |
Alexis Hetu | 2205c20 | 2015-04-16 10:38:41 -0400 | [diff] [blame^] | 69 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTrunc, genType, "trunc", genType); |
| 70 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpRound, genType, "round", genType); |
| 71 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpRoundEven, genType, "roundEven", genType); |
Nicolas Capens | 33cda11 | 2015-02-24 17:35:47 -0500 | [diff] [blame] | 72 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpCeil, genType, "ceil", genType); |
| 73 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpFract, genType, "fract", genType); |
| 74 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMod, genType, "mod", genType, float1); |
| 75 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMod, genType, "mod", genType, genType); |
| 76 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMin, genType, "min", genType, float1); |
| 77 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMin, genType, "min", genType, genType); |
Alexis Hetu | 2205c20 | 2015-04-16 10:38:41 -0400 | [diff] [blame^] | 78 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genIType, "min", genIType, genIType); |
| 79 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genIType, "min", genIType, int1); |
| 80 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genUType, "min", genUType, genUType); |
| 81 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genUType, "min", genUType, uint1); |
Nicolas Capens | 33cda11 | 2015-02-24 17:35:47 -0500 | [diff] [blame] | 82 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMax, genType, "max", genType, float1); |
| 83 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMax, genType, "max", genType, genType); |
Alexis Hetu | 2205c20 | 2015-04-16 10:38:41 -0400 | [diff] [blame^] | 84 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genIType, "max", genIType, genIType); |
| 85 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genIType, "max", genIType, int1); |
| 86 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genUType, "max", genUType, genUType); |
| 87 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genUType, "max", genUType, uint1); |
Nicolas Capens | 33cda11 | 2015-02-24 17:35:47 -0500 | [diff] [blame] | 88 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpClamp, genType, "clamp", genType, float1, float1); |
| 89 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpClamp, genType, "clamp", genType, genType, genType); |
Alexis Hetu | 2205c20 | 2015-04-16 10:38:41 -0400 | [diff] [blame^] | 90 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genIType, "clamp", genIType, int1, int1); |
| 91 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genIType, "clamp", genIType, genIType, genIType); |
| 92 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genUType, "clamp", genUType, uint1, uint1); |
| 93 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genUType, "clamp", genUType, genUType, genUType); |
Nicolas Capens | 33cda11 | 2015-02-24 17:35:47 -0500 | [diff] [blame] | 94 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMix, genType, "mix", genType, genType, float1); |
| 95 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMix, genType, "mix", genType, genType, genType); |
| 96 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpStep, genType, "step", genType, genType); |
| 97 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpStep, genType, "step", float1, genType); |
| 98 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSmoothStep, genType, "smoothstep", genType, genType, genType); |
| 99 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSmoothStep, genType, "smoothstep", float1, float1, genType); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 100 | |
Alexis Hetu | 2205c20 | 2015-04-16 10:38:41 -0400 | [diff] [blame^] | 101 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIsNan, genBType, "isnan", genType); |
| 102 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIsInf, genBType, "isinf", genType); |
| 103 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpFloatBitsToInt, genIType, "floatBitsToInt", genType); |
| 104 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpFloatBitsToUint, genUType, "floatBitsToUint", genType); |
| 105 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIntBitsToFloat, genType, "intBitsToFloat", genIType); |
| 106 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUintBitsToFloat, genType, "uintBitsToFloat", genUType);
|
| 107 |
|
| 108 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackSnorm2x16, uint1, "packSnorm2x16", float2); |
| 109 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackUnorm2x16, uint1, "packUnorm2x16", float2); |
| 110 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackHalf2x16, uint1, "packHalf2x16", float2); |
| 111 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackSnorm2x16, float2, "unpackSnorm2x16", uint1); |
| 112 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackUnorm2x16, float2, "unpackUnorm2x16", uint1); |
| 113 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackHalf2x16, float2, "unpackHalf2x16", uint1); |
| 114 | |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 115 | // |
| 116 | // Geometric Functions. |
| 117 | // |
Nicolas Capens | 33cda11 | 2015-02-24 17:35:47 -0500 | [diff] [blame] | 118 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLength, float1, "length", genType); |
| 119 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpDistance, float1, "distance", genType, genType); |
| 120 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpDot, float1, "dot", genType, genType); |
| 121 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpCross, float3, "cross", float3, float3); |
| 122 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpNormalize, genType, "normalize", genType); |
| 123 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpFaceForward, genType, "faceforward", genType, genType, genType); |
| 124 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpReflect, genType, "reflect", genType, genType); |
| 125 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpRefract, genType, "refract", genType, genType, float1); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 126 | |
Alexis Hetu | b14178b | 2015-04-13 13:23:20 -0400 | [diff] [blame] | 127 | TType *mat2 = new TType(EbtFloat, 2, 2); |
Alexis Hetu | 2205c20 | 2015-04-16 10:38:41 -0400 | [diff] [blame^] | 128 | TType *mat2x3 = new TType(EbtFloat, 2, 3); |
| 129 | TType *mat2x4 = new TType(EbtFloat, 2, 4); |
| 130 | TType *mat3x2 = new TType(EbtFloat, 3, 2); |
Alexis Hetu | b14178b | 2015-04-13 13:23:20 -0400 | [diff] [blame] | 131 | TType *mat3 = new TType(EbtFloat, 3, 3); |
Alexis Hetu | 2205c20 | 2015-04-16 10:38:41 -0400 | [diff] [blame^] | 132 | TType *mat3x4 = new TType(EbtFloat, 3, 4); |
| 133 | TType *mat4x2 = new TType(EbtFloat, 4, 2); |
| 134 | TType *mat4x3 = new TType(EbtFloat, 4, 3); |
Alexis Hetu | b14178b | 2015-04-13 13:23:20 -0400 | [diff] [blame] | 135 | TType *mat4 = new TType(EbtFloat, 4, 4); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 136 | |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 137 | // |
| 138 | // Matrix Functions. |
| 139 | // |
Nicolas Capens | 33cda11 | 2015-02-24 17:35:47 -0500 | [diff] [blame] | 140 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat2, "matrixCompMult", mat2, mat2); |
| 141 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat3, "matrixCompMult", mat3, mat3); |
| 142 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat4, "matrixCompMult", mat4, mat4); |
Alexis Hetu | 2205c20 | 2015-04-16 10:38:41 -0400 | [diff] [blame^] | 143 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat2x3, "matrixCompMult", mat2x3, mat2x3); |
| 144 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat3x2, "matrixCompMult", mat3x2, mat3x2); |
| 145 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat2x4, "matrixCompMult", mat2x4, mat2x4); |
| 146 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat4x2, "matrixCompMult", mat4x2, mat4x2); |
| 147 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat3x4, "matrixCompMult", mat3x4, mat3x4); |
| 148 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat4x3, "matrixCompMult", mat4x3, mat4x3);
|
| 149 |
|
| 150 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2, "outerProduct", float2, float2); |
| 151 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3, "outerProduct", float3, float3); |
| 152 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4, "outerProduct", float4, float4); |
| 153 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2x3, "outerProduct", float3, float2); |
| 154 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3x2, "outerProduct", float2, float3); |
| 155 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2x4, "outerProduct", float4, float2); |
| 156 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4x2, "outerProduct", float2, float4); |
| 157 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3x4, "outerProduct", float4, float3); |
| 158 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4x3, "outerProduct", float3, float4);
|
| 159 |
|
| 160 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2, "transpose", mat2); |
| 161 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3, "transpose", mat3); |
| 162 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4, "transpose", mat4); |
| 163 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2x3, "transpose", mat3x2); |
| 164 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3x2, "transpose", mat2x3); |
| 165 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2x4, "transpose", mat4x2); |
| 166 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4x2, "transpose", mat2x4); |
| 167 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3x4, "transpose", mat4x3); |
| 168 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4x3, "transpose", mat3x4);
|
| 169 |
|
| 170 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat2); |
| 171 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat3); |
| 172 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat4);
|
| 173 |
|
| 174 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat2, "inverse", mat2); |
| 175 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat3, "inverse", mat3); |
| 176 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat4, "inverse", mat4);
|
| 177 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 178 | |
Nicolas Capens | 70da3d4 | 2015-02-18 16:58:10 -0500 | [diff] [blame] | 179 | TType *bool1 = new TType(EbtBool); |
Nicolas Capens | 8fa9d23 | 2015-02-19 15:53:16 -0500 | [diff] [blame] | 180 | TType *vec = new TType(EbtVec); |
| 181 | TType *ivec = new TType(EbtIVec); |
Alexis Hetu | 2205c20 | 2015-04-16 10:38:41 -0400 | [diff] [blame^] | 182 | TType *uvec = new TType(EbtUVec);
|
Nicolas Capens | 8fa9d23 | 2015-02-19 15:53:16 -0500 | [diff] [blame] | 183 | TType *bvec = new TType(EbtBVec); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 184 | |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 185 | // |
| 186 | // Vector relational functions. |
| 187 | // |
Nicolas Capens | 33cda11 | 2015-02-24 17:35:47 -0500 | [diff] [blame] | 188 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThan, bvec, "lessThan", vec, vec); |
| 189 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThan, bvec, "lessThan", ivec, ivec); |
Alexis Hetu | 2205c20 | 2015-04-16 10:38:41 -0400 | [diff] [blame^] | 190 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpLessThan, bvec, "lessThan", uvec, uvec); |
Nicolas Capens | 33cda11 | 2015-02-24 17:35:47 -0500 | [diff] [blame] | 191 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", vec, vec); |
| 192 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", ivec, ivec); |
Alexis Hetu | 2205c20 | 2015-04-16 10:38:41 -0400 | [diff] [blame^] | 193 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", uvec, uvec); |
Nicolas Capens | 33cda11 | 2015-02-24 17:35:47 -0500 | [diff] [blame] | 194 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThan, bvec, "greaterThan", vec, vec); |
| 195 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThan, bvec, "greaterThan", ivec, ivec); |
Alexis Hetu | 2205c20 | 2015-04-16 10:38:41 -0400 | [diff] [blame^] | 196 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpGreaterThan, bvec, "greaterThan", uvec, uvec); |
Nicolas Capens | 33cda11 | 2015-02-24 17:35:47 -0500 | [diff] [blame] | 197 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", vec, vec); |
| 198 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", ivec, ivec); |
Alexis Hetu | 2205c20 | 2015-04-16 10:38:41 -0400 | [diff] [blame^] | 199 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", uvec, uvec); |
Nicolas Capens | 33cda11 | 2015-02-24 17:35:47 -0500 | [diff] [blame] | 200 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", vec, vec); |
| 201 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", ivec, ivec); |
Alexis Hetu | 2205c20 | 2015-04-16 10:38:41 -0400 | [diff] [blame^] | 202 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpVectorEqual, bvec, "equal", uvec, uvec); |
Nicolas Capens | 33cda11 | 2015-02-24 17:35:47 -0500 | [diff] [blame] | 203 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", bvec, bvec); |
| 204 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", vec, vec); |
| 205 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", ivec, ivec); |
Alexis Hetu | 2205c20 | 2015-04-16 10:38:41 -0400 | [diff] [blame^] | 206 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", uvec, uvec); |
Nicolas Capens | 33cda11 | 2015-02-24 17:35:47 -0500 | [diff] [blame] | 207 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", bvec, bvec); |
| 208 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAny, bool1, "any", bvec); |
| 209 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAll, bool1, "all", bvec); |
| 210 | symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorLogicalNot, bvec, "not", bvec); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 211 | |
Nicolas Capens | 70da3d4 | 2015-02-18 16:58:10 -0500 | [diff] [blame] | 212 | TType *sampler2D = new TType(EbtSampler2D); |
| 213 | TType *samplerCube = new TType(EbtSamplerCube); |
| 214 | TType *sampler3D = new TType(EbtSampler3D); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 215 | |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 216 | // |
| 217 | // Texture Functions for GLSL ES 1.0 |
| 218 | // |
| 219 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2); |
| 220 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3); |
| 221 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4); |
| 222 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3); |
| 223 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture3D", sampler3D, float3); |
| 224 | |
| 225 | if(resources.OES_EGL_image_external) |
| 226 | { |
Nicolas Capens | 70da3d4 | 2015-02-18 16:58:10 -0500 | [diff] [blame] | 227 | TType *samplerExternalOES = new TType(EbtSamplerExternalOES); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 228 | |
| 229 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", samplerExternalOES, float2); |
| 230 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float3); |
| 231 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float4); |
| 232 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture3D", samplerExternalOES, float3); |
| 233 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 234 | |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 235 | if(type == GL_FRAGMENT_SHADER) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 236 | { |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 237 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2, float1); |
| 238 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3, float1); |
| 239 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4, float1); |
| 240 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3, float1); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 241 | |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 242 | if(resources.OES_standard_derivatives) |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 243 | { |
Nicolas Capens | 18d5ef9 | 2015-02-24 17:38:08 -0500 | [diff] [blame] | 244 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpDFdx, "GL_OES_standard_derivatives", genType, "dFdx", genType); |
| 245 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpDFdy, "GL_OES_standard_derivatives", genType, "dFdy", genType); |
| 246 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpFwidth,"GL_OES_standard_derivatives", genType, "fwidth", genType); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 247 | } |
| 248 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 249 | |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 250 | if(type == GL_VERTEX_SHADER) |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 251 | { |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 252 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLod", sampler2D, float2, float1); |
| 253 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float3, float1); |
| 254 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float4, float1); |
| 255 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLod", samplerCube, float3, float1); |
| 256 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture3DLod", sampler3D, float3, float1); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 257 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 258 | |
Nicolas Capens | 82cd6d8 | 2015-02-18 17:53:39 -0500 | [diff] [blame] | 259 | TType *gvec4 = new TType(EbtGVec4); |
| 260 | |
| 261 | TType *gsampler2D = new TType(EbtGSampler2D); |
| 262 | TType *gsamplerCube = new TType(EbtGSamplerCube); |
| 263 | TType *gsampler3D = new TType(EbtGSampler3D); |
| 264 | TType *gsampler2DArray = new TType(EbtGSampler2DArray); |
| 265 | |
| 266 | // |
| 267 | // Texture Functions for GLSL ES 3.0 |
| 268 | // |
| 269 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2); |
| 270 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3); |
| 271 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3); |
| 272 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3); |
| 273 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3); |
| 274 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4); |
| 275 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4); |
| 276 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2D, float2, float1); |
| 277 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler3D, float3, float1); |
| 278 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsamplerCube, float3, float1); |
| 279 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2DArray, float3, float1); |
| 280 | |
| 281 | if(type == GL_FRAGMENT_SHADER) |
| 282 | { |
| 283 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2, float1); |
| 284 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3, float1); |
| 285 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3, float1); |
| 286 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3, float1); |
| 287 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3, float1); |
| 288 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4, float1); |
| 289 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4, float1); |
| 290 | } |
| 291 | |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 292 | // |
| 293 | // Depth range in window coordinates |
| 294 | // |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 295 | TTypeList *members = NewPoolTTypeList(); |
| 296 | TTypeLine near = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0}; |
| 297 | TTypeLine far = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0}; |
| 298 | TTypeLine diff = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0}; |
| 299 | near.type->setFieldName("near"); |
| 300 | far.type->setFieldName("far"); |
| 301 | diff.type->setFieldName("diff"); |
| 302 | members->push_back(near); |
| 303 | members->push_back(far); |
| 304 | members->push_back(diff); |
| 305 | TVariable *depthRangeParameters = new TVariable(NewPoolTString("gl_DepthRangeParameters"), TType(members, "gl_DepthRangeParameters"), true); |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 306 | symbolTable.insert(COMMON_BUILTINS, *depthRangeParameters); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 307 | TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(members, "gl_DepthRangeParameters")); |
| 308 | depthRange->setQualifier(EvqUniform); |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 309 | symbolTable.insert(COMMON_BUILTINS, *depthRange); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 310 | |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 311 | // |
| 312 | // Implementation dependent built-in constants. |
| 313 | // |
| 314 | symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexAttribs", resources.MaxVertexAttribs); |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 315 | symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors); |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 316 | symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits); |
| 317 | symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits); |
| 318 | symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxTextureImageUnits", resources.MaxTextureImageUnits); |
| 319 | symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 320 | symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxVaryingVectors", resources.MaxVaryingVectors); |
| 321 | symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxDrawBuffers", resources.MaxDrawBuffers); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 322 | } |
| 323 | |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 324 | void IdentifyBuiltIns(GLenum shaderType, |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 325 | const ShBuiltInResources &resources, |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 326 | TSymbolTable &symbolTable) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 327 | { |
| 328 | // |
| 329 | // First, insert some special built-in variables that are not in |
| 330 | // the built-in header files. |
| 331 | // |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 332 | switch(shaderType) |
| 333 | { |
| 334 | case GL_FRAGMENT_SHADER: |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 335 | symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4))); |
| 336 | symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1))); |
| 337 | symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2))); |
| 338 | symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4))); |
| 339 | symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 340 | break; |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 341 | case GL_VERTEX_SHADER: |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 342 | symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4))); |
| 343 | symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 344 | break; |
| 345 | default: assert(false && "Language not supported"); |
| 346 | } |
| 347 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 348 | // Finally add resource-specific variables. |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 349 | switch(shaderType) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 350 | { |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 351 | case GL_FRAGMENT_SHADER: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 352 | { |
| 353 | // Set up gl_FragData. The array size. |
Alexis Hetu | b14178b | 2015-04-13 13:23:20 -0400 | [diff] [blame] | 354 | TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, 1, true); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 355 | fragData.setArraySize(resources.MaxDrawBuffers); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 356 | symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData"), fragData)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 357 | } |
| 358 | break; |
| 359 | default: break; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | void InitExtensionBehavior(const ShBuiltInResources& resources, |
| 364 | TExtensionBehavior& extBehavior) |
| 365 | { |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 366 | if(resources.OES_standard_derivatives) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 367 | extBehavior["GL_OES_standard_derivatives"] = EBhUndefined; |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 368 | if(resources.OES_fragment_precision_high) |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 369 | extBehavior["GL_FRAGMENT_PRECISION_HIGH"] = EBhUndefined; |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 370 | if(resources.OES_EGL_image_external) |
| 371 | extBehavior["GL_OES_EGL_image_external"] = EBhUndefined; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 372 | } |