Commit dc4b4f85 by zmo@google.com

Always emit precision in shader variable declarations.

After the shader compile (and before code output), the precision scopes are already lost. In order to correctly output precisions, we need to emit precision in each variable declaration, therefore, each variable should have its precision set. This CL fixes the bugs that the precisions are lost for variables using default precsions and struct fields. Also, this CL fixes a bug in the grammar: constructors are not type_specifier and they shouldn't have precisions. BUG=168 TEST=webgl conformance tests, gles2 conformance tests. Review URL: http://codereview.appspot.com/4617041 git-svn-id: https://angleproject.googlecode.com/svn/trunk@695 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 189be2f1
#define MAJOR_VERSION 0 #define MAJOR_VERSION 0
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 694 #define BUILD_REVISION 695
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -18,7 +18,9 @@ bool InitializeSymbolTable( ...@@ -18,7 +18,9 @@ bool InitializeSymbolTable(
{ {
TIntermediate intermediate(infoSink); TIntermediate intermediate(infoSink);
TExtensionBehavior extBehavior; TExtensionBehavior extBehavior;
TParseContext parseContext(symbolTable, extBehavior, intermediate, type, spec, 0, NULL, infoSink); // 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);
GlobalParseContext = &parseContext; GlobalParseContext = &parseContext;
...@@ -127,7 +129,7 @@ bool TCompiler::compile(const char* const shaderStrings[], ...@@ -127,7 +129,7 @@ bool TCompiler::compile(const char* const shaderStrings[],
TIntermediate intermediate(infoSink); TIntermediate intermediate(infoSink);
TParseContext parseContext(symbolTable, extensionBehavior, intermediate, TParseContext parseContext(symbolTable, extensionBehavior, intermediate,
shaderType, shaderSpec, compileOptions, shaderType, shaderSpec, compileOptions, true,
sourcePath, infoSink); sourcePath, infoSink);
GlobalParseContext = &parseContext; GlobalParseContext = &parseContext;
......
...@@ -261,6 +261,8 @@ void TParseContext::binaryOpError(int line, const char* op, TString left, TStrin ...@@ -261,6 +261,8 @@ void TParseContext::binaryOpError(int line, const char* op, TString left, TStrin
} }
bool TParseContext::precisionErrorCheck(int line, TPrecision precision, TBasicType type){ bool TParseContext::precisionErrorCheck(int line, TPrecision precision, TBasicType type){
if (!checksPrecisionErrors)
return false;
switch( type ){ switch( type ){
case EbtFloat: case EbtFloat:
if( precision == EbpUndefined ){ if( precision == EbpUndefined ){
......
...@@ -30,8 +30,8 @@ struct TPragma { ...@@ -30,8 +30,8 @@ struct TPragma {
// they can be passed to the parser without needing a global. // they can be passed to the parser without needing a global.
// //
struct TParseContext { struct TParseContext {
TParseContext(TSymbolTable& symt, TExtensionBehavior& ext, TIntermediate& interm, ShShaderType type, ShShaderSpec spec, int options, const char* sourcePath, TInfoSink& is) : TParseContext(TSymbolTable& symt, TExtensionBehavior& ext, TIntermediate& interm, ShShaderType type, ShShaderSpec spec, int options, bool checksPrecErrors, const char* sourcePath, TInfoSink& is) :
intermediate(interm), symbolTable(symt), extensionBehavior(ext), infoSink(is), shaderType(type), shaderSpec(spec), compileOptions(options), sourcePath(sourcePath), treeRoot(0), intermediate(interm), symbolTable(symt), extensionBehavior(ext), infoSink(is), shaderType(type), shaderSpec(spec), compileOptions(options), checksPrecisionErrors(checksPrecErrors), sourcePath(sourcePath), treeRoot(0),
recoveredFromError(false), numErrors(0), lexAfterType(false), loopNestingLevel(0), recoveredFromError(false), numErrors(0), lexAfterType(false), loopNestingLevel(0),
inTypeParen(false), scanner(NULL), contextPragma(true, false) { } inTypeParen(false), scanner(NULL), contextPragma(true, false) { }
TIntermediate& intermediate; // to hold and build a parse tree TIntermediate& intermediate; // to hold and build a parse tree
...@@ -50,6 +50,7 @@ struct TParseContext { ...@@ -50,6 +50,7 @@ struct TParseContext {
bool inTypeParen; // true if in parentheses, looking only for an identifier bool inTypeParen; // true if in parentheses, looking only for an identifier
const TType* currentFunctionType; // the return type of the function that's currently being parsed const TType* currentFunctionType; // the return type of the function that's currently being parsed
bool functionReturnsValue; // true if a non-void function has a return bool functionReturnsValue; // true if a non-void function has a return
bool checksPrecisionErrors; // true if an error will be generated when a variable is declared without precision, explicit or implicit.
void error(TSourceLoc loc, const char *reason, const char* token, void error(TSourceLoc loc, const char *reason, const char* token,
const char* extraInfoFormat, ...); const char* extraInfoFormat, ...);
......
...@@ -18,18 +18,6 @@ void TranslatorESSL::translate(TIntermNode* root) { ...@@ -18,18 +18,6 @@ void TranslatorESSL::translate(TIntermNode* root) {
// Write built-in extension behaviors. // Write built-in extension behaviors.
writeExtensionBehavior(); writeExtensionBehavior();
// FIXME(zmo): no need to emit default precision if all variables emit
// their own precision.
// http://code.google.com/p/angleproject/issues/detail?id=168
if (this->getShaderType() == SH_FRAGMENT_SHADER) {
// Write default float precision.
sink << "#if defined(GL_FRAGMENT_PRECISION_HIGH)\n"
<< "precision highp float;\n"
<< "#else\n"
<< "precision mediump float;\n"
<< "#endif\n";
}
// Write translated shader. // Write translated shader.
TOutputESSL outputESSL(sink); TOutputESSL outputESSL(sink);
root->traverse(&outputESSL); root->traverse(&outputESSL);
......
...@@ -591,17 +591,10 @@ function_call_header ...@@ -591,17 +591,10 @@ function_call_header
// Grammar Note: Constructors look like functions, but are recognized as types. // Grammar Note: Constructors look like functions, but are recognized as types.
function_identifier function_identifier
: type_specifier { : type_specifier_nonarray {
// //
// Constructor // Constructor
// //
if ($1.array) {
// Constructors for arrays are not allowed.
context->error($1.line, "cannot construct this type", "array", "");
context->recover();
$1.setArray(false);
}
TOperator op = EOpNull; TOperator op = EOpNull;
if ($1.userDef) { if ($1.userDef) {
op = EOpConstructStruct; op = EOpConstructStruct;
...@@ -1176,13 +1169,6 @@ parameter_type_specifier ...@@ -1176,13 +1169,6 @@ parameter_type_specifier
init_declarator_list init_declarator_list
: single_declaration { : single_declaration {
$$ = $1; $$ = $1;
if ($$.type.precision == EbpUndefined) {
$$.type.precision = context->symbolTable.getDefaultPrecision($1.type.type);
if (context->precisionErrorCheck($1.line, $$.type.precision, $1.type.type)) {
context->recover();
}
}
} }
| init_declarator_list COMMA IDENTIFIER { | init_declarator_list COMMA IDENTIFIER {
TIntermSymbol* symbol = context->intermediate.addSymbol(0, *$3.string, TType($1.type), $3.line); TIntermSymbol* symbol = context->intermediate.addSymbol(0, *$3.string, TType($1.type), $3.line);
...@@ -1490,6 +1476,13 @@ type_qualifier ...@@ -1490,6 +1476,13 @@ type_qualifier
type_specifier type_specifier
: type_specifier_no_prec { : type_specifier_no_prec {
$$ = $1; $$ = $1;
if ($$.precision == EbpUndefined) {
$$.precision = context->symbolTable.getDefaultPrecision($1.type);
if (context->precisionErrorCheck($1.line, $$.precision, $1.type)) {
context->recover();
}
}
} }
| precision_qualifier type_specifier_no_prec { | precision_qualifier type_specifier_no_prec {
$$ = $2; $$ = $2;
...@@ -1693,6 +1686,7 @@ struct_declaration ...@@ -1693,6 +1686,7 @@ struct_declaration
type->setBasicType($1.type); type->setBasicType($1.type);
type->setNominalSize($1.size); type->setNominalSize($1.size);
type->setMatrix($1.matrix); type->setMatrix($1.matrix);
type->setPrecision($1.precision);
// don't allow arrays of arrays // don't allow arrays of arrays
if (type->isArray()) { if (type->isArray()) {
......
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