Commit 77891c0a by Shao Committed by Commit Bot

Fix wrong assignment of maxUniformVectors in GLSL compiler

This patch intends to fix a bug in ANGLE GLSL compiler. In TCompiler::Init(resources), we should initialize maxUniformVectors by resource.maxComputeUniformComponents / 4 when we attempt to initialize a compiler for compute shader instead of resource.maxFragmentUniformVectors. BUG=angleproject:2083 Change-Id: I4901f71ef5ac4f5770e2d5f8ee21786fcf19fbca Reviewed-on: https://chromium-review.googlesource.com/545190 Commit-Queue: Jiawei Shao <jiawei.shao@intel.com> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 690057da
...@@ -135,6 +135,23 @@ size_t GetGlobalMaxTokenSize(ShShaderSpec spec) ...@@ -135,6 +135,23 @@ size_t GetGlobalMaxTokenSize(ShShaderSpec spec)
} }
} }
int GetMaxUniformVectorsForShaderType(GLenum shaderType, const ShBuiltInResources &resources)
{
switch (shaderType)
{
case GL_VERTEX_SHADER:
return resources.MaxVertexUniformVectors;
case GL_FRAGMENT_SHADER:
return resources.MaxFragmentUniformVectors;
case GL_COMPUTE_SHADER:
// TODO (jiawei.shao@intel.com): check if we need finer-grained component counting
return resources.MaxComputeUniformComponents / 4;
default:
UNIMPLEMENTED();
return -1;
}
}
namespace namespace
{ {
...@@ -242,9 +259,10 @@ bool TCompiler::shouldRunLoopAndIndexingValidation(ShCompileOptions compileOptio ...@@ -242,9 +259,10 @@ bool TCompiler::shouldRunLoopAndIndexingValidation(ShCompileOptions compileOptio
bool TCompiler::Init(const ShBuiltInResources &resources) bool TCompiler::Init(const ShBuiltInResources &resources)
{ {
shaderVersion = 100; shaderVersion = 100;
maxUniformVectors = (shaderType == GL_VERTEX_SHADER) ? resources.MaxVertexUniformVectors
: resources.MaxFragmentUniformVectors; maxUniformVectors = GetMaxUniformVectorsForShaderType(shaderType, resources);
maxExpressionComplexity = resources.MaxExpressionComplexity; maxExpressionComplexity = resources.MaxExpressionComplexity;
maxCallStackDepth = resources.MaxCallStackDepth; maxCallStackDepth = resources.MaxCallStackDepth;
maxFunctionParameters = resources.MaxFunctionParameters; maxFunctionParameters = resources.MaxFunctionParameters;
......
...@@ -62,11 +62,37 @@ class ComputeShaderValidationTest : public ShaderCompileTreeTest ...@@ -62,11 +62,37 @@ class ComputeShaderValidationTest : public ShaderCompileTreeTest
public: public:
ComputeShaderValidationTest() {} ComputeShaderValidationTest() {}
private: protected:
::GLenum getShaderType() const override { return GL_COMPUTE_SHADER; } ::GLenum getShaderType() const override { return GL_COMPUTE_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; } ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
}; };
class ComputeShaderEnforcePackingValidationTest : public ComputeShaderValidationTest
{
public:
ComputeShaderEnforcePackingValidationTest() {}
protected:
void initResources(ShBuiltInResources *resources) override
{
resources->MaxComputeUniformComponents = kMaxComputeUniformComponents;
// We need both MaxFragmentUniformVectors and MaxFragmentUniformVectors smaller than
// MaxComputeUniformComponents / 4.
resources->MaxVertexUniformVectors = 16;
resources->MaxFragmentUniformVectors = 16;
}
void SetUp() override
{
mExtraCompileOptions |= (SH_VARIABLES | SH_ENFORCE_PACKING_RESTRICTIONS);
ShaderCompileTreeTest::SetUp();
}
// It is unnecessary to use a very large MaxComputeUniformComponents in this test.
static constexpr GLint kMaxComputeUniformComponents = 128;
};
// This is a test for a bug that used to exist in ANGLE: // This is a test for a bug that used to exist in ANGLE:
// Calling a function with all parameters missing should not succeed. // Calling a function with all parameters missing should not succeed.
TEST_F(FragmentShaderValidationTest, FunctionParameterMismatch) TEST_F(FragmentShaderValidationTest, FunctionParameterMismatch)
...@@ -3879,3 +3905,34 @@ TEST_F(FragmentShaderValidationTest, StructAsBoolConstructorArgument) ...@@ -3879,3 +3905,34 @@ TEST_F(FragmentShaderValidationTest, StructAsBoolConstructorArgument)
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog; FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
} }
} }
// Test that a compute shader can be compiled with MAX_COMPUTE_UNIFORM_COMPONENTS uniform
// components.
TEST_F(ComputeShaderEnforcePackingValidationTest, MaxComputeUniformComponents)
{
GLint uniformVectorCount = kMaxComputeUniformComponents / 4;
std::ostringstream ostream;
ostream << "#version 310 es\n"
"layout(local_size_x = 1) in;\n";
for (GLint i = 0; i < uniformVectorCount; ++i)
{
ostream << "uniform vec4 u_value" << i << ";\n";
}
ostream << "void main()\n"
"{\n";
for (GLint i = 0; i < uniformVectorCount; ++i)
{
ostream << " vec4 v" << i << " = u_value" << i << ";\n";
}
ostream << "}\n";
if (!compile(ostream.str()))
{
FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
}
}
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