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

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

Issue 651543003: Disallow active attrib aliasing at shader program link time. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 static const char* kAttrib1Name; 148 static const char* kAttrib1Name;
149 static const char* kAttrib2Name; 149 static const char* kAttrib2Name;
150 static const char* kAttrib3Name; 150 static const char* kAttrib3Name;
151 static const GLint kAttrib1Size = 1; 151 static const GLint kAttrib1Size = 1;
152 static const GLint kAttrib2Size = 1; 152 static const GLint kAttrib2Size = 1;
153 static const GLint kAttrib3Size = 1; 153 static const GLint kAttrib3Size = 1;
154 static const GLenum kAttrib1Precision = GL_MEDIUM_FLOAT; 154 static const GLenum kAttrib1Precision = GL_MEDIUM_FLOAT;
155 static const GLenum kAttrib2Precision = GL_HIGH_FLOAT; 155 static const GLenum kAttrib2Precision = GL_HIGH_FLOAT;
156 static const GLenum kAttrib3Precision = GL_LOW_FLOAT; 156 static const GLenum kAttrib3Precision = GL_LOW_FLOAT;
157 static const bool kAttribStaticUse = false; 157 static const bool kAttribStaticUse = true;
158 static const GLint kAttrib1Location = 0; 158 static const GLint kAttrib1Location = 0;
159 static const GLint kAttrib2Location = 1; 159 static const GLint kAttrib2Location = 1;
160 static const GLint kAttrib3Location = 2; 160 static const GLint kAttrib3Location = 2;
161 static const GLenum kAttrib1Type = GL_FLOAT_VEC4; 161 static const GLenum kAttrib1Type = GL_FLOAT_VEC4;
162 static const GLenum kAttrib2Type = GL_FLOAT_VEC2; 162 static const GLenum kAttrib2Type = GL_FLOAT_VEC2;
163 static const GLenum kAttrib3Type = GL_FLOAT_VEC3; 163 static const GLenum kAttrib3Type = GL_FLOAT_VEC3;
164 static const GLint kInvalidAttribLocation = 30; 164 static const GLint kInvalidAttribLocation = 30;
165 static const GLint kBadAttribIndex = kNumVertexAttribs; 165 static const GLint kBadAttribIndex = kNumVertexAttribs;
166 166
167 static const char* kUniform1Name; 167 static const char* kUniform1Name;
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 const GLuint kFShaderServiceId = 12; 1127 const GLuint kFShaderServiceId = 12;
1128 AttributeMap attrib_map; 1128 AttributeMap attrib_map;
1129 for (uint32 ii = 0; ii < kNumAttribs; ++ii) { 1129 for (uint32 ii = 0; ii < kNumAttribs; ++ii) {
1130 attrib_map[kAttribs[ii].name] = TestHelper::ConstructAttribute( 1130 attrib_map[kAttribs[ii].name] = TestHelper::ConstructAttribute(
1131 kAttribs[ii].type, 1131 kAttribs[ii].type,
1132 kAttribs[ii].size, 1132 kAttribs[ii].size,
1133 SH_PRECISION_MEDIUMP, 1133 SH_PRECISION_MEDIUMP,
1134 kAttribStaticUse, 1134 kAttribStaticUse,
1135 kAttribs[ii].name); 1135 kAttribs[ii].name);
1136 } 1136 }
1137 const char kAttribMatName[] = "matAttrib";
1138 attrib_map[kAttribMatName] = TestHelper::ConstructAttribute(
1139 GL_FLOAT_MAT2,
1140 1,
1141 SH_PRECISION_MEDIUMP,
1142 kAttribStaticUse,
1143 kAttribMatName);
1137 // Check we can create shader. 1144 // Check we can create shader.
1138 Shader* vshader = shader_manager_.CreateShader( 1145 Shader* vshader = shader_manager_.CreateShader(
1139 kVShaderClientId, kVShaderServiceId, GL_VERTEX_SHADER); 1146 kVShaderClientId, kVShaderServiceId, GL_VERTEX_SHADER);
1140 Shader* fshader = shader_manager_.CreateShader( 1147 Shader* fshader = shader_manager_.CreateShader(
1141 kFShaderClientId, kFShaderServiceId, GL_FRAGMENT_SHADER); 1148 kFShaderClientId, kFShaderServiceId, GL_FRAGMENT_SHADER);
1142 // Check shader got created. 1149 // Check shader got created.
1143 ASSERT_TRUE(vshader != NULL && fshader != NULL); 1150 ASSERT_TRUE(vshader != NULL && fshader != NULL);
1144 // Set Status 1151 // Set Status
1145 TestHelper::SetShaderStates( 1152 TestHelper::SetShaderStates(
1146 gl_.get(), vshader, true, NULL, NULL, &attrib_map, NULL, NULL, NULL); 1153 gl_.get(), vshader, true, NULL, NULL, &attrib_map, NULL, NULL, NULL);
(...skipping 19 matching lines...) Expand all
1166 manager_.CreateProgram(kClientProgramId, kServiceProgramId); 1173 manager_.CreateProgram(kClientProgramId, kServiceProgramId);
1167 ASSERT_TRUE(program != NULL); 1174 ASSERT_TRUE(program != NULL);
1168 EXPECT_TRUE(program->AttachShader(&shader_manager_, vshader)); 1175 EXPECT_TRUE(program->AttachShader(&shader_manager_, vshader));
1169 EXPECT_TRUE(program->AttachShader(&shader_manager_, fshader)); 1176 EXPECT_TRUE(program->AttachShader(&shader_manager_, fshader));
1170 1177
1171 EXPECT_FALSE(program->DetectAttribLocationBindingConflicts()); 1178 EXPECT_FALSE(program->DetectAttribLocationBindingConflicts());
1172 EXPECT_TRUE(LinkAsExpected(program, true)); 1179 EXPECT_TRUE(LinkAsExpected(program, true));
1173 1180
1174 program->SetAttribLocationBinding(kAttrib1Name, 0); 1181 program->SetAttribLocationBinding(kAttrib1Name, 0);
1175 EXPECT_FALSE(program->DetectAttribLocationBindingConflicts()); 1182 EXPECT_FALSE(program->DetectAttribLocationBindingConflicts());
1183 EXPECT_CALL(*(gl_.get()), BindAttribLocation(_, 0, _))
1184 .Times(1)
1185 .RetiresOnSaturation();
1176 EXPECT_TRUE(LinkAsExpected(program, true)); 1186 EXPECT_TRUE(LinkAsExpected(program, true));
1177 1187
1178 program->SetAttribLocationBinding("xxx", 0); 1188 program->SetAttribLocationBinding("xxx", 0);
1179 EXPECT_FALSE(program->DetectAttribLocationBindingConflicts()); 1189 EXPECT_FALSE(program->DetectAttribLocationBindingConflicts());
1190 EXPECT_CALL(*(gl_.get()), BindAttribLocation(_, 0, _))
1191 .Times(1)
1192 .RetiresOnSaturation();
1180 EXPECT_TRUE(LinkAsExpected(program, true)); 1193 EXPECT_TRUE(LinkAsExpected(program, true));
1181 1194
1182 program->SetAttribLocationBinding(kAttrib2Name, 1); 1195 program->SetAttribLocationBinding(kAttrib2Name, 1);
1183 EXPECT_FALSE(program->DetectAttribLocationBindingConflicts()); 1196 EXPECT_FALSE(program->DetectAttribLocationBindingConflicts());
1197 EXPECT_CALL(*(gl_.get()), BindAttribLocation(_, _, _))
1198 .Times(2)
1199 .RetiresOnSaturation();
1184 EXPECT_TRUE(LinkAsExpected(program, true)); 1200 EXPECT_TRUE(LinkAsExpected(program, true));
1185 1201
1186 program->SetAttribLocationBinding(kAttrib2Name, 0); 1202 program->SetAttribLocationBinding(kAttrib2Name, 0);
1187 EXPECT_TRUE(program->DetectAttribLocationBindingConflicts()); 1203 EXPECT_TRUE(program->DetectAttribLocationBindingConflicts());
1188 EXPECT_TRUE(LinkAsExpected(program, false)); 1204 EXPECT_TRUE(LinkAsExpected(program, false));
1205
1206 program->SetAttribLocationBinding(kAttribMatName, 1);
1207 program->SetAttribLocationBinding(kAttrib2Name, 3);
1208 EXPECT_CALL(*(gl_.get()), BindAttribLocation(_, _, _))
1209 .Times(3)
1210 .RetiresOnSaturation();
1211 EXPECT_FALSE(program->DetectAttribLocationBindingConflicts());
1212 EXPECT_TRUE(LinkAsExpected(program, true));
1213
1214 program->SetAttribLocationBinding(kAttrib2Name, 2);
1215 EXPECT_TRUE(program->DetectAttribLocationBindingConflicts());
1216 EXPECT_TRUE(LinkAsExpected(program, false));
1189 } 1217 }
1190 1218
1191 TEST_F(ProgramManagerWithShaderTest, UniformsPrecisionMismatch) { 1219 TEST_F(ProgramManagerWithShaderTest, UniformsPrecisionMismatch) {
1192 // Set up shader 1220 // Set up shader
1193 const GLuint kVShaderClientId = 1; 1221 const GLuint kVShaderClientId = 1;
1194 const GLuint kVShaderServiceId = 11; 1222 const GLuint kVShaderServiceId = 11;
1195 const GLuint kFShaderClientId = 2; 1223 const GLuint kFShaderClientId = 2;
1196 const GLuint kFShaderServiceId = 12; 1224 const GLuint kFShaderServiceId = 12;
1197 1225
1198 UniformMap vertex_uniform_map; 1226 UniformMap vertex_uniform_map;
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
1754 SetExpectationsForProgramLoad(ProgramCache::PROGRAM_LOAD_SUCCESS); 1782 SetExpectationsForProgramLoad(ProgramCache::PROGRAM_LOAD_SUCCESS);
1755 SetExpectationsForNotCachingProgram(); 1783 SetExpectationsForNotCachingProgram();
1756 SetExpectationsForProgramLoadSuccess(); 1784 SetExpectationsForProgramLoadSuccess();
1757 1785
1758 EXPECT_TRUE(program_->Link(NULL, NULL, NULL, 1786 EXPECT_TRUE(program_->Link(NULL, NULL, NULL,
1759 Program::kCountOnlyStaticallyUsed, base::Bind(&ShaderCacheCb))); 1787 Program::kCountOnlyStaticallyUsed, base::Bind(&ShaderCacheCb)));
1760 } 1788 }
1761 1789
1762 } // namespace gles2 1790 } // namespace gles2
1763 } // namespace gpu 1791 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698