| OLD | NEW |
| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 if (hit == varyings.end()) | 110 if (hit == varyings.end()) |
| 111 return false; | 111 return false; |
| 112 return hit->second.isInvariant; | 112 return hit->second.isInvariant; |
| 113 } | 113 } |
| 114 | 114 |
| 115 uint32_t ComputeOffset(const void* start, const void* position) { | 115 uint32_t ComputeOffset(const void* start, const void* position) { |
| 116 return static_cast<const uint8_t*>(position) - | 116 return static_cast<const uint8_t*>(position) - |
| 117 static_cast<const uint8_t*>(start); | 117 static_cast<const uint8_t*>(start); |
| 118 } | 118 } |
| 119 | 119 |
| 120 ShaderVariableBaseType FragmentOutputTypeToBaseType(GLenum type) { |
| 121 switch (type) { |
| 122 case GL_INT: |
| 123 case GL_INT_VEC2: |
| 124 case GL_INT_VEC3: |
| 125 case GL_INT_VEC4: |
| 126 return SHADER_VARIABLE_INT; |
| 127 case GL_UNSIGNED_INT: |
| 128 case GL_UNSIGNED_INT_VEC2: |
| 129 case GL_UNSIGNED_INT_VEC3: |
| 130 case GL_UNSIGNED_INT_VEC4: |
| 131 return SHADER_VARIABLE_UINT; |
| 132 case GL_FLOAT: |
| 133 case GL_FLOAT_VEC2: |
| 134 case GL_FLOAT_VEC3: |
| 135 case GL_FLOAT_VEC4: |
| 136 return SHADER_VARIABLE_FLOAT; |
| 137 default: |
| 138 NOTREACHED(); |
| 139 return SHADER_VARIABLE_UNDEFINED_TYPE; |
| 140 } |
| 141 } |
| 142 |
| 120 } // anonymous namespace. | 143 } // anonymous namespace. |
| 121 | 144 |
| 122 Program::UniformInfo::UniformInfo() | 145 Program::UniformInfo::UniformInfo() |
| 123 : size(0), | 146 : size(0), |
| 124 type(GL_NONE), | 147 type(GL_NONE), |
| 125 accepts_api_type(0), | 148 accepts_api_type(0), |
| 126 fake_location_base(0), | 149 fake_location_base(0), |
| 127 is_array(false) {} | 150 is_array(false) {} |
| 128 | 151 |
| 129 Program::UniformInfo::UniformInfo(const std::string& client_name, | 152 Program::UniformInfo::UniformInfo(const std::string& client_name, |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 : manager_(manager), | 288 : manager_(manager), |
| 266 use_count_(0), | 289 use_count_(0), |
| 267 max_attrib_name_length_(0), | 290 max_attrib_name_length_(0), |
| 268 max_uniform_name_length_(0), | 291 max_uniform_name_length_(0), |
| 269 service_id_(service_id), | 292 service_id_(service_id), |
| 270 deleted_(false), | 293 deleted_(false), |
| 271 valid_(false), | 294 valid_(false), |
| 272 link_status_(false), | 295 link_status_(false), |
| 273 uniforms_cleared_(false), | 296 uniforms_cleared_(false), |
| 274 transform_feedback_buffer_mode_(GL_NONE) { | 297 transform_feedback_buffer_mode_(GL_NONE) { |
| 298 DCHECK(manager_); |
| 299 fragment_output_base_types_.resize(manager_->max_draw_buffers()); |
| 300 ResetFragmentOutputBaseTypes(); |
| 275 manager_->StartTracking(this); | 301 manager_->StartTracking(this); |
| 276 } | 302 } |
| 277 | 303 |
| 278 void Program::Reset() { | 304 void Program::Reset() { |
| 279 valid_ = false; | 305 valid_ = false; |
| 280 link_status_ = false; | 306 link_status_ = false; |
| 281 max_uniform_name_length_ = 0; | 307 max_uniform_name_length_ = 0; |
| 282 max_attrib_name_length_ = 0; | 308 max_attrib_name_length_ = 0; |
| 283 attrib_infos_.clear(); | 309 attrib_infos_.clear(); |
| 284 uniform_infos_.clear(); | 310 uniform_infos_.clear(); |
| 285 uniform_locations_.clear(); | 311 uniform_locations_.clear(); |
| 286 fragment_input_infos_.clear(); | 312 fragment_input_infos_.clear(); |
| 287 fragment_input_locations_.clear(); | 313 fragment_input_locations_.clear(); |
| 288 program_output_infos_.clear(); | 314 program_output_infos_.clear(); |
| 289 sampler_indices_.clear(); | 315 sampler_indices_.clear(); |
| 290 attrib_location_to_index_map_.clear(); | 316 attrib_location_to_index_map_.clear(); |
| 317 ResetFragmentOutputBaseTypes(); |
| 318 } |
| 319 |
| 320 void Program::ResetFragmentOutputBaseTypes() { |
| 321 for (uint32_t ii = 0; ii < fragment_output_base_types_.size(); ++ii) { |
| 322 fragment_output_base_types_[ii] = SHADER_VARIABLE_UNDEFINED_TYPE; |
| 323 } |
| 324 } |
| 325 |
| 326 void Program::UpdateFragmentOutputBaseTypes() { |
| 327 ResetFragmentOutputBaseTypes(); |
| 328 Shader* fragment_shader = |
| 329 attached_shaders_[ShaderTypeToIndex(GL_FRAGMENT_SHADER)].get(); |
| 330 DCHECK(fragment_shader); |
| 331 for (auto const& output : fragment_shader->output_variable_list()) { |
| 332 DCHECK(output.location == -1 || |
| 333 (output.location >= 0 && |
| 334 output.location < static_cast<int>(manager_->max_draw_buffers()))); |
| 335 int draw_buffer = (output.location == -1 ? 0 : output.location); |
| 336 int count = static_cast<int>(output.arraySize == 0 ? 1 : output.arraySize); |
| 337 // TODO(zmo): Handle the special case in ES2 where gl_FragColor could |
| 338 // be broadcasting to all draw buffers. |
| 339 DCHECK_LE(draw_buffer + count, |
| 340 static_cast<int>(manager_->max_draw_buffers())); |
| 341 for (int ii = draw_buffer; ii < draw_buffer + count; ++ii) { |
| 342 DCHECK_EQ(SHADER_VARIABLE_UNDEFINED_TYPE, |
| 343 fragment_output_base_types_[ii]); |
| 344 fragment_output_base_types_[ii] = |
| 345 FragmentOutputTypeToBaseType(output.type); |
| 346 } |
| 347 } |
| 291 } | 348 } |
| 292 | 349 |
| 293 std::string Program::ProcessLogInfo( | 350 std::string Program::ProcessLogInfo( |
| 294 const std::string& log) { | 351 const std::string& log) { |
| 295 std::string output; | 352 std::string output; |
| 296 re2::StringPiece input(log); | 353 re2::StringPiece input(log); |
| 297 std::string prior_log; | 354 std::string prior_log; |
| 298 std::string hashed_name; | 355 std::string hashed_name; |
| 299 while (RE2::Consume(&input, | 356 while (RE2::Consume(&input, |
| 300 "(.*?)(webgl_[0123456789abcdefABCDEF]+)", | 357 "(.*?)(webgl_[0123456789abcdefABCDEF]+)", |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 for (const UniformInfo& info : uniform_infos_) { | 573 for (const UniformInfo& info : uniform_infos_) { |
| 517 DVLOG(1) << ii++ << ": loc = " << info.element_locations[0] | 574 DVLOG(1) << ii++ << ": loc = " << info.element_locations[0] |
| 518 << ", size = " << info.size | 575 << ", size = " << info.size |
| 519 << ", type = " << GLES2Util::GetStringEnum(info.type) | 576 << ", type = " << GLES2Util::GetStringEnum(info.type) |
| 520 << ", name = " << info.name; | 577 << ", name = " << info.name; |
| 521 } | 578 } |
| 522 } | 579 } |
| 523 | 580 |
| 524 UpdateFragmentInputs(); | 581 UpdateFragmentInputs(); |
| 525 UpdateProgramOutputs(); | 582 UpdateProgramOutputs(); |
| 583 UpdateFragmentOutputBaseTypes(); |
| 526 | 584 |
| 527 valid_ = true; | 585 valid_ = true; |
| 528 } | 586 } |
| 529 | 587 |
| 530 void Program::UpdateUniforms() { | 588 void Program::UpdateUniforms() { |
| 531 // Reserve each client-bound uniform location. This way unbound uniforms will | 589 // Reserve each client-bound uniform location. This way unbound uniforms will |
| 532 // not be allocated to locations that user expects bound uniforms to be, even | 590 // not be allocated to locations that user expects bound uniforms to be, even |
| 533 // if the expected uniforms are optimized away by the driver. | 591 // if the expected uniforms are optimized away by the driver. |
| 534 for (const auto& binding : bind_uniform_location_map_) { | 592 for (const auto& binding : bind_uniform_location_map_) { |
| 535 if (binding.second < 0) | 593 if (binding.second < 0) |
| (...skipping 1707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2243 glDeleteProgram(service_id()); | 2301 glDeleteProgram(service_id()); |
| 2244 } | 2302 } |
| 2245 manager_->StopTracking(this); | 2303 manager_->StopTracking(this); |
| 2246 manager_ = NULL; | 2304 manager_ = NULL; |
| 2247 } | 2305 } |
| 2248 } | 2306 } |
| 2249 | 2307 |
| 2250 ProgramManager::ProgramManager( | 2308 ProgramManager::ProgramManager( |
| 2251 ProgramCache* program_cache, | 2309 ProgramCache* program_cache, |
| 2252 uint32_t max_varying_vectors, | 2310 uint32_t max_varying_vectors, |
| 2311 uint32_t max_draw_buffers, |
| 2253 uint32_t max_dual_source_draw_buffers, | 2312 uint32_t max_dual_source_draw_buffers, |
| 2254 const GpuPreferences& gpu_preferences, | 2313 const GpuPreferences& gpu_preferences, |
| 2255 FeatureInfo* feature_info) | 2314 FeatureInfo* feature_info) |
| 2256 : program_count_(0), | 2315 : program_count_(0), |
| 2257 have_context_(true), | 2316 have_context_(true), |
| 2258 program_cache_(program_cache), | 2317 program_cache_(program_cache), |
| 2259 max_varying_vectors_(max_varying_vectors), | 2318 max_varying_vectors_(max_varying_vectors), |
| 2319 max_draw_buffers_(max_draw_buffers), |
| 2260 max_dual_source_draw_buffers_(max_dual_source_draw_buffers), | 2320 max_dual_source_draw_buffers_(max_dual_source_draw_buffers), |
| 2261 gpu_preferences_(gpu_preferences), | 2321 gpu_preferences_(gpu_preferences), |
| 2262 feature_info_(feature_info) {} | 2322 feature_info_(feature_info) {} |
| 2263 | 2323 |
| 2264 ProgramManager::~ProgramManager() { | 2324 ProgramManager::~ProgramManager() { |
| 2265 DCHECK(programs_.empty()); | 2325 DCHECK(programs_.empty()); |
| 2266 } | 2326 } |
| 2267 | 2327 |
| 2268 void ProgramManager::Destroy(bool have_context) { | 2328 void ProgramManager::Destroy(bool have_context) { |
| 2269 have_context_ = have_context; | 2329 have_context_ = have_context; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2366 DCHECK(program); | 2426 DCHECK(program); |
| 2367 program->ClearUniforms(&zero_); | 2427 program->ClearUniforms(&zero_); |
| 2368 } | 2428 } |
| 2369 | 2429 |
| 2370 int32_t ProgramManager::MakeFakeLocation(int32_t index, int32_t element) { | 2430 int32_t ProgramManager::MakeFakeLocation(int32_t index, int32_t element) { |
| 2371 return index + element * 0x10000; | 2431 return index + element * 0x10000; |
| 2372 } | 2432 } |
| 2373 | 2433 |
| 2374 } // namespace gles2 | 2434 } // namespace gles2 |
| 2375 } // namespace gpu | 2435 } // namespace gpu |
| OLD | NEW |