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

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: update vertex attrib base type for vertexAttrib{I}Pointer only if the vertex attrib array is enabled 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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) {
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 std::string Program::ProcessLogInfo( 386 std::string Program::ProcessLogInfo(
360 const std::string& log) { 387 const std::string& log) {
361 std::string output; 388 std::string output;
362 re2::StringPiece input(log); 389 re2::StringPiece input(log);
363 std::string prior_log; 390 std::string prior_log;
364 std::string hashed_name; 391 std::string hashed_name;
365 while (RE2::Consume(&input, 392 while (RE2::Consume(&input,
366 "(.*?)(webgl_[0123456789abcdefABCDEF]+)", 393 "(.*?)(webgl_[0123456789abcdefABCDEF]+)",
367 &prior_log, 394 &prior_log,
368 &hashed_name)) { 395 &hashed_name)) {
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 DVLOG(1) << ii++ << ": loc = " << info.element_locations[0] 610 DVLOG(1) << ii++ << ": loc = " << info.element_locations[0]
584 << ", size = " << info.size 611 << ", size = " << info.size
585 << ", type = " << GLES2Util::GetStringEnum(info.type) 612 << ", type = " << GLES2Util::GetStringEnum(info.type)
586 << ", name = " << info.name; 613 << ", name = " << info.name;
587 } 614 }
588 } 615 }
589 616
590 UpdateFragmentInputs(); 617 UpdateFragmentInputs();
591 UpdateProgramOutputs(); 618 UpdateProgramOutputs();
592 UpdateFragmentOutputBaseTypes(); 619 UpdateFragmentOutputBaseTypes();
620 UpdateVertexInputBaseTypes();
593 621
594 valid_ = true; 622 valid_ = true;
595 } 623 }
596 624
597 void Program::UpdateUniforms() { 625 void Program::UpdateUniforms() {
598 // Reserve each client-bound uniform location. This way unbound uniforms will 626 // Reserve each client-bound uniform location. This way unbound uniforms will
599 // not be allocated to locations that user expects bound uniforms to be, even 627 // not be allocated to locations that user expects bound uniforms to be, even
600 // if the expected uniforms are optimized away by the driver. 628 // if the expected uniforms are optimized away by the driver.
601 for (const auto& binding : bind_uniform_location_map_) { 629 for (const auto& binding : bind_uniform_location_map_) {
602 if (binding.second < 0) 630 if (binding.second < 0)
(...skipping 1863 matching lines...) Expand 10 before | Expand all | Expand 10 after
2466 DCHECK(program); 2494 DCHECK(program);
2467 program->ClearUniforms(&zero_); 2495 program->ClearUniforms(&zero_);
2468 } 2496 }
2469 2497
2470 int32_t ProgramManager::MakeFakeLocation(int32_t index, int32_t element) { 2498 int32_t ProgramManager::MakeFakeLocation(int32_t index, int32_t element) {
2471 return index + element * 0x10000; 2499 return index + element * 0x10000;
2472 } 2500 }
2473 2501
2474 } // namespace gles2 2502 } // namespace gles2
2475 } // namespace gpu 2503 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698