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/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/common/gles2_cmd_utils.h" |
15 #include "gpu/command_buffer/service/common_decoder.h" | 15 #include "gpu/command_buffer/service/common_decoder.h" |
| 16 #include "gpu/command_buffer/service/feature_info.h" |
16 #include "gpu/command_buffer/service/mocks.h" | 17 #include "gpu/command_buffer/service/mocks.h" |
17 #include "gpu/command_buffer/service/test_helper.h" | 18 #include "gpu/command_buffer/service/test_helper.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 using ::gfx::MockGLInterface; | 21 using ::gfx::MockGLInterface; |
21 using ::testing::_; | 22 using ::testing::_; |
22 using ::testing::DoAll; | 23 using ::testing::DoAll; |
23 using ::testing::InSequence; | 24 using ::testing::InSequence; |
24 using ::testing::MatcherCast; | 25 using ::testing::MatcherCast; |
25 using ::testing::Pointee; | 26 using ::testing::Pointee; |
26 using ::testing::Return; | 27 using ::testing::Return; |
27 using ::testing::ReturnRef; | 28 using ::testing::ReturnRef; |
28 using ::testing::SetArrayArgument; | 29 using ::testing::SetArrayArgument; |
29 using ::testing::SetArgumentPointee; | 30 using ::testing::SetArgumentPointee; |
30 using ::testing::StrEq; | 31 using ::testing::StrEq; |
31 using ::testing::StrictMock; | 32 using ::testing::StrictMock; |
32 | 33 |
33 namespace gpu { | 34 namespace gpu { |
34 namespace gles2 { | 35 namespace gles2 { |
35 | 36 |
36 class ProgramManagerTest : public testing::Test { | 37 class ProgramManagerTest : public testing::Test { |
37 public: | 38 public: |
38 ProgramManagerTest() { } | 39 ProgramManagerTest() : manager_(NULL) { } |
39 ~ProgramManagerTest() { | 40 ~ProgramManagerTest() { |
40 manager_.Destroy(false); | 41 manager_.Destroy(false); |
41 } | 42 } |
42 | 43 |
43 protected: | 44 protected: |
44 virtual void SetUp() { | 45 virtual void SetUp() { |
45 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); | 46 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
46 ::gfx::GLInterface::SetGLInterface(gl_.get()); | 47 ::gfx::GLInterface::SetGLInterface(gl_.get()); |
47 } | 48 } |
48 | 49 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 EXPECT_FALSE(info1->InUse()); | 128 EXPECT_FALSE(info1->InUse()); |
128 EXPECT_FALSE(info1->IsValid()); | 129 EXPECT_FALSE(info1->IsValid()); |
129 EXPECT_FALSE(info1->IsDeleted()); | 130 EXPECT_FALSE(info1->IsDeleted()); |
130 EXPECT_FALSE(info1->CanLink()); | 131 EXPECT_FALSE(info1->CanLink()); |
131 EXPECT_TRUE(info1->log_info() == NULL); | 132 EXPECT_TRUE(info1->log_info() == NULL); |
132 } | 133 } |
133 | 134 |
134 class ProgramManagerWithShaderTest : public testing::Test { | 135 class ProgramManagerWithShaderTest : public testing::Test { |
135 public: | 136 public: |
136 ProgramManagerWithShaderTest() | 137 ProgramManagerWithShaderTest() |
137 : program_info_(NULL) { | 138 : manager_(NULL), program_info_(NULL) { |
138 } | 139 } |
139 | 140 |
140 ~ProgramManagerWithShaderTest() { | 141 ~ProgramManagerWithShaderTest() { |
141 manager_.Destroy(false); | 142 manager_.Destroy(false); |
142 shader_manager_.Destroy(false); | 143 shader_manager_.Destroy(false); |
143 } | 144 } |
144 | 145 |
145 static const GLint kNumVertexAttribs = 16; | 146 static const GLint kNumVertexAttribs = 16; |
146 | 147 |
147 static const GLuint kClientProgramId = 123; | 148 static const GLuint kClientProgramId = 123; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 ASSERT_TRUE(fragment_shader != NULL); | 212 ASSERT_TRUE(fragment_shader != NULL); |
212 vertex_shader->SetStatus(true, NULL, NULL); | 213 vertex_shader->SetStatus(true, NULL, NULL); |
213 fragment_shader->SetStatus(true, NULL, NULL); | 214 fragment_shader->SetStatus(true, NULL, NULL); |
214 | 215 |
215 program_info_ = manager_.CreateProgramInfo( | 216 program_info_ = manager_.CreateProgramInfo( |
216 kClientProgramId, kServiceProgramId); | 217 kClientProgramId, kServiceProgramId); |
217 ASSERT_TRUE(program_info_ != NULL); | 218 ASSERT_TRUE(program_info_ != NULL); |
218 | 219 |
219 program_info_->AttachShader(&shader_manager_, vertex_shader); | 220 program_info_->AttachShader(&shader_manager_, vertex_shader); |
220 program_info_->AttachShader(&shader_manager_, fragment_shader); | 221 program_info_->AttachShader(&shader_manager_, fragment_shader); |
221 program_info_->Link(); | 222 program_info_->Link(NULL, NULL, NULL, NULL); |
222 } | 223 } |
223 | 224 |
224 void SetupShader(AttribInfo* attribs, size_t num_attribs, | 225 void SetupShader(AttribInfo* attribs, size_t num_attribs, |
225 UniformInfo* uniforms, size_t num_uniforms, | 226 UniformInfo* uniforms, size_t num_uniforms, |
226 GLuint service_id) { | 227 GLuint service_id) { |
227 TestHelper::SetupShader( | 228 TestHelper::SetupShader( |
228 gl_.get(), attribs, num_attribs, uniforms, num_uniforms, service_id); | 229 gl_.get(), attribs, num_attribs, uniforms, num_uniforms, service_id); |
229 } | 230 } |
230 | 231 |
231 void SetupDefaultShaderExpectations() { | 232 void SetupDefaultShaderExpectations() { |
(...skipping 12 matching lines...) Expand all Loading... |
244 } | 245 } |
245 | 246 |
246 // Return true if link status matches expected_link_status | 247 // Return true if link status matches expected_link_status |
247 bool LinkAsExpected(ProgramManager::ProgramInfo* program_info, | 248 bool LinkAsExpected(ProgramManager::ProgramInfo* program_info, |
248 bool expected_link_status) { | 249 bool expected_link_status) { |
249 GLuint service_id = program_info->service_id(); | 250 GLuint service_id = program_info->service_id(); |
250 if (expected_link_status) { | 251 if (expected_link_status) { |
251 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, | 252 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, |
252 service_id); | 253 service_id); |
253 } | 254 } |
254 program_info->Link(); | 255 program_info->Link(NULL, NULL, NULL, NULL); |
255 GLint link_status; | 256 GLint link_status; |
256 program_info->GetProgramiv(GL_LINK_STATUS, &link_status); | 257 program_info->GetProgramiv(GL_LINK_STATUS, &link_status); |
257 return (static_cast<bool>(link_status) == expected_link_status); | 258 return (static_cast<bool>(link_status) == expected_link_status); |
258 } | 259 } |
259 | 260 |
260 static AttribInfo kAttribs[]; | 261 static AttribInfo kAttribs[]; |
261 static UniformInfo kUniforms[]; | 262 static UniformInfo kUniforms[]; |
262 | 263 |
263 scoped_ptr<StrictMock<gfx::MockGLInterface> > gl_; | 264 scoped_ptr<StrictMock<gfx::MockGLInterface> > gl_; |
264 | 265 |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 vshader->SetStatus(true, "", NULL); | 578 vshader->SetStatus(true, "", NULL); |
578 ShaderManager::ShaderInfo* fshader = shader_manager_.CreateShaderInfo( | 579 ShaderManager::ShaderInfo* fshader = shader_manager_.CreateShaderInfo( |
579 kFShaderClientId, kFShaderServiceId, GL_FRAGMENT_SHADER); | 580 kFShaderClientId, kFShaderServiceId, GL_FRAGMENT_SHADER); |
580 ASSERT_TRUE(fshader != NULL); | 581 ASSERT_TRUE(fshader != NULL); |
581 fshader->SetStatus(true, "", NULL); | 582 fshader->SetStatus(true, "", NULL); |
582 ProgramManager::ProgramInfo* program_info = | 583 ProgramManager::ProgramInfo* program_info = |
583 manager_.CreateProgramInfo(kClientProgramId, kServiceProgramId); | 584 manager_.CreateProgramInfo(kClientProgramId, kServiceProgramId); |
584 ASSERT_TRUE(program_info != NULL); | 585 ASSERT_TRUE(program_info != NULL); |
585 EXPECT_TRUE(program_info->AttachShader(&shader_manager_, vshader)); | 586 EXPECT_TRUE(program_info->AttachShader(&shader_manager_, vshader)); |
586 EXPECT_TRUE(program_info->AttachShader(&shader_manager_, fshader)); | 587 EXPECT_TRUE(program_info->AttachShader(&shader_manager_, fshader)); |
587 program_info->Link(); | 588 program_info->Link(NULL, NULL, NULL, NULL); |
588 GLint value = 0; | 589 GLint value = 0; |
589 program_info->GetProgramiv(GL_ACTIVE_ATTRIBUTES, &value); | 590 program_info->GetProgramiv(GL_ACTIVE_ATTRIBUTES, &value); |
590 EXPECT_EQ(3, value); | 591 EXPECT_EQ(3, value); |
591 // Check that we skipped the "gl_" uniform. | 592 // Check that we skipped the "gl_" uniform. |
592 program_info->GetProgramiv(GL_ACTIVE_UNIFORMS, &value); | 593 program_info->GetProgramiv(GL_ACTIVE_UNIFORMS, &value); |
593 EXPECT_EQ(2, value); | 594 EXPECT_EQ(2, value); |
594 // Check that our max length adds room for the array spec and is not as long | 595 // Check that our max length adds room for the array spec and is not as long |
595 // as the "gl_" uniform we skipped. | 596 // as the "gl_" uniform we skipped. |
596 // +4u is to account for "gl_" and NULL terminator. | 597 // +4u is to account for "gl_" and NULL terminator. |
597 program_info->GetProgramiv(GL_ACTIVE_UNIFORM_MAX_LENGTH, &value); | 598 program_info->GetProgramiv(GL_ACTIVE_UNIFORM_MAX_LENGTH, &value); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 const size_t kNumUniforms = arraysize(kUniforms); | 672 const size_t kNumUniforms = arraysize(kUniforms); |
672 static const GLuint kClientProgramId = 1234; | 673 static const GLuint kClientProgramId = 1234; |
673 static const GLuint kServiceProgramId = 5679; | 674 static const GLuint kServiceProgramId = 5679; |
674 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, | 675 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, |
675 kServiceProgramId); | 676 kServiceProgramId); |
676 ProgramManager::ProgramInfo* program_info = manager_.CreateProgramInfo( | 677 ProgramManager::ProgramInfo* program_info = manager_.CreateProgramInfo( |
677 kClientProgramId, kServiceProgramId); | 678 kClientProgramId, kServiceProgramId); |
678 ASSERT_TRUE(program_info != NULL); | 679 ASSERT_TRUE(program_info != NULL); |
679 EXPECT_TRUE(program_info->AttachShader(&shader_manager_, vshader)); | 680 EXPECT_TRUE(program_info->AttachShader(&shader_manager_, vshader)); |
680 EXPECT_TRUE(program_info->AttachShader(&shader_manager_, fshader)); | 681 EXPECT_TRUE(program_info->AttachShader(&shader_manager_, fshader)); |
681 program_info->Link(); | 682 program_info->Link(NULL, NULL, NULL, NULL); |
682 // Check that we got the good type, not the bad. | 683 // Check that we got the good type, not the bad. |
683 // Check Attribs | 684 // Check Attribs |
684 for (unsigned index = 0; index < kNumAttribs; ++index) { | 685 for (unsigned index = 0; index < kNumAttribs; ++index) { |
685 const ProgramManager::ProgramInfo::VertexAttribInfo* attrib_info = | 686 const ProgramManager::ProgramInfo::VertexAttribInfo* attrib_info = |
686 program_info->GetAttribInfo(index); | 687 program_info->GetAttribInfo(index); |
687 ASSERT_TRUE(attrib_info != NULL); | 688 ASSERT_TRUE(attrib_info != NULL); |
688 ShaderTranslator::VariableMap::const_iterator it = attrib_map.find( | 689 ShaderTranslator::VariableMap::const_iterator it = attrib_map.find( |
689 attrib_info->name); | 690 attrib_info->name); |
690 ASSERT_TRUE(it != attrib_map.end()); | 691 ASSERT_TRUE(it != attrib_map.end()); |
691 EXPECT_EQ(it->first, attrib_info->name); | 692 EXPECT_EQ(it->first, attrib_info->name); |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 kUniform3FakeLocation, | 991 kUniform3FakeLocation, |
991 kUniform3RealLocation, | 992 kUniform3RealLocation, |
992 kUniform3DesiredLocation, | 993 kUniform3DesiredLocation, |
993 kUniform3GoodName, | 994 kUniform3GoodName, |
994 }, | 995 }, |
995 }; | 996 }; |
996 const size_t kNumAttribs = arraysize(kAttribs); | 997 const size_t kNumAttribs = arraysize(kAttribs); |
997 const size_t kNumUniforms = arraysize(kUniforms); | 998 const size_t kNumUniforms = arraysize(kUniforms); |
998 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, | 999 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, |
999 kServiceProgramId); | 1000 kServiceProgramId); |
1000 program_info->Link(); | 1001 program_info->Link(NULL, NULL, NULL, NULL); |
1001 SetupExpectationsForClearingUniforms(kUniforms, kNumUniforms); | 1002 SetupExpectationsForClearingUniforms(kUniforms, kNumUniforms); |
1002 manager_.ClearUniforms(program_info); | 1003 manager_.ClearUniforms(program_info); |
1003 } | 1004 } |
1004 } | 1005 } |
1005 | 1006 |
1006 TEST_F(ProgramManagerWithShaderTest, BindUniformLocation) { | 1007 TEST_F(ProgramManagerWithShaderTest, BindUniformLocation) { |
1007 const GLuint kVShaderClientId = 2001; | 1008 const GLuint kVShaderClientId = 2001; |
1008 const GLuint kFShaderClientId = 2002; | 1009 const GLuint kFShaderClientId = 2002; |
1009 const GLuint kVShaderServiceId = 3001; | 1010 const GLuint kVShaderServiceId = 3001; |
1010 const GLuint kFShaderServiceId = 3002; | 1011 const GLuint kFShaderServiceId = 3002; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 kUniform3RealLocation, | 1063 kUniform3RealLocation, |
1063 kUniform3DesiredLocation, | 1064 kUniform3DesiredLocation, |
1064 kUniform3GoodName, | 1065 kUniform3GoodName, |
1065 }, | 1066 }, |
1066 }; | 1067 }; |
1067 | 1068 |
1068 const size_t kNumAttribs = arraysize(kAttribs); | 1069 const size_t kNumAttribs = arraysize(kAttribs); |
1069 const size_t kNumUniforms = arraysize(kUniforms); | 1070 const size_t kNumUniforms = arraysize(kUniforms); |
1070 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, | 1071 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, |
1071 kServiceProgramId); | 1072 kServiceProgramId); |
1072 program_info->Link(); | 1073 program_info->Link(NULL, NULL, NULL, NULL); |
1073 | 1074 |
1074 EXPECT_EQ(kUniform1DesiredLocation, | 1075 EXPECT_EQ(kUniform1DesiredLocation, |
1075 program_info->GetUniformFakeLocation(kUniform1Name)); | 1076 program_info->GetUniformFakeLocation(kUniform1Name)); |
1076 EXPECT_EQ(kUniform3DesiredLocation, | 1077 EXPECT_EQ(kUniform3DesiredLocation, |
1077 program_info->GetUniformFakeLocation(kUniform3BadName)); | 1078 program_info->GetUniformFakeLocation(kUniform3BadName)); |
1078 EXPECT_EQ(kUniform3DesiredLocation, | 1079 EXPECT_EQ(kUniform3DesiredLocation, |
1079 program_info->GetUniformFakeLocation(kUniform3GoodName)); | 1080 program_info->GetUniformFakeLocation(kUniform3GoodName)); |
1080 } | 1081 } |
1081 | 1082 |
| 1083 class ProgramManagerWithCacheTest : public testing::Test { |
| 1084 public: |
| 1085 static const GLuint kClientProgramId = 1; |
| 1086 static const GLuint kServiceProgramId = 10; |
| 1087 static const GLuint kVertexShaderClientId = 2; |
| 1088 static const GLuint kFragmentShaderClientId = 20; |
| 1089 static const GLuint kVertexShaderServiceId = 3; |
| 1090 static const GLuint kFragmentShaderServiceId = 30; |
| 1091 |
| 1092 ProgramManagerWithCacheTest() |
| 1093 : cache_(new MockProgramCache()), |
| 1094 manager_(cache_.get()), |
| 1095 vertex_shader_(NULL), |
| 1096 fragment_shader_(NULL), |
| 1097 program_info_(NULL) { |
| 1098 } |
| 1099 ~ProgramManagerWithCacheTest() { |
| 1100 manager_.Destroy(false); |
| 1101 shader_manager_.Destroy(false); |
| 1102 } |
| 1103 |
| 1104 protected: |
| 1105 virtual void SetUp() { |
| 1106 gl_.reset(new StrictMock<gfx::MockGLInterface>()); |
| 1107 ::gfx::GLInterface::SetGLInterface(gl_.get()); |
| 1108 |
| 1109 vertex_shader_ = shader_manager_.CreateShaderInfo( |
| 1110 kVertexShaderClientId, kVertexShaderServiceId, GL_VERTEX_SHADER); |
| 1111 fragment_shader_ = shader_manager_.CreateShaderInfo( |
| 1112 kFragmentShaderClientId, kFragmentShaderServiceId, GL_FRAGMENT_SHADER); |
| 1113 ASSERT_TRUE(vertex_shader_ != NULL); |
| 1114 ASSERT_TRUE(fragment_shader_ != NULL); |
| 1115 vertex_shader_->UpdateSource("lka asjf bjajsdfj"); |
| 1116 fragment_shader_->UpdateSource("lka asjf a fasgag 3rdsf3 bjajsdfj"); |
| 1117 |
| 1118 program_info_ = manager_.CreateProgramInfo( |
| 1119 kClientProgramId, kServiceProgramId); |
| 1120 ASSERT_TRUE(program_info_ != NULL); |
| 1121 |
| 1122 program_info_->AttachShader(&shader_manager_, vertex_shader_); |
| 1123 program_info_->AttachShader(&shader_manager_, fragment_shader_); |
| 1124 } |
| 1125 |
| 1126 virtual void TearDown() { |
| 1127 ::gfx::GLInterface::SetGLInterface(NULL); |
| 1128 } |
| 1129 |
| 1130 void SetShadersCompiled() { |
| 1131 cache_->ShaderCompilationSucceeded(*vertex_shader_->source()); |
| 1132 cache_->ShaderCompilationSucceeded(*fragment_shader_->source()); |
| 1133 vertex_shader_->SetStatus(true, NULL, NULL); |
| 1134 fragment_shader_->SetStatus(true, NULL, NULL); |
| 1135 vertex_shader_->FlagSourceAsCompiled(true); |
| 1136 fragment_shader_->FlagSourceAsCompiled(true); |
| 1137 } |
| 1138 |
| 1139 void SetShadersNotCompiledButCached() { |
| 1140 SetShadersCompiled(); |
| 1141 vertex_shader_->FlagSourceAsCompiled(false); |
| 1142 fragment_shader_->FlagSourceAsCompiled(false); |
| 1143 } |
| 1144 |
| 1145 void SetProgramCached() { |
| 1146 cache_->LinkedProgramCacheSuccess( |
| 1147 vertex_shader_->source()->c_str(), |
| 1148 fragment_shader_->source()->c_str(), |
| 1149 &program_info_->bind_attrib_location_map()); |
| 1150 } |
| 1151 |
| 1152 void SetExpectationsForProgramCached() { |
| 1153 SetExpectationsForProgramCached(program_info_, |
| 1154 vertex_shader_, |
| 1155 fragment_shader_); |
| 1156 } |
| 1157 |
| 1158 void SetExpectationsForProgramCached( |
| 1159 ProgramManager::ProgramInfo* program_info, |
| 1160 ShaderManager::ShaderInfo* vertex_shader, |
| 1161 ShaderManager::ShaderInfo* fragment_shader) { |
| 1162 EXPECT_CALL(*cache_.get(), SaveLinkedProgram( |
| 1163 program_info->service_id(), |
| 1164 vertex_shader, |
| 1165 fragment_shader, |
| 1166 &program_info->bind_attrib_location_map())).Times(1); |
| 1167 } |
| 1168 |
| 1169 void SetExpectationsForNotCachingProgram() { |
| 1170 SetExpectationsForNotCachingProgram(program_info_, |
| 1171 vertex_shader_, |
| 1172 fragment_shader_); |
| 1173 } |
| 1174 |
| 1175 void SetExpectationsForNotCachingProgram( |
| 1176 ProgramManager::ProgramInfo* program_info, |
| 1177 ShaderManager::ShaderInfo* vertex_shader, |
| 1178 ShaderManager::ShaderInfo* fragment_shader) { |
| 1179 EXPECT_CALL(*cache_.get(), SaveLinkedProgram( |
| 1180 program_info->service_id(), |
| 1181 vertex_shader, |
| 1182 fragment_shader, |
| 1183 &program_info->bind_attrib_location_map())).Times(0); |
| 1184 } |
| 1185 |
| 1186 void SetExpectationsForProgramLoad(ProgramCache::ProgramLoadResult result) { |
| 1187 SetExpectationsForProgramLoad(kServiceProgramId, |
| 1188 program_info_, |
| 1189 vertex_shader_, |
| 1190 fragment_shader_, |
| 1191 result); |
| 1192 } |
| 1193 |
| 1194 void SetExpectationsForProgramLoad( |
| 1195 GLuint service_program_id, |
| 1196 ProgramManager::ProgramInfo* program_info, |
| 1197 ShaderManager::ShaderInfo* vertex_shader, |
| 1198 ShaderManager::ShaderInfo* fragment_shader, |
| 1199 ProgramCache::ProgramLoadResult result) { |
| 1200 EXPECT_CALL(*cache_.get(), |
| 1201 LoadLinkedProgram(service_program_id, |
| 1202 vertex_shader, |
| 1203 fragment_shader, |
| 1204 &program_info->bind_attrib_location_map())) |
| 1205 .WillOnce(Return(result)); |
| 1206 } |
| 1207 |
| 1208 void SetExpectationsForProgramLoadSuccess() { |
| 1209 SetExpectationsForProgramLoadSuccess(kServiceProgramId); |
| 1210 } |
| 1211 |
| 1212 void SetExpectationsForProgramLoadSuccess(GLuint service_program_id) { |
| 1213 TestHelper::SetupProgramSuccessExpectations(gl_.get(), |
| 1214 NULL, |
| 1215 0, |
| 1216 NULL, |
| 1217 0, |
| 1218 service_program_id); |
| 1219 } |
| 1220 |
| 1221 void SetExpectationsForProgramLink() { |
| 1222 SetExpectationsForProgramLink(kServiceProgramId); |
| 1223 } |
| 1224 |
| 1225 void SetExpectationsForProgramLink(GLuint service_program_id) { |
| 1226 TestHelper::SetupShader(gl_.get(), NULL, 0, NULL, 0, service_program_id); |
| 1227 if (gfx::g_GL_ARB_get_program_binary) { |
| 1228 EXPECT_CALL(*gl_.get(), |
| 1229 ProgramParameteri(service_program_id, |
| 1230 PROGRAM_BINARY_RETRIEVABLE_HINT, |
| 1231 GL_TRUE)).Times(1); |
| 1232 } |
| 1233 } |
| 1234 |
| 1235 void SetExpectationsForSuccessCompile( |
| 1236 const ShaderManager::ShaderInfo* shader) { |
| 1237 const GLuint shader_id = shader->service_id(); |
| 1238 const char* src = shader->source()->c_str(); |
| 1239 EXPECT_CALL(*gl_.get(), |
| 1240 ShaderSource(shader_id, 1, Pointee(src), NULL)).Times(1); |
| 1241 EXPECT_CALL(*gl_.get(), CompileShader(shader_id)).Times(1); |
| 1242 EXPECT_CALL(*gl_.get(), GetShaderiv(shader_id, GL_COMPILE_STATUS, _)) |
| 1243 .WillOnce(SetArgumentPointee<2>(GL_TRUE)); |
| 1244 } |
| 1245 |
| 1246 void SetExpectationsForNoCompile(const ShaderManager::ShaderInfo* shader) { |
| 1247 const GLuint shader_id = shader->service_id(); |
| 1248 const char* src = shader->source()->c_str(); |
| 1249 EXPECT_CALL(*gl_.get(), |
| 1250 ShaderSource(shader_id, 1, Pointee(src), NULL)).Times(0); |
| 1251 EXPECT_CALL(*gl_.get(), CompileShader(shader_id)).Times(0); |
| 1252 EXPECT_CALL(*gl_.get(), GetShaderiv(shader_id, GL_COMPILE_STATUS, _)) |
| 1253 .Times(0); |
| 1254 } |
| 1255 |
| 1256 void SetExpectationsForErrorCompile(const ShaderManager::ShaderInfo* shader) { |
| 1257 const GLuint shader_id = shader->service_id(); |
| 1258 const char* src = shader->source()->c_str(); |
| 1259 EXPECT_CALL(*gl_.get(), |
| 1260 ShaderSource(shader_id, 1, Pointee(src), NULL)).Times(1); |
| 1261 EXPECT_CALL(*gl_.get(), CompileShader(shader_id)).Times(1); |
| 1262 EXPECT_CALL(*gl_.get(), GetShaderiv(shader_id, GL_COMPILE_STATUS, _)) |
| 1263 .WillOnce(SetArgumentPointee<2>(GL_FALSE)); |
| 1264 EXPECT_CALL(*gl_.get(), GetShaderiv(shader_id, GL_INFO_LOG_LENGTH, _)) |
| 1265 .WillOnce(SetArgumentPointee<2>(0)); |
| 1266 EXPECT_CALL(*gl_.get(), GetShaderInfoLog(shader_id, 0, _, _)) |
| 1267 .Times(1); |
| 1268 } |
| 1269 |
| 1270 scoped_ptr<StrictMock<gfx::MockGLInterface> > gl_; |
| 1271 |
| 1272 scoped_ptr<MockProgramCache> cache_; |
| 1273 ProgramManager manager_; |
| 1274 |
| 1275 ShaderManager::ShaderInfo* vertex_shader_; |
| 1276 ShaderManager::ShaderInfo* fragment_shader_; |
| 1277 ProgramManager::ProgramInfo* program_info_; |
| 1278 ShaderManager shader_manager_; |
| 1279 }; |
| 1280 |
| 1281 // GCC requires these declarations, but MSVC requires they not be present |
| 1282 #ifndef COMPILER_MSVC |
| 1283 const GLuint ProgramManagerWithCacheTest::kClientProgramId; |
| 1284 const GLuint ProgramManagerWithCacheTest::kServiceProgramId; |
| 1285 const GLuint ProgramManagerWithCacheTest::kVertexShaderClientId; |
| 1286 const GLuint ProgramManagerWithCacheTest::kFragmentShaderClientId; |
| 1287 const GLuint ProgramManagerWithCacheTest::kVertexShaderServiceId; |
| 1288 const GLuint ProgramManagerWithCacheTest::kFragmentShaderServiceId; |
| 1289 #endif |
| 1290 |
| 1291 TEST_F(ProgramManagerWithCacheTest, CacheSuccessAfterShaderCompile) { |
| 1292 SetExpectationsForSuccessCompile(vertex_shader_); |
| 1293 FeatureInfo::Ref info(new FeatureInfo()); |
| 1294 manager_.DoCompileShader(vertex_shader_, NULL, info.get()); |
| 1295 EXPECT_EQ(ProgramCache::COMPILATION_SUCCEEDED, |
| 1296 cache_->GetShaderCompilationStatus(*vertex_shader_->source())); |
| 1297 } |
| 1298 |
| 1299 TEST_F(ProgramManagerWithCacheTest, CacheUnknownAfterShaderError) { |
| 1300 SetExpectationsForErrorCompile(vertex_shader_); |
| 1301 FeatureInfo::Ref info(new FeatureInfo()); |
| 1302 manager_.DoCompileShader(vertex_shader_, NULL, info.get()); |
| 1303 EXPECT_EQ(ProgramCache::COMPILATION_UNKNOWN, |
| 1304 cache_->GetShaderCompilationStatus(*vertex_shader_->source())); |
| 1305 } |
| 1306 |
| 1307 TEST_F(ProgramManagerWithCacheTest, NoCompileWhenShaderCached) { |
| 1308 cache_->ShaderCompilationSucceeded(vertex_shader_->source()->c_str()); |
| 1309 SetExpectationsForNoCompile(vertex_shader_); |
| 1310 FeatureInfo::Ref info(new FeatureInfo()); |
| 1311 manager_.DoCompileShader(vertex_shader_, NULL, info.get()); |
| 1312 } |
| 1313 |
| 1314 TEST_F(ProgramManagerWithCacheTest, CacheProgramOnSuccessfulLink) { |
| 1315 SetShadersCompiled(); |
| 1316 SetExpectationsForProgramLink(); |
| 1317 SetExpectationsForProgramCached(); |
| 1318 EXPECT_TRUE(program_info_->Link(NULL, NULL, NULL, NULL)); |
| 1319 } |
| 1320 |
| 1321 TEST_F(ProgramManagerWithCacheTest, CompileShaderOnLinkCacheMiss) { |
| 1322 SetShadersCompiled(); |
| 1323 vertex_shader_->FlagSourceAsCompiled(false); |
| 1324 |
| 1325 FeatureInfo::Ref info(new FeatureInfo()); |
| 1326 |
| 1327 SetExpectationsForSuccessCompile(vertex_shader_); |
| 1328 SetExpectationsForProgramLink(); |
| 1329 SetExpectationsForProgramCached(); |
| 1330 EXPECT_TRUE(program_info_->Link(&shader_manager_, NULL, NULL, info.get())); |
| 1331 } |
| 1332 |
| 1333 TEST_F(ProgramManagerWithCacheTest, LoadProgramOnProgramCacheHit) { |
| 1334 SetShadersNotCompiledButCached(); |
| 1335 SetProgramCached(); |
| 1336 |
| 1337 SetExpectationsForNoCompile(vertex_shader_); |
| 1338 SetExpectationsForNoCompile(fragment_shader_); |
| 1339 SetExpectationsForProgramLoad(ProgramCache::PROGRAM_LOAD_SUCCESS); |
| 1340 SetExpectationsForNotCachingProgram(); |
| 1341 SetExpectationsForProgramLoadSuccess(); |
| 1342 |
| 1343 EXPECT_TRUE(program_info_->Link(NULL, NULL, NULL, NULL)); |
| 1344 } |
| 1345 |
| 1346 TEST_F(ProgramManagerWithCacheTest, CompileAndLinkOnProgramCacheError) { |
| 1347 SetShadersNotCompiledButCached(); |
| 1348 SetProgramCached(); |
| 1349 |
| 1350 SetExpectationsForSuccessCompile(vertex_shader_); |
| 1351 SetExpectationsForSuccessCompile(fragment_shader_); |
| 1352 SetExpectationsForProgramLoad(ProgramCache::PROGRAM_LOAD_FAILURE); |
| 1353 SetExpectationsForProgramLink(); |
| 1354 SetExpectationsForProgramCached(); |
| 1355 |
| 1356 FeatureInfo::Ref info(new FeatureInfo()); |
| 1357 EXPECT_TRUE(program_info_->Link(&shader_manager_, NULL, NULL, info.get())); |
| 1358 } |
| 1359 |
| 1360 TEST_F(ProgramManagerWithCacheTest, CorrectCompileOnSourceChangeNoCompile) { |
| 1361 SetShadersNotCompiledButCached(); |
| 1362 SetProgramCached(); |
| 1363 |
| 1364 const GLuint kNewShaderClientId = 4; |
| 1365 const GLuint kNewShaderServiceId = 40; |
| 1366 const GLuint kNewProgramClientId = 5; |
| 1367 const GLuint kNewProgramServiceId = 50; |
| 1368 |
| 1369 ShaderManager::ShaderInfo* new_vertex_shader = |
| 1370 shader_manager_.CreateShaderInfo(kNewShaderClientId, |
| 1371 kNewShaderServiceId, |
| 1372 GL_VERTEX_SHADER); |
| 1373 |
| 1374 const std::string original_source = *vertex_shader_->source(); |
| 1375 new_vertex_shader->UpdateSource(original_source.c_str()); |
| 1376 |
| 1377 ProgramManager::ProgramInfo* program_info = manager_.CreateProgramInfo( |
| 1378 kNewProgramClientId, kNewProgramServiceId); |
| 1379 ASSERT_TRUE(program_info != NULL); |
| 1380 program_info->AttachShader(&shader_manager_, new_vertex_shader); |
| 1381 program_info->AttachShader(&shader_manager_, fragment_shader_); |
| 1382 |
| 1383 SetExpectationsForNoCompile(new_vertex_shader); |
| 1384 |
| 1385 manager_.DoCompileShader(new_vertex_shader, NULL, NULL); |
| 1386 |
| 1387 new_vertex_shader->UpdateSource("different!"); |
| 1388 EXPECT_EQ(original_source, |
| 1389 *new_vertex_shader->deferred_compilation_source()); |
| 1390 |
| 1391 EXPECT_FALSE(new_vertex_shader->source_compiled()); |
| 1392 EXPECT_FALSE(fragment_shader_->source_compiled()); |
| 1393 |
| 1394 SetExpectationsForNoCompile(fragment_shader_); |
| 1395 SetExpectationsForNotCachingProgram(program_info, |
| 1396 new_vertex_shader, |
| 1397 fragment_shader_); |
| 1398 SetExpectationsForProgramLoad(kNewProgramServiceId, |
| 1399 program_info, |
| 1400 new_vertex_shader, |
| 1401 fragment_shader_, |
| 1402 ProgramCache::PROGRAM_LOAD_SUCCESS); |
| 1403 SetExpectationsForProgramLoadSuccess(kNewProgramServiceId); |
| 1404 |
| 1405 FeatureInfo::Ref info(new FeatureInfo()); |
| 1406 EXPECT_TRUE(program_info->Link(&shader_manager_, NULL, NULL, info.get())); |
| 1407 } |
| 1408 |
| 1409 TEST_F(ProgramManagerWithCacheTest, CorrectCompileOnSourceChangeWithCompile) { |
| 1410 SetShadersNotCompiledButCached(); |
| 1411 SetProgramCached(); |
| 1412 |
| 1413 const GLuint kNewShaderClientId = 4; |
| 1414 const GLuint kNewShaderServiceId = 40; |
| 1415 const GLuint kNewProgramClientId = 5; |
| 1416 const GLuint kNewProgramServiceId = 50; |
| 1417 |
| 1418 ShaderManager::ShaderInfo* new_vertex_shader = |
| 1419 shader_manager_.CreateShaderInfo(kNewShaderClientId, |
| 1420 kNewShaderServiceId, |
| 1421 GL_VERTEX_SHADER); |
| 1422 |
| 1423 new_vertex_shader->UpdateSource(vertex_shader_->source()->c_str()); |
| 1424 |
| 1425 ProgramManager::ProgramInfo* program_info = manager_.CreateProgramInfo( |
| 1426 kNewProgramClientId, kNewProgramServiceId); |
| 1427 ASSERT_TRUE(program_info != NULL); |
| 1428 program_info->AttachShader(&shader_manager_, new_vertex_shader); |
| 1429 program_info->AttachShader(&shader_manager_, fragment_shader_); |
| 1430 |
| 1431 SetExpectationsForNoCompile(new_vertex_shader); |
| 1432 |
| 1433 manager_.DoCompileShader(new_vertex_shader, NULL, NULL); |
| 1434 |
| 1435 const std::string differentSource = "different!"; |
| 1436 new_vertex_shader->UpdateSource(differentSource.c_str()); |
| 1437 SetExpectationsForSuccessCompile(new_vertex_shader); |
| 1438 |
| 1439 FeatureInfo::Ref info(new FeatureInfo()); |
| 1440 manager_.DoCompileShader(new_vertex_shader, NULL, info.get()); |
| 1441 EXPECT_EQ(differentSource, |
| 1442 *new_vertex_shader->deferred_compilation_source()); |
| 1443 |
| 1444 EXPECT_TRUE(new_vertex_shader->source_compiled()); |
| 1445 EXPECT_FALSE(fragment_shader_->source_compiled()); |
| 1446 |
| 1447 // so we don't recompile because we were pending originally |
| 1448 SetExpectationsForNoCompile(new_vertex_shader); |
| 1449 SetExpectationsForSuccessCompile(fragment_shader_); |
| 1450 SetExpectationsForProgramCached(program_info, |
| 1451 new_vertex_shader, |
| 1452 fragment_shader_); |
| 1453 SetExpectationsForProgramLink(kNewProgramServiceId); |
| 1454 |
| 1455 EXPECT_TRUE(program_info->Link(&shader_manager_, NULL, NULL, info.get())); |
| 1456 } |
| 1457 |
1082 } // namespace gles2 | 1458 } // namespace gles2 |
1083 } // namespace gpu | 1459 } // namespace gpu |
1084 | |
1085 | |
OLD | NEW |