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) { | 120 ShaderVariableBaseType InputOutputTypeToBaseType(bool is_input, GLenum type) { |
121 switch (type) { | 121 switch (type) { |
122 case GL_INT: | 122 case GL_INT: |
123 case GL_INT_VEC2: | 123 case GL_INT_VEC2: |
124 case GL_INT_VEC3: | 124 case GL_INT_VEC3: |
125 case GL_INT_VEC4: | 125 case GL_INT_VEC4: |
126 return SHADER_VARIABLE_INT; | 126 return SHADER_VARIABLE_INT; |
127 case GL_UNSIGNED_INT: | 127 case GL_UNSIGNED_INT: |
128 case GL_UNSIGNED_INT_VEC2: | 128 case GL_UNSIGNED_INT_VEC2: |
129 case GL_UNSIGNED_INT_VEC3: | 129 case GL_UNSIGNED_INT_VEC3: |
130 case GL_UNSIGNED_INT_VEC4: | 130 case GL_UNSIGNED_INT_VEC4: |
131 return SHADER_VARIABLE_UINT; | 131 return SHADER_VARIABLE_UINT; |
132 case GL_FLOAT: | 132 case GL_FLOAT: |
133 case GL_FLOAT_VEC2: | 133 case GL_FLOAT_VEC2: |
134 case GL_FLOAT_VEC3: | 134 case GL_FLOAT_VEC3: |
135 case GL_FLOAT_VEC4: | 135 case GL_FLOAT_VEC4: |
136 return SHADER_VARIABLE_FLOAT; | 136 return SHADER_VARIABLE_FLOAT; |
137 case GL_FLOAT_MAT2: | |
138 case GL_FLOAT_MAT3: | |
139 case GL_FLOAT_MAT4: | |
140 case GL_FLOAT_MAT2x3: | |
141 case GL_FLOAT_MAT3x2: | |
142 case GL_FLOAT_MAT2x4: | |
143 case GL_FLOAT_MAT4x2: | |
144 case GL_FLOAT_MAT3x4: | |
145 case GL_FLOAT_MAT4x3: | |
146 DCHECK(is_input); | |
147 return SHADER_VARIABLE_FLOAT; | |
137 default: | 148 default: |
138 NOTREACHED(); | 149 NOTREACHED(); |
139 return SHADER_VARIABLE_UNDEFINED_TYPE; | 150 return SHADER_VARIABLE_UNDEFINED_TYPE; |
140 } | 151 } |
141 } | 152 } |
142 | 153 |
143 } // anonymous namespace. | 154 } // anonymous namespace. |
144 | 155 |
145 Program::UniformInfo::UniformInfo() | 156 Program::UniformInfo::UniformInfo() |
146 : size(0), | 157 : size(0), |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 use_count_(0), | 300 use_count_(0), |
290 max_attrib_name_length_(0), | 301 max_attrib_name_length_(0), |
291 max_uniform_name_length_(0), | 302 max_uniform_name_length_(0), |
292 service_id_(service_id), | 303 service_id_(service_id), |
293 deleted_(false), | 304 deleted_(false), |
294 valid_(false), | 305 valid_(false), |
295 link_status_(false), | 306 link_status_(false), |
296 uniforms_cleared_(false), | 307 uniforms_cleared_(false), |
297 transform_feedback_buffer_mode_(GL_NONE), | 308 transform_feedback_buffer_mode_(GL_NONE), |
298 fragment_output_type_mask_(0u), | 309 fragment_output_type_mask_(0u), |
299 fragment_output_written_mask_(0u) { | 310 fragment_output_written_mask_(0u), |
311 vertex_input_type_mask_(0u), | |
312 vertex_input_written_mask_(0u) { | |
300 DCHECK(manager_); | 313 DCHECK(manager_); |
301 manager_->StartTracking(this); | 314 manager_->StartTracking(this); |
302 } | 315 } |
303 | 316 |
304 void Program::Reset() { | 317 void Program::Reset() { |
305 valid_ = false; | 318 valid_ = false; |
306 link_status_ = false; | 319 link_status_ = false; |
307 max_uniform_name_length_ = 0; | 320 max_uniform_name_length_ = 0; |
308 max_attrib_name_length_ = 0; | 321 max_attrib_name_length_ = 0; |
309 attrib_infos_.clear(); | 322 attrib_infos_.clear(); |
310 uniform_infos_.clear(); | 323 uniform_infos_.clear(); |
311 uniform_locations_.clear(); | 324 uniform_locations_.clear(); |
312 fragment_input_infos_.clear(); | 325 fragment_input_infos_.clear(); |
313 fragment_input_locations_.clear(); | 326 fragment_input_locations_.clear(); |
314 program_output_infos_.clear(); | 327 program_output_infos_.clear(); |
315 sampler_indices_.clear(); | 328 sampler_indices_.clear(); |
316 attrib_location_to_index_map_.clear(); | 329 attrib_location_to_index_map_.clear(); |
317 fragment_output_type_mask_ = 0u; | 330 fragment_output_type_mask_ = 0u; |
318 fragment_output_written_mask_ = 0u; | 331 fragment_output_written_mask_ = 0u; |
332 vertex_input_type_mask_ = 0u; | |
333 vertex_input_written_mask_ = 0u; | |
319 } | 334 } |
320 | 335 |
321 void Program::UpdateFragmentOutputBaseTypes() { | 336 void Program::UpdateFragmentOutputBaseTypes() { |
322 fragment_output_type_mask_ = 0u; | 337 fragment_output_type_mask_ = 0u; |
323 fragment_output_written_mask_ = 0u; | 338 fragment_output_written_mask_ = 0u; |
324 Shader* fragment_shader = | 339 Shader* fragment_shader = |
325 attached_shaders_[ShaderTypeToIndex(GL_FRAGMENT_SHADER)].get(); | 340 attached_shaders_[ShaderTypeToIndex(GL_FRAGMENT_SHADER)].get(); |
326 DCHECK(fragment_shader); | 341 DCHECK(fragment_shader); |
327 for (auto const& output : fragment_shader->output_variable_list()) { | 342 for (auto const& output : fragment_shader->output_variable_list()) { |
328 int location = output.location; | 343 int location = output.location; |
(...skipping 15 matching lines...) Expand all Loading... | |
344 // TODO(zmo): This does not work with glBindFragDataLocationIndexed. | 359 // TODO(zmo): This does not work with glBindFragDataLocationIndexed. |
345 // crbug.com/628010 | 360 // crbug.com/628010 |
346 // For example: | 361 // For example: |
347 // glBindFragDataLocationIndexed(program, loc, 0, "FragData0"); | 362 // glBindFragDataLocationIndexed(program, loc, 0, "FragData0"); |
348 // glBindFragDataLocationIndexed(program, loc, 1, "FragData1"); | 363 // glBindFragDataLocationIndexed(program, loc, 1, "FragData1"); |
349 // The program links OK, but both calling glGetFragDataLocation on both | 364 // The program links OK, but both calling glGetFragDataLocation on both |
350 // "FragData0" and "FragData1" returns 0. | 365 // "FragData0" and "FragData1" returns 0. |
351 int shift_bits = ii * 2; | 366 int shift_bits = ii * 2; |
352 fragment_output_written_mask_ |= 0x3 << shift_bits; | 367 fragment_output_written_mask_ |= 0x3 << shift_bits; |
353 fragment_output_type_mask_ |= | 368 fragment_output_type_mask_ |= |
354 FragmentOutputTypeToBaseType(output.type) << shift_bits; | 369 InputOutputTypeToBaseType(false, output.type) << shift_bits; |
355 } | 370 } |
356 } | 371 } |
357 } | 372 } |
358 | 373 |
374 void Program::UpdateVertexInputBaseTypes() { | |
375 vertex_input_type_mask_ = 0u; | |
376 vertex_input_written_mask_ = 0u; | |
377 for (size_t ii = 0; ii < attrib_infos_.size(); ++ii) { | |
Zhenyao Mo
2016/07/21 13:10:46
See, if size() > 16, your code will be wrong.
yunchao
2016/07/22 13:43:54
Acknowledged.
| |
378 const VertexAttrib& input = attrib_infos_[ii]; | |
379 int shift_bits = input.location * 2; | |
380 vertex_input_written_mask_ |= 0x3 << shift_bits; | |
381 vertex_input_type_mask_ |= | |
382 InputOutputTypeToBaseType(true, input.type) << shift_bits; | |
383 } | |
384 } | |
385 | |
359 void Program::UpdateUniformBlockSizeInfo() { | 386 void Program::UpdateUniformBlockSizeInfo() { |
360 switch (feature_info().context_type()) { | 387 switch (feature_info().context_type()) { |
361 case CONTEXT_TYPE_OPENGLES2: | 388 case CONTEXT_TYPE_OPENGLES2: |
362 case CONTEXT_TYPE_WEBGL1: | 389 case CONTEXT_TYPE_WEBGL1: |
363 // Uniform blocks do not exist in ES2. | 390 // Uniform blocks do not exist in ES2. |
364 return; | 391 return; |
365 default: | 392 default: |
366 break; | 393 break; |
367 } | 394 } |
368 | 395 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
616 DVLOG(1) << ii++ << ": loc = " << info.element_locations[0] | 643 DVLOG(1) << ii++ << ": loc = " << info.element_locations[0] |
617 << ", size = " << info.size | 644 << ", size = " << info.size |
618 << ", type = " << GLES2Util::GetStringEnum(info.type) | 645 << ", type = " << GLES2Util::GetStringEnum(info.type) |
619 << ", name = " << info.name; | 646 << ", name = " << info.name; |
620 } | 647 } |
621 } | 648 } |
622 | 649 |
623 UpdateFragmentInputs(); | 650 UpdateFragmentInputs(); |
624 UpdateProgramOutputs(); | 651 UpdateProgramOutputs(); |
625 UpdateFragmentOutputBaseTypes(); | 652 UpdateFragmentOutputBaseTypes(); |
653 UpdateVertexInputBaseTypes(); | |
626 UpdateUniformBlockSizeInfo(); | 654 UpdateUniformBlockSizeInfo(); |
627 | 655 |
628 valid_ = true; | 656 valid_ = true; |
629 } | 657 } |
630 | 658 |
631 void Program::UpdateUniforms() { | 659 void Program::UpdateUniforms() { |
632 // Reserve each client-bound uniform location. This way unbound uniforms will | 660 // Reserve each client-bound uniform location. This way unbound uniforms will |
633 // not be allocated to locations that user expects bound uniforms to be, even | 661 // not be allocated to locations that user expects bound uniforms to be, even |
634 // if the expected uniforms are optimized away by the driver. | 662 // if the expected uniforms are optimized away by the driver. |
635 for (const auto& binding : bind_uniform_location_map_) { | 663 for (const auto& binding : bind_uniform_location_map_) { |
(...skipping 1856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2492 DCHECK(program); | 2520 DCHECK(program); |
2493 program->ClearUniforms(&zero_); | 2521 program->ClearUniforms(&zero_); |
2494 } | 2522 } |
2495 | 2523 |
2496 int32_t ProgramManager::MakeFakeLocation(int32_t index, int32_t element) { | 2524 int32_t ProgramManager::MakeFakeLocation(int32_t index, int32_t element) { |
2497 return index + element * 0x10000; | 2525 return index + element * 0x10000; |
2498 } | 2526 } |
2499 | 2527 |
2500 } // namespace gles2 | 2528 } // namespace gles2 |
2501 } // namespace gpu | 2529 } // namespace gpu |
OLD | NEW |