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

Side by Side Diff: gpu/command_buffer/client/program_info_manager.cc

Issue 12326146: Refactor/Rename a bunch of GPU stuff (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 <map> 5 #include <map>
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "../client/program_info_manager.h" 8 #include "../client/program_info_manager.h"
9 #include "../client/atomicops.h" 9 #include "../client/atomicops.h"
10 #include "../client/gles2_implementation.h" 10 #include "../client/gles2_implementation.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 virtual bool GetActiveUniform(GLES2Implementation* gl, 135 virtual bool GetActiveUniform(GLES2Implementation* gl,
136 GLuint program, 136 GLuint program,
137 GLuint index, 137 GLuint index,
138 GLsizei bufsize, 138 GLsizei bufsize,
139 GLsizei* length, 139 GLsizei* length,
140 GLint* size, 140 GLint* size,
141 GLenum* type, 141 GLenum* type,
142 char* name) OVERRIDE; 142 char* name) OVERRIDE;
143 143
144 private: 144 private:
145 class ProgramInfo { 145 class Program {
146 public: 146 public:
147 struct UniformInfo { 147 struct UniformInfo {
148 UniformInfo(GLsizei _size, GLenum _type, const std::string& _name); 148 UniformInfo(GLsizei _size, GLenum _type, const std::string& _name);
149 149
150 GLsizei size; 150 GLsizei size;
151 GLenum type; 151 GLenum type;
152 bool is_array; 152 bool is_array;
153 std::string name; 153 std::string name;
154 std::vector<GLint> element_locations; 154 std::vector<GLint> element_locations;
155 }; 155 };
156 struct VertexAttribInfo { 156 struct VertexAttrib {
157 VertexAttribInfo(GLsizei _size, GLenum _type, const std::string& _name, 157 VertexAttrib(GLsizei _size, GLenum _type, const std::string& _name,
158 GLint _location) 158 GLint _location)
159 : size(_size), 159 : size(_size),
160 type(_type), 160 type(_type),
161 location(_location), 161 location(_location),
162 name(_name) { 162 name(_name) {
163 } 163 }
164 GLsizei size; 164 GLsizei size;
165 GLenum type; 165 GLenum type;
166 GLint location; 166 GLint location;
167 std::string name; 167 std::string name;
168 }; 168 };
169 169
170 typedef std::vector<UniformInfo> UniformInfoVector; 170 typedef std::vector<UniformInfo> UniformInfoVector;
171 typedef std::vector<VertexAttribInfo> AttribInfoVector; 171 typedef std::vector<VertexAttrib> AttribInfoVector;
172 172
173 ProgramInfo(); 173 Program();
174 174
175 const AttribInfoVector& GetAttribInfos() const { 175 const AttribInfoVector& GetAttribInfos() const {
176 return attrib_infos_; 176 return attrib_infos_;
177 } 177 }
178 178
179 const VertexAttribInfo* GetAttribInfo(GLint index) const { 179 const VertexAttrib* GetAttribInfo(GLint index) const {
180 return (static_cast<size_t>(index) < attrib_infos_.size()) ? 180 return (static_cast<size_t>(index) < attrib_infos_.size()) ?
181 &attrib_infos_[index] : NULL; 181 &attrib_infos_[index] : NULL;
182 } 182 }
183 183
184 GLint GetAttribLocation(const std::string& name) const; 184 GLint GetAttribLocation(const std::string& name) const;
185 185
186 const UniformInfo* GetUniformInfo(GLint index) const { 186 const UniformInfo* GetUniformInfo(GLint index) const {
187 return (static_cast<size_t>(index) < uniform_infos_.size()) ? 187 return (static_cast<size_t>(index) < uniform_infos_.size()) ?
188 &uniform_infos_[index] : NULL; 188 &uniform_infos_[index] : NULL;
189 } 189 }
(...skipping 16 matching lines...) Expand all
206 206
207 GLsizei max_uniform_name_length_; 207 GLsizei max_uniform_name_length_;
208 208
209 // Uniform info by index. 209 // Uniform info by index.
210 UniformInfoVector uniform_infos_; 210 UniformInfoVector uniform_infos_;
211 211
212 // This is true if glLinkProgram was successful last time it was called. 212 // This is true if glLinkProgram was successful last time it was called.
213 bool link_status_; 213 bool link_status_;
214 }; 214 };
215 215
216 ProgramInfo* GetProgramInfo(GLES2Implementation* gl, GLuint program); 216 Program* GetProgramInfo(GLES2Implementation* gl, GLuint program);
217 217
218 // TODO(gman): Switch to a faster container. 218 // TODO(gman): Switch to a faster container.
219 typedef std::map<GLuint, ProgramInfo> ProgramInfoMap; 219 typedef std::map<GLuint, Program> ProgramInfoMap;
220 220
221 ProgramInfoMap program_infos_; 221 ProgramInfoMap program_infos_;
222 222
223 mutable Lock lock_; 223 mutable Lock lock_;
224 }; 224 };
225 225
226 CachedProgramInfoManager::ProgramInfo::UniformInfo::UniformInfo( 226 CachedProgramInfoManager::Program::UniformInfo::UniformInfo(
227 GLsizei _size, GLenum _type, const std::string& _name) 227 GLsizei _size, GLenum _type, const std::string& _name)
228 : size(_size), 228 : size(_size),
229 type(_type), 229 type(_type),
230 name(_name) { 230 name(_name) {
231 is_array = (!name.empty() && name[name.size() - 1] == ']'); 231 is_array = (!name.empty() && name[name.size() - 1] == ']');
232 GPU_DCHECK(!(size > 1 && !is_array)); 232 GPU_DCHECK(!(size > 1 && !is_array));
233 } 233 }
234 234
235 CachedProgramInfoManager::ProgramInfo::ProgramInfo() 235 CachedProgramInfoManager::Program::Program()
236 : cached_(false), 236 : cached_(false),
237 max_attrib_name_length_(0), 237 max_attrib_name_length_(0),
238 max_uniform_name_length_(0), 238 max_uniform_name_length_(0),
239 link_status_(false) { 239 link_status_(false) {
240 } 240 }
241 241
242 // TODO(gman): Add a faster lookup. 242 // TODO(gman): Add a faster lookup.
243 GLint CachedProgramInfoManager::ProgramInfo::GetAttribLocation( 243 GLint CachedProgramInfoManager::Program::GetAttribLocation(
244 const std::string& name) const { 244 const std::string& name) const {
245 for (GLuint ii = 0; ii < attrib_infos_.size(); ++ii) { 245 for (GLuint ii = 0; ii < attrib_infos_.size(); ++ii) {
246 const VertexAttribInfo& info = attrib_infos_[ii]; 246 const VertexAttrib& info = attrib_infos_[ii];
247 if (info.name == name) { 247 if (info.name == name) {
248 return info.location; 248 return info.location;
249 } 249 }
250 } 250 }
251 return -1; 251 return -1;
252 } 252 }
253 253
254 GLint CachedProgramInfoManager::ProgramInfo::GetUniformLocation( 254 GLint CachedProgramInfoManager::Program::GetUniformLocation(
255 const std::string& name) const { 255 const std::string& name) const {
256 bool getting_array_location = false; 256 bool getting_array_location = false;
257 size_t open_pos = std::string::npos; 257 size_t open_pos = std::string::npos;
258 int index = 0; 258 int index = 0;
259 if (!GLES2Util::ParseUniformName( 259 if (!GLES2Util::ParseUniformName(
260 name, &open_pos, &index, &getting_array_location)) { 260 name, &open_pos, &index, &getting_array_location)) {
261 return -1; 261 return -1;
262 } 262 }
263 for (GLuint ii = 0; ii < uniform_infos_.size(); ++ii) { 263 for (GLuint ii = 0; ii < uniform_infos_.size(); ++ii) {
264 const UniformInfo& info = uniform_infos_[ii]; 264 const UniformInfo& info = uniform_infos_[ii];
265 if (info.name == name || 265 if (info.name == name ||
266 (info.is_array && 266 (info.is_array &&
267 info.name.compare(0, info.name.size() - 3, name) == 0)) { 267 info.name.compare(0, info.name.size() - 3, name) == 0)) {
268 return info.element_locations[0]; 268 return info.element_locations[0];
269 } else if (getting_array_location && info.is_array) { 269 } else if (getting_array_location && info.is_array) {
270 // Look for an array specification. 270 // Look for an array specification.
271 size_t open_pos_2 = info.name.find_last_of('['); 271 size_t open_pos_2 = info.name.find_last_of('[');
272 if (open_pos_2 == open_pos && 272 if (open_pos_2 == open_pos &&
273 name.compare(0, open_pos, info.name, 0, open_pos) == 0) { 273 name.compare(0, open_pos, info.name, 0, open_pos) == 0) {
274 if (index >= 0 && index < info.size) { 274 if (index >= 0 && index < info.size) {
275 return info.element_locations[index]; 275 return info.element_locations[index];
276 } 276 }
277 } 277 }
278 } 278 }
279 } 279 }
280 return -1; 280 return -1;
281 } 281 }
282 282
283 bool CachedProgramInfoManager::ProgramInfo::GetProgramiv( 283 bool CachedProgramInfoManager::Program::GetProgramiv(
284 GLenum pname, GLint* params) { 284 GLenum pname, GLint* params) {
285 switch (pname) { 285 switch (pname) {
286 case GL_LINK_STATUS: 286 case GL_LINK_STATUS:
287 *params = link_status_; 287 *params = link_status_;
288 return true; 288 return true;
289 case GL_ACTIVE_ATTRIBUTES: 289 case GL_ACTIVE_ATTRIBUTES:
290 *params = attrib_infos_.size(); 290 *params = attrib_infos_.size();
291 return true; 291 return true;
292 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: 292 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
293 *params = max_attrib_name_length_; 293 *params = max_attrib_name_length_;
(...skipping 13 matching lines...) Expand all
307 template<typename T> static T LocalGetAs( 307 template<typename T> static T LocalGetAs(
308 const std::vector<int8>& data, uint32 offset, size_t size) { 308 const std::vector<int8>& data, uint32 offset, size_t size) {
309 const int8* p = &data[0] + offset; 309 const int8* p = &data[0] + offset;
310 if (offset + size > data.size()) { 310 if (offset + size > data.size()) {
311 GPU_NOTREACHED(); 311 GPU_NOTREACHED();
312 return NULL; 312 return NULL;
313 } 313 }
314 return static_cast<T>(static_cast<const void*>(p)); 314 return static_cast<T>(static_cast<const void*>(p));
315 } 315 }
316 316
317 void CachedProgramInfoManager::ProgramInfo::Update( 317 void CachedProgramInfoManager::Program::Update(
318 GLES2Implementation* gl, GLuint program) { 318 GLES2Implementation* gl, GLuint program) {
319 if (cached_) { 319 if (cached_) {
320 return; 320 return;
321 } 321 }
322 std::vector<int8> result; 322 std::vector<int8> result;
323 gl->GetProgramInfoCHROMIUMHelper(program, &result); 323 gl->GetProgramInfoCHROMIUMHelper(program, &result);
324 if (result.empty()) { 324 if (result.empty()) {
325 // This should only happen on a lost context. 325 // This should only happen on a lost context.
326 return; 326 return;
327 } 327 }
(...skipping 12 matching lines...) Expand all
340 result, sizeof(*header), 340 result, sizeof(*header),
341 sizeof(ProgramInput) * (header->num_attribs + header->num_uniforms)); 341 sizeof(ProgramInput) * (header->num_attribs + header->num_uniforms));
342 const ProgramInput* input = inputs; 342 const ProgramInput* input = inputs;
343 for (uint32 ii = 0; ii < header->num_attribs; ++ii) { 343 for (uint32 ii = 0; ii < header->num_attribs; ++ii) {
344 const int32* location = LocalGetAs<const int32*>( 344 const int32* location = LocalGetAs<const int32*>(
345 result, input->location_offset, sizeof(int32)); 345 result, input->location_offset, sizeof(int32));
346 const char* name_buf = LocalGetAs<const char*>( 346 const char* name_buf = LocalGetAs<const char*>(
347 result, input->name_offset, input->name_length); 347 result, input->name_offset, input->name_length);
348 std::string name(name_buf, input->name_length); 348 std::string name(name_buf, input->name_length);
349 attrib_infos_.push_back( 349 attrib_infos_.push_back(
350 VertexAttribInfo(input->size, input->type, name, *location)); 350 VertexAttrib(input->size, input->type, name, *location));
351 max_attrib_name_length_ = std::max( 351 max_attrib_name_length_ = std::max(
352 static_cast<GLsizei>(name.size() + 1), max_attrib_name_length_); 352 static_cast<GLsizei>(name.size() + 1), max_attrib_name_length_);
353 ++input; 353 ++input;
354 } 354 }
355 for (uint32 ii = 0; ii < header->num_uniforms; ++ii) { 355 for (uint32 ii = 0; ii < header->num_uniforms; ++ii) {
356 const int32* locations = LocalGetAs<const int32*>( 356 const int32* locations = LocalGetAs<const int32*>(
357 result, input->location_offset, sizeof(int32) * input->size); 357 result, input->location_offset, sizeof(int32) * input->size);
358 const char* name_buf = LocalGetAs<const char*>( 358 const char* name_buf = LocalGetAs<const char*>(
359 result, input->name_offset, input->name_length); 359 result, input->name_offset, input->name_length);
360 std::string name(name_buf, input->name_length); 360 std::string name(name_buf, input->name_length);
(...skipping 11 matching lines...) Expand all
372 cached_ = true; 372 cached_ = true;
373 } 373 }
374 374
375 CachedProgramInfoManager::CachedProgramInfoManager() { 375 CachedProgramInfoManager::CachedProgramInfoManager() {
376 } 376 }
377 377
378 CachedProgramInfoManager::~CachedProgramInfoManager() { 378 CachedProgramInfoManager::~CachedProgramInfoManager() {
379 379
380 } 380 }
381 381
382 CachedProgramInfoManager::ProgramInfo* 382 CachedProgramInfoManager::Program*
383 CachedProgramInfoManager::GetProgramInfo( 383 CachedProgramInfoManager::GetProgramInfo(
384 GLES2Implementation* gl, GLuint program) { 384 GLES2Implementation* gl, GLuint program) {
385 ProgramInfoMap::iterator it = program_infos_.find(program); 385 ProgramInfoMap::iterator it = program_infos_.find(program);
386 if (it == program_infos_.end()) { 386 if (it == program_infos_.end()) {
387 return NULL; 387 return NULL;
388 } 388 }
389 ProgramInfo* info = &it->second; 389 Program* info = &it->second;
390 info->Update(gl, program); 390 info->Update(gl, program);
391 return info; 391 return info;
392 } 392 }
393 393
394 void CachedProgramInfoManager::CreateInfo(GLuint program) { 394 void CachedProgramInfoManager::CreateInfo(GLuint program) {
395 AutoLock auto_lock(lock_); 395 AutoLock auto_lock(lock_);
396 DeleteInfo(program); 396 DeleteInfo(program);
397 std::pair<ProgramInfoMap::iterator, bool> result = 397 std::pair<ProgramInfoMap::iterator, bool> result =
398 program_infos_.insert(std::make_pair(program, ProgramInfo())); 398 program_infos_.insert(std::make_pair(program, Program()));
399 399
400 GPU_DCHECK(result.second); 400 GPU_DCHECK(result.second);
401 } 401 }
402 402
403 void CachedProgramInfoManager::DeleteInfo(GLuint program) { 403 void CachedProgramInfoManager::DeleteInfo(GLuint program) {
404 program_infos_.erase(program); 404 program_infos_.erase(program);
405 } 405 }
406 406
407 bool CachedProgramInfoManager::GetProgramiv( 407 bool CachedProgramInfoManager::GetProgramiv(
408 GLES2Implementation* gl, GLuint program, GLenum pname, GLint* params) { 408 GLES2Implementation* gl, GLuint program, GLenum pname, GLint* params) {
409 AutoLock auto_lock(lock_); 409 AutoLock auto_lock(lock_);
410 ProgramInfo* info = GetProgramInfo(gl, program); 410 Program* info = GetProgramInfo(gl, program);
411 if (!info) { 411 if (!info) {
412 return false; 412 return false;
413 } 413 }
414 return info->GetProgramiv(pname, params); 414 return info->GetProgramiv(pname, params);
415 } 415 }
416 416
417 GLint CachedProgramInfoManager::GetAttribLocation( 417 GLint CachedProgramInfoManager::GetAttribLocation(
418 GLES2Implementation* gl, GLuint program, const char* name) { 418 GLES2Implementation* gl, GLuint program, const char* name) {
419 AutoLock auto_lock(lock_); 419 AutoLock auto_lock(lock_);
420 ProgramInfo* info = GetProgramInfo(gl, program); 420 Program* info = GetProgramInfo(gl, program);
421 if (info) { 421 if (info) {
422 return info->GetAttribLocation(name); 422 return info->GetAttribLocation(name);
423 } 423 }
424 return gl->GetAttribLocationHelper(program, name); 424 return gl->GetAttribLocationHelper(program, name);
425 } 425 }
426 426
427 GLint CachedProgramInfoManager::GetUniformLocation( 427 GLint CachedProgramInfoManager::GetUniformLocation(
428 GLES2Implementation* gl, GLuint program, const char* name) { 428 GLES2Implementation* gl, GLuint program, const char* name) {
429 AutoLock auto_lock(lock_); 429 AutoLock auto_lock(lock_);
430 ProgramInfo* info = GetProgramInfo(gl, program); 430 Program* info = GetProgramInfo(gl, program);
431 if (info) { 431 if (info) {
432 return info->GetUniformLocation(name); 432 return info->GetUniformLocation(name);
433 } 433 }
434 return gl->GetUniformLocationHelper(program, name); 434 return gl->GetUniformLocationHelper(program, name);
435 } 435 }
436 436
437 bool CachedProgramInfoManager::GetActiveAttrib( 437 bool CachedProgramInfoManager::GetActiveAttrib(
438 GLES2Implementation* gl, 438 GLES2Implementation* gl,
439 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, 439 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length,
440 GLint* size, GLenum* type, char* name) { 440 GLint* size, GLenum* type, char* name) {
441 AutoLock auto_lock(lock_); 441 AutoLock auto_lock(lock_);
442 ProgramInfo* info = GetProgramInfo(gl, program); 442 Program* info = GetProgramInfo(gl, program);
443 if (info) { 443 if (info) {
444 const ProgramInfo::VertexAttribInfo* attrib_info = 444 const Program::VertexAttrib* attrib_info =
445 info->GetAttribInfo(index); 445 info->GetAttribInfo(index);
446 if (attrib_info) { 446 if (attrib_info) {
447 if (size) { 447 if (size) {
448 *size = attrib_info->size; 448 *size = attrib_info->size;
449 } 449 }
450 if (type) { 450 if (type) {
451 *type = attrib_info->type; 451 *type = attrib_info->type;
452 } 452 }
453 if (length || name) { 453 if (length || name) {
454 GLsizei max_size = std::min(static_cast<size_t>(bufsize) - 1, 454 GLsizei max_size = std::min(static_cast<size_t>(bufsize) - 1,
(...skipping 12 matching lines...) Expand all
467 } 467 }
468 return gl->GetActiveAttribHelper( 468 return gl->GetActiveAttribHelper(
469 program, index, bufsize, length, size, type, name); 469 program, index, bufsize, length, size, type, name);
470 } 470 }
471 471
472 bool CachedProgramInfoManager::GetActiveUniform( 472 bool CachedProgramInfoManager::GetActiveUniform(
473 GLES2Implementation* gl, 473 GLES2Implementation* gl,
474 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, 474 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length,
475 GLint* size, GLenum* type, char* name) { 475 GLint* size, GLenum* type, char* name) {
476 AutoLock auto_lock(lock_); 476 AutoLock auto_lock(lock_);
477 ProgramInfo* info = GetProgramInfo(gl, program); 477 Program* info = GetProgramInfo(gl, program);
478 if (info) { 478 if (info) {
479 const ProgramInfo::UniformInfo* uniform_info = info->GetUniformInfo(index); 479 const Program::UniformInfo* uniform_info = info->GetUniformInfo(index);
480 if (uniform_info) { 480 if (uniform_info) {
481 if (size) { 481 if (size) {
482 *size = uniform_info->size; 482 *size = uniform_info->size;
483 } 483 }
484 if (type) { 484 if (type) {
485 *type = uniform_info->type; 485 *type = uniform_info->type;
486 } 486 }
487 if (length || name) { 487 if (length || name) {
488 GLsizei max_size = std::min(static_cast<size_t>(bufsize) - 1, 488 GLsizei max_size = std::min(static_cast<size_t>(bufsize) - 1,
489 std::max(static_cast<size_t>(0), 489 std::max(static_cast<size_t>(0),
(...skipping 24 matching lines...) Expand all
514 if (shared_resources_across_processes) { 514 if (shared_resources_across_processes) {
515 return new NonCachedProgramInfoManager(); 515 return new NonCachedProgramInfoManager();
516 } else { 516 } else {
517 return new CachedProgramInfoManager(); 517 return new CachedProgramInfoManager();
518 } 518 }
519 } 519 }
520 520
521 } // namespace gles2 521 } // namespace gles2
522 } // namespace gpu 522 } // namespace gpu
523 523
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation_unittest_autogen.h ('k') | gpu/command_buffer/client/share_group.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698