Place built-in intrinsics into their corresponding symbol table level.

TRAC #22954 Signed-off-by: Jamie Madill Signed-off-by: Shannon Woods Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2270 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 89992b5e
...@@ -27,8 +27,27 @@ bool isWebGLBasedSpec(ShShaderSpec spec) ...@@ -27,8 +27,27 @@ bool isWebGLBasedSpec(ShShaderSpec spec)
} }
namespace { namespace {
bool InitializeBuiltIns(const TBuiltInStrings &builtInStrings, TInfoSink &infoSink, TParseContext &parseContext)
{
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.message(EPrefixInternalError, "Unable to parse built-ins");
return false;
}
}
return true;
}
bool InitializeSymbolTable( bool InitializeSymbolTable(
const TBuiltInStrings& builtInStrings, const TBuiltIns &builtIns,
ShShaderType type, ShShaderSpec spec, const ShBuiltInResources& resources, ShShaderType type, ShShaderSpec spec, const ShBuiltInResources& resources,
TInfoSink& infoSink, TSymbolTable& symbolTable) TInfoSink& infoSink, TSymbolTable& symbolTable)
{ {
...@@ -43,34 +62,25 @@ bool InitializeSymbolTable( ...@@ -43,34 +62,25 @@ bool InitializeSymbolTable(
GlobalParseContext = &parseContext; GlobalParseContext = &parseContext;
assert(symbolTable.isEmpty()); assert(symbolTable.isEmpty());
// //
// Parse the built-ins. This should only happen once per // Parse the built-ins into the symbol table levels corresponding to each shader version (cf. ESymbolLevel).
// 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(); // TODO: Common built-ins. // Common built-ins
symbolTable.push();
if (!InitializeBuiltIns(builtIns.getCommonBuiltIns(), infoSink, parseContext))
return false;
// GLSL ES 1.0 built-ins // GLSL ES 1.0 built-ins
symbolTable.push(); symbolTable.push();
for (TBuiltInStrings::const_iterator i = builtInStrings.begin(); i != builtInStrings.end(); ++i) if (!InitializeBuiltIns(builtIns.getEssl1BuiltIns(), infoSink, parseContext))
{
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.message(EPrefixInternalError, "Unable to parse built-ins");
return false; return false;
}
}
symbolTable.push(); // TODO: GLSL ES 3.0 built-ins. // GLSL ES 3.0 built-ins
symbolTable.push();
if (!InitializeBuiltIns(builtIns.getEssl3BuiltIns(), infoSink, parseContext))
return false;
IdentifyBuiltIns(type, spec, resources, symbolTable); IdentifyBuiltIns(type, spec, resources, symbolTable);
...@@ -250,12 +260,12 @@ bool TCompiler::compile(const char* const shaderStrings[], ...@@ -250,12 +260,12 @@ bool TCompiler::compile(const char* const shaderStrings[],
bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources& resources) bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources& resources)
{ {
TBuiltIns builtIns;
compileResources = resources; compileResources = resources;
TBuiltIns builtIns;
builtIns.initialize(shaderType, shaderSpec, resources, extensionBehavior); builtIns.initialize(shaderType, shaderSpec, resources, extensionBehavior);
return InitializeSymbolTable(builtIns.getBuiltInStrings(),
shaderType, shaderSpec, resources, infoSink, symbolTable); return InitializeSymbolTable(builtIns, shaderType, shaderSpec, resources, infoSink, symbolTable);
} }
void TCompiler::clearResults() void TCompiler::clearResults()
......
// //
// 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
// Prototypes for built-in functions seen by both vertex and fragment shaders. // Prototypes for built-in functions seen by both vertex and fragment shaders.
// //
//============================================================================ //============================================================================
static TString BuiltInFunctionsCommon(const ShBuiltInResources& resources) static TString BuiltInFunctionsCommon()
{ {
TString s; TString s;
...@@ -311,26 +311,6 @@ static TString BuiltInFunctionsCommon(const ShBuiltInResources& resources) ...@@ -311,26 +311,6 @@ static TString BuiltInFunctionsCommon(const ShBuiltInResources& resources)
s.append(TString("bvec4 not(bvec4 x);")); s.append(TString("bvec4 not(bvec4 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);"));
}
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);"));
}
//
// Noise functions. // Noise functions.
// //
//s.append(TString("float noise1(float x);")); //s.append(TString("float noise1(float x);"));
...@@ -356,12 +336,39 @@ static TString BuiltInFunctionsCommon(const ShBuiltInResources& resources) ...@@ -356,12 +336,39 @@ static TString BuiltInFunctionsCommon(const ShBuiltInResources& resources)
return s; return s;
} }
static TString BuiltInFunctionsCommonTexture1_0(const ShBuiltInResources& resources)
{
TString s;
//
// Texture Functions for GLSL ES 1.0
//
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);"));
}
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);"));
}
return s;
}
//============================================================================ //============================================================================
// //
// Prototypes for built-in functions seen by vertex shaders only. // Prototypes for built-in functions seen by vertex shaders only.
// //
//============================================================================ //============================================================================
static TString BuiltInFunctionsVertex(const ShBuiltInResources& resources) static TString BuiltInFunctionsVertexTexture1_0()
{ {
TString s; TString s;
...@@ -386,7 +393,7 @@ static TString BuiltInFunctionsVertex(const ShBuiltInResources& resources) ...@@ -386,7 +393,7 @@ static TString BuiltInFunctionsVertex(const ShBuiltInResources& resources)
// Prototypes for built-in functions seen by fragment shaders only. // Prototypes for built-in functions seen by fragment shaders only.
// //
//============================================================================ //============================================================================
static TString BuiltInFunctionsFragment(const ShBuiltInResources& resources) static TString BuiltInFunctionsFragmentTexture1_0(const ShBuiltInResources& resources)
{ {
TString s; TString s;
...@@ -506,23 +513,25 @@ void TBuiltIns::initialize(ShShaderType type, ShShaderSpec spec, ...@@ -506,23 +513,25 @@ void TBuiltIns::initialize(ShShaderType type, ShShaderSpec spec,
{ {
switch (type) { switch (type) {
case SH_FRAGMENT_SHADER: case SH_FRAGMENT_SHADER:
builtInStrings.push_back(DefaultPrecisionFragment()); commonBuiltIns.push_back(DefaultPrecisionFragment());
builtInStrings.push_back(BuiltInFunctionsCommon(resources)); commonBuiltIns.push_back(BuiltInFunctionsCommon());
builtInStrings.push_back(BuiltInFunctionsFragment(resources)); essl1BuiltIns.push_back(BuiltInFunctionsCommonTexture1_0(resources));
builtInStrings.push_back(StandardUniforms()); essl1BuiltIns.push_back(BuiltInFunctionsFragmentTexture1_0(resources));
commonBuiltIns.push_back(StandardUniforms());
break; break;
case SH_VERTEX_SHADER: case SH_VERTEX_SHADER:
builtInStrings.push_back(DefaultPrecisionVertex()); commonBuiltIns.push_back(DefaultPrecisionVertex());
builtInStrings.push_back(BuiltInFunctionsCommon(resources)); commonBuiltIns.push_back(BuiltInFunctionsCommon());
builtInStrings.push_back(BuiltInFunctionsVertex(resources)); essl1BuiltIns.push_back(BuiltInFunctionsCommonTexture1_0(resources));
builtInStrings.push_back(StandardUniforms()); essl1BuiltIns.push_back(BuiltInFunctionsVertexTexture1_0());
commonBuiltIns.push_back(StandardUniforms());
break; break;
default: assert(false && "Language not supported"); default: assert(false && "Language not supported");
} }
builtInStrings.push_back(BuiltInConstants(spec, resources, extensionBehavior)); commonBuiltIns.push_back(BuiltInConstants(spec, resources, extensionBehavior));
} }
void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec, void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
......
// //
// 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -20,10 +20,14 @@ public: ...@@ -20,10 +20,14 @@ public:
void initialize(ShShaderType type, ShShaderSpec spec, void initialize(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources& resources, const ShBuiltInResources& resources,
const TExtensionBehavior& extensionBehavior); const TExtensionBehavior& extensionBehavior);
const TBuiltInStrings& getBuiltInStrings() { return builtInStrings; } const TBuiltInStrings &getCommonBuiltIns() const { return commonBuiltIns; }
const TBuiltInStrings &getEssl1BuiltIns() const { return essl1BuiltIns; }
const TBuiltInStrings &getEssl3BuiltIns() const { return essl3BuiltIns; }
protected: protected:
TBuiltInStrings builtInStrings; TBuiltInStrings commonBuiltIns;
TBuiltInStrings essl1BuiltIns;
TBuiltInStrings essl3BuiltIns;
}; };
void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec, void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment