| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "gpu/command_buffer/service/program_manager.h" | 5 #include "gpu/command_buffer/service/program_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 using ::testing::DoAll; | 24 using ::testing::DoAll; |
| 25 using ::testing::InSequence; | 25 using ::testing::InSequence; |
| 26 using ::testing::MatcherCast; | 26 using ::testing::MatcherCast; |
| 27 using ::testing::Pointee; | 27 using ::testing::Pointee; |
| 28 using ::testing::Return; | 28 using ::testing::Return; |
| 29 using ::testing::ReturnRef; | 29 using ::testing::ReturnRef; |
| 30 using ::testing::SetArrayArgument; | 30 using ::testing::SetArrayArgument; |
| 31 using ::testing::SetArgumentPointee; | 31 using ::testing::SetArgumentPointee; |
| 32 using ::testing::StrEq; | 32 using ::testing::StrEq; |
| 33 | 33 |
| 34 // ANGLE now uses GLenum values directory for types | |
| 35 // TODO(jmadill): Delete these defines when the ANGLE | |
| 36 // roll reliably passes translator version 126 | |
| 37 #if (ANGLE_SH_VERSION >= 126) | |
| 38 #define SH_FLOAT GL_FLOAT | |
| 39 #define SH_FLOAT_VEC2 GL_FLOAT_VEC2 | |
| 40 #define SH_FLOAT_VEC3 GL_FLOAT_VEC3 | |
| 41 #define SH_FLOAT_VEC4 GL_FLOAT_VEC4 | |
| 42 #endif | |
| 43 | |
| 44 namespace gpu { | 34 namespace gpu { |
| 45 namespace gles2 { | 35 namespace gles2 { |
| 46 | 36 |
| 47 namespace { | 37 namespace { |
| 48 const uint32 kMaxVaryingVectors = 8; | 38 const uint32 kMaxVaryingVectors = 8; |
| 49 | 39 |
| 50 void ShaderCacheCb(const std::string& key, const std::string& shader) {} | 40 void ShaderCacheCb(const std::string& key, const std::string& shader) {} |
| 51 } // namespace anonymous | 41 } // namespace anonymous |
| 52 | 42 |
| 53 class ProgramManagerTest : public GpuServiceTest { | 43 class ProgramManagerTest : public GpuServiceTest { |
| (...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1254 | 1244 |
| 1255 EXPECT_TRUE(program->DetectUniformsMismatch(&conflicting_name)); | 1245 EXPECT_TRUE(program->DetectUniformsMismatch(&conflicting_name)); |
| 1256 EXPECT_EQ("a", conflicting_name); | 1246 EXPECT_EQ("a", conflicting_name); |
| 1257 EXPECT_TRUE(LinkAsExpected(program, false)); | 1247 EXPECT_TRUE(LinkAsExpected(program, false)); |
| 1258 } | 1248 } |
| 1259 | 1249 |
| 1260 // If a varying has different type in the vertex and fragment | 1250 // If a varying has different type in the vertex and fragment |
| 1261 // shader, linking should fail. | 1251 // shader, linking should fail. |
| 1262 TEST_F(ProgramManagerWithShaderTest, VaryingTypeMismatch) { | 1252 TEST_F(ProgramManagerWithShaderTest, VaryingTypeMismatch) { |
| 1263 const VarInfo kVertexVarying = | 1253 const VarInfo kVertexVarying = |
| 1264 { SH_FLOAT_VEC3, 1, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; | 1254 { GL_FLOAT_VEC3, 1, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; |
| 1265 const VarInfo kFragmentVarying = | 1255 const VarInfo kFragmentVarying = |
| 1266 { SH_FLOAT_VEC4, 1, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; | 1256 { GL_FLOAT_VEC4, 1, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; |
| 1267 Program* program = SetupShaderVariableTest( | 1257 Program* program = SetupShaderVariableTest( |
| 1268 &kVertexVarying, 1, &kFragmentVarying, 1); | 1258 &kVertexVarying, 1, &kFragmentVarying, 1); |
| 1269 | 1259 |
| 1270 std::string conflicting_name; | 1260 std::string conflicting_name; |
| 1271 | 1261 |
| 1272 EXPECT_TRUE(program->DetectVaryingsMismatch(&conflicting_name)); | 1262 EXPECT_TRUE(program->DetectVaryingsMismatch(&conflicting_name)); |
| 1273 EXPECT_EQ("a", conflicting_name); | 1263 EXPECT_EQ("a", conflicting_name); |
| 1274 EXPECT_TRUE(LinkAsExpected(program, false)); | 1264 EXPECT_TRUE(LinkAsExpected(program, false)); |
| 1275 } | 1265 } |
| 1276 | 1266 |
| 1277 // If a varying has different array size in the vertex and fragment | 1267 // If a varying has different array size in the vertex and fragment |
| 1278 // shader, linking should fail. | 1268 // shader, linking should fail. |
| 1279 TEST_F(ProgramManagerWithShaderTest, VaryingArraySizeMismatch) { | 1269 TEST_F(ProgramManagerWithShaderTest, VaryingArraySizeMismatch) { |
| 1280 const VarInfo kVertexVarying = | 1270 const VarInfo kVertexVarying = |
| 1281 { SH_FLOAT, 2, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; | 1271 { GL_FLOAT, 2, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; |
| 1282 const VarInfo kFragmentVarying = | 1272 const VarInfo kFragmentVarying = |
| 1283 { SH_FLOAT, 3, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; | 1273 { GL_FLOAT, 3, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; |
| 1284 Program* program = SetupShaderVariableTest( | 1274 Program* program = SetupShaderVariableTest( |
| 1285 &kVertexVarying, 1, &kFragmentVarying, 1); | 1275 &kVertexVarying, 1, &kFragmentVarying, 1); |
| 1286 | 1276 |
| 1287 std::string conflicting_name; | 1277 std::string conflicting_name; |
| 1288 | 1278 |
| 1289 EXPECT_TRUE(program->DetectVaryingsMismatch(&conflicting_name)); | 1279 EXPECT_TRUE(program->DetectVaryingsMismatch(&conflicting_name)); |
| 1290 EXPECT_EQ("a", conflicting_name); | 1280 EXPECT_EQ("a", conflicting_name); |
| 1291 EXPECT_TRUE(LinkAsExpected(program, false)); | 1281 EXPECT_TRUE(LinkAsExpected(program, false)); |
| 1292 } | 1282 } |
| 1293 | 1283 |
| 1294 // If a varying has different precision in the vertex and fragment | 1284 // If a varying has different precision in the vertex and fragment |
| 1295 // shader, linking should succeed. | 1285 // shader, linking should succeed. |
| 1296 TEST_F(ProgramManagerWithShaderTest, VaryingPrecisionMismatch) { | 1286 TEST_F(ProgramManagerWithShaderTest, VaryingPrecisionMismatch) { |
| 1297 const VarInfo kVertexVarying = | 1287 const VarInfo kVertexVarying = |
| 1298 { SH_FLOAT, 2, SH_PRECISION_HIGHP, 1, "a", kVarVarying }; | 1288 { GL_FLOAT, 2, SH_PRECISION_HIGHP, 1, "a", kVarVarying }; |
| 1299 const VarInfo kFragmentVarying = | 1289 const VarInfo kFragmentVarying = |
| 1300 { SH_FLOAT, 2, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; | 1290 { GL_FLOAT, 2, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; |
| 1301 Program* program = SetupShaderVariableTest( | 1291 Program* program = SetupShaderVariableTest( |
| 1302 &kVertexVarying, 1, &kFragmentVarying, 1); | 1292 &kVertexVarying, 1, &kFragmentVarying, 1); |
| 1303 | 1293 |
| 1304 std::string conflicting_name; | 1294 std::string conflicting_name; |
| 1305 | 1295 |
| 1306 EXPECT_FALSE(program->DetectVaryingsMismatch(&conflicting_name)); | 1296 EXPECT_FALSE(program->DetectVaryingsMismatch(&conflicting_name)); |
| 1307 EXPECT_TRUE(conflicting_name.empty()); | 1297 EXPECT_TRUE(conflicting_name.empty()); |
| 1308 EXPECT_TRUE(LinkAsExpected(program, true)); | 1298 EXPECT_TRUE(LinkAsExpected(program, true)); |
| 1309 } | 1299 } |
| 1310 | 1300 |
| 1311 // If a varying is statically used in fragment shader but not | 1301 // If a varying is statically used in fragment shader but not |
| 1312 // declared in vertex shader, link should fail. | 1302 // declared in vertex shader, link should fail. |
| 1313 TEST_F(ProgramManagerWithShaderTest, VaryingMissing) { | 1303 TEST_F(ProgramManagerWithShaderTest, VaryingMissing) { |
| 1314 const VarInfo kFragmentVarying = | 1304 const VarInfo kFragmentVarying = |
| 1315 { SH_FLOAT, 3, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; | 1305 { GL_FLOAT, 3, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; |
| 1316 Program* program = SetupShaderVariableTest( | 1306 Program* program = SetupShaderVariableTest( |
| 1317 NULL, 0, &kFragmentVarying, 1); | 1307 NULL, 0, &kFragmentVarying, 1); |
| 1318 | 1308 |
| 1319 std::string conflicting_name; | 1309 std::string conflicting_name; |
| 1320 | 1310 |
| 1321 EXPECT_TRUE(program->DetectVaryingsMismatch(&conflicting_name)); | 1311 EXPECT_TRUE(program->DetectVaryingsMismatch(&conflicting_name)); |
| 1322 EXPECT_EQ("a", conflicting_name); | 1312 EXPECT_EQ("a", conflicting_name); |
| 1323 EXPECT_TRUE(LinkAsExpected(program, false)); | 1313 EXPECT_TRUE(LinkAsExpected(program, false)); |
| 1324 } | 1314 } |
| 1325 | 1315 |
| 1326 // If a varying is declared but not statically used in fragment | 1316 // If a varying is declared but not statically used in fragment |
| 1327 // shader, even if it's not declared in vertex shader, link should | 1317 // shader, even if it's not declared in vertex shader, link should |
| 1328 // succeed. | 1318 // succeed. |
| 1329 TEST_F(ProgramManagerWithShaderTest, InactiveVarying) { | 1319 TEST_F(ProgramManagerWithShaderTest, InactiveVarying) { |
| 1330 const VarInfo kFragmentVarying = | 1320 const VarInfo kFragmentVarying = |
| 1331 { SH_FLOAT, 3, SH_PRECISION_MEDIUMP, 0, "a", kVarVarying }; | 1321 { GL_FLOAT, 3, SH_PRECISION_MEDIUMP, 0, "a", kVarVarying }; |
| 1332 Program* program = SetupShaderVariableTest( | 1322 Program* program = SetupShaderVariableTest( |
| 1333 NULL, 0, &kFragmentVarying, 1); | 1323 NULL, 0, &kFragmentVarying, 1); |
| 1334 | 1324 |
| 1335 std::string conflicting_name; | 1325 std::string conflicting_name; |
| 1336 | 1326 |
| 1337 EXPECT_FALSE(program->DetectVaryingsMismatch(&conflicting_name)); | 1327 EXPECT_FALSE(program->DetectVaryingsMismatch(&conflicting_name)); |
| 1338 EXPECT_TRUE(conflicting_name.empty()); | 1328 EXPECT_TRUE(conflicting_name.empty()); |
| 1339 EXPECT_TRUE(LinkAsExpected(program, true)); | 1329 EXPECT_TRUE(LinkAsExpected(program, true)); |
| 1340 } | 1330 } |
| 1341 | 1331 |
| 1342 // Uniforms and attributes are both global variables, thus sharing | 1332 // Uniforms and attributes are both global variables, thus sharing |
| 1343 // the same namespace. Any name conflicts should cause link | 1333 // the same namespace. Any name conflicts should cause link |
| 1344 // failure. | 1334 // failure. |
| 1345 TEST_F(ProgramManagerWithShaderTest, AttribUniformNameConflict) { | 1335 TEST_F(ProgramManagerWithShaderTest, AttribUniformNameConflict) { |
| 1346 const VarInfo kVertexAttribute = | 1336 const VarInfo kVertexAttribute = |
| 1347 { SH_FLOAT_VEC4, 1, SH_PRECISION_MEDIUMP, 1, "a", kVarAttribute }; | 1337 { GL_FLOAT_VEC4, 1, SH_PRECISION_MEDIUMP, 1, "a", kVarAttribute }; |
| 1348 const VarInfo kFragmentUniform = | 1338 const VarInfo kFragmentUniform = |
| 1349 { SH_FLOAT_VEC4, 1, SH_PRECISION_MEDIUMP, 1, "a", kVarUniform }; | 1339 { GL_FLOAT_VEC4, 1, SH_PRECISION_MEDIUMP, 1, "a", kVarUniform }; |
| 1350 Program* program = SetupShaderVariableTest( | 1340 Program* program = SetupShaderVariableTest( |
| 1351 &kVertexAttribute, 1, &kFragmentUniform, 1); | 1341 &kVertexAttribute, 1, &kFragmentUniform, 1); |
| 1352 | 1342 |
| 1353 std::string conflicting_name; | 1343 std::string conflicting_name; |
| 1354 | 1344 |
| 1355 EXPECT_TRUE(program->DetectGlobalNameConflicts(&conflicting_name)); | 1345 EXPECT_TRUE(program->DetectGlobalNameConflicts(&conflicting_name)); |
| 1356 EXPECT_EQ("a", conflicting_name); | 1346 EXPECT_EQ("a", conflicting_name); |
| 1357 EXPECT_TRUE(LinkAsExpected(program, false)); | 1347 EXPECT_TRUE(LinkAsExpected(program, false)); |
| 1358 } | 1348 } |
| 1359 | 1349 |
| 1360 // Varyings go over 8 rows. | 1350 // Varyings go over 8 rows. |
| 1361 TEST_F(ProgramManagerWithShaderTest, TooManyVaryings) { | 1351 TEST_F(ProgramManagerWithShaderTest, TooManyVaryings) { |
| 1362 const VarInfo kVertexVaryings[] = { | 1352 const VarInfo kVertexVaryings[] = { |
| 1363 { SH_FLOAT_VEC4, 4, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }, | 1353 { GL_FLOAT_VEC4, 4, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }, |
| 1364 { SH_FLOAT_VEC4, 5, SH_PRECISION_MEDIUMP, 1, "b", kVarVarying } | 1354 { GL_FLOAT_VEC4, 5, SH_PRECISION_MEDIUMP, 1, "b", kVarVarying } |
| 1365 }; | 1355 }; |
| 1366 const VarInfo kFragmentVaryings[] = { | 1356 const VarInfo kFragmentVaryings[] = { |
| 1367 { SH_FLOAT_VEC4, 4, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }, | 1357 { GL_FLOAT_VEC4, 4, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }, |
| 1368 { SH_FLOAT_VEC4, 5, SH_PRECISION_MEDIUMP, 1, "b", kVarVarying } | 1358 { GL_FLOAT_VEC4, 5, SH_PRECISION_MEDIUMP, 1, "b", kVarVarying } |
| 1369 }; | 1359 }; |
| 1370 Program* program = SetupShaderVariableTest( | 1360 Program* program = SetupShaderVariableTest( |
| 1371 kVertexVaryings, 2, kFragmentVaryings, 2); | 1361 kVertexVaryings, 2, kFragmentVaryings, 2); |
| 1372 | 1362 |
| 1373 EXPECT_FALSE( | 1363 EXPECT_FALSE( |
| 1374 program->CheckVaryingsPacking(Program::kCountOnlyStaticallyUsed)); | 1364 program->CheckVaryingsPacking(Program::kCountOnlyStaticallyUsed)); |
| 1375 EXPECT_TRUE(LinkAsExpected(program, false)); | 1365 EXPECT_TRUE(LinkAsExpected(program, false)); |
| 1376 } | 1366 } |
| 1377 | 1367 |
| 1378 // Varyings go over 8 rows but some are inactive | 1368 // Varyings go over 8 rows but some are inactive |
| 1379 TEST_F(ProgramManagerWithShaderTest, TooManyInactiveVaryings) { | 1369 TEST_F(ProgramManagerWithShaderTest, TooManyInactiveVaryings) { |
| 1380 const VarInfo kVertexVaryings[] = { | 1370 const VarInfo kVertexVaryings[] = { |
| 1381 { SH_FLOAT_VEC4, 4, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }, | 1371 { GL_FLOAT_VEC4, 4, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }, |
| 1382 { SH_FLOAT_VEC4, 5, SH_PRECISION_MEDIUMP, 1, "b", kVarVarying } | 1372 { GL_FLOAT_VEC4, 5, SH_PRECISION_MEDIUMP, 1, "b", kVarVarying } |
| 1383 }; | 1373 }; |
| 1384 const VarInfo kFragmentVaryings[] = { | 1374 const VarInfo kFragmentVaryings[] = { |
| 1385 { SH_FLOAT_VEC4, 4, SH_PRECISION_MEDIUMP, 0, "a", kVarVarying }, | 1375 { GL_FLOAT_VEC4, 4, SH_PRECISION_MEDIUMP, 0, "a", kVarVarying }, |
| 1386 { SH_FLOAT_VEC4, 5, SH_PRECISION_MEDIUMP, 1, "b", kVarVarying } | 1376 { GL_FLOAT_VEC4, 5, SH_PRECISION_MEDIUMP, 1, "b", kVarVarying } |
| 1387 }; | 1377 }; |
| 1388 Program* program = SetupShaderVariableTest( | 1378 Program* program = SetupShaderVariableTest( |
| 1389 kVertexVaryings, 2, kFragmentVaryings, 2); | 1379 kVertexVaryings, 2, kFragmentVaryings, 2); |
| 1390 | 1380 |
| 1391 EXPECT_TRUE( | 1381 EXPECT_TRUE( |
| 1392 program->CheckVaryingsPacking(Program::kCountOnlyStaticallyUsed)); | 1382 program->CheckVaryingsPacking(Program::kCountOnlyStaticallyUsed)); |
| 1393 EXPECT_TRUE(LinkAsExpected(program, true)); | 1383 EXPECT_TRUE(LinkAsExpected(program, true)); |
| 1394 } | 1384 } |
| 1395 | 1385 |
| 1396 // Varyings go over 8 rows but some are inactive. | 1386 // Varyings go over 8 rows but some are inactive. |
| 1397 // However, we still fail the check if kCountAll option is used. | 1387 // However, we still fail the check if kCountAll option is used. |
| 1398 TEST_F(ProgramManagerWithShaderTest, CountAllVaryingsInPacking) { | 1388 TEST_F(ProgramManagerWithShaderTest, CountAllVaryingsInPacking) { |
| 1399 const VarInfo kVertexVaryings[] = { | 1389 const VarInfo kVertexVaryings[] = { |
| 1400 { SH_FLOAT_VEC4, 4, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }, | 1390 { GL_FLOAT_VEC4, 4, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }, |
| 1401 { SH_FLOAT_VEC4, 5, SH_PRECISION_MEDIUMP, 1, "b", kVarVarying } | 1391 { GL_FLOAT_VEC4, 5, SH_PRECISION_MEDIUMP, 1, "b", kVarVarying } |
| 1402 }; | 1392 }; |
| 1403 const VarInfo kFragmentVaryings[] = { | 1393 const VarInfo kFragmentVaryings[] = { |
| 1404 { SH_FLOAT_VEC4, 4, SH_PRECISION_MEDIUMP, 0, "a", kVarVarying }, | 1394 { GL_FLOAT_VEC4, 4, SH_PRECISION_MEDIUMP, 0, "a", kVarVarying }, |
| 1405 { SH_FLOAT_VEC4, 5, SH_PRECISION_MEDIUMP, 1, "b", kVarVarying } | 1395 { GL_FLOAT_VEC4, 5, SH_PRECISION_MEDIUMP, 1, "b", kVarVarying } |
| 1406 }; | 1396 }; |
| 1407 Program* program = SetupShaderVariableTest( | 1397 Program* program = SetupShaderVariableTest( |
| 1408 kVertexVaryings, 2, kFragmentVaryings, 2); | 1398 kVertexVaryings, 2, kFragmentVaryings, 2); |
| 1409 | 1399 |
| 1410 EXPECT_FALSE(program->CheckVaryingsPacking(Program::kCountAll)); | 1400 EXPECT_FALSE(program->CheckVaryingsPacking(Program::kCountAll)); |
| 1411 } | 1401 } |
| 1412 | 1402 |
| 1413 TEST_F(ProgramManagerWithShaderTest, ClearWithSamplerTypes) { | 1403 TEST_F(ProgramManagerWithShaderTest, ClearWithSamplerTypes) { |
| 1414 const GLuint kVShaderClientId = 2001; | 1404 const GLuint kVShaderClientId = 2001; |
| 1415 const GLuint kFShaderClientId = 2002; | 1405 const GLuint kFShaderClientId = 2002; |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1778 SetExpectationsForProgramLoad(ProgramCache::PROGRAM_LOAD_SUCCESS); | 1768 SetExpectationsForProgramLoad(ProgramCache::PROGRAM_LOAD_SUCCESS); |
| 1779 SetExpectationsForNotCachingProgram(); | 1769 SetExpectationsForNotCachingProgram(); |
| 1780 SetExpectationsForProgramLoadSuccess(); | 1770 SetExpectationsForProgramLoadSuccess(); |
| 1781 | 1771 |
| 1782 EXPECT_TRUE(program_->Link(NULL, NULL, NULL, | 1772 EXPECT_TRUE(program_->Link(NULL, NULL, NULL, |
| 1783 Program::kCountOnlyStaticallyUsed, base::Bind(&ShaderCacheCb))); | 1773 Program::kCountOnlyStaticallyUsed, base::Bind(&ShaderCacheCb))); |
| 1784 } | 1774 } |
| 1785 | 1775 |
| 1786 } // namespace gles2 | 1776 } // namespace gles2 |
| 1787 } // namespace gpu | 1777 } // namespace gpu |
| OLD | NEW |