Commit 26e1a466 by Jamie Madill

Revert "translator: Fix variable collection for gl_DepthRange."

Build errors on Linux: error: comparison of integers of different signs: 'const int' and 'const unsigned int' BUG=angleproject:991 BUG=478570 This reverts commit f1ae954b. Change-Id: I217aba1b32dc0e70d6153337a1f0ccef0483a0e1 Reviewed-on: https://chromium-review.googlesource.com/268792Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent f1ae954b
......@@ -70,8 +70,6 @@ struct COMPILER_EXPORT ShaderVariable
const ShaderVariable **leafVar,
std::string* originalFullName) const;
bool isBuiltIn() const { return name.compare(0, 3, "gl_") == 0; }
GLenum type;
GLenum precision;
std::string name;
......
......@@ -139,7 +139,6 @@ CollectVariables::CollectVariables(std::vector<sh::Attribute> *attribs,
mUniforms(uniforms),
mVaryings(varyings),
mInterfaceBlocks(interfaceBlocks),
mDepthRangeAdded(false),
mPointCoordAdded(false),
mFrontFacingAdded(false),
mFragCoordAdded(false),
......@@ -171,56 +170,6 @@ void CollectVariables::visitSymbol(TIntermSymbol *symbol)
{
UNREACHABLE();
}
else if (symbolName == "gl_DepthRange")
{
ASSERT(symbol->getQualifier() == EvqUniform);
if (!mDepthRangeAdded)
{
Uniform info;
const char kName[] = "gl_DepthRange";
info.name = kName;
info.mappedName = kName;
info.type = GL_STRUCT_ANGLEX;
info.arraySize = 0;
info.precision = GL_NONE;
info.staticUse = true;
ShaderVariable nearInfo;
const char kNearName[] = "near";
nearInfo.name = kNearName;
nearInfo.mappedName = kNearName;
nearInfo.type = GL_FLOAT;
nearInfo.arraySize = 0;
nearInfo.precision = GL_HIGH_FLOAT;
nearInfo.staticUse = true;
ShaderVariable farInfo;
const char kFarName[] = "far";
farInfo.name = kFarName;
farInfo.mappedName = kFarName;
farInfo.type = GL_FLOAT;
farInfo.arraySize = 0;
farInfo.precision = GL_HIGH_FLOAT;
farInfo.staticUse = true;
ShaderVariable diffInfo;
const char kDiffName[] = "diff";
diffInfo.name = kDiffName;
diffInfo.mappedName = kDiffName;
diffInfo.type = GL_FLOAT;
diffInfo.arraySize = 0;
diffInfo.precision = GL_HIGH_FLOAT;
diffInfo.staticUse = true;
info.fields.push_back(nearInfo);
info.fields.push_back(farInfo);
info.fields.push_back(diffInfo);
mUniforms->push_back(info);
mDepthRangeAdded = true;
}
}
else
{
switch (symbol->getQualifier())
......@@ -243,6 +192,7 @@ void CollectVariables::visitSymbol(TIntermSymbol *symbol)
// Set static use on the parent interface block here
namedBlock->staticUse = true;
}
else
{
......@@ -250,7 +200,7 @@ void CollectVariables::visitSymbol(TIntermSymbol *symbol)
}
// It's an internal error to reference an undefined user uniform
ASSERT(symbolName.compare(0, 3, "gl_") != 0 || var);
ASSERT(symbolName.compare(0, 3, "gl_") == 0 || var);
}
break;
case EvqFragCoord:
......
......@@ -47,7 +47,6 @@ class CollectVariables : public TIntermTraverser
std::map<std::string, InterfaceBlockField *> mInterfaceBlockFields;
bool mDepthRangeAdded;
bool mPointCoordAdded;
bool mFrontFacingAdded;
bool mFragCoordAdded;
......
......@@ -45,6 +45,7 @@ struct PackedVarying : public sh::Varying
{}
bool registerAssigned() const { return registerIndex != GL_INVALID_INDEX; }
bool isBuiltIn() const { return name.compare(0, 3, "gl_") == 0; }
void resetRegisterAssignment()
{
......
......@@ -1375,9 +1375,7 @@ bool ProgramD3D::linkUniforms(gl::InfoLog &infoLog, const gl::Shader &vertexShad
if (uniform.staticUse)
{
unsigned int registerBase = uniform.isBuiltIn() ? GL_INVALID_INDEX :
vertexShaderD3D->getUniformRegister(uniform.name);
defineUniformBase(vertexShaderD3D, uniform, registerBase);
defineUniformBase(vertexShaderD3D, uniform, vertexShaderD3D->getUniformRegister(uniform.name));
}
}
......@@ -1387,9 +1385,7 @@ bool ProgramD3D::linkUniforms(gl::InfoLog &infoLog, const gl::Shader &vertexShad
if (uniform.staticUse)
{
unsigned int registerBase = uniform.isBuiltIn() ? GL_INVALID_INDEX :
fragmentShaderD3D->getUniformRegister(uniform.name);
defineUniformBase(fragmentShaderD3D, uniform, registerBase);
defineUniformBase(fragmentShaderD3D, uniform, fragmentShaderD3D->getUniformRegister(uniform.name));
}
}
......@@ -1400,16 +1396,21 @@ bool ProgramD3D::linkUniforms(gl::InfoLog &infoLog, const gl::Shader &vertexShad
initializeUniformStorage();
// special case for gl_DepthRange, the only built-in uniform (also a struct)
if (vertexShaderD3D->usesDepthRange() || fragmentShaderD3D->usesDepthRange())
{
const sh::BlockMemberInfo &defaultInfo = sh::BlockMemberInfo::getDefaultBlockInfo();
mUniforms.push_back(new gl::LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.near", 0, -1, defaultInfo));
mUniforms.push_back(new gl::LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.far", 0, -1, defaultInfo));
mUniforms.push_back(new gl::LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.diff", 0, -1, defaultInfo));
}
return true;
}
void ProgramD3D::defineUniformBase(const ShaderD3D *shader, const sh::Uniform &uniform, unsigned int uniformRegister)
{
if (uniformRegister == GL_INVALID_INDEX)
{
defineUniform(shader, uniform, uniform.name, nullptr);
}
ShShaderOutput outputType = shader->getCompilerOutputType();
sh::HLSLBlockEncoder encoder(sh::HLSLBlockEncoder::GetStrategyFor(outputType));
encoder.skipRegisters(uniformRegister);
......@@ -1426,8 +1427,7 @@ void ProgramD3D::defineUniform(const ShaderD3D *shader, const sh::ShaderVariable
{
const std::string &elementString = (uniform.isArray() ? ArrayString(elementIndex) : "");
if (encoder)
encoder->enterAggregateType();
encoder->enterAggregateType();
for (size_t fieldIndex = 0; fieldIndex < uniform.fields.size(); fieldIndex++)
{
......@@ -1437,14 +1437,13 @@ void ProgramD3D::defineUniform(const ShaderD3D *shader, const sh::ShaderVariable
defineUniform(shader, field, fieldFullName, encoder);
}
if (encoder)
encoder->exitAggregateType();
encoder->exitAggregateType();
}
}
else // Not a struct
{
// Arrays are treated as aggregate types
if (uniform.isArray() && encoder)
if (uniform.isArray())
{
encoder->enterAggregateType();
}
......@@ -1452,36 +1451,29 @@ void ProgramD3D::defineUniform(const ShaderD3D *shader, const sh::ShaderVariable
gl::LinkedUniform *linkedUniform = getUniformByName(fullName);
// Advance the uniform offset, to track registers allocation for structs
sh::BlockMemberInfo blockInfo = encoder ?
encoder->encodeType(uniform.type, uniform.arraySize, false) :
sh::BlockMemberInfo::getDefaultBlockInfo();
sh::BlockMemberInfo blockInfo = encoder->encodeType(uniform.type, uniform.arraySize, false);
if (!linkedUniform)
{
linkedUniform = new gl::LinkedUniform(uniform.type, uniform.precision, fullName, uniform.arraySize,
-1, sh::BlockMemberInfo::getDefaultBlockInfo());
ASSERT(linkedUniform);
if (encoder)
linkedUniform->registerElement = sh::HLSLBlockEncoder::getBlockRegisterElement(blockInfo);
linkedUniform->registerElement = sh::HLSLBlockEncoder::getBlockRegisterElement(blockInfo);
mUniforms.push_back(linkedUniform);
}
if (encoder)
if (shader->getShaderType() == GL_FRAGMENT_SHADER)
{
if (shader->getShaderType() == GL_FRAGMENT_SHADER)
{
linkedUniform->psRegisterIndex = sh::HLSLBlockEncoder::getBlockRegister(blockInfo);
}
else if (shader->getShaderType() == GL_VERTEX_SHADER)
{
linkedUniform->vsRegisterIndex = sh::HLSLBlockEncoder::getBlockRegister(blockInfo);
}
else UNREACHABLE();
linkedUniform->psRegisterIndex = sh::HLSLBlockEncoder::getBlockRegister(blockInfo);
}
else if (shader->getShaderType() == GL_VERTEX_SHADER)
{
linkedUniform->vsRegisterIndex = sh::HLSLBlockEncoder::getBlockRegister(blockInfo);
}
else UNREACHABLE();
// Arrays are treated as aggregate types
if (uniform.isArray() && encoder)
if (uniform.isArray())
{
encoder->exitAggregateType();
}
......
......@@ -218,7 +218,7 @@ void ShaderD3D::compileToHLSL(ShHandle compiler, const std::string &source)
{
const sh::Uniform &uniform = mUniforms[uniformIndex];
if (uniform.staticUse && !uniform.isBuiltIn())
if (uniform.staticUse)
{
unsigned int index = static_cast<unsigned int>(-1);
bool getUniformRegisterResult = ShGetUniformRegister(compiler, uniform.name, &index);
......
......@@ -19,10 +19,8 @@ class CollectVariablesTest : public testing::Test
{
public:
CollectVariablesTest(GLenum shaderType)
: mShaderType(shaderType),
mTranslator(nullptr)
{
}
: mShaderType(shaderType)
{}
protected:
virtual void SetUp()
......@@ -31,67 +29,14 @@ class CollectVariablesTest : public testing::Test
ShInitBuiltInResources(&resources);
resources.MaxDrawBuffers = 8;
initTranslator(resources);
}
virtual void TearDown()
{
SafeDelete(mTranslator);
}
void initTranslator(const ShBuiltInResources &resources)
{
SafeDelete(mTranslator);
mTranslator = new TranslatorGLSL(
mShaderType, SH_GLES3_SPEC, SH_GLSL_COMPATIBILITY_OUTPUT);
ASSERT_TRUE(mTranslator->Init(resources));
}
// For use in the gl_DepthRange tests.
void validateDepthRangeShader(const std::string &shaderString)
virtual void TearDown()
{
const char *shaderStrings[] = { shaderString.c_str() };
ASSERT_TRUE(mTranslator->compile(shaderStrings, 1, SH_VARIABLES));
const std::vector<sh::Uniform> &uniforms = mTranslator->getUniforms();
ASSERT_EQ(1u, uniforms.size());
const sh::Uniform &uniform = uniforms[0];
EXPECT_EQ("gl_DepthRange", uniform.name);
ASSERT_TRUE(uniform.isStruct());
ASSERT_EQ(3u, uniform.fields.size());
bool foundNear = false;
bool foundFar = false;
bool foundDiff = false;
for (const auto &field : uniform.fields)
{
if (field.name == "near")
{
EXPECT_FALSE(foundNear);
foundNear = true;
}
else if (field.name == "far")
{
EXPECT_FALSE(foundFar);
foundFar = true;
}
else
{
ASSERT_EQ("diff", field.name);
EXPECT_FALSE(foundDiff);
foundDiff = true;
}
EXPECT_EQ(0u, field.arraySize);
EXPECT_FALSE(field.isStruct());
EXPECT_EQ(GL_HIGH_FLOAT, field.precision);
EXPECT_TRUE(field.staticUse);
EXPECT_EQ(GL_FLOAT, field.type);
}
EXPECT_TRUE(foundNear && foundFar && foundDiff);
delete mTranslator;
}
GLenum mShaderType;
......@@ -424,27 +369,3 @@ TEST_F(CollectVertexVariablesTest, VaryingInterpolation)
EXPECT_EQ("vary", varying->name);
EXPECT_EQ(sh::INTERPOLATION_CENTROID, varying->interpolation);
}
// Test for builtin uniform "gl_DepthRange" (Vertex shader)
TEST_F(CollectVertexVariablesTest, DepthRange)
{
const std::string &shaderString =
"attribute vec4 position;\n"
"void main() {\n"
" gl_Position = position + vec4(gl_DepthRange.near, gl_DepthRange.far, gl_DepthRange.diff, 1.0);\n"
"}\n";
validateDepthRangeShader(shaderString);
}
// Test for builtin uniform "gl_DepthRange" (Fragment shader)
TEST_F(CollectFragmentVariablesTest, DepthRange)
{
const std::string &shaderString =
"precision mediump float;\n"
"void main() {\n"
" gl_FragColor = vec4(gl_DepthRange.near, gl_DepthRange.far, gl_DepthRange.diff, 1.0);\n"
"}\n";
validateDepthRangeShader(shaderString);
}
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