Chromium Code Reviews| 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 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1248 | 1248 |
| 1249 // Set up program | 1249 // Set up program |
| 1250 const GLuint kClientProgramId = 6666; | 1250 const GLuint kClientProgramId = 6666; |
| 1251 const GLuint kServiceProgramId = 8888; | 1251 const GLuint kServiceProgramId = 8888; |
| 1252 Program* program = | 1252 Program* program = |
| 1253 manager_.CreateProgram(kClientProgramId, kServiceProgramId); | 1253 manager_.CreateProgram(kClientProgramId, kServiceProgramId); |
| 1254 ASSERT_TRUE(program != NULL); | 1254 ASSERT_TRUE(program != NULL); |
| 1255 EXPECT_TRUE(program->AttachShader(&shader_manager_, vshader)); | 1255 EXPECT_TRUE(program->AttachShader(&shader_manager_, vshader)); |
| 1256 EXPECT_TRUE(program->AttachShader(&shader_manager_, fshader)); | 1256 EXPECT_TRUE(program->AttachShader(&shader_manager_, fshader)); |
| 1257 | 1257 |
| 1258 EXPECT_TRUE(program->DetectUniformsMismatch()); | 1258 std::string conflicting_name; |
| 1259 | |
| 1260 EXPECT_TRUE(program->DetectUniformsMismatch(conflicting_name)); | |
| 1261 EXPECT_FALSE(conflicting_name.empty()); | |
| 1259 EXPECT_TRUE(LinkAsExpected(program, false)); | 1262 EXPECT_TRUE(LinkAsExpected(program, false)); |
| 1260 } | 1263 } |
| 1261 | 1264 |
| 1262 // If a varying has different type in the vertex and fragment | 1265 // If a varying has different type in the vertex and fragment |
| 1263 // shader, linking should fail. | 1266 // shader, linking should fail. |
| 1264 TEST_F(ProgramManagerWithShaderTest, VaryingTypeMismatch) { | 1267 TEST_F(ProgramManagerWithShaderTest, VaryingTypeMismatch) { |
| 1265 const VarInfo kVertexVarying = | 1268 const VarInfo kVertexVarying = |
| 1266 { SH_FLOAT_VEC3, 1, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; | 1269 { SH_FLOAT_VEC3, 1, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; |
| 1267 const VarInfo kFragmentVarying = | 1270 const VarInfo kFragmentVarying = |
| 1268 { SH_FLOAT_VEC4, 1, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; | 1271 { SH_FLOAT_VEC4, 1, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; |
| 1269 Program* program = SetupShaderVariableTest( | 1272 Program* program = SetupShaderVariableTest( |
| 1270 &kVertexVarying, 1, &kFragmentVarying, 1); | 1273 &kVertexVarying, 1, &kFragmentVarying, 1); |
| 1271 | 1274 |
| 1272 EXPECT_TRUE(program->DetectVaryingsMismatch()); | 1275 std::string conflicting_name; |
| 1276 | |
| 1277 EXPECT_TRUE(program->DetectVaryingsMismatch(conflicting_name)); | |
| 1278 EXPECT_FALSE(conflicting_name.empty()); | |
|
piman
2014/01/09 18:16:46
nit: maybe check that conficting_name is "a"
| |
| 1273 EXPECT_TRUE(LinkAsExpected(program, false)); | 1279 EXPECT_TRUE(LinkAsExpected(program, false)); |
| 1274 } | 1280 } |
| 1275 | 1281 |
| 1276 // If a varying has different array size in the vertex and fragment | 1282 // If a varying has different array size in the vertex and fragment |
| 1277 // shader, linking should fail. | 1283 // shader, linking should fail. |
| 1278 TEST_F(ProgramManagerWithShaderTest, VaryingArraySizeMismatch) { | 1284 TEST_F(ProgramManagerWithShaderTest, VaryingArraySizeMismatch) { |
| 1279 const VarInfo kVertexVarying = | 1285 const VarInfo kVertexVarying = |
| 1280 { SH_FLOAT, 2, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; | 1286 { SH_FLOAT, 2, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; |
| 1281 const VarInfo kFragmentVarying = | 1287 const VarInfo kFragmentVarying = |
| 1282 { SH_FLOAT, 3, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; | 1288 { SH_FLOAT, 3, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; |
| 1283 Program* program = SetupShaderVariableTest( | 1289 Program* program = SetupShaderVariableTest( |
| 1284 &kVertexVarying, 1, &kFragmentVarying, 1); | 1290 &kVertexVarying, 1, &kFragmentVarying, 1); |
| 1285 | 1291 |
| 1286 EXPECT_TRUE(program->DetectVaryingsMismatch()); | 1292 std::string conflicting_name; |
| 1293 | |
| 1294 EXPECT_TRUE(program->DetectVaryingsMismatch(conflicting_name)); | |
| 1295 EXPECT_FALSE(conflicting_name.empty()); | |
|
piman
2014/01/09 18:16:46
nit: maybe check that conficting_name is "a"
| |
| 1287 EXPECT_TRUE(LinkAsExpected(program, false)); | 1296 EXPECT_TRUE(LinkAsExpected(program, false)); |
| 1288 } | 1297 } |
| 1289 | 1298 |
| 1290 // If a varying has different precision in the vertex and fragment | 1299 // If a varying has different precision in the vertex and fragment |
| 1291 // shader, linking should succeed. | 1300 // shader, linking should succeed. |
| 1292 TEST_F(ProgramManagerWithShaderTest, VaryingPrecisionMismatch) { | 1301 TEST_F(ProgramManagerWithShaderTest, VaryingPrecisionMismatch) { |
| 1293 const VarInfo kVertexVarying = | 1302 const VarInfo kVertexVarying = |
| 1294 { SH_FLOAT, 2, SH_PRECISION_HIGHP, 1, "a", kVarVarying }; | 1303 { SH_FLOAT, 2, SH_PRECISION_HIGHP, 1, "a", kVarVarying }; |
| 1295 const VarInfo kFragmentVarying = | 1304 const VarInfo kFragmentVarying = |
| 1296 { SH_FLOAT, 2, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; | 1305 { SH_FLOAT, 2, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; |
| 1297 Program* program = SetupShaderVariableTest( | 1306 Program* program = SetupShaderVariableTest( |
| 1298 &kVertexVarying, 1, &kFragmentVarying, 1); | 1307 &kVertexVarying, 1, &kFragmentVarying, 1); |
| 1299 | 1308 |
| 1300 EXPECT_FALSE(program->DetectVaryingsMismatch()); | 1309 std::string conflicting_name; |
| 1310 | |
| 1311 EXPECT_FALSE(program->DetectVaryingsMismatch(conflicting_name)); | |
| 1312 EXPECT_TRUE(conflicting_name.empty()); | |
| 1301 EXPECT_TRUE(LinkAsExpected(program, true)); | 1313 EXPECT_TRUE(LinkAsExpected(program, true)); |
| 1302 } | 1314 } |
| 1303 | 1315 |
| 1304 // If a varying is statically used in fragment shader but not | 1316 // If a varying is statically used in fragment shader but not |
| 1305 // declared in vertex shader, link should fail. | 1317 // declared in vertex shader, link should fail. |
| 1306 TEST_F(ProgramManagerWithShaderTest, VaryingMissing) { | 1318 TEST_F(ProgramManagerWithShaderTest, VaryingMissing) { |
| 1307 const VarInfo kFragmentVarying = | 1319 const VarInfo kFragmentVarying = |
| 1308 { SH_FLOAT, 3, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; | 1320 { SH_FLOAT, 3, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }; |
| 1309 Program* program = SetupShaderVariableTest( | 1321 Program* program = SetupShaderVariableTest( |
| 1310 NULL, 0, &kFragmentVarying, 1); | 1322 NULL, 0, &kFragmentVarying, 1); |
| 1311 | 1323 |
| 1312 EXPECT_TRUE(program->DetectVaryingsMismatch()); | 1324 std::string conflicting_name; |
| 1325 | |
| 1326 EXPECT_TRUE(program->DetectVaryingsMismatch(conflicting_name)); | |
| 1327 EXPECT_FALSE(conflicting_name.empty()); | |
|
piman
2014/01/09 18:16:46
nit: maybe check that conficting_name is "a"
| |
| 1313 EXPECT_TRUE(LinkAsExpected(program, false)); | 1328 EXPECT_TRUE(LinkAsExpected(program, false)); |
| 1314 } | 1329 } |
| 1315 | 1330 |
| 1316 // If a varying is declared but not statically used in fragment | 1331 // If a varying is declared but not statically used in fragment |
| 1317 // shader, even if it's not declared in vertex shader, link should | 1332 // shader, even if it's not declared in vertex shader, link should |
| 1318 // succeed. | 1333 // succeed. |
| 1319 TEST_F(ProgramManagerWithShaderTest, InactiveVarying) { | 1334 TEST_F(ProgramManagerWithShaderTest, InactiveVarying) { |
| 1320 const VarInfo kFragmentVarying = | 1335 const VarInfo kFragmentVarying = |
| 1321 { SH_FLOAT, 3, SH_PRECISION_MEDIUMP, 0, "a", kVarVarying }; | 1336 { SH_FLOAT, 3, SH_PRECISION_MEDIUMP, 0, "a", kVarVarying }; |
| 1322 Program* program = SetupShaderVariableTest( | 1337 Program* program = SetupShaderVariableTest( |
| 1323 NULL, 0, &kFragmentVarying, 1); | 1338 NULL, 0, &kFragmentVarying, 1); |
| 1324 | 1339 |
| 1325 EXPECT_FALSE(program->DetectVaryingsMismatch()); | 1340 std::string conflicting_name; |
| 1341 | |
| 1342 EXPECT_FALSE(program->DetectVaryingsMismatch(conflicting_name)); | |
| 1343 EXPECT_TRUE(conflicting_name.empty()); | |
| 1326 EXPECT_TRUE(LinkAsExpected(program, true)); | 1344 EXPECT_TRUE(LinkAsExpected(program, true)); |
| 1327 } | 1345 } |
| 1328 | 1346 |
| 1329 // Uniforms and attributes are both global variables, thus sharing | 1347 // Uniforms and attributes are both global variables, thus sharing |
| 1330 // the same namespace. Any name conflicts should cause link | 1348 // the same namespace. Any name conflicts should cause link |
| 1331 // failure. | 1349 // failure. |
| 1332 TEST_F(ProgramManagerWithShaderTest, AttribUniformNameConflict) { | 1350 TEST_F(ProgramManagerWithShaderTest, AttribUniformNameConflict) { |
| 1333 const VarInfo kVertexAttribute = | 1351 const VarInfo kVertexAttribute = |
| 1334 { SH_FLOAT_VEC4, 1, SH_PRECISION_MEDIUMP, 1, "a", kVarAttribute }; | 1352 { SH_FLOAT_VEC4, 1, SH_PRECISION_MEDIUMP, 1, "a", kVarAttribute }; |
| 1335 const VarInfo kFragmentUniform = | 1353 const VarInfo kFragmentUniform = |
| 1336 { SH_FLOAT_VEC4, 1, SH_PRECISION_MEDIUMP, 1, "a", kVarUniform }; | 1354 { SH_FLOAT_VEC4, 1, SH_PRECISION_MEDIUMP, 1, "a", kVarUniform }; |
| 1337 Program* program = SetupShaderVariableTest( | 1355 Program* program = SetupShaderVariableTest( |
| 1338 &kVertexAttribute, 1, &kFragmentUniform, 1); | 1356 &kVertexAttribute, 1, &kFragmentUniform, 1); |
| 1339 | 1357 |
| 1340 EXPECT_TRUE(program->DetectGlobalNameConflicts()); | 1358 std::string conflicting_name; |
| 1359 | |
| 1360 EXPECT_TRUE(program->DetectGlobalNameConflicts(conflicting_name)); | |
| 1361 EXPECT_FALSE(conflicting_name.empty()); | |
|
piman
2014/01/09 18:16:46
nit: maybe check that conficting_name is "a"
| |
| 1341 EXPECT_TRUE(LinkAsExpected(program, false)); | 1362 EXPECT_TRUE(LinkAsExpected(program, false)); |
| 1342 } | 1363 } |
| 1343 | 1364 |
| 1344 // Varyings go over 8 rows. | 1365 // Varyings go over 8 rows. |
| 1345 TEST_F(ProgramManagerWithShaderTest, TooManyVaryings) { | 1366 TEST_F(ProgramManagerWithShaderTest, TooManyVaryings) { |
| 1346 const VarInfo kVertexVaryings[] = { | 1367 const VarInfo kVertexVaryings[] = { |
| 1347 { SH_FLOAT_VEC4, 4, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }, | 1368 { SH_FLOAT_VEC4, 4, SH_PRECISION_MEDIUMP, 1, "a", kVarVarying }, |
| 1348 { SH_FLOAT_VEC4, 5, SH_PRECISION_MEDIUMP, 1, "b", kVarVarying } | 1369 { SH_FLOAT_VEC4, 5, SH_PRECISION_MEDIUMP, 1, "b", kVarVarying } |
| 1349 }; | 1370 }; |
| 1350 const VarInfo kFragmentVaryings[] = { | 1371 const VarInfo kFragmentVaryings[] = { |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1748 SetExpectationsForProgramLoad(ProgramCache::PROGRAM_LOAD_SUCCESS); | 1769 SetExpectationsForProgramLoad(ProgramCache::PROGRAM_LOAD_SUCCESS); |
| 1749 SetExpectationsForNotCachingProgram(); | 1770 SetExpectationsForNotCachingProgram(); |
| 1750 SetExpectationsForProgramLoadSuccess(); | 1771 SetExpectationsForProgramLoadSuccess(); |
| 1751 | 1772 |
| 1752 EXPECT_TRUE(program_->Link(NULL, NULL, NULL, NULL, | 1773 EXPECT_TRUE(program_->Link(NULL, NULL, NULL, NULL, |
| 1753 base::Bind(&ShaderCacheCb))); | 1774 base::Bind(&ShaderCacheCb))); |
| 1754 } | 1775 } |
| 1755 | 1776 |
| 1756 } // namespace gles2 | 1777 } // namespace gles2 |
| 1757 } // namespace gpu | 1778 } // namespace gpu |
| OLD | NEW |