Commit 4888ceb6 by alokp@chromium.org

Made the API of shader translator library consistent.

- We recently started using OpenGL-type enums. This CL makes all old enums consistent with the new scheme. - Renamed TBuiltInResource to ShBuiltInResources to have a consistent prefix BUG=46 Review URL: http://codereview.appspot.com/2328041 git-svn-id: https://angleproject.googlecode.com/svn/trunk@443 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 2fa73694
......@@ -17,7 +17,61 @@ extern "C" {
// Version number for shader translation API.
// It is incremented everytime the API changes.
#define SH_VERSION 100
#define SH_VERSION 101
//
// The names of the following enums have been derived by replacing GL prefix
// with SH. For example, SH_INFO_LOG_LENGTH is equivalent to GL_INFO_LOG_LENGTH.
// The enum values are also equal to the values of their GL counterpart. This
// is done to make it easier for applications to use the shader library.
//
typedef enum {
SH_FRAGMENT_SHADER = 0x8B30,
SH_VERTEX_SHADER = 0x8B31
} ShShaderType;
typedef enum {
SH_GLES2_SPEC = 0x8B40,
SH_WEBGL_SPEC = 0x8B41
} ShShaderSpec;
typedef enum {
SH_NONE = 0,
SH_INT = 0x1404,
SH_FLOAT = 0x1406,
SH_FLOAT_VEC2 = 0x8B50,
SH_FLOAT_VEC3 = 0x8B51,
SH_FLOAT_VEC4 = 0x8B52,
SH_INT_VEC2 = 0x8B53,
SH_INT_VEC3 = 0x8B54,
SH_INT_VEC4 = 0x8B55,
SH_BOOL = 0x8B56,
SH_BOOL_VEC2 = 0x8B57,
SH_BOOL_VEC3 = 0x8B58,
SH_BOOL_VEC4 = 0x8B59,
SH_FLOAT_MAT2 = 0x8B5A,
SH_FLOAT_MAT3 = 0x8B5B,
SH_FLOAT_MAT4 = 0x8B5C,
SH_SAMPLER_2D = 0x8B5E,
SH_SAMPLER_CUBE = 0x8B60
} ShDataType;
typedef enum {
SH_INFO_LOG_LENGTH = 0x8B84,
SH_OBJECT_CODE_LENGTH = 0x8B88, // GL_SHADER_SOURCE_LENGTH
SH_ACTIVE_UNIFORMS = 0x8B86,
SH_ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87,
SH_ACTIVE_ATTRIBUTES = 0x8B89,
SH_ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A
} ShShaderInfo;
// Compile options.
typedef enum {
SH_VALIDATE = 0,
SH_INTERMEDIATE_TREE = 0x001,
SH_OBJECT_CODE = 0x002,
SH_ATTRIBUTES_UNIFORMS = 0x004
} ShCompileOptions;
//
// Driver must call this first, once, before doing any other
......@@ -30,23 +84,6 @@ int ShInitialize();
// If the function succeeds, the return value is nonzero, else zero.
//
int ShFinalize();
//
// Types of languages the compiler can consume.
//
typedef enum {
EShLangVertex,
EShLangFragment,
EShLangCount,
} EShLanguage;
//
// The language specification compiler conforms to.
// It currently supports OpenGL ES and WebGL specifications.
//
typedef enum {
EShSpecGLES2,
EShSpecWebGL,
} EShSpec;
//
// Implementation dependent built-in resources (constants and extensions).
......@@ -67,12 +104,12 @@ typedef struct
// Extensions.
// Set to 1 to enable the extension, else 0.
int OES_standard_derivatives;
} TBuiltInResource;
} ShBuiltInResources;
//
// Initialize built-in resources with minimum expected values.
//
void ShInitBuiltInResource(TBuiltInResource* resources);
void ShInitBuiltInResources(ShBuiltInResources* resources);
//
// ShHandle held by but opaque to the driver. It is allocated,
......@@ -86,74 +123,41 @@ typedef void* ShHandle;
//
// Driver calls these to create and destroy compiler objects.
//
ShHandle ShConstructCompiler(EShLanguage, EShSpec, const TBuiltInResource*);
void ShDestruct(ShHandle);
// Returns the handle of constructed compiler.
// Parameters:
// type: Specifies the type of shader - SH_FRAGMENT_SHADER or SH_VERTEX_SHADER.
// spec: Specifies the language spec the compiler must conform to -
// SH_GLES2_SPEC or SH_WEBGL_SPEC.
// resources: Specifies the built-in resources.
ShHandle ShConstructCompiler(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources* resources);
void ShDestruct(ShHandle handle);
typedef enum {
// Performs validations only.
EShOptNone = 0x000,
// Writes intermediate tree to info log.
// Can be queried by calling ShGetInfoLog().
EShOptIntermediateTree = 0x001,
// Translates intermediate tree to glsl or hlsl shader.
// Can be queried by calling ShGetObjectCode().
EShOptObjectCode = 0x002,
// Extracts attributes and uniforms.
// Can be queried by calling ShGetActiveAttrib() and ShGetActiveUniform().
EShOptAttribsUniforms = 0x004,
} EShCompileOptions;
//
// The return value of ShCompile is boolean, indicating
// success or failure.
//
// The info-log should be written by ShCompile into
// ShHandle, so it can answer future queries.
//
// Compiles the given shader source.
// If the function succeeds, the return value is nonzero, else zero.
// Parameters:
// handle: Specifies the handle of compiler to be used.
// shaderStrings: Specifies an array of pointers to null-terminated strings
// containing the shader source code.
// numStrings: Specifies the number of elements in shaderStrings array.
// compileOptions: A mask containing the following parameters:
// SH_VALIDATE: Performs validations only.
// SH_INTERMEDIATE_TREE: Writes intermediate tree to info log.
// Can be queried by calling ShGetInfoLog().
// SH_OBJECT_CODE: Translates intermediate tree to glsl or hlsl shader.
// Can be queried by calling ShGetObjectCode().
// SH_ATTRIBUTES_UNIFORMS: Extracts attributes and uniforms.
// Can be queried by calling ShGetActiveAttrib() and
// ShGetActiveUniform().
//
int ShCompile(
const ShHandle,
const ShHandle handle,
const char* const shaderStrings[],
const int numStrings,
int compileOptions
);
// The names of the following enums have been derived by replacing GL prefix
// with SH. For example, SH_INFO_LOG_LENGTH is equivalent to GL_INFO_LOG_LENGTH.
// The enum values are also equal to the values of their GL counterpart. This
// is done to make it easier for applications to use the shader library.
//
// The only exception to this rule is SH_OBJECT_CODE_LENGTH, which does not
// have a GL equivalent. It uses the value of GL_SHADER_SOURCE_LENGTH instead.
typedef enum {
SH_INFO_LOG_LENGTH = 0x8B84,
SH_OBJECT_CODE_LENGTH = 0x8B88, // equal to GL_SHADER_SOURCE_LENGTH.
SH_ACTIVE_UNIFORMS = 0x8B86,
SH_ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87,
SH_ACTIVE_ATTRIBUTES = 0x8B89,
SH_ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A,
} EShInfo;
typedef enum {
SH_NONE = 0,
SH_FLOAT = 0x1406,
SH_FLOAT_VEC2 = 0x8B50,
SH_FLOAT_VEC3 = 0x8B51,
SH_FLOAT_VEC4 = 0x8B52,
SH_FLOAT_MAT2 = 0x8B5A,
SH_FLOAT_MAT3 = 0x8B5B,
SH_FLOAT_MAT4 = 0x8B5C,
SH_INT = 0x1404,
SH_INT_VEC2 = 0x8B53,
SH_INT_VEC3 = 0x8B54,
SH_INT_VEC4 = 0x8B55,
SH_BOOL = 0x8B56,
SH_BOOL_VEC2 = 0x8B57,
SH_BOOL_VEC3 = 0x8B58,
SH_BOOL_VEC4 = 0x8B59,
SH_SAMPLER_2D = 0x8B5E,
SH_SAMPLER_CUBE = 0x8B60,
} EShDataType;
// Returns a parameter from a compiled shader.
// Parameters:
// handle: Specifies the compiler
......@@ -173,7 +177,7 @@ typedef enum {
// termination character.
//
// params: Requested parameter
void ShGetInfo(const ShHandle handle, EShInfo pname, int* params);
void ShGetInfo(const ShHandle handle, ShShaderInfo pname, int* params);
// Returns nul-terminated information log for a compiled shader.
// Parameters:
......@@ -213,7 +217,7 @@ void ShGetActiveAttrib(const ShHandle handle,
int index,
int* length,
int* size,
EShDataType* type,
ShDataType* type,
char* name);
// Returns information about an active uniform variable.
......@@ -234,7 +238,7 @@ void ShGetActiveUniform(const ShHandle handle,
int index,
int* length,
int* size,
EShDataType* type,
ShDataType* type,
char* name);
#ifdef __cplusplus
......
......@@ -22,13 +22,13 @@ enum TFailCode {
EFailCompilerCreate,
};
static EShLanguage FindLanguage(char *lang);
bool CompileFile(char *fileName, ShHandle, int);
void usage();
void FreeFileData(char **data);
char** ReadFileData(char *fileName);
void LogMsg(char* msg, const char* name, const int num, const char* logName);
void PrintActiveVariables(ShHandle compiler, EShInfo varType);
static ShShaderType FindShaderType(char *lang);
static bool CompileFile(char *fileName, ShHandle, int);
static void usage();
static void FreeFileData(char **data);
static char** ReadFileData(char *fileName);
static void LogMsg(char* msg, const char* name, const int num, const char* logName);
static void PrintActiveVariables(ShHandle compiler, ShShaderInfo varType);
//Added to accomodate the multiple strings.
int OutputMultipleStrings = 1;
......@@ -36,9 +36,9 @@ int OutputMultipleStrings = 1;
//
// Set up the per compile resources
//
void GenerateResources(TBuiltInResource* resources)
void GenerateResources(ShBuiltInResources* resources)
{
ShInitBuiltInResource(resources);
ShInitBuiltInResources(resources);
resources->MaxVertexAttribs = 8;
resources->MaxVertexUniformVectors = 128;
......@@ -66,7 +66,7 @@ int main(int argc, char* argv[])
ShInitialize();
TBuiltInResource resources;
ShBuiltInResources resources;
GenerateResources(&resources);
argc--;
......@@ -74,22 +74,22 @@ int main(int argc, char* argv[])
for (; (argc >= 1) && (failCode == ESuccess); argc--, argv++) {
if (argv[0][0] == '-' || argv[0][0] == '/') {
switch (argv[0][1]) {
case 'i': compileOptions |= EShOptIntermediateTree; break;
case 'o': compileOptions |= EShOptObjectCode; break;
case 'u': compileOptions |= EShOptAttribsUniforms; break;
case 'i': compileOptions |= SH_INTERMEDIATE_TREE; break;
case 'o': compileOptions |= SH_OBJECT_CODE; break;
case 'u': compileOptions |= SH_ATTRIBUTES_UNIFORMS; break;
default: failCode = EFailUsage;
}
} else {
ShHandle compiler = 0;
switch (FindLanguage(argv[0])) {
case EShLangVertex:
switch (FindShaderType(argv[0])) {
case SH_VERTEX_SHADER:
if (vertexCompiler == 0)
vertexCompiler = ShConstructCompiler(EShLangVertex, EShSpecGLES2, &resources);
vertexCompiler = ShConstructCompiler(SH_VERTEX_SHADER, SH_GLES2_SPEC, &resources);
compiler = vertexCompiler;
break;
case EShLangFragment:
case SH_FRAGMENT_SHADER:
if (fragmentCompiler == 0)
fragmentCompiler = ShConstructCompiler(EShLangFragment, EShSpecGLES2, &resources);
fragmentCompiler = ShConstructCompiler(SH_FRAGMENT_SHADER, SH_GLES2_SPEC, &resources);
compiler = fragmentCompiler;
break;
default: break;
......@@ -105,7 +105,7 @@ int main(int argc, char* argv[])
LogMsg("END", "COMPILER", numCompiles, "INFO LOG");
printf("\n\n");
if (compiled && (compileOptions & EShOptObjectCode)) {
if (compiled && (compileOptions & SH_OBJECT_CODE)) {
LogMsg("BEGIN", "COMPILER", numCompiles, "OBJ CODE");
ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &bufferLen);
buffer = (char*) realloc(buffer, bufferLen * sizeof(char));
......@@ -114,7 +114,7 @@ int main(int argc, char* argv[])
LogMsg("END", "COMPILER", numCompiles, "OBJ CODE");
printf("\n\n");
}
if (compiled && (compileOptions & EShOptAttribsUniforms)) {
if (compiled && (compileOptions & SH_ATTRIBUTES_UNIFORMS)) {
LogMsg("BEGIN", "COMPILER", numCompiles, "ACTIVE ATTRIBS");
PrintActiveVariables(compiler, SH_ACTIVE_ATTRIBUTES);
LogMsg("END", "COMPILER", numCompiles, "ACTIVE ATTRIBS");
......@@ -151,16 +151,16 @@ int main(int argc, char* argv[])
}
//
// Deduce the language from the filename. Files must end in one of the
// Deduce the shader type from the filename. Files must end in one of the
// following extensions:
//
// .frag* = fragment programs
// .vert* = vertex programs
// .frag* = fragment shader
// .vert* = vertex shader
//
static EShLanguage FindLanguage(char *name)
ShShaderType FindShaderType(char *name)
{
if (!name)
return EShLangFragment;
return SH_FRAGMENT_SHADER;
char *ext = strrchr(name, '.');
......@@ -168,11 +168,11 @@ static EShLanguage FindLanguage(char *name)
for (; ext > name && ext[0] != '.'; ext--);
if (ext = strrchr(name, '.')) {
if (strncmp(ext, ".frag", 4) == 0) return EShLangFragment;
if (strncmp(ext, ".vert", 4) == 0) return EShLangVertex;
if (strncmp(ext, ".frag", 4) == 0) return SH_FRAGMENT_SHADER;
if (strncmp(ext, ".vert", 4) == 0) return SH_VERTEX_SHADER;
}
return EShLangFragment;
return SH_FRAGMENT_SHADER;
}
//
......@@ -274,7 +274,7 @@ void LogMsg(char* msg, const char* name, const int num, const char* logName)
printf("#### %s %s %d %s ####\n", msg, name, num, logName);
}
void PrintActiveVariables(ShHandle compiler, EShInfo varType)
void PrintActiveVariables(ShHandle compiler, ShShaderInfo varType)
{
int nameSize = 0;
switch (varType) {
......@@ -290,7 +290,7 @@ void PrintActiveVariables(ShHandle compiler, EShInfo varType)
char* name = (char*) malloc(nameSize * sizeof(char));
int activeVars = 0, size = 0;
EShDataType type;
ShDataType type = SH_NONE;
char* typeName = NULL;
ShGetInfo(compiler, varType, &activeVars);
for (int i = 0; i < activeVars; ++i) {
......
......@@ -11,9 +11,9 @@
// compile object used by higher level code. It returns
// a subclass of TCompiler.
//
TCompiler* ConstructCompiler(EShLanguage language, EShSpec spec)
TCompiler* ConstructCompiler(ShShaderType type, ShShaderSpec spec)
{
return new TranslatorGLSL(language, spec);
return new TranslatorGLSL(type, spec);
}
//
......
......@@ -11,9 +11,9 @@
// compile object used by higher level code. It returns
// a subclass of TCompiler.
//
TCompiler* ConstructCompiler(EShLanguage language, EShSpec spec)
TCompiler* ConstructCompiler(ShShaderType type, ShShaderSpec spec)
{
return new TranslatorHLSL(language, spec);
return new TranslatorHLSL(type, spec);
}
//
......
......@@ -10,12 +10,12 @@
static bool InitializeSymbolTable(
const TBuiltInStrings& builtInStrings,
EShLanguage language, EShSpec spec, const TBuiltInResource& resources,
ShShaderType type, ShShaderSpec spec, const ShBuiltInResources& resources,
TInfoSink& infoSink, TSymbolTable& symbolTable)
{
TIntermediate intermediate(infoSink);
TExtensionBehavior extBehavior;
TParseContext parseContext(symbolTable, extBehavior, intermediate, language, spec, infoSink);
TParseContext parseContext(symbolTable, extBehavior, intermediate, type, spec, infoSink);
GlobalParseContext = &parseContext;
......@@ -53,7 +53,7 @@ static bool InitializeSymbolTable(
}
}
IdentifyBuiltIns(language, spec, resources, symbolTable);
IdentifyBuiltIns(type, spec, resources, symbolTable);
FinalizePreprocessor();
......@@ -68,7 +68,17 @@ static void DefineExtensionMacros(const TExtensionBehavior& extBehavior)
}
}
bool TCompiler::Init(const TBuiltInResource& resources)
TCompiler::TCompiler(ShShaderType type, ShShaderSpec spec)
: shaderType(type),
shaderSpec(spec)
{
}
TCompiler::~TCompiler()
{
}
bool TCompiler::Init(const ShBuiltInResources& resources)
{
// Generate built-in symbol table.
if (!InitBuiltInSymbolTable(resources))
......@@ -89,7 +99,7 @@ bool TCompiler::compile(const char* const shaderStrings[],
TIntermediate intermediate(infoSink);
TParseContext parseContext(symbolTable, extensionBehavior, intermediate,
language, spec, infoSink);
shaderType, shaderSpec, infoSink);
GlobalParseContext = &parseContext;
setInitialState();
......@@ -110,13 +120,13 @@ bool TCompiler::compile(const char* const shaderStrings[],
if (success) {
success = intermediate.postProcess(parseContext.treeRoot);
if (success && (compileOptions & EShOptIntermediateTree))
if (success && (compileOptions & SH_INTERMEDIATE_TREE))
intermediate.outputTree(parseContext.treeRoot);
if (success && (compileOptions & EShOptObjectCode))
if (success && (compileOptions & SH_OBJECT_CODE))
translate(parseContext.treeRoot);
if (success && (compileOptions & EShOptAttribsUniforms))
if (success && (compileOptions & SH_ATTRIBUTES_UNIFORMS))
collectAttribsUniforms(parseContext.treeRoot);
}
......@@ -131,12 +141,13 @@ bool TCompiler::compile(const char* const shaderStrings[],
return success;
}
bool TCompiler::InitBuiltInSymbolTable(const TBuiltInResource& resources)
bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources& resources)
{
TBuiltIns builtIns;
builtIns.initialize(language, spec, resources);
return InitializeSymbolTable(builtIns.getBuiltInStrings(), language, spec, resources, infoSink, symbolTable);
builtIns.initialize(shaderType, shaderSpec, resources);
return InitializeSymbolTable(builtIns.getBuiltInStrings(),
shaderType, shaderSpec, resources, infoSink, symbolTable);
}
void TCompiler::clearResults()
......
......@@ -341,7 +341,7 @@ static TString BuiltInFunctionsCommon()
// Prototypes for built-in functions seen by vertex shaders only.
//
//============================================================================
static TString BuiltInFunctionsVertex(const TBuiltInResource& resources)
static TString BuiltInFunctionsVertex(const ShBuiltInResources& resources)
{
TString s;
......@@ -373,7 +373,7 @@ static TString BuiltInFunctionsVertex(const TBuiltInResource& resources)
// Prototypes for built-in functions seen by fragment shaders only.
//
//============================================================================
static TString BuiltInFunctionsFragment(const TBuiltInResource& resources)
static TString BuiltInFunctionsFragment(const ShBuiltInResources& resources)
{
TString s;
......@@ -467,7 +467,7 @@ static TString DefaultPrecisionFragment()
// Implementation dependent built-in constants.
//
//============================================================================
static TString BuiltInConstants(const TBuiltInResource &resources)
static TString BuiltInConstants(const ShBuiltInResources &resources)
{
TStringStream s;
......@@ -484,17 +484,18 @@ static TString BuiltInConstants(const TBuiltInResource &resources)
return s.str();
}
void TBuiltIns::initialize(EShLanguage language, EShSpec spec, const TBuiltInResource& resources)
void TBuiltIns::initialize(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources& resources)
{
switch (language) {
case EShLangFragment:
switch (type) {
case SH_FRAGMENT_SHADER:
builtInStrings.push_back(DefaultPrecisionFragment());
builtInStrings.push_back(BuiltInFunctionsCommon());
builtInStrings.push_back(BuiltInFunctionsFragment(resources));
builtInStrings.push_back(StandardUniforms());
break;
case EShLangVertex:
case SH_VERTEX_SHADER:
builtInStrings.push_back(DefaultPrecisionVertex());
builtInStrings.push_back(BuiltInFunctionsCommon());
builtInStrings.push_back(BuiltInFunctionsVertex(resources));
......@@ -507,14 +508,16 @@ void TBuiltIns::initialize(EShLanguage language, EShSpec spec, const TBuiltInRes
builtInStrings.push_back(BuiltInConstants(resources));
}
void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource& resources, TSymbolTable& symbolTable)
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(language) {
case EShLangFragment:
switch(type) {
case SH_FRAGMENT_SHADER:
symbolTable.insert(*new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4)));
symbolTable.insert(*new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1)));
symbolTable.insert(*new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4)));
......@@ -522,7 +525,7 @@ void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource
symbolTable.insert(*new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2)));
break;
case EShLangVertex:
case SH_VERTEX_SHADER:
symbolTable.insert(*new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4)));
symbolTable.insert(*new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1)));
break;
......@@ -590,10 +593,10 @@ void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource
symbolTable.relateToOperator("all", EOpAll);
// Map language-specific operators.
switch(language) {
case EShLangVertex:
switch(type) {
case SH_VERTEX_SHADER:
break;
case EShLangFragment:
case SH_FRAGMENT_SHADER:
if (resources.OES_standard_derivatives) {
symbolTable.relateToOperator("dFdx", EOpDFdx);
symbolTable.relateToOperator("dFdy", EOpDFdy);
......@@ -608,8 +611,8 @@ void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource
}
// Finally add resource-specific variables.
switch(language) {
case EShLangFragment: {
switch(type) {
case SH_FRAGMENT_SHADER: {
// Set up gl_FragData. The array size.
TType fragData(EbtFloat, EbpMedium, EvqFragColor, 4, false, true);
fragData.setArraySize(resources.MaxDrawBuffers);
......@@ -620,7 +623,7 @@ void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource
}
}
void InitExtensionBehavior(const TBuiltInResource& resources,
void InitExtensionBehavior(const ShBuiltInResources& resources,
TExtensionBehavior& extBehavior)
{
if (resources.OES_standard_derivatives)
......
......@@ -17,17 +17,19 @@ class TBuiltIns {
public:
POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
void initialize(EShLanguage language, EShSpec spec, const TBuiltInResource& resources);
void initialize(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources& resources);
const TBuiltInStrings& getBuiltInStrings() { return builtInStrings; }
protected:
TBuiltInStrings builtInStrings;
};
void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource& resources,
void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources& resources,
TSymbolTable& symbolTable);
void InitExtensionBehavior(const TBuiltInResource& resources,
void InitExtensionBehavior(const ShBuiltInResources& resources,
TExtensionBehavior& extensionBehavior);
extern "C" int InitPreprocessor(void);
......
......@@ -96,7 +96,7 @@ int OutputHLSL::vectorSize(const TType &type) const
void OutputHLSL::header()
{
EShLanguage language = mContext.language;
ShShaderType shaderType = mContext.shaderType;
TInfoSinkBase &out = mHeader;
for (StructDeclarations::iterator structDeclaration = mStructDeclarations.begin(); structDeclaration != mStructDeclarations.end(); structDeclaration++)
......@@ -109,7 +109,7 @@ void OutputHLSL::header()
out << *constructor;
}
if (language == EShLangFragment)
if (shaderType == SH_FRAGMENT_SHADER)
{
TString uniforms;
TString varyings;
......@@ -946,7 +946,7 @@ bool OutputHLSL::visitUnary(Visit visit, TIntermUnary *node)
bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
{
EShLanguage language = mContext.language;
ShShaderType shaderType = mContext.shaderType;
TInfoSinkBase &out = mBody;
switch (node->getOp())
......
......@@ -415,7 +415,7 @@ bool TParseContext::reservedErrorCheck(int line, const TString& identifier)
error(line, reservedErrMsg, "gl_", "");
return true;
}
if (spec == EShSpecWebGL) {
if (shaderSpec == SH_WEBGL_SPEC) {
if (identifier.substr(0, 6) == TString("webgl_")) {
error(line, reservedErrMsg, "webgl_", "");
return true;
......
......@@ -30,16 +30,16 @@ struct TPragma {
// they can be passed to the parser without needing a global.
//
struct TParseContext {
TParseContext(TSymbolTable& symt, const TExtensionBehavior& ext, TIntermediate& interm, EShLanguage l, EShSpec s, TInfoSink& is) :
intermediate(interm), symbolTable(symt), extensionBehavior(ext), infoSink(is), language(l), spec(s), treeRoot(0),
TParseContext(TSymbolTable& symt, const TExtensionBehavior& ext, TIntermediate& interm, ShShaderType type, ShShaderSpec spec, TInfoSink& is) :
intermediate(interm), symbolTable(symt), extensionBehavior(ext), infoSink(is), shaderType(type), shaderSpec(spec), treeRoot(0),
recoveredFromError(false), numErrors(0), lexAfterType(false), loopNestingLevel(0),
inTypeParen(false), contextPragma(true, false) { }
TIntermediate& intermediate; // to hold and build a parse tree
TSymbolTable& symbolTable; // symbol table that goes with the language currently being parsed
TExtensionBehavior extensionBehavior; // mapping between supported extensions and current behavior.
TInfoSink& infoSink;
EShLanguage language; // vertex or fragment language (future: pack or unpack)
EShSpec spec; // The language specification compiler conforms to - GLES2 or WebGL.
ShShaderType shaderType; // vertex or fragment language (future: pack or unpack)
ShShaderSpec shaderSpec; // The language specification compiler conforms to - GLES2 or WebGL.
TIntermNode* treeRoot; // root of parse tree being created
bool recoveredFromError; // true if a parse error has occurred, but we continue to parse
int numErrors;
......
......@@ -39,11 +39,11 @@ public:
//
class TCompiler : public TShHandleBase {
public:
TCompiler(EShLanguage l, EShSpec s) : language(l), spec(s) {}
virtual ~TCompiler() {}
TCompiler(ShShaderType type, ShShaderSpec spec);
virtual ~TCompiler();
virtual TCompiler* getAsCompiler() { return this; }
bool Init(const TBuiltInResource& resources);
bool Init(const ShBuiltInResources& resources);
bool compile(const char* const shaderStrings[],
const int numStrings,
int compileOptions);
......@@ -55,7 +55,7 @@ public:
protected:
// Initialize symbol-table with built-in symbols.
bool InitBuiltInSymbolTable(const TBuiltInResource& resources);
bool InitBuiltInSymbolTable(const ShBuiltInResources& resources);
// Clears the results from the previous compilation.
void clearResults();
// Collect info for all attribs and uniforms.
......@@ -64,8 +64,8 @@ protected:
virtual void translate(TIntermNode* root) = 0;
private:
EShLanguage language;
EShSpec spec;
ShShaderType shaderType;
ShShaderSpec shaderSpec;
// Built-in symbol table for the given language, spec, and resources.
// It is preserved from compile-to-compile.
......@@ -88,7 +88,7 @@ private:
// destroy the machine dependent objects, which contain the
// above machine independent information.
//
TCompiler* ConstructCompiler(EShLanguage, EShSpec);
TCompiler* ConstructCompiler(ShShaderType type, ShShaderSpec spec);
void DeleteCompiler(TCompiler*);
#endif // _SHHANDLE_INCLUDED_
......@@ -31,12 +31,12 @@ static int getVariableMaxLength(const TVariableInfoList& varList)
return static_cast<int>(maxLen) + 1;
}
static void getVariableInfo(EShInfo varType,
static void getVariableInfo(ShShaderInfo varType,
const ShHandle handle,
int index,
int* length,
int* size,
EShDataType* type,
ShDataType* type,
char* name)
{
if (!handle || !size || !type || !name)
......@@ -87,7 +87,7 @@ int ShFinalize()
//
// Initialize built-in resources with minimum expected values.
//
void ShInitBuiltInResource(TBuiltInResource* resources)
void ShInitBuiltInResources(ShBuiltInResources* resources)
{
// Constants.
resources->MaxVertexAttribs = 8;
......@@ -106,12 +106,13 @@ void ShInitBuiltInResource(TBuiltInResource* resources)
//
// Driver calls these to create and destroy compiler objects.
//
ShHandle ShConstructCompiler(EShLanguage language, EShSpec spec, const TBuiltInResource* resources)
ShHandle ShConstructCompiler(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources* resources)
{
if (!InitThread())
return 0;
TShHandleBase* base = static_cast<TShHandleBase*>(ConstructCompiler(language, spec));
TShHandleBase* base = static_cast<TShHandleBase*>(ConstructCompiler(type, spec));
TCompiler* compiler = base->getAsCompiler();
if (compiler == 0)
return 0;
......@@ -172,7 +173,7 @@ int ShCompile(
return success ? 1 : 0;
}
void ShGetInfo(const ShHandle handle, EShInfo pname, int* params)
void ShGetInfo(const ShHandle handle, ShShaderInfo pname, int* params)
{
if (!handle || !params)
return;
......@@ -242,7 +243,7 @@ void ShGetActiveAttrib(const ShHandle handle,
int index,
int* length,
int* size,
EShDataType* type,
ShDataType* type,
char* name)
{
getVariableInfo(SH_ACTIVE_ATTRIBUTES,
......@@ -253,7 +254,7 @@ void ShGetActiveUniform(const ShHandle handle,
int index,
int* length,
int* size,
EShDataType* type,
ShDataType* type,
char* name)
{
getVariableInfo(SH_ACTIVE_UNIFORMS,
......
......@@ -8,8 +8,8 @@
#include "compiler/OutputGLSL.h"
TranslatorGLSL::TranslatorGLSL(EShLanguage lang, EShSpec spec)
: TCompiler(lang, spec) {
TranslatorGLSL::TranslatorGLSL(ShShaderType type, ShShaderSpec spec)
: TCompiler(type, spec) {
}
void TranslatorGLSL::translate(TIntermNode* root) {
......
......@@ -11,7 +11,7 @@
class TranslatorGLSL : public TCompiler {
public:
TranslatorGLSL(EShLanguage lang, EShSpec spec);
TranslatorGLSL(ShShaderType type, ShShaderSpec spec);
protected:
virtual void translate(TIntermNode* root);
......
......@@ -8,8 +8,8 @@
#include "compiler/OutputHLSL.h"
TranslatorHLSL::TranslatorHLSL(EShLanguage lang, EShSpec spec)
: TCompiler(lang, spec)
TranslatorHLSL::TranslatorHLSL(ShShaderType type, ShShaderSpec spec)
: TCompiler(type, spec)
{
}
......
......@@ -11,7 +11,7 @@
class TranslatorHLSL : public TCompiler {
public:
TranslatorHLSL(EShLanguage lang, EShSpec spec);
TranslatorHLSL(ShShaderType type, ShShaderSpec spec);
protected:
virtual void translate(TIntermNode* root);
......
......@@ -14,7 +14,7 @@ static TString arrayBrackets(int index)
}
// Returns the data type for an attribute or uniform.
static EShDataType getVariableDataType(const TType& type)
static ShDataType getVariableDataType(const TType& type)
{
switch (type.getBasicType()) {
case EbtFloat:
......
......@@ -11,7 +11,7 @@
// It is currently being used to store info about active attribs and uniforms.
struct TVariableInfo {
TPersistString name;
EShDataType type;
ShDataType type;
int size;
};
typedef std::vector<TVariableInfo> TVariableInfoList;
......
......@@ -40,48 +40,26 @@ compiler/tools. Remove it when we can exclusively use the newer version.
#define YY_DECL int yylex(YYSTYPE* pyylval, void* parseContextLocal)
extern void yyerror(const char*);
#define FRAG_VERT_ONLY(S, L) { \
if (parseContext->language != EShLangFragment && \
parseContext->language != EShLangVertex) { \
parseContext->error(L, " supported in vertex/fragment shaders only ", S, "", ""); \
parseContext->recover(); \
} \
#define FRAG_VERT_ONLY(S, L) { \
if (parseContext->shaderType != SH_FRAGMENT_SHADER && \
parseContext->shaderType != SH_VERTEX_SHADER) { \
parseContext->error(L, " supported in vertex/fragment shaders only ", S, "", ""); \
parseContext->recover(); \
} \
}
#define VERTEX_ONLY(S, L) { \
if (parseContext->language != EShLangVertex) { \
parseContext->error(L, " supported in vertex shaders only ", S, "", ""); \
parseContext->recover(); \
} \
#define VERTEX_ONLY(S, L) { \
if (parseContext->shaderType != SH_VERTEX_SHADER) { \
parseContext->error(L, " supported in vertex shaders only ", S, "", ""); \
parseContext->recover(); \
} \
}
#define FRAG_ONLY(S, L) { \
if (parseContext->language != EShLangFragment) { \
parseContext->error(L, " supported in fragment shaders only ", S, "", ""); \
parseContext->recover(); \
} \
}
#define PACK_ONLY(S, L) { \
if (parseContext->language != EShLangPack) { \
parseContext->error(L, " supported in pack shaders only ", S, "", ""); \
parseContext->recover(); \
} \
}
#define UNPACK_ONLY(S, L) { \
if (parseContext->language != EShLangUnpack) { \
parseContext->error(L, " supported in unpack shaders only ", S, "", ""); \
parseContext->recover(); \
} \
}
#define PACK_UNPACK_ONLY(S, L) { \
if (parseContext->language != EShLangUnpack && \
parseContext->language != EShLangPack) { \
parseContext->error(L, " supported in pack/unpack shaders only ", S, "", ""); \
parseContext->recover(); \
} \
#define FRAG_ONLY(S, L) { \
if (parseContext->shaderType != SH_FRAGMENT_SHADER) { \
parseContext->error(L, " supported in fragment shaders only ", S, "", ""); \
parseContext->recover(); \
} \
}
%}
%union {
......@@ -1498,7 +1476,7 @@ type_qualifier
| VARYING {
if (parseContext->globalErrorCheck($1.line, parseContext->symbolTable.atGlobalLevel(), "varying"))
parseContext->recover();
if (parseContext->language == EShLangVertex)
if (parseContext->shaderType == SH_VERTEX_SHADER)
$$.setBasic(EbtVoid, EvqVaryingOut, $1.line);
else
$$.setBasic(EbtVoid, EvqVaryingIn, $1.line);
......@@ -1506,7 +1484,7 @@ type_qualifier
| INVARIANT VARYING {
if (parseContext->globalErrorCheck($1.line, parseContext->symbolTable.atGlobalLevel(), "invariant varying"))
parseContext->recover();
if (parseContext->language == EShLangVertex)
if (parseContext->shaderType == SH_VERTEX_SHADER)
$$.setBasic(EbtVoid, EvqInvariantVaryingOut, $1.line);
else
$$.setBasic(EbtVoid, EvqInvariantVaryingIn, $1.line);
......
......@@ -34,8 +34,8 @@ Shader::Shader(ResourceManager *manager, GLuint handle) : mHandle(handle), mReso
if (result)
{
TBuiltInResource resources;
ShInitBuiltInResource(&resources);
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
resources.MaxVertexAttribs = MAX_VERTEX_ATTRIBS;
resources.MaxVertexUniformVectors = MAX_VERTEX_UNIFORM_VECTORS;
resources.MaxVaryingVectors = MAX_VARYING_VECTORS;
......@@ -46,8 +46,8 @@ Shader::Shader(ResourceManager *manager, GLuint handle) : mHandle(handle), mReso
resources.MaxDrawBuffers = MAX_DRAW_BUFFERS;
resources.OES_standard_derivatives = 1;
mFragmentCompiler = ShConstructCompiler(EShLangFragment, EShSpecGLES2, &resources);
mVertexCompiler = ShConstructCompiler(EShLangVertex, EShSpecGLES2, &resources);
mFragmentCompiler = ShConstructCompiler(SH_FRAGMENT_SHADER, SH_GLES2_SPEC, &resources);
mVertexCompiler = ShConstructCompiler(SH_VERTEX_SHADER, SH_GLES2_SPEC, &resources);
}
}
......@@ -281,7 +281,7 @@ void Shader::compileToHLSL(void *compiler)
delete[] mInfoLog;
mInfoLog = NULL;
int result = ShCompile(compiler, &mSource, 1, EShOptObjectCode);
int result = ShCompile(compiler, &mSource, 1, SH_OBJECT_CODE);
if (result)
{
......
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