summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Capens <nicolas@transgaming.com>2013-06-23 01:25:21 -0400
committerShannon Woods <shannonwoods@chromium.org>2013-06-26 19:06:46 -0400
commit8cf3a7ec683903e3c7425c563fd77e620e7a45a2 (patch)
tree0b0cf5670ff24c6b639107227df3ffa2d9a35deb
parent45494d463d72c4b6c2b2071c5b361713d2ae0a25 (diff)
downloadangle_dx11-8cf3a7ec683903e3c7425c563fd77e620e7a45a2.tar.gz
Initialize the symbol table without invoking the parser.
TRAC #23368 Signed-off-by: Jamie Madill Signed-off-by: Shannon Woods Author: Nicolas Capens
-rw-r--r--src/compiler/Compiler.cpp88
-rw-r--r--src/compiler/Initialize.cpp797
-rw-r--r--src/compiler/Initialize.h18
-rw-r--r--src/compiler/SymbolTable.h31
4 files changed, 416 insertions, 518 deletions
diff --git a/src/compiler/Compiler.cpp b/src/compiler/Compiler.cpp
index f97714f2..4525cb92 100644
--- a/src/compiler/Compiler.cpp
+++ b/src/compiler/Compiler.cpp
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
+// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
@@ -27,52 +27,6 @@ bool isWebGLBasedSpec(ShShaderSpec spec)
}
namespace {
-bool InitializeSymbolTable(
- const TBuiltInStrings& builtInStrings,
- ShShaderType type, ShShaderSpec spec, const ShBuiltInResources& resources,
- TInfoSink& infoSink, TSymbolTable& symbolTable)
-{
- TIntermediate intermediate(infoSink);
- TExtensionBehavior extBehavior;
- InitExtensionBehavior(resources, extBehavior);
- // The builtins deliberately don't specify precisions for the function
- // arguments and return types. For that reason we don't try to check them.
- TParseContext parseContext(symbolTable, extBehavior, intermediate, type, spec, 0, false, NULL, infoSink);
- parseContext.fragmentPrecisionHigh = resources.FragmentPrecisionHigh == 1;
-
- GlobalParseContext = &parseContext;
-
- assert(symbolTable.isEmpty());
- //
- // Parse the built-ins. This should only happen once per
- // language symbol table.
- //
- // Push the symbol table to give it an initial scope. This
- // push should not have a corresponding pop, so that built-ins
- // are preserved, and the test for an empty table fails.
- //
- symbolTable.push();
-
- for (TBuiltInStrings::const_iterator i = builtInStrings.begin(); i != builtInStrings.end(); ++i)
- {
- const char* builtInShaders = i->c_str();
- int builtInLengths = static_cast<int>(i->size());
- if (builtInLengths <= 0)
- continue;
-
- if (PaParseStrings(1, &builtInShaders, &builtInLengths, &parseContext) != 0)
- {
- infoSink.info.prefix(EPrefixInternalError);
- infoSink.info << "Unable to parse built-ins";
- return false;
- }
- }
-
- IdentifyBuiltIns(type, spec, resources, symbolTable);
-
- return true;
-}
-
class TScopedPoolAllocator {
public:
TScopedPoolAllocator(TPoolAllocator* allocator, bool pushPop)
@@ -252,14 +206,42 @@ bool TCompiler::compile(const char* const shaderStrings[],
return success;
}
-bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources& resources)
+bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
{
- TBuiltIns builtIns;
-
compileResources = resources;
- builtIns.initialize(shaderType, shaderSpec, resources, extensionBehavior);
- return InitializeSymbolTable(builtIns.getBuiltInStrings(),
- shaderType, shaderSpec, resources, infoSink, symbolTable);
+
+ assert(symbolTable.isEmpty());
+ symbolTable.push();
+
+ TPublicType integer;
+ integer.type = EbtInt;
+ integer.size = 1;
+ integer.matrix = false;
+ integer.array = false;
+
+ TPublicType floatingPoint;
+ floatingPoint.type = EbtFloat;
+ floatingPoint.size = 1;
+ floatingPoint.matrix = false;
+ floatingPoint.array = false;
+
+ switch(shaderType)
+ {
+ case SH_FRAGMENT_SHADER:
+ symbolTable.setDefaultPrecision(integer, EbpMedium);
+ break;
+ case SH_VERTEX_SHADER:
+ symbolTable.setDefaultPrecision(integer, EbpHigh);
+ symbolTable.setDefaultPrecision(floatingPoint, EbpHigh);
+ break;
+ default: assert(false && "Language not supported");
+ }
+
+ InsertBuiltInFunctions(shaderType, shaderSpec, resources, extensionBehavior, symbolTable);
+
+ IdentifyBuiltIns(shaderType, shaderSpec, resources, symbolTable);
+
+ return true;
}
void TCompiler::clearResults()
diff --git a/src/compiler/Initialize.cpp b/src/compiler/Initialize.cpp
index d0ca47ad..9b070cad 100644
--- a/src/compiler/Initialize.cpp
+++ b/src/compiler/Initialize.cpp
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
+// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
@@ -14,479 +14,406 @@
#include "compiler/intermediate.h"
-//============================================================================
-//
-// Prototypes for built-in functions seen by both vertex and fragment shaders.
-//
-//============================================================================
-static TString BuiltInFunctionsCommon(const ShBuiltInResources& resources)
+void InsertBuiltInFunctions(ShShaderType type, ShShaderSpec spec, const ShBuiltInResources &resources,
+ const TExtensionBehavior &extensionBehavior, TSymbolTable &symbolTable)
{
- TString s;
+ 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.
//
- s.append(TString("float radians(float degrees);"));
- s.append(TString("vec2 radians(vec2 degrees);"));
- s.append(TString("vec3 radians(vec3 degrees);"));
- s.append(TString("vec4 radians(vec4 degrees);"));
-
- s.append(TString("float degrees(float radians);"));
- s.append(TString("vec2 degrees(vec2 radians);"));
- s.append(TString("vec3 degrees(vec3 radians);"));
- s.append(TString("vec4 degrees(vec4 radians);"));
-
- s.append(TString("float sin(float angle);"));
- s.append(TString("vec2 sin(vec2 angle);"));
- s.append(TString("vec3 sin(vec3 angle);"));
- s.append(TString("vec4 sin(vec4 angle);"));
-
- s.append(TString("float cos(float angle);"));
- s.append(TString("vec2 cos(vec2 angle);"));
- s.append(TString("vec3 cos(vec3 angle);"));
- s.append(TString("vec4 cos(vec4 angle);"));
-
- s.append(TString("float tan(float angle);"));
- s.append(TString("vec2 tan(vec2 angle);"));
- s.append(TString("vec3 tan(vec3 angle);"));
- s.append(TString("vec4 tan(vec4 angle);"));
-
- s.append(TString("float asin(float x);"));
- s.append(TString("vec2 asin(vec2 x);"));
- s.append(TString("vec3 asin(vec3 x);"));
- s.append(TString("vec4 asin(vec4 x);"));
-
- s.append(TString("float acos(float x);"));
- s.append(TString("vec2 acos(vec2 x);"));
- s.append(TString("vec3 acos(vec3 x);"));
- s.append(TString("vec4 acos(vec4 x);"));
-
- s.append(TString("float atan(float y, float x);"));
- s.append(TString("vec2 atan(vec2 y, vec2 x);"));
- s.append(TString("vec3 atan(vec3 y, vec3 x);"));
- s.append(TString("vec4 atan(vec4 y, vec4 x);"));
-
- s.append(TString("float atan(float y_over_x);"));
- s.append(TString("vec2 atan(vec2 y_over_x);"));
- s.append(TString("vec3 atan(vec3 y_over_x);"));
- s.append(TString("vec4 atan(vec4 y_over_x);"));
+ symbolTable.insertBuiltIn(float1, "radians", float1, "degrees");
+ symbolTable.insertBuiltIn(float2, "radians", float2, "degrees");
+ symbolTable.insertBuiltIn(float3, "radians", float3, "degrees");
+ symbolTable.insertBuiltIn(float4, "radians", float4, "degrees");
+
+ symbolTable.insertBuiltIn(float1, "degrees", float1, "radians");
+ symbolTable.insertBuiltIn(float2, "degrees", float2, "radians");
+ symbolTable.insertBuiltIn(float3, "degrees", float3, "radians");
+ symbolTable.insertBuiltIn(float4, "degrees", float4, "radians");
+
+ symbolTable.insertBuiltIn(float1, "sin", float1, "angle");
+ symbolTable.insertBuiltIn(float2, "sin", float2, "angle");
+ symbolTable.insertBuiltIn(float3, "sin", float3, "angle");
+ symbolTable.insertBuiltIn(float4, "sin", float4, "angle");
+
+ symbolTable.insertBuiltIn(float1, "cos", float1, "angle");
+ symbolTable.insertBuiltIn(float2, "cos", float2, "angle");
+ symbolTable.insertBuiltIn(float3, "cos", float3, "angle");
+ symbolTable.insertBuiltIn(float4, "cos", float4, "angle");
+
+ symbolTable.insertBuiltIn(float1, "tan", float1, "angle");
+ symbolTable.insertBuiltIn(float2, "tan", float2, "angle");
+ symbolTable.insertBuiltIn(float3, "tan", float3, "angle");
+ symbolTable.insertBuiltIn(float4, "tan", float4, "angle");
+
+ symbolTable.insertBuiltIn(float1, "asin", float1, "x");
+ symbolTable.insertBuiltIn(float2, "asin", float2, "x");
+ symbolTable.insertBuiltIn(float3, "asin", float3, "x");
+ symbolTable.insertBuiltIn(float4, "asin", float4, "x");
+
+ symbolTable.insertBuiltIn(float1, "acos", float1, "x");
+ symbolTable.insertBuiltIn(float2, "acos", float2, "x");
+ symbolTable.insertBuiltIn(float3, "acos", float3, "x");
+ symbolTable.insertBuiltIn(float4, "acos", float4, "x");
+
+ symbolTable.insertBuiltIn(float1, "atan", float1, "y", float1, "x");
+ symbolTable.insertBuiltIn(float2, "atan", float2, "y", float2, "x");
+ symbolTable.insertBuiltIn(float3, "atan", float3, "y", float3, "x");
+ symbolTable.insertBuiltIn(float4, "atan", float4, "y", float4, "x");
+
+ symbolTable.insertBuiltIn(float1, "atan", float1, "y_over_x");
+ symbolTable.insertBuiltIn(float2, "atan", float2, "y_over_x");
+ symbolTable.insertBuiltIn(float3, "atan", float3, "y_over_x");
+ symbolTable.insertBuiltIn(float4, "atan", float4, "y_over_x");
//
// Exponential Functions.
//
- s.append(TString("float pow(float x, float y);"));
- s.append(TString("vec2 pow(vec2 x, vec2 y);"));
- s.append(TString("vec3 pow(vec3 x, vec3 y);"));
- s.append(TString("vec4 pow(vec4 x, vec4 y);"));
-
- s.append(TString("float exp(float x);"));
- s.append(TString("vec2 exp(vec2 x);"));
- s.append(TString("vec3 exp(vec3 x);"));
- s.append(TString("vec4 exp(vec4 x);"));
-
- s.append(TString("float log(float x);"));
- s.append(TString("vec2 log(vec2 x);"));
- s.append(TString("vec3 log(vec3 x);"));
- s.append(TString("vec4 log(vec4 x);"));
-
- s.append(TString("float exp2(float x);"));
- s.append(TString("vec2 exp2(vec2 x);"));
- s.append(TString("vec3 exp2(vec3 x);"));
- s.append(TString("vec4 exp2(vec4 x);"));
-
- s.append(TString("float log2(float x);"));
- s.append(TString("vec2 log2(vec2 x);"));
- s.append(TString("vec3 log2(vec3 x);"));
- s.append(TString("vec4 log2(vec4 x);"));
-
- s.append(TString("float sqrt(float x);"));
- s.append(TString("vec2 sqrt(vec2 x);"));
- s.append(TString("vec3 sqrt(vec3 x);"));
- s.append(TString("vec4 sqrt(vec4 x);"));
-
- s.append(TString("float inversesqrt(float x);"));
- s.append(TString("vec2 inversesqrt(vec2 x);"));
- s.append(TString("vec3 inversesqrt(vec3 x);"));
- s.append(TString("vec4 inversesqrt(vec4 x);"));
+ symbolTable.insertBuiltIn(float1, "pow", float1, "x", float1, "y");
+ symbolTable.insertBuiltIn(float2, "pow", float2, "x", float2, "y");
+ symbolTable.insertBuiltIn(float3, "pow", float3, "x", float3, "y");
+ symbolTable.insertBuiltIn(float4, "pow", float4, "x", float4, "y");
+
+ symbolTable.insertBuiltIn(float1, "exp", float1, "x");
+ symbolTable.insertBuiltIn(float2, "exp", float2, "x");
+ symbolTable.insertBuiltIn(float3, "exp", float3, "x");
+ symbolTable.insertBuiltIn(float4, "exp", float4, "x");
+
+ symbolTable.insertBuiltIn(float1, "log", float1, "x");
+ symbolTable.insertBuiltIn(float2, "log", float2, "x");
+ symbolTable.insertBuiltIn(float3, "log", float3, "x");
+ symbolTable.insertBuiltIn(float4, "log", float4, "x");
+
+ symbolTable.insertBuiltIn(float1, "exp2", float1, "x");
+ symbolTable.insertBuiltIn(float2, "exp2", float2, "x");
+ symbolTable.insertBuiltIn(float3, "exp2", float3, "x");
+ symbolTable.insertBuiltIn(float4, "exp2", float4, "x");
+
+ symbolTable.insertBuiltIn(float1, "log2", float1, "x");
+ symbolTable.insertBuiltIn(float2, "log2", float2, "x");
+ symbolTable.insertBuiltIn(float3, "log2", float3, "x");
+ symbolTable.insertBuiltIn(float4, "log2", float4, "x");
+
+ symbolTable.insertBuiltIn(float1, "sqrt", float1, "x");
+ symbolTable.insertBuiltIn(float2, "sqrt", float2, "x");
+ symbolTable.insertBuiltIn(float3, "sqrt", float3, "x");
+ symbolTable.insertBuiltIn(float4, "sqrt", float4, "x");
+
+ symbolTable.insertBuiltIn(float1, "inversesqrt", float1, "x");
+ symbolTable.insertBuiltIn(float2, "inversesqrt", float2, "x");
+ symbolTable.insertBuiltIn(float3, "inversesqrt", float3, "x");
+ symbolTable.insertBuiltIn(float4, "inversesqrt", float4, "x");
//
// Common Functions.
//
- s.append(TString("float abs(float x);"));
- s.append(TString("vec2 abs(vec2 x);"));
- s.append(TString("vec3 abs(vec3 x);"));
- s.append(TString("vec4 abs(vec4 x);"));
-
- s.append(TString("float sign(float x);"));
- s.append(TString("vec2 sign(vec2 x);"));
- s.append(TString("vec3 sign(vec3 x);"));
- s.append(TString("vec4 sign(vec4 x);"));
-
- s.append(TString("float floor(float x);"));
- s.append(TString("vec2 floor(vec2 x);"));
- s.append(TString("vec3 floor(vec3 x);"));
- s.append(TString("vec4 floor(vec4 x);"));
-
- s.append(TString("float ceil(float x);"));
- s.append(TString("vec2 ceil(vec2 x);"));
- s.append(TString("vec3 ceil(vec3 x);"));
- s.append(TString("vec4 ceil(vec4 x);"));
-
- s.append(TString("float fract(float x);"));
- s.append(TString("vec2 fract(vec2 x);"));
- s.append(TString("vec3 fract(vec3 x);"));
- s.append(TString("vec4 fract(vec4 x);"));
-
- s.append(TString("float mod(float x, float y);"));
- s.append(TString("vec2 mod(vec2 x, float y);"));
- s.append(TString("vec3 mod(vec3 x, float y);"));
- s.append(TString("vec4 mod(vec4 x, float y);"));
- s.append(TString("vec2 mod(vec2 x, vec2 y);"));
- s.append(TString("vec3 mod(vec3 x, vec3 y);"));
- s.append(TString("vec4 mod(vec4 x, vec4 y);"));
-
- s.append(TString("float min(float x, float y);"));
- s.append(TString("vec2 min(vec2 x, float y);"));
- s.append(TString("vec3 min(vec3 x, float y);"));
- s.append(TString("vec4 min(vec4 x, float y);"));
- s.append(TString("vec2 min(vec2 x, vec2 y);"));
- s.append(TString("vec3 min(vec3 x, vec3 y);"));
- s.append(TString("vec4 min(vec4 x, vec4 y);"));
-
- s.append(TString("float max(float x, float y);"));
- s.append(TString("vec2 max(vec2 x, float y);"));
- s.append(TString("vec3 max(vec3 x, float y);"));
- s.append(TString("vec4 max(vec4 x, float y);"));
- s.append(TString("vec2 max(vec2 x, vec2 y);"));
- s.append(TString("vec3 max(vec3 x, vec3 y);"));
- s.append(TString("vec4 max(vec4 x, vec4 y);"));
-
- s.append(TString("float clamp(float x, float minVal, float maxVal);"));
- s.append(TString("vec2 clamp(vec2 x, float minVal, float maxVal);"));
- s.append(TString("vec3 clamp(vec3 x, float minVal, float maxVal);"));
- s.append(TString("vec4 clamp(vec4 x, float minVal, float maxVal);"));
- s.append(TString("vec2 clamp(vec2 x, vec2 minVal, vec2 maxVal);"));
- s.append(TString("vec3 clamp(vec3 x, vec3 minVal, vec3 maxVal);"));
- s.append(TString("vec4 clamp(vec4 x, vec4 minVal, vec4 maxVal);"));
-
- s.append(TString("float mix(float x, float y, float a);"));
- s.append(TString("vec2 mix(vec2 x, vec2 y, float a);"));
- s.append(TString("vec3 mix(vec3 x, vec3 y, float a);"));
- s.append(TString("vec4 mix(vec4 x, vec4 y, float a);"));
- s.append(TString("vec2 mix(vec2 x, vec2 y, vec2 a);"));
- s.append(TString("vec3 mix(vec3 x, vec3 y, vec3 a);"));
- s.append(TString("vec4 mix(vec4 x, vec4 y, vec4 a);"));
-
- s.append(TString("float step(float edge, float x);"));
- s.append(TString("vec2 step(vec2 edge, vec2 x);"));
- s.append(TString("vec3 step(vec3 edge, vec3 x);"));
- s.append(TString("vec4 step(vec4 edge, vec4 x);"));
- s.append(TString("vec2 step(float edge, vec2 x);"));
- s.append(TString("vec3 step(float edge, vec3 x);"));
- s.append(TString("vec4 step(float edge, vec4 x);"));
-
- s.append(TString("float smoothstep(float edge0, float edge1, float x);"));
- s.append(TString("vec2 smoothstep(vec2 edge0, vec2 edge1, vec2 x);"));
- s.append(TString("vec3 smoothstep(vec3 edge0, vec3 edge1, vec3 x);"));
- s.append(TString("vec4 smoothstep(vec4 edge0, vec4 edge1, vec4 x);"));
- s.append(TString("vec2 smoothstep(float edge0, float edge1, vec2 x);"));
- s.append(TString("vec3 smoothstep(float edge0, float edge1, vec3 x);"));
- s.append(TString("vec4 smoothstep(float edge0, float edge1, vec4 x);"));
+ symbolTable.insertBuiltIn(float1, "abs", float1, "x");
+ symbolTable.insertBuiltIn(float2, "abs", float2, "x");
+ symbolTable.insertBuiltIn(float3, "abs", float3, "x");
+ symbolTable.insertBuiltIn(float4, "abs", float4, "x");
+
+ symbolTable.insertBuiltIn(float1, "sign", float1, "x");
+ symbolTable.insertBuiltIn(float2, "sign", float2, "x");
+ symbolTable.insertBuiltIn(float3, "sign", float3, "x");
+ symbolTable.insertBuiltIn(float4, "sign", float4, "x");
+
+ symbolTable.insertBuiltIn(float1, "floor", float1, "x");
+ symbolTable.insertBuiltIn(float2, "floor", float2, "x");
+ symbolTable.insertBuiltIn(float3, "floor", float3, "x");
+ symbolTable.insertBuiltIn(float4, "floor", float4, "x");
+
+ symbolTable.insertBuiltIn(float1, "ceil", float1, "x");
+ symbolTable.insertBuiltIn(float2, "ceil", float2, "x");
+ symbolTable.insertBuiltIn(float3, "ceil", float3, "x");
+ symbolTable.insertBuiltIn(float4, "ceil", float4, "x");
+
+ symbolTable.insertBuiltIn(float1, "fract", float1, "x");
+ symbolTable.insertBuiltIn(float2, "fract", float2, "x");
+ symbolTable.insertBuiltIn(float3, "fract", float3, "x");
+ symbolTable.insertBuiltIn(float4, "fract", float4, "x");
+
+ symbolTable.insertBuiltIn(float1, "mod", float1, "x", float1, "y");
+ symbolTable.insertBuiltIn(float2, "mod", float2, "x", float1, "y");
+ symbolTable.insertBuiltIn(float3, "mod", float3, "x", float1, "y");
+ symbolTable.insertBuiltIn(float4, "mod", float4, "x", float1, "y");
+ symbolTable.insertBuiltIn(float2, "mod", float2, "x", float2, "y");
+ symbolTable.insertBuiltIn(float3, "mod", float3, "x", float3, "y");
+ symbolTable.insertBuiltIn(float4, "mod", float4, "x", float4, "y");
+
+ symbolTable.insertBuiltIn(float1, "min", float1, "x", float1, "y");
+ symbolTable.insertBuiltIn(float2, "min", float2, "x", float1, "y");
+ symbolTable.insertBuiltIn(float3, "min", float3, "x", float1, "y");
+ symbolTable.insertBuiltIn(float4, "min", float4, "x", float1, "y");
+ symbolTable.insertBuiltIn(float2, "min", float2, "x", float2, "y");
+ symbolTable.insertBuiltIn(float3, "min", float3, "x", float3, "y");
+ symbolTable.insertBuiltIn(float4, "min", float4, "x", float4, "y");
+
+ symbolTable.insertBuiltIn(float1, "max", float1, "x", float1, "y");
+ symbolTable.insertBuiltIn(float2, "max", float2, "x", float1, "y");
+ symbolTable.insertBuiltIn(float3, "max", float3, "x", float1, "y");
+ symbolTable.insertBuiltIn(float4, "max", float4, "x", float1, "y");
+ symbolTable.insertBuiltIn(float2, "max", float2, "x", float2, "y");
+ symbolTable.insertBuiltIn(float3, "max", float3, "x", float3, "y");
+ symbolTable.insertBuiltIn(float4, "max", float4, "x", float4, "y");
+
+ symbolTable.insertBuiltIn(float1, "clamp", float1, "x", float1, "minVal", float1, "maxVal");
+ symbolTable.insertBuiltIn(float2, "clamp", float2, "x", float1, "minVal", float1, "maxVal");
+ symbolTable.insertBuiltIn(float3, "clamp", float3, "x", float1, "minVal", float1, "maxVal");
+ symbolTable.insertBuiltIn(float4, "clamp", float4, "x", float1, "minVal", float1, "maxVal");
+ symbolTable.insertBuiltIn(float2, "clamp", float2, "x", float2, "minVal", float2, "maxVal");
+ symbolTable.insertBuiltIn(float3, "clamp", float3, "x", float3, "minVal", float3, "maxVal");
+ symbolTable.insertBuiltIn(float4, "clamp", float4, "x", float4, "minVal", float4, "maxVal");
+
+ symbolTable.insertBuiltIn(float1, "mix", float1, "x", float1, "y", float1, "a");
+ symbolTable.insertBuiltIn(float2, "mix", float2, "x", float2, "y", float1, "a");
+ symbolTable.insertBuiltIn(float3, "mix", float3, "x", float3, "y", float1, "a");
+ symbolTable.insertBuiltIn(float4, "mix", float4, "x", float4, "y", float1, "a");
+ symbolTable.insertBuiltIn(float2, "mix", float2, "x", float2, "y", float2, "a");
+ symbolTable.insertBuiltIn(float3, "mix", float3, "x", float3, "y", float3, "a");
+ symbolTable.insertBuiltIn(float4, "mix", float4, "x", float4, "y", float4, "a");
+
+ symbolTable.insertBuiltIn(float1, "step", float1, "edge", float1, "x");
+ symbolTable.insertBuiltIn(float2, "step", float2, "edge", float2, "x");
+ symbolTable.insertBuiltIn(float3, "step", float3, "edge", float3, "x");
+ symbolTable.insertBuiltIn(float4, "step", float4, "edge", float4, "x");
+ symbolTable.insertBuiltIn(float2, "step", float1, "edge", float2, "x");
+ symbolTable.insertBuiltIn(float3, "step", float1, "edge", float3, "x");
+ symbolTable.insertBuiltIn(float4, "step", float1, "edge", float4, "x");
+
+ symbolTable.insertBuiltIn(float1, "smoothstep", float1, "edge0", float1, "edge1", float1, "x");
+ symbolTable.insertBuiltIn(float2, "smoothstep", float2, "edge0", float2, "edge1", float2, "x");
+ symbolTable.insertBuiltIn(float3, "smoothstep", float3, "edge0", float3, "edge1", float3, "x");
+ symbolTable.insertBuiltIn(float4, "smoothstep", float4, "edge0", float4, "edge1", float4, "x");
+ symbolTable.insertBuiltIn(float2, "smoothstep", float1, "edge0", float1, "edge1", float2, "x");
+ symbolTable.insertBuiltIn(float3, "smoothstep", float1, "edge0", float1, "edge1", float3, "x");
+ symbolTable.insertBuiltIn(float4, "smoothstep", float1, "edge0", float1, "edge1", float4, "x");
//
// Geometric Functions.
//
- s.append(TString("float length(float x);"));
- s.append(TString("float length(vec2 x);"));
- s.append(TString("float length(vec3 x);"));
- s.append(TString("float length(vec4 x);"));
-
- s.append(TString("float distance(float p0, float p1);"));
- s.append(TString("float distance(vec2 p0, vec2 p1);"));
- s.append(TString("float distance(vec3 p0, vec3 p1);"));
- s.append(TString("float distance(vec4 p0, vec4 p1);"));
-
- s.append(TString("float dot(float x, float y);"));
- s.append(TString("float dot(vec2 x, vec2 y);"));
- s.append(TString("float dot(vec3 x, vec3 y);"));
- s.append(TString("float dot(vec4 x, vec4 y);"));
-
- s.append(TString("vec3 cross(vec3 x, vec3 y);"));
- s.append(TString("float normalize(float x);"));
- s.append(TString("vec2 normalize(vec2 x);"));
- s.append(TString("vec3 normalize(vec3 x);"));
- s.append(TString("vec4 normalize(vec4 x);"));
-
- s.append(TString("float faceforward(float N, float I, float Nref);"));
- s.append(TString("vec2 faceforward(vec2 N, vec2 I, vec2 Nref);"));
- s.append(TString("vec3 faceforward(vec3 N, vec3 I, vec3 Nref);"));
- s.append(TString("vec4 faceforward(vec4 N, vec4 I, vec4 Nref);"));
-
- s.append(TString("float reflect(float I, float N);"));
- s.append(TString("vec2 reflect(vec2 I, vec2 N);"));
- s.append(TString("vec3 reflect(vec3 I, vec3 N);"));
- s.append(TString("vec4 reflect(vec4 I, vec4 N);"));
-
- s.append(TString("float refract(float I, float N, float eta);"));
- s.append(TString("vec2 refract(vec2 I, vec2 N, float eta);"));
- s.append(TString("vec3 refract(vec3 I, vec3 N, float eta);"));
- s.append(TString("vec4 refract(vec4 I, vec4 N, float eta);"));
+ symbolTable.insertBuiltIn(float1, "length", float1, "x");
+ symbolTable.insertBuiltIn(float1, "length", float2, "x");
+ symbolTable.insertBuiltIn(float1, "length", float3, "x");
+ symbolTable.insertBuiltIn(float1, "length", float4, "x");
+
+ symbolTable.insertBuiltIn(float1, "distance", float1, "p0", float1, "p1");
+ symbolTable.insertBuiltIn(float1, "distance", float2, "p0", float2, "p1");
+ symbolTable.insertBuiltIn(float1, "distance", float3, "p0", float3, "p1");
+ symbolTable.insertBuiltIn(float1, "distance", float4, "p0", float4, "p1");
+
+ symbolTable.insertBuiltIn(float1, "dot", float1, "x", float1, "y");
+ symbolTable.insertBuiltIn(float1, "dot", float2, "x", float2, "y");
+ symbolTable.insertBuiltIn(float1, "dot", float3, "x", float3, "y");
+ symbolTable.insertBuiltIn(float1, "dot", float4, "x", float4, "y");
+
+ symbolTable.insertBuiltIn(float3, "cross", float3, "x", float3, "y");
+ symbolTable.insertBuiltIn(float1, "normalize", float1, "x");
+ symbolTable.insertBuiltIn(float2, "normalize", float2, "x");
+ symbolTable.insertBuiltIn(float3, "normalize", float3, "x");
+ symbolTable.insertBuiltIn(float4, "normalize", float4, "x");
+
+ symbolTable.insertBuiltIn(float1, "faceforward", float1, "N", float1, "I", float1, "Nref");
+ symbolTable.insertBuiltIn(float2, "faceforward", float2, "N", float2, "I", float2, "Nref");
+ symbolTable.insertBuiltIn(float3, "faceforward", float3, "N", float3, "I", float3, "Nref");
+ symbolTable.insertBuiltIn(float4, "faceforward", float4, "N", float4, "I", float4, "Nref");
+
+ symbolTable.insertBuiltIn(float1, "reflect", float1, "I", float1, "N");
+ symbolTable.insertBuiltIn(float2, "reflect", float2, "I", float2, "N");
+ symbolTable.insertBuiltIn(float3, "reflect", float3, "I", float3, "N");
+ symbolTable.insertBuiltIn(float4, "reflect", float4, "I", float4, "N");
+
+ symbolTable.insertBuiltIn(float1, "refract", float1, "I", float1, "N", float1, "eta");
+ symbolTable.insertBuiltIn(float2, "refract", float2, "I", float2, "N", float1, "eta");
+ symbolTable.insertBuiltIn(float3, "refract", float3, "I", float3, "N", float1, "eta");
+ symbolTable.insertBuiltIn(float4, "refract", float4, "I", float4, "N", float1, "eta");
+
+ 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.
//
- 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);"));
+ symbolTable.insertBuiltIn(mat2, "matrixCompMult", mat2, "x", mat2, "y");
+ symbolTable.insertBuiltIn(mat3, "matrixCompMult", mat3, "x", mat3, "y");
+ symbolTable.insertBuiltIn(mat4, "matrixCompMult", mat4, "x", mat4, "y");
+
+ 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.
//
- s.append(TString("bvec2 lessThan(vec2 x, vec2 y);"));
- s.append(TString("bvec3 lessThan(vec3 x, vec3 y);"));
- s.append(TString("bvec4 lessThan(vec4 x, vec4 y);"));
-
- s.append(TString("bvec2 lessThan(ivec2 x, ivec2 y);"));
- s.append(TString("bvec3 lessThan(ivec3 x, ivec3 y);"));
- s.append(TString("bvec4 lessThan(ivec4 x, ivec4 y);"));
+ symbolTable.insertBuiltIn(bool2, "lessThan", float2, "x", float2, "y");
+ symbolTable.insertBuiltIn(bool3, "lessThan", float3, "x", float3, "y");
+ symbolTable.insertBuiltIn(bool4, "lessThan", float4, "x", float4, "y");
- s.append(TString("bvec2 lessThanEqual(vec2 x, vec2 y);"));
- s.append(TString("bvec3 lessThanEqual(vec3 x, vec3 y);"));
- s.append(TString("bvec4 lessThanEqual(vec4 x, vec4 y);"));
+ symbolTable.insertBuiltIn(bool2, "lessThan", int2, "x", int2, "y");
+ symbolTable.insertBuiltIn(bool3, "lessThan", int3, "x", int3, "y");
+ symbolTable.insertBuiltIn(bool4, "lessThan", int4, "x", int4, "y");
- s.append(TString("bvec2 lessThanEqual(ivec2 x, ivec2 y);"));
- s.append(TString("bvec3 lessThanEqual(ivec3 x, ivec3 y);"));
- s.append(TString("bvec4 lessThanEqual(ivec4 x, ivec4 y);"));
+ symbolTable.insertBuiltIn(bool2, "lessThanEqual", float2, "x", float2, "y");
+ symbolTable.insertBuiltIn(bool3, "lessThanEqual", float3, "x", float3, "y");
+ symbolTable.insertBuiltIn(bool4, "lessThanEqual", float4, "x", float4, "y");
- s.append(TString("bvec2 greaterThan(vec2 x, vec2 y);"));
- s.append(TString("bvec3 greaterThan(vec3 x, vec3 y);"));
- s.append(TString("bvec4 greaterThan(vec4 x, vec4 y);"));
+ symbolTable.insertBuiltIn(bool2, "lessThanEqual", int2, "x", int2, "y");
+ symbolTable.insertBuiltIn(bool3, "lessThanEqual", int3, "x", int3, "y");
+ symbolTable.insertBuiltIn(bool4, "lessThanEqual", int4, "x", int4, "y");
- s.append(TString("bvec2 greaterThan(ivec2 x, ivec2 y);"));
- s.append(TString("bvec3 greaterThan(ivec3 x, ivec3 y);"));
- s.append(TString("bvec4 greaterThan(ivec4 x, ivec4 y);"));
+ symbolTable.insertBuiltIn(bool2, "greaterThan", float2, "x", float2, "y");
+ symbolTable.insertBuiltIn(bool3, "greaterThan", float3, "x", float3, "y");
+ symbolTable.insertBuiltIn(bool4, "greaterThan", float4, "x", float4, "y");
- s.append(TString("bvec2 greaterThanEqual(vec2 x, vec2 y);"));
- s.append(TString("bvec3 greaterThanEqual(vec3 x, vec3 y);"));
- s.append(TString("bvec4 greaterThanEqual(vec4 x, vec4 y);"));
+ symbolTable.insertBuiltIn(bool2, "greaterThan", int2, "x", int2, "y");
+ symbolTable.insertBuiltIn(bool3, "greaterThan", int3, "x", int3, "y");
+ symbolTable.insertBuiltIn(bool4, "greaterThan", int4, "x", int4, "y");
- s.append(TString("bvec2 greaterThanEqual(ivec2 x, ivec2 y);"));
- s.append(TString("bvec3 greaterThanEqual(ivec3 x, ivec3 y);"));
- s.append(TString("bvec4 greaterThanEqual(ivec4 x, ivec4 y);"));
+ symbolTable.insertBuiltIn(bool2, "greaterThanEqual", float2, "x", float2, "y");
+ symbolTable.insertBuiltIn(bool3, "greaterThanEqual", float3, "x", float3, "y");
+ symbolTable.insertBuiltIn(bool4, "greaterThanEqual", float4, "x", float4, "y");
- s.append(TString("bvec2 equal(vec2 x, vec2 y);"));
- s.append(TString("bvec3 equal(vec3 x, vec3 y);"));
- s.append(TString("bvec4 equal(vec4 x, vec4 y);"));
+ symbolTable.insertBuiltIn(bool2, "greaterThanEqual", int2, "x", int2, "y");
+ symbolTable.insertBuiltIn(bool3, "greaterThanEqual", int3, "x", int3, "y");
+ symbolTable.insertBuiltIn(bool4, "greaterThanEqual", int4, "x", int4, "y");
- s.append(TString("bvec2 equal(ivec2 x, ivec2 y);"));
- s.append(TString("bvec3 equal(ivec3 x, ivec3 y);"));
- s.append(TString("bvec4 equal(ivec4 x, ivec4 y);"));
+ symbolTable.insertBuiltIn(bool2, "equal", float2, "x", float2, "y");
+ symbolTable.insertBuiltIn(bool3, "equal", float3, "x", float3, "y");
+ symbolTable.insertBuiltIn(bool4, "equal", float4, "x", float4, "y");
- s.append(TString("bvec2 equal(bvec2 x, bvec2 y);"));
- s.append(TString("bvec3 equal(bvec3 x, bvec3 y);"));
- s.append(TString("bvec4 equal(bvec4 x, bvec4 y);"));
+ symbolTable.insertBuiltIn(bool2, "equal", int2, "x", int2, "y");
+ symbolTable.insertBuiltIn(bool3, "equal", int3, "x", int3, "y");
+ symbolTable.insertBuiltIn(bool4, "equal", int4, "x", int4, "y");
- s.append(TString("bvec2 notEqual(vec2 x, vec2 y);"));
- s.append(TString("bvec3 notEqual(vec3 x, vec3 y);"));
- s.append(TString("bvec4 notEqual(vec4 x, vec4 y);"));
+ symbolTable.insertBuiltIn(bool2, "equal", bool2, "x", bool2, "y");
+ symbolTable.insertBuiltIn(bool3, "equal", bool3, "x", bool3, "y");
+ symbolTable.insertBuiltIn(bool4, "equal", bool4, "x", bool4, "y");
- s.append(TString("bvec2 notEqual(ivec2 x, ivec2 y);"));
- s.append(TString("bvec3 notEqual(ivec3 x, ivec3 y);"));
- s.append(TString("bvec4 notEqual(ivec4 x, ivec4 y);"));
+ symbolTable.insertBuiltIn(bool2, "notEqual", float2, "x", float2, "y");
+ symbolTable.insertBuiltIn(bool3, "notEqual", float3, "x", float3, "y");
+ symbolTable.insertBuiltIn(bool4, "notEqual", float4, "x", float4, "y");
- s.append(TString("bvec2 notEqual(bvec2 x, bvec2 y);"));
- s.append(TString("bvec3 notEqual(bvec3 x, bvec3 y);"));
- s.append(TString("bvec4 notEqual(bvec4 x, bvec4 y);"));
+ symbolTable.insertBuiltIn(bool2, "notEqual", int2, "x", int2, "y");
+ symbolTable.insertBuiltIn(bool3, "notEqual", int3, "x", int3, "y");
+ symbolTable.insertBuiltIn(bool4, "notEqual", int4, "x", int4, "y");
- s.append(TString("bool any(bvec2 x);"));
- s.append(TString("bool any(bvec3 x);"));
- s.append(TString("bool any(bvec4 x);"));
+ symbolTable.insertBuiltIn(bool2, "notEqual", bool2, "x", bool2, "y");
+ symbolTable.insertBuiltIn(bool3, "notEqual", bool3, "x", bool3, "y");
+ symbolTable.insertBuiltIn(bool4, "notEqual", bool4, "x", bool4, "y");
- s.append(TString("bool all(bvec2 x);"));
- s.append(TString("bool all(bvec3 x);"));
- s.append(TString("bool all(bvec4 x);"));
+ symbolTable.insertBuiltIn(bool1, "any", bool2, "x");
+ symbolTable.insertBuiltIn(bool1, "any", bool3, "x");
+ symbolTable.insertBuiltIn(bool1, "any", bool4, "x");
- s.append(TString("bvec2 not(bvec2 x);"));
- s.append(TString("bvec3 not(bvec3 x);"));
- s.append(TString("bvec4 not(bvec4 x);"));
+ symbolTable.insertBuiltIn(bool1, "all", bool2, "x");
+ symbolTable.insertBuiltIn(bool1, "all", bool3, "x");
+ symbolTable.insertBuiltIn(bool1, "all", bool4, "x");
- //
- // Texture Functions.
- //
- s.append(TString("vec4 texture2D(sampler2D sampler, vec2 coord);"));
- s.append(TString("vec4 texture2DProj(sampler2D sampler, vec3 coord);"));
- s.append(TString("vec4 texture2DProj(sampler2D sampler, vec4 coord);"));
- s.append(TString("vec4 textureCube(samplerCube sampler, vec3 coord);"));
-
- if (resources.OES_EGL_image_external) {
- s.append(TString("vec4 texture2D(samplerExternalOES sampler, vec2 coord);"));
- s.append(TString("vec4 texture2DProj(samplerExternalOES sampler, vec3 coord);"));
- s.append(TString("vec4 texture2DProj(samplerExternalOES sampler, vec4 coord);"));
- }
+ symbolTable.insertBuiltIn(bool2, "not", bool2, "x");
+ symbolTable.insertBuiltIn(bool3, "not", bool3, "x");
+ symbolTable.insertBuiltIn(bool4, "not", bool4, "x");
- if (resources.ARB_texture_rectangle) {
- s.append(TString("vec4 texture2DRect(sampler2DRect sampler, vec2 coord);"));
- s.append(TString("vec4 texture2DRectProj(sampler2DRect sampler, vec3 coord);"));
- s.append(TString("vec4 texture2DRectProj(sampler2DRect sampler, vec4 coord);"));
- }
+ TType *sampler2D = new TType(EbtSampler2D, EbpUndefined, EvqGlobal, 1);
+ TType *samplerCube = new TType(EbtSamplerCube, EbpUndefined, EvqGlobal, 1);
//
- // Noise functions.
+ // Texture Functions
//
- //s.append(TString("float noise1(float x);"));
- //s.append(TString("float noise1(vec2 x);"));
- //s.append(TString("float noise1(vec3 x);"));
- //s.append(TString("float noise1(vec4 x);"));
-
- //s.append(TString("vec2 noise2(float x);"));
- //s.append(TString("vec2 noise2(vec2 x);"));
- //s.append(TString("vec2 noise2(vec3 x);"));
- //s.append(TString("vec2 noise2(vec4 x);"));
-
- //s.append(TString("vec3 noise3(float x);"));
- //s.append(TString("vec3 noise3(vec2 x);"));
- //s.append(TString("vec3 noise3(vec3 x);"));
- //s.append(TString("vec3 noise3(vec4 x);"));
-
- //s.append(TString("vec4 noise4(float x);"));
- //s.append(TString("vec4 noise4(vec2 x);"));
- //s.append(TString("vec4 noise4(vec3 x);"));
- //s.append(TString("vec4 noise4(vec4 x);"));
-
- return s;
-}
+ symbolTable.insertBuiltIn(float4, "texture2D", sampler2D, "sampler", float2, "coord");
+ symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, "sampler", float3, "coord");
+ symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, "sampler", float4, "coord");
+ symbolTable.insertBuiltIn(float4, "textureCube", samplerCube, "sampler", float3, "coord");
-//============================================================================
-//
-// Prototypes for built-in functions seen by vertex shaders only.
-//
-//============================================================================
-static TString BuiltInFunctionsVertex(const ShBuiltInResources& resources)
-{
- TString s;
-
- //
- // Geometric Functions.
- //
- //s.append(TString("vec4 ftransform();"));
-
- //
- // Texture Functions.
- //
- s.append(TString("vec4 texture2DLod(sampler2D sampler, vec2 coord, float lod);"));
- s.append(TString("vec4 texture2DProjLod(sampler2D sampler, vec3 coord, float lod);"));
- s.append(TString("vec4 texture2DProjLod(sampler2D sampler, vec4 coord, float lod);"));
- s.append(TString("vec4 textureCubeLod(samplerCube sampler, vec3 coord, float lod);"));
+ if (resources.OES_EGL_image_external)
+ {
+ TType *samplerExternalOES = new TType(EbtSamplerExternalOES, EbpUndefined, EvqGlobal, 1);
- return s;
-}
+ symbolTable.insertBuiltIn(float4, "texture2D", samplerExternalOES, "sampler", float2, "coord");
+ symbolTable.insertBuiltIn(float4, "texture2DProj", samplerExternalOES, "sampler", float3, "coord");
+ symbolTable.insertBuiltIn(float4, "texture2DProj", samplerExternalOES, "sampler", float4, "coord");
+ }
-//============================================================================
-//
-// Prototypes for built-in functions seen by fragment shaders only.
-//
-//============================================================================
-static TString BuiltInFunctionsFragment(const ShBuiltInResources& resources)
-{
- TString s;
+ if (resources.ARB_texture_rectangle)
+ {
+ TType *sampler2DRect = new TType(EbtSampler2DRect, EbpUndefined, EvqGlobal, 1);
- //
- // Texture Functions.
- //
- s.append(TString("vec4 texture2D(sampler2D sampler, vec2 coord, float bias);"));
- s.append(TString("vec4 texture2DProj(sampler2D sampler, vec3 coord, float bias);"));
- s.append(TString("vec4 texture2DProj(sampler2D sampler, vec4 coord, float bias);"));
- s.append(TString("vec4 textureCube(samplerCube sampler, vec3 coord, float bias);"));
-
- if (resources.OES_standard_derivatives) {
- s.append(TString("float dFdx(float p);"));
- s.append(TString("vec2 dFdx(vec2 p);"));
- s.append(TString("vec3 dFdx(vec3 p);"));
- s.append(TString("vec4 dFdx(vec4 p);"));
-
- s.append(TString("float dFdy(float p);"));
- s.append(TString("vec2 dFdy(vec2 p);"));
- s.append(TString("vec3 dFdy(vec3 p);"));
- s.append(TString("vec4 dFdy(vec4 p);"));
-
- s.append(TString("float fwidth(float p);"));
- s.append(TString("vec2 fwidth(vec2 p);"));
- s.append(TString("vec3 fwidth(vec3 p);"));
- s.append(TString("vec4 fwidth(vec4 p);"));
+ symbolTable.insertBuiltIn(float4, "texture2DRect", sampler2DRect, "sampler", float2, "coord");
+ symbolTable.insertBuiltIn(float4, "texture2DRectProj", sampler2DRect, "sampler", float3, "coord");
+ symbolTable.insertBuiltIn(float4, "texture2DRectProj", sampler2DRect, "sampler", float4, "coord");
}
- return s;
-}
+ if(type == SH_FRAGMENT_SHADER)
+ {
+ symbolTable.insertBuiltIn(float4, "texture2D", sampler2D, "sampler", float2, "coord", float1, "bias");
+ symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, "sampler", float3, "coord", float1, "bias");
+ symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, "sampler", float4, "coord", float1, "bias");
+ symbolTable.insertBuiltIn(float4, "textureCube", samplerCube, "sampler", float3, "coord", float1, "bias");
+
+ if (resources.OES_standard_derivatives)
+ {
+ symbolTable.insertBuiltIn(float1, "dFdx", float1, "p");
+ symbolTable.insertBuiltIn(float2, "dFdx", float2, "p");
+ symbolTable.insertBuiltIn(float3, "dFdx", float3, "p");
+ symbolTable.insertBuiltIn(float4, "dFdx", float4, "p");
+
+ symbolTable.insertBuiltIn(float1, "dFdy", float1, "p");
+ symbolTable.insertBuiltIn(float2, "dFdy", float2, "p");
+ symbolTable.insertBuiltIn(float3, "dFdy", float3, "p");
+ symbolTable.insertBuiltIn(float4, "dFdy", float4, "p");
+
+ symbolTable.insertBuiltIn(float1, "fwidth", float1, "p");
+ symbolTable.insertBuiltIn(float2, "fwidth", float2, "p");
+ symbolTable.insertBuiltIn(float3, "fwidth", float3, "p");
+ symbolTable.insertBuiltIn(float4, "fwidth", float4, "p");
+ }
+ }
-//============================================================================
-//
-// Standard uniforms.
-//
-//============================================================================
-static TString StandardUniforms()
-{
- TString s;
+ if(type == SH_VERTEX_SHADER)
+ {
+ symbolTable.insertBuiltIn(float4, "texture2DLod", sampler2D, "sampler", float2, "coord", float1, "lod");
+ symbolTable.insertBuiltIn(float4, "texture2DProjLod", sampler2D, "sampler", float3, "coord", float1, "lod");
+ symbolTable.insertBuiltIn(float4, "texture2DProjLod", sampler2D, "sampler", float4, "coord", float1, "lod");
+ symbolTable.insertBuiltIn(float4, "textureCubeLod", samplerCube, "sampler", float3, "coord", float1, "lod");
+ }
//
// Depth range in window coordinates
//
- s.append(TString("struct gl_DepthRangeParameters {"));
- s.append(TString(" highp float near;")); // n
- s.append(TString(" highp float far;")); // f
- s.append(TString(" highp float diff;")); // f - n
- s.append(TString("};"));
- s.append(TString("uniform gl_DepthRangeParameters gl_DepthRange;"));
-
- return s;
-}
-
-//============================================================================
-//
-// Default precision for vertex shaders.
-//
-//============================================================================
-static TString DefaultPrecisionVertex()
-{
- TString s;
-
- s.append(TString("precision highp int;"));
- s.append(TString("precision highp float;"));
-
- return s;
-}
-
-//============================================================================
-//
-// Default precision for fragment shaders.
-//
-//============================================================================
-static TString DefaultPrecisionFragment()
-{
- TString s;
-
- s.append(TString("precision mediump int;"));
- // No default precision for float in fragment shaders
-
- return s;
-}
-
-//============================================================================
-//
-// Implementation dependent built-in constants.
-//
-//============================================================================
-static TString BuiltInConstants(ShShaderSpec spec, const ShBuiltInResources &resources, const TExtensionBehavior& extensionBehavior)
-{
- TStringStream s;
-
- s << "const int gl_MaxVertexAttribs = " << resources.MaxVertexAttribs << ";";
- s << "const int gl_MaxVertexUniformVectors = " << resources.MaxVertexUniformVectors << ";";
+ TTypeList *members = NewPoolTTypeList();
+ TType *near = new TType(EbtFloat, EbpHigh, EvqGlobal, 1);
+ TType *far = new TType(EbtFloat, EbpHigh, EvqGlobal, 1);
+ TType *diff = new TType(EbtFloat, EbpHigh, EvqGlobal, 1);
+ near->setFieldName("near");
+ far->setFieldName("far");
+ diff->setFieldName("diff");
+ members->push_back(near);
+ members->push_back(far);
+ members->push_back(diff);
+ TVariable *depthRangeParameters = new TVariable(NewPoolTString("gl_DepthRangeParameters"), TType(members, "gl_DepthRangeParameters"), true);
+ symbolTable.insert(*depthRangeParameters);
+ TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(members, "gl_DepthRangeParameters"));
+ depthRange->setQualifier(EvqUniform);
+ symbolTable.insert(*depthRange);
- s << "const int gl_MaxVaryingVectors = " << resources.MaxVaryingVectors << ";";
- s << "const int gl_MaxVertexTextureImageUnits = " << resources.MaxVertexTextureImageUnits << ";";
- s << "const int gl_MaxCombinedTextureImageUnits = " << resources.MaxCombinedTextureImageUnits << ";";
- s << "const int gl_MaxTextureImageUnits = " << resources.MaxTextureImageUnits << ";";
- s << "const int gl_MaxFragmentUniformVectors = " << resources.MaxFragmentUniformVectors << ";";
+ //
+ // 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)
{
@@ -494,40 +421,13 @@ static TString BuiltInConstants(ShShaderSpec spec, const ShBuiltInResources &res
const bool usingMRTExtension = (iter != extensionBehavior.end() && (iter->second == EBhEnable || iter->second == EBhRequire));
const int maxDrawBuffers = (usingMRTExtension ? resources.MaxDrawBuffers : 1);
- s << "const int gl_MaxDrawBuffers = " << maxDrawBuffers << ";";
+ symbolTable.insertConstInt("gl_MaxDrawBuffers", maxDrawBuffers);
}
-
- return s.str();
-}
-
-void TBuiltIns::initialize(ShShaderType type, ShShaderSpec spec,
- const ShBuiltInResources& resources,
- const TExtensionBehavior& extensionBehavior)
-{
- switch (type) {
- case SH_FRAGMENT_SHADER:
- builtInStrings.push_back(DefaultPrecisionFragment());
- builtInStrings.push_back(BuiltInFunctionsCommon(resources));
- builtInStrings.push_back(BuiltInFunctionsFragment(resources));
- builtInStrings.push_back(StandardUniforms());
- break;
-
- case SH_VERTEX_SHADER:
- builtInStrings.push_back(DefaultPrecisionVertex());
- builtInStrings.push_back(BuiltInFunctionsCommon(resources));
- builtInStrings.push_back(BuiltInFunctionsVertex(resources));
- builtInStrings.push_back(StandardUniforms());
- break;
-
- default: assert(false && "Language not supported");
- }
-
- builtInStrings.push_back(BuiltInConstants(spec, resources, extensionBehavior));
}
void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
- const ShBuiltInResources& resources,
- TSymbolTable& symbolTable)
+ const ShBuiltInResources &resources,
+ TSymbolTable &symbolTable)
{
//
// First, insert some special built-in variables that are not in
@@ -571,8 +471,6 @@ void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
// expected to be resolved through a library of functions, versus as
// operations.
//
- symbolTable.relateToOperator("not", EOpVectorLogicalNot);
-
symbolTable.relateToOperator("matrixCompMult", EOpMul);
symbolTable.relateToOperator("equal", EOpVectorEqual);
@@ -623,6 +521,7 @@ void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
symbolTable.relateToOperator("any", EOpAny);
symbolTable.relateToOperator("all", EOpAll);
+ symbolTable.relateToOperator("not", EOpVectorLogicalNot);
// Map language-specific operators.
switch(type) {
diff --git a/src/compiler/Initialize.h b/src/compiler/Initialize.h
index c76a05a3..d08700cc 100644
--- a/src/compiler/Initialize.h
+++ b/src/compiler/Initialize.h
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
+// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
@@ -11,20 +11,8 @@
#include "compiler/ShHandle.h"
#include "compiler/SymbolTable.h"
-typedef TVector<TString> TBuiltInStrings;
-
-class TBuiltIns {
-public:
- POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
-
- void initialize(ShShaderType type, ShShaderSpec spec,
- const ShBuiltInResources& resources,
- const TExtensionBehavior& extensionBehavior);
- const TBuiltInStrings& getBuiltInStrings() { return builtInStrings; }
-
-protected:
- TBuiltInStrings builtInStrings;
-};
+void InsertBuiltInFunctions(ShShaderType type, ShShaderSpec spec, const ShBuiltInResources &resources,
+ const TExtensionBehavior &extensionBehavior, TSymbolTable &table);
void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources& resources,
diff --git a/src/compiler/SymbolTable.h b/src/compiler/SymbolTable.h
index f6e19598..a5406027 100644
--- a/src/compiler/SymbolTable.h
+++ b/src/compiler/SymbolTable.h
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
+// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
@@ -273,6 +273,35 @@ public:
return table[currentLevel()]->insert(symbol);
}
+ bool insertConstInt(const char *name, int value)
+ {
+ TVariable *constant = new TVariable(NewPoolTString(name), TType(EbtInt, EbpUndefined, EvqConst, 1));
+ constant->getConstPointer()->setIConst(value);
+ return insert(*constant);
+ }
+
+ bool insertBuiltIn(TType *rvalue, const char *name, TType *ptype1, const char *pname1, TType *ptype2 = 0, const char *pname2 = 0, TType *ptype3 = 0, const char *pname3 = 0)
+ {
+ TFunction *function = new TFunction(NewPoolTString(name), *rvalue);
+
+ TParameter param1 = {NewPoolTString(pname1), ptype1};
+ function->addParameter(param1);
+
+ if (pname2)
+ {
+ TParameter param2 = {NewPoolTString(pname2), ptype2};
+ function->addParameter(param2);
+ }
+
+ if (pname3)
+ {
+ TParameter param3 = {NewPoolTString(pname3), ptype3};
+ function->addParameter(param3);
+ }
+
+ return insert(*function);
+ }
+
TSymbol* find(const TString& name, bool* builtIn = 0, bool *sameScope = 0)
{
int level = currentLevel();