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

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

Issue 9570023: Fails glLinkProgram if two glBindAttribLocation conflicts. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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
« no previous file with comments | « gpu/command_buffer/service/program_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 EXPECT_CALL(*gl_, GetUniformLocation(service_id, 327 EXPECT_CALL(*gl_, GetUniformLocation(service_id,
328 StrEq(element_name))) 328 StrEq(element_name)))
329 .WillOnce(Return(info.real_location + jj * 2)) 329 .WillOnce(Return(info.real_location + jj * 2))
330 .RetiresOnSaturation(); 330 .RetiresOnSaturation();
331 } 331 }
332 } 332 }
333 } 333 }
334 } 334 }
335 } 335 }
336 336
337
338 void SetupDefaultShaderExpectations() { 337 void SetupDefaultShaderExpectations() {
339 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms, 338 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms,
340 kServiceProgramId); 339 kServiceProgramId);
341 } 340 }
342 341
343 virtual void TearDown() { 342 virtual void TearDown() {
344 ::gfx::GLInterface::SetGLInterface(NULL); 343 ::gfx::GLInterface::SetGLInterface(NULL);
345 } 344 }
346 345
346 // Return true if link status matches expected_link_status
347 bool LinkAsExpected(ProgramManager::ProgramInfo* program_info,
348 bool expected_link_status) {
349 GLuint service_id = program_info->service_id();
350 if (expected_link_status) {
351 SetupShader(kAttribs, kNumAttribs, kUniforms, kNumUniforms,
352 service_id);
353 }
354 program_info->Link();
355 GLint link_status;
356 program_info->GetProgramiv(GL_LINK_STATUS, &link_status);
357 return (static_cast<bool>(link_status) == expected_link_status);
358 }
359
347 static AttribInfo kAttribs[]; 360 static AttribInfo kAttribs[];
348 static UniformInfo kUniforms[]; 361 static UniformInfo kUniforms[];
349 362
350 scoped_ptr<StrictMock<gfx::MockGLInterface> > gl_; 363 scoped_ptr<StrictMock<gfx::MockGLInterface> > gl_;
351 364
352 ProgramManager manager_; 365 ProgramManager manager_;
353 ProgramManager::ProgramInfo* program_info_; 366 ProgramManager::ProgramInfo* program_info_;
354 ShaderManager shader_manager_; 367 ShaderManager shader_manager_;
355 }; 368 };
356 369
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 input->name_offset, input->name_length); 944 input->name_offset, input->name_length);
932 ASSERT_TRUE(name_buf != NULL); 945 ASSERT_TRUE(name_buf != NULL);
933 std::string name(name_buf, input->name_length); 946 std::string name(name_buf, input->name_length);
934 EXPECT_STREQ(expected.good_name, name.c_str()); 947 EXPECT_STREQ(expected.good_name, name.c_str());
935 ++input; 948 ++input;
936 } 949 }
937 EXPECT_EQ(header->num_attribs + header->num_uniforms, 950 EXPECT_EQ(header->num_attribs + header->num_uniforms,
938 static_cast<uint32>(input - inputs)); 951 static_cast<uint32>(input - inputs));
939 } 952 }
940 953
954 TEST_F(ProgramManagerWithShaderTest, BindAttribLocationConflicts) {
955 // Set up shader
956 const GLuint kVShaderClientId = 1;
957 const GLuint kVShaderServiceId = 11;
958 const GLuint kFShaderClientId = 2;
959 const GLuint kFShaderServiceId = 12;
960 MockShaderTranslator shader_translator;
961 ShaderTranslator::VariableMap attrib_map;
962 for (uint32 ii = 0; ii < kNumAttribs; ++ii) {
963 attrib_map[kAttribs[ii].name] = ShaderTranslatorInterface::VariableInfo(
964 kAttribs[ii].type, kAttribs[ii].size, kAttribs[ii].name);
965 }
966 ShaderTranslator::VariableMap uniform_map;
967 EXPECT_CALL(shader_translator, attrib_map())
968 .WillRepeatedly(ReturnRef(attrib_map));
969 EXPECT_CALL(shader_translator, uniform_map())
970 .WillRepeatedly(ReturnRef(uniform_map));
971 // Check we can create shader.
972 ShaderManager::ShaderInfo* vshader = shader_manager_.CreateShaderInfo(
973 kVShaderClientId, kVShaderServiceId, GL_VERTEX_SHADER);
974 ShaderManager::ShaderInfo* fshader = shader_manager_.CreateShaderInfo(
975 kFShaderClientId, kFShaderServiceId, GL_FRAGMENT_SHADER);
976 // Check shader got created.
977 ASSERT_TRUE(vshader != NULL && fshader != NULL);
978 // Set Status
979 vshader->SetStatus(true, "", &shader_translator);
980 // Check attrib infos got copied.
981 for (ShaderTranslator::VariableMap::const_iterator it = attrib_map.begin();
982 it != attrib_map.end(); ++it) {
983 const ShaderManager::ShaderInfo::VariableInfo* variable_info =
984 vshader->GetAttribInfo(it->first);
985 ASSERT_TRUE(variable_info != NULL);
986 EXPECT_EQ(it->second.type, variable_info->type);
987 EXPECT_EQ(it->second.size, variable_info->size);
988 EXPECT_EQ(it->second.name, variable_info->name);
989 }
990 fshader->SetStatus(true, "", NULL);
991
992 // Set up program
993 const GLuint kClientProgramId = 6666;
994 const GLuint kServiceProgramId = 8888;
995 ProgramManager::ProgramInfo* program_info =
996 manager_.CreateProgramInfo(kClientProgramId, kServiceProgramId);
997 ASSERT_TRUE(program_info != NULL);
998 EXPECT_TRUE(program_info->AttachShader(&shader_manager_, vshader));
999 EXPECT_TRUE(program_info->AttachShader(&shader_manager_, fshader));
1000
1001 EXPECT_FALSE(program_info->DetectAttribLocationBindingConflicts());
1002 EXPECT_TRUE(LinkAsExpected(program_info, true));
1003
1004 program_info->SetAttribLocationBinding(kAttrib1Name, 0);
1005 EXPECT_FALSE(program_info->DetectAttribLocationBindingConflicts());
1006 EXPECT_TRUE(LinkAsExpected(program_info, true));
1007
1008 program_info->SetAttribLocationBinding("xxx", 0);
1009 EXPECT_FALSE(program_info->DetectAttribLocationBindingConflicts());
1010 EXPECT_TRUE(LinkAsExpected(program_info, true));
1011
1012 program_info->SetAttribLocationBinding(kAttrib2Name, 1);
1013 EXPECT_FALSE(program_info->DetectAttribLocationBindingConflicts());
1014 EXPECT_TRUE(LinkAsExpected(program_info, true));
1015
1016 program_info->SetAttribLocationBinding(kAttrib2Name, 0);
1017 EXPECT_TRUE(program_info->DetectAttribLocationBindingConflicts());
1018 EXPECT_TRUE(LinkAsExpected(program_info, false));
1019 }
1020
941 } // namespace gles2 1021 } // namespace gles2
942 } // namespace gpu 1022 } // namespace gpu
943 1023
944 1024
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/program_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698