Commit fc75e217 by Zhenyao Mo

Add an option in ANGLE shader translator to initialize gl_Position to vec4(0.0, 0.0, 0.0, 1.0).

This is to work around driver bugs where shader compile or program link would fail incorrectly if gl_Position is not set in vertex shader. At the moment at least Linux NVIDIA driver has this bug. ANGLEBUG=472 R=alokp@chromium.org, kbr@chromium.org Review URL: https://codereview.appspot.com/13509043
parent 8cdc21c2
...@@ -183,6 +183,12 @@ typedef enum { ...@@ -183,6 +183,12 @@ typedef enum {
// This flag limits the depth of the call stack. // This flag limits the depth of the call stack.
SH_LIMIT_CALL_STACK_DEPTH = 0x4000, SH_LIMIT_CALL_STACK_DEPTH = 0x4000,
// This flag initializes gl_Position to vec4(0.0, 0.0, 0.0, 1.0) at
// the beginning of the vertex shader, and has no effect in the
// fragment shader. It is intended as a workaround for drivers which
// incorrectly fail to link programs if gl_Position is not written.
SH_INIT_GL_POSITION = 0x8000,
} ShCompileOptions; } ShCompileOptions;
// Defines alternate strategies for implementing array index clamping. // Defines alternate strategies for implementing array index clamping.
......
...@@ -93,6 +93,8 @@ ...@@ -93,6 +93,8 @@
'compiler/InitializeDll.cpp', 'compiler/InitializeDll.cpp',
'compiler/InitializeDll.h', 'compiler/InitializeDll.h',
'compiler/InitializeGlobals.h', 'compiler/InitializeGlobals.h',
'compiler/InitializeGLPosition.cpp',
'compiler/InitializeGLPosition.h',
'compiler/InitializeParseContext.cpp', 'compiler/InitializeParseContext.cpp',
'compiler/InitializeParseContext.h', 'compiler/InitializeParseContext.h',
'compiler/Intermediate.cpp', 'compiler/Intermediate.cpp',
......
#define MAJOR_VERSION 1 #define MAJOR_VERSION 1
#define MINOR_VERSION 2 #define MINOR_VERSION 2
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 2443 #define BUILD_REVISION 2444
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "compiler/DetectCallDepth.h" #include "compiler/DetectCallDepth.h"
#include "compiler/ForLoopUnroll.h" #include "compiler/ForLoopUnroll.h"
#include "compiler/Initialize.h" #include "compiler/Initialize.h"
#include "compiler/InitializeGLPosition.h"
#include "compiler/InitializeParseContext.h" #include "compiler/InitializeParseContext.h"
#include "compiler/MapLongVariableNames.h" #include "compiler/MapLongVariableNames.h"
#include "compiler/ParseHelper.h" #include "compiler/ParseHelper.h"
...@@ -188,6 +189,11 @@ bool TCompiler::compile(const char* const shaderStrings[], ...@@ -188,6 +189,11 @@ bool TCompiler::compile(const char* const shaderStrings[],
if (success && (compileOptions & SH_MAP_LONG_VARIABLE_NAMES) && hashFunction == NULL) if (success && (compileOptions & SH_MAP_LONG_VARIABLE_NAMES) && hashFunction == NULL)
mapLongVariableNames(root); mapLongVariableNames(root);
if (success && shaderType == SH_VERTEX_SHADER && (compileOptions & SH_INIT_GL_POSITION)) {
InitializeGLPosition initGLPosition;
root->traverse(&initGLPosition);
}
if (success && (compileOptions & SH_VARIABLES)) { if (success && (compileOptions & SH_VARIABLES)) {
collectVariables(root); collectVariables(root);
if (compileOptions & SH_ENFORCE_PACKING_RESTRICTIONS) { if (compileOptions & SH_ENFORCE_PACKING_RESTRICTIONS) {
......
//
// 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.
//
#include "compiler/InitializeGLPosition.h"
#include "compiler/debug.h"
bool InitializeGLPosition::visitAggregate(Visit visit, TIntermAggregate* node)
{
bool visitChildren = !mCodeInserted;
switch (node->getOp())
{
case EOpSequence: break;
case EOpFunction:
{
// Function definition.
ASSERT(visit == PreVisit);
if (node->getName() == "main(")
{
TIntermSequence &sequence = node->getSequence();
ASSERT((sequence.size() == 1) || (sequence.size() == 2));
TIntermAggregate *body = NULL;
if (sequence.size() == 1)
{
body = new TIntermAggregate(EOpSequence);
sequence.push_back(body);
}
else
{
body = sequence[1]->getAsAggregate();
}
ASSERT(body);
insertCode(body->getSequence());
mCodeInserted = true;
}
break;
}
default: visitChildren = false; break;
}
return visitChildren;
}
void InitializeGLPosition::insertCode(TIntermSequence& sequence)
{
TIntermBinary *binary = new TIntermBinary(EOpAssign);
sequence.insert(sequence.begin(), binary);
TIntermSymbol *left = new TIntermSymbol(
0, "gl_Position", TType(EbtFloat, EbpUndefined, EvqPosition, 4));
binary->setLeft(left);
ConstantUnion *u = new ConstantUnion[4];
for (int ii = 0; ii < 3; ++ii)
u[ii].setFConst(0.0f);
u[3].setFConst(1.0f);
TIntermConstantUnion *right = new TIntermConstantUnion(
u, TType(EbtFloat, EbpUndefined, EvqConst, 4));
binary->setRight(right);
}
//
// 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.
//
#ifndef COMPILER_INITIALIZE_GL_POSITION_H_
#define COMPILER_INITIALIZE_GL_POSITION_H_
#include "compiler/intermediate.h"
class InitializeGLPosition : public TIntermTraverser
{
public:
InitializeGLPosition() : mCodeInserted(false) { }
protected:
virtual bool visitBinary(Visit visit, TIntermBinary* node) { return false; }
virtual bool visitUnary(Visit visit, TIntermUnary* node) { return false; }
virtual bool visitSelection(Visit visit, TIntermSelection* node) { return false; }
virtual bool visitLoop(Visit visit, TIntermLoop* node) { return false; }
virtual bool visitBranch(Visit visit, TIntermBranch* node) { return false; }
virtual bool visitAggregate(Visit visit, TIntermAggregate* node);
private:
// Insert AST node in the beginning of main() for "gl_Position = vec4(0.0, 0.0, 0.0, 1.0);".
void insertCode(TIntermSequence& sequence);
bool mCodeInserted;
};
#endif // COMPILER_INITIALIZE_GL_POSITION_H_
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