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 | |
| 13 | #include "compiler/Initialize.h" |
| 14 | |
| 15 | #include "compiler/intermediate.h" |
| 16 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 17 | void InsertBuiltInFunctions(ShShaderType type, const ShBuiltInResources &resources, TSymbolTable &symbolTable) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 18 | { |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 19 | TType *float1 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 1); |
| 20 | TType *float2 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 2); |
| 21 | TType *float3 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 3); |
| 22 | TType *float4 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 4); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 23 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 24 | TType *int2 = new TType(EbtInt, EbpUndefined, EvqGlobal, 2); |
| 25 | TType *int3 = new TType(EbtInt, EbpUndefined, EvqGlobal, 3); |
| 26 | TType *int4 = new TType(EbtInt, EbpUndefined, EvqGlobal, 4); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 27 | |
Nicolas Capens | 434311c | 2014-05-28 19:23:55 -0400 | [diff] [blame] | 28 | symbolTable.insertBuiltIn(float1, "radians", float1); |
| 29 | symbolTable.insertBuiltIn(float2, "radians", float2); |
| 30 | symbolTable.insertBuiltIn(float3, "radians", float3); |
| 31 | symbolTable.insertBuiltIn(float4, "radians", float4); |
| 32 | symbolTable.insertBuiltIn(float1, "degrees", float1); |
| 33 | symbolTable.insertBuiltIn(float2, "degrees", float2); |
| 34 | symbolTable.insertBuiltIn(float3, "degrees", float3); |
| 35 | symbolTable.insertBuiltIn(float4, "degrees", float4); |
| 36 | symbolTable.insertBuiltIn(float1, "sin", float1); |
| 37 | symbolTable.insertBuiltIn(float2, "sin", float2); |
| 38 | symbolTable.insertBuiltIn(float3, "sin", float3); |
| 39 | symbolTable.insertBuiltIn(float4, "sin", float4); |
| 40 | symbolTable.insertBuiltIn(float1, "cos", float1); |
| 41 | symbolTable.insertBuiltIn(float2, "cos", float2); |
| 42 | symbolTable.insertBuiltIn(float3, "cos", float3); |
| 43 | symbolTable.insertBuiltIn(float4, "cos", float4); |
| 44 | symbolTable.insertBuiltIn(float1, "tan", float1); |
| 45 | symbolTable.insertBuiltIn(float2, "tan", float2); |
| 46 | symbolTable.insertBuiltIn(float3, "tan", float3); |
| 47 | symbolTable.insertBuiltIn(float4, "tan", float4); |
| 48 | symbolTable.insertBuiltIn(float1, "asin", float1); |
| 49 | symbolTable.insertBuiltIn(float2, "asin", float2); |
| 50 | symbolTable.insertBuiltIn(float3, "asin", float3); |
| 51 | symbolTable.insertBuiltIn(float4, "asin", float4); |
| 52 | symbolTable.insertBuiltIn(float1, "acos", float1); |
| 53 | symbolTable.insertBuiltIn(float2, "acos", float2); |
| 54 | symbolTable.insertBuiltIn(float3, "acos", float3); |
| 55 | symbolTable.insertBuiltIn(float4, "acos", float4); |
| 56 | symbolTable.insertBuiltIn(float1, "atan", float1, float1); |
| 57 | symbolTable.insertBuiltIn(float2, "atan", float2, float2); |
| 58 | symbolTable.insertBuiltIn(float3, "atan", float3, float3); |
| 59 | symbolTable.insertBuiltIn(float4, "atan", float4, float4); |
| 60 | symbolTable.insertBuiltIn(float1, "atan", float1); |
| 61 | symbolTable.insertBuiltIn(float2, "atan", float2); |
| 62 | symbolTable.insertBuiltIn(float3, "atan", float3); |
| 63 | symbolTable.insertBuiltIn(float4, "atan", float4); |
| 64 | symbolTable.insertBuiltIn(float1, "pow", float1, float1); |
| 65 | symbolTable.insertBuiltIn(float2, "pow", float2, float2); |
| 66 | symbolTable.insertBuiltIn(float3, "pow", float3, float3); |
| 67 | symbolTable.insertBuiltIn(float4, "pow", float4, float4); |
| 68 | symbolTable.insertBuiltIn(float1, "exp", float1); |
| 69 | symbolTable.insertBuiltIn(float2, "exp", float2); |
| 70 | symbolTable.insertBuiltIn(float3, "exp", float3); |
| 71 | symbolTable.insertBuiltIn(float4, "exp", float4); |
| 72 | symbolTable.insertBuiltIn(float1, "log", float1); |
| 73 | symbolTable.insertBuiltIn(float2, "log", float2); |
| 74 | symbolTable.insertBuiltIn(float3, "log", float3); |
| 75 | symbolTable.insertBuiltIn(float4, "log", float4); |
| 76 | symbolTable.insertBuiltIn(float1, "exp2", float1); |
| 77 | symbolTable.insertBuiltIn(float2, "exp2", float2); |
| 78 | symbolTable.insertBuiltIn(float3, "exp2", float3); |
| 79 | symbolTable.insertBuiltIn(float4, "exp2", float4); |
| 80 | symbolTable.insertBuiltIn(float1, "log2", float1); |
| 81 | symbolTable.insertBuiltIn(float2, "log2", float2); |
| 82 | symbolTable.insertBuiltIn(float3, "log2", float3); |
| 83 | symbolTable.insertBuiltIn(float4, "log2", float4); |
| 84 | symbolTable.insertBuiltIn(float1, "sqrt", float1); |
| 85 | symbolTable.insertBuiltIn(float2, "sqrt", float2); |
| 86 | symbolTable.insertBuiltIn(float3, "sqrt", float3); |
| 87 | symbolTable.insertBuiltIn(float4, "sqrt", float4); |
| 88 | symbolTable.insertBuiltIn(float1, "inversesqrt", float1); |
| 89 | symbolTable.insertBuiltIn(float2, "inversesqrt", float2); |
| 90 | symbolTable.insertBuiltIn(float3, "inversesqrt", float3); |
| 91 | symbolTable.insertBuiltIn(float4, "inversesqrt", float4); |
| 92 | symbolTable.insertBuiltIn(float1, "abs", float1); |
| 93 | symbolTable.insertBuiltIn(float2, "abs", float2); |
| 94 | symbolTable.insertBuiltIn(float3, "abs", float3); |
| 95 | symbolTable.insertBuiltIn(float4, "abs", float4); |
| 96 | symbolTable.insertBuiltIn(float1, "sign", float1); |
| 97 | symbolTable.insertBuiltIn(float2, "sign", float2); |
| 98 | symbolTable.insertBuiltIn(float3, "sign", float3); |
| 99 | symbolTable.insertBuiltIn(float4, "sign", float4); |
| 100 | symbolTable.insertBuiltIn(float1, "floor", float1); |
| 101 | symbolTable.insertBuiltIn(float2, "floor", float2); |
| 102 | symbolTable.insertBuiltIn(float3, "floor", float3); |
| 103 | symbolTable.insertBuiltIn(float4, "floor", float4); |
| 104 | symbolTable.insertBuiltIn(float1, "ceil", float1); |
| 105 | symbolTable.insertBuiltIn(float2, "ceil", float2); |
| 106 | symbolTable.insertBuiltIn(float3, "ceil", float3); |
| 107 | symbolTable.insertBuiltIn(float4, "ceil", float4); |
| 108 | symbolTable.insertBuiltIn(float1, "fract", float1); |
| 109 | symbolTable.insertBuiltIn(float2, "fract", float2); |
| 110 | symbolTable.insertBuiltIn(float3, "fract", float3); |
| 111 | symbolTable.insertBuiltIn(float4, "fract", float4); |
| 112 | symbolTable.insertBuiltIn(float1, "mod", float1, float1); |
| 113 | symbolTable.insertBuiltIn(float2, "mod", float2, float1); |
| 114 | symbolTable.insertBuiltIn(float3, "mod", float3, float1); |
| 115 | symbolTable.insertBuiltIn(float4, "mod", float4, float1); |
| 116 | symbolTable.insertBuiltIn(float2, "mod", float2, float2); |
| 117 | symbolTable.insertBuiltIn(float3, "mod", float3, float3); |
| 118 | symbolTable.insertBuiltIn(float4, "mod", float4, float4); |
| 119 | symbolTable.insertBuiltIn(float1, "min", float1, float1); |
| 120 | symbolTable.insertBuiltIn(float2, "min", float2, float1); |
| 121 | symbolTable.insertBuiltIn(float3, "min", float3, float1); |
| 122 | symbolTable.insertBuiltIn(float4, "min", float4, float1); |
| 123 | symbolTable.insertBuiltIn(float2, "min", float2, float2); |
| 124 | symbolTable.insertBuiltIn(float3, "min", float3, float3); |
| 125 | symbolTable.insertBuiltIn(float4, "min", float4, float4); |
| 126 | symbolTable.insertBuiltIn(float1, "max", float1, float1); |
| 127 | symbolTable.insertBuiltIn(float2, "max", float2, float1); |
| 128 | symbolTable.insertBuiltIn(float3, "max", float3, float1); |
| 129 | symbolTable.insertBuiltIn(float4, "max", float4, float1); |
| 130 | symbolTable.insertBuiltIn(float2, "max", float2, float2); |
| 131 | symbolTable.insertBuiltIn(float3, "max", float3, float3); |
| 132 | symbolTable.insertBuiltIn(float4, "max", float4, float4); |
| 133 | symbolTable.insertBuiltIn(float1, "clamp", float1, float1, float1); |
| 134 | symbolTable.insertBuiltIn(float2, "clamp", float2, float1, float1); |
| 135 | symbolTable.insertBuiltIn(float3, "clamp", float3, float1, float1); |
| 136 | symbolTable.insertBuiltIn(float4, "clamp", float4, float1, float1); |
| 137 | symbolTable.insertBuiltIn(float2, "clamp", float2, float2, float2); |
| 138 | symbolTable.insertBuiltIn(float3, "clamp", float3, float3, float3); |
| 139 | symbolTable.insertBuiltIn(float4, "clamp", float4, float4, float4); |
| 140 | symbolTable.insertBuiltIn(float1, "mix", float1, float1, float1); |
| 141 | symbolTable.insertBuiltIn(float2, "mix", float2, float2, float1); |
| 142 | symbolTable.insertBuiltIn(float3, "mix", float3, float3, float1); |
| 143 | symbolTable.insertBuiltIn(float4, "mix", float4, float4, float1); |
| 144 | symbolTable.insertBuiltIn(float2, "mix", float2, float2, float2); |
| 145 | symbolTable.insertBuiltIn(float3, "mix", float3, float3, float3); |
| 146 | symbolTable.insertBuiltIn(float4, "mix", float4, float4, float4); |
| 147 | symbolTable.insertBuiltIn(float1, "step", float1, float1); |
| 148 | symbolTable.insertBuiltIn(float2, "step", float2, float2); |
| 149 | symbolTable.insertBuiltIn(float3, "step", float3, float3); |
| 150 | symbolTable.insertBuiltIn(float4, "step", float4, float4); |
| 151 | symbolTable.insertBuiltIn(float2, "step", float1, float2); |
| 152 | symbolTable.insertBuiltIn(float3, "step", float1, float3); |
| 153 | symbolTable.insertBuiltIn(float4, "step", float1, float4); |
| 154 | symbolTable.insertBuiltIn(float1, "smoothstep", float1, float1, float1); |
| 155 | symbolTable.insertBuiltIn(float2, "smoothstep", float2, float2, float2); |
| 156 | symbolTable.insertBuiltIn(float3, "smoothstep", float3, float3, float3); |
| 157 | symbolTable.insertBuiltIn(float4, "smoothstep", float4, float4, float4); |
| 158 | symbolTable.insertBuiltIn(float2, "smoothstep", float1, float1, float2); |
| 159 | symbolTable.insertBuiltIn(float3, "smoothstep", float1, float1, float3); |
| 160 | symbolTable.insertBuiltIn(float4, "smoothstep", float1, float1, float4); |
| 161 | symbolTable.insertBuiltIn(float1, "length", float1); |
| 162 | symbolTable.insertBuiltIn(float1, "length", float2); |
| 163 | symbolTable.insertBuiltIn(float1, "length", float3); |
| 164 | symbolTable.insertBuiltIn(float1, "length", float4); |
| 165 | symbolTable.insertBuiltIn(float1, "distance", float1, float1); |
| 166 | symbolTable.insertBuiltIn(float1, "distance", float2, float2); |
| 167 | symbolTable.insertBuiltIn(float1, "distance", float3, float3); |
| 168 | symbolTable.insertBuiltIn(float1, "distance", float4, float4); |
| 169 | symbolTable.insertBuiltIn(float1, "dot", float1, float1); |
| 170 | symbolTable.insertBuiltIn(float1, "dot", float2, float2); |
| 171 | symbolTable.insertBuiltIn(float1, "dot", float3, float3); |
| 172 | symbolTable.insertBuiltIn(float1, "dot", float4, float4); |
| 173 | symbolTable.insertBuiltIn(float3, "cross", float3, float3); |
| 174 | symbolTable.insertBuiltIn(float1, "normalize", float1); |
| 175 | symbolTable.insertBuiltIn(float2, "normalize", float2); |
| 176 | symbolTable.insertBuiltIn(float3, "normalize", float3); |
| 177 | symbolTable.insertBuiltIn(float4, "normalize", float4); |
| 178 | symbolTable.insertBuiltIn(float1, "faceforward", float1, float1, float1); |
| 179 | symbolTable.insertBuiltIn(float2, "faceforward", float2, float2, float2); |
| 180 | symbolTable.insertBuiltIn(float3, "faceforward", float3, float3, float3); |
| 181 | symbolTable.insertBuiltIn(float4, "faceforward", float4, float4, float4); |
| 182 | symbolTable.insertBuiltIn(float1, "reflect", float1, float1); |
| 183 | symbolTable.insertBuiltIn(float2, "reflect", float2, float2); |
| 184 | symbolTable.insertBuiltIn(float3, "reflect", float3, float3); |
| 185 | symbolTable.insertBuiltIn(float4, "reflect", float4, float4); |
| 186 | symbolTable.insertBuiltIn(float1, "refract", float1, float1, float1); |
| 187 | symbolTable.insertBuiltIn(float2, "refract", float2, float2, float1); |
| 188 | symbolTable.insertBuiltIn(float3, "refract", float3, float3, float1); |
| 189 | symbolTable.insertBuiltIn(float4, "refract", float4, float4, float1); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 190 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 191 | TType *mat2 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 2, true); |
| 192 | TType *mat3 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 3, true); |
| 193 | TType *mat4 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 4, true); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 194 | |
Nicolas Capens | 434311c | 2014-05-28 19:23:55 -0400 | [diff] [blame] | 195 | symbolTable.insertBuiltIn(mat2, "matrixCompMult", mat2, mat2); |
| 196 | symbolTable.insertBuiltIn(mat3, "matrixCompMult", mat3, mat3); |
| 197 | symbolTable.insertBuiltIn(mat4, "matrixCompMult", mat4, mat4); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 198 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 199 | TType *bool1 = new TType(EbtBool, EbpUndefined, EvqGlobal, 1); |
| 200 | TType *bool2 = new TType(EbtBool, EbpUndefined, EvqGlobal, 2); |
| 201 | TType *bool3 = new TType(EbtBool, EbpUndefined, EvqGlobal, 3); |
| 202 | TType *bool4 = new TType(EbtBool, EbpUndefined, EvqGlobal, 4); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 203 | |
Nicolas Capens | 434311c | 2014-05-28 19:23:55 -0400 | [diff] [blame] | 204 | symbolTable.insertBuiltIn(bool2, "lessThan", float2, float2); |
| 205 | symbolTable.insertBuiltIn(bool3, "lessThan", float3, float3); |
| 206 | symbolTable.insertBuiltIn(bool4, "lessThan", float4, float4); |
| 207 | symbolTable.insertBuiltIn(bool2, "lessThan", int2, int2); |
| 208 | symbolTable.insertBuiltIn(bool3, "lessThan", int3, int3); |
| 209 | symbolTable.insertBuiltIn(bool4, "lessThan", int4, int4); |
| 210 | symbolTable.insertBuiltIn(bool2, "lessThanEqual", float2, float2); |
| 211 | symbolTable.insertBuiltIn(bool3, "lessThanEqual", float3, float3); |
| 212 | symbolTable.insertBuiltIn(bool4, "lessThanEqual", float4, float4); |
| 213 | symbolTable.insertBuiltIn(bool2, "lessThanEqual", int2, int2); |
| 214 | symbolTable.insertBuiltIn(bool3, "lessThanEqual", int3, int3); |
| 215 | symbolTable.insertBuiltIn(bool4, "lessThanEqual", int4, int4); |
| 216 | symbolTable.insertBuiltIn(bool2, "greaterThan", float2, float2); |
| 217 | symbolTable.insertBuiltIn(bool3, "greaterThan", float3, float3); |
| 218 | symbolTable.insertBuiltIn(bool4, "greaterThan", float4, float4); |
| 219 | symbolTable.insertBuiltIn(bool2, "greaterThan", int2, int2); |
| 220 | symbolTable.insertBuiltIn(bool3, "greaterThan", int3, int3); |
| 221 | symbolTable.insertBuiltIn(bool4, "greaterThan", int4, int4); |
| 222 | symbolTable.insertBuiltIn(bool2, "greaterThanEqual", float2, float2); |
| 223 | symbolTable.insertBuiltIn(bool3, "greaterThanEqual", float3, float3); |
| 224 | symbolTable.insertBuiltIn(bool4, "greaterThanEqual", float4, float4); |
| 225 | symbolTable.insertBuiltIn(bool2, "greaterThanEqual", int2, int2); |
| 226 | symbolTable.insertBuiltIn(bool3, "greaterThanEqual", int3, int3); |
| 227 | symbolTable.insertBuiltIn(bool4, "greaterThanEqual", int4, int4); |
| 228 | symbolTable.insertBuiltIn(bool2, "equal", float2, float2); |
| 229 | symbolTable.insertBuiltIn(bool3, "equal", float3, float3); |
| 230 | symbolTable.insertBuiltIn(bool4, "equal", float4, float4); |
| 231 | symbolTable.insertBuiltIn(bool2, "equal", int2, int2); |
| 232 | symbolTable.insertBuiltIn(bool3, "equal", int3, int3); |
| 233 | symbolTable.insertBuiltIn(bool4, "equal", int4, int4); |
| 234 | symbolTable.insertBuiltIn(bool2, "equal", bool2, bool2); |
| 235 | symbolTable.insertBuiltIn(bool3, "equal", bool3, bool3); |
| 236 | symbolTable.insertBuiltIn(bool4, "equal", bool4, bool4); |
| 237 | symbolTable.insertBuiltIn(bool2, "notEqual", float2, float2); |
| 238 | symbolTable.insertBuiltIn(bool3, "notEqual", float3, float3); |
| 239 | symbolTable.insertBuiltIn(bool4, "notEqual", float4, float4); |
| 240 | symbolTable.insertBuiltIn(bool2, "notEqual", int2, int2); |
| 241 | symbolTable.insertBuiltIn(bool3, "notEqual", int3, int3); |
| 242 | symbolTable.insertBuiltIn(bool4, "notEqual", int4, int4); |
| 243 | symbolTable.insertBuiltIn(bool2, "notEqual", bool2, bool2); |
| 244 | symbolTable.insertBuiltIn(bool3, "notEqual", bool3, bool3); |
| 245 | symbolTable.insertBuiltIn(bool4, "notEqual", bool4, bool4); |
| 246 | symbolTable.insertBuiltIn(bool1, "any", bool2); |
| 247 | symbolTable.insertBuiltIn(bool1, "any", bool3); |
| 248 | symbolTable.insertBuiltIn(bool1, "any", bool4); |
| 249 | symbolTable.insertBuiltIn(bool1, "all", bool2); |
| 250 | symbolTable.insertBuiltIn(bool1, "all", bool3); |
| 251 | symbolTable.insertBuiltIn(bool1, "all", bool4); |
| 252 | symbolTable.insertBuiltIn(bool2, "not", bool2); |
| 253 | symbolTable.insertBuiltIn(bool3, "not", bool3); |
| 254 | symbolTable.insertBuiltIn(bool4, "not", bool4); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 255 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 256 | TType *sampler2D = new TType(EbtSampler2D, EbpUndefined, EvqGlobal, 1); |
| 257 | TType *samplerCube = new TType(EbtSamplerCube, EbpUndefined, EvqGlobal, 1); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 258 | |
Nicolas Capens | 434311c | 2014-05-28 19:23:55 -0400 | [diff] [blame] | 259 | symbolTable.insertBuiltIn(float4, "texture2D", sampler2D, float2); |
| 260 | symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float3); |
| 261 | symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float4); |
| 262 | symbolTable.insertBuiltIn(float4, "textureCube", samplerCube, float3); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 263 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 264 | if(type == SH_FRAGMENT_SHADER) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 265 | { |
Nicolas Capens | 434311c | 2014-05-28 19:23:55 -0400 | [diff] [blame] | 266 | symbolTable.insertBuiltIn(float4, "texture2D", sampler2D, float2, float1); |
| 267 | symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float3, float1); |
| 268 | symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float4, float1); |
| 269 | symbolTable.insertBuiltIn(float4, "textureCube", samplerCube, float3, float1); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 270 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 271 | if (resources.OES_standard_derivatives) |
| 272 | { |
Nicolas Capens | 434311c | 2014-05-28 19:23:55 -0400 | [diff] [blame] | 273 | symbolTable.insertBuiltIn(float1, "dFdx", float1); |
| 274 | symbolTable.insertBuiltIn(float2, "dFdx", float2); |
| 275 | symbolTable.insertBuiltIn(float3, "dFdx", float3); |
| 276 | symbolTable.insertBuiltIn(float4, "dFdx", float4); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 277 | |
Nicolas Capens | 434311c | 2014-05-28 19:23:55 -0400 | [diff] [blame] | 278 | symbolTable.insertBuiltIn(float1, "dFdy", float1); |
| 279 | symbolTable.insertBuiltIn(float2, "dFdy", float2); |
| 280 | symbolTable.insertBuiltIn(float3, "dFdy", float3); |
| 281 | symbolTable.insertBuiltIn(float4, "dFdy", float4); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 282 | |
Nicolas Capens | 434311c | 2014-05-28 19:23:55 -0400 | [diff] [blame] | 283 | symbolTable.insertBuiltIn(float1, "fwidth", float1); |
| 284 | symbolTable.insertBuiltIn(float2, "fwidth", float2); |
| 285 | symbolTable.insertBuiltIn(float3, "fwidth", float3); |
| 286 | symbolTable.insertBuiltIn(float4, "fwidth", float4); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 287 | } |
| 288 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 289 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 290 | if(type == SH_VERTEX_SHADER) |
| 291 | { |
Nicolas Capens | 434311c | 2014-05-28 19:23:55 -0400 | [diff] [blame] | 292 | symbolTable.insertBuiltIn(float4, "texture2DLod", sampler2D, float2, float1); |
| 293 | symbolTable.insertBuiltIn(float4, "texture2DProjLod", sampler2D, float3, float1); |
| 294 | symbolTable.insertBuiltIn(float4, "texture2DProjLod", sampler2D, float4, float1); |
| 295 | symbolTable.insertBuiltIn(float4, "textureCubeLod", samplerCube, float3, float1); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 296 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 297 | |
Nicolas Capens | e9c5e4f | 2014-05-28 22:46:43 -0400 | [diff] [blame^] | 298 | TType *samplerExternalOES = new TType(EbtSamplerExternalOES, EbpUndefined, EvqGlobal, 1); |
| 299 | |
| 300 | if(resources.OES_EGL_image_external) |
| 301 | { |
| 302 | symbolTable.insertBuiltIn(float4, "texture2D", samplerExternalOES, float2); |
| 303 | symbolTable.insertBuiltIn(float4, "texture2DProj", samplerExternalOES, float3); |
| 304 | symbolTable.insertBuiltIn(float4, "texture2DProj", samplerExternalOES, float4); |
| 305 | } |
| 306 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 307 | TTypeList *members = NewPoolTTypeList(); |
| 308 | TTypeLine near = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0}; |
| 309 | TTypeLine far = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0}; |
| 310 | TTypeLine diff = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0}; |
| 311 | near.type->setFieldName("near"); |
| 312 | far.type->setFieldName("far"); |
| 313 | diff.type->setFieldName("diff"); |
| 314 | members->push_back(near); |
| 315 | members->push_back(far); |
| 316 | members->push_back(diff); |
| 317 | TVariable *depthRangeParameters = new TVariable(NewPoolTString("gl_DepthRangeParameters"), TType(members, "gl_DepthRangeParameters"), true); |
| 318 | symbolTable.insert(*depthRangeParameters); |
| 319 | TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(members, "gl_DepthRangeParameters")); |
| 320 | depthRange->setQualifier(EvqUniform); |
| 321 | symbolTable.insert(*depthRange); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 322 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 323 | symbolTable.insertConstInt("gl_MaxVertexAttribs", resources.MaxVertexAttribs); |
| 324 | symbolTable.insertConstInt("gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors); |
| 325 | symbolTable.insertConstInt("gl_MaxVaryingVectors", resources.MaxVaryingVectors); |
| 326 | symbolTable.insertConstInt("gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits); |
| 327 | symbolTable.insertConstInt("gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits); |
| 328 | symbolTable.insertConstInt("gl_MaxTextureImageUnits", resources.MaxTextureImageUnits); |
| 329 | symbolTable.insertConstInt("gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors); |
| 330 | symbolTable.insertConstInt("gl_MaxDrawBuffers", resources.MaxDrawBuffers); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec, |
| 334 | const ShBuiltInResources& resources, |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 335 | TSymbolTable &symbolTable) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 336 | { |
| 337 | // |
| 338 | // First, insert some special built-in variables that are not in |
| 339 | // the built-in header files. |
| 340 | // |
| 341 | switch(type) { |
| 342 | case SH_FRAGMENT_SHADER: |
| 343 | symbolTable.insert(*new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4))); |
| 344 | symbolTable.insert(*new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1))); |
| 345 | symbolTable.insert(*new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4))); |
| 346 | symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4))); |
| 347 | symbolTable.insert(*new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2))); |
| 348 | break; |
| 349 | case SH_VERTEX_SHADER: |
| 350 | symbolTable.insert(*new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4))); |
| 351 | symbolTable.insert(*new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1))); |
| 352 | break; |
| 353 | default: assert(false && "Language not supported"); |
| 354 | } |
| 355 | |
| 356 | // |
| 357 | // Next, identify which built-ins from the already loaded headers have |
| 358 | // a mapping to an operator. Those that are not identified as such are |
| 359 | // expected to be resolved through a library of functions, versus as |
| 360 | // operations. |
| 361 | // |
| 362 | symbolTable.relateToOperator("not", EOpVectorLogicalNot); |
| 363 | |
| 364 | symbolTable.relateToOperator("matrixCompMult", EOpMul); |
| 365 | |
| 366 | symbolTable.relateToOperator("equal", EOpVectorEqual); |
| 367 | symbolTable.relateToOperator("notEqual", EOpVectorNotEqual); |
| 368 | symbolTable.relateToOperator("lessThan", EOpLessThan); |
| 369 | symbolTable.relateToOperator("greaterThan", EOpGreaterThan); |
| 370 | symbolTable.relateToOperator("lessThanEqual", EOpLessThanEqual); |
| 371 | symbolTable.relateToOperator("greaterThanEqual", EOpGreaterThanEqual); |
| 372 | |
| 373 | symbolTable.relateToOperator("radians", EOpRadians); |
| 374 | symbolTable.relateToOperator("degrees", EOpDegrees); |
| 375 | symbolTable.relateToOperator("sin", EOpSin); |
| 376 | symbolTable.relateToOperator("cos", EOpCos); |
| 377 | symbolTable.relateToOperator("tan", EOpTan); |
| 378 | symbolTable.relateToOperator("asin", EOpAsin); |
| 379 | symbolTable.relateToOperator("acos", EOpAcos); |
| 380 | symbolTable.relateToOperator("atan", EOpAtan); |
| 381 | |
| 382 | symbolTable.relateToOperator("pow", EOpPow); |
| 383 | symbolTable.relateToOperator("exp2", EOpExp2); |
| 384 | symbolTable.relateToOperator("log", EOpLog); |
| 385 | symbolTable.relateToOperator("exp", EOpExp); |
| 386 | symbolTable.relateToOperator("log2", EOpLog2); |
| 387 | symbolTable.relateToOperator("sqrt", EOpSqrt); |
| 388 | symbolTable.relateToOperator("inversesqrt", EOpInverseSqrt); |
| 389 | |
| 390 | symbolTable.relateToOperator("abs", EOpAbs); |
| 391 | symbolTable.relateToOperator("sign", EOpSign); |
| 392 | symbolTable.relateToOperator("floor", EOpFloor); |
| 393 | symbolTable.relateToOperator("ceil", EOpCeil); |
| 394 | symbolTable.relateToOperator("fract", EOpFract); |
| 395 | symbolTable.relateToOperator("mod", EOpMod); |
| 396 | symbolTable.relateToOperator("min", EOpMin); |
| 397 | symbolTable.relateToOperator("max", EOpMax); |
| 398 | symbolTable.relateToOperator("clamp", EOpClamp); |
| 399 | symbolTable.relateToOperator("mix", EOpMix); |
| 400 | symbolTable.relateToOperator("step", EOpStep); |
| 401 | symbolTable.relateToOperator("smoothstep", EOpSmoothStep); |
| 402 | |
| 403 | symbolTable.relateToOperator("length", EOpLength); |
| 404 | symbolTable.relateToOperator("distance", EOpDistance); |
| 405 | symbolTable.relateToOperator("dot", EOpDot); |
| 406 | symbolTable.relateToOperator("cross", EOpCross); |
| 407 | symbolTable.relateToOperator("normalize", EOpNormalize); |
| 408 | symbolTable.relateToOperator("faceforward", EOpFaceForward); |
| 409 | symbolTable.relateToOperator("reflect", EOpReflect); |
| 410 | symbolTable.relateToOperator("refract", EOpRefract); |
| 411 | |
| 412 | symbolTable.relateToOperator("any", EOpAny); |
| 413 | symbolTable.relateToOperator("all", EOpAll); |
| 414 | |
| 415 | // Map language-specific operators. |
| 416 | switch(type) { |
| 417 | case SH_VERTEX_SHADER: |
| 418 | break; |
| 419 | case SH_FRAGMENT_SHADER: |
| 420 | if (resources.OES_standard_derivatives) { |
| 421 | symbolTable.relateToOperator("dFdx", EOpDFdx); |
| 422 | symbolTable.relateToOperator("dFdy", EOpDFdy); |
| 423 | symbolTable.relateToOperator("fwidth", EOpFwidth); |
| 424 | |
| 425 | symbolTable.relateToExtension("dFdx", "GL_OES_standard_derivatives"); |
| 426 | symbolTable.relateToExtension("dFdy", "GL_OES_standard_derivatives"); |
| 427 | symbolTable.relateToExtension("fwidth", "GL_OES_standard_derivatives"); |
| 428 | } |
| 429 | break; |
| 430 | default: break; |
| 431 | } |
| 432 | |
| 433 | // Finally add resource-specific variables. |
| 434 | switch(type) |
| 435 | { |
| 436 | case SH_FRAGMENT_SHADER: |
| 437 | { |
| 438 | // Set up gl_FragData. The array size. |
| 439 | TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, false, true); |
| 440 | fragData.setArraySize(resources.MaxDrawBuffers); |
| 441 | symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData"), fragData)); |
| 442 | } |
| 443 | break; |
| 444 | default: break; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | void InitExtensionBehavior(const ShBuiltInResources& resources, |
| 449 | TExtensionBehavior& extBehavior) |
| 450 | { |
| 451 | if (resources.OES_standard_derivatives) |
| 452 | extBehavior["GL_OES_standard_derivatives"] = EBhUndefined; |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 453 | if (resources.OES_fragment_precision_high) |
| 454 | extBehavior["GL_FRAGMENT_PRECISION_HIGH"] = EBhUndefined; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 455 | } |