void SetLineNumber(TSourceLoc line, TSourceLoc& outLine) { outLine.file = NULL; outLine.line = line.line; if (line.file && line.file[0]) { // GLSL does not permit quoted strings in #line directives if(line.file[0] == '"') { TString stripped(line.file + 1); size_t len = stripped.size(); if(stripped[len - 1] == '"') { stripped.resize(len - 1); } outLine.file = NewPoolTString(stripped.c_str())->c_str(); } else { outLine.file = NewPoolTString(line.file)->c_str(); } } }
TSymbolTableLevel* TSymbolTableLevel::clone() const { TSymbolTableLevel *symTableLevel = new TSymbolTableLevel(); symTableLevel->anonId = anonId; symTableLevel->thisLevel = thisLevel; std::vector<bool> containerCopied(anonId, false); tLevel::const_iterator iter; for (iter = level.begin(); iter != level.end(); ++iter) { const TAnonMember* anon = iter->second->getAsAnonMember(); if (anon) { // Insert all the anonymous members of this same container at once, // avoid inserting the other members in the future, once this has been done, // allowing them to all be part of the same new container. if (! containerCopied[anon->getAnonId()]) { TVariable* container = anon->getAnonContainer().clone(); container->changeName(NewPoolTString("")); // insert the whole container symTableLevel->insert(*container, false); containerCopied[anon->getAnonId()] = true; } } else symTableLevel->insert(*iter->second->clone(), false); } return symTableLevel; }
const TString *TFunction::buildMangledName() const { std::string newName = mangleName(getName()).c_str(); for (const auto &p : parameters) { newName += p.type->getMangledName().c_str(); } return NewPoolTString(newName.c_str()); }
// // Make the passed-in variable information become a member of the // global uniform block. If this doesn't exist yet, make it. // void TParseContextBase::growGlobalUniformBlock(TSourceLoc& loc, TType& memberType, TString& memberName) { // make the global block, if not yet made if (globalUniformBlock == nullptr) { TString& blockName = *NewPoolTString(getGlobalUniformBlockName()); TQualifier blockQualifier; blockQualifier.clear(); blockQualifier.storage = EvqUniform; TType blockType(new TTypeList, blockName, blockQualifier); TString* instanceName = NewPoolTString(""); globalUniformBlock = new TVariable(instanceName, blockType, true); firstNewMember = 0; } // add the requested member as a member to the block TType* type = new TType; type->shallowCopy(memberType); type->setFieldName(memberName); TTypeLoc typeLoc = {type, loc}; globalUniformBlock->getType().getWritableStruct()->push_back(typeLoc); }
// // Make the passed-in variable information become a member of the // global uniform block. If this doesn't exist yet, make it. // void TParseContextBase::growGlobalUniformBlock(const TSourceLoc& loc, TType& memberType, const TString& memberName, TTypeList* typeList) { // Make the global block, if not yet made. if (globalUniformBlock == nullptr) { TQualifier blockQualifier; blockQualifier.clear(); blockQualifier.storage = EvqUniform; TType blockType(new TTypeList, *NewPoolTString(getGlobalUniformBlockName()), blockQualifier); setUniformBlockDefaults(blockType); globalUniformBlock = new TVariable(NewPoolTString(""), blockType, true); firstNewMember = 0; } // Update with binding and set globalUniformBlock->getWritableType().getQualifier().layoutBinding = globalUniformBinding; globalUniformBlock->getWritableType().getQualifier().layoutSet = globalUniformSet; // Add the requested member as a member to the global block. TType* type = new TType; type->shallowCopy(memberType); type->setFieldName(memberName); if (typeList) type->setStruct(typeList); TTypeLoc typeLoc = {type, loc}; globalUniformBlock->getType().getWritableStruct()->push_back(typeLoc); // Insert into the symbol table. if (firstNewMember == 0) { // This is the first request; we need a normal symbol table insert if (symbolTable.insert(*globalUniformBlock)) trackLinkage(*globalUniformBlock); else error(loc, "failed to insert the global constant buffer", "uniform", ""); } else { // This is a follow-on request; we need to amend the first insert symbolTable.amend(*globalUniformBlock, firstNewMember); } ++firstNewMember; }
int TScanContext::identifierOrType() { parserToken->sType.lex.string = NewPoolTString(tokenText); if (field) return IDENTIFIER; parserToken->sType.lex.symbol = parseContext.symbolTable.find(*parserToken->sType.lex.string); if (afterType == false && parserToken->sType.lex.symbol) { if (const TVariable* variable = parserToken->sType.lex.symbol->getAsVariable()) { if (variable->isUserType()) { afterType = true; return TYPE_NAME; } } } return IDENTIFIER; }
void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInResources &resources, TSymbolTable &symbolTable) { const TType *float1 = TCache::getType(EbtFloat); const TType *float2 = TCache::getType(EbtFloat, 2); const TType *float3 = TCache::getType(EbtFloat, 3); const TType *float4 = TCache::getType(EbtFloat, 4); const TType *int1 = TCache::getType(EbtInt); const TType *int2 = TCache::getType(EbtInt, 2); const TType *int3 = TCache::getType(EbtInt, 3); const TType *uint1 = TCache::getType(EbtUInt); const TType *bool1 = TCache::getType(EbtBool); const TType *genType = TCache::getType(EbtGenType); const TType *genIType = TCache::getType(EbtGenIType); const TType *genUType = TCache::getType(EbtGenUType); const TType *genBType = TCache::getType(EbtGenBType); // // Angle and Trigonometric Functions. // symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpRadians, genType, "radians", genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpDegrees, genType, "degrees", genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSin, genType, "sin", genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpCos, genType, "cos", genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpTan, genType, "tan", genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAsin, genType, "asin", genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAcos, genType, "acos", genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAtan, genType, "atan", genType, genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAtan, genType, "atan", genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpSinh, genType, "sinh", genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpCosh, genType, "cosh", genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTanh, genType, "tanh", genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAsinh, genType, "asinh", genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAcosh, genType, "acosh", genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAtanh, genType, "atanh", genType); // // Exponential Functions. // symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpPow, genType, "pow", genType, genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpExp, genType, "exp", genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLog, genType, "log", genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpExp2, genType, "exp2", genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLog2, genType, "log2", genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSqrt, genType, "sqrt", genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpInverseSqrt, genType, "inversesqrt", genType); // // Common Functions. // symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAbs, genType, "abs", genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAbs, genIType, "abs", genIType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSign, genType, "sign", genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpSign, genIType, "sign", genIType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpFloor, genType, "floor", genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTrunc, genType, "trunc", genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpRound, genType, "round", genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpRoundEven, genType, "roundEven", genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpCeil, genType, "ceil", genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpFract, genType, "fract", genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMod, genType, "mod", genType, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMod, genType, "mod", genType, genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMin, genType, "min", genType, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMin, genType, "min", genType, genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genIType, "min", genIType, genIType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genIType, "min", genIType, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genUType, "min", genUType, genUType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genUType, "min", genUType, uint1); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMax, genType, "max", genType, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMax, genType, "max", genType, genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genIType, "max", genIType, genIType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genIType, "max", genIType, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genUType, "max", genUType, genUType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genUType, "max", genUType, uint1); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpClamp, genType, "clamp", genType, float1, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpClamp, genType, "clamp", genType, genType, genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genIType, "clamp", genIType, int1, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genIType, "clamp", genIType, genIType, genIType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genUType, "clamp", genUType, uint1, uint1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genUType, "clamp", genUType, genUType, genUType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMix, genType, "mix", genType, genType, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMix, genType, "mix", genType, genType, genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMix, genType, "mix", genType, genType, genBType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpStep, genType, "step", genType, genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpStep, genType, "step", float1, genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSmoothStep, genType, "smoothstep", genType, genType, genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSmoothStep, genType, "smoothstep", float1, float1, genType); const TType *outFloat1 = TCache::getType(EbtFloat, EvqOut); const TType *outFloat2 = TCache::getType(EbtFloat, EvqOut, 2); const TType *outFloat3 = TCache::getType(EbtFloat, EvqOut, 3); const TType *outFloat4 = TCache::getType(EbtFloat, EvqOut, 4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float1, "modf", float1, outFloat1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float2, "modf", float2, outFloat2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float3, "modf", float3, outFloat3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float4, "modf", float4, outFloat4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIsNan, genBType, "isnan", genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIsInf, genBType, "isinf", genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpFloatBitsToInt, genIType, "floatBitsToInt", genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpFloatBitsToUint, genUType, "floatBitsToUint", genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIntBitsToFloat, genType, "intBitsToFloat", genIType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUintBitsToFloat, genType, "uintBitsToFloat", genUType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackSnorm2x16, uint1, "packSnorm2x16", float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackUnorm2x16, uint1, "packUnorm2x16", float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackHalf2x16, uint1, "packHalf2x16", float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackSnorm2x16, float2, "unpackSnorm2x16", uint1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackUnorm2x16, float2, "unpackUnorm2x16", uint1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackHalf2x16, float2, "unpackHalf2x16", uint1); // // Geometric Functions. // symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLength, float1, "length", genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpDistance, float1, "distance", genType, genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpDot, float1, "dot", genType, genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpCross, float3, "cross", float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpNormalize, genType, "normalize", genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpFaceForward, genType, "faceforward", genType, genType, genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpReflect, genType, "reflect", genType, genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpRefract, genType, "refract", genType, genType, float1); const TType *mat2 = TCache::getType(EbtFloat, 2, 2); const TType *mat3 = TCache::getType(EbtFloat, 3, 3); const TType *mat4 = TCache::getType(EbtFloat, 4, 4); const TType *mat2x3 = TCache::getType(EbtFloat, 2, 3); const TType *mat3x2 = TCache::getType(EbtFloat, 3, 2); const TType *mat2x4 = TCache::getType(EbtFloat, 2, 4); const TType *mat4x2 = TCache::getType(EbtFloat, 4, 2); const TType *mat3x4 = TCache::getType(EbtFloat, 3, 4); const TType *mat4x3 = TCache::getType(EbtFloat, 4, 3); // // Matrix Functions. // symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat2, "matrixCompMult", mat2, mat2); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat3, "matrixCompMult", mat3, mat3); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat4, "matrixCompMult", mat4, mat4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat2x3, "matrixCompMult", mat2x3, mat2x3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat3x2, "matrixCompMult", mat3x2, mat3x2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat2x4, "matrixCompMult", mat2x4, mat2x4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat4x2, "matrixCompMult", mat4x2, mat4x2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat3x4, "matrixCompMult", mat3x4, mat3x4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat4x3, "matrixCompMult", mat4x3, mat4x3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2, "outerProduct", float2, float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3, "outerProduct", float3, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4, "outerProduct", float4, float4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2x3, "outerProduct", float3, float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3x2, "outerProduct", float2, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2x4, "outerProduct", float4, float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4x2, "outerProduct", float2, float4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3x4, "outerProduct", float4, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4x3, "outerProduct", float3, float4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2, "transpose", mat2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3, "transpose", mat3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4, "transpose", mat4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2x3, "transpose", mat3x2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3x2, "transpose", mat2x3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2x4, "transpose", mat4x2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4x2, "transpose", mat2x4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3x4, "transpose", mat4x3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4x3, "transpose", mat3x4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat2, "inverse", mat2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat3, "inverse", mat3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat4, "inverse", mat4); const TType *vec = TCache::getType(EbtVec); const TType *ivec = TCache::getType(EbtIVec); const TType *uvec = TCache::getType(EbtUVec); const TType *bvec = TCache::getType(EbtBVec); // // Vector relational functions. // symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThan, bvec, "lessThan", vec, vec); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThan, bvec, "lessThan", ivec, ivec); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpLessThan, bvec, "lessThan", uvec, uvec); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", vec, vec); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", ivec, ivec); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", uvec, uvec); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThan, bvec, "greaterThan", vec, vec); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThan, bvec, "greaterThan", ivec, ivec); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpGreaterThan, bvec, "greaterThan", uvec, uvec); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", vec, vec); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", ivec, ivec); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", uvec, uvec); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", vec, vec); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", ivec, ivec); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpVectorEqual, bvec, "equal", uvec, uvec); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", bvec, bvec); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", vec, vec); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", ivec, ivec); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", uvec, uvec); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", bvec, bvec); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAny, bool1, "any", bvec); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAll, bool1, "all", bvec); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorLogicalNot, bvec, "not", bvec); const TType *sampler2D = TCache::getType(EbtSampler2D); const TType *samplerCube = TCache::getType(EbtSamplerCube); // // Texture Functions for GLSL ES 1.0 // symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3); if (resources.OES_EGL_image_external) { const TType *samplerExternalOES = TCache::getType(EbtSamplerExternalOES); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", samplerExternalOES, float2); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float3); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float4); } if (resources.ARB_texture_rectangle) { const TType *sampler2DRect = TCache::getType(EbtSampler2DRect); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRect", sampler2DRect, float2); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, float3); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, float4); } if (resources.EXT_shader_texture_lod) { /* The *Grad* variants are new to both vertex and fragment shaders; the fragment * shader specific pieces are added separately below. */ symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "texture2DGradEXT", sampler2D, float2, float2, float2); symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "texture2DProjGradEXT", sampler2D, float3, float2, float2); symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "texture2DProjGradEXT", sampler2D, float4, float2, float2); symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "textureCubeGradEXT", samplerCube, float3, float3, float3); } if (type == GL_FRAGMENT_SHADER) { symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2, float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3, float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4, float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3, float1); if (resources.OES_standard_derivatives) { symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpDFdx, "GL_OES_standard_derivatives", genType, "dFdx", genType); symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpDFdy, "GL_OES_standard_derivatives", genType, "dFdy", genType); symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpFwidth, "GL_OES_standard_derivatives", genType, "fwidth", genType); } if (resources.EXT_shader_texture_lod) { symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "texture2DLodEXT", sampler2D, float2, float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "texture2DProjLodEXT", sampler2D, float3, float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "texture2DProjLodEXT", sampler2D, float4, float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "textureCubeLodEXT", samplerCube, float3, float1); } } if (type == GL_VERTEX_SHADER) { symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLod", sampler2D, float2, float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float3, float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float4, float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLod", samplerCube, float3, float1); } const TType *gvec4 = TCache::getType(EbtGVec4); const TType *gsampler2D = TCache::getType(EbtGSampler2D); const TType *gsamplerCube = TCache::getType(EbtGSamplerCube); const TType *gsampler3D = TCache::getType(EbtGSampler3D); const TType *gsampler2DArray = TCache::getType(EbtGSampler2DArray); // // Texture Functions for GLSL ES 3.0 // symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2D, float2, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler3D, float3, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsamplerCube, float3, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2DArray, float3, float1); if (type == GL_FRAGMENT_SHADER) { symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4, float1); } const TType *sampler2DShadow = TCache::getType(EbtSampler2DShadow); const TType *samplerCubeShadow = TCache::getType(EbtSamplerCubeShadow); const TType *sampler2DArrayShadow = TCache::getType(EbtSampler2DArrayShadow); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DArrayShadow, float4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLod", sampler2DShadow, float3, float1); if (type == GL_FRAGMENT_SHADER) { symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4, float1); } symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsampler2D, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler3D, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsamplerCube, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler2DArray, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", sampler2DShadow, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", samplerCubeShadow, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", sampler2DArrayShadow, int1); if (type == GL_FRAGMENT_SHADER) { symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDFdx, genType, "dFdx", genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDFdy, genType, "dFdy", genType); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpFwidth, genType, "fwidth", genType); } symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2); if (type == GL_FRAGMENT_SHADER) { symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2, float1); } symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2); if (type == GL_FRAGMENT_SHADER) { symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2, float1); } symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2D, float2, float1, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler3D, float3, float1, int3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLodOffset", sampler2DShadow, float3, float1, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2DArray, float3, float1, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float3, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float4, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler3D, float4, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLod", sampler2DShadow, float4, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float3, float1, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float4, float1, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler3D, float4, float1, int3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLodOffset", sampler2DShadow, float4, float1, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2D, int2, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler3D, int3, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2DArray, int3, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2D, int2, int1, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler3D, int3, int1, int3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2DArray, int3, int1, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2D, float2, float2, float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler3D, float3, float3, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsamplerCube, float3, float3, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DShadow, float3, float2, float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", samplerCubeShadow, float4, float3, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2DArray, float3, float2, float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DArrayShadow, float4, float2, float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2D, float2, float2, float2, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler3D, float3, float3, float3, int3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DShadow, float3, float2, float2, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2DArray, float3, float2, float2, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DArrayShadow, float4, float2, float2, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float3, float2, float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float4, float2, float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler3D, float4, float3, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGrad", sampler2DShadow, float4, float2, float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float3, float2, float2, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float4, float2, float2, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler3D, float4, float3, float3, int3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGradOffset", sampler2DShadow, float4, float2, float2, int2); // // Depth range in window coordinates // TFieldList *fields = NewPoolTFieldList(); TSourceLoc zeroSourceLoc = {0, 0, 0, 0}; TField *near = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("near"), zeroSourceLoc); TField *far = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("far"), zeroSourceLoc); TField *diff = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("diff"), zeroSourceLoc); fields->push_back(near); fields->push_back(far); fields->push_back(diff); TStructure *depthRangeStruct = new TStructure(NewPoolTString("gl_DepthRangeParameters"), fields); TVariable *depthRangeParameters = new TVariable(&depthRangeStruct->name(), depthRangeStruct, true); symbolTable.insert(COMMON_BUILTINS, depthRangeParameters); TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct)); depthRange->setQualifier(EvqUniform); symbolTable.insert(COMMON_BUILTINS, depthRange); // // Implementation dependent built-in constants. // symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexAttribs", resources.MaxVertexAttribs); symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors); symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits); symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits); symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxTextureImageUnits", resources.MaxTextureImageUnits); symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors); symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxVaryingVectors", resources.MaxVaryingVectors); { symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxDrawBuffers", resources.MaxDrawBuffers); if (resources.EXT_blend_func_extended) { symbolTable.insertConstIntExt(COMMON_BUILTINS, "GL_EXT_blend_func_extended", "gl_MaxDualSourceDrawBuffersEXT", resources.MaxDualSourceDrawBuffers); } } symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxVertexOutputVectors", resources.MaxVertexOutputVectors); symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxFragmentInputVectors", resources.MaxFragmentInputVectors); symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MinProgramTexelOffset", resources.MinProgramTexelOffset); symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxProgramTexelOffset", resources.MaxProgramTexelOffset); }
// // Copy a symbol, but the copy is writable; call readOnly() afterward if that's not desired. // TSymbol::TSymbol(const TSymbol& copyOf) { name = NewPoolTString(copyOf.name->c_str()); uniqueId = copyOf.uniqueId; writable = true; }
void TSymbolTable::insertBuiltIn( ESymbolLevel level, TType *rvalue, const char *name, TType *ptype1, TType *ptype2, TType *ptype3, TType *ptype4, TType *ptype5) { if (ptype1->getBasicType() == EbtGSampler2D) { bool gvec4 = (rvalue->getBasicType() == EbtGVec4); insertBuiltIn(level, gvec4 ? new TType(EbtFloat, 4) : rvalue, name, new TType(EbtSampler2D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name, new TType(EbtISampler2D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name, new TType(EbtUSampler2D), ptype2, ptype3, ptype4, ptype5); return; } if (ptype1->getBasicType() == EbtGSampler3D) { bool gvec4 = (rvalue->getBasicType() == EbtGVec4); insertBuiltIn(level, gvec4 ? new TType(EbtFloat, 4) : rvalue, name, new TType(EbtSampler3D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name, new TType(EbtISampler3D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name, new TType(EbtUSampler3D), ptype2, ptype3, ptype4, ptype5); return; } if (ptype1->getBasicType() == EbtGSamplerCube) { bool gvec4 = (rvalue->getBasicType() == EbtGVec4); insertBuiltIn(level, gvec4 ? new TType(EbtFloat, 4) : rvalue, name, new TType(EbtSamplerCube), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name, new TType(EbtISamplerCube), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name, new TType(EbtUSamplerCube), ptype2, ptype3, ptype4, ptype5); return; } if (ptype1->getBasicType() == EbtGSampler2DArray) { bool gvec4 = (rvalue->getBasicType() == EbtGVec4); insertBuiltIn(level, gvec4 ? new TType(EbtFloat, 4) : rvalue, name, new TType(EbtSampler2DArray), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name, new TType(EbtISampler2DArray), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name, new TType(EbtUSampler2DArray), ptype2, ptype3, ptype4, ptype5); return; } TFunction *function = new TFunction(NewPoolTString(name), *rvalue); TType *types[] = {ptype1, ptype2, ptype3, ptype4, ptype5}; for (size_t ii = 0; ii < sizeof(types) / sizeof(types[0]); ++ii) { if (types[ii]) { TParameter param = {NULL, types[ii]}; function->addParameter(param); } } insert(level, function); }
void TSymbolTable::insertBuiltIn(ESymbolLevel level, TOperator op, const char *ext, const TType *rvalue, const char *name, const TType *ptype1, const TType *ptype2, const TType *ptype3, const TType *ptype4, const TType *ptype5) { if (ptype1->getBasicType() == EbtGSampler2D) { insertUnmangledBuiltIn(name); bool gvec4 = (rvalue->getBasicType() == EbtGVec4); insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSampler2D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISampler2D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name, TCache::getType(EbtUSampler2D), ptype2, ptype3, ptype4, ptype5); } else if (ptype1->getBasicType() == EbtGSampler3D) { insertUnmangledBuiltIn(name); bool gvec4 = (rvalue->getBasicType() == EbtGVec4); insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSampler3D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISampler3D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name, TCache::getType(EbtUSampler3D), ptype2, ptype3, ptype4, ptype5); } else if (ptype1->getBasicType() == EbtGSamplerCube) { insertUnmangledBuiltIn(name); bool gvec4 = (rvalue->getBasicType() == EbtGVec4); insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSamplerCube), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISamplerCube), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name, TCache::getType(EbtUSamplerCube), ptype2, ptype3, ptype4, ptype5); } else if (ptype1->getBasicType() == EbtGSampler2DArray) { insertUnmangledBuiltIn(name); bool gvec4 = (rvalue->getBasicType() == EbtGVec4); insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSampler2DArray), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISampler2DArray), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name, TCache::getType(EbtUSampler2DArray), ptype2, ptype3, ptype4, ptype5); } else if (IsGenType(rvalue) || IsGenType(ptype1) || IsGenType(ptype2) || IsGenType(ptype3)) { ASSERT(!ptype4 && !ptype5); insertUnmangledBuiltIn(name); insertBuiltIn(level, op, ext, SpecificType(rvalue, 1), name, SpecificType(ptype1, 1), SpecificType(ptype2, 1), SpecificType(ptype3, 1)); insertBuiltIn(level, op, ext, SpecificType(rvalue, 2), name, SpecificType(ptype1, 2), SpecificType(ptype2, 2), SpecificType(ptype3, 2)); insertBuiltIn(level, op, ext, SpecificType(rvalue, 3), name, SpecificType(ptype1, 3), SpecificType(ptype2, 3), SpecificType(ptype3, 3)); insertBuiltIn(level, op, ext, SpecificType(rvalue, 4), name, SpecificType(ptype1, 4), SpecificType(ptype2, 4), SpecificType(ptype3, 4)); } else if (IsVecType(rvalue) || IsVecType(ptype1) || IsVecType(ptype2) || IsVecType(ptype3)) { ASSERT(!ptype4 && !ptype5); insertUnmangledBuiltIn(name); insertBuiltIn(level, op, ext, VectorType(rvalue, 2), name, VectorType(ptype1, 2), VectorType(ptype2, 2), VectorType(ptype3, 2)); insertBuiltIn(level, op, ext, VectorType(rvalue, 3), name, VectorType(ptype1, 3), VectorType(ptype2, 3), VectorType(ptype3, 3)); insertBuiltIn(level, op, ext, VectorType(rvalue, 4), name, VectorType(ptype1, 4), VectorType(ptype2, 4), VectorType(ptype3, 4)); } else { TFunction *function = new TFunction(NewPoolTString(name), rvalue, op, ext); function->addParameter(TConstParameter(ptype1)); if (ptype2) { function->addParameter(TConstParameter(ptype2)); } if (ptype3) { function->addParameter(TConstParameter(ptype3)); } if (ptype4) { function->addParameter(TConstParameter(ptype4)); } if (ptype5) { function->addParameter(TConstParameter(ptype5)); } ASSERT(hasUnmangledBuiltIn(name)); insert(level, function); } }
EHlslTokenClass HlslScanContext::identifierOrType() { parserToken->string = NewPoolTString(tokenText); return EHTokIdentifier; }
// // Fill in token information for the next token, except for the token class. // Returns the enum value of the token class of the next token found. // Return 0 (EndOfTokens) on end of input. // EHlslTokenClass HlslScanContext::tokenizeClass(HlslToken& token) { do { parserToken = &token; TPpToken ppToken; int token = ppContext.tokenize(ppToken); if (token == EndOfInput) return EHTokNone; tokenText = ppToken.name; loc = ppToken.loc; parserToken->loc = loc; switch (token) { case ';': return EHTokSemicolon; case ',': return EHTokComma; case ':': return EHTokColon; case '=': return EHTokAssign; case '(': return EHTokLeftParen; case ')': return EHTokRightParen; case '.': return EHTokDot; case '!': return EHTokBang; case '-': return EHTokDash; case '~': return EHTokTilde; case '+': return EHTokPlus; case '*': return EHTokStar; case '/': return EHTokSlash; case '%': return EHTokPercent; case '<': return EHTokLeftAngle; case '>': return EHTokRightAngle; case '|': return EHTokVerticalBar; case '^': return EHTokCaret; case '&': return EHTokAmpersand; case '?': return EHTokQuestion; case '[': return EHTokLeftBracket; case ']': return EHTokRightBracket; case '{': return EHTokLeftBrace; case '}': return EHTokRightBrace; case '\\': parseContext.error(loc, "illegal use of escape character", "\\", ""); break; case PPAtomAddAssign: return EHTokAddAssign; case PPAtomSubAssign: return EHTokSubAssign; case PPAtomMulAssign: return EHTokMulAssign; case PPAtomDivAssign: return EHTokDivAssign; case PPAtomModAssign: return EHTokModAssign; case PpAtomRight: return EHTokRightOp; case PpAtomLeft: return EHTokLeftOp; case PpAtomRightAssign: return EHTokRightAssign; case PpAtomLeftAssign: return EHTokLeftAssign; case PpAtomAndAssign: return EHTokAndAssign; case PpAtomOrAssign: return EHTokOrAssign; case PpAtomXorAssign: return EHTokXorAssign; case PpAtomAnd: return EHTokAndOp; case PpAtomOr: return EHTokOrOp; case PpAtomXor: return EHTokXorOp; case PpAtomEQ: return EHTokEqOp; case PpAtomGE: return EHTokGeOp; case PpAtomNE: return EHTokNeOp; case PpAtomLE: return EHTokLeOp; case PpAtomDecrement: return EHTokDecOp; case PpAtomIncrement: return EHTokIncOp; case PpAtomColonColon: return EHTokColonColon; case PpAtomConstInt: parserToken->i = ppToken.ival; return EHTokIntConstant; case PpAtomConstUint: parserToken->i = ppToken.ival; return EHTokUintConstant; case PpAtomConstFloat: parserToken->d = ppToken.dval; return EHTokFloatConstant; case PpAtomConstDouble: parserToken->d = ppToken.dval; return EHTokDoubleConstant; case PpAtomIdentifier: { EHlslTokenClass token = tokenizeIdentifier(); return token; } case PpAtomConstString: { parserToken->string = NewPoolTString(tokenText); return EHTokStringConstant; } case EndOfInput: return EHTokNone; default: char buf[2]; buf[0] = (char)token; buf[1] = 0; parseContext.error(loc, "unexpected token", buf, ""); break; } } while (true); }
void TSymbolTable::insertBuiltIn(ESymbolLevel level, TOperator op, const char *ext, TType *rvalue, const char *name, TType *ptype1, TType *ptype2, TType *ptype3, TType *ptype4, TType *ptype5) { if (ptype1->getBasicType() == EbtGSampler2D) { bool gvec4 = (rvalue->getBasicType() == EbtGVec4); insertBuiltIn(level, gvec4 ? new TType(EbtFloat, 4) : rvalue, name, new TType(EbtSampler2D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name, new TType(EbtISampler2D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name, new TType(EbtUSampler2D), ptype2, ptype3, ptype4, ptype5); } else if (ptype1->getBasicType() == EbtGSampler3D) { bool gvec4 = (rvalue->getBasicType() == EbtGVec4); insertBuiltIn(level, gvec4 ? new TType(EbtFloat, 4) : rvalue, name, new TType(EbtSampler3D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name, new TType(EbtISampler3D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name, new TType(EbtUSampler3D), ptype2, ptype3, ptype4, ptype5); } else if (ptype1->getBasicType() == EbtGSamplerCube) { bool gvec4 = (rvalue->getBasicType() == EbtGVec4); insertBuiltIn(level, gvec4 ? new TType(EbtFloat, 4) : rvalue, name, new TType(EbtSamplerCube), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name, new TType(EbtISamplerCube), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name, new TType(EbtUSamplerCube), ptype2, ptype3, ptype4, ptype5); } else if (ptype1->getBasicType() == EbtGSampler2DArray) { bool gvec4 = (rvalue->getBasicType() == EbtGVec4); insertBuiltIn(level, gvec4 ? new TType(EbtFloat, 4) : rvalue, name, new TType(EbtSampler2DArray), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name, new TType(EbtISampler2DArray), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name, new TType(EbtUSampler2DArray), ptype2, ptype3, ptype4, ptype5); } else if (IsGenType(rvalue) || IsGenType(ptype1) || IsGenType(ptype2) || IsGenType(ptype3)) { ASSERT(!ptype4 && !ptype5); insertBuiltIn(level, op, ext, SpecificType(rvalue, 1), name, SpecificType(ptype1, 1), SpecificType(ptype2, 1), SpecificType(ptype3, 1)); insertBuiltIn(level, op, ext, SpecificType(rvalue, 2), name, SpecificType(ptype1, 2), SpecificType(ptype2, 2), SpecificType(ptype3, 2)); insertBuiltIn(level, op, ext, SpecificType(rvalue, 3), name, SpecificType(ptype1, 3), SpecificType(ptype2, 3), SpecificType(ptype3, 3)); insertBuiltIn(level, op, ext, SpecificType(rvalue, 4), name, SpecificType(ptype1, 4), SpecificType(ptype2, 4), SpecificType(ptype3, 4)); } else if (IsVecType(rvalue) || IsVecType(ptype1) || IsVecType(ptype2) || IsVecType(ptype3)) { ASSERT(!ptype4 && !ptype5); insertBuiltIn(level, op, ext, VectorType(rvalue, 2), name, VectorType(ptype1, 2), VectorType(ptype2, 2), VectorType(ptype3, 2)); insertBuiltIn(level, op, ext, VectorType(rvalue, 3), name, VectorType(ptype1, 3), VectorType(ptype2, 3), VectorType(ptype3, 3)); insertBuiltIn(level, op, ext, VectorType(rvalue, 4), name, VectorType(ptype1, 4), VectorType(ptype2, 4), VectorType(ptype3, 4)); } else { TFunction *function = new TFunction(NewPoolTString(name), *rvalue, op, ext); TParameter param1 = {0, ptype1}; function->addParameter(param1); if (ptype2) { TParameter param2 = {0, ptype2}; function->addParameter(param2); } if (ptype3) { TParameter param3 = {0, ptype3}; function->addParameter(param3); } if (ptype4) { TParameter param4 = {0, ptype4}; function->addParameter(param4); } if (ptype5) { TParameter param5 = {0, ptype5}; function->addParameter(param5); } insert(level, function); } }
void IdentifyBuiltIns(sh::GLenum type, ShShaderSpec spec, const ShBuiltInResources &resources, TSymbolTable &symbolTable) { // // Insert some special built-in variables that are not in // the built-in header files. // switch (type) { case GL_FRAGMENT_SHADER: symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4))); symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1))); symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2))); { symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4))); TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, 1, true); fragData.setArraySize(resources.MaxDrawBuffers); symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragData"), fragData)); if (resources.EXT_blend_func_extended) { symbolTable.insert( ESSL1_BUILTINS, "GL_EXT_blend_func_extended", new TVariable(NewPoolTString("gl_SecondaryFragColorEXT"), TType(EbtFloat, EbpMedium, EvqSecondaryFragColorEXT, 4))); TType secondaryFragData(EbtFloat, EbpMedium, EvqSecondaryFragDataEXT, 4, 1, true); secondaryFragData.setArraySize(resources.MaxDualSourceDrawBuffers); symbolTable.insert( ESSL1_BUILTINS, "GL_EXT_blend_func_extended", new TVariable(NewPoolTString("gl_SecondaryFragDataEXT"), secondaryFragData)); } if (resources.EXT_frag_depth) { symbolTable.insert(ESSL1_BUILTINS, "GL_EXT_frag_depth", new TVariable(NewPoolTString("gl_FragDepthEXT"), TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium, EvqFragDepth, 1))); } if (resources.EXT_shader_framebuffer_fetch || resources.NV_shader_framebuffer_fetch) { TType lastFragData(EbtFloat, EbpMedium, EvqLastFragData, 4, 1, true); lastFragData.setArraySize(resources.MaxDrawBuffers); if (resources.EXT_shader_framebuffer_fetch) { symbolTable.insert(ESSL1_BUILTINS, "GL_EXT_shader_framebuffer_fetch", new TVariable(NewPoolTString("gl_LastFragData"), lastFragData)); } else if (resources.NV_shader_framebuffer_fetch) { symbolTable.insert(ESSL1_BUILTINS, "GL_NV_shader_framebuffer_fetch", new TVariable(NewPoolTString("gl_LastFragColor"), TType(EbtFloat, EbpMedium, EvqLastFragColor, 4))); symbolTable.insert(ESSL1_BUILTINS, "GL_NV_shader_framebuffer_fetch", new TVariable(NewPoolTString("gl_LastFragData"), lastFragData)); } } else if (resources.ARM_shader_framebuffer_fetch) { symbolTable.insert(ESSL1_BUILTINS, "GL_ARM_shader_framebuffer_fetch", new TVariable(NewPoolTString("gl_LastFragColorARM"), TType(EbtFloat, EbpMedium, EvqLastFragColor, 4))); } } break; case GL_VERTEX_SHADER: symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4))); symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1))); symbolTable.insert(ESSL3_BUILTINS, new TVariable(NewPoolTString("gl_InstanceID"), TType(EbtInt, EbpHigh, EvqInstanceID, 1))); break; default: assert(false && "Language not supported"); } }
void TBuiltIns::initialize() { // initialize the symbol table null semantic string TParameter::NullSemantic = NewPoolTString ( "" ); // // Initialize all the built-in strings for parsing. // TString BuiltInFunctions; { //============================================================================ // // Prototypes for built-in functions seen by both vertex and fragment shaders. // //============================================================================ TString& s = BuiltInFunctions; // // Angle and Trigonometric Functions. // s.append(TString("float radians(float degrees);")); s.append(TString("float2 radians(float2 degrees);")); s.append(TString("float3 radians(float3 degrees);")); s.append(TString("float4 radians(float4 degrees);")); s.append(TString("float2x2 radians(float2x2 degrees);")); s.append(TString("float3x3 radians(float3x3 degrees);")); s.append(TString("float4x4 radians(float4x4 degrees);")); s.append(TString("float degrees(float radians);")); s.append(TString("float2 degrees(float2 radians);")); s.append(TString("float3 degrees(float3 radians);")); s.append(TString("float4 degrees(float4 radians);")); s.append(TString("float2x2 degrees(float2x2 radians);")); s.append(TString("float3x3 degrees(float3x3 radians);")); s.append(TString("float4x4 degrees(float4x4 radians);")); s.append(TString("float sin(float angle);")); s.append(TString("float2 sin(float2 angle);")); s.append(TString("float3 sin(float3 angle);")); s.append(TString("float4 sin(float4 angle);")); s.append(TString("float2x2 sin(float2x2 angle);")); s.append(TString("float3x3 sin(float3x3 angle);")); s.append(TString("float4x4 sin(float4x4 angle);")); s.append(TString("float cos(float angle);")); s.append(TString("float2 cos(float2 angle);")); s.append(TString("float3 cos(float3 angle);")); s.append(TString("float4 cos(float4 angle);")); s.append(TString("float2x2 cos(float2x2 angle);")); s.append(TString("float3x3 cos(float3x3 angle);")); s.append(TString("float4x4 cos(float4x4 angle);")); s.append(TString("float tan(float angle);")); s.append(TString("float2 tan(float2 angle);")); s.append(TString("float3 tan(float3 angle);")); s.append(TString("float4 tan(float4 angle);")); s.append(TString("float2x2 tan(float2x2 angle);")); s.append(TString("float3x3 tan(float3x3 angle);")); s.append(TString("float4x4 tan(float4x4 angle);")); s.append(TString("float asin(float x);")); s.append(TString("float2 asin(float2 x);")); s.append(TString("float3 asin(float3 x);")); s.append(TString("float4 asin(float4 x);")); s.append(TString("float2x2 asin(float2x2 x);")); s.append(TString("float3x3 asin(float3x3 x);")); s.append(TString("float4x4 asin(float4x4 x);")); s.append(TString("float acos(float x);")); s.append(TString("float2 acos(float2 x);")); s.append(TString("float3 acos(float3 x);")); s.append(TString("float4 acos(float4 x);")); s.append(TString("float2x2 acos(float2x2 x);")); s.append(TString("float3x3 acos(float3x3 x);")); s.append(TString("float4x4 acos(float4x4 x);")); s.append(TString("float atan2(float y, float x);")); s.append(TString("float2 atan2(float2 y, float2 x);")); s.append(TString("float3 atan2(float3 y, float3 x);")); s.append(TString("float4 atan2(float4 y, float4 x);")); s.append(TString("float2x2 atan2(float2x2 y, float2x2 x);")); s.append(TString("float3x3 atan2(float3x3 y, float3x3 x);")); s.append(TString("float4x4 atan2(float4x4 y, float4x4 x);")); s.append(TString("float atan(float y_over_x);")); s.append(TString("float2 atan(float2 y_over_x);")); s.append(TString("float3 atan(float3 y_over_x);")); s.append(TString("float4 atan(float4 y_over_x);")); s.append(TString("float2x2 atan(float2x2 y_over_x);")); s.append(TString("float3x3 atan(float3x3 y_over_x);")); s.append(TString("float4x4 atan(float4x4 y_over_x);")); // // Exponential Functions. // s.append(TString("float pow(float x, float y);")); s.append(TString("float2 pow(float2 x, float2 y);")); s.append(TString("float3 pow(float3 x, float3 y);")); s.append(TString("float4 pow(float4 x, float4 y);")); s.append(TString("float2x2 pow(float2x2 x, float2x2 y);")); s.append(TString("float3x3 pow(float3x3 x, float3x3 y);")); s.append(TString("float4x4 pow(float4x4 x, float4x4 y);")); s.append(TString("float exp(float x);")); s.append(TString("float2 exp(float2 x);")); s.append(TString("float3 exp(float3 x);")); s.append(TString("float4 exp(float4 x);")); s.append(TString("float2x2 exp(float2x2 x);")); s.append(TString("float3x3 exp(float3x3 x);")); s.append(TString("float4x4 exp(float4x4 x);")); s.append(TString("float log(float x);")); s.append(TString("float2 log(float2 x);")); s.append(TString("float3 log(float3 x);")); s.append(TString("float4 log(float4 x);")); s.append(TString("float2x2 log(float2x2 x);")); s.append(TString("float3x3 log(float3x3 x);")); s.append(TString("float4x4 log(float4x4 x);")); s.append(TString("float exp2(float x);")); s.append(TString("float2 exp2(float2 x);")); s.append(TString("float3 exp2(float3 x);")); s.append(TString("float4 exp2(float4 x);")); s.append(TString("float2x2 exp2(float2x2 x);")); s.append(TString("float3x3 exp2(float3x3 x);")); s.append(TString("float4x4 exp2(float4x4 x);")); s.append(TString("float log2(float x);")); s.append(TString("float2 log2(float2 x);")); s.append(TString("float3 log2(float3 x);")); s.append(TString("float4 log2(float4 x);")); s.append(TString("float2x2 log2(float2x2 x);")); s.append(TString("float3x3 log2(float3x3 x);")); s.append(TString("float4x4 log2(float4x4 x);")); s.append(TString("float log10(float x);")); s.append(TString("float2 log10(float2 x);")); s.append(TString("float3 log10(float3 x);")); s.append(TString("float4 log10(float4 x);")); s.append(TString("float2x2 log10(float2x2 x);")); s.append(TString("float3x3 log10(float3x3 x);")); s.append(TString("float4x4 log10(float4x4 x);")); s.append(TString("float sqrt(float x);")); s.append(TString("float2 sqrt(float2 x);")); s.append(TString("float3 sqrt(float3 x);")); s.append(TString("float4 sqrt(float4 x);")); s.append(TString("float2x2 sqrt(float2x2 x);")); s.append(TString("float3x3 sqrt(float3x3 x);")); s.append(TString("float4x4 sqrt(float4x4 x);")); //DX HLSL versions s.append(TString("float rsqrt(float x);")); s.append(TString("float2 rsqrt(float2 x);")); s.append(TString("float3 rsqrt(float3 x);")); s.append(TString("float4 rsqrt(float4 x);")); s.append(TString("float2x2 rsqrt(float2x2 x);")); s.append(TString("float3x3 rsqrt(float3x3 x);")); s.append(TString("float4x4 rsqrt(float4x4 x);")); // // Common Functions. // s.append(TString("float abs(float x);")); s.append(TString("float2 abs(float2 x);")); s.append(TString("float3 abs(float3 x);")); s.append(TString("float4 abs(float4 x);")); s.append(TString("float2x2 abs(float2x2 x);")); s.append(TString("float3x3 abs(float3x3 x);")); s.append(TString("float4x4 abs(float4x4 x);")); s.append(TString("float sign(float x);")); s.append(TString("float2 sign(float2 x);")); s.append(TString("float3 sign(float3 x);")); s.append(TString("float4 sign(float4 x);")); s.append(TString("float2x2 sign(float2x2 x);")); s.append(TString("float3x3 sign(float3x3 x);")); s.append(TString("float4x4 sign(float4x4 x);")); s.append(TString("float floor(float x);")); s.append(TString("float2 floor(float2 x);")); s.append(TString("float3 floor(float3 x);")); s.append(TString("float4 floor(float4 x);")); s.append(TString("float2x2 floor(float2x2 x);")); s.append(TString("float3x3 floor(float3x3 x);")); s.append(TString("float4x4 floor(float4x4 x);")); s.append(TString("float ceil(float x);")); s.append(TString("float2 ceil(float2 x);")); s.append(TString("float3 ceil(float3 x);")); s.append(TString("float4 ceil(float4 x);")); s.append(TString("float2x2 ceil(float2x2 x);")); s.append(TString("float3x3 ceil(float3x3 x);")); s.append(TString("float4x4 ceil(float4x4 x);")); //DX HLSL versions s.append(TString("float frac(float x);")); s.append(TString("float2 frac(float2 x);")); s.append(TString("float3 frac(float3 x);")); s.append(TString("float4 frac(float4 x);")); s.append(TString("float2x2 frac(float2x2 x);")); s.append(TString("float3x3 frac(float3x3 x);")); s.append(TString("float4x4 frac(float4x4 x);")); s.append(TString("float fmod(float x, float y);")); s.append(TString("float2 fmod(float2 x, float2 y);")); s.append(TString("float3 fmod(float3 x, float3 y);")); s.append(TString("float4 fmod(float4 x, float4 y);")); s.append(TString("float min(float x, float y);")); s.append(TString("float2 min(float2 x, float2 y);")); s.append(TString("float3 min(float3 x, float3 y);")); s.append(TString("float4 min(float4 x, float4 y);")); s.append(TString("float2x2 min(float2x2 x, float2x2 y);")); s.append(TString("float3x3 min(float3x3 x, float3x3 y);")); s.append(TString("float4x4 min(float4x4 x, float4x4 y);")); s.append(TString("float max(float x, float y);")); s.append(TString("float2 max(float2 x, float2 y);")); s.append(TString("float3 max(float3 x, float3 y);")); s.append(TString("float4 max(float4 x, float4 y);")); s.append(TString("float2x2 max(float2x2 x, float2x2 y);")); s.append(TString("float3x3 max(float3x3 x, float3x3 y);")); s.append(TString("float4x4 max(float4x4 x, float4x4 y);")); s.append(TString("float clamp(float x, float minVal, float maxVal);")); s.append(TString("float2 clamp(float2 x, float2 minVal, float2 maxVal);")); s.append(TString("float3 clamp(float3 x, float3 minVal, float3 maxVal);")); s.append(TString("float4 clamp(float4 x, float4 minVal, float4 maxVal);")); s.append(TString("float2x2 clamp(float2x2 x, float2x2 minVal, float2x2 maxVal);")); s.append(TString("float3x3 clamp(float3x3 x, float3x3 minVal, float3x3 maxVal);")); s.append(TString("float4x4 clamp(float4x4 x, float4x4 minVal, float4x4 maxVal);")); //HLSL specific shortcut s.append(TString("float saturate(float x);")); s.append(TString("float2 saturate(float2 x);")); s.append(TString("float3 saturate(float3 x);")); s.append(TString("float4 saturate(float4 x);")); s.append(TString("float2x2 saturate(float2x2 x);")); s.append(TString("float3x3 saturate(float3x3 x);")); s.append(TString("float4x4 saturate(float4x4 x);")); // HLSL modf s.append(TString("float modf(float x, out int ip);")); s.append(TString("float modf(float x, out float ip);")); s.append(TString("float2 modf(float2 x, out int2 ip);")); s.append(TString("float2 modf(float2 x, out float2 ip);")); s.append(TString("float3 modf(float3 x, out int3 ip);")); s.append(TString("float3 modf(float3 x, out float3 ip);")); s.append(TString("float4 modf(float4 x, out int4 ip);")); s.append(TString("float4 modf(float4 x, out float4 ip);")); // HLSL round s.append(TString("float round(float x);")); s.append(TString("float2 round(float2 x);")); s.append(TString("float3 round(float3 x);")); s.append(TString("float4 round(float4 x);")); // HLSL trunc s.append(TString("float trunc(float x);")); s.append(TString("float2 trunc(float2 x);")); s.append(TString("float3 trunc(float3 x);")); s.append(TString("float4 trunc(float4 x);")); // HLSL ldexp s.append(TString("float ldexp(float x, float expon);")); s.append(TString("float2 ldexp(float2 x, float2 expon);")); s.append(TString("float3 ldexp(float3 x, float3 expon);")); s.append(TString("float4 ldexp(float4 x, float4 expon);")); s.append(TString("float2x2 ldexp(float2x2 x, float2x2 expon);")); s.append(TString("float3x3 ldexp(float3x3 x, float3x3 expon);")); s.append(TString("float4x4 ldexp(float4x4 x, float4x4 expon);")); // HLSL sincos s.append(TString("void sincos(float x, out float s, out float c);")); s.append(TString("void sincos(float2 x, out float2 s, out float2 c);")); s.append(TString("void sincos(float3 x, out float3 s, out float3 c);")); s.append(TString("void sincos(float4 x, out float4 s, out float4 c);")); s.append(TString("void sincos(float2x2 x, out float2x2 s, out float2x2 c);")); s.append(TString("void sincos(float3x3 x, out float3x3 s, out float3x3 c);")); s.append(TString("void sincos(float4x4 x, out float4x4 s, out float4x4 c);")); //DX HLSL versions s.append(TString("float lerp(float x, float y, float a);")); s.append(TString("float2 lerp(float2 x, float2 y, float2 a);")); s.append(TString("float3 lerp(float3 x, float3 y, float3 a);")); s.append(TString("float4 lerp(float4 x, float4 y, float4 a);")); s.append(TString("float2x2 lerp(float2x2 x, float2x2 y, float2x2 a);")); s.append(TString("float3x3 lerp(float3x3 x, float3x3 y, float3x3 a);")); s.append(TString("float4x4 lerp(float4x4 x, float4x4 y, float4x4 a);")); s.append(TString("float step(float edge, float x);")); s.append(TString("float2 step(float2 edge, float2 x);")); s.append(TString("float3 step(float3 edge, float3 x);")); s.append(TString("float4 step(float4 edge, float4 x);")); s.append(TString("float2x2 step(float2x2 edge, float2x2 x);")); s.append(TString("float3x3 step(float3x3 edge, float3x3 x);")); s.append(TString("float4x4 step(float4x4 edge, float4x4 x);")); s.append(TString("float smoothstep(float edge0, float edge1, float x);")); s.append(TString("float2 smoothstep(float2 edge0, float2 edge1, float2 x);")); s.append(TString("float3 smoothstep(float3 edge0, float3 edge1, float3 x);")); s.append(TString("float4 smoothstep(float4 edge0, float4 edge1, float4 x);")); s.append(TString("float2x2 smoothstep(float2x2 edge0, float2x2 edge1, float2x2 x);")); s.append(TString("float3x3 smoothstep(float3x3 edge0, float3x3 edge1, float3x3 x);")); s.append(TString("float4x4 smoothstep(float4x4 edge0, float4x4 edge1, float4x4 x);")); s.append(TString("float4 lit(float n_dot_l, float n_dot_h, float m);")); // // Geometric Functions. // s.append(TString("float length(float x);")); s.append(TString("float length(float2 x);")); s.append(TString("float length(float3 x);")); s.append(TString("float length(float4 x);")); s.append(TString("float distance(float p0, float p1);")); s.append(TString("float distance(float2 p0, float2 p1);")); s.append(TString("float distance(float3 p0, float3 p1);")); s.append(TString("float distance(float4 p0, float4 p1);")); s.append(TString("float dot(float x, float y);")); s.append(TString("float dot(float2 x, float2 y);")); s.append(TString("float dot(float3 x, float3 y);")); s.append(TString("float dot(float4 x, float4 y);")); s.append(TString("float3 cross(float3 x, float3 y);")); s.append(TString("float normalize(float x);")); s.append(TString("float2 normalize(float2 x);")); s.append(TString("float3 normalize(float3 x);")); s.append(TString("float4 normalize(float4 x);")); s.append(TString("float faceforward(float N, float I, float Nref);")); s.append(TString("float2 faceforward(float2 N, float2 I, float2 Nref);")); s.append(TString("float3 faceforward(float3 N, float3 I, float3 Nref);")); s.append(TString("float4 faceforward(float4 N, float4 I, float4 Nref);")); s.append(TString("float reflect(float I, float N);")); s.append(TString("float2 reflect(float2 I, float2 N);")); s.append(TString("float3 reflect(float3 I, float3 N);")); s.append(TString("float4 reflect(float4 I, float4 N);")); s.append(TString("float refract(float I, float N, float eta);")); s.append(TString("float2 refract(float2 I, float2 N, float eta);")); s.append(TString("float3 refract(float3 I, float3 N, float eta);")); s.append(TString("float4 refract(float4 I, float4 N, float eta);")); // // Matrix Functions. // //s.append(TString("mat2 matrixCompMult(mat2 x, mat2 y);")); //s.append(TString("mat3 matrixCompMult(mat3 x, mat3 y);")); //s.append(TString("mat4 matrixCompMult(mat4 x, mat4 y);")); // // HLSL Matrix Functions. // s.append(TString("float2x2 mul(float2x2 x, float2x2 y);")); s.append(TString("float3x3 mul(float3x3 x, float3x3 y);")); s.append(TString("float4x4 mul(float4x4 x, float4x4 y);")); s.append(TString("float2 mul(float2 x, float2x2 y);")); s.append(TString("float3 mul(float3 x, float3x3 y);")); s.append(TString("float4 mul(float4 x, float4x4 y);")); s.append(TString("float2 mul(float2x2 x, float2 y);")); s.append(TString("float3 mul(float3x3 x, float3 y);")); s.append(TString("float4 mul(float4x4 x, float4 y);")); s.append(TString("float2x2 transpose(float2x2 m);")); s.append(TString("float3x3 transpose(float3x3 m);")); s.append(TString("float4x4 transpose(float4x4 m);")); s.append(TString("float determinant(float2x2 m);")); s.append(TString("float determinant(float3x3 m);")); s.append(TString("float determinant(float4x4 m);")); // // Vector relational functions. // s.append(TString("bool any(bool2 x);")); s.append(TString("bool any(bool3 x);")); s.append(TString("bool any(bool4 x);")); s.append(TString("bool all(bool2 x);")); s.append(TString("bool all(bool3 x);")); s.append(TString("bool all(bool4 x);")); //s.append(TString("bvec2 not(bvec2 x);")); //s.append(TString("bvec3 not(bvec3 x);")); //s.append(TString("bvec4 not(bvec4 x);")); // // Texture Functions. // //DX HLSL texture functions s.append(TString("float4 tex1D(sampler1D s, float coord);")); s.append(TString("float4 tex1D(sampler1DShadow s, float2 coord);")); s.append(TString("float4 tex1D(sampler1D s, float coord, float ddx, float ddy);")); s.append(TString("float4 tex1Dproj(sampler1D s, float4 coord);")); s.append(TString("float4 tex1Dproj(sampler1DShadow s, float4 coord);")); s.append(TString("float4 tex1Dbias(sampler1D s, float4 coord);")); s.append(TString("float4 tex1Dlod(sampler1D s, float4 coord);")); s.append(TString("float4 tex1Dgrad(sampler1D s, float coord, float ddx, float ddy);")); s.append(TString("float4 tex2D(sampler2D s, float2 coord);")); s.append(TString("float4 tex2D(sampler2DShadow s, float3 coord);")); s.append(TString("float4 tex2D(sampler2D s, float2 coord, float2 ddx, float2 ddy);")); s.append(TString("float4 tex2Dproj(sampler2D s, float4 coord);")); s.append(TString("float4 tex2Dproj(sampler2DShadow s, float4 coord);")); s.append(TString("float4 tex2Dbias(sampler2D s, float4 coord);")); s.append(TString("float4 tex2Dlod(sampler2D s, float4 coord);")); s.append(TString("float4 tex2Dgrad(sampler2D s, float2 coord2, float2 ddx, float2 ddy);")); s.append(TString("float4 tex3D(sampler3D s, float3 coord);")); s.append(TString("float4 tex3D(sampler3D s, float3 coord, float3 ddx, float3 ddy);")); s.append(TString("float4 tex3Dproj(sampler3D s, float4 coord);")); s.append(TString("float4 tex3Dbias(sampler3D s, float4 coord);")); s.append(TString("float4 tex3Dlod(sampler3D s, float4 coord);")); s.append(TString("float4 tex3Dgrad(sampler3D s, float3 coord, float3 ddx, float3 ddy);")); s.append(TString("float4 texCUBE(samplerCUBE s, float3 coord);")); s.append(TString("float4 texCUBE(samplerCUBE s, float3 coord, float3 ddx, float3 ddy);")); s.append(TString("float4 texCUBEproj(samplerCUBE s, float4 coord);")); s.append(TString("float4 texCUBEbias(samplerCUBE s, float4 coord);")); s.append(TString("float4 texCUBElod(samplerCUBE s, float4 coord);")); s.append(TString("float4 texCUBEgrad(samplerCUBE s, float3 coord, float3 ddx, float3 ddy);")); s.append(TString("float4 texRECT(samplerRECT s, float2 coord);")); s.append(TString("float4 texRECT(samplerRECTShadow s, float3 coord);")); s.append(TString("float4 texRECTproj(samplerRECT s, float4 coord);")); s.append(TString("float4 texRECTproj(samplerRECTShadow s, float4 coord);")); s.append(TString("float4 texRECTproj(samplerRECT s, float3 coord);")); s.append(TString("float shadow2D(sampler2DShadow s, float3 coord);")); s.append(TString("float shadow2Dproj(sampler2DShadow s, float4 coord);")); s.append(TString("float4 tex1D(sampler s, float coord);")); s.append(TString("float4 tex1D(sampler s, float coord, float ddx, float ddy);")); s.append(TString("float4 tex1Dproj(sampler s, float4 coord);")); s.append(TString("float4 tex1Dbias(sampler s, float4 coord);")); s.append(TString("float4 tex1Dlod(sampler s, float4 coord);")); s.append(TString("float4 tex1Dgrad(sampler s, float coord, float ddx, float ddy);")); s.append(TString("float4 tex2D(sampler s, float2 coord);")); s.append(TString("float4 tex2D(sampler s, float2 coord, float2 ddx, float2 ddy);")); s.append(TString("float4 tex2Dproj(sampler s, float4 coord);")); s.append(TString("float4 tex2Dbias(sampler s, float4 coord);")); s.append(TString("float4 tex2Dlod(sampler s, float4 coord);")); s.append(TString("float4 tex2Dgrad(sampler s, float2 coord2, float2 ddx, float2 ddy);")); s.append(TString("float4 tex3D(sampler s, float3 coord);")); s.append(TString("float4 tex3D(sampler s, float3 coord, float3 ddx, float3 ddy);")); s.append(TString("float4 tex3Dproj(sampler s, float4 coord);")); s.append(TString("float4 tex3Dbias(sampler s, float4 coord);")); s.append(TString("float4 tex3Dlod(sampler s, float4 coord);")); s.append(TString("float4 tex3Dgrad(sampler s, float3 coord, float3 ddx, float3 ddy);")); s.append(TString("float4 texCUBE(sampler s, float3 coord);")); s.append(TString("float4 texCUBE(sampler s, float3 coord, float3 ddx, float3 ddy);")); s.append(TString("float4 texCUBEproj(sampler s, float4 coord);")); s.append(TString("float4 texCUBEbias(sampler s, float4 coord);")); s.append(TString("float4 texCUBElod(sampler s, float4 coord);")); s.append(TString("float4 texCUBEgrad(sampler s, float3 coord, float3 ddx, float3 ddy);")); s.append(TString("float4 texRECT(sampler s, float2 coord);")); s.append(TString("float4 texRECTproj(sampler s, float4 coord);")); s.append(TString("float4 texRECTproj(sampler s, float3 coord);")); // // Noise functions. // s.append(TString("float noise(float x);")); s.append(TString("float noise(float2 x);")); s.append(TString("float noise(float3 x);")); s.append(TString("float noise(float4 x);")); s.append(TString("float ddx(float p);")); s.append(TString("float2 ddx(float2 p);")); s.append(TString("float3 ddx(float3 p);")); s.append(TString("float4 ddx(float4 p);")); s.append(TString("float2x2 ddx(float2x2 p);")); s.append(TString("float3x3 ddx(float3x3 p);")); s.append(TString("float4x4 ddx(float4x4 p);")); s.append(TString("float ddy(float p);")); s.append(TString("float2 ddy(float2 p);")); s.append(TString("float3 ddy(float3 p);")); s.append(TString("float4 ddy(float4 p);")); s.append(TString("float2x2 ddy(float2x2 p);")); s.append(TString("float3x3 ddy(float3x3 p);")); s.append(TString("float4x4 ddy(float4x4 p);")); s.append(TString("float fwidth(float p);")); s.append(TString("float2 fwidth(float2 p);")); s.append(TString("float3 fwidth(float3 p);")); s.append(TString("float4 fwidth(float4 p);")); s.append(TString("float2x2 fwidth(float2x2 p);")); s.append(TString("float3x3 fwidth(float3x3 p);")); s.append(TString("float4x4 fwidth(float4x4 p);")); // // Special HLSL functions // s.append(TString("int4 D3DCOLORtoUBYTE4(float4 x);")); s.append(TString("void clip(float x);")); s.append(TString("\n")); } builtInStrings[EShLangFragment].push_back(BuiltInFunctions.c_str()); builtInStrings[EShLangVertex].push_back(BuiltInFunctions); }
void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec, const ShBuiltInResources &resources, TSymbolTable &symbolTable) { // // First, insert some special built-in variables that are not in // the built-in header files. // switch(type) { case SH_FRAGMENT_SHADER: symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4))); symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1))); symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2))); // // In CSS Shaders, gl_FragColor, gl_FragData, and gl_MaxDrawBuffers are not available. // Instead, css_MixColor and css_ColorMatrix are available. // if (spec != SH_CSS_SHADERS_SPEC) { symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4))); symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4))); if (resources.EXT_frag_depth) { symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragDepthEXT"), TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium, EvqFragDepth, 1))); symbolTable.relateToExtension(ESSL1_BUILTINS, "gl_FragDepthEXT", "GL_EXT_frag_depth"); } } else { symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("css_MixColor"), TType(EbtFloat, EbpMedium, EvqGlobal, 4))); symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("css_ColorMatrix"), TType(EbtFloat, EbpMedium, EvqGlobal, 4, 4))); } break; case SH_VERTEX_SHADER: symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4))); symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1))); break; default: assert(false && "Language not supported"); } // // Next, identify which built-ins from the already loaded headers have // a mapping to an operator. Those that are not identified as such are // expected to be resolved through a library of functions, versus as // operations. // symbolTable.relateToOperator(COMMON_BUILTINS, "matrixCompMult", EOpMul); symbolTable.relateToOperator(COMMON_BUILTINS, "equal", EOpVectorEqual); symbolTable.relateToOperator(COMMON_BUILTINS, "notEqual", EOpVectorNotEqual); symbolTable.relateToOperator(COMMON_BUILTINS, "lessThan", EOpLessThan); symbolTable.relateToOperator(COMMON_BUILTINS, "greaterThan", EOpGreaterThan); symbolTable.relateToOperator(COMMON_BUILTINS, "lessThanEqual", EOpLessThanEqual); symbolTable.relateToOperator(COMMON_BUILTINS, "greaterThanEqual", EOpGreaterThanEqual); symbolTable.relateToOperator(COMMON_BUILTINS, "radians", EOpRadians); symbolTable.relateToOperator(COMMON_BUILTINS, "degrees", EOpDegrees); symbolTable.relateToOperator(COMMON_BUILTINS, "sin", EOpSin); symbolTable.relateToOperator(COMMON_BUILTINS, "cos", EOpCos); symbolTable.relateToOperator(COMMON_BUILTINS, "tan", EOpTan); symbolTable.relateToOperator(COMMON_BUILTINS, "asin", EOpAsin); symbolTable.relateToOperator(COMMON_BUILTINS, "acos", EOpAcos); symbolTable.relateToOperator(COMMON_BUILTINS, "atan", EOpAtan); symbolTable.relateToOperator(COMMON_BUILTINS, "pow", EOpPow); symbolTable.relateToOperator(COMMON_BUILTINS, "exp2", EOpExp2); symbolTable.relateToOperator(COMMON_BUILTINS, "log", EOpLog); symbolTable.relateToOperator(COMMON_BUILTINS, "exp", EOpExp); symbolTable.relateToOperator(COMMON_BUILTINS, "log2", EOpLog2); symbolTable.relateToOperator(COMMON_BUILTINS, "sqrt", EOpSqrt); symbolTable.relateToOperator(COMMON_BUILTINS, "inversesqrt", EOpInverseSqrt); symbolTable.relateToOperator(COMMON_BUILTINS, "abs", EOpAbs); symbolTable.relateToOperator(COMMON_BUILTINS, "sign", EOpSign); symbolTable.relateToOperator(COMMON_BUILTINS, "floor", EOpFloor); symbolTable.relateToOperator(COMMON_BUILTINS, "ceil", EOpCeil); symbolTable.relateToOperator(COMMON_BUILTINS, "fract", EOpFract); symbolTable.relateToOperator(COMMON_BUILTINS, "mod", EOpMod); symbolTable.relateToOperator(COMMON_BUILTINS, "min", EOpMin); symbolTable.relateToOperator(COMMON_BUILTINS, "max", EOpMax); symbolTable.relateToOperator(COMMON_BUILTINS, "clamp", EOpClamp); symbolTable.relateToOperator(COMMON_BUILTINS, "mix", EOpMix); symbolTable.relateToOperator(COMMON_BUILTINS, "step", EOpStep); symbolTable.relateToOperator(COMMON_BUILTINS, "smoothstep", EOpSmoothStep); symbolTable.relateToOperator(COMMON_BUILTINS, "length", EOpLength); symbolTable.relateToOperator(COMMON_BUILTINS, "distance", EOpDistance); symbolTable.relateToOperator(COMMON_BUILTINS, "dot", EOpDot); symbolTable.relateToOperator(COMMON_BUILTINS, "cross", EOpCross); symbolTable.relateToOperator(COMMON_BUILTINS, "normalize", EOpNormalize); symbolTable.relateToOperator(COMMON_BUILTINS, "faceforward", EOpFaceForward); symbolTable.relateToOperator(COMMON_BUILTINS, "reflect", EOpReflect); symbolTable.relateToOperator(COMMON_BUILTINS, "refract", EOpRefract); symbolTable.relateToOperator(COMMON_BUILTINS, "any", EOpAny); symbolTable.relateToOperator(COMMON_BUILTINS, "all", EOpAll); symbolTable.relateToOperator(COMMON_BUILTINS, "not", EOpVectorLogicalNot); // Map language-specific operators. switch(type) { case SH_VERTEX_SHADER: break; case SH_FRAGMENT_SHADER: if (resources.OES_standard_derivatives) { symbolTable.relateToOperator(ESSL1_BUILTINS, "dFdx", EOpDFdx); symbolTable.relateToOperator(ESSL1_BUILTINS, "dFdy", EOpDFdy); symbolTable.relateToOperator(ESSL1_BUILTINS, "fwidth", EOpFwidth); symbolTable.relateToExtension(ESSL1_BUILTINS, "dFdx", "GL_OES_standard_derivatives"); symbolTable.relateToExtension(ESSL1_BUILTINS, "dFdy", "GL_OES_standard_derivatives"); symbolTable.relateToExtension(ESSL1_BUILTINS, "fwidth", "GL_OES_standard_derivatives"); } if (resources.EXT_shader_texture_lod) { symbolTable.relateToExtension(ESSL1_BUILTINS, "texture2DLodEXT", "GL_EXT_shader_texture_lod"); symbolTable.relateToExtension(ESSL1_BUILTINS, "texture2DProjLodEXT", "GL_EXT_shader_texture_lod"); symbolTable.relateToExtension(ESSL1_BUILTINS, "textureCubeLodEXT", "GL_EXT_shader_texture_lod"); } break; default: break; } symbolTable.relateToOperator(ESSL3_BUILTINS, "dFdx", EOpDFdx); symbolTable.relateToOperator(ESSL3_BUILTINS, "dFdy", EOpDFdy); symbolTable.relateToOperator(ESSL3_BUILTINS, "fwidth", EOpFwidth); if (resources.EXT_shader_texture_lod) { symbolTable.relateToExtension(ESSL1_BUILTINS, "texture2DGradEXT", "GL_EXT_shader_texture_lod"); symbolTable.relateToExtension(ESSL1_BUILTINS, "texture2DProjGradEXT", "GL_EXT_shader_texture_lod"); symbolTable.relateToExtension(ESSL1_BUILTINS, "textureCubeGradEXT", "GL_EXT_shader_texture_lod"); } // Finally add resource-specific variables. switch(type) { case SH_FRAGMENT_SHADER: if (spec != SH_CSS_SHADERS_SPEC) { // Set up gl_FragData. The array size. TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, 1, true); fragData.setArraySize(resources.MaxDrawBuffers); symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData"), fragData)); } break; default: break; } }
void InsertBuiltInFunctions(ShShaderType type, ShShaderSpec spec, const ShBuiltInResources &resources, TSymbolTable &symbolTable) { TType *float1 = new TType(EbtFloat); TType *float2 = new TType(EbtFloat, 2); TType *float3 = new TType(EbtFloat, 3); TType *float4 = new TType(EbtFloat, 4); TType *int1 = new TType(EbtInt); TType *int2 = new TType(EbtInt, 2); TType *int3 = new TType(EbtInt, 3); TType *int4 = new TType(EbtInt, 4); // // Angle and Trigonometric Functions. // symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "radians", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "radians", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "radians", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "radians", float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "degrees", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "degrees", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "degrees", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "degrees", float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "sin", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "sin", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "sin", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "sin", float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "cos", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "cos", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "cos", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "cos", float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "tan", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "tan", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "tan", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "tan", float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "asin", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "asin", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "asin", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "asin", float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "acos", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "acos", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "acos", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "acos", float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "atan", float1, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "atan", float2, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "atan", float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "atan", float4, float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "atan", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "atan", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "atan", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "atan", float4); // // Exponential Functions. // symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "pow", float1, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "pow", float2, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "pow", float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "pow", float4, float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "exp", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "exp", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "exp", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "exp", float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "log", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "log", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "log", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "log", float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "exp2", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "exp2", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "exp2", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "exp2", float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "log2", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "log2", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "log2", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "log2", float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "sqrt", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "sqrt", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "sqrt", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "sqrt", float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "inversesqrt", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "inversesqrt", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "inversesqrt", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "inversesqrt", float4); // // Common Functions. // symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "abs", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "abs", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "abs", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "abs", float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "sign", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "sign", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "sign", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "sign", float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "floor", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "floor", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "floor", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "floor", float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "ceil", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "ceil", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "ceil", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "ceil", float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "fract", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "fract", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "fract", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "fract", float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "mod", float1, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mod", float2, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mod", float3, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mod", float4, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mod", float2, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mod", float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mod", float4, float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "min", float1, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "min", float2, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "min", float3, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "min", float4, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "min", float2, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "min", float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "min", float4, float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "max", float1, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "max", float2, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "max", float3, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "max", float4, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "max", float2, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "max", float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "max", float4, float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "clamp", float1, float1, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "clamp", float2, float1, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "clamp", float3, float1, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "clamp", float4, float1, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "clamp", float2, float2, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "clamp", float3, float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "clamp", float4, float4, float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "mix", float1, float1, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mix", float2, float2, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mix", float3, float3, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mix", float4, float4, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mix", float2, float2, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mix", float3, float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mix", float4, float4, float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "step", float1, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "step", float2, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "step", float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "step", float4, float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "step", float1, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "step", float1, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "step", float1, float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "smoothstep", float1, float1, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "smoothstep", float2, float2, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "smoothstep", float3, float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "smoothstep", float4, float4, float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "smoothstep", float1, float1, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "smoothstep", float1, float1, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "smoothstep", float1, float1, float4); // // Geometric Functions. // symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float1, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float2, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float4, float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float1, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float2, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float4, float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "cross", float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "normalize", float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "normalize", float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "normalize", float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "normalize", float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "faceforward", float1, float1, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "faceforward", float2, float2, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "faceforward", float3, float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "faceforward", float4, float4, float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "reflect", float1, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "reflect", float2, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "reflect", float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "reflect", float4, float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "refract", float1, float1, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "refract", float2, float2, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "refract", float3, float3, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "refract", float4, float4, float1); TType *mat2 = new TType(EbtFloat, 2, 2); TType *mat3 = new TType(EbtFloat, 3, 3); TType *mat4 = new TType(EbtFloat, 4, 4); // // Matrix Functions. // symbolTable.insertBuiltIn(COMMON_BUILTINS, mat2, "matrixCompMult", mat2, mat2); symbolTable.insertBuiltIn(COMMON_BUILTINS, mat3, "matrixCompMult", mat3, mat3); symbolTable.insertBuiltIn(COMMON_BUILTINS, mat4, "matrixCompMult", mat4, mat4); TType *bool1 = new TType(EbtBool); TType *bool2 = new TType(EbtBool, 2); TType *bool3 = new TType(EbtBool, 3); TType *bool4 = new TType(EbtBool, 4); // // Vector relational functions. // symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThan", float2, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThan", float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThan", float4, float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThan", int2, int2); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThan", int3, int3); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThan", int4, int4); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThanEqual", float2, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThanEqual", float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThanEqual", float4, float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThanEqual", int2, int2); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThanEqual", int3, int3); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThanEqual", int4, int4); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThan", float2, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThan", float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThan", float4, float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThan", int2, int2); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThan", int3, int3); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThan", int4, int4); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThanEqual", float2, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThanEqual", float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThanEqual", float4, float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThanEqual", int2, int2); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThanEqual", int3, int3); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThanEqual", int4, int4); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "equal", float2, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "equal", float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "equal", float4, float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "equal", int2, int2); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "equal", int3, int3); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "equal", int4, int4); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "equal", bool2, bool2); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "equal", bool3, bool3); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "equal", bool4, bool4); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "notEqual", float2, float2); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "notEqual", float3, float3); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "notEqual", float4, float4); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "notEqual", int2, int2); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "notEqual", int3, int3); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "notEqual", int4, int4); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "notEqual", bool2, bool2); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "notEqual", bool3, bool3); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "notEqual", bool4, bool4); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool2); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool3); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool4); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool2); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool3); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool4); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "not", bool2); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "not", bool3); symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "not", bool4); TType *sampler2D = new TType(EbtSampler2D); TType *samplerCube = new TType(EbtSamplerCube); // // Texture Functions for GLSL ES 1.0 // symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3); if (resources.OES_EGL_image_external) { TType *samplerExternalOES = new TType(EbtSamplerExternalOES); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", samplerExternalOES, float2); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float3); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float4); } if (resources.ARB_texture_rectangle) { TType *sampler2DRect = new TType(EbtSampler2DRect); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRect", sampler2DRect, float2); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, float3); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, float4); } if (resources.EXT_shader_texture_lod) { /* The *Grad* variants are new to both vertex and fragment shaders; the fragment * shader specific pieces are added separately below. */ symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DGradEXT", sampler2D, float2, float2, float2); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjGradEXT", sampler2D, float3, float2, float2); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjGradEXT", sampler2D, float4, float2, float2); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeGradEXT", samplerCube, float3, float3, float3); } if (type == SH_FRAGMENT_SHADER) { symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2, float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3, float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4, float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3, float1); if (resources.OES_standard_derivatives) { symbolTable.insertBuiltIn(ESSL1_BUILTINS, float1, "dFdx", float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float2, "dFdx", float2); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float3, "dFdx", float3); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "dFdx", float4); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float1, "dFdy", float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float2, "dFdy", float2); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float3, "dFdy", float3); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "dFdy", float4); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float1, "fwidth", float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float2, "fwidth", float2); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float3, "fwidth", float3); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "fwidth", float4); } if (resources.EXT_shader_texture_lod) { symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLodEXT", sampler2D, float2, float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLodEXT", sampler2D, float3, float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLodEXT", sampler2D, float4, float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLodEXT", samplerCube, float3, float1); } } if(type == SH_VERTEX_SHADER) { symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLod", sampler2D, float2, float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float3, float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float4, float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLod", samplerCube, float3, float1); } TType *gvec4 = new TType(EbtGVec4); TType *gsampler2D = new TType(EbtGSampler2D); TType *gsamplerCube = new TType(EbtGSamplerCube); TType *gsampler3D = new TType(EbtGSampler3D); TType *gsampler2DArray = new TType(EbtGSampler2DArray); // // Texture Functions for GLSL ES 3.0 // symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2D, float2, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler3D, float3, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsamplerCube, float3, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2DArray, float3, float1); if (type == SH_FRAGMENT_SHADER) { symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4, float1); } TType *sampler2DShadow = new TType(EbtSampler2DShadow); TType *samplerCubeShadow = new TType(EbtSamplerCubeShadow); TType *sampler2DArrayShadow = new TType(EbtSampler2DArrayShadow); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DArrayShadow, float4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLod", sampler2DShadow, float3, float1); if (type == SH_FRAGMENT_SHADER) { symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4, float1); } symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsampler2D, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler3D, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsamplerCube, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler2DArray, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", sampler2DShadow, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", samplerCubeShadow, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", sampler2DArrayShadow, int1); if(type == SH_FRAGMENT_SHADER) { symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "dFdx", float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "dFdx", float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "dFdx", float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "dFdx", float4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "dFdy", float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "dFdy", float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "dFdy", float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "dFdy", float4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "fwidth", float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "fwidth", float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "fwidth", float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "fwidth", float4); } symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2); if(type == SH_FRAGMENT_SHADER) { symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2, float1); } symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2); if(type == SH_FRAGMENT_SHADER) { symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2, float1); } symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2D, float2, float1, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler3D, float3, float1, int3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLodOffset", sampler2DShadow, float3, float1, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2DArray, float3, float1, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float3, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float4, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler3D, float4, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLod", sampler2DShadow, float4, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float3, float1, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float4, float1, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler3D, float4, float1, int3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLodOffset", sampler2DShadow, float4, float1, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2D, int2, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler3D, int3, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2DArray, int3, int1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2D, int2, int1, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler3D, int3, int1, int3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2DArray, int3, int1, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2D, float2, float2, float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler3D, float3, float3, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsamplerCube, float3, float3, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DShadow, float3, float2, float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", samplerCubeShadow, float4, float3, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2DArray, float3, float2, float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DArrayShadow, float4, float2, float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2D, float2, float2, float2, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler3D, float3, float3, float3, int3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DShadow, float3, float2, float2, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2DArray, float3, float2, float2, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DArrayShadow, float4, float2, float2, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float3, float2, float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float4, float2, float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler3D, float4, float3, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGrad", sampler2DShadow, float4, float2, float2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float3, float2, float2, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float4, float2, float2, int2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler3D, float4, float3, float3, int3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGradOffset", sampler2DShadow, float4, float2, float2, int2); // // Depth range in window coordinates // TFieldList *fields = NewPoolTFieldList(); TSourceLoc zeroSourceLoc = {0, 0, 0, 0}; TField *near = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("near"), zeroSourceLoc); TField *far = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("far"), zeroSourceLoc); TField *diff = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("diff"), zeroSourceLoc); fields->push_back(near); fields->push_back(far); fields->push_back(diff); TStructure *depthRangeStruct = new TStructure(NewPoolTString("gl_DepthRangeParameters"), fields); TVariable *depthRangeParameters = new TVariable(&depthRangeStruct->name(), depthRangeStruct, true); symbolTable.insert(COMMON_BUILTINS, *depthRangeParameters); TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct)); depthRange->setQualifier(EvqUniform); symbolTable.insert(COMMON_BUILTINS, *depthRange); // // Implementation dependent built-in constants. // symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexAttribs", resources.MaxVertexAttribs); symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors); symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits); symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits); symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxTextureImageUnits", resources.MaxTextureImageUnits); symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors); symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxVaryingVectors", resources.MaxVaryingVectors); if (spec != SH_CSS_SHADERS_SPEC) { symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxDrawBuffers", resources.MaxDrawBuffers); } symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxVertexOutputVectors", resources.MaxVertexOutputVectors); symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxFragmentInputVectors", resources.MaxFragmentInputVectors); symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MinProgramTexelOffset", resources.MinProgramTexelOffset); symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxProgramTexelOffset", resources.MaxProgramTexelOffset); }
void InsertBuiltInFunctions(ShShaderType type, ShShaderSpec spec, const ShBuiltInResources &resources, TSymbolTable &symbolTable) { TType *float1 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 1); TType *float2 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 2); TType *float3 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 3); TType *float4 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 4); TType *int2 = new TType(EbtInt, EbpUndefined, EvqGlobal, 2); TType *int3 = new TType(EbtInt, EbpUndefined, EvqGlobal, 3); TType *int4 = new TType(EbtInt, EbpUndefined, EvqGlobal, 4); // // Angle and Trigonometric Functions. // symbolTable.insertBuiltIn(float1, "radians", float1); symbolTable.insertBuiltIn(float2, "radians", float2); symbolTable.insertBuiltIn(float3, "radians", float3); symbolTable.insertBuiltIn(float4, "radians", float4); symbolTable.insertBuiltIn(float1, "degrees", float1); symbolTable.insertBuiltIn(float2, "degrees", float2); symbolTable.insertBuiltIn(float3, "degrees", float3); symbolTable.insertBuiltIn(float4, "degrees", float4); symbolTable.insertBuiltIn(float1, "sin", float1); symbolTable.insertBuiltIn(float2, "sin", float2); symbolTable.insertBuiltIn(float3, "sin", float3); symbolTable.insertBuiltIn(float4, "sin", float4); symbolTable.insertBuiltIn(float1, "cos", float1); symbolTable.insertBuiltIn(float2, "cos", float2); symbolTable.insertBuiltIn(float3, "cos", float3); symbolTable.insertBuiltIn(float4, "cos", float4); symbolTable.insertBuiltIn(float1, "tan", float1); symbolTable.insertBuiltIn(float2, "tan", float2); symbolTable.insertBuiltIn(float3, "tan", float3); symbolTable.insertBuiltIn(float4, "tan", float4); symbolTable.insertBuiltIn(float1, "asin", float1); symbolTable.insertBuiltIn(float2, "asin", float2); symbolTable.insertBuiltIn(float3, "asin", float3); symbolTable.insertBuiltIn(float4, "asin", float4); symbolTable.insertBuiltIn(float1, "acos", float1); symbolTable.insertBuiltIn(float2, "acos", float2); symbolTable.insertBuiltIn(float3, "acos", float3); symbolTable.insertBuiltIn(float4, "acos", float4); symbolTable.insertBuiltIn(float1, "atan", float1, float1); symbolTable.insertBuiltIn(float2, "atan", float2, float2); symbolTable.insertBuiltIn(float3, "atan", float3, float3); symbolTable.insertBuiltIn(float4, "atan", float4, float4); symbolTable.insertBuiltIn(float1, "atan", float1); symbolTable.insertBuiltIn(float2, "atan", float2); symbolTable.insertBuiltIn(float3, "atan", float3); symbolTable.insertBuiltIn(float4, "atan", float4); // // Exponential Functions. // symbolTable.insertBuiltIn(float1, "pow", float1, float1); symbolTable.insertBuiltIn(float2, "pow", float2, float2); symbolTable.insertBuiltIn(float3, "pow", float3, float3); symbolTable.insertBuiltIn(float4, "pow", float4, float4); symbolTable.insertBuiltIn(float1, "exp", float1); symbolTable.insertBuiltIn(float2, "exp", float2); symbolTable.insertBuiltIn(float3, "exp", float3); symbolTable.insertBuiltIn(float4, "exp", float4); symbolTable.insertBuiltIn(float1, "log", float1); symbolTable.insertBuiltIn(float2, "log", float2); symbolTable.insertBuiltIn(float3, "log", float3); symbolTable.insertBuiltIn(float4, "log", float4); symbolTable.insertBuiltIn(float1, "exp2", float1); symbolTable.insertBuiltIn(float2, "exp2", float2); symbolTable.insertBuiltIn(float3, "exp2", float3); symbolTable.insertBuiltIn(float4, "exp2", float4); symbolTable.insertBuiltIn(float1, "log2", float1); symbolTable.insertBuiltIn(float2, "log2", float2); symbolTable.insertBuiltIn(float3, "log2", float3); symbolTable.insertBuiltIn(float4, "log2", float4); symbolTable.insertBuiltIn(float1, "sqrt", float1); symbolTable.insertBuiltIn(float2, "sqrt", float2); symbolTable.insertBuiltIn(float3, "sqrt", float3); symbolTable.insertBuiltIn(float4, "sqrt", float4); symbolTable.insertBuiltIn(float1, "inversesqrt", float1); symbolTable.insertBuiltIn(float2, "inversesqrt", float2); symbolTable.insertBuiltIn(float3, "inversesqrt", float3); symbolTable.insertBuiltIn(float4, "inversesqrt", float4); // // Common Functions. // symbolTable.insertBuiltIn(float1, "abs", float1); symbolTable.insertBuiltIn(float2, "abs", float2); symbolTable.insertBuiltIn(float3, "abs", float3); symbolTable.insertBuiltIn(float4, "abs", float4); symbolTable.insertBuiltIn(float1, "sign", float1); symbolTable.insertBuiltIn(float2, "sign", float2); symbolTable.insertBuiltIn(float3, "sign", float3); symbolTable.insertBuiltIn(float4, "sign", float4); symbolTable.insertBuiltIn(float1, "floor", float1); symbolTable.insertBuiltIn(float2, "floor", float2); symbolTable.insertBuiltIn(float3, "floor", float3); symbolTable.insertBuiltIn(float4, "floor", float4); symbolTable.insertBuiltIn(float1, "ceil", float1); symbolTable.insertBuiltIn(float2, "ceil", float2); symbolTable.insertBuiltIn(float3, "ceil", float3); symbolTable.insertBuiltIn(float4, "ceil", float4); symbolTable.insertBuiltIn(float1, "fract", float1); symbolTable.insertBuiltIn(float2, "fract", float2); symbolTable.insertBuiltIn(float3, "fract", float3); symbolTable.insertBuiltIn(float4, "fract", float4); symbolTable.insertBuiltIn(float1, "mod", float1, float1); symbolTable.insertBuiltIn(float2, "mod", float2, float1); symbolTable.insertBuiltIn(float3, "mod", float3, float1); symbolTable.insertBuiltIn(float4, "mod", float4, float1); symbolTable.insertBuiltIn(float2, "mod", float2, float2); symbolTable.insertBuiltIn(float3, "mod", float3, float3); symbolTable.insertBuiltIn(float4, "mod", float4, float4); symbolTable.insertBuiltIn(float1, "min", float1, float1); symbolTable.insertBuiltIn(float2, "min", float2, float1); symbolTable.insertBuiltIn(float3, "min", float3, float1); symbolTable.insertBuiltIn(float4, "min", float4, float1); symbolTable.insertBuiltIn(float2, "min", float2, float2); symbolTable.insertBuiltIn(float3, "min", float3, float3); symbolTable.insertBuiltIn(float4, "min", float4, float4); symbolTable.insertBuiltIn(float1, "max", float1, float1); symbolTable.insertBuiltIn(float2, "max", float2, float1); symbolTable.insertBuiltIn(float3, "max", float3, float1); symbolTable.insertBuiltIn(float4, "max", float4, float1); symbolTable.insertBuiltIn(float2, "max", float2, float2); symbolTable.insertBuiltIn(float3, "max", float3, float3); symbolTable.insertBuiltIn(float4, "max", float4, float4); symbolTable.insertBuiltIn(float1, "clamp", float1, float1, float1); symbolTable.insertBuiltIn(float2, "clamp", float2, float1, float1); symbolTable.insertBuiltIn(float3, "clamp", float3, float1, float1); symbolTable.insertBuiltIn(float4, "clamp", float4, float1, float1); symbolTable.insertBuiltIn(float2, "clamp", float2, float2, float2); symbolTable.insertBuiltIn(float3, "clamp", float3, float3, float3); symbolTable.insertBuiltIn(float4, "clamp", float4, float4, float4); symbolTable.insertBuiltIn(float1, "mix", float1, float1, float1); symbolTable.insertBuiltIn(float2, "mix", float2, float2, float1); symbolTable.insertBuiltIn(float3, "mix", float3, float3, float1); symbolTable.insertBuiltIn(float4, "mix", float4, float4, float1); symbolTable.insertBuiltIn(float2, "mix", float2, float2, float2); symbolTable.insertBuiltIn(float3, "mix", float3, float3, float3); symbolTable.insertBuiltIn(float4, "mix", float4, float4, float4); symbolTable.insertBuiltIn(float1, "step", float1, float1); symbolTable.insertBuiltIn(float2, "step", float2, float2); symbolTable.insertBuiltIn(float3, "step", float3, float3); symbolTable.insertBuiltIn(float4, "step", float4, float4); symbolTable.insertBuiltIn(float2, "step", float1, float2); symbolTable.insertBuiltIn(float3, "step", float1, float3); symbolTable.insertBuiltIn(float4, "step", float1, float4); symbolTable.insertBuiltIn(float1, "smoothstep", float1, float1, float1); symbolTable.insertBuiltIn(float2, "smoothstep", float2, float2, float2); symbolTable.insertBuiltIn(float3, "smoothstep", float3, float3, float3); symbolTable.insertBuiltIn(float4, "smoothstep", float4, float4, float4); symbolTable.insertBuiltIn(float2, "smoothstep", float1, float1, float2); symbolTable.insertBuiltIn(float3, "smoothstep", float1, float1, float3); symbolTable.insertBuiltIn(float4, "smoothstep", float1, float1, float4); // // Geometric Functions. // symbolTable.insertBuiltIn(float1, "length", float1); symbolTable.insertBuiltIn(float1, "length", float2); symbolTable.insertBuiltIn(float1, "length", float3); symbolTable.insertBuiltIn(float1, "length", float4); symbolTable.insertBuiltIn(float1, "distance", float1, float1); symbolTable.insertBuiltIn(float1, "distance", float2, float2); symbolTable.insertBuiltIn(float1, "distance", float3, float3); symbolTable.insertBuiltIn(float1, "distance", float4, float4); symbolTable.insertBuiltIn(float1, "dot", float1, float1); symbolTable.insertBuiltIn(float1, "dot", float2, float2); symbolTable.insertBuiltIn(float1, "dot", float3, float3); symbolTable.insertBuiltIn(float1, "dot", float4, float4); symbolTable.insertBuiltIn(float3, "cross", float3, float3); symbolTable.insertBuiltIn(float1, "normalize", float1); symbolTable.insertBuiltIn(float2, "normalize", float2); symbolTable.insertBuiltIn(float3, "normalize", float3); symbolTable.insertBuiltIn(float4, "normalize", float4); symbolTable.insertBuiltIn(float1, "faceforward", float1, float1, float1); symbolTable.insertBuiltIn(float2, "faceforward", float2, float2, float2); symbolTable.insertBuiltIn(float3, "faceforward", float3, float3, float3); symbolTable.insertBuiltIn(float4, "faceforward", float4, float4, float4); symbolTable.insertBuiltIn(float1, "reflect", float1, float1); symbolTable.insertBuiltIn(float2, "reflect", float2, float2); symbolTable.insertBuiltIn(float3, "reflect", float3, float3); symbolTable.insertBuiltIn(float4, "reflect", float4, float4); symbolTable.insertBuiltIn(float1, "refract", float1, float1, float1); symbolTable.insertBuiltIn(float2, "refract", float2, float2, float1); symbolTable.insertBuiltIn(float3, "refract", float3, float3, float1); symbolTable.insertBuiltIn(float4, "refract", float4, float4, float1); TType *mat2 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 2, true); TType *mat3 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 3, true); TType *mat4 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 4, true); // // Matrix Functions. // symbolTable.insertBuiltIn(mat2, "matrixCompMult", mat2, mat2); symbolTable.insertBuiltIn(mat3, "matrixCompMult", mat3, mat3); symbolTable.insertBuiltIn(mat4, "matrixCompMult", mat4, mat4); TType *bool1 = new TType(EbtBool, EbpUndefined, EvqGlobal, 1); TType *bool2 = new TType(EbtBool, EbpUndefined, EvqGlobal, 2); TType *bool3 = new TType(EbtBool, EbpUndefined, EvqGlobal, 3); TType *bool4 = new TType(EbtBool, EbpUndefined, EvqGlobal, 4); // // Vector relational functions. // symbolTable.insertBuiltIn(bool2, "lessThan", float2, float2); symbolTable.insertBuiltIn(bool3, "lessThan", float3, float3); symbolTable.insertBuiltIn(bool4, "lessThan", float4, float4); symbolTable.insertBuiltIn(bool2, "lessThan", int2, int2); symbolTable.insertBuiltIn(bool3, "lessThan", int3, int3); symbolTable.insertBuiltIn(bool4, "lessThan", int4, int4); symbolTable.insertBuiltIn(bool2, "lessThanEqual", float2, float2); symbolTable.insertBuiltIn(bool3, "lessThanEqual", float3, float3); symbolTable.insertBuiltIn(bool4, "lessThanEqual", float4, float4); symbolTable.insertBuiltIn(bool2, "lessThanEqual", int2, int2); symbolTable.insertBuiltIn(bool3, "lessThanEqual", int3, int3); symbolTable.insertBuiltIn(bool4, "lessThanEqual", int4, int4); symbolTable.insertBuiltIn(bool2, "greaterThan", float2, float2); symbolTable.insertBuiltIn(bool3, "greaterThan", float3, float3); symbolTable.insertBuiltIn(bool4, "greaterThan", float4, float4); symbolTable.insertBuiltIn(bool2, "greaterThan", int2, int2); symbolTable.insertBuiltIn(bool3, "greaterThan", int3, int3); symbolTable.insertBuiltIn(bool4, "greaterThan", int4, int4); symbolTable.insertBuiltIn(bool2, "greaterThanEqual", float2, float2); symbolTable.insertBuiltIn(bool3, "greaterThanEqual", float3, float3); symbolTable.insertBuiltIn(bool4, "greaterThanEqual", float4, float4); symbolTable.insertBuiltIn(bool2, "greaterThanEqual", int2, int2); symbolTable.insertBuiltIn(bool3, "greaterThanEqual", int3, int3); symbolTable.insertBuiltIn(bool4, "greaterThanEqual", int4, int4); symbolTable.insertBuiltIn(bool2, "equal", float2, float2); symbolTable.insertBuiltIn(bool3, "equal", float3, float3); symbolTable.insertBuiltIn(bool4, "equal", float4, float4); symbolTable.insertBuiltIn(bool2, "equal", int2, int2); symbolTable.insertBuiltIn(bool3, "equal", int3, int3); symbolTable.insertBuiltIn(bool4, "equal", int4, int4); symbolTable.insertBuiltIn(bool2, "equal", bool2, bool2); symbolTable.insertBuiltIn(bool3, "equal", bool3, bool3); symbolTable.insertBuiltIn(bool4, "equal", bool4, bool4); symbolTable.insertBuiltIn(bool2, "notEqual", float2, float2); symbolTable.insertBuiltIn(bool3, "notEqual", float3, float3); symbolTable.insertBuiltIn(bool4, "notEqual", float4, float4); symbolTable.insertBuiltIn(bool2, "notEqual", int2, int2); symbolTable.insertBuiltIn(bool3, "notEqual", int3, int3); symbolTable.insertBuiltIn(bool4, "notEqual", int4, int4); symbolTable.insertBuiltIn(bool2, "notEqual", bool2, bool2); symbolTable.insertBuiltIn(bool3, "notEqual", bool3, bool3); symbolTable.insertBuiltIn(bool4, "notEqual", bool4, bool4); symbolTable.insertBuiltIn(bool1, "any", bool2); symbolTable.insertBuiltIn(bool1, "any", bool3); symbolTable.insertBuiltIn(bool1, "any", bool4); symbolTable.insertBuiltIn(bool1, "all", bool2); symbolTable.insertBuiltIn(bool1, "all", bool3); symbolTable.insertBuiltIn(bool1, "all", bool4); symbolTable.insertBuiltIn(bool2, "not", bool2); symbolTable.insertBuiltIn(bool3, "not", bool3); symbolTable.insertBuiltIn(bool4, "not", bool4); TType *sampler2D = new TType(EbtSampler2D, EbpUndefined, EvqGlobal, 1); TType *samplerCube = new TType(EbtSamplerCube, EbpUndefined, EvqGlobal, 1); // // Texture Functions for GLSL ES 1.0 // symbolTable.insertBuiltIn(float4, "texture2D", sampler2D, float2); symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float3); symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float4); symbolTable.insertBuiltIn(float4, "textureCube", samplerCube, float3); if (resources.OES_EGL_image_external) { TType *samplerExternalOES = new TType(EbtSamplerExternalOES, EbpUndefined, EvqGlobal, 1); symbolTable.insertBuiltIn(float4, "texture2D", samplerExternalOES, float2); symbolTable.insertBuiltIn(float4, "texture2DProj", samplerExternalOES, float3); symbolTable.insertBuiltIn(float4, "texture2DProj", samplerExternalOES, float4); } if (resources.ARB_texture_rectangle) { TType *sampler2DRect = new TType(EbtSampler2DRect, EbpUndefined, EvqGlobal, 1); symbolTable.insertBuiltIn(float4, "texture2DRect", sampler2DRect, float2); symbolTable.insertBuiltIn(float4, "texture2DRectProj", sampler2DRect, float3); symbolTable.insertBuiltIn(float4, "texture2DRectProj", sampler2DRect, float4); } if (type == SH_FRAGMENT_SHADER) { symbolTable.insertBuiltIn(float4, "texture2D", sampler2D, float2, float1); symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float3, float1); symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float4, float1); symbolTable.insertBuiltIn(float4, "textureCube", samplerCube, float3, float1); if (resources.OES_standard_derivatives) { symbolTable.insertBuiltIn(float1, "dFdx", float1); symbolTable.insertBuiltIn(float2, "dFdx", float2); symbolTable.insertBuiltIn(float3, "dFdx", float3); symbolTable.insertBuiltIn(float4, "dFdx", float4); symbolTable.insertBuiltIn(float1, "dFdy", float1); symbolTable.insertBuiltIn(float2, "dFdy", float2); symbolTable.insertBuiltIn(float3, "dFdy", float3); symbolTable.insertBuiltIn(float4, "dFdy", float4); symbolTable.insertBuiltIn(float1, "fwidth", float1); symbolTable.insertBuiltIn(float2, "fwidth", float2); symbolTable.insertBuiltIn(float3, "fwidth", float3); symbolTable.insertBuiltIn(float4, "fwidth", float4); } } if(type == SH_VERTEX_SHADER) { symbolTable.insertBuiltIn(float4, "texture2DLod", sampler2D, float2, float1); symbolTable.insertBuiltIn(float4, "texture2DProjLod", sampler2D, float3, float1); symbolTable.insertBuiltIn(float4, "texture2DProjLod", sampler2D, float4, float1); symbolTable.insertBuiltIn(float4, "textureCubeLod", samplerCube, float3, float1); } // // Depth range in window coordinates // TFieldList *fields = NewPoolTFieldList(); TField *near = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("near")); TField *far = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("far")); TField *diff = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("diff")); fields->push_back(near); fields->push_back(far); fields->push_back(diff); TStructure *depthRangeStruct = new TStructure(NewPoolTString("gl_DepthRangeParameters"), fields); TVariable *depthRangeParameters = new TVariable(&depthRangeStruct->name(), depthRangeStruct, true); symbolTable.insert(*depthRangeParameters); TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct)); depthRange->setQualifier(EvqUniform); symbolTable.insert(*depthRange); // // Implementation dependent built-in constants. // symbolTable.insertConstInt("gl_MaxVertexAttribs", resources.MaxVertexAttribs); symbolTable.insertConstInt("gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors); symbolTable.insertConstInt("gl_MaxVaryingVectors", resources.MaxVaryingVectors); symbolTable.insertConstInt("gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits); symbolTable.insertConstInt("gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits); symbolTable.insertConstInt("gl_MaxTextureImageUnits", resources.MaxTextureImageUnits); symbolTable.insertConstInt("gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors); if (spec != SH_CSS_SHADERS_SPEC) { symbolTable.insertConstInt("gl_MaxDrawBuffers", resources.MaxDrawBuffers); } }