Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Unified Diff: gpu/command_buffer/service/program_manager_unittest.cc

Issue 23534007: Apply varying packing rule. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: final Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gpu/command_buffer/service/program_manager.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/service/program_manager_unittest.cc
diff --git a/gpu/command_buffer/service/program_manager_unittest.cc b/gpu/command_buffer/service/program_manager_unittest.cc
index c23845829b947c5c4a9d6145b208fe208525d4c9..1bf0a760e7007ea464d7cd85606780aca3fcd528 100644
--- a/gpu/command_buffer/service/program_manager_unittest.cc
+++ b/gpu/command_buffer/service/program_manager_unittest.cc
@@ -36,12 +36,14 @@ namespace gpu {
namespace gles2 {
namespace {
+const uint32 kMaxVaryingVectors = 8;
+
void ShaderCacheCb(const std::string& key, const std::string& shader) {}
-} // namespace
+} // namespace anonymous
class ProgramManagerTest : public testing::Test {
public:
- ProgramManagerTest() : manager_(NULL) { }
+ ProgramManagerTest() : manager_(NULL, kMaxVaryingVectors) { }
virtual ~ProgramManagerTest() {
manager_.Destroy(false);
}
@@ -139,7 +141,7 @@ TEST_F(ProgramManagerTest, Program) {
class ProgramManagerWithShaderTest : public testing::Test {
public:
ProgramManagerWithShaderTest()
- : manager_(NULL), program_(NULL) {
+ : manager_(NULL, kMaxVaryingVectors), program_(NULL) {
}
virtual ~ProgramManagerWithShaderTest() {
@@ -209,6 +211,13 @@ class ProgramManagerWithShaderTest : public testing::Test {
protected:
typedef TestHelper::AttribInfo AttribInfo;
typedef TestHelper::UniformInfo UniformInfo;
+ typedef struct {
+ int type;
+ int size;
+ int precision;
+ int static_use;
+ std::string name;
+ } VarInfo;
virtual void SetUp() {
gl_.reset(new StrictMock<gfx::MockGLInterface>());
@@ -272,16 +281,10 @@ class ProgramManagerWithShaderTest : public testing::Test {
return (static_cast<bool>(link_status) == expected_link_status);
}
- Program* SetupVaryingsMatchingTest(bool vertex_varying_declare,
- int vertex_varying_type,
- int vertex_varying_size,
- int vertex_varying_precision,
- int vertex_varying_static_use,
- bool frag_varying_declare,
- int frag_varying_type,
- int frag_varying_size,
- int frag_varying_precision,
- int frag_varying_static_use) {
+ Program* SetupVaryingsTest(const VarInfo* vertex_varyings,
+ size_t vertex_varying_size,
+ const VarInfo* fragment_varyings,
+ size_t fragment_varying_size) {
// Set up shader
const GLuint kVShaderClientId = 1;
const GLuint kVShaderServiceId = 11;
@@ -292,10 +295,13 @@ class ProgramManagerWithShaderTest : public testing::Test {
ShaderTranslator::VariableMap vertex_attrib_map;
ShaderTranslator::VariableMap vertex_uniform_map;
ShaderTranslator::VariableMap vertex_varying_map;
- if (vertex_varying_declare) {
- vertex_varying_map["a"] = ShaderTranslator::VariableInfo(
- vertex_varying_type, vertex_varying_size,
- vertex_varying_precision, vertex_varying_static_use, "a");
+ for (size_t ii = 0; ii < vertex_varying_size; ++ii) {
+ vertex_varying_map[vertex_varyings[ii].name] =
+ ShaderTranslator::VariableInfo(vertex_varyings[ii].type,
+ vertex_varyings[ii].size,
+ vertex_varyings[ii].precision,
+ vertex_varyings[ii].static_use,
+ vertex_varyings[ii].name);
}
ShaderTranslator::NameMap vertex_name_map;
EXPECT_CALL(vertex_shader_translator, attrib_map())
@@ -311,10 +317,13 @@ class ProgramManagerWithShaderTest : public testing::Test {
ShaderTranslator::VariableMap frag_attrib_map;
ShaderTranslator::VariableMap frag_uniform_map;
ShaderTranslator::VariableMap frag_varying_map;
- if (frag_varying_declare) {
- frag_varying_map["a"] = ShaderTranslator::VariableInfo(
- frag_varying_type, frag_varying_size,
- frag_varying_precision, frag_varying_static_use, "a");
+ for (size_t ii = 0; ii < fragment_varying_size; ++ii) {
+ frag_varying_map[fragment_varyings[ii].name] =
+ ShaderTranslator::VariableInfo(fragment_varyings[ii].type,
+ fragment_varyings[ii].size,
+ fragment_varyings[ii].precision,
+ fragment_varyings[ii].static_use,
+ fragment_varyings[ii].name);
}
ShaderTranslator::NameMap frag_name_map;
EXPECT_CALL(frag_shader_translator, attrib_map())
@@ -1167,9 +1176,12 @@ TEST_F(ProgramManagerWithShaderTest, UniformsPrecisionMismatch) {
// If a varying has different type in the vertex and fragment
// shader, linking should fail.
TEST_F(ProgramManagerWithShaderTest, VaryingTypeMismatch) {
- Program* program = SetupVaryingsMatchingTest(
- true, SH_FLOAT_VEC3, 1, SH_PRECISION_MEDIUMP, 1,
- true, SH_FLOAT_VEC4, 1, SH_PRECISION_MEDIUMP, 1);
+ const VarInfo kVertexVarying =
+ { SH_FLOAT_VEC3, 1, SH_PRECISION_MEDIUMP, 1, "a" };
+ const VarInfo kFragmentVarying =
+ { SH_FLOAT_VEC4, 1, SH_PRECISION_MEDIUMP, 1, "a" };
+ Program* program = SetupVaryingsTest(
+ &kVertexVarying, 1, &kFragmentVarying, 1);
EXPECT_TRUE(program->DetectVaryingsMismatch());
EXPECT_TRUE(LinkAsExpected(program, false));
@@ -1178,9 +1190,12 @@ TEST_F(ProgramManagerWithShaderTest, VaryingTypeMismatch) {
// If a varying has different array size in the vertex and fragment
// shader, linking should fail.
TEST_F(ProgramManagerWithShaderTest, VaryingArraySizeMismatch) {
- Program* program = SetupVaryingsMatchingTest(
- true, SH_FLOAT, 2, SH_PRECISION_MEDIUMP, 1,
- true, SH_FLOAT, 3, SH_PRECISION_MEDIUMP, 1);
+ const VarInfo kVertexVarying =
+ { SH_FLOAT, 2, SH_PRECISION_MEDIUMP, 1, "a" };
+ const VarInfo kFragmentVarying =
+ { SH_FLOAT, 3, SH_PRECISION_MEDIUMP, 1, "a" };
+ Program* program = SetupVaryingsTest(
+ &kVertexVarying, 1, &kFragmentVarying, 1);
EXPECT_TRUE(program->DetectVaryingsMismatch());
EXPECT_TRUE(LinkAsExpected(program, false));
@@ -1189,9 +1204,12 @@ TEST_F(ProgramManagerWithShaderTest, VaryingArraySizeMismatch) {
// If a varying has different precision in the vertex and fragment
// shader, linking should succeed.
TEST_F(ProgramManagerWithShaderTest, VaryingPrecisionMismatch) {
- Program* program = SetupVaryingsMatchingTest(
- true, SH_FLOAT, 2, SH_PRECISION_HIGHP, 1,
- true, SH_FLOAT, 2, SH_PRECISION_MEDIUMP, 1);
+ const VarInfo kVertexVarying =
+ { SH_FLOAT, 2, SH_PRECISION_HIGHP, 1, "a" };
+ const VarInfo kFragmentVarying =
+ { SH_FLOAT, 2, SH_PRECISION_MEDIUMP, 1, "a" };
+ Program* program = SetupVaryingsTest(
+ &kVertexVarying, 1, &kFragmentVarying, 1);
EXPECT_FALSE(program->DetectVaryingsMismatch());
EXPECT_TRUE(LinkAsExpected(program, true));
@@ -1200,9 +1218,10 @@ TEST_F(ProgramManagerWithShaderTest, VaryingPrecisionMismatch) {
// If a varying is statically used in fragment shader but not
// declared in vertex shader, link should fail.
TEST_F(ProgramManagerWithShaderTest, VaryingMissing) {
- Program* program = SetupVaryingsMatchingTest(
- false, 0, 0, 0, 0,
- true, SH_FLOAT, 3, SH_PRECISION_MEDIUMP, 1);
+ const VarInfo kFragmentVarying =
+ { SH_FLOAT, 3, SH_PRECISION_MEDIUMP, 1, "a" };
+ Program* program = SetupVaryingsTest(
+ NULL, 0, &kFragmentVarying, 1);
EXPECT_TRUE(program->DetectVaryingsMismatch());
EXPECT_TRUE(LinkAsExpected(program, false));
@@ -1212,14 +1231,49 @@ TEST_F(ProgramManagerWithShaderTest, VaryingMissing) {
// shader, even if it's not declared in vertex shader, link should
// succeed.
TEST_F(ProgramManagerWithShaderTest, InactiveVarying) {
- Program* program = SetupVaryingsMatchingTest(
- false, 0, 0, 0, 0,
- true, SH_FLOAT, 3, SH_PRECISION_MEDIUMP, 0);
+ const VarInfo kFragmentVarying =
+ { SH_FLOAT, 3, SH_PRECISION_MEDIUMP, 0, "a" };
+ Program* program = SetupVaryingsTest(
+ NULL, 0, &kFragmentVarying, 1);
EXPECT_FALSE(program->DetectVaryingsMismatch());
EXPECT_TRUE(LinkAsExpected(program, true));
}
+// Varyings go over 8 rows.
+TEST_F(ProgramManagerWithShaderTest, TooManyVaryings) {
+ const VarInfo kVertexVaryings[] = {
+ { SH_FLOAT_VEC4, 4, SH_PRECISION_MEDIUMP, 1, "a" },
+ { SH_FLOAT_VEC4, 5, SH_PRECISION_MEDIUMP, 1, "b" }
+ };
+ const VarInfo kFragmentVaryings[] = {
+ { SH_FLOAT_VEC4, 4, SH_PRECISION_MEDIUMP, 1, "a" },
+ { SH_FLOAT_VEC4, 5, SH_PRECISION_MEDIUMP, 1, "b" }
+ };
+ Program* program = SetupVaryingsTest(
+ kVertexVaryings, 2, kFragmentVaryings, 2);
+
+ EXPECT_FALSE(program->CheckVaryingsPacking());
+ EXPECT_TRUE(LinkAsExpected(program, false));
+}
+
+// Varyings go over 8 rows but some are inactive
+TEST_F(ProgramManagerWithShaderTest, TooManyInactiveVaryings) {
+ const VarInfo kVertexVaryings[] = {
+ { SH_FLOAT_VEC4, 4, SH_PRECISION_MEDIUMP, 1, "a" },
+ { SH_FLOAT_VEC4, 5, SH_PRECISION_MEDIUMP, 1, "b" }
+ };
+ const VarInfo kFragmentVaryings[] = {
+ { SH_FLOAT_VEC4, 4, SH_PRECISION_MEDIUMP, 0, "a" },
+ { SH_FLOAT_VEC4, 5, SH_PRECISION_MEDIUMP, 1, "b" }
+ };
+ Program* program = SetupVaryingsTest(
+ kVertexVaryings, 2, kFragmentVaryings, 2);
+
+ EXPECT_TRUE(program->CheckVaryingsPacking());
+ EXPECT_TRUE(LinkAsExpected(program, true));
+}
+
TEST_F(ProgramManagerWithShaderTest, ClearWithSamplerTypes) {
const GLuint kVShaderClientId = 2001;
const GLuint kFShaderClientId = 2002;
@@ -1378,7 +1432,7 @@ class ProgramManagerWithCacheTest : public testing::Test {
ProgramManagerWithCacheTest()
: cache_(new MockProgramCache()),
- manager_(cache_.get()),
+ manager_(cache_.get(), kMaxVaryingVectors),
vertex_shader_(NULL),
fragment_shader_(NULL),
program_(NULL) {
« no previous file with comments | « gpu/command_buffer/service/program_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698