Commit c0ca7b4e by acleung@chromium.org

Use new symbol table initization for vertex shader.

BUG= R=alokp@chromium.org Review URL: https://codereview.appspot.com/10247043 git-svn-id: https://angleproject.googlecode.com/svn/trunk@2426 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 18f50f78
...@@ -69,7 +69,20 @@ bool InitializeSymbolTable( ...@@ -69,7 +69,20 @@ bool InitializeSymbolTable(
} }
} }
InsertBuiltInFunctionsCommon(resources, &symbolTable);
switch (type) {
case SH_FRAGMENT_SHADER:
InsertBuiltInFunctionsCommon(resources, &symbolTable);
break;
case SH_VERTEX_SHADER:
InsertBuiltInFunctionsCommon(resources, &symbolTable);
InsertBuiltInFunctionsVertex(resources, &symbolTable);
break;
default: assert(false && "Language not supported");
}
IdentifyBuiltIns(type, spec, resources, symbolTable); IdentifyBuiltIns(type, spec, resources, symbolTable);
return true; return true;
......
...@@ -16,31 +16,6 @@ ...@@ -16,31 +16,6 @@
//============================================================================ //============================================================================
// //
// 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);"));
return s;
}
//============================================================================
//
// Prototypes for built-in functions seen by fragment shaders only. // Prototypes for built-in functions seen by fragment shaders only.
// //
//============================================================================ //============================================================================
...@@ -164,7 +139,6 @@ void TBuiltIns::initialize(ShShaderType type, ShShaderSpec spec, ...@@ -164,7 +139,6 @@ void TBuiltIns::initialize(ShShaderType type, ShShaderSpec spec,
case SH_VERTEX_SHADER: case SH_VERTEX_SHADER:
builtInStrings.push_back(DefaultPrecisionVertex()); builtInStrings.push_back(DefaultPrecisionVertex());
builtInStrings.push_back(BuiltInFunctionsVertex(resources));
builtInStrings.push_back(StandardUniforms()); builtInStrings.push_back(StandardUniforms());
break; break;
......
...@@ -16,6 +16,7 @@ static void builtin1(TSymbolTable* t, TType* rvalue, const char* name, TType* pt ...@@ -16,6 +16,7 @@ static void builtin1(TSymbolTable* t, TType* rvalue, const char* name, TType* pt
f->addParameter(param); f->addParameter(param);
t->insert(*f); t->insert(*f);
} }
static void builtin2(TSymbolTable* t, TType* rvalue, const char* name, TType* ptype1, const char* pname1, TType* ptype2, const char* pname2) static void builtin2(TSymbolTable* t, TType* rvalue, const char* name, TType* ptype1, const char* pname1, TType* ptype2, const char* pname2)
{ {
TFunction* f = new TFunction(new TString(name), *rvalue); TFunction* f = new TFunction(new TString(name), *rvalue);
...@@ -37,7 +38,8 @@ static void builtin3(TSymbolTable* t, TType* rvalue, const char* name, TType* pt ...@@ -37,7 +38,8 @@ static void builtin3(TSymbolTable* t, TType* rvalue, const char* name, TType* pt
f->addParameter(param3); f->addParameter(param3);
t->insert(*f); t->insert(*f);
} }
void InsertBuiltInFunctionsCommon(const ShBuiltInResources& resources, TSymbolTable * t) {
void InsertBuiltInFunctionsCommon(const ShBuiltInResources& resources, TSymbolTable* t) {
builtin1(t, new TType(EbtFloat, EbpUndefined, EvqGlobal, 1, false, false), "radians", new TType(EbtFloat, EbpUndefined, EvqGlobal, 1, false, false), "degrees"); builtin1(t, new TType(EbtFloat, EbpUndefined, EvqGlobal, 1, false, false), "radians", new TType(EbtFloat, EbpUndefined, EvqGlobal, 1, false, false), "degrees");
builtin1(t, new TType(EbtFloat, EbpUndefined, EvqGlobal, 2, false, false), "radians", new TType(EbtFloat, EbpUndefined, EvqGlobal, 2, false, false), "degrees"); builtin1(t, new TType(EbtFloat, EbpUndefined, EvqGlobal, 2, false, false), "radians", new TType(EbtFloat, EbpUndefined, EvqGlobal, 2, false, false), "degrees");
builtin1(t, new TType(EbtFloat, EbpUndefined, EvqGlobal, 3, false, false), "radians", new TType(EbtFloat, EbpUndefined, EvqGlobal, 3, false, false), "degrees"); builtin1(t, new TType(EbtFloat, EbpUndefined, EvqGlobal, 3, false, false), "radians", new TType(EbtFloat, EbpUndefined, EvqGlobal, 3, false, false), "degrees");
...@@ -277,3 +279,11 @@ void InsertBuiltInFunctionsCommon(const ShBuiltInResources& resources, TSymbolTa ...@@ -277,3 +279,11 @@ void InsertBuiltInFunctionsCommon(const ShBuiltInResources& resources, TSymbolTa
builtin2(t, new TType(EbtFloat, EbpUndefined, EvqGlobal, 4, false, false), "texture2DRectProj", new TType(EbtSampler2DRect, EbpUndefined, EvqGlobal, 1, false, false), "sampler", new TType(EbtFloat, EbpUndefined, EvqGlobal, 4, false, false), "coord"); builtin2(t, new TType(EbtFloat, EbpUndefined, EvqGlobal, 4, false, false), "texture2DRectProj", new TType(EbtSampler2DRect, EbpUndefined, EvqGlobal, 1, false, false), "sampler", new TType(EbtFloat, EbpUndefined, EvqGlobal, 4, false, false), "coord");
} }
} }
void InsertBuiltInFunctionsVertex(const ShBuiltInResources& resources, TSymbolTable* t) {
builtin3(t, new TType(EbtFloat, EbpUndefined, EvqGlobal, 4, false, false), "texture2DLod", new TType(EbtSampler2D, EbpUndefined, EvqGlobal, 1, false, false), "sampler", new TType(EbtFloat, EbpUndefined, EvqGlobal, 2, false, false), "coord", new TType(EbtFloat, EbpUndefined, EvqGlobal, 1, false, false), "lod");
builtin3(t, new TType(EbtFloat, EbpUndefined, EvqGlobal, 4, false, false), "texture2DProjLod", new TType(EbtSampler2D, EbpUndefined, EvqGlobal, 1, false, false), "sampler", new TType(EbtFloat, EbpUndefined, EvqGlobal, 3, false, false), "coord", new TType(EbtFloat, EbpUndefined, EvqGlobal, 1, false, false), "lod");
builtin3(t, new TType(EbtFloat, EbpUndefined, EvqGlobal, 4, false, false), "texture2DProjLod", new TType(EbtSampler2D, EbpUndefined, EvqGlobal, 1, false, false), "sampler", new TType(EbtFloat, EbpUndefined, EvqGlobal, 4, false, false), "coord", new TType(EbtFloat, EbpUndefined, EvqGlobal, 1, false, false), "lod");
builtin3(t, new TType(EbtFloat, EbpUndefined, EvqGlobal, 4, false, false), "textureCubeLod", new TType(EbtSamplerCube, EbpUndefined, EvqGlobal, 1, false, false), "sampler", new TType(EbtFloat, EbpUndefined, EvqGlobal, 3, false, false), "coord", new TType(EbtFloat, EbpUndefined, EvqGlobal, 1, false, false), "lod");
}
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
class TSymbolTable; class TSymbolTable;
extern void InsertBuiltInFunctionsCommon(const ShBuiltInResources& resources, TSymbolTable * t); extern void InsertBuiltInFunctionsCommon(const ShBuiltInResources& resources, TSymbolTable* t);
extern void InsertBuiltInFunctionsVertex(const ShBuiltInResources& resources, TSymbolTable* t);
#endif // _BUILTIN_SYMBOL_TABLE_INCLUDED_ #endif // _BUILTIN_SYMBOL_TABLE_INCLUDED_
...@@ -38,6 +38,7 @@ static void builtin1(TSymbolTable* t, TType* rvalue, const char* name, TType* pt ...@@ -38,6 +38,7 @@ static void builtin1(TSymbolTable* t, TType* rvalue, const char* name, TType* pt
f->addParameter(param); f->addParameter(param);
t->insert(*f); t->insert(*f);
} }
static void builtin2(TSymbolTable* t, TType* rvalue, const char* name, TType* ptype1, const char* pname1, TType* ptype2, const char* pname2) static void builtin2(TSymbolTable* t, TType* rvalue, const char* name, TType* ptype1, const char* pname1, TType* ptype2, const char* pname2)
{ {
TFunction* f = new TFunction(new TString(name), *rvalue); TFunction* f = new TFunction(new TString(name), *rvalue);
...@@ -59,33 +60,42 @@ static void builtin3(TSymbolTable* t, TType* rvalue, const char* name, TType* pt ...@@ -59,33 +60,42 @@ static void builtin3(TSymbolTable* t, TType* rvalue, const char* name, TType* pt
f->addParameter(param3); f->addParameter(param3);
t->insert(*f); t->insert(*f);
} }
""" """
output.write(registerfunc) output.write(registerfunc)
commonHeader = "void InsertBuiltInFunctionsCommon(const ShBuiltInResources& resources, TSymbolTable * t) {\n" # A function that parses the JSON representation of a list of builtin functions.
def parseBuiltin(name):
for func in builtin[name]:
out = ""
indent = " ";
size = len(func['parameter'])
if 'condition' in func:
out += indent + "if (" + func['condition'] + ") {\n"
indent += indent;
out += indent + "builtin" + str(size) + "(t, "
out += ttypeMap[func['return_type']]
out += ", \"" + func['name'] + "\""
paramlist = func['parameter']
paramdef = "";
for param in paramlist:
paramdef += ", "
paramdef += ttypeMap[param['type']]
paramdef += ", \"" + param['name'] + "\""
out += paramdef + ");\n"
if 'condition' in func:
out += " }\n"
output.write(out)
commonHeader = "void InsertBuiltInFunctionsCommon(const ShBuiltInResources& resources, TSymbolTable* t) {\n"
output.write(commonHeader) output.write(commonHeader)
parseBuiltin("common")
output.write("}\n\n")
for func in builtin["common"]: vertexHeader = "void InsertBuiltInFunctionsVertex(const ShBuiltInResources& resources, TSymbolTable* t) {\n"
out = "" output.write(vertexHeader)
indent = " "; parseBuiltin("vertex")
size = len(func['parameter']) output.write("}\n\n")
if 'condition' in func:
out += indent + "if (" + func['condition'] + ") {\n"
indent += indent;
out += indent + "builtin" + str(size) + "(t, "
out += ttypeMap[func['return_type']]
out += ", \"" + func['name'] + "\""
paramlist = func['parameter']
paramdef = "";
for param in paramlist:
paramdef += ", "
paramdef += ttypeMap[param['type']]
paramdef += ", \"" + param['name'] + "\""
out += paramdef + ");\n"
if 'condition' in func:
out += " }\n"
output.write(out)
output.write("}\n")
json_data.close() json_data.close()
output.close() output.close()
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