daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
Nicolas Capens | 1fbc287 | 2014-01-03 14:12:09 -0500 | [diff] [blame] | 2 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [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 | // |
Nicolas Capens | 4fd5e4a | 2014-02-14 18:17:15 -0500 | [diff] [blame] | 8 | // Create symbols that declare built-in definitions, add built-ins that |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 9 | // cannot be expressed in the files, and establish mappings between |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 10 | // built-in functions and operators. |
| 11 | // |
| 12 | |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 13 | #include "compiler/translator/Initialize.h" |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 14 | #include "compiler/translator/Cache.h" |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 15 | |
Jamie Madill | b1a85f4 | 2014-08-19 15:23:24 -0400 | [diff] [blame] | 16 | #include "compiler/translator/IntermNode.h" |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 17 | #include "angle_gl.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 18 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 19 | namespace sh |
| 20 | { |
| 21 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 22 | void InsertBuiltInFunctions(sh::GLenum type, |
| 23 | ShShaderSpec spec, |
| 24 | const ShBuiltInResources &resources, |
| 25 | TSymbolTable &symbolTable) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 26 | { |
Martin Radev | 2cc85b3 | 2016-08-05 16:22:53 +0300 | [diff] [blame] | 27 | const TType *voidType = TCache::getType(EbtVoid); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 28 | const TType *float1 = TCache::getType(EbtFloat); |
| 29 | const TType *float2 = TCache::getType(EbtFloat, 2); |
| 30 | const TType *float3 = TCache::getType(EbtFloat, 3); |
| 31 | const TType *float4 = TCache::getType(EbtFloat, 4); |
| 32 | const TType *int1 = TCache::getType(EbtInt); |
| 33 | const TType *int2 = TCache::getType(EbtInt, 2); |
| 34 | const TType *int3 = TCache::getType(EbtInt, 3); |
| 35 | const TType *uint1 = TCache::getType(EbtUInt); |
| 36 | const TType *bool1 = TCache::getType(EbtBool); |
| 37 | const TType *genType = TCache::getType(EbtGenType); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 38 | const TType *genIType = TCache::getType(EbtGenIType); |
| 39 | const TType *genUType = TCache::getType(EbtGenUType); |
| 40 | const TType *genBType = TCache::getType(EbtGenBType); |
alokp@chromium.org | e4249f0 | 2010-07-26 18:13:52 +0000 | [diff] [blame] | 41 | |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 42 | // |
alokp@chromium.org | e4249f0 | 2010-07-26 18:13:52 +0000 | [diff] [blame] | 43 | // Angle and Trigonometric Functions. |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 44 | // |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame^] | 45 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpRadians, genType, genType); |
| 46 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpDegrees, genType, genType); |
| 47 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpSin, genType, genType); |
| 48 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpCos, genType, genType); |
| 49 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpTan, genType, genType); |
| 50 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpAsin, genType, genType); |
| 51 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpAcos, genType, genType); |
| 52 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpAtan, genType, genType, genType); |
| 53 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpAtan, genType, genType); |
| 54 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpSinh, genType, genType); |
| 55 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpCosh, genType, genType); |
| 56 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpTanh, genType, genType); |
| 57 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpAsinh, genType, genType); |
| 58 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpAcosh, genType, genType); |
| 59 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpAtanh, genType, genType); |
Olli Etuaho | 5c9cd3d | 2014-12-18 13:04:25 +0200 | [diff] [blame] | 60 | |
alokp@chromium.org | e4249f0 | 2010-07-26 18:13:52 +0000 | [diff] [blame] | 61 | // |
| 62 | // Exponential Functions. |
| 63 | // |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame^] | 64 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpPow, genType, genType, genType); |
| 65 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpExp, genType, genType); |
| 66 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpLog, genType, genType); |
| 67 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpExp2, genType, genType); |
| 68 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpLog2, genType, genType); |
| 69 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpSqrt, genType, genType); |
| 70 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpInverseSqrt, genType, genType); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 71 | |
alokp@chromium.org | e4249f0 | 2010-07-26 18:13:52 +0000 | [diff] [blame] | 72 | // |
| 73 | // Common Functions. |
| 74 | // |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame^] | 75 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpAbs, genType, genType); |
| 76 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpAbs, genIType, genIType); |
| 77 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpSign, genType, genType); |
| 78 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpSign, genIType, genIType); |
| 79 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpFloor, genType, genType); |
| 80 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpTrunc, genType, genType); |
| 81 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpRound, genType, genType); |
| 82 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpRoundEven, genType, genType); |
| 83 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpCeil, genType, genType); |
| 84 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpFract, genType, genType); |
| 85 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpMod, genType, genType, float1); |
| 86 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpMod, genType, genType, genType); |
| 87 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpMin, genType, genType, float1); |
| 88 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpMin, genType, genType, genType); |
| 89 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpMin, genIType, genIType, genIType); |
| 90 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpMin, genIType, genIType, int1); |
| 91 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpMin, genUType, genUType, genUType); |
| 92 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpMin, genUType, genUType, uint1); |
| 93 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpMax, genType, genType, float1); |
| 94 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpMax, genType, genType, genType); |
| 95 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpMax, genIType, genIType, genIType); |
| 96 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpMax, genIType, genIType, int1); |
| 97 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpMax, genUType, genUType, genUType); |
| 98 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpMax, genUType, genUType, uint1); |
| 99 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpClamp, genType, genType, float1, float1); |
| 100 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpClamp, genType, genType, genType, genType); |
| 101 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpClamp, genIType, genIType, int1, int1); |
| 102 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpClamp, genIType, genIType, genIType, genIType); |
| 103 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpClamp, genUType, genUType, uint1, uint1); |
| 104 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpClamp, genUType, genUType, genUType, genUType); |
| 105 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpMix, genType, genType, genType, float1); |
| 106 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpMix, genType, genType, genType, genType); |
| 107 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpMix, genType, genType, genType, genBType); |
| 108 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpStep, genType, genType, genType); |
| 109 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpStep, genType, float1, genType); |
| 110 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpSmoothStep, genType, genType, genType, genType); |
| 111 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpSmoothStep, genType, float1, float1, genType); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 112 | |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 113 | const TType *outFloat1 = TCache::getType(EbtFloat, EvqOut); |
| 114 | const TType *outFloat2 = TCache::getType(EbtFloat, EvqOut, 2); |
| 115 | const TType *outFloat3 = TCache::getType(EbtFloat, EvqOut, 3); |
| 116 | const TType *outFloat4 = TCache::getType(EbtFloat, EvqOut, 4); |
Olli Etuaho | b6e07a6 | 2015-02-16 12:22:10 +0200 | [diff] [blame] | 117 | |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame^] | 118 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpModf, float1, float1, outFloat1); |
| 119 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpModf, float2, float2, outFloat2); |
| 120 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpModf, float3, float3, outFloat3); |
| 121 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpModf, float4, float4, outFloat4); |
Olli Etuaho | b6e07a6 | 2015-02-16 12:22:10 +0200 | [diff] [blame] | 122 | |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame^] | 123 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpIsNan, genBType, genType); |
| 124 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpIsInf, genBType, genType); |
| 125 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpFloatBitsToInt, genIType, genType); |
| 126 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpFloatBitsToUint, genUType, genType); |
| 127 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpIntBitsToFloat, genType, genIType); |
| 128 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpUintBitsToFloat, genType, genUType); |
Olli Etuaho | e8d2c07 | 2015-01-08 16:33:54 +0200 | [diff] [blame] | 129 | |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame^] | 130 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpPackSnorm2x16, uint1, float2); |
| 131 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpPackUnorm2x16, uint1, float2); |
| 132 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpPackHalf2x16, uint1, float2); |
| 133 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpUnpackSnorm2x16, float2, uint1); |
| 134 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpUnpackUnorm2x16, float2, uint1); |
| 135 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpUnpackHalf2x16, float2, uint1); |
Olli Etuaho | 7700ff6 | 2015-01-15 12:16:29 +0200 | [diff] [blame] | 136 | |
alokp@chromium.org | e4249f0 | 2010-07-26 18:13:52 +0000 | [diff] [blame] | 137 | // |
| 138 | // Geometric Functions. |
| 139 | // |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame^] | 140 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpLength, float1, genType); |
| 141 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpDistance, float1, genType, genType); |
| 142 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpDot, float1, genType, genType); |
| 143 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpCross, float3, float3, float3); |
| 144 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpNormalize, genType, genType); |
| 145 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpFaceForward, genType, genType, genType, |
| 146 | genType); |
| 147 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpReflect, genType, genType, genType); |
| 148 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpRefract, genType, genType, genType, float1); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 149 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 150 | const TType *mat2 = TCache::getType(EbtFloat, 2, 2); |
| 151 | const TType *mat3 = TCache::getType(EbtFloat, 3, 3); |
| 152 | const TType *mat4 = TCache::getType(EbtFloat, 4, 4); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 153 | const TType *mat2x3 = TCache::getType(EbtFloat, 2, 3); |
| 154 | const TType *mat3x2 = TCache::getType(EbtFloat, 3, 2); |
| 155 | const TType *mat2x4 = TCache::getType(EbtFloat, 2, 4); |
| 156 | const TType *mat4x2 = TCache::getType(EbtFloat, 4, 2); |
| 157 | const TType *mat3x4 = TCache::getType(EbtFloat, 3, 4); |
| 158 | const TType *mat4x3 = TCache::getType(EbtFloat, 4, 3); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 159 | |
alokp@chromium.org | e4249f0 | 2010-07-26 18:13:52 +0000 | [diff] [blame] | 160 | // |
| 161 | // Matrix Functions. |
| 162 | // |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame^] | 163 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpMulMatrixComponentWise, mat2, mat2, mat2); |
| 164 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpMulMatrixComponentWise, mat3, mat3, mat3); |
| 165 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpMulMatrixComponentWise, mat4, mat4, mat4); |
| 166 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpMulMatrixComponentWise, mat2x3, mat2x3, mat2x3); |
| 167 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpMulMatrixComponentWise, mat3x2, mat3x2, mat3x2); |
| 168 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpMulMatrixComponentWise, mat2x4, mat2x4, mat2x4); |
| 169 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpMulMatrixComponentWise, mat4x2, mat4x2, mat4x2); |
| 170 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpMulMatrixComponentWise, mat3x4, mat3x4, mat3x4); |
| 171 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpMulMatrixComponentWise, mat4x3, mat4x3, mat4x3); |
Olli Etuaho | e39706d | 2014-12-30 16:40:36 +0200 | [diff] [blame] | 172 | |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame^] | 173 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat2, float2, float2); |
| 174 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat3, float3, float3); |
| 175 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat4, float4, float4); |
| 176 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat2x3, float3, float2); |
| 177 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat3x2, float2, float3); |
| 178 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat2x4, float4, float2); |
| 179 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat4x2, float2, float4); |
| 180 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat3x4, float4, float3); |
| 181 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat4x3, float3, float4); |
Olli Etuaho | e39706d | 2014-12-30 16:40:36 +0200 | [diff] [blame] | 182 | |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame^] | 183 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat2, mat2); |
| 184 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat3, mat3); |
| 185 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat4, mat4); |
| 186 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat2x3, mat3x2); |
| 187 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat3x2, mat2x3); |
| 188 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat2x4, mat4x2); |
| 189 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat4x2, mat2x4); |
| 190 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat3x4, mat4x3); |
| 191 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat4x3, mat3x4); |
Olli Etuaho | e39706d | 2014-12-30 16:40:36 +0200 | [diff] [blame] | 192 | |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame^] | 193 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpDeterminant, float1, mat2); |
| 194 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpDeterminant, float1, mat3); |
| 195 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpDeterminant, float1, mat4); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 196 | |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame^] | 197 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpInverse, mat2, mat2); |
| 198 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpInverse, mat3, mat3); |
| 199 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpInverse, mat4, mat4); |
Olli Etuaho | abf6dad | 2015-01-14 14:45:16 +0200 | [diff] [blame] | 200 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 201 | const TType *vec = TCache::getType(EbtVec); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 202 | const TType *ivec = TCache::getType(EbtIVec); |
| 203 | const TType *uvec = TCache::getType(EbtUVec); |
| 204 | const TType *bvec = TCache::getType(EbtBVec); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 205 | |
alokp@chromium.org | e4249f0 | 2010-07-26 18:13:52 +0000 | [diff] [blame] | 206 | // |
| 207 | // Vector relational functions. |
| 208 | // |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame^] | 209 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpLessThanComponentWise, bvec, vec, vec); |
| 210 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpLessThanComponentWise, bvec, ivec, ivec); |
| 211 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpLessThanComponentWise, bvec, uvec, uvec); |
| 212 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpLessThanEqualComponentWise, bvec, vec, vec); |
| 213 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpLessThanEqualComponentWise, bvec, ivec, ivec); |
| 214 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpLessThanEqualComponentWise, bvec, uvec, uvec); |
| 215 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpGreaterThanComponentWise, bvec, vec, vec); |
| 216 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpGreaterThanComponentWise, bvec, ivec, ivec); |
| 217 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpGreaterThanComponentWise, bvec, uvec, uvec); |
| 218 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpGreaterThanEqualComponentWise, bvec, vec, vec); |
| 219 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpGreaterThanEqualComponentWise, bvec, ivec, |
| 220 | ivec); |
| 221 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpGreaterThanEqualComponentWise, bvec, uvec, uvec); |
| 222 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpEqualComponentWise, bvec, vec, vec); |
| 223 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpEqualComponentWise, bvec, ivec, ivec); |
| 224 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpEqualComponentWise, bvec, uvec, uvec); |
| 225 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpEqualComponentWise, bvec, bvec, bvec); |
| 226 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpNotEqualComponentWise, bvec, vec, vec); |
| 227 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpNotEqualComponentWise, bvec, ivec, ivec); |
| 228 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpNotEqualComponentWise, bvec, uvec, uvec); |
| 229 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpNotEqualComponentWise, bvec, bvec, bvec); |
| 230 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpAny, bool1, bvec); |
| 231 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpAll, bool1, bvec); |
| 232 | symbolTable.insertBuiltInOp(COMMON_BUILTINS, EOpLogicalNotComponentWise, bvec, bvec); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 233 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 234 | const TType *sampler2D = TCache::getType(EbtSampler2D); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 235 | const TType *samplerCube = TCache::getType(EbtSamplerCube); |
shannonwoods@chromium.org | 2ac0be9 | 2013-05-30 00:02:27 +0000 | [diff] [blame] | 236 | |
| 237 | // |
| 238 | // Texture Functions for GLSL ES 1.0 |
| 239 | // |
Nicolas Capens | 8f80e02 | 2013-07-11 11:20:50 -0400 | [diff] [blame] | 240 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2); |
| 241 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3); |
| 242 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4); |
| 243 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3); |
shannonwoods@chromium.org | 2ac0be9 | 2013-05-30 00:02:27 +0000 | [diff] [blame] | 244 | |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 245 | if (resources.OES_EGL_image_external || resources.NV_EGL_stream_consumer_external) |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 246 | { |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 247 | const TType *samplerExternalOES = TCache::getType(EbtSamplerExternalOES); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 248 | |
Nicolas Capens | 8f80e02 | 2013-07-11 11:20:50 -0400 | [diff] [blame] | 249 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", samplerExternalOES, float2); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 250 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, |
| 251 | float3); |
| 252 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, |
| 253 | float4); |
shannonwoods@chromium.org | 2ac0be9 | 2013-05-30 00:02:27 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 256 | if (resources.ARB_texture_rectangle) |
| 257 | { |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 258 | const TType *sampler2DRect = TCache::getType(EbtSampler2DRect); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 259 | |
Nicolas Capens | 8f80e02 | 2013-07-11 11:20:50 -0400 | [diff] [blame] | 260 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRect", sampler2DRect, float2); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 261 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, |
| 262 | float3); |
| 263 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, |
| 264 | float4); |
shannonwoods@chromium.org | 2ac0be9 | 2013-05-30 00:02:27 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Nicolas Capens | 4648508 | 2014-04-15 13:12:50 -0400 | [diff] [blame] | 267 | if (resources.EXT_shader_texture_lod) |
| 268 | { |
| 269 | /* The *Grad* variants are new to both vertex and fragment shaders; the fragment |
| 270 | * shader specific pieces are added separately below. |
| 271 | */ |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 272 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, |
| 273 | "texture2DGradEXT", sampler2D, float2, float2, float2); |
| 274 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, |
| 275 | "texture2DProjGradEXT", sampler2D, float3, float2, float2); |
| 276 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, |
| 277 | "texture2DProjGradEXT", sampler2D, float4, float2, float2); |
| 278 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, |
| 279 | "textureCubeGradEXT", samplerCube, float3, float3, float3); |
Nicolas Capens | 4648508 | 2014-04-15 13:12:50 -0400 | [diff] [blame] | 280 | } |
| 281 | |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 282 | if (type == GL_FRAGMENT_SHADER) |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 283 | { |
Nicolas Capens | 8f80e02 | 2013-07-11 11:20:50 -0400 | [diff] [blame] | 284 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2, float1); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 285 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3, |
| 286 | float1); |
| 287 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4, |
| 288 | float1); |
| 289 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3, |
| 290 | float1); |
shannonwoods@chromium.org | 2ac0be9 | 2013-05-30 00:02:27 +0000 | [diff] [blame] | 291 | |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 292 | if (resources.OES_standard_derivatives) |
| 293 | { |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame^] | 294 | symbolTable.insertBuiltInOp(ESSL1_BUILTINS, EOpDFdx, "GL_OES_standard_derivatives", |
| 295 | genType, genType); |
| 296 | symbolTable.insertBuiltInOp(ESSL1_BUILTINS, EOpDFdy, "GL_OES_standard_derivatives", |
| 297 | genType, genType); |
| 298 | symbolTable.insertBuiltInOp(ESSL1_BUILTINS, EOpFwidth, "GL_OES_standard_derivatives", |
| 299 | genType, genType); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 300 | } |
Nicolas Capens | 4648508 | 2014-04-15 13:12:50 -0400 | [diff] [blame] | 301 | |
| 302 | if (resources.EXT_shader_texture_lod) |
| 303 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 304 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, |
| 305 | "texture2DLodEXT", sampler2D, float2, float1); |
| 306 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, |
| 307 | "texture2DProjLodEXT", sampler2D, float3, float1); |
| 308 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, |
| 309 | "texture2DProjLodEXT", sampler2D, float4, float1); |
| 310 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, |
| 311 | "textureCubeLodEXT", samplerCube, float3, float1); |
Nicolas Capens | 4648508 | 2014-04-15 13:12:50 -0400 | [diff] [blame] | 312 | } |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 313 | } |
| 314 | |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 315 | if (type == GL_VERTEX_SHADER) |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 316 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 317 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLod", sampler2D, float2, |
| 318 | float1); |
| 319 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float3, |
| 320 | float1); |
| 321 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float4, |
| 322 | float1); |
| 323 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLod", samplerCube, float3, |
| 324 | float1); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 325 | } |
shannonwoods@chromium.org | c6ac65f | 2013-05-30 00:02:50 +0000 | [diff] [blame] | 326 | |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 327 | const TType *gvec4 = TCache::getType(EbtGVec4); |
Nicolas Capens | 4fd5e4a | 2014-02-14 18:17:15 -0500 | [diff] [blame] | 328 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 329 | const TType *gsampler2D = TCache::getType(EbtGSampler2D); |
| 330 | const TType *gsamplerCube = TCache::getType(EbtGSamplerCube); |
| 331 | const TType *gsampler3D = TCache::getType(EbtGSampler3D); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 332 | const TType *gsampler2DArray = TCache::getType(EbtGSampler2DArray); |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 333 | const TType *gsampler2DMS = TCache::getType(EbtGSampler2DMS); |
Nicolas Capens | 73f5bf6 | 2013-06-17 16:13:33 -0400 | [diff] [blame] | 334 | |
shannonwoods@chromium.org | c6ac65f | 2013-05-30 00:02:50 +0000 | [diff] [blame] | 335 | // |
| 336 | // Texture Functions for GLSL ES 3.0 |
| 337 | // |
Nicolas Capens | 4fd5e4a | 2014-02-14 18:17:15 -0500 | [diff] [blame] | 338 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2); |
| 339 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3); |
| 340 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3); |
| 341 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3); |
| 342 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3); |
| 343 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4); |
| 344 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4); |
| 345 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2D, float2, float1); |
| 346 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler3D, float3, float1); |
| 347 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsamplerCube, float3, float1); |
| 348 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2DArray, float3, float1); |
shannonwoods@chromium.org | c6ac65f | 2013-05-30 00:02:50 +0000 | [diff] [blame] | 349 | |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 350 | if (resources.OES_EGL_image_external_essl3) |
| 351 | { |
| 352 | const TType *samplerExternalOES = TCache::getType(EbtSamplerExternalOES); |
| 353 | |
| 354 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "texture", samplerExternalOES, float2); |
| 355 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureProj", samplerExternalOES, |
| 356 | float3); |
| 357 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureProj", samplerExternalOES, |
| 358 | float4); |
| 359 | } |
| 360 | |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 361 | if (type == GL_FRAGMENT_SHADER) |
Nicolas Capens | 67a819f | 2013-07-09 12:08:58 -0400 | [diff] [blame] | 362 | { |
Nicolas Capens | 4fd5e4a | 2014-02-14 18:17:15 -0500 | [diff] [blame] | 363 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2, float1); |
| 364 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3, float1); |
| 365 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3, float1); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 366 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3, |
| 367 | float1); |
Nicolas Capens | 4fd5e4a | 2014-02-14 18:17:15 -0500 | [diff] [blame] | 368 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3, float1); |
| 369 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4, float1); |
| 370 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4, float1); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 371 | |
| 372 | if (resources.OES_EGL_image_external_essl3) |
| 373 | { |
| 374 | const TType *samplerExternalOES = TCache::getType(EbtSamplerExternalOES); |
| 375 | |
| 376 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "texture", samplerExternalOES, float2, |
| 377 | float1); |
| 378 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureProj", samplerExternalOES, |
| 379 | float3, float1); |
| 380 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureProj", samplerExternalOES, |
| 381 | float4, float1); |
| 382 | } |
Nicolas Capens | 67a819f | 2013-07-09 12:08:58 -0400 | [diff] [blame] | 383 | } |
| 384 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 385 | const TType *sampler2DShadow = TCache::getType(EbtSampler2DShadow); |
| 386 | const TType *samplerCubeShadow = TCache::getType(EbtSamplerCubeShadow); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 387 | const TType *sampler2DArrayShadow = TCache::getType(EbtSampler2DArrayShadow); |
Nicolas Capens | 77c9d1a | 2013-07-11 11:10:34 -0400 | [diff] [blame] | 388 | |
Nicolas Capens | 8f80e02 | 2013-07-11 11:20:50 -0400 | [diff] [blame] | 389 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3); |
| 390 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4); |
| 391 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DArrayShadow, float4); |
| 392 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 393 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLod", sampler2DShadow, float3, |
| 394 | float1); |
Nicolas Capens | 77c9d1a | 2013-07-11 11:10:34 -0400 | [diff] [blame] | 395 | |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 396 | if (type == GL_FRAGMENT_SHADER) |
Nicolas Capens | 77c9d1a | 2013-07-11 11:10:34 -0400 | [diff] [blame] | 397 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 398 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3, |
| 399 | float1); |
| 400 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4, |
| 401 | float1); |
| 402 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4, |
| 403 | float1); |
Nicolas Capens | 77c9d1a | 2013-07-11 11:10:34 -0400 | [diff] [blame] | 404 | } |
| 405 | |
Nicolas Capens | 4fd5e4a | 2014-02-14 18:17:15 -0500 | [diff] [blame] | 406 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsampler2D, int1); |
| 407 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler3D, int1); |
| 408 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsamplerCube, int1); |
| 409 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler2DArray, int1); |
Nicolas Capens | 8f80e02 | 2013-07-11 11:20:50 -0400 | [diff] [blame] | 410 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", sampler2DShadow, int1); |
| 411 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", samplerCubeShadow, int1); |
| 412 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", sampler2DArrayShadow, int1); |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 413 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsampler2DMS); |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 414 | |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 415 | if (resources.OES_EGL_image_external_essl3) |
| 416 | { |
| 417 | const TType *samplerExternalOES = TCache::getType(EbtSamplerExternalOES); |
| 418 | |
| 419 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", samplerExternalOES, int1); |
| 420 | } |
| 421 | |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 422 | if (type == GL_FRAGMENT_SHADER) |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 423 | { |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame^] | 424 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpDFdx, genType, genType); |
| 425 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpDFdy, genType, genType); |
| 426 | symbolTable.insertBuiltInOp(ESSL3_BUILTINS, EOpFwidth, genType, genType); |
alokp@chromium.org | 0609889 | 2010-08-26 19:36:42 +0000 | [diff] [blame] | 427 | } |
alokp@chromium.org | e4249f0 | 2010-07-26 18:13:52 +0000 | [diff] [blame] | 428 | |
Nicolas Capens | 4fd5e4a | 2014-02-14 18:17:15 -0500 | [diff] [blame] | 429 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2); |
| 430 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 431 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, |
| 432 | int2); |
| 433 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, |
| 434 | int2); |
Nicolas Capens | 4fd5e4a | 2014-02-14 18:17:15 -0500 | [diff] [blame] | 435 | |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 436 | if (type == GL_FRAGMENT_SHADER) |
Nicolas Capens | 4fd5e4a | 2014-02-14 18:17:15 -0500 | [diff] [blame] | 437 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 438 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2, |
| 439 | float1); |
| 440 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3, |
| 441 | float1); |
| 442 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, |
| 443 | int2, float1); |
| 444 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, |
| 445 | int2, float1); |
Nicolas Capens | 4fd5e4a | 2014-02-14 18:17:15 -0500 | [diff] [blame] | 446 | } |
Nicolas Capens | 1fbc287 | 2014-01-03 14:12:09 -0500 | [diff] [blame] | 447 | |
Nicolas Capens | df86c6b | 2014-02-14 20:09:17 -0500 | [diff] [blame] | 448 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2); |
| 449 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2); |
| 450 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 451 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, |
| 452 | int2); |
Nicolas Capens | df86c6b | 2014-02-14 20:09:17 -0500 | [diff] [blame] | 453 | |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 454 | if (type == GL_FRAGMENT_SHADER) |
Nicolas Capens | df86c6b | 2014-02-14 20:09:17 -0500 | [diff] [blame] | 455 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 456 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, |
| 457 | int2, float1); |
| 458 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, |
| 459 | int2, float1); |
| 460 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, |
| 461 | int3, float1); |
| 462 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, |
| 463 | float4, int2, float1); |
Nicolas Capens | df86c6b | 2014-02-14 20:09:17 -0500 | [diff] [blame] | 464 | } |
| 465 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 466 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2D, float2, float1, |
| 467 | int2); |
| 468 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler3D, float3, float1, |
| 469 | int3); |
| 470 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLodOffset", sampler2DShadow, float3, |
| 471 | float1, int2); |
| 472 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2DArray, float3, |
| 473 | float1, int2); |
Nicolas Capens | df86c6b | 2014-02-14 20:09:17 -0500 | [diff] [blame] | 474 | |
Nicolas Capens | 2adc256 | 2014-02-14 23:50:59 -0500 | [diff] [blame] | 475 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float3, float1); |
| 476 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float4, float1); |
| 477 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler3D, float4, float1); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 478 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLod", sampler2DShadow, float4, |
| 479 | float1); |
Nicolas Capens | 2adc256 | 2014-02-14 23:50:59 -0500 | [diff] [blame] | 480 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 481 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float3, |
| 482 | float1, int2); |
| 483 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float4, |
| 484 | float1, int2); |
| 485 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler3D, float4, |
| 486 | float1, int3); |
| 487 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLodOffset", sampler2DShadow, |
| 488 | float4, float1, int2); |
Nicolas Capens | 2adc256 | 2014-02-14 23:50:59 -0500 | [diff] [blame] | 489 | |
Nicolas Capens | fc01454 | 2014-02-18 14:47:13 -0500 | [diff] [blame] | 490 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2D, int2, int1); |
| 491 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler3D, int3, int1); |
| 492 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2DArray, int3, int1); |
| 493 | |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 494 | if (resources.OES_EGL_image_external_essl3) |
| 495 | { |
| 496 | const TType *samplerExternalOES = TCache::getType(EbtSamplerExternalOES); |
| 497 | |
| 498 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "texelFetch", samplerExternalOES, int2, |
| 499 | int1); |
| 500 | } |
| 501 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 502 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2D, int2, int1, |
| 503 | int2); |
| 504 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler3D, int3, int1, |
| 505 | int3); |
| 506 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2DArray, int3, |
| 507 | int1, int2); |
Nicolas Capens | fc01454 | 2014-02-18 14:47:13 -0500 | [diff] [blame] | 508 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 509 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2D, float2, float2, |
| 510 | float2); |
| 511 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler3D, float3, float3, |
| 512 | float3); |
| 513 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsamplerCube, float3, float3, |
| 514 | float3); |
| 515 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DShadow, float3, |
| 516 | float2, float2); |
| 517 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", samplerCubeShadow, float4, |
| 518 | float3, float3); |
| 519 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2DArray, float3, float2, |
| 520 | float2); |
| 521 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DArrayShadow, float4, |
| 522 | float2, float2); |
Nicolas Capens | d11d549 | 2014-02-19 17:06:10 -0500 | [diff] [blame] | 523 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 524 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2D, float2, |
| 525 | float2, float2, int2); |
| 526 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler3D, float3, |
| 527 | float3, float3, int3); |
| 528 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DShadow, float3, |
| 529 | float2, float2, int2); |
| 530 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2DArray, float3, |
| 531 | float2, float2, int2); |
| 532 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DArrayShadow, |
| 533 | float4, float2, float2, int2); |
Nicolas Capens | bf7db10 | 2014-02-19 17:20:28 -0500 | [diff] [blame] | 534 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 535 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float3, float2, |
| 536 | float2); |
| 537 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float4, float2, |
| 538 | float2); |
| 539 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler3D, float4, float3, |
| 540 | float3); |
| 541 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGrad", sampler2DShadow, float4, |
| 542 | float2, float2); |
Nicolas Capens | f7378e3 | 2014-02-19 17:29:32 -0500 | [diff] [blame] | 543 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 544 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float3, |
| 545 | float2, float2, int2); |
| 546 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float4, |
| 547 | float2, float2, int2); |
| 548 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler3D, float4, |
| 549 | float3, float3, int3); |
| 550 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGradOffset", sampler2DShadow, |
| 551 | float4, float2, float2, int2); |
Nicolas Capens | f7378e3 | 2014-02-19 17:29:32 -0500 | [diff] [blame] | 552 | |
Martin Radev | 2cc85b3 | 2016-08-05 16:22:53 +0300 | [diff] [blame] | 553 | const TType *gimage2D = TCache::getType(EbtGImage2D); |
| 554 | const TType *gimage3D = TCache::getType(EbtGImage3D); |
| 555 | const TType *gimage2DArray = TCache::getType(EbtGImage2DArray); |
| 556 | const TType *gimageCube = TCache::getType(EbtGImageCube); |
| 557 | |
| 558 | symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, voidType, "imageStore", gimage2D, int2, gvec4); |
| 559 | symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, voidType, "imageStore", gimage3D, int3, gvec4); |
| 560 | symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, voidType, "imageStore", gimage2DArray, int3, gvec4); |
| 561 | symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, voidType, "imageStore", gimageCube, int3, gvec4); |
| 562 | |
| 563 | symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "imageLoad", gimage2D, int2); |
| 564 | symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "imageLoad", gimage3D, int3); |
| 565 | symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "imageLoad", gimage2DArray, int3); |
| 566 | symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "imageLoad", gimageCube, int3); |
| 567 | |
| 568 | symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, int2, "imageSize", gimage2D); |
| 569 | symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, int3, "imageSize", gimage3D); |
| 570 | symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, int3, "imageSize", gimage2DArray); |
Xinghua Cao | fb02830 | 2016-11-28 18:21:57 +0800 | [diff] [blame] | 571 | symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, int2, "imageSize", gimageCube); |
Martin Radev | 2cc85b3 | 2016-08-05 16:22:53 +0300 | [diff] [blame] | 572 | |
Martin Radev | d7c5b0a | 2016-07-27 14:04:43 +0300 | [diff] [blame] | 573 | symbolTable.insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpMemoryBarrier, voidType, |
| 574 | "memoryBarrier"); |
| 575 | symbolTable.insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpMemoryBarrierAtomicCounter, |
| 576 | voidType, "memoryBarrierAtomicCounter"); |
| 577 | symbolTable.insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpMemoryBarrierBuffer, |
| 578 | voidType, "memoryBarrierBuffer"); |
| 579 | symbolTable.insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpMemoryBarrierImage, voidType, |
| 580 | "memoryBarrierImage"); |
| 581 | |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 582 | symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "texelFetch", gsampler2DMS, int2, int1); |
| 583 | |
Martin Radev | d7c5b0a | 2016-07-27 14:04:43 +0300 | [diff] [blame] | 584 | if (type == GL_COMPUTE_SHADER) |
| 585 | { |
| 586 | symbolTable.insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpBarrier, voidType, |
| 587 | "barrier"); |
| 588 | symbolTable.insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpMemoryBarrierShared, |
| 589 | voidType, "memoryBarrierShared"); |
| 590 | symbolTable.insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpGroupMemoryBarrier, |
| 591 | voidType, "groupMemoryBarrier"); |
| 592 | } |
| 593 | |
alokp@chromium.org | e4249f0 | 2010-07-26 18:13:52 +0000 | [diff] [blame] | 594 | // |
| 595 | // Depth range in window coordinates |
| 596 | // |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 597 | TFieldList *fields = NewPoolTFieldList(); |
Jamie Madill | 37f77d2 | 2014-04-30 16:10:13 -0400 | [diff] [blame] | 598 | TSourceLoc zeroSourceLoc = {0, 0, 0, 0}; |
Jamie Madill | e064d44 | 2016-06-21 20:00:41 -0400 | [diff] [blame] | 599 | auto highpFloat1 = new TType(EbtFloat, EbpHigh, EvqGlobal, 1); |
| 600 | TField *near = new TField(highpFloat1, NewPoolTString("near"), zeroSourceLoc); |
| 601 | TField *far = new TField(highpFloat1, NewPoolTString("far"), zeroSourceLoc); |
| 602 | TField *diff = new TField(highpFloat1, NewPoolTString("diff"), zeroSourceLoc); |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 603 | fields->push_back(near); |
| 604 | fields->push_back(far); |
| 605 | fields->push_back(diff); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 606 | TStructure *depthRangeStruct = |
| 607 | new TStructure(NewPoolTString("gl_DepthRangeParameters"), fields); |
Jamie Madill | e064d44 | 2016-06-21 20:00:41 -0400 | [diff] [blame] | 608 | TVariable *depthRangeParameters = |
| 609 | new TVariable(&depthRangeStruct->name(), TType(depthRangeStruct), true); |
Nicolas Capens | adfffe4 | 2014-06-17 02:13:36 -0400 | [diff] [blame] | 610 | symbolTable.insert(COMMON_BUILTINS, depthRangeParameters); |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 611 | TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct)); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 612 | depthRange->setQualifier(EvqUniform); |
Jamie Madill | e064d44 | 2016-06-21 20:00:41 -0400 | [diff] [blame] | 613 | // Ensure we evaluate the mangled name for depth range, so we allocate to the current scope. |
| 614 | depthRangeParameters->getType().getMangledName(); |
| 615 | depthRange->getType().getMangledName(); |
Nicolas Capens | adfffe4 | 2014-06-17 02:13:36 -0400 | [diff] [blame] | 616 | symbolTable.insert(COMMON_BUILTINS, depthRange); |
alokp@chromium.org | e4249f0 | 2010-07-26 18:13:52 +0000 | [diff] [blame] | 617 | |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 618 | // |
| 619 | // Implementation dependent built-in constants. |
| 620 | // |
Martin Radev | e93d24e | 2016-07-28 12:06:05 +0300 | [diff] [blame] | 621 | symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexAttribs", resources.MaxVertexAttribs, |
| 622 | EbpMedium); |
| 623 | symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexUniformVectors", |
| 624 | resources.MaxVertexUniformVectors, EbpMedium); |
| 625 | symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexTextureImageUnits", |
| 626 | resources.MaxVertexTextureImageUnits, EbpMedium); |
| 627 | symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxCombinedTextureImageUnits", |
| 628 | resources.MaxCombinedTextureImageUnits, EbpMedium); |
| 629 | symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxTextureImageUnits", |
| 630 | resources.MaxTextureImageUnits, EbpMedium); |
| 631 | symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxFragmentUniformVectors", |
| 632 | resources.MaxFragmentUniformVectors, EbpMedium); |
alokp@chromium.org | e4249f0 | 2010-07-26 18:13:52 +0000 | [diff] [blame] | 633 | |
Martin Radev | e93d24e | 2016-07-28 12:06:05 +0300 | [diff] [blame] | 634 | symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxVaryingVectors", resources.MaxVaryingVectors, |
| 635 | EbpMedium); |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 636 | |
Qiankun Miao | c2c5fc4 | 2016-08-31 15:24:22 +0800 | [diff] [blame] | 637 | symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxDrawBuffers", resources.MaxDrawBuffers, |
| 638 | EbpMedium); |
| 639 | if (resources.EXT_blend_func_extended) |
shannon.woods%transgaming.com@gtempaccount.com | 5209de8 | 2013-04-13 03:41:53 +0000 | [diff] [blame] | 640 | { |
Qiankun Miao | c2c5fc4 | 2016-08-31 15:24:22 +0800 | [diff] [blame] | 641 | symbolTable.insertConstIntExt(COMMON_BUILTINS, "GL_EXT_blend_func_extended", |
| 642 | "gl_MaxDualSourceDrawBuffersEXT", |
| 643 | resources.MaxDualSourceDrawBuffers); |
shannon.woods%transgaming.com@gtempaccount.com | 5209de8 | 2013-04-13 03:41:53 +0000 | [diff] [blame] | 644 | } |
alokp@chromium.org | e4249f0 | 2010-07-26 18:13:52 +0000 | [diff] [blame] | 645 | |
Martin Radev | e93d24e | 2016-07-28 12:06:05 +0300 | [diff] [blame] | 646 | symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxVertexOutputVectors", |
| 647 | resources.MaxVertexOutputVectors, EbpMedium); |
| 648 | symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxFragmentInputVectors", |
| 649 | resources.MaxFragmentInputVectors, EbpMedium); |
| 650 | symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MinProgramTexelOffset", |
| 651 | resources.MinProgramTexelOffset, EbpMedium); |
| 652 | symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxProgramTexelOffset", |
| 653 | resources.MaxProgramTexelOffset, EbpMedium); |
| 654 | |
| 655 | symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxImageUnits", resources.MaxImageUnits, |
| 656 | EbpMedium); |
| 657 | symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxVertexImageUniforms", |
| 658 | resources.MaxVertexImageUniforms, EbpMedium); |
| 659 | symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxFragmentImageUniforms", |
| 660 | resources.MaxFragmentImageUniforms, EbpMedium); |
| 661 | symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxComputeImageUniforms", |
| 662 | resources.MaxComputeImageUniforms, EbpMedium); |
| 663 | symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxCombinedImageUniforms", |
| 664 | resources.MaxCombinedImageUniforms, EbpMedium); |
| 665 | |
| 666 | symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxCombinedShaderOutputResources", |
| 667 | resources.MaxCombinedShaderOutputResources, EbpMedium); |
| 668 | |
| 669 | symbolTable.insertConstIvec3(ESSL3_1_BUILTINS, "gl_MaxComputeWorkGroupCount", |
| 670 | resources.MaxComputeWorkGroupCount, EbpHigh); |
| 671 | symbolTable.insertConstIvec3(ESSL3_1_BUILTINS, "gl_MaxComputeWorkGroupSize", |
| 672 | resources.MaxComputeWorkGroupSize, EbpHigh); |
| 673 | symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxComputeUniformComponents", |
| 674 | resources.MaxComputeUniformComponents, EbpMedium); |
| 675 | symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxComputeTextureImageUnits", |
| 676 | resources.MaxComputeTextureImageUnits, EbpMedium); |
| 677 | |
| 678 | symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxComputeAtomicCounters", |
| 679 | resources.MaxComputeAtomicCounters, EbpMedium); |
| 680 | symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxComputeAtomicCounterBuffers", |
| 681 | resources.MaxComputeAtomicCounterBuffers, EbpMedium); |
| 682 | |
| 683 | symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxVertexAtomicCounters", |
| 684 | resources.MaxVertexAtomicCounters, EbpMedium); |
| 685 | symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxFragmentAtomicCounters", |
| 686 | resources.MaxFragmentAtomicCounters, EbpMedium); |
| 687 | symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxCombinedAtomicCounters", |
| 688 | resources.MaxCombinedAtomicCounters, EbpMedium); |
| 689 | symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxAtomicCounterBindings", |
| 690 | resources.MaxAtomicCounterBindings, EbpMedium); |
| 691 | |
| 692 | symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxVertexAtomicCounterBuffers", |
| 693 | resources.MaxVertexAtomicCounterBuffers, EbpMedium); |
| 694 | symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxFragmentAtomicCounterBuffers", |
| 695 | resources.MaxFragmentAtomicCounterBuffers, EbpMedium); |
| 696 | symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxCombinedAtomicCounterBuffers", |
| 697 | resources.MaxCombinedAtomicCounterBuffers, EbpMedium); |
| 698 | symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxAtomicCounterBufferSize", |
| 699 | resources.MaxAtomicCounterBufferSize, EbpMedium); |
alokp@chromium.org | e4249f0 | 2010-07-26 18:13:52 +0000 | [diff] [blame] | 700 | } |
| 701 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 702 | void IdentifyBuiltIns(sh::GLenum type, |
| 703 | ShShaderSpec spec, |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 704 | const ShBuiltInResources &resources, |
| 705 | TSymbolTable &symbolTable) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 706 | { |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 707 | // |
Olli Etuaho | 4f52da4 | 2015-03-11 10:48:41 +0200 | [diff] [blame] | 708 | // Insert some special built-in variables that are not in |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 709 | // the built-in header files. |
| 710 | // |
Olli Etuaho | 09b04a2 | 2016-12-15 13:30:26 +0000 | [diff] [blame] | 711 | |
| 712 | if (resources.OVR_multiview && type != GL_COMPUTE_SHADER) |
| 713 | { |
| 714 | symbolTable.insert(COMMON_BUILTINS, "GL_OVR_multiview", |
| 715 | new TVariable(NewPoolTString("gl_ViewID_OVR"), |
| 716 | TType(EbtUInt, EbpHigh, EvqViewIDOVR, 1))); |
| 717 | } |
| 718 | |
Olli Etuaho | 61ffec8 | 2015-03-11 10:35:01 +0200 | [diff] [blame] | 719 | switch (type) |
| 720 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 721 | case GL_FRAGMENT_SHADER: |
| 722 | { |
| 723 | symbolTable.insert(COMMON_BUILTINS, |
| 724 | new TVariable(NewPoolTString("gl_FragCoord"), |
| 725 | TType(EbtFloat, EbpMedium, EvqFragCoord, 4))); |
| 726 | symbolTable.insert(COMMON_BUILTINS, |
| 727 | new TVariable(NewPoolTString("gl_FrontFacing"), |
| 728 | TType(EbtBool, EbpUndefined, EvqFrontFacing, 1))); |
| 729 | symbolTable.insert(COMMON_BUILTINS, |
| 730 | new TVariable(NewPoolTString("gl_PointCoord"), |
| 731 | TType(EbtFloat, EbpMedium, EvqPointCoord, 2))); |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 732 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 733 | symbolTable.insert(ESSL1_BUILTINS, |
| 734 | new TVariable(NewPoolTString("gl_FragColor"), |
| 735 | TType(EbtFloat, EbpMedium, EvqFragColor, 4))); |
| 736 | TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, 1, true); |
| 737 | fragData.setArraySize(resources.MaxDrawBuffers); |
| 738 | symbolTable.insert(ESSL1_BUILTINS, |
| 739 | new TVariable(NewPoolTString("gl_FragData"), fragData)); |
Olli Etuaho | 4f52da4 | 2015-03-11 10:48:41 +0200 | [diff] [blame] | 740 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 741 | if (resources.EXT_blend_func_extended) |
| 742 | { |
| 743 | symbolTable.insert( |
| 744 | ESSL1_BUILTINS, "GL_EXT_blend_func_extended", |
| 745 | new TVariable(NewPoolTString("gl_SecondaryFragColorEXT"), |
| 746 | TType(EbtFloat, EbpMedium, EvqSecondaryFragColorEXT, 4))); |
| 747 | TType secondaryFragData(EbtFloat, EbpMedium, EvqSecondaryFragDataEXT, 4, 1, true); |
| 748 | secondaryFragData.setArraySize(resources.MaxDualSourceDrawBuffers); |
| 749 | symbolTable.insert( |
| 750 | ESSL1_BUILTINS, "GL_EXT_blend_func_extended", |
| 751 | new TVariable(NewPoolTString("gl_SecondaryFragDataEXT"), secondaryFragData)); |
| 752 | } |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 753 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 754 | if (resources.EXT_frag_depth) |
| 755 | { |
| 756 | symbolTable.insert( |
| 757 | ESSL1_BUILTINS, "GL_EXT_frag_depth", |
| 758 | new TVariable( |
| 759 | NewPoolTString("gl_FragDepthEXT"), |
| 760 | TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium, |
| 761 | EvqFragDepthEXT, 1))); |
| 762 | } |
Olli Etuaho | 4f52da4 | 2015-03-11 10:48:41 +0200 | [diff] [blame] | 763 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 764 | symbolTable.insert(ESSL3_BUILTINS, |
| 765 | new TVariable(NewPoolTString("gl_FragDepth"), |
| 766 | TType(EbtFloat, EbpHigh, EvqFragDepth, 1))); |
Kimmo Kinnunen | 5f0246c | 2015-07-22 10:30:35 +0300 | [diff] [blame] | 767 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 768 | if (resources.EXT_shader_framebuffer_fetch || resources.NV_shader_framebuffer_fetch) |
| 769 | { |
| 770 | TType lastFragData(EbtFloat, EbpMedium, EvqLastFragData, 4, 1, true); |
| 771 | lastFragData.setArraySize(resources.MaxDrawBuffers); |
Olli Etuaho | 4f52da4 | 2015-03-11 10:48:41 +0200 | [diff] [blame] | 772 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 773 | if (resources.EXT_shader_framebuffer_fetch) |
| 774 | { |
| 775 | symbolTable.insert( |
| 776 | ESSL1_BUILTINS, "GL_EXT_shader_framebuffer_fetch", |
| 777 | new TVariable(NewPoolTString("gl_LastFragData"), lastFragData)); |
| 778 | } |
| 779 | else if (resources.NV_shader_framebuffer_fetch) |
| 780 | { |
| 781 | symbolTable.insert( |
| 782 | ESSL1_BUILTINS, "GL_NV_shader_framebuffer_fetch", |
| 783 | new TVariable(NewPoolTString("gl_LastFragColor"), |
| 784 | TType(EbtFloat, EbpMedium, EvqLastFragColor, 4))); |
| 785 | symbolTable.insert( |
| 786 | ESSL1_BUILTINS, "GL_NV_shader_framebuffer_fetch", |
| 787 | new TVariable(NewPoolTString("gl_LastFragData"), lastFragData)); |
| 788 | } |
| 789 | } |
| 790 | else if (resources.ARM_shader_framebuffer_fetch) |
| 791 | { |
| 792 | symbolTable.insert(ESSL1_BUILTINS, "GL_ARM_shader_framebuffer_fetch", |
| 793 | new TVariable(NewPoolTString("gl_LastFragColorARM"), |
| 794 | TType(EbtFloat, EbpMedium, EvqLastFragColor, 4))); |
| 795 | } |
| 796 | } |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 797 | |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 798 | break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 799 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 800 | case GL_VERTEX_SHADER: |
| 801 | symbolTable.insert(COMMON_BUILTINS, |
| 802 | new TVariable(NewPoolTString("gl_Position"), |
| 803 | TType(EbtFloat, EbpHigh, EvqPosition, 4))); |
| 804 | symbolTable.insert(COMMON_BUILTINS, |
| 805 | new TVariable(NewPoolTString("gl_PointSize"), |
| 806 | TType(EbtFloat, EbpMedium, EvqPointSize, 1))); |
| 807 | symbolTable.insert(ESSL3_BUILTINS, |
| 808 | new TVariable(NewPoolTString("gl_InstanceID"), |
| 809 | TType(EbtInt, EbpHigh, EvqInstanceID, 1))); |
| 810 | symbolTable.insert(ESSL3_BUILTINS, |
| 811 | new TVariable(NewPoolTString("gl_VertexID"), |
| 812 | TType(EbtInt, EbpHigh, EvqVertexID, 1))); |
| 813 | break; |
| 814 | case GL_COMPUTE_SHADER: |
| 815 | { |
| 816 | symbolTable.insert(ESSL3_1_BUILTINS, |
| 817 | new TVariable(NewPoolTString("gl_NumWorkGroups"), |
| 818 | TType(EbtUInt, EbpUndefined, EvqNumWorkGroups, 3))); |
| 819 | symbolTable.insert(ESSL3_1_BUILTINS, |
| 820 | new TVariable(NewPoolTString("gl_WorkGroupSize"), |
| 821 | TType(EbtUInt, EbpUndefined, EvqWorkGroupSize, 3))); |
| 822 | symbolTable.insert(ESSL3_1_BUILTINS, |
| 823 | new TVariable(NewPoolTString("gl_WorkGroupID"), |
| 824 | TType(EbtUInt, EbpUndefined, EvqWorkGroupID, 3))); |
| 825 | symbolTable.insert( |
| 826 | ESSL3_1_BUILTINS, |
| 827 | new TVariable(NewPoolTString("gl_LocalInvocationID"), |
| 828 | TType(EbtUInt, EbpUndefined, EvqLocalInvocationID, 3))); |
| 829 | symbolTable.insert( |
| 830 | ESSL3_1_BUILTINS, |
| 831 | new TVariable(NewPoolTString("gl_GlobalInvocationID"), |
| 832 | TType(EbtUInt, EbpUndefined, EvqGlobalInvocationID, 3))); |
| 833 | symbolTable.insert( |
| 834 | ESSL3_1_BUILTINS, |
| 835 | new TVariable(NewPoolTString("gl_LocalInvocationIndex"), |
| 836 | TType(EbtUInt, EbpUndefined, EvqLocalInvocationIndex, 1))); |
| 837 | } |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 838 | break; |
Martin Radev | b088360 | 2016-08-04 17:48:58 +0300 | [diff] [blame] | 839 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 840 | default: |
| 841 | assert(false && "Language not supported"); |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 842 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 843 | } |
| 844 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 845 | void InitExtensionBehavior(const ShBuiltInResources &resources, TExtensionBehavior &extBehavior) |
alokp@chromium.org | ad771eb | 2010-09-07 17:36:23 +0000 | [diff] [blame] | 846 | { |
| 847 | if (resources.OES_standard_derivatives) |
zmo@google.com | 09c323a | 2011-08-12 18:22:25 +0000 | [diff] [blame] | 848 | extBehavior["GL_OES_standard_derivatives"] = EBhUndefined; |
| 849 | if (resources.OES_EGL_image_external) |
| 850 | extBehavior["GL_OES_EGL_image_external"] = EBhUndefined; |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 851 | if (resources.OES_EGL_image_external_essl3) |
| 852 | extBehavior["GL_OES_EGL_image_external_essl3"] = EBhUndefined; |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 853 | if (resources.NV_EGL_stream_consumer_external) |
| 854 | extBehavior["GL_NV_EGL_stream_consumer_external"] = EBhUndefined; |
kbr@chromium.org | 205fef3 | 2011-11-22 20:50:02 +0000 | [diff] [blame] | 855 | if (resources.ARB_texture_rectangle) |
| 856 | extBehavior["GL_ARB_texture_rectangle"] = EBhUndefined; |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 857 | if (resources.EXT_blend_func_extended) |
| 858 | extBehavior["GL_EXT_blend_func_extended"] = EBhUndefined; |
shannon.woods@transgaming.com | 550cd09 | 2013-02-28 23:19:54 +0000 | [diff] [blame] | 859 | if (resources.EXT_draw_buffers) |
| 860 | extBehavior["GL_EXT_draw_buffers"] = EBhUndefined; |
Jamie Madill | 2aeb26a | 2013-07-08 14:02:55 -0400 | [diff] [blame] | 861 | if (resources.EXT_frag_depth) |
| 862 | extBehavior["GL_EXT_frag_depth"] = EBhUndefined; |
Nicolas Capens | 4648508 | 2014-04-15 13:12:50 -0400 | [diff] [blame] | 863 | if (resources.EXT_shader_texture_lod) |
| 864 | extBehavior["GL_EXT_shader_texture_lod"] = EBhUndefined; |
Erik Dahlström | ea7a212 | 2014-11-17 16:15:57 +0100 | [diff] [blame] | 865 | if (resources.EXT_shader_framebuffer_fetch) |
| 866 | extBehavior["GL_EXT_shader_framebuffer_fetch"] = EBhUndefined; |
| 867 | if (resources.NV_shader_framebuffer_fetch) |
| 868 | extBehavior["GL_NV_shader_framebuffer_fetch"] = EBhUndefined; |
| 869 | if (resources.ARM_shader_framebuffer_fetch) |
| 870 | extBehavior["GL_ARM_shader_framebuffer_fetch"] = EBhUndefined; |
Olli Etuaho | 09b04a2 | 2016-12-15 13:30:26 +0000 | [diff] [blame] | 871 | if (resources.OVR_multiview) |
| 872 | { |
| 873 | extBehavior["GL_OVR_multiview"] = EBhUndefined; |
| 874 | extBehavior["GL_OVR_multiview2"] = EBhUndefined; |
| 875 | } |
alokp@chromium.org | ad771eb | 2010-09-07 17:36:23 +0000 | [diff] [blame] | 876 | } |
David Yen | 0fbd128 | 2015-02-02 14:46:09 -0800 | [diff] [blame] | 877 | |
| 878 | void ResetExtensionBehavior(TExtensionBehavior &extBehavior) |
| 879 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 880 | for (auto ext_iter = extBehavior.begin(); ext_iter != extBehavior.end(); ++ext_iter) |
David Yen | 0fbd128 | 2015-02-02 14:46:09 -0800 | [diff] [blame] | 881 | { |
| 882 | ext_iter->second = EBhUndefined; |
| 883 | } |
| 884 | } |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 885 | |
| 886 | } // namespace sh |