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_.reset( |
| 300 new ShaderVariableBaseType[manager_->max_draw_buffers()]); |
| 301 ResetFragmentOutputBaseTypes(); |
275 manager_->StartTracking(this); | 302 manager_->StartTracking(this); |
276 } | 303 } |
277 | 304 |
278 void Program::Reset() { | 305 void Program::Reset() { |
279 valid_ = false; | 306 valid_ = false; |
280 link_status_ = false; | 307 link_status_ = false; |
281 max_uniform_name_length_ = 0; | 308 max_uniform_name_length_ = 0; |
282 max_attrib_name_length_ = 0; | 309 max_attrib_name_length_ = 0; |
283 attrib_infos_.clear(); | 310 attrib_infos_.clear(); |
284 uniform_infos_.clear(); | 311 uniform_infos_.clear(); |
285 uniform_locations_.clear(); | 312 uniform_locations_.clear(); |
286 fragment_input_infos_.clear(); | 313 fragment_input_infos_.clear(); |
287 fragment_input_locations_.clear(); | 314 fragment_input_locations_.clear(); |
288 program_output_infos_.clear(); | 315 program_output_infos_.clear(); |
289 sampler_indices_.clear(); | 316 sampler_indices_.clear(); |
290 attrib_location_to_index_map_.clear(); | 317 attrib_location_to_index_map_.clear(); |
| 318 ResetFragmentOutputBaseTypes(); |
| 319 } |
| 320 |
| 321 void Program::ResetFragmentOutputBaseTypes() { |
| 322 for (uint32_t ii = 0; ii < manager_->max_draw_buffers(); ++ii) { |
| 323 fragment_output_base_types_[ii] = SHADER_VARIABLE_UNDEFINED_TYPE; |
| 324 } |
| 325 } |
| 326 |
| 327 void Program::UpdateFragmentOutputBaseTypes() { |
| 328 ResetFragmentOutputBaseTypes(); |
| 329 Shader* fragment_shader = |
| 330 attached_shaders_[ShaderTypeToIndex(GL_FRAGMENT_SHADER)].get(); |
| 331 DCHECK(fragment_shader); |
| 332 for (auto const& output : fragment_shader->output_variable_list()) { |
| 333 DCHECK(output.location == -1 || |
| 334 (output.location >= 0 && |
| 335 output.location < static_cast<int>(manager_->max_draw_buffers()))); |
| 336 if (ProgramManager::HasBuiltInPrefix(output.name)) { |
| 337 if (output.name != "gl_FragColor" && output.name != "gl_FragData") |
| 338 continue; |
| 339 } |
| 340 int draw_buffer = (output.location == -1 ? 0 : output.location); |
| 341 int count = static_cast<int>(output.arraySize == 0 ? 1 : output.arraySize); |
| 342 // TODO(zmo): Handle the special case in ES2 where gl_FragColor could |
| 343 // be broadcasting to all draw buffers. |
| 344 DCHECK_LE(draw_buffer + count, |
| 345 static_cast<int>(manager_->max_draw_buffers())); |
| 346 for (int ii = draw_buffer; ii < draw_buffer + count; ++ii) { |
| 347 DCHECK_EQ(SHADER_VARIABLE_UNDEFINED_TYPE, |
| 348 fragment_output_base_types_[ii]); |
| 349 fragment_output_base_types_[ii] = |
| 350 FragmentOutputTypeToBaseType(output.type); |
| 351 } |
| 352 } |
291 } | 353 } |
292 | 354 |
293 std::string Program::ProcessLogInfo( | 355 std::string Program::ProcessLogInfo( |
294 const std::string& log) { | 356 const std::string& log) { |
295 std::string output; | 357 std::string output; |
296 re2::StringPiece input(log); | 358 re2::StringPiece input(log); |
297 std::string prior_log; | 359 std::string prior_log; |
298 std::string hashed_name; | 360 std::string hashed_name; |
299 while (RE2::Consume(&input, | 361 while (RE2::Consume(&input, |
300 "(.*?)(webgl_[0123456789abcdefABCDEF]+)", | 362 "(.*?)(webgl_[0123456789abcdefABCDEF]+)", |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 for (const UniformInfo& info : uniform_infos_) { | 578 for (const UniformInfo& info : uniform_infos_) { |
517 DVLOG(1) << ii++ << ": loc = " << info.element_locations[0] | 579 DVLOG(1) << ii++ << ": loc = " << info.element_locations[0] |
518 << ", size = " << info.size | 580 << ", size = " << info.size |
519 << ", type = " << GLES2Util::GetStringEnum(info.type) | 581 << ", type = " << GLES2Util::GetStringEnum(info.type) |
520 << ", name = " << info.name; | 582 << ", name = " << info.name; |
521 } | 583 } |
522 } | 584 } |
523 | 585 |
524 UpdateFragmentInputs(); | 586 UpdateFragmentInputs(); |
525 UpdateProgramOutputs(); | 587 UpdateProgramOutputs(); |
| 588 UpdateFragmentOutputBaseTypes(); |
526 | 589 |
527 valid_ = true; | 590 valid_ = true; |
528 } | 591 } |
529 | 592 |
530 void Program::UpdateUniforms() { | 593 void Program::UpdateUniforms() { |
531 // Reserve each client-bound uniform location. This way unbound uniforms will | 594 // 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 | 595 // not be allocated to locations that user expects bound uniforms to be, even |
533 // if the expected uniforms are optimized away by the driver. | 596 // if the expected uniforms are optimized away by the driver. |
534 for (const auto& binding : bind_uniform_location_map_) { | 597 for (const auto& binding : bind_uniform_location_map_) { |
535 if (binding.second < 0) | 598 if (binding.second < 0) |
(...skipping 1707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2243 glDeleteProgram(service_id()); | 2306 glDeleteProgram(service_id()); |
2244 } | 2307 } |
2245 manager_->StopTracking(this); | 2308 manager_->StopTracking(this); |
2246 manager_ = NULL; | 2309 manager_ = NULL; |
2247 } | 2310 } |
2248 } | 2311 } |
2249 | 2312 |
2250 ProgramManager::ProgramManager( | 2313 ProgramManager::ProgramManager( |
2251 ProgramCache* program_cache, | 2314 ProgramCache* program_cache, |
2252 uint32_t max_varying_vectors, | 2315 uint32_t max_varying_vectors, |
| 2316 uint32_t max_draw_buffers, |
2253 uint32_t max_dual_source_draw_buffers, | 2317 uint32_t max_dual_source_draw_buffers, |
2254 const GpuPreferences& gpu_preferences, | 2318 const GpuPreferences& gpu_preferences, |
2255 FeatureInfo* feature_info) | 2319 FeatureInfo* feature_info) |
2256 : program_count_(0), | 2320 : program_count_(0), |
2257 have_context_(true), | 2321 have_context_(true), |
2258 program_cache_(program_cache), | 2322 program_cache_(program_cache), |
2259 max_varying_vectors_(max_varying_vectors), | 2323 max_varying_vectors_(max_varying_vectors), |
| 2324 max_draw_buffers_(max_draw_buffers), |
2260 max_dual_source_draw_buffers_(max_dual_source_draw_buffers), | 2325 max_dual_source_draw_buffers_(max_dual_source_draw_buffers), |
2261 gpu_preferences_(gpu_preferences), | 2326 gpu_preferences_(gpu_preferences), |
2262 feature_info_(feature_info) {} | 2327 feature_info_(feature_info) {} |
2263 | 2328 |
2264 ProgramManager::~ProgramManager() { | 2329 ProgramManager::~ProgramManager() { |
2265 DCHECK(programs_.empty()); | 2330 DCHECK(programs_.empty()); |
2266 } | 2331 } |
2267 | 2332 |
2268 void ProgramManager::Destroy(bool have_context) { | 2333 void ProgramManager::Destroy(bool have_context) { |
2269 have_context_ = have_context; | 2334 have_context_ = have_context; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2366 DCHECK(program); | 2431 DCHECK(program); |
2367 program->ClearUniforms(&zero_); | 2432 program->ClearUniforms(&zero_); |
2368 } | 2433 } |
2369 | 2434 |
2370 int32_t ProgramManager::MakeFakeLocation(int32_t index, int32_t element) { | 2435 int32_t ProgramManager::MakeFakeLocation(int32_t index, int32_t element) { |
2371 return index + element * 0x10000; | 2436 return index + element * 0x10000; |
2372 } | 2437 } |
2373 | 2438 |
2374 } // namespace gles2 | 2439 } // namespace gles2 |
2375 } // namespace gpu | 2440 } // namespace gpu |
OLD | NEW |