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

Side by Side Diff: gpu/command_buffer/service/program_manager_unittest.cc

Issue 10568003: Add support for GL_CHROMIUM_consistent_uniform_locations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "gpu/command_buffer/common/gl_mock.h" 12 #include "gpu/command_buffer/common/gl_mock.h"
13 #include "gpu/command_buffer/common/gles2_cmd_format.h" 13 #include "gpu/command_buffer/common/gles2_cmd_format.h"
14 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
14 #include "gpu/command_buffer/service/common_decoder.h" 15 #include "gpu/command_buffer/service/common_decoder.h"
15 #include "gpu/command_buffer/service/mocks.h" 16 #include "gpu/command_buffer/service/mocks.h"
16 #include "gpu/command_buffer/service/test_helper.h" 17 #include "gpu/command_buffer/service/test_helper.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 using ::gfx::MockGLInterface; 20 using ::gfx::MockGLInterface;
20 using ::testing::_; 21 using ::testing::_;
21 using ::testing::DoAll; 22 using ::testing::DoAll;
22 using ::testing::InSequence; 23 using ::testing::InSequence;
23 using ::testing::MatcherCast; 24 using ::testing::MatcherCast;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 kClient1Id, kService1Id); 124 kClient1Id, kService1Id);
124 ASSERT_TRUE(info1); 125 ASSERT_TRUE(info1);
125 EXPECT_EQ(kService1Id, info1->service_id()); 126 EXPECT_EQ(kService1Id, info1->service_id());
126 EXPECT_FALSE(info1->InUse()); 127 EXPECT_FALSE(info1->InUse());
127 EXPECT_FALSE(info1->IsValid()); 128 EXPECT_FALSE(info1->IsValid());
128 EXPECT_FALSE(info1->IsDeleted()); 129 EXPECT_FALSE(info1->IsDeleted());
129 EXPECT_FALSE(info1->CanLink()); 130 EXPECT_FALSE(info1->CanLink());
130 EXPECT_TRUE(info1->log_info() == NULL); 131 EXPECT_TRUE(info1->log_info() == NULL);
131 } 132 }
132 133
133 TEST_F(ProgramManagerTest, SwizzleLocation) {
134 GLint power = 1;
135 for (GLint p = 0; p < 5; ++p, power *= 10) {
136 GLint limit = power * 20 + 1;
137 for (GLint ii = -limit; ii < limit; ii += power) {
138 GLint s = manager_.SwizzleLocation(ii);
139 EXPECT_EQ(ii, manager_.UnswizzleLocation(s));
140 }
141 }
142 }
143
144 class ProgramManagerWithShaderTest : public testing::Test { 134 class ProgramManagerWithShaderTest : public testing::Test {
145 public: 135 public:
146 ProgramManagerWithShaderTest() 136 ProgramManagerWithShaderTest()
147 : program_info_(NULL) { 137 : program_info_(NULL) {
148 } 138 }
149 139
150 ~ProgramManagerWithShaderTest() { 140 ~ProgramManagerWithShaderTest() {
151 manager_.Destroy(false); 141 manager_.Destroy(false);
152 shader_manager_.Destroy(false); 142 shader_manager_.Destroy(false);
153 } 143 }
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 program_info->GetUniformFakeLocation(kUniform3BadName)); 476 program_info->GetUniformFakeLocation(kUniform3BadName));
487 // Check we can get uniform2 as "uniform2" even though the name is 477 // Check we can get uniform2 as "uniform2" even though the name is
488 // "uniform2[0]" 478 // "uniform2[0]"
489 EXPECT_EQ(kUniform2FakeLocation, 479 EXPECT_EQ(kUniform2FakeLocation,
490 program_info->GetUniformFakeLocation("uniform2")); 480 program_info->GetUniformFakeLocation("uniform2"));
491 // Check we can get uniform3 as "uniform3[0]" even though we simulated GL 481 // Check we can get uniform3 as "uniform3[0]" even though we simulated GL
492 // returning "uniform3" 482 // returning "uniform3"
493 EXPECT_EQ(kUniform3FakeLocation, 483 EXPECT_EQ(kUniform3FakeLocation,
494 program_info->GetUniformFakeLocation(kUniform3GoodName)); 484 program_info->GetUniformFakeLocation(kUniform3GoodName));
495 // Check that we can get the locations of the array elements > 1 485 // Check that we can get the locations of the array elements > 1
496 EXPECT_EQ(ProgramManager::ProgramInfo::GetFakeLocation( 486 EXPECT_EQ(GLES2Util::MakeFakeLocation(kUniform2FakeLocation, 1),
497 kUniform2FakeLocation, 1),
498 program_info->GetUniformFakeLocation("uniform2[1]")); 487 program_info->GetUniformFakeLocation("uniform2[1]"));
499 EXPECT_EQ(ProgramManager::ProgramInfo::GetFakeLocation( 488 EXPECT_EQ(GLES2Util::MakeFakeLocation(kUniform2FakeLocation, 2),
500 kUniform2FakeLocation, 2),
501 program_info->GetUniformFakeLocation("uniform2[2]")); 489 program_info->GetUniformFakeLocation("uniform2[2]"));
502 EXPECT_EQ(-1, program_info->GetUniformFakeLocation("uniform2[3]")); 490 EXPECT_EQ(-1, program_info->GetUniformFakeLocation("uniform2[3]"));
503 EXPECT_EQ(ProgramManager::ProgramInfo::GetFakeLocation( 491 EXPECT_EQ(GLES2Util::MakeFakeLocation(kUniform3FakeLocation, 1),
504 kUniform3FakeLocation, 1),
505 program_info->GetUniformFakeLocation("uniform3[1]")); 492 program_info->GetUniformFakeLocation("uniform3[1]"));
506 EXPECT_EQ(-1, program_info->GetUniformFakeLocation("uniform3[2]")); 493 EXPECT_EQ(-1, program_info->GetUniformFakeLocation("uniform3[2]"));
507 } 494 }
508 495
509 TEST_F(ProgramManagerWithShaderTest, GetUniformInfoByFakeLocation) { 496 TEST_F(ProgramManagerWithShaderTest, GetUniformInfoByFakeLocation) {
510 const GLint kInvalidLocation = 1234; 497 const GLint kInvalidLocation = 1234;
511 const ProgramManager::ProgramInfo::UniformInfo* info; 498 const ProgramManager::ProgramInfo::UniformInfo* info;
512 const ProgramManager::ProgramInfo* program_info = 499 const ProgramManager::ProgramInfo* program_info =
513 manager_.GetProgramInfo(kClientProgramId); 500 manager_.GetProgramInfo(kClientProgramId);
514 GLint real_location = -1; 501 GLint real_location = -1;
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 } 828 }
842 // TODO(gman): Don't assume these are in order. 829 // TODO(gman): Don't assume these are in order.
843 for (uint32 ii = 0; ii < header->num_uniforms; ++ii) { 830 for (uint32 ii = 0; ii < header->num_uniforms; ++ii) {
844 const UniformInfo& expected = kUniforms[ii]; 831 const UniformInfo& expected = kUniforms[ii];
845 EXPECT_EQ(expected.size, input->size); 832 EXPECT_EQ(expected.size, input->size);
846 EXPECT_EQ(expected.type, input->type); 833 EXPECT_EQ(expected.type, input->type);
847 const int32* locations = bucket.GetDataAs<const int32*>( 834 const int32* locations = bucket.GetDataAs<const int32*>(
848 input->location_offset, sizeof(int32) * input->size); 835 input->location_offset, sizeof(int32) * input->size);
849 ASSERT_TRUE(locations != NULL); 836 ASSERT_TRUE(locations != NULL);
850 for (int32 jj = 0; jj < input->size; ++jj) { 837 for (int32 jj = 0; jj < input->size; ++jj) {
851 EXPECT_EQ(manager_.SwizzleLocation( 838 EXPECT_EQ(GLES2Util::SwizzleLocation(
852 ProgramManager::ProgramInfo::GetFakeLocation( 839 GLES2Util::MakeFakeLocation(expected.fake_location, jj)),
853 expected.fake_location, jj)),
854 locations[jj]); 840 locations[jj]);
855 } 841 }
856 const char* name_buf = bucket.GetDataAs<const char*>( 842 const char* name_buf = bucket.GetDataAs<const char*>(
857 input->name_offset, input->name_length); 843 input->name_offset, input->name_length);
858 ASSERT_TRUE(name_buf != NULL); 844 ASSERT_TRUE(name_buf != NULL);
859 std::string name(name_buf, input->name_length); 845 std::string name(name_buf, input->name_length);
860 EXPECT_STREQ(expected.good_name, name.c_str()); 846 EXPECT_STREQ(expected.good_name, name.c_str());
861 ++input; 847 ++input;
862 } 848 }
863 EXPECT_EQ(header->num_attribs + header->num_uniforms, 849 EXPECT_EQ(header->num_attribs + header->num_uniforms,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 const size_t kNumAttribs = arraysize(kAttribs); 978 const size_t kNumAttribs = arraysize(kAttribs);
993 const size_t kNumUniforms = arraysize(kUniforms); 979 const size_t kNumUniforms = arraysize(kUniforms);
994 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, 980 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms,
995 kServiceProgramId); 981 kServiceProgramId);
996 program_info->Link(); 982 program_info->Link();
997 SetupExpectationsForClearingUniforms(kUniforms, kNumUniforms); 983 SetupExpectationsForClearingUniforms(kUniforms, kNumUniforms);
998 manager_.ClearUniforms(program_info); 984 manager_.ClearUniforms(program_info);
999 } 985 }
1000 } 986 }
1001 987
988 TEST_F(ProgramManagerWithShaderTest, UniformsAreSorted) {
989 const GLuint kVShaderClientId = 2001;
990 const GLuint kFShaderClientId = 2002;
991 const GLuint kVShaderServiceId = 3001;
992 const GLuint kFShaderServiceId = 3002;
993 ShaderManager::ShaderInfo* vshader = shader_manager_.CreateShaderInfo(
994 kVShaderClientId, kVShaderServiceId, GL_VERTEX_SHADER);
995 ASSERT_TRUE(vshader != NULL);
996 vshader->SetStatus(true, "", NULL);
997 ShaderManager::ShaderInfo* fshader = shader_manager_.CreateShaderInfo(
998 kFShaderClientId, kFShaderServiceId, GL_FRAGMENT_SHADER);
999 ASSERT_TRUE(fshader != NULL);
1000 fshader->SetStatus(true, "", NULL);
1001 static ProgramManagerWithShaderTest::AttribInfo kAttribs[] = {
1002 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
1003 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
1004 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
1005 };
1006 static ProgramManagerWithShaderTest::UniformInfo kUniforms[] = {
1007 { kUniform2Name,
1008 kUniform2Size,
1009 kUniform2Type,
1010 kUniform2FakeLocation,
1011 kUniform2RealLocation,
1012 kUniform2Name,
1013 },
1014 { kUniform3GoodName,
1015 kUniform3Size,
1016 kUniform3Type,
1017 kUniform3FakeLocation,
1018 kUniform3RealLocation,
1019 kUniform3GoodName,
1020 },
1021 { kUniform1Name,
1022 kUniform1Size,
1023 kUniform1Type,
1024 kUniform1FakeLocation,
1025 kUniform1RealLocation,
1026 kUniform1Name,
1027 },
1028 };
1029 const size_t kNumAttribs= arraysize(kAttribs);
1030 const size_t kNumUniforms = arraysize(kUniforms);
1031 static const GLuint kClientProgramId = 1234;
1032 static const GLuint kServiceProgramId = 5679;
1033 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms,
1034 kServiceProgramId);
1035 ProgramManager::ProgramInfo* program_info = manager_.CreateProgramInfo(
1036 kClientProgramId, kServiceProgramId);
1037 ASSERT_TRUE(program_info != NULL);
1038 EXPECT_TRUE(program_info->AttachShader(&shader_manager_, vshader));
1039 EXPECT_TRUE(program_info->AttachShader(&shader_manager_, fshader));
1040 program_info->Link();
1041 // Check Uniforms
1042 const ProgramManager::ProgramInfo::UniformInfo* uniform_info =
1043 program_info->GetUniformInfo(0);
1044 ASSERT_TRUE(uniform_info != NULL);
1045 EXPECT_STREQ(kUniform1Name, uniform_info->name.c_str());
1046 EXPECT_EQ(0, uniform_info->fake_location_base);
1047 uniform_info = program_info->GetUniformInfo(1);
1048 ASSERT_TRUE(uniform_info != NULL);
1049 EXPECT_STREQ(kUniform2Name, uniform_info->name.c_str());
1050 EXPECT_EQ(1, uniform_info->fake_location_base);
1051 uniform_info = program_info->GetUniformInfo(2);
1052 ASSERT_TRUE(uniform_info != NULL);
1053 EXPECT_STREQ(kUniform3GoodName, uniform_info->name.c_str());
1054 EXPECT_EQ(2, uniform_info->fake_location_base);
1055 }
1056
1002 } // namespace gles2 1057 } // namespace gles2
1003 } // namespace gpu 1058 } // namespace gpu
1004 1059
1005 1060
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/program_manager.cc ('k') | gpu/command_buffer/service/test_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698