michael@0: // michael@0: // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: // michael@0: // Create strings that declare built-in definitions, add built-ins that michael@0: // cannot be expressed in the files, and establish mappings between michael@0: // built-in functions and operators. michael@0: // michael@0: michael@0: #include "compiler/Initialize.h" michael@0: michael@0: #include "compiler/intermediate.h" michael@0: michael@0: void InsertBuiltInFunctions(ShShaderType type, ShShaderSpec spec, const ShBuiltInResources &resources, TSymbolTable &symbolTable) michael@0: { michael@0: TType *float1 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 1); michael@0: TType *float2 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 2); michael@0: TType *float3 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 3); michael@0: TType *float4 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 4); michael@0: michael@0: TType *int2 = new TType(EbtInt, EbpUndefined, EvqGlobal, 2); michael@0: TType *int3 = new TType(EbtInt, EbpUndefined, EvqGlobal, 3); michael@0: TType *int4 = new TType(EbtInt, EbpUndefined, EvqGlobal, 4); michael@0: michael@0: // michael@0: // Angle and Trigonometric Functions. michael@0: // michael@0: symbolTable.insertBuiltIn(float1, "radians", float1); michael@0: symbolTable.insertBuiltIn(float2, "radians", float2); michael@0: symbolTable.insertBuiltIn(float3, "radians", float3); michael@0: symbolTable.insertBuiltIn(float4, "radians", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "degrees", float1); michael@0: symbolTable.insertBuiltIn(float2, "degrees", float2); michael@0: symbolTable.insertBuiltIn(float3, "degrees", float3); michael@0: symbolTable.insertBuiltIn(float4, "degrees", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "sin", float1); michael@0: symbolTable.insertBuiltIn(float2, "sin", float2); michael@0: symbolTable.insertBuiltIn(float3, "sin", float3); michael@0: symbolTable.insertBuiltIn(float4, "sin", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "cos", float1); michael@0: symbolTable.insertBuiltIn(float2, "cos", float2); michael@0: symbolTable.insertBuiltIn(float3, "cos", float3); michael@0: symbolTable.insertBuiltIn(float4, "cos", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "tan", float1); michael@0: symbolTable.insertBuiltIn(float2, "tan", float2); michael@0: symbolTable.insertBuiltIn(float3, "tan", float3); michael@0: symbolTable.insertBuiltIn(float4, "tan", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "asin", float1); michael@0: symbolTable.insertBuiltIn(float2, "asin", float2); michael@0: symbolTable.insertBuiltIn(float3, "asin", float3); michael@0: symbolTable.insertBuiltIn(float4, "asin", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "acos", float1); michael@0: symbolTable.insertBuiltIn(float2, "acos", float2); michael@0: symbolTable.insertBuiltIn(float3, "acos", float3); michael@0: symbolTable.insertBuiltIn(float4, "acos", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "atan", float1, float1); michael@0: symbolTable.insertBuiltIn(float2, "atan", float2, float2); michael@0: symbolTable.insertBuiltIn(float3, "atan", float3, float3); michael@0: symbolTable.insertBuiltIn(float4, "atan", float4, float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "atan", float1); michael@0: symbolTable.insertBuiltIn(float2, "atan", float2); michael@0: symbolTable.insertBuiltIn(float3, "atan", float3); michael@0: symbolTable.insertBuiltIn(float4, "atan", float4); michael@0: michael@0: // michael@0: // Exponential Functions. michael@0: // michael@0: symbolTable.insertBuiltIn(float1, "pow", float1, float1); michael@0: symbolTable.insertBuiltIn(float2, "pow", float2, float2); michael@0: symbolTable.insertBuiltIn(float3, "pow", float3, float3); michael@0: symbolTable.insertBuiltIn(float4, "pow", float4, float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "exp", float1); michael@0: symbolTable.insertBuiltIn(float2, "exp", float2); michael@0: symbolTable.insertBuiltIn(float3, "exp", float3); michael@0: symbolTable.insertBuiltIn(float4, "exp", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "log", float1); michael@0: symbolTable.insertBuiltIn(float2, "log", float2); michael@0: symbolTable.insertBuiltIn(float3, "log", float3); michael@0: symbolTable.insertBuiltIn(float4, "log", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "exp2", float1); michael@0: symbolTable.insertBuiltIn(float2, "exp2", float2); michael@0: symbolTable.insertBuiltIn(float3, "exp2", float3); michael@0: symbolTable.insertBuiltIn(float4, "exp2", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "log2", float1); michael@0: symbolTable.insertBuiltIn(float2, "log2", float2); michael@0: symbolTable.insertBuiltIn(float3, "log2", float3); michael@0: symbolTable.insertBuiltIn(float4, "log2", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "sqrt", float1); michael@0: symbolTable.insertBuiltIn(float2, "sqrt", float2); michael@0: symbolTable.insertBuiltIn(float3, "sqrt", float3); michael@0: symbolTable.insertBuiltIn(float4, "sqrt", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "inversesqrt", float1); michael@0: symbolTable.insertBuiltIn(float2, "inversesqrt", float2); michael@0: symbolTable.insertBuiltIn(float3, "inversesqrt", float3); michael@0: symbolTable.insertBuiltIn(float4, "inversesqrt", float4); michael@0: michael@0: // michael@0: // Common Functions. michael@0: // michael@0: symbolTable.insertBuiltIn(float1, "abs", float1); michael@0: symbolTable.insertBuiltIn(float2, "abs", float2); michael@0: symbolTable.insertBuiltIn(float3, "abs", float3); michael@0: symbolTable.insertBuiltIn(float4, "abs", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "sign", float1); michael@0: symbolTable.insertBuiltIn(float2, "sign", float2); michael@0: symbolTable.insertBuiltIn(float3, "sign", float3); michael@0: symbolTable.insertBuiltIn(float4, "sign", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "floor", float1); michael@0: symbolTable.insertBuiltIn(float2, "floor", float2); michael@0: symbolTable.insertBuiltIn(float3, "floor", float3); michael@0: symbolTable.insertBuiltIn(float4, "floor", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "ceil", float1); michael@0: symbolTable.insertBuiltIn(float2, "ceil", float2); michael@0: symbolTable.insertBuiltIn(float3, "ceil", float3); michael@0: symbolTable.insertBuiltIn(float4, "ceil", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "fract", float1); michael@0: symbolTable.insertBuiltIn(float2, "fract", float2); michael@0: symbolTable.insertBuiltIn(float3, "fract", float3); michael@0: symbolTable.insertBuiltIn(float4, "fract", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "mod", float1, float1); michael@0: symbolTable.insertBuiltIn(float2, "mod", float2, float1); michael@0: symbolTable.insertBuiltIn(float3, "mod", float3, float1); michael@0: symbolTable.insertBuiltIn(float4, "mod", float4, float1); michael@0: symbolTable.insertBuiltIn(float2, "mod", float2, float2); michael@0: symbolTable.insertBuiltIn(float3, "mod", float3, float3); michael@0: symbolTable.insertBuiltIn(float4, "mod", float4, float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "min", float1, float1); michael@0: symbolTable.insertBuiltIn(float2, "min", float2, float1); michael@0: symbolTable.insertBuiltIn(float3, "min", float3, float1); michael@0: symbolTable.insertBuiltIn(float4, "min", float4, float1); michael@0: symbolTable.insertBuiltIn(float2, "min", float2, float2); michael@0: symbolTable.insertBuiltIn(float3, "min", float3, float3); michael@0: symbolTable.insertBuiltIn(float4, "min", float4, float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "max", float1, float1); michael@0: symbolTable.insertBuiltIn(float2, "max", float2, float1); michael@0: symbolTable.insertBuiltIn(float3, "max", float3, float1); michael@0: symbolTable.insertBuiltIn(float4, "max", float4, float1); michael@0: symbolTable.insertBuiltIn(float2, "max", float2, float2); michael@0: symbolTable.insertBuiltIn(float3, "max", float3, float3); michael@0: symbolTable.insertBuiltIn(float4, "max", float4, float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "clamp", float1, float1, float1); michael@0: symbolTable.insertBuiltIn(float2, "clamp", float2, float1, float1); michael@0: symbolTable.insertBuiltIn(float3, "clamp", float3, float1, float1); michael@0: symbolTable.insertBuiltIn(float4, "clamp", float4, float1, float1); michael@0: symbolTable.insertBuiltIn(float2, "clamp", float2, float2, float2); michael@0: symbolTable.insertBuiltIn(float3, "clamp", float3, float3, float3); michael@0: symbolTable.insertBuiltIn(float4, "clamp", float4, float4, float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "mix", float1, float1, float1); michael@0: symbolTable.insertBuiltIn(float2, "mix", float2, float2, float1); michael@0: symbolTable.insertBuiltIn(float3, "mix", float3, float3, float1); michael@0: symbolTable.insertBuiltIn(float4, "mix", float4, float4, float1); michael@0: symbolTable.insertBuiltIn(float2, "mix", float2, float2, float2); michael@0: symbolTable.insertBuiltIn(float3, "mix", float3, float3, float3); michael@0: symbolTable.insertBuiltIn(float4, "mix", float4, float4, float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "step", float1, float1); michael@0: symbolTable.insertBuiltIn(float2, "step", float2, float2); michael@0: symbolTable.insertBuiltIn(float3, "step", float3, float3); michael@0: symbolTable.insertBuiltIn(float4, "step", float4, float4); michael@0: symbolTable.insertBuiltIn(float2, "step", float1, float2); michael@0: symbolTable.insertBuiltIn(float3, "step", float1, float3); michael@0: symbolTable.insertBuiltIn(float4, "step", float1, float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "smoothstep", float1, float1, float1); michael@0: symbolTable.insertBuiltIn(float2, "smoothstep", float2, float2, float2); michael@0: symbolTable.insertBuiltIn(float3, "smoothstep", float3, float3, float3); michael@0: symbolTable.insertBuiltIn(float4, "smoothstep", float4, float4, float4); michael@0: symbolTable.insertBuiltIn(float2, "smoothstep", float1, float1, float2); michael@0: symbolTable.insertBuiltIn(float3, "smoothstep", float1, float1, float3); michael@0: symbolTable.insertBuiltIn(float4, "smoothstep", float1, float1, float4); michael@0: michael@0: // michael@0: // Geometric Functions. michael@0: // michael@0: symbolTable.insertBuiltIn(float1, "length", float1); michael@0: symbolTable.insertBuiltIn(float1, "length", float2); michael@0: symbolTable.insertBuiltIn(float1, "length", float3); michael@0: symbolTable.insertBuiltIn(float1, "length", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "distance", float1, float1); michael@0: symbolTable.insertBuiltIn(float1, "distance", float2, float2); michael@0: symbolTable.insertBuiltIn(float1, "distance", float3, float3); michael@0: symbolTable.insertBuiltIn(float1, "distance", float4, float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "dot", float1, float1); michael@0: symbolTable.insertBuiltIn(float1, "dot", float2, float2); michael@0: symbolTable.insertBuiltIn(float1, "dot", float3, float3); michael@0: symbolTable.insertBuiltIn(float1, "dot", float4, float4); michael@0: michael@0: symbolTable.insertBuiltIn(float3, "cross", float3, float3); michael@0: symbolTable.insertBuiltIn(float1, "normalize", float1); michael@0: symbolTable.insertBuiltIn(float2, "normalize", float2); michael@0: symbolTable.insertBuiltIn(float3, "normalize", float3); michael@0: symbolTable.insertBuiltIn(float4, "normalize", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "faceforward", float1, float1, float1); michael@0: symbolTable.insertBuiltIn(float2, "faceforward", float2, float2, float2); michael@0: symbolTable.insertBuiltIn(float3, "faceforward", float3, float3, float3); michael@0: symbolTable.insertBuiltIn(float4, "faceforward", float4, float4, float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "reflect", float1, float1); michael@0: symbolTable.insertBuiltIn(float2, "reflect", float2, float2); michael@0: symbolTable.insertBuiltIn(float3, "reflect", float3, float3); michael@0: symbolTable.insertBuiltIn(float4, "reflect", float4, float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "refract", float1, float1, float1); michael@0: symbolTable.insertBuiltIn(float2, "refract", float2, float2, float1); michael@0: symbolTable.insertBuiltIn(float3, "refract", float3, float3, float1); michael@0: symbolTable.insertBuiltIn(float4, "refract", float4, float4, float1); michael@0: michael@0: TType *mat2 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 2, true); michael@0: TType *mat3 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 3, true); michael@0: TType *mat4 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 4, true); michael@0: michael@0: // michael@0: // Matrix Functions. michael@0: // michael@0: symbolTable.insertBuiltIn(mat2, "matrixCompMult", mat2, mat2); michael@0: symbolTable.insertBuiltIn(mat3, "matrixCompMult", mat3, mat3); michael@0: symbolTable.insertBuiltIn(mat4, "matrixCompMult", mat4, mat4); michael@0: michael@0: TType *bool1 = new TType(EbtBool, EbpUndefined, EvqGlobal, 1); michael@0: TType *bool2 = new TType(EbtBool, EbpUndefined, EvqGlobal, 2); michael@0: TType *bool3 = new TType(EbtBool, EbpUndefined, EvqGlobal, 3); michael@0: TType *bool4 = new TType(EbtBool, EbpUndefined, EvqGlobal, 4); michael@0: michael@0: // michael@0: // Vector relational functions. michael@0: // michael@0: symbolTable.insertBuiltIn(bool2, "lessThan", float2, float2); michael@0: symbolTable.insertBuiltIn(bool3, "lessThan", float3, float3); michael@0: symbolTable.insertBuiltIn(bool4, "lessThan", float4, float4); michael@0: michael@0: symbolTable.insertBuiltIn(bool2, "lessThan", int2, int2); michael@0: symbolTable.insertBuiltIn(bool3, "lessThan", int3, int3); michael@0: symbolTable.insertBuiltIn(bool4, "lessThan", int4, int4); michael@0: michael@0: symbolTable.insertBuiltIn(bool2, "lessThanEqual", float2, float2); michael@0: symbolTable.insertBuiltIn(bool3, "lessThanEqual", float3, float3); michael@0: symbolTable.insertBuiltIn(bool4, "lessThanEqual", float4, float4); michael@0: michael@0: symbolTable.insertBuiltIn(bool2, "lessThanEqual", int2, int2); michael@0: symbolTable.insertBuiltIn(bool3, "lessThanEqual", int3, int3); michael@0: symbolTable.insertBuiltIn(bool4, "lessThanEqual", int4, int4); michael@0: michael@0: symbolTable.insertBuiltIn(bool2, "greaterThan", float2, float2); michael@0: symbolTable.insertBuiltIn(bool3, "greaterThan", float3, float3); michael@0: symbolTable.insertBuiltIn(bool4, "greaterThan", float4, float4); michael@0: michael@0: symbolTable.insertBuiltIn(bool2, "greaterThan", int2, int2); michael@0: symbolTable.insertBuiltIn(bool3, "greaterThan", int3, int3); michael@0: symbolTable.insertBuiltIn(bool4, "greaterThan", int4, int4); michael@0: michael@0: symbolTable.insertBuiltIn(bool2, "greaterThanEqual", float2, float2); michael@0: symbolTable.insertBuiltIn(bool3, "greaterThanEqual", float3, float3); michael@0: symbolTable.insertBuiltIn(bool4, "greaterThanEqual", float4, float4); michael@0: michael@0: symbolTable.insertBuiltIn(bool2, "greaterThanEqual", int2, int2); michael@0: symbolTable.insertBuiltIn(bool3, "greaterThanEqual", int3, int3); michael@0: symbolTable.insertBuiltIn(bool4, "greaterThanEqual", int4, int4); michael@0: michael@0: symbolTable.insertBuiltIn(bool2, "equal", float2, float2); michael@0: symbolTable.insertBuiltIn(bool3, "equal", float3, float3); michael@0: symbolTable.insertBuiltIn(bool4, "equal", float4, float4); michael@0: michael@0: symbolTable.insertBuiltIn(bool2, "equal", int2, int2); michael@0: symbolTable.insertBuiltIn(bool3, "equal", int3, int3); michael@0: symbolTable.insertBuiltIn(bool4, "equal", int4, int4); michael@0: michael@0: symbolTable.insertBuiltIn(bool2, "equal", bool2, bool2); michael@0: symbolTable.insertBuiltIn(bool3, "equal", bool3, bool3); michael@0: symbolTable.insertBuiltIn(bool4, "equal", bool4, bool4); michael@0: michael@0: symbolTable.insertBuiltIn(bool2, "notEqual", float2, float2); michael@0: symbolTable.insertBuiltIn(bool3, "notEqual", float3, float3); michael@0: symbolTable.insertBuiltIn(bool4, "notEqual", float4, float4); michael@0: michael@0: symbolTable.insertBuiltIn(bool2, "notEqual", int2, int2); michael@0: symbolTable.insertBuiltIn(bool3, "notEqual", int3, int3); michael@0: symbolTable.insertBuiltIn(bool4, "notEqual", int4, int4); michael@0: michael@0: symbolTable.insertBuiltIn(bool2, "notEqual", bool2, bool2); michael@0: symbolTable.insertBuiltIn(bool3, "notEqual", bool3, bool3); michael@0: symbolTable.insertBuiltIn(bool4, "notEqual", bool4, bool4); michael@0: michael@0: symbolTable.insertBuiltIn(bool1, "any", bool2); michael@0: symbolTable.insertBuiltIn(bool1, "any", bool3); michael@0: symbolTable.insertBuiltIn(bool1, "any", bool4); michael@0: michael@0: symbolTable.insertBuiltIn(bool1, "all", bool2); michael@0: symbolTable.insertBuiltIn(bool1, "all", bool3); michael@0: symbolTable.insertBuiltIn(bool1, "all", bool4); michael@0: michael@0: symbolTable.insertBuiltIn(bool2, "not", bool2); michael@0: symbolTable.insertBuiltIn(bool3, "not", bool3); michael@0: symbolTable.insertBuiltIn(bool4, "not", bool4); michael@0: michael@0: TType *sampler2D = new TType(EbtSampler2D, EbpUndefined, EvqGlobal, 1); michael@0: TType *samplerCube = new TType(EbtSamplerCube, EbpUndefined, EvqGlobal, 1); michael@0: michael@0: // michael@0: // Texture Functions for GLSL ES 1.0 michael@0: // michael@0: symbolTable.insertBuiltIn(float4, "texture2D", sampler2D, float2); michael@0: symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float3); michael@0: symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float4); michael@0: symbolTable.insertBuiltIn(float4, "textureCube", samplerCube, float3); michael@0: michael@0: if (resources.OES_EGL_image_external) michael@0: { michael@0: TType *samplerExternalOES = new TType(EbtSamplerExternalOES, EbpUndefined, EvqGlobal, 1); michael@0: michael@0: symbolTable.insertBuiltIn(float4, "texture2D", samplerExternalOES, float2); michael@0: symbolTable.insertBuiltIn(float4, "texture2DProj", samplerExternalOES, float3); michael@0: symbolTable.insertBuiltIn(float4, "texture2DProj", samplerExternalOES, float4); michael@0: } michael@0: michael@0: if (resources.ARB_texture_rectangle) michael@0: { michael@0: TType *sampler2DRect = new TType(EbtSampler2DRect, EbpUndefined, EvqGlobal, 1); michael@0: michael@0: symbolTable.insertBuiltIn(float4, "texture2DRect", sampler2DRect, float2); michael@0: symbolTable.insertBuiltIn(float4, "texture2DRectProj", sampler2DRect, float3); michael@0: symbolTable.insertBuiltIn(float4, "texture2DRectProj", sampler2DRect, float4); michael@0: } michael@0: michael@0: if (type == SH_FRAGMENT_SHADER) michael@0: { michael@0: symbolTable.insertBuiltIn(float4, "texture2D", sampler2D, float2, float1); michael@0: symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float3, float1); michael@0: symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float4, float1); michael@0: symbolTable.insertBuiltIn(float4, "textureCube", samplerCube, float3, float1); michael@0: michael@0: if (resources.OES_standard_derivatives) michael@0: { michael@0: symbolTable.insertBuiltIn(float1, "dFdx", float1); michael@0: symbolTable.insertBuiltIn(float2, "dFdx", float2); michael@0: symbolTable.insertBuiltIn(float3, "dFdx", float3); michael@0: symbolTable.insertBuiltIn(float4, "dFdx", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "dFdy", float1); michael@0: symbolTable.insertBuiltIn(float2, "dFdy", float2); michael@0: symbolTable.insertBuiltIn(float3, "dFdy", float3); michael@0: symbolTable.insertBuiltIn(float4, "dFdy", float4); michael@0: michael@0: symbolTable.insertBuiltIn(float1, "fwidth", float1); michael@0: symbolTable.insertBuiltIn(float2, "fwidth", float2); michael@0: symbolTable.insertBuiltIn(float3, "fwidth", float3); michael@0: symbolTable.insertBuiltIn(float4, "fwidth", float4); michael@0: } michael@0: } michael@0: michael@0: if(type == SH_VERTEX_SHADER) michael@0: { michael@0: symbolTable.insertBuiltIn(float4, "texture2DLod", sampler2D, float2, float1); michael@0: symbolTable.insertBuiltIn(float4, "texture2DProjLod", sampler2D, float3, float1); michael@0: symbolTable.insertBuiltIn(float4, "texture2DProjLod", sampler2D, float4, float1); michael@0: symbolTable.insertBuiltIn(float4, "textureCubeLod", samplerCube, float3, float1); michael@0: } michael@0: michael@0: // michael@0: // Depth range in window coordinates michael@0: // michael@0: TFieldList *fields = NewPoolTFieldList(); michael@0: TField *near = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("near")); michael@0: TField *far = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("far")); michael@0: TField *diff = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("diff")); michael@0: fields->push_back(near); michael@0: fields->push_back(far); michael@0: fields->push_back(diff); michael@0: TStructure *depthRangeStruct = new TStructure(NewPoolTString("gl_DepthRangeParameters"), fields); michael@0: TVariable *depthRangeParameters = new TVariable(&depthRangeStruct->name(), depthRangeStruct, true); michael@0: symbolTable.insert(*depthRangeParameters); michael@0: TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct)); michael@0: depthRange->setQualifier(EvqUniform); michael@0: symbolTable.insert(*depthRange); michael@0: michael@0: // michael@0: // Implementation dependent built-in constants. michael@0: // michael@0: symbolTable.insertConstInt("gl_MaxVertexAttribs", resources.MaxVertexAttribs); michael@0: symbolTable.insertConstInt("gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors); michael@0: symbolTable.insertConstInt("gl_MaxVaryingVectors", resources.MaxVaryingVectors); michael@0: symbolTable.insertConstInt("gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits); michael@0: symbolTable.insertConstInt("gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits); michael@0: symbolTable.insertConstInt("gl_MaxTextureImageUnits", resources.MaxTextureImageUnits); michael@0: symbolTable.insertConstInt("gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors); michael@0: michael@0: if (spec != SH_CSS_SHADERS_SPEC) michael@0: { michael@0: symbolTable.insertConstInt("gl_MaxDrawBuffers", resources.MaxDrawBuffers); michael@0: } michael@0: } michael@0: michael@0: void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec, michael@0: const ShBuiltInResources &resources, michael@0: TSymbolTable &symbolTable) michael@0: { michael@0: // michael@0: // First, insert some special built-in variables that are not in michael@0: // the built-in header files. michael@0: // michael@0: switch(type) { michael@0: case SH_FRAGMENT_SHADER: michael@0: symbolTable.insert(*new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4))); michael@0: symbolTable.insert(*new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1))); michael@0: symbolTable.insert(*new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2))); michael@0: michael@0: // michael@0: // In CSS Shaders, gl_FragColor, gl_FragData, and gl_MaxDrawBuffers are not available. michael@0: // Instead, css_MixColor and css_ColorMatrix are available. michael@0: // michael@0: if (spec != SH_CSS_SHADERS_SPEC) { michael@0: symbolTable.insert(*new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4))); michael@0: symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4))); michael@0: if (resources.EXT_frag_depth) { michael@0: symbolTable.insert(*new TVariable(NewPoolTString("gl_FragDepthEXT"), TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium, EvqFragDepth, 1))); michael@0: symbolTable.relateToExtension("gl_FragDepthEXT", "GL_EXT_frag_depth"); michael@0: } michael@0: } else { michael@0: symbolTable.insert(*new TVariable(NewPoolTString("css_MixColor"), TType(EbtFloat, EbpMedium, EvqGlobal, 4))); michael@0: symbolTable.insert(*new TVariable(NewPoolTString("css_ColorMatrix"), TType(EbtFloat, EbpMedium, EvqGlobal, 4, true))); michael@0: } michael@0: michael@0: break; michael@0: michael@0: case SH_VERTEX_SHADER: michael@0: symbolTable.insert(*new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4))); michael@0: symbolTable.insert(*new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1))); michael@0: break; michael@0: michael@0: default: assert(false && "Language not supported"); michael@0: } michael@0: michael@0: // michael@0: // Next, identify which built-ins from the already loaded headers have michael@0: // a mapping to an operator. Those that are not identified as such are michael@0: // expected to be resolved through a library of functions, versus as michael@0: // operations. michael@0: // michael@0: symbolTable.relateToOperator("matrixCompMult", EOpMul); michael@0: michael@0: symbolTable.relateToOperator("equal", EOpVectorEqual); michael@0: symbolTable.relateToOperator("notEqual", EOpVectorNotEqual); michael@0: symbolTable.relateToOperator("lessThan", EOpLessThan); michael@0: symbolTable.relateToOperator("greaterThan", EOpGreaterThan); michael@0: symbolTable.relateToOperator("lessThanEqual", EOpLessThanEqual); michael@0: symbolTable.relateToOperator("greaterThanEqual", EOpGreaterThanEqual); michael@0: michael@0: symbolTable.relateToOperator("radians", EOpRadians); michael@0: symbolTable.relateToOperator("degrees", EOpDegrees); michael@0: symbolTable.relateToOperator("sin", EOpSin); michael@0: symbolTable.relateToOperator("cos", EOpCos); michael@0: symbolTable.relateToOperator("tan", EOpTan); michael@0: symbolTable.relateToOperator("asin", EOpAsin); michael@0: symbolTable.relateToOperator("acos", EOpAcos); michael@0: symbolTable.relateToOperator("atan", EOpAtan); michael@0: michael@0: symbolTable.relateToOperator("pow", EOpPow); michael@0: symbolTable.relateToOperator("exp2", EOpExp2); michael@0: symbolTable.relateToOperator("log", EOpLog); michael@0: symbolTable.relateToOperator("exp", EOpExp); michael@0: symbolTable.relateToOperator("log2", EOpLog2); michael@0: symbolTable.relateToOperator("sqrt", EOpSqrt); michael@0: symbolTable.relateToOperator("inversesqrt", EOpInverseSqrt); michael@0: michael@0: symbolTable.relateToOperator("abs", EOpAbs); michael@0: symbolTable.relateToOperator("sign", EOpSign); michael@0: symbolTable.relateToOperator("floor", EOpFloor); michael@0: symbolTable.relateToOperator("ceil", EOpCeil); michael@0: symbolTable.relateToOperator("fract", EOpFract); michael@0: symbolTable.relateToOperator("mod", EOpMod); michael@0: symbolTable.relateToOperator("min", EOpMin); michael@0: symbolTable.relateToOperator("max", EOpMax); michael@0: symbolTable.relateToOperator("clamp", EOpClamp); michael@0: symbolTable.relateToOperator("mix", EOpMix); michael@0: symbolTable.relateToOperator("step", EOpStep); michael@0: symbolTable.relateToOperator("smoothstep", EOpSmoothStep); michael@0: michael@0: symbolTable.relateToOperator("length", EOpLength); michael@0: symbolTable.relateToOperator("distance", EOpDistance); michael@0: symbolTable.relateToOperator("dot", EOpDot); michael@0: symbolTable.relateToOperator("cross", EOpCross); michael@0: symbolTable.relateToOperator("normalize", EOpNormalize); michael@0: symbolTable.relateToOperator("faceforward", EOpFaceForward); michael@0: symbolTable.relateToOperator("reflect", EOpReflect); michael@0: symbolTable.relateToOperator("refract", EOpRefract); michael@0: michael@0: symbolTable.relateToOperator("any", EOpAny); michael@0: symbolTable.relateToOperator("all", EOpAll); michael@0: symbolTable.relateToOperator("not", EOpVectorLogicalNot); michael@0: michael@0: // Map language-specific operators. michael@0: switch(type) { michael@0: case SH_VERTEX_SHADER: michael@0: break; michael@0: case SH_FRAGMENT_SHADER: michael@0: if (resources.OES_standard_derivatives) { michael@0: symbolTable.relateToOperator("dFdx", EOpDFdx); michael@0: symbolTable.relateToOperator("dFdy", EOpDFdy); michael@0: symbolTable.relateToOperator("fwidth", EOpFwidth); michael@0: michael@0: symbolTable.relateToExtension("dFdx", "GL_OES_standard_derivatives"); michael@0: symbolTable.relateToExtension("dFdy", "GL_OES_standard_derivatives"); michael@0: symbolTable.relateToExtension("fwidth", "GL_OES_standard_derivatives"); michael@0: } michael@0: break; michael@0: default: break; michael@0: } michael@0: michael@0: // Finally add resource-specific variables. michael@0: switch(type) { michael@0: case SH_FRAGMENT_SHADER: michael@0: if (spec != SH_CSS_SHADERS_SPEC) { michael@0: // Set up gl_FragData. The array size. michael@0: TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, false, true); michael@0: fragData.setArraySize(resources.MaxDrawBuffers); michael@0: symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData"), fragData)); michael@0: } michael@0: break; michael@0: default: break; michael@0: } michael@0: } michael@0: michael@0: void InitExtensionBehavior(const ShBuiltInResources& resources, michael@0: TExtensionBehavior& extBehavior) michael@0: { michael@0: if (resources.OES_standard_derivatives) michael@0: extBehavior["GL_OES_standard_derivatives"] = EBhUndefined; michael@0: if (resources.OES_EGL_image_external) michael@0: extBehavior["GL_OES_EGL_image_external"] = EBhUndefined; michael@0: if (resources.ARB_texture_rectangle) michael@0: extBehavior["GL_ARB_texture_rectangle"] = EBhUndefined; michael@0: if (resources.EXT_draw_buffers) michael@0: extBehavior["GL_EXT_draw_buffers"] = EBhUndefined; michael@0: if (resources.EXT_frag_depth) michael@0: extBehavior["GL_EXT_frag_depth"] = EBhUndefined; michael@0: }