| 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 ASSERT_TRUE(fragment_shader != NULL); | 243 ASSERT_TRUE(fragment_shader != NULL); |
| 244 vertex_shader->SetStatus(true, NULL, NULL); | 244 vertex_shader->SetStatus(true, NULL, NULL); |
| 245 fragment_shader->SetStatus(true, NULL, NULL); | 245 fragment_shader->SetStatus(true, NULL, NULL); |
| 246 | 246 |
| 247 program_ = manager_.CreateProgram( | 247 program_ = manager_.CreateProgram( |
| 248 kClientProgramId, kServiceProgramId); | 248 kClientProgramId, kServiceProgramId); |
| 249 ASSERT_TRUE(program_ != NULL); | 249 ASSERT_TRUE(program_ != NULL); |
| 250 | 250 |
| 251 program_->AttachShader(&shader_manager_, vertex_shader); | 251 program_->AttachShader(&shader_manager_, vertex_shader); |
| 252 program_->AttachShader(&shader_manager_, fragment_shader); | 252 program_->AttachShader(&shader_manager_, fragment_shader); |
| 253 program_->Link(NULL, NULL, NULL, base::Bind(&ShaderCacheCb)); | 253 program_->Link(NULL, NULL, NULL, NULL, base::Bind(&ShaderCacheCb)); |
| 254 } | 254 } |
| 255 | 255 |
| 256 void SetupShader(AttribInfo* attribs, size_t num_attribs, | 256 void SetupShader(AttribInfo* attribs, size_t num_attribs, |
| 257 UniformInfo* uniforms, size_t num_uniforms, | 257 UniformInfo* uniforms, size_t num_uniforms, |
| 258 GLuint service_id) { | 258 GLuint service_id) { |
| 259 TestHelper::SetupShader( | 259 TestHelper::SetupShader( |
| 260 gl_.get(), attribs, num_attribs, uniforms, num_uniforms, service_id); | 260 gl_.get(), attribs, num_attribs, uniforms, num_uniforms, service_id); |
| 261 } | 261 } |
| 262 | 262 |
| 263 void SetupDefaultShaderExpectations() { | 263 void SetupDefaultShaderExpectations() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 276 } | 276 } |
| 277 | 277 |
| 278 // Return true if link status matches expected_link_status | 278 // Return true if link status matches expected_link_status |
| 279 bool LinkAsExpected(Program* program, | 279 bool LinkAsExpected(Program* program, |
| 280 bool expected_link_status) { | 280 bool expected_link_status) { |
| 281 GLuint service_id = program->service_id(); | 281 GLuint service_id = program->service_id(); |
| 282 if (expected_link_status) { | 282 if (expected_link_status) { |
| 283 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, | 283 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, |
| 284 service_id); | 284 service_id); |
| 285 } | 285 } |
| 286 program->Link(NULL, NULL, NULL, base::Bind(&ShaderCacheCb)); | 286 program->Link(NULL, NULL, NULL, NULL, base::Bind(&ShaderCacheCb)); |
| 287 GLint link_status; | 287 GLint link_status; |
| 288 program->GetProgramiv(GL_LINK_STATUS, &link_status); | 288 program->GetProgramiv(GL_LINK_STATUS, &link_status); |
| 289 return (static_cast<bool>(link_status) == expected_link_status); | 289 return (static_cast<bool>(link_status) == expected_link_status); |
| 290 } | 290 } |
| 291 | 291 |
| 292 Program* SetupShaderVariableTest(const VarInfo* vertex_variables, | 292 Program* SetupShaderVariableTest(const VarInfo* vertex_variables, |
| 293 size_t vertex_variable_size, | 293 size_t vertex_variable_size, |
| 294 const VarInfo* fragment_variables, | 294 const VarInfo* fragment_variables, |
| 295 size_t fragment_variable_size) { | 295 size_t fragment_variable_size) { |
| 296 // Set up shader | 296 // Set up shader |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 vshader->SetStatus(true, "", NULL); | 713 vshader->SetStatus(true, "", NULL); |
| 714 Shader* fshader = shader_manager_.CreateShader( | 714 Shader* fshader = shader_manager_.CreateShader( |
| 715 kFShaderClientId, kFShaderServiceId, GL_FRAGMENT_SHADER); | 715 kFShaderClientId, kFShaderServiceId, GL_FRAGMENT_SHADER); |
| 716 ASSERT_TRUE(fshader != NULL); | 716 ASSERT_TRUE(fshader != NULL); |
| 717 fshader->SetStatus(true, "", NULL); | 717 fshader->SetStatus(true, "", NULL); |
| 718 Program* program = | 718 Program* program = |
| 719 manager_.CreateProgram(kClientProgramId, kServiceProgramId); | 719 manager_.CreateProgram(kClientProgramId, kServiceProgramId); |
| 720 ASSERT_TRUE(program != NULL); | 720 ASSERT_TRUE(program != NULL); |
| 721 EXPECT_TRUE(program->AttachShader(&shader_manager_, vshader)); | 721 EXPECT_TRUE(program->AttachShader(&shader_manager_, vshader)); |
| 722 EXPECT_TRUE(program->AttachShader(&shader_manager_, fshader)); | 722 EXPECT_TRUE(program->AttachShader(&shader_manager_, fshader)); |
| 723 program->Link(NULL, NULL, NULL, base::Bind(&ShaderCacheCb)); | 723 program->Link(NULL, NULL, NULL, NULL, base::Bind(&ShaderCacheCb)); |
| 724 GLint value = 0; | 724 GLint value = 0; |
| 725 program->GetProgramiv(GL_ACTIVE_ATTRIBUTES, &value); | 725 program->GetProgramiv(GL_ACTIVE_ATTRIBUTES, &value); |
| 726 EXPECT_EQ(3, value); | 726 EXPECT_EQ(3, value); |
| 727 // Check that we skipped the "gl_" uniform. | 727 // Check that we skipped the "gl_" uniform. |
| 728 program->GetProgramiv(GL_ACTIVE_UNIFORMS, &value); | 728 program->GetProgramiv(GL_ACTIVE_UNIFORMS, &value); |
| 729 EXPECT_EQ(2, value); | 729 EXPECT_EQ(2, value); |
| 730 // Check that our max length adds room for the array spec and is not as long | 730 // Check that our max length adds room for the array spec and is not as long |
| 731 // as the "gl_" uniform we skipped. | 731 // as the "gl_" uniform we skipped. |
| 732 // +4u is to account for "gl_" and NULL terminator. | 732 // +4u is to account for "gl_" and NULL terminator. |
| 733 program->GetProgramiv(GL_ACTIVE_UNIFORM_MAX_LENGTH, &value); | 733 program->GetProgramiv(GL_ACTIVE_UNIFORM_MAX_LENGTH, &value); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 vshader->SetStatus(true, "", NULL); | 781 vshader->SetStatus(true, "", NULL); |
| 782 Shader* fshader = shader_manager_.CreateShader( | 782 Shader* fshader = shader_manager_.CreateShader( |
| 783 kFShaderClientId, kFShaderServiceId, GL_FRAGMENT_SHADER); | 783 kFShaderClientId, kFShaderServiceId, GL_FRAGMENT_SHADER); |
| 784 ASSERT_TRUE(fshader != NULL); | 784 ASSERT_TRUE(fshader != NULL); |
| 785 fshader->SetStatus(true, "", NULL); | 785 fshader->SetStatus(true, "", NULL); |
| 786 Program* program = | 786 Program* program = |
| 787 manager_.CreateProgram(kClientProgramId, kServiceProgramId); | 787 manager_.CreateProgram(kClientProgramId, kServiceProgramId); |
| 788 ASSERT_TRUE(program != NULL); | 788 ASSERT_TRUE(program != NULL); |
| 789 EXPECT_TRUE(program->AttachShader(&shader_manager_, vshader)); | 789 EXPECT_TRUE(program->AttachShader(&shader_manager_, vshader)); |
| 790 EXPECT_TRUE(program->AttachShader(&shader_manager_, fshader)); | 790 EXPECT_TRUE(program->AttachShader(&shader_manager_, fshader)); |
| 791 program->Link(NULL, NULL, NULL, base::Bind(&ShaderCacheCb)); | 791 program->Link(NULL, NULL, NULL, NULL, base::Bind(&ShaderCacheCb)); |
| 792 | 792 |
| 793 // Check that we get the correct locations. | 793 // Check that we get the correct locations. |
| 794 EXPECT_EQ(kUniform2FakeLocation, | 794 EXPECT_EQ(kUniform2FakeLocation, |
| 795 program->GetUniformFakeLocation(kUniform2Name)); | 795 program->GetUniformFakeLocation(kUniform2Name)); |
| 796 EXPECT_EQ(kUniform3FakeLocation, | 796 EXPECT_EQ(kUniform3FakeLocation, |
| 797 program->GetUniformFakeLocation(kUniform3Name)); | 797 program->GetUniformFakeLocation(kUniform3Name)); |
| 798 } | 798 } |
| 799 | 799 |
| 800 // Some GL drivers incorrectly return the wrong type. For example they return | 800 // Some GL drivers incorrectly return the wrong type. For example they return |
| 801 // GL_FLOAT_VEC2 when they should return GL_FLOAT_MAT2. Check we handle this. | 801 // GL_FLOAT_VEC2 when they should return GL_FLOAT_MAT2. Check we handle this. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 const size_t kNumUniforms = arraysize(kUniforms); | 882 const size_t kNumUniforms = arraysize(kUniforms); |
| 883 static const GLuint kClientProgramId = 1234; | 883 static const GLuint kClientProgramId = 1234; |
| 884 static const GLuint kServiceProgramId = 5679; | 884 static const GLuint kServiceProgramId = 5679; |
| 885 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, | 885 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, |
| 886 kServiceProgramId); | 886 kServiceProgramId); |
| 887 Program* program = manager_.CreateProgram( | 887 Program* program = manager_.CreateProgram( |
| 888 kClientProgramId, kServiceProgramId); | 888 kClientProgramId, kServiceProgramId); |
| 889 ASSERT_TRUE(program!= NULL); | 889 ASSERT_TRUE(program!= NULL); |
| 890 EXPECT_TRUE(program->AttachShader(&shader_manager_, vshader)); | 890 EXPECT_TRUE(program->AttachShader(&shader_manager_, vshader)); |
| 891 EXPECT_TRUE(program->AttachShader(&shader_manager_, fshader)); | 891 EXPECT_TRUE(program->AttachShader(&shader_manager_, fshader)); |
| 892 program->Link(NULL, NULL, NULL, base::Bind(&ShaderCacheCb)); | 892 program->Link(NULL, NULL, NULL, NULL, base::Bind(&ShaderCacheCb)); |
| 893 // Check that we got the good type, not the bad. | 893 // Check that we got the good type, not the bad. |
| 894 // Check Attribs | 894 // Check Attribs |
| 895 for (unsigned index = 0; index < kNumAttribs; ++index) { | 895 for (unsigned index = 0; index < kNumAttribs; ++index) { |
| 896 const Program::VertexAttrib* attrib_info = | 896 const Program::VertexAttrib* attrib_info = |
| 897 program->GetAttribInfo(index); | 897 program->GetAttribInfo(index); |
| 898 ASSERT_TRUE(attrib_info != NULL); | 898 ASSERT_TRUE(attrib_info != NULL); |
| 899 ShaderTranslator::VariableMap::const_iterator it = attrib_map.find( | 899 ShaderTranslator::VariableMap::const_iterator it = attrib_map.find( |
| 900 attrib_info->name); | 900 attrib_info->name); |
| 901 ASSERT_TRUE(it != attrib_map.end()); | 901 ASSERT_TRUE(it != attrib_map.end()); |
| 902 EXPECT_EQ(it->first, attrib_info->name); | 902 EXPECT_EQ(it->first, attrib_info->name); |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1433 kUniform3FakeLocation, | 1433 kUniform3FakeLocation, |
| 1434 kUniform3RealLocation, | 1434 kUniform3RealLocation, |
| 1435 kUniform3DesiredLocation, | 1435 kUniform3DesiredLocation, |
| 1436 kUniform3GoodName, | 1436 kUniform3GoodName, |
| 1437 }, | 1437 }, |
| 1438 }; | 1438 }; |
| 1439 const size_t kNumAttribs = arraysize(kAttribs); | 1439 const size_t kNumAttribs = arraysize(kAttribs); |
| 1440 const size_t kNumUniforms = arraysize(kUniforms); | 1440 const size_t kNumUniforms = arraysize(kUniforms); |
| 1441 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, | 1441 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, |
| 1442 kServiceProgramId); | 1442 kServiceProgramId); |
| 1443 program->Link(NULL, NULL, NULL, base::Bind(&ShaderCacheCb)); | 1443 program->Link(NULL, NULL, NULL, NULL, base::Bind(&ShaderCacheCb)); |
| 1444 SetupExpectationsForClearingUniforms(kUniforms, kNumUniforms); | 1444 SetupExpectationsForClearingUniforms(kUniforms, kNumUniforms); |
| 1445 manager_.ClearUniforms(program); | 1445 manager_.ClearUniforms(program); |
| 1446 } | 1446 } |
| 1447 } | 1447 } |
| 1448 | 1448 |
| 1449 TEST_F(ProgramManagerWithShaderTest, BindUniformLocation) { | 1449 TEST_F(ProgramManagerWithShaderTest, BindUniformLocation) { |
| 1450 const GLuint kVShaderClientId = 2001; | 1450 const GLuint kVShaderClientId = 2001; |
| 1451 const GLuint kFShaderClientId = 2002; | 1451 const GLuint kFShaderClientId = 2002; |
| 1452 const GLuint kVShaderServiceId = 3001; | 1452 const GLuint kVShaderServiceId = 3001; |
| 1453 const GLuint kFShaderServiceId = 3002; | 1453 const GLuint kFShaderServiceId = 3002; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1505 kUniform3RealLocation, | 1505 kUniform3RealLocation, |
| 1506 kUniform3DesiredLocation, | 1506 kUniform3DesiredLocation, |
| 1507 kUniform3GoodName, | 1507 kUniform3GoodName, |
| 1508 }, | 1508 }, |
| 1509 }; | 1509 }; |
| 1510 | 1510 |
| 1511 const size_t kNumAttribs = arraysize(kAttribs); | 1511 const size_t kNumAttribs = arraysize(kAttribs); |
| 1512 const size_t kNumUniforms = arraysize(kUniforms); | 1512 const size_t kNumUniforms = arraysize(kUniforms); |
| 1513 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, | 1513 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, |
| 1514 kServiceProgramId); | 1514 kServiceProgramId); |
| 1515 program->Link(NULL, NULL, NULL, base::Bind(&ShaderCacheCb)); | 1515 program->Link(NULL, NULL, NULL, NULL, base::Bind(&ShaderCacheCb)); |
| 1516 | 1516 |
| 1517 EXPECT_EQ(kUniform1DesiredLocation, | 1517 EXPECT_EQ(kUniform1DesiredLocation, |
| 1518 program->GetUniformFakeLocation(kUniform1Name)); | 1518 program->GetUniformFakeLocation(kUniform1Name)); |
| 1519 EXPECT_EQ(kUniform3DesiredLocation, | 1519 EXPECT_EQ(kUniform3DesiredLocation, |
| 1520 program->GetUniformFakeLocation(kUniform3BadName)); | 1520 program->GetUniformFakeLocation(kUniform3BadName)); |
| 1521 EXPECT_EQ(kUniform3DesiredLocation, | 1521 EXPECT_EQ(kUniform3DesiredLocation, |
| 1522 program->GetUniformFakeLocation(kUniform3GoodName)); | 1522 program->GetUniformFakeLocation(kUniform3GoodName)); |
| 1523 } | 1523 } |
| 1524 | 1524 |
| 1525 class ProgramManagerWithCacheTest : public testing::Test { | 1525 class ProgramManagerWithCacheTest : public testing::Test { |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1728 const GLuint ProgramManagerWithCacheTest::kVertexShaderClientId; | 1728 const GLuint ProgramManagerWithCacheTest::kVertexShaderClientId; |
| 1729 const GLuint ProgramManagerWithCacheTest::kFragmentShaderClientId; | 1729 const GLuint ProgramManagerWithCacheTest::kFragmentShaderClientId; |
| 1730 const GLuint ProgramManagerWithCacheTest::kVertexShaderServiceId; | 1730 const GLuint ProgramManagerWithCacheTest::kVertexShaderServiceId; |
| 1731 const GLuint ProgramManagerWithCacheTest::kFragmentShaderServiceId; | 1731 const GLuint ProgramManagerWithCacheTest::kFragmentShaderServiceId; |
| 1732 #endif | 1732 #endif |
| 1733 | 1733 |
| 1734 TEST_F(ProgramManagerWithCacheTest, CacheProgramOnSuccessfulLink) { | 1734 TEST_F(ProgramManagerWithCacheTest, CacheProgramOnSuccessfulLink) { |
| 1735 SetShadersCompiled(); | 1735 SetShadersCompiled(); |
| 1736 SetExpectationsForProgramLink(); | 1736 SetExpectationsForProgramLink(); |
| 1737 SetExpectationsForProgramCached(); | 1737 SetExpectationsForProgramCached(); |
| 1738 EXPECT_TRUE(program_->Link(NULL, NULL, NULL, | 1738 EXPECT_TRUE(program_->Link(NULL, NULL, NULL, NULL, |
| 1739 base::Bind(&ShaderCacheCb))); | 1739 base::Bind(&ShaderCacheCb))); |
| 1740 } | 1740 } |
| 1741 | 1741 |
| 1742 TEST_F(ProgramManagerWithCacheTest, LoadProgramOnProgramCacheHit) { | 1742 TEST_F(ProgramManagerWithCacheTest, LoadProgramOnProgramCacheHit) { |
| 1743 SetShadersCompiled(); | 1743 SetShadersCompiled(); |
| 1744 SetProgramCached(); | 1744 SetProgramCached(); |
| 1745 | 1745 |
| 1746 SetExpectationsForNoCompile(vertex_shader_); | 1746 SetExpectationsForNoCompile(vertex_shader_); |
| 1747 SetExpectationsForNoCompile(fragment_shader_); | 1747 SetExpectationsForNoCompile(fragment_shader_); |
| 1748 SetExpectationsForProgramLoad(ProgramCache::PROGRAM_LOAD_SUCCESS); | 1748 SetExpectationsForProgramLoad(ProgramCache::PROGRAM_LOAD_SUCCESS); |
| 1749 SetExpectationsForNotCachingProgram(); | 1749 SetExpectationsForNotCachingProgram(); |
| 1750 SetExpectationsForProgramLoadSuccess(); | 1750 SetExpectationsForProgramLoadSuccess(); |
| 1751 | 1751 |
| 1752 EXPECT_TRUE(program_->Link(NULL, NULL, NULL, | 1752 EXPECT_TRUE(program_->Link(NULL, NULL, NULL, NULL, |
| 1753 base::Bind(&ShaderCacheCb))); | 1753 base::Bind(&ShaderCacheCb))); |
| 1754 } | 1754 } |
| 1755 | 1755 |
| 1756 } // namespace gles2 | 1756 } // namespace gles2 |
| 1757 } // namespace gpu | 1757 } // namespace gpu |
| OLD | NEW |