From a4e6858b9498682aa929485c95c8ccc71528e1b1 Mon Sep 17 00:00:00 2001
From: dan sinclair <dsinclair@google.com>
Date: Wed, 6 May 2020 21:48:23 +0000
Subject: [PATCH] Remove push constants.

Push constants won't be supported by WebGPU. This CL removes them from
Tint.

For the SPIR-V reader case, this means the push constant will cause a
unknown storage class error.

Bug: tint:19
Change-Id: I10b09ce589b6b370fc828af0cd56e6213c5bc694
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21180
Reviewed-by: David Neto <dneto@google.com>
---
 src/ast/storage_class.cc                         |  4 ----
 src/ast/storage_class.h                          |  1 -
 src/reader/spirv/enum_converter.cc               |  2 --
 src/reader/spirv/enum_converter_test.cc          |  2 --
 .../spirv/parser_impl_convert_type_test.cc       | 16 ----------------
 src/reader/wgsl/lexer.cc                         |  2 --
 src/reader/wgsl/lexer_test.cc                    |  1 -
 src/reader/wgsl/parser_impl.cc                   |  5 -----
 .../wgsl/parser_impl_storage_class_test.cc       |  1 -
 ...rser_impl_variable_storage_decoration_test.cc |  1 -
 src/reader/wgsl/token.cc                         |  2 --
 src/reader/wgsl/token.h                          |  4 ----
 src/writer/spirv/builder.cc                      |  2 --
 src/writer/spirv/builder_type_test.cc            |  1 -
 14 files changed, 44 deletions(-)

diff --git a/src/ast/storage_class.cc b/src/ast/storage_class.cc
index 4545358641..add2597c52 100644
--- a/src/ast/storage_class.cc
+++ b/src/ast/storage_class.cc
@@ -51,10 +51,6 @@ std::ostream& operator<<(std::ostream& out, StorageClass sc) {
       out << "image";
       break;
     }
-    case StorageClass::kPushConstant: {
-      out << "push_constant";
-      break;
-    }
     case StorageClass::kPrivate: {
       out << "private";
       break;
diff --git a/src/ast/storage_class.h b/src/ast/storage_class.h
index 3a25fed92c..2fd13cdda4 100644
--- a/src/ast/storage_class.h
+++ b/src/ast/storage_class.h
@@ -30,7 +30,6 @@ enum class StorageClass {
   kUniformConstant,
   kStorageBuffer,
   kImage,
-  kPushConstant,
   kPrivate,
   kFunction
 };
diff --git a/src/reader/spirv/enum_converter.cc b/src/reader/spirv/enum_converter.cc
index aea3bbf579..26aba0ab06 100644
--- a/src/reader/spirv/enum_converter.cc
+++ b/src/reader/spirv/enum_converter.cc
@@ -54,8 +54,6 @@ ast::StorageClass EnumConverter::ToStorageClass(SpvStorageClass sc) {
       return ast::StorageClass::kStorageBuffer;
     case SpvStorageClassImage:
       return ast::StorageClass::kImage;
-    case SpvStorageClassPushConstant:
-      return ast::StorageClass::kPushConstant;
     case SpvStorageClassPrivate:
       return ast::StorageClass::kPrivate;
     case SpvStorageClassFunction:
diff --git a/src/reader/spirv/enum_converter_test.cc b/src/reader/spirv/enum_converter_test.cc
index 0b2eb759ea..fc9b07646c 100644
--- a/src/reader/spirv/enum_converter_test.cc
+++ b/src/reader/spirv/enum_converter_test.cc
@@ -150,8 +150,6 @@ INSTANTIATE_TEST_SUITE_P(
         StorageClassCase{SpvStorageClassStorageBuffer, true,
                          ast::StorageClass::kStorageBuffer},
         StorageClassCase{SpvStorageClassImage, true, ast::StorageClass::kImage},
-        StorageClassCase{SpvStorageClassPushConstant, true,
-                         ast::StorageClass::kPushConstant},
         StorageClassCase{SpvStorageClassPrivate, true,
                          ast::StorageClass::kPrivate},
         StorageClassCase{SpvStorageClassFunction, true,
diff --git a/src/reader/spirv/parser_impl_convert_type_test.cc b/src/reader/spirv/parser_impl_convert_type_test.cc
index 75746ad818..84e80dbd8a 100644
--- a/src/reader/spirv/parser_impl_convert_type_test.cc
+++ b/src/reader/spirv/parser_impl_convert_type_test.cc
@@ -628,22 +628,6 @@ TEST_F(SpvParserTest, ConvertType_PointerImage) {
   EXPECT_TRUE(p->error().empty());
 }
 
-TEST_F(SpvParserTest, ConvertType_PointerPushConstant) {
-  auto* p = parser(test::Assemble(R"(
-  %float = OpTypeFloat 32
-  %3 = OpTypePointer PushConstant %float
-  )"));
-  EXPECT_TRUE(p->BuildInternalModule());
-
-  auto* type = p->ConvertType(3);
-  EXPECT_TRUE(type->IsPointer());
-  auto* ptr_ty = type->AsPointer();
-  EXPECT_NE(ptr_ty, nullptr);
-  EXPECT_TRUE(ptr_ty->type()->IsF32());
-  EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kPushConstant);
-  EXPECT_TRUE(p->error().empty());
-}
-
 TEST_F(SpvParserTest, ConvertType_PointerPrivate) {
   auto* p = parser(test::Assemble(R"(
   %float = OpTypeFloat 32
diff --git a/src/reader/wgsl/lexer.cc b/src/reader/wgsl/lexer.cc
index d1a6982962..dc70410986 100644
--- a/src/reader/wgsl/lexer.cc
+++ b/src/reader/wgsl/lexer.cc
@@ -602,8 +602,6 @@ Token Lexer::check_keyword(const Source& source, const std::string& str) {
     return {Token::Type::kPrivate, source, "private"};
   if (str == "ptr")
     return {Token::Type::kPtr, source, "ptr"};
-  if (str == "push_constant")
-    return {Token::Type::kPushConstant, source, "push_constant"};
   if (str == "return")
     return {Token::Type::kReturn, source, "return"};
   if (str == "set")
diff --git a/src/reader/wgsl/lexer_test.cc b/src/reader/wgsl/lexer_test.cc
index 71a1109107..aba0eb6d55 100644
--- a/src/reader/wgsl/lexer_test.cc
+++ b/src/reader/wgsl/lexer_test.cc
@@ -476,7 +476,6 @@ INSTANTIATE_TEST_SUITE_P(
         TokenData{"position", Token::Type::kPosition},
         TokenData{"private", Token::Type::kPrivate},
         TokenData{"ptr", Token::Type::kPtr},
-        TokenData{"push_constant", Token::Type::kPushConstant},
         TokenData{"return", Token::Type::kReturn},
         TokenData{"set", Token::Type::kSet},
         TokenData{"storage_buffer", Token::Type::kStorageBuffer},
diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc
index e87aa780bc..be74cec65f 100644
--- a/src/reader/wgsl/parser_impl.cc
+++ b/src/reader/wgsl/parser_impl.cc
@@ -927,7 +927,6 @@ ast::type::Type* ParserImpl::type_decl_matrix(Token t) {
 //  | UNIFORM_CONSTANT
 //  | STORAGE_BUFFER
 //  | IMAGE
-//  | PUSH_CONSTANT
 //  | PRIVATE
 //  | FUNCTION
 ast::StorageClass ParserImpl::storage_class() {
@@ -960,10 +959,6 @@ ast::StorageClass ParserImpl::storage_class() {
     next();  // consume the peek
     return ast::StorageClass::kImage;
   }
-  if (t.IsPushConstant()) {
-    next();  // consume the peek
-    return ast::StorageClass::kPushConstant;
-  }
   if (t.IsPrivate()) {
     next();  // consume the peek
     return ast::StorageClass::kPrivate;
diff --git a/src/reader/wgsl/parser_impl_storage_class_test.cc b/src/reader/wgsl/parser_impl_storage_class_test.cc
index c2de306469..ed3f3587e6 100644
--- a/src/reader/wgsl/parser_impl_storage_class_test.cc
+++ b/src/reader/wgsl/parser_impl_storage_class_test.cc
@@ -73,7 +73,6 @@ INSTANTIATE_TEST_SUITE_P(
                          ast::StorageClass::kUniformConstant},
         StorageClassData{"storage_buffer", ast::StorageClass::kStorageBuffer},
         StorageClassData{"image", ast::StorageClass::kImage},
-        StorageClassData{"push_constant", ast::StorageClass::kPushConstant},
         StorageClassData{"private", ast::StorageClass::kPrivate},
         StorageClassData{"function", ast::StorageClass::kFunction}));
 
diff --git a/src/reader/wgsl/parser_impl_variable_storage_decoration_test.cc b/src/reader/wgsl/parser_impl_variable_storage_decoration_test.cc
index 112df1c0c6..6cbe9cd188 100644
--- a/src/reader/wgsl/parser_impl_variable_storage_decoration_test.cc
+++ b/src/reader/wgsl/parser_impl_variable_storage_decoration_test.cc
@@ -74,7 +74,6 @@ INSTANTIATE_TEST_SUITE_P(
         VariableStorageData{"storage_buffer",
                             ast::StorageClass::kStorageBuffer},
         VariableStorageData{"image", ast::StorageClass::kImage},
-        VariableStorageData{"push_constant", ast::StorageClass::kPushConstant},
         VariableStorageData{"private", ast::StorageClass::kPrivate},
         VariableStorageData{"function", ast::StorageClass::kFunction}));
 
diff --git a/src/reader/wgsl/token.cc b/src/reader/wgsl/token.cc
index fbbc1aa456..16b85e74d4 100644
--- a/src/reader/wgsl/token.cc
+++ b/src/reader/wgsl/token.cc
@@ -241,8 +241,6 @@ std::string Token::TypeToName(Type type) {
       return "private";
     case Token::Type::kPtr:
       return "ptr";
-    case Token::Type::kPushConstant:
-      return "push_constant";
     case Token::Type::kRegardless:
       return "regardless";
     case Token::Type::kReturn:
diff --git a/src/reader/wgsl/token.h b/src/reader/wgsl/token.h
index 418979de4f..3784986c2f 100644
--- a/src/reader/wgsl/token.h
+++ b/src/reader/wgsl/token.h
@@ -252,8 +252,6 @@ class Token {
     kPrivate,
     /// A 'ptr'
     kPtr,
-    /// A 'push_constant'
-    kPushConstant,
     /// A 'regardless'
     kRegardless,
     /// A 'return'
@@ -565,8 +563,6 @@ class Token {
   bool IsPrivate() const { return type_ == Type::kPrivate; }
   /// @returns true if token is a 'ptr'
   bool IsPtr() const { return type_ == Type::kPtr; }
-  /// @returns true if token is a 'push_constant'
-  bool IsPushConstant() const { return type_ == Type::kPushConstant; }
   /// @returns true if token is a 'return'
   bool IsReturn() const { return type_ == Type::kReturn; }
   /// @returns true if token is a 'set'
diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc
index fc205f0110..43e2172347 100644
--- a/src/writer/spirv/builder.cc
+++ b/src/writer/spirv/builder.cc
@@ -1611,8 +1611,6 @@ SpvStorageClass Builder::ConvertStorageClass(ast::StorageClass klass) const {
       return SpvStorageClassStorageBuffer;
     case ast::StorageClass::kImage:
       return SpvStorageClassImage;
-    case ast::StorageClass::kPushConstant:
-      return SpvStorageClassPushConstant;
     case ast::StorageClass::kPrivate:
       return SpvStorageClassPrivate;
     case ast::StorageClass::kFunction:
diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc
index 544ec0273a..b49e987546 100644
--- a/src/writer/spirv/builder_type_test.cc
+++ b/src/writer/spirv/builder_type_test.cc
@@ -498,7 +498,6 @@ INSTANTIATE_TEST_SUITE_P(
         PtrData{ast::StorageClass::kStorageBuffer,
                 SpvStorageClassStorageBuffer},
         PtrData{ast::StorageClass::kImage, SpvStorageClassImage},
-        PtrData{ast::StorageClass::kPushConstant, SpvStorageClassPushConstant},
         PtrData{ast::StorageClass::kPrivate, SpvStorageClassPrivate},
         PtrData{ast::StorageClass::kFunction, SpvStorageClassFunction}));