| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 for (GLint ii = 0; ii < num_attribs; ++ii) { | 95 for (GLint ii = 0; ii < num_attribs; ++ii) { |
| 96 GLsizei length = 0; | 96 GLsizei length = 0; |
| 97 GLsizei size = 0; | 97 GLsizei size = 0; |
| 98 GLenum type = 0; | 98 GLenum type = 0; |
| 99 glGetActiveAttrib( | 99 glGetActiveAttrib( |
| 100 service_id_, ii, max_len, &length, &size, &type, name_buffer.get()); | 100 service_id_, ii, max_len, &length, &size, &type, name_buffer.get()); |
| 101 DCHECK(max_len == 0 || length < max_len); | 101 DCHECK(max_len == 0 || length < max_len); |
| 102 DCHECK(length == 0 || name_buffer[length] == '\0'); | 102 DCHECK(length == 0 || name_buffer[length] == '\0'); |
| 103 if (!IsInvalidPrefix(name_buffer.get(), length)) { | 103 if (!IsInvalidPrefix(name_buffer.get(), length)) { |
| 104 std::string name; | 104 std::string name; |
| 105 GetCorrectedVariableInfo(false, name_buffer.get(), &name, &size, &type); | 105 std::string original_name; |
| 106 GetCorrectedVariableInfo( |
| 107 false, name_buffer.get(), &name, &original_name, &size, &type); |
| 106 // TODO(gman): Should we check for error? | 108 // TODO(gman): Should we check for error? |
| 107 GLint location = glGetAttribLocation(service_id_, name_buffer.get()); | 109 GLint location = glGetAttribLocation(service_id_, name_buffer.get()); |
| 108 if (location > max_location) { | 110 if (location > max_location) { |
| 109 max_location = location; | 111 max_location = location; |
| 110 } | 112 } |
| 111 attrib_infos_.push_back(VertexAttribInfo(size, type, name, location)); | 113 attrib_infos_.push_back( |
| 112 max_attrib_name_length_ = std::max(max_attrib_name_length_, length); | 114 VertexAttribInfo(size, type, original_name, location)); |
| 115 max_attrib_name_length_ = std::max( |
| 116 max_attrib_name_length_, static_cast<GLsizei>(original_name.size())); |
| 113 } | 117 } |
| 114 } | 118 } |
| 115 | 119 |
| 116 // Create attrib location to index map. | 120 // Create attrib location to index map. |
| 117 attrib_location_to_index_map_.resize(max_location + 1); | 121 attrib_location_to_index_map_.resize(max_location + 1); |
| 118 for (GLint ii = 0; ii <= max_location; ++ii) { | 122 for (GLint ii = 0; ii <= max_location; ++ii) { |
| 119 attrib_location_to_index_map_[ii] = -1; | 123 attrib_location_to_index_map_[ii] = -1; |
| 120 } | 124 } |
| 121 for (size_t ii = 0; ii < attrib_infos_.size(); ++ii) { | 125 for (size_t ii = 0; ii < attrib_infos_.size(); ++ii) { |
| 122 const VertexAttribInfo& info = attrib_infos_[ii]; | 126 const VertexAttribInfo& info = attrib_infos_[ii]; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 135 GLsizei size = 0; | 139 GLsizei size = 0; |
| 136 GLenum type = 0; | 140 GLenum type = 0; |
| 137 glGetActiveUniform( | 141 glGetActiveUniform( |
| 138 service_id_, ii, max_len, &length, &size, &type, name_buffer.get()); | 142 service_id_, ii, max_len, &length, &size, &type, name_buffer.get()); |
| 139 DCHECK(max_len == 0 || length < max_len); | 143 DCHECK(max_len == 0 || length < max_len); |
| 140 DCHECK(length == 0 || name_buffer[length] == '\0'); | 144 DCHECK(length == 0 || name_buffer[length] == '\0'); |
| 141 // TODO(gman): Should we check for error? | 145 // TODO(gman): Should we check for error? |
| 142 if (!IsInvalidPrefix(name_buffer.get(), length)) { | 146 if (!IsInvalidPrefix(name_buffer.get(), length)) { |
| 143 GLint location = glGetUniformLocation(service_id_, name_buffer.get()); | 147 GLint location = glGetUniformLocation(service_id_, name_buffer.get()); |
| 144 std::string name; | 148 std::string name; |
| 145 GetCorrectedVariableInfo(true, name_buffer.get(), &name, &size, &type); | 149 std::string original_name; |
| 146 const UniformInfo* info = AddUniformInfo(size, type, location, name); | 150 GetCorrectedVariableInfo( |
| 151 true, name_buffer.get(), &name, &original_name, &size, &type); |
| 152 const UniformInfo* info = |
| 153 AddUniformInfo(size, type, location, name, original_name); |
| 147 for (size_t jj = 0; jj < info->element_locations.size(); ++jj) { | 154 for (size_t jj = 0; jj < info->element_locations.size(); ++jj) { |
| 148 if (info->element_locations[jj] > max_location) { | 155 if (info->element_locations[jj] > max_location) { |
| 149 max_location = info->element_locations[jj]; | 156 max_location = info->element_locations[jj]; |
| 150 } | 157 } |
| 151 } | 158 } |
| 152 if (info->IsSampler()) { | 159 if (info->IsSampler()) { |
| 153 sampler_indices_.push_back(index); | 160 sampler_indices_.push_back(index); |
| 154 } | 161 } |
| 155 max_uniform_name_length_ = | 162 max_uniform_name_length_ = |
| 156 std::max(max_uniform_name_length_, | 163 std::max(max_uniform_name_length_, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 } | 264 } |
| 258 } | 265 } |
| 259 return NULL; | 266 return NULL; |
| 260 } | 267 } |
| 261 | 268 |
| 262 // Note: This is only valid to call right after a program has been linked | 269 // Note: This is only valid to call right after a program has been linked |
| 263 // successfully. | 270 // successfully. |
| 264 void ProgramManager::ProgramInfo::GetCorrectedVariableInfo( | 271 void ProgramManager::ProgramInfo::GetCorrectedVariableInfo( |
| 265 bool use_uniforms, | 272 bool use_uniforms, |
| 266 const std::string& name, std::string* corrected_name, | 273 const std::string& name, std::string* corrected_name, |
| 274 std::string* original_name, |
| 267 GLsizei* size, GLenum* type) const { | 275 GLsizei* size, GLenum* type) const { |
| 268 DCHECK(corrected_name); | 276 DCHECK(corrected_name); |
| 277 DCHECK(original_name); |
| 269 DCHECK(size); | 278 DCHECK(size); |
| 270 DCHECK(type); | 279 DCHECK(type); |
| 271 const char* kArraySpec = "[0]"; | 280 const char* kArraySpec = "[0]"; |
| 272 for (int jj = 0; jj < 2; ++jj) { | 281 for (int jj = 0; jj < 2; ++jj) { |
| 273 std::string test_name(name + ((jj == 1) ? kArraySpec : "")); | 282 std::string test_name(name + ((jj == 1) ? kArraySpec : "")); |
| 274 for (int ii = 0; ii < kMaxAttachedShaders; ++ii) { | 283 for (int ii = 0; ii < kMaxAttachedShaders; ++ii) { |
| 275 ShaderManager::ShaderInfo* shader_info = attached_shaders_[ii].get(); | 284 ShaderManager::ShaderInfo* shader_info = attached_shaders_[ii].get(); |
| 276 if (shader_info) { | 285 if (shader_info) { |
| 277 const ShaderManager::ShaderInfo::VariableInfo* variable_info = | 286 const ShaderManager::ShaderInfo::VariableInfo* variable_info = |
| 278 use_uniforms ? shader_info->GetUniformInfo(test_name) : | 287 use_uniforms ? shader_info->GetUniformInfo(test_name) : |
| 279 shader_info->GetAttribInfo(test_name); | 288 shader_info->GetAttribInfo(test_name); |
| 280 // Note: There is an assuption here that if an attrib is defined in more | 289 // Note: There is an assuption here that if an attrib is defined in more |
| 281 // than 1 attached shader their types and sizes match. Should we check | 290 // than 1 attached shader their types and sizes match. Should we check |
| 282 // for that case? | 291 // for that case? |
| 283 if (variable_info) { | 292 if (variable_info) { |
| 284 *corrected_name = test_name; | 293 *corrected_name = test_name; |
| 294 *original_name = variable_info->name; |
| 285 *type = variable_info->type; | 295 *type = variable_info->type; |
| 286 *size = variable_info->size; | 296 *size = variable_info->size; |
| 287 return; | 297 return; |
| 288 } | 298 } |
| 289 } | 299 } |
| 290 } | 300 } |
| 291 } | 301 } |
| 292 *corrected_name = name; | 302 *corrected_name = name; |
| 303 *original_name = name; |
| 293 } | 304 } |
| 294 | 305 |
| 295 const ProgramManager::ProgramInfo::UniformInfo* | 306 const ProgramManager::ProgramInfo::UniformInfo* |
| 296 ProgramManager::ProgramInfo::AddUniformInfo( | 307 ProgramManager::ProgramInfo::AddUniformInfo( |
| 297 GLsizei size, GLenum type, GLint location, const std::string& name) { | 308 GLsizei size, GLenum type, GLint location, const std::string& name, |
| 309 const std::string& original_name) { |
| 298 const char* kArraySpec = "[0]"; | 310 const char* kArraySpec = "[0]"; |
| 299 uniform_infos_.push_back(UniformInfo(size, type, name)); | 311 uniform_infos_.push_back(UniformInfo(size, type, original_name)); |
| 300 UniformInfo& info = uniform_infos_.back(); | 312 UniformInfo& info = uniform_infos_.back(); |
| 301 info.element_locations.resize(size); | 313 info.element_locations.resize(size); |
| 302 info.element_locations[0] = location; | 314 info.element_locations[0] = location; |
| 303 DCHECK_GE(size, 0); | 315 DCHECK_GE(size, 0); |
| 304 size_t num_texture_units = info.IsSampler() ? static_cast<size_t>(size) : 0u; | 316 size_t num_texture_units = info.IsSampler() ? static_cast<size_t>(size) : 0u; |
| 305 info.texture_units.clear(); | 317 info.texture_units.clear(); |
| 306 info.texture_units.resize(num_texture_units, 0); | 318 info.texture_units.resize(num_texture_units, 0); |
| 307 | 319 |
| 308 if (size > 1) { | 320 if (size > 1) { |
| 309 // Sadly there is no way to tell if this is an array except if the name | |
| 310 // has an array string or the size > 1. That means an array of size 1 can | |
| 311 // be ambiguous. | |
| 312 // | |
| 313 // For now we just make sure that if the size is > 1 then the name must have | |
| 314 // an array spec. | |
| 315 | |
| 316 // Go through the array element locations looking for a match. | 321 // Go through the array element locations looking for a match. |
| 317 // We can skip the first element because it's the same as the | 322 // We can skip the first element because it's the same as the |
| 318 // the location without the array operators. | 323 // the location without the array operators. |
| 319 size_t array_pos = name.rfind(kArraySpec); | 324 size_t array_pos = name.rfind(kArraySpec); |
| 320 std::string base_name = name; | 325 std::string base_name = name; |
| 321 if (name.size() > 3) { | 326 if (name.size() > 3) { |
| 322 if (array_pos != name.size() - 3) { | 327 if (array_pos != name.size() - 3) { |
| 323 info.name = name + kArraySpec; | 328 info.name = name + kArraySpec; |
| 324 } else { | 329 } else { |
| 325 base_name = name.substr(0, name.size() - 3); | 330 base_name = name.substr(0, name.size() - 3); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 DCHECK(info); | 542 DCHECK(info); |
| 538 DCHECK(IsOwned(info)); | 543 DCHECK(IsOwned(info)); |
| 539 info->DecUseCount(); | 544 info->DecUseCount(); |
| 540 RemoveProgramInfoIfUnused(shader_manager, info); | 545 RemoveProgramInfoIfUnused(shader_manager, info); |
| 541 } | 546 } |
| 542 | 547 |
| 543 } // namespace gles2 | 548 } // namespace gles2 |
| 544 } // namespace gpu | 549 } // namespace gpu |
| 545 | 550 |
| 546 | 551 |
| OLD | NEW |