WebGL 2: make sure VertexAttrib type match the corresponding attrib type in shader.
Fix bugs in attrib-type-match.html

BUG=628459
TEST=conformance2/rendering/attrib-type-match.html
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel

Review-Url: https://codereview.chromium.org/2148723004
Cr-Commit-Position: refs/heads/master@{#407168}
diff --git a/gpu/command_buffer/service/context_state.h b/gpu/command_buffer/service/context_state.h
index d026df9a..a8f573a 100644
--- a/gpu/command_buffer/service/context_state.h
+++ b/gpu/command_buffer/service/context_state.h
@@ -243,6 +243,31 @@
   void SetBoundBuffer(GLenum target, Buffer* buffer);
   void RemoveBoundBuffer(Buffer* buffer);
 
+  void InitGenericAttribBaseType(GLuint max_vertex_attribs) {
+      max_vertex_attribs_ = max_vertex_attribs;
+
+      uint32_t packed_size = max_vertex_attribs_ / 16;
+      packed_size += (max_vertex_attribs_ % 16 == 0) ? 0 : 1;
+      generic_attrib_base_type_mask_.resize(packed_size);
+      for (uint32_t i = 0; i < packed_size; ++i) {
+        generic_attrib_base_type_mask_[i] = 0xFFFFFFFF;
+      }
+  }
+
+  void SetGenericVertexAttribBaseType(GLuint index, GLenum base_type) {
+    DCHECK(index < max_vertex_attribs_);
+    int shift_bits = (index % 16) * 2;
+    generic_attrib_base_type_mask_[index / 16] &= ~(0x3 << shift_bits);
+    generic_attrib_base_type_mask_[index / 16] |= (base_type << shift_bits);
+  }
+
+  // Return 16 attributes' base types, in which the generic attribute
+  // specified by argument 'index' located.
+  uint32_t GetGenericVertexAttribBaseTypeMask(GLuint index) {
+    DCHECK(index < max_vertex_attribs_);
+    return generic_attrib_base_type_mask_[index / 16];
+  }
+
   void UnbindTexture(TextureRef* texture);
   void UnbindSampler(Sampler* sampler);
 
@@ -320,6 +345,12 @@
 
   bool framebuffer_srgb_;
 
+  uint32_t max_vertex_attribs_;
+  // Generic vertex attrib base types: FLOAT, INT, or UINT.
+  // Each base type is encoded into 2 bits, the lowest 2 bits for location 0,
+  // the highest 2 bits for location (max_vertex_attribs_ - 1).
+  std::vector<uint32_t> generic_attrib_base_type_mask_;
+
   FeatureInfo* feature_info_;
   std::unique_ptr<ErrorState> error_state_;
 };