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

Side by Side Diff: gpu/command_buffer/service/program_manager.cc

Issue 2148723004: WebGL 2: make sure VertexAttrib type match the corresponding attrib type in shader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: code clean Created 4 years, 5 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
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 "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
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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 attrib_infos_.clear(); 320 attrib_infos_.clear();
310 uniform_infos_.clear(); 321 uniform_infos_.clear();
311 uniform_locations_.clear(); 322 uniform_locations_.clear();
312 fragment_input_infos_.clear(); 323 fragment_input_infos_.clear();
313 fragment_input_locations_.clear(); 324 fragment_input_locations_.clear();
314 program_output_infos_.clear(); 325 program_output_infos_.clear();
315 sampler_indices_.clear(); 326 sampler_indices_.clear();
316 attrib_location_to_index_map_.clear(); 327 attrib_location_to_index_map_.clear();
317 fragment_output_type_mask_ = 0u; 328 fragment_output_type_mask_ = 0u;
318 fragment_output_written_mask_ = 0u; 329 fragment_output_written_mask_ = 0u;
330 vertex_input_base_type_mask_.clear();
331 vertex_input_type_written_mask_.clear();
319 } 332 }
320 333
321 void Program::UpdateFragmentOutputBaseTypes() { 334 void Program::UpdateFragmentOutputBaseTypes() {
322 fragment_output_type_mask_ = 0u; 335 fragment_output_type_mask_ = 0u;
323 fragment_output_written_mask_ = 0u; 336 fragment_output_written_mask_ = 0u;
324 Shader* fragment_shader = 337 Shader* fragment_shader =
325 attached_shaders_[ShaderTypeToIndex(GL_FRAGMENT_SHADER)].get(); 338 attached_shaders_[ShaderTypeToIndex(GL_FRAGMENT_SHADER)].get();
326 DCHECK(fragment_shader); 339 DCHECK(fragment_shader);
327 for (auto const& output : fragment_shader->output_variable_list()) { 340 for (auto const& output : fragment_shader->output_variable_list()) {
328 int location = output.location; 341 int location = output.location;
(...skipping 15 matching lines...) Expand all
344 // TODO(zmo): This does not work with glBindFragDataLocationIndexed. 357 // TODO(zmo): This does not work with glBindFragDataLocationIndexed.
345 // crbug.com/628010 358 // crbug.com/628010
346 // For example: 359 // For example:
347 // glBindFragDataLocationIndexed(program, loc, 0, "FragData0"); 360 // glBindFragDataLocationIndexed(program, loc, 0, "FragData0");
348 // glBindFragDataLocationIndexed(program, loc, 1, "FragData1"); 361 // glBindFragDataLocationIndexed(program, loc, 1, "FragData1");
349 // The program links OK, but both calling glGetFragDataLocation on both 362 // The program links OK, but both calling glGetFragDataLocation on both
350 // "FragData0" and "FragData1" returns 0. 363 // "FragData0" and "FragData1" returns 0.
351 int shift_bits = ii * 2; 364 int shift_bits = ii * 2;
352 fragment_output_written_mask_ |= 0x3 << shift_bits; 365 fragment_output_written_mask_ |= 0x3 << shift_bits;
353 fragment_output_type_mask_ |= 366 fragment_output_type_mask_ |=
354 FragmentOutputTypeToBaseType(output.type) << shift_bits; 367 InputOutputTypeToBaseType(false, output.type) << shift_bits;
355 } 368 }
356 } 369 }
357 } 370 }
358 371
372 void Program::UpdateVertexInputBaseTypes() {
373 max_vertex_attribs_ = manager_->max_vertex_attribs();
374 uint32_t packed_size = max_vertex_attribs_ / 16;
375 packed_size += (max_vertex_attribs_ % 16 == 0) ? 0 : 1;
376 vertex_input_base_type_mask_.resize(packed_size);
377 vertex_input_type_written_mask_.resize(packed_size);
378
379 for (uint32_t ii = 0; ii < packed_size; ++ii) {
380 vertex_input_type_written_mask_[ii] = 0u;
381 vertex_input_base_type_mask_[ii] = 0u;
382 }
383
384 for (size_t ii = 0; ii < attrib_infos_.size(); ++ii) {
385 DCHECK(ii < max_vertex_attribs_);
386 const VertexAttrib& input = attrib_infos_[ii];
387 if (ProgramManager::HasBuiltInPrefix(input.name)) {
388 continue;
389 }
390 int shift_bits = (input.location % 16) * 2;
391 vertex_input_type_written_mask_[ii / 16] |= 0x3 << shift_bits;
392 vertex_input_base_type_mask_[ii / 16] |=
393 InputOutputTypeToBaseType(true, input.type) << shift_bits;
394 }
395 }
396
359 void Program::UpdateUniformBlockSizeInfo() { 397 void Program::UpdateUniformBlockSizeInfo() {
360 switch (feature_info().context_type()) { 398 switch (feature_info().context_type()) {
361 case CONTEXT_TYPE_OPENGLES2: 399 case CONTEXT_TYPE_OPENGLES2:
362 case CONTEXT_TYPE_WEBGL1: 400 case CONTEXT_TYPE_WEBGL1:
363 // Uniform blocks do not exist in ES2. 401 // Uniform blocks do not exist in ES2.
364 return; 402 return;
365 default: 403 default:
366 break; 404 break;
367 } 405 }
368 406
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 DVLOG(1) << ii++ << ": loc = " << info.element_locations[0] 654 DVLOG(1) << ii++ << ": loc = " << info.element_locations[0]
617 << ", size = " << info.size 655 << ", size = " << info.size
618 << ", type = " << GLES2Util::GetStringEnum(info.type) 656 << ", type = " << GLES2Util::GetStringEnum(info.type)
619 << ", name = " << info.name; 657 << ", name = " << info.name;
620 } 658 }
621 } 659 }
622 660
623 UpdateFragmentInputs(); 661 UpdateFragmentInputs();
624 UpdateProgramOutputs(); 662 UpdateProgramOutputs();
625 UpdateFragmentOutputBaseTypes(); 663 UpdateFragmentOutputBaseTypes();
664 UpdateVertexInputBaseTypes();
626 UpdateUniformBlockSizeInfo(); 665 UpdateUniformBlockSizeInfo();
627 666
628 valid_ = true; 667 valid_ = true;
629 } 668 }
630 669
631 void Program::UpdateUniforms() { 670 void Program::UpdateUniforms() {
632 // Reserve each client-bound uniform location. This way unbound uniforms will 671 // 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 672 // not be allocated to locations that user expects bound uniforms to be, even
634 // if the expected uniforms are optimized away by the driver. 673 // if the expected uniforms are optimized away by the driver.
635 for (const auto& binding : bind_uniform_location_map_) { 674 for (const auto& binding : bind_uniform_location_map_) {
(...skipping 1733 matching lines...) Expand 10 before | Expand all | Expand 10 after
2369 manager_->StopTracking(this); 2408 manager_->StopTracking(this);
2370 manager_ = NULL; 2409 manager_ = NULL;
2371 } 2410 }
2372 } 2411 }
2373 2412
2374 ProgramManager::ProgramManager( 2413 ProgramManager::ProgramManager(
2375 ProgramCache* program_cache, 2414 ProgramCache* program_cache,
2376 uint32_t max_varying_vectors, 2415 uint32_t max_varying_vectors,
2377 uint32_t max_draw_buffers, 2416 uint32_t max_draw_buffers,
2378 uint32_t max_dual_source_draw_buffers, 2417 uint32_t max_dual_source_draw_buffers,
2418 uint32_t max_vertex_attribs,
2379 const GpuPreferences& gpu_preferences, 2419 const GpuPreferences& gpu_preferences,
2380 FeatureInfo* feature_info) 2420 FeatureInfo* feature_info)
2381 : program_count_(0), 2421 : program_count_(0),
2382 have_context_(true), 2422 have_context_(true),
2383 program_cache_(program_cache), 2423 program_cache_(program_cache),
2384 max_varying_vectors_(max_varying_vectors), 2424 max_varying_vectors_(max_varying_vectors),
2385 max_draw_buffers_(max_draw_buffers), 2425 max_draw_buffers_(max_draw_buffers),
2386 max_dual_source_draw_buffers_(max_dual_source_draw_buffers), 2426 max_dual_source_draw_buffers_(max_dual_source_draw_buffers),
2427 max_vertex_attribs_(max_vertex_attribs),
2387 gpu_preferences_(gpu_preferences), 2428 gpu_preferences_(gpu_preferences),
2388 feature_info_(feature_info) {} 2429 feature_info_(feature_info) {}
2389 2430
2390 ProgramManager::~ProgramManager() { 2431 ProgramManager::~ProgramManager() {
2391 DCHECK(programs_.empty()); 2432 DCHECK(programs_.empty());
2392 } 2433 }
2393 2434
2394 void ProgramManager::Destroy(bool have_context) { 2435 void ProgramManager::Destroy(bool have_context) {
2395 have_context_ = have_context; 2436 have_context_ = have_context;
2396 programs_.clear(); 2437 programs_.clear();
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2492 DCHECK(program); 2533 DCHECK(program);
2493 program->ClearUniforms(&zero_); 2534 program->ClearUniforms(&zero_);
2494 } 2535 }
2495 2536
2496 int32_t ProgramManager::MakeFakeLocation(int32_t index, int32_t element) { 2537 int32_t ProgramManager::MakeFakeLocation(int32_t index, int32_t element) {
2497 return index + element * 0x10000; 2538 return index + element * 0x10000;
2498 } 2539 }
2499 2540
2500 } // namespace gles2 2541 } // namespace gles2
2501 } // namespace gpu 2542 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698