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

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

Issue 619723008: Switch to use ANGLE's new APIs to query shader variables. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: win build fix 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/shader_manager.h" 5 #include "gpu/command_buffer/service/shader_manager.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "gpu/command_buffer/service/gpu_service_test.h" 8 #include "gpu/command_buffer/service/gpu_service_test.h"
9 #include "gpu/command_buffer/service/mocks.h" 9 #include "gpu/command_buffer/service/mocks.h"
10 #include "gpu/command_buffer/service/test_helper.h" 10 #include "gpu/command_buffer/service/test_helper.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 EXPECT_TRUE(manager_.IsOwned(shader1.get())); 86 EXPECT_TRUE(manager_.IsOwned(shader1.get()));
87 EXPECT_FALSE(manager_.IsOwned(shader2.get())); 87 EXPECT_FALSE(manager_.IsOwned(shader2.get()));
88 } 88 }
89 89
90 TEST_F(ShaderManagerTest, DoCompile) { 90 TEST_F(ShaderManagerTest, DoCompile) {
91 const GLuint kClient1Id = 1; 91 const GLuint kClient1Id = 1;
92 const GLuint kService1Id = 11; 92 const GLuint kService1Id = 11;
93 const GLenum kShader1Type = GL_VERTEX_SHADER; 93 const GLenum kShader1Type = GL_VERTEX_SHADER;
94 const char* kClient1Source = "hello world"; 94 const char* kClient1Source = "hello world";
95 const GLenum kAttrib1Type = GL_FLOAT_VEC2; 95 const GLenum kAttrib1Type = GL_FLOAT_VEC2;
96 const GLsizei kAttrib1Size = 2; 96 const GLint kAttrib1Size = 2;
97 const int kAttrib1Precision = SH_PRECISION_MEDIUMP; 97 const GLenum kAttrib1Precision = GL_MEDIUM_FLOAT;
98 const char* kAttrib1Name = "attr1"; 98 const char* kAttrib1Name = "attr1";
99 const GLenum kAttrib2Type = GL_FLOAT_VEC3; 99 const GLenum kAttrib2Type = GL_FLOAT_VEC3;
100 const GLsizei kAttrib2Size = 4; 100 const GLint kAttrib2Size = 4;
101 const int kAttrib2Precision = SH_PRECISION_HIGHP; 101 const GLenum kAttrib2Precision = GL_HIGH_FLOAT;
102 const char* kAttrib2Name = "attr2"; 102 const char* kAttrib2Name = "attr2";
103 const int kAttribStaticUse = 0; 103 const bool kAttribStaticUse = false;
104 const GLenum kUniform1Type = GL_FLOAT_MAT2; 104 const GLenum kUniform1Type = GL_FLOAT_MAT2;
105 const GLsizei kUniform1Size = 3; 105 const GLint kUniform1Size = 3;
106 const int kUniform1Precision = SH_PRECISION_LOWP; 106 const GLenum kUniform1Precision = GL_LOW_FLOAT;
107 const int kUniform1StaticUse = 1; 107 const bool kUniform1StaticUse = true;
108 const char* kUniform1Name = "uni1"; 108 const char* kUniform1Name = "uni1";
109 const GLenum kUniform2Type = GL_FLOAT_MAT3; 109 const GLenum kUniform2Type = GL_FLOAT_MAT3;
110 const GLsizei kUniform2Size = 5; 110 const GLint kUniform2Size = 5;
111 const int kUniform2Precision = SH_PRECISION_MEDIUMP; 111 const GLenum kUniform2Precision = GL_MEDIUM_FLOAT;
112 const int kUniform2StaticUse = 0; 112 const bool kUniform2StaticUse = false;
113 const char* kUniform2Name = "uni2"; 113 const char* kUniform2Name = "uni2";
114 const GLenum kVarying1Type = GL_FLOAT_VEC4; 114 const GLenum kVarying1Type = GL_FLOAT_VEC4;
115 const GLsizei kVarying1Size = 1; 115 const GLint kVarying1Size = 1;
116 const int kVarying1Precision = SH_PRECISION_HIGHP; 116 const GLenum kVarying1Precision = GL_HIGH_FLOAT;
117 const int kVarying1StaticUse = 0; 117 const bool kVarying1StaticUse = false;
118 const char* kVarying1Name = "varying1"; 118 const char* kVarying1Name = "varying1";
119 119
120 // Check we can create shader. 120 // Check we can create shader.
121 Shader* shader1 = manager_.CreateShader( 121 Shader* shader1 = manager_.CreateShader(
122 kClient1Id, kService1Id, kShader1Type); 122 kClient1Id, kService1Id, kShader1Type);
123 // Check shader got created. 123 // Check shader got created.
124 ASSERT_TRUE(shader1 != NULL); 124 ASSERT_TRUE(shader1 != NULL);
125 EXPECT_EQ(kService1Id, shader1->service_id()); 125 EXPECT_EQ(kService1Id, shader1->service_id());
126 // Check if the shader has correct type. 126 // Check if the shader has correct type.
127 EXPECT_EQ(kShader1Type, shader1->shader_type()); 127 EXPECT_EQ(kShader1Type, shader1->shader_type());
(...skipping 10 matching lines...) Expand all
138 // Check we can set its source. 138 // Check we can set its source.
139 shader1->set_source(kClient1Source); 139 shader1->set_source(kClient1Source);
140 EXPECT_STREQ(kClient1Source, shader1->source().c_str()); 140 EXPECT_STREQ(kClient1Source, shader1->source().c_str());
141 EXPECT_TRUE(shader1->signature_source().empty()); 141 EXPECT_TRUE(shader1->signature_source().empty());
142 142
143 // Check DoCompile() will set compilation states, log, translated source, 143 // Check DoCompile() will set compilation states, log, translated source,
144 // shader variables, and name mapping. 144 // shader variables, and name mapping.
145 const std::string kLog = "foo"; 145 const std::string kLog = "foo";
146 const std::string kTranslatedSource = "poo"; 146 const std::string kTranslatedSource = "poo";
147 147
148 ShaderTranslator::VariableMap attrib_map; 148 AttributeMap attrib_map;
149 attrib_map[kAttrib1Name] = ShaderTranslatorInterface::VariableInfo( 149 attrib_map[kAttrib1Name] = TestHelper::ConstructAttribute(
150 kAttrib1Type, kAttrib1Size, kAttrib1Precision, 150 kAttrib1Type, kAttrib1Size, kAttrib1Precision,
151 kAttribStaticUse, kAttrib1Name); 151 kAttribStaticUse, kAttrib1Name);
152 attrib_map[kAttrib2Name] = ShaderTranslatorInterface::VariableInfo( 152 attrib_map[kAttrib2Name] = TestHelper::ConstructAttribute(
153 kAttrib2Type, kAttrib2Size, kAttrib2Precision, 153 kAttrib2Type, kAttrib2Size, kAttrib2Precision,
154 kAttribStaticUse, kAttrib2Name); 154 kAttribStaticUse, kAttrib2Name);
155 ShaderTranslator::VariableMap uniform_map; 155 UniformMap uniform_map;
156 uniform_map[kUniform1Name] = ShaderTranslatorInterface::VariableInfo( 156 uniform_map[kUniform1Name] = TestHelper::ConstructUniform(
157 kUniform1Type, kUniform1Size, kUniform1Precision, 157 kUniform1Type, kUniform1Size, kUniform1Precision,
158 kUniform1StaticUse, kUniform1Name); 158 kUniform1StaticUse, kUniform1Name);
159 uniform_map[kUniform2Name] = ShaderTranslatorInterface::VariableInfo( 159 uniform_map[kUniform2Name] = TestHelper::ConstructUniform(
160 kUniform2Type, kUniform2Size, kUniform2Precision, 160 kUniform2Type, kUniform2Size, kUniform2Precision,
161 kUniform2StaticUse, kUniform2Name); 161 kUniform2StaticUse, kUniform2Name);
162 ShaderTranslator::VariableMap varying_map; 162 VaryingMap varying_map;
163 varying_map[kVarying1Name] = ShaderTranslatorInterface::VariableInfo( 163 varying_map[kVarying1Name] = TestHelper::ConstructVarying(
164 kVarying1Type, kVarying1Size, kVarying1Precision, 164 kVarying1Type, kVarying1Size, kVarying1Precision,
165 kVarying1StaticUse, kVarying1Name); 165 kVarying1StaticUse, kVarying1Name);
166 166
167 TestHelper::SetShaderStates( 167 TestHelper::SetShaderStates(
168 gl_.get(), shader1, true, &kLog, &kTranslatedSource, 168 gl_.get(), shader1, true, &kLog, &kTranslatedSource,
169 &attrib_map, &uniform_map, &varying_map, NULL); 169 &attrib_map, &uniform_map, &varying_map, NULL);
170 EXPECT_TRUE(shader1->valid()); 170 EXPECT_TRUE(shader1->valid());
171 // When compilation succeeds, no log is recorded. 171 // When compilation succeeds, no log is recorded.
172 EXPECT_STREQ("", shader1->log_info().c_str()); 172 EXPECT_STREQ("", shader1->log_info().c_str());
173 EXPECT_STREQ(kClient1Source, shader1->signature_source().c_str()); 173 EXPECT_STREQ(kClient1Source, shader1->signature_source().c_str());
174 EXPECT_STREQ(kTranslatedSource.c_str(), shader1->translated_source().c_str()); 174 EXPECT_STREQ(kTranslatedSource.c_str(), shader1->translated_source().c_str());
175 175
176 // Check varying infos got copied. 176 // Check varying infos got copied.
177 EXPECT_EQ(attrib_map.size(), shader1->attrib_map().size()); 177 EXPECT_EQ(attrib_map.size(), shader1->attrib_map().size());
178 for (ShaderTranslator::VariableMap::const_iterator it = attrib_map.begin(); 178 for (AttributeMap::const_iterator it = attrib_map.begin();
179 it != attrib_map.end(); ++it) { 179 it != attrib_map.end(); ++it) {
180 const Shader::VariableInfo* variable_info = 180 const sh::Attribute* variable_info = shader1->GetAttribInfo(it->first);
181 shader1->GetAttribInfo(it->first);
182 ASSERT_TRUE(variable_info != NULL); 181 ASSERT_TRUE(variable_info != NULL);
183 EXPECT_EQ(it->second.type, variable_info->type); 182 EXPECT_EQ(it->second.type, variable_info->type);
184 EXPECT_EQ(it->second.size, variable_info->size); 183 EXPECT_EQ(it->second.arraySize, variable_info->arraySize);
185 EXPECT_EQ(it->second.precision, variable_info->precision); 184 EXPECT_EQ(it->second.precision, variable_info->precision);
186 EXPECT_EQ(it->second.static_use, variable_info->static_use); 185 EXPECT_EQ(it->second.staticUse, variable_info->staticUse);
187 EXPECT_STREQ(it->second.name.c_str(), variable_info->name.c_str()); 186 EXPECT_STREQ(it->second.name.c_str(), variable_info->name.c_str());
188 } 187 }
189 // Check uniform infos got copied. 188 // Check uniform infos got copied.
190 EXPECT_EQ(uniform_map.size(), shader1->uniform_map().size()); 189 EXPECT_EQ(uniform_map.size(), shader1->uniform_map().size());
191 for (ShaderTranslator::VariableMap::const_iterator it = uniform_map.begin(); 190 for (UniformMap::const_iterator it = uniform_map.begin();
192 it != uniform_map.end(); ++it) { 191 it != uniform_map.end(); ++it) {
193 const Shader::VariableInfo* variable_info = 192 const sh::Uniform* variable_info = shader1->GetUniformInfo(it->first);
194 shader1->GetUniformInfo(it->first);
195 ASSERT_TRUE(variable_info != NULL); 193 ASSERT_TRUE(variable_info != NULL);
196 EXPECT_EQ(it->second.type, variable_info->type); 194 EXPECT_EQ(it->second.type, variable_info->type);
197 EXPECT_EQ(it->second.size, variable_info->size); 195 EXPECT_EQ(it->second.arraySize, variable_info->arraySize);
198 EXPECT_EQ(it->second.precision, variable_info->precision); 196 EXPECT_EQ(it->second.precision, variable_info->precision);
199 EXPECT_EQ(it->second.static_use, variable_info->static_use); 197 EXPECT_EQ(it->second.staticUse, variable_info->staticUse);
200 EXPECT_STREQ(it->second.name.c_str(), variable_info->name.c_str()); 198 EXPECT_STREQ(it->second.name.c_str(), variable_info->name.c_str());
201 } 199 }
202 // Check varying infos got copied. 200 // Check varying infos got copied.
203 EXPECT_EQ(varying_map.size(), shader1->varying_map().size()); 201 EXPECT_EQ(varying_map.size(), shader1->varying_map().size());
204 for (ShaderTranslator::VariableMap::const_iterator it = varying_map.begin(); 202 for (VaryingMap::const_iterator it = varying_map.begin();
205 it != varying_map.end(); ++it) { 203 it != varying_map.end(); ++it) {
206 const Shader::VariableInfo* variable_info = 204 const sh::Varying* variable_info = shader1->GetVaryingInfo(it->first);
207 shader1->GetVaryingInfo(it->first);
208 ASSERT_TRUE(variable_info != NULL); 205 ASSERT_TRUE(variable_info != NULL);
209 EXPECT_EQ(it->second.type, variable_info->type); 206 EXPECT_EQ(it->second.type, variable_info->type);
210 EXPECT_EQ(it->second.size, variable_info->size); 207 EXPECT_EQ(it->second.arraySize, variable_info->arraySize);
211 EXPECT_EQ(it->second.precision, variable_info->precision); 208 EXPECT_EQ(it->second.precision, variable_info->precision);
212 EXPECT_EQ(it->second.static_use, variable_info->static_use); 209 EXPECT_EQ(it->second.staticUse, variable_info->staticUse);
213 EXPECT_STREQ(it->second.name.c_str(), variable_info->name.c_str()); 210 EXPECT_STREQ(it->second.name.c_str(), variable_info->name.c_str());
214 } 211 }
215 212
216 // Compile failure case. 213 // Compile failure case.
217 TestHelper::SetShaderStates( 214 TestHelper::SetShaderStates(
218 gl_.get(), shader1, false, &kLog, &kTranslatedSource, 215 gl_.get(), shader1, false, &kLog, &kTranslatedSource,
219 &attrib_map, &uniform_map, &varying_map, NULL); 216 &attrib_map, &uniform_map, &varying_map, NULL);
220 EXPECT_FALSE(shader1->valid()); 217 EXPECT_FALSE(shader1->valid());
221 EXPECT_STREQ(kLog.c_str(), shader1->log_info().c_str()); 218 EXPECT_STREQ(kLog.c_str(), shader1->log_info().c_str());
222 EXPECT_STREQ("", shader1->translated_source().c_str()); 219 EXPECT_STREQ("", shader1->translated_source().c_str());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 EXPECT_FALSE(shader1->InUse()); 260 EXPECT_FALSE(shader1->InUse());
264 shader2 = manager_.GetShader(kClient1Id); 261 shader2 = manager_.GetShader(kClient1Id);
265 EXPECT_EQ(shader1, shader2); 262 EXPECT_EQ(shader1, shader2);
266 manager_.MarkAsDeleted(shader1); // this should delete the shader. 263 manager_.MarkAsDeleted(shader1); // this should delete the shader.
267 shader2 = manager_.GetShader(kClient1Id); 264 shader2 = manager_.GetShader(kClient1Id);
268 EXPECT_TRUE(shader2 == NULL); 265 EXPECT_TRUE(shader2 == NULL);
269 } 266 }
270 267
271 } // namespace gles2 268 } // namespace gles2
272 } // namespace gpu 269 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/shader_manager.cc ('k') | gpu/command_buffer/service/shader_translator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698