From eff1fb88fcec547cfc7c83dae33639f4bfe1eb94 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Wed, 4 Nov 2020 22:19:33 +0000 Subject: [PATCH] [wgsl-reader][wgsl-writer] Update storage texture type name. This Cl updates the storage textures to have `storage` in the name. So, `texture_ro_1d` -> `texture_storage_ro_1d` Bug: tint:286 Change-Id: I0a9ea02f15de2681d64e272cb42be51a940b6a13 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31840 Commit-Queue: dan sinclair Commit-Queue: Ryan Harrison Reviewed-by: Ryan Harrison --- src/reader/wgsl/lexer.cc | 40 +++++ src/reader/wgsl/lexer_test.cc | 20 +++ src/reader/wgsl/parser_impl.cc | 10 ++ src/reader/wgsl/parser_impl_error_msg_test.cc | 34 ++++- .../parser_impl_storage_texture_type_test.cc | 143 ++++++++++++++---- .../parser_impl_texture_sampler_types_test.cc | 71 ++++++++- src/reader/wgsl/token.cc | 20 +-- src/reader/wgsl/token.h | 30 ++-- src/writer/wgsl/generator_impl.cc | 3 +- src/writer/wgsl/generator_impl_type_test.cc | 20 +-- 10 files changed, 314 insertions(+), 77 deletions(-) diff --git a/src/reader/wgsl/lexer.cc b/src/reader/wgsl/lexer.cc index a91ff09b84..5fbe325608 100644 --- a/src/reader/wgsl/lexer.cc +++ b/src/reader/wgsl/lexer.cc @@ -735,6 +735,46 @@ Token Lexer::check_keyword(const Source& source, const std::string& str) { return {Token::Type::kTextureSampledCubeArray, source, "texture_sampled_cube_array"}; } + if (str == "texture_storage_ro_1d") { + return {Token::Type::kTextureStorageReadonly1d, source, + "texture_storage_ro_1d"}; + } + if (str == "texture_storage_ro_1d_array") { + return {Token::Type::kTextureStorageReadonly1dArray, source, + "texture_storage_ro_1d_array"}; + } + if (str == "texture_storage_ro_2d") { + return {Token::Type::kTextureStorageReadonly2d, source, + "texture_storage_ro_2d"}; + } + if (str == "texture_storage_ro_2d_array") { + return {Token::Type::kTextureStorageReadonly2dArray, source, + "texture_storage_ro_2d_array"}; + } + if (str == "texture_storage_ro_3d") { + return {Token::Type::kTextureStorageReadonly3d, source, + "texture_storage_ro_3d"}; + } + if (str == "texture_storage_wo_1d") { + return {Token::Type::kTextureStorageWriteonly1d, source, + "texture_storage_wo_1d"}; + } + if (str == "texture_storage_wo_1d_array") { + return {Token::Type::kTextureStorageWriteonly1dArray, source, + "texture_storage_wo_1d_array"}; + } + if (str == "texture_storage_wo_2d") { + return {Token::Type::kTextureStorageWriteonly2d, source, + "texture_storage_wo_2d"}; + } + if (str == "texture_storage_wo_2d_array") { + return {Token::Type::kTextureStorageWriteonly2dArray, source, + "texture_storage_wo_2d_array"}; + } + if (str == "texture_storage_wo_3d") { + return {Token::Type::kTextureStorageWriteonly3d, source, + "texture_storage_wo_3d"}; + } if (str == "texture_wo_1d") return {Token::Type::kTextureStorageWriteonly1d, source, "texture_wo_1d"}; if (str == "texture_wo_1d_array") { diff --git a/src/reader/wgsl/lexer_test.cc b/src/reader/wgsl/lexer_test.cc index 2dcc32505d..1f2d142fa8 100644 --- a/src/reader/wgsl/lexer_test.cc +++ b/src/reader/wgsl/lexer_test.cc @@ -575,6 +575,26 @@ INSTANTIATE_TEST_SUITE_P( TokenData{"texture_ro_2d_array", Token::Type::kTextureStorageReadonly2dArray}, TokenData{"texture_ro_3d", Token::Type::kTextureStorageReadonly3d}, + TokenData{"texture_storage_ro_1d", + Token::Type::kTextureStorageReadonly1d}, + TokenData{"texture_storage_ro_1d_array", + Token::Type::kTextureStorageReadonly1dArray}, + TokenData{"texture_storage_ro_2d", + Token::Type::kTextureStorageReadonly2d}, + TokenData{"texture_storage_ro_2d_array", + Token::Type::kTextureStorageReadonly2dArray}, + TokenData{"texture_storage_ro_3d", + Token::Type::kTextureStorageReadonly3d}, + TokenData{"texture_storage_wo_1d", + Token::Type::kTextureStorageWriteonly1d}, + TokenData{"texture_storage_wo_1d_array", + Token::Type::kTextureStorageWriteonly1dArray}, + TokenData{"texture_storage_wo_2d", + Token::Type::kTextureStorageWriteonly2d}, + TokenData{"texture_storage_wo_2d_array", + Token::Type::kTextureStorageWriteonly2dArray}, + TokenData{"texture_storage_wo_3d", + Token::Type::kTextureStorageWriteonly3d}, TokenData{"texture_sampled_1d", Token::Type::kTextureSampled1d}, TokenData{"texture_sampled_1d_array", Token::Type::kTextureSampled1dArray}, diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index c53354896b..d2497dadc8 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -541,6 +541,16 @@ ast::type::TextureDimension ParserImpl::multisampled_texture_type() { // | TEXTURE_WO_2D // | TEXTURE_WO_2D_ARRAY // | TEXTURE_WO_3D +// | TEXTURE_STORAGE_RO_1D +// | TEXTURE_STORAGE_RO_1D_ARRAY +// | TEXTURE_STORAGE_RO_2D +// | TEXTURE_STORAGE_RO_2D_ARRAY +// | TEXTURE_STORAGE_RO_3D +// | TEXTURE_STORAGE_WO_1D +// | TEXTURE_STORAGE_WO_1D_ARRAY +// | TEXTURE_STORAGE_WO_2D +// | TEXTURE_STORAGE_WO_2D_ARRAY +// | TEXTURE_STORAGE_WO_3D std::pair ParserImpl::storage_texture_type() { if (match(Token::Type::kTextureStorageReadonly1d)) diff --git a/src/reader/wgsl/parser_impl_error_msg_test.cc b/src/reader/wgsl/parser_impl_error_msg_test.cc index 224f658c4b..641c5cc373 100644 --- a/src/reader/wgsl/parser_impl_error_msg_test.cc +++ b/src/reader/wgsl/parser_impl_error_msg_test.cc @@ -595,27 +595,55 @@ TEST_F(ParserImplErrorTest, GlobalDeclMultisampledTextureInvalidSubtype) { " ^\n"); } -TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingLessThan) { +TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingLessThan_Old) { EXPECT("var x : texture_ro_2d;", "test.wgsl:1:23 error: missing '<' for storage texture type\n" "var x : texture_ro_2d;\n" " ^\n"); } -TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingGreaterThan) { +TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingGreaterThan_Old) { EXPECT("var x : texture_ro_2d' for storage texture type\n" "var x : texture_ro_2d;", "test.wgsl:1:23 error: invalid format for storage texture type\n" "var x : texture_ro_2d<1>;\n" " ^\n"); } +TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingLessThan) { + EXPECT("var x : texture_storage_ro_2d;", + "test.wgsl:1:31 error: missing '<' for storage texture type\n" + "var x : texture_storage_ro_2d;\n" + " ^\n"); +} + +TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingGreaterThan) { + EXPECT("var x : texture_storage_ro_2d' for storage texture type\n" + "var x : texture_storage_ro_2d;", + "test.wgsl:1:31 error: invalid format for storage texture type\n" + "var x : texture_storage_ro_2d<>;\n" + " ^\n"); +} + +TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingInvalidSubtype) { + EXPECT("var x : texture_storage_ro_2d<1>;", + "test.wgsl:1:31 error: invalid format for storage texture type\n" + "var x : texture_storage_ro_2d<1>;\n" + " ^\n"); +} + TEST_F(ParserImplErrorTest, GlobalDeclStructDecoMissingStruct) { EXPECT("[[block]];", "test.wgsl:1:10 error: expected declaration after decorations\n" diff --git a/src/reader/wgsl/parser_impl_storage_texture_type_test.cc b/src/reader/wgsl/parser_impl_storage_texture_type_test.cc index 7f40b6dd7c..fd9ba94d86 100644 --- a/src/reader/wgsl/parser_impl_storage_texture_type_test.cc +++ b/src/reader/wgsl/parser_impl_storage_texture_type_test.cc @@ -25,91 +25,170 @@ namespace { TEST_F(ParserImplTest, StorageTextureType_Invalid) { auto* p = parser("abc"); auto t = p->storage_texture_type(); - EXPECT_EQ(t.first, ast::type::TextureDimension::kNone); - EXPECT_EQ(t.second, ast::AccessControl::kReadOnly); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::kNone); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kReadOnly); EXPECT_FALSE(p->has_error()); } -TEST_F(ParserImplTest, StorageTextureType_Readonly1d) { +TEST_F(ParserImplTest, StorageTextureType_Readonly1d_Old) { auto* p = parser("texture_ro_1d"); auto t = p->storage_texture_type(); - EXPECT_EQ(t.first, ast::type::TextureDimension::k1d); - EXPECT_EQ(t.second, ast::AccessControl::kReadOnly); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k1d); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kReadOnly); EXPECT_FALSE(p->has_error()); } -TEST_F(ParserImplTest, StorageTextureType_Readonly1dArray) { +TEST_F(ParserImplTest, StorageTextureType_Readonly1dArray_Old) { auto* p = parser("texture_ro_1d_array"); auto t = p->storage_texture_type(); - EXPECT_EQ(t.first, ast::type::TextureDimension::k1dArray); - EXPECT_EQ(t.second, ast::AccessControl::kReadOnly); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k1dArray); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kReadOnly); EXPECT_FALSE(p->has_error()); } -TEST_F(ParserImplTest, StorageTextureType_Readonly2d) { +TEST_F(ParserImplTest, StorageTextureType_Readonly2d_Old) { auto* p = parser("texture_ro_2d"); auto t = p->storage_texture_type(); - EXPECT_EQ(t.first, ast::type::TextureDimension::k2d); - EXPECT_EQ(t.second, ast::AccessControl::kReadOnly); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k2d); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kReadOnly); EXPECT_FALSE(p->has_error()); } -TEST_F(ParserImplTest, StorageTextureType_Readonly2dArray) { +TEST_F(ParserImplTest, StorageTextureType_Readonly2dArray_Old) { auto* p = parser("texture_ro_2d_array"); auto t = p->storage_texture_type(); - EXPECT_EQ(t.first, ast::type::TextureDimension::k2dArray); - EXPECT_EQ(t.second, ast::AccessControl::kReadOnly); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k2dArray); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kReadOnly); EXPECT_FALSE(p->has_error()); } -TEST_F(ParserImplTest, StorageTextureType_Readonly3d) { +TEST_F(ParserImplTest, StorageTextureType_Readonly3d_Old) { auto* p = parser("texture_ro_3d"); auto t = p->storage_texture_type(); - EXPECT_EQ(t.first, ast::type::TextureDimension::k3d); - EXPECT_EQ(t.second, ast::AccessControl::kReadOnly); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k3d); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kReadOnly); EXPECT_FALSE(p->has_error()); } -TEST_F(ParserImplTest, StorageTextureType_Writeonly1d) { +TEST_F(ParserImplTest, StorageTextureType_Writeonly1d_Old) { auto* p = parser("texture_wo_1d"); auto t = p->storage_texture_type(); - EXPECT_EQ(t.first, ast::type::TextureDimension::k1d); - EXPECT_EQ(t.second, ast::AccessControl::kWriteOnly); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k1d); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kWriteOnly); EXPECT_FALSE(p->has_error()); } -TEST_F(ParserImplTest, StorageTextureType_Writeonly1dArray) { +TEST_F(ParserImplTest, StorageTextureType_Writeonly1dArray_Old) { auto* p = parser("texture_wo_1d_array"); auto t = p->storage_texture_type(); - EXPECT_EQ(t.first, ast::type::TextureDimension::k1dArray); - EXPECT_EQ(t.second, ast::AccessControl::kWriteOnly); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k1dArray); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kWriteOnly); EXPECT_FALSE(p->has_error()); } -TEST_F(ParserImplTest, StorageTextureType_Writeonly2d) { +TEST_F(ParserImplTest, StorageTextureType_Writeonly2d_Old) { auto* p = parser("texture_wo_2d"); auto t = p->storage_texture_type(); - EXPECT_EQ(t.first, ast::type::TextureDimension::k2d); - EXPECT_EQ(t.second, ast::AccessControl::kWriteOnly); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k2d); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kWriteOnly); EXPECT_FALSE(p->has_error()); } -TEST_F(ParserImplTest, StorageTextureType_Writeonly2dArray) { +TEST_F(ParserImplTest, StorageTextureType_Writeonly2dArray_Old) { auto* p = parser("texture_wo_2d_array"); auto t = p->storage_texture_type(); - EXPECT_EQ(t.first, ast::type::TextureDimension::k2dArray); - EXPECT_EQ(t.second, ast::AccessControl::kWriteOnly); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k2dArray); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kWriteOnly); EXPECT_FALSE(p->has_error()); } -TEST_F(ParserImplTest, StorageTextureType_Writeonly3d) { +TEST_F(ParserImplTest, StorageTextureType_Writeonly3d_Old) { auto* p = parser("texture_wo_3d"); auto t = p->storage_texture_type(); - EXPECT_EQ(t.first, ast::type::TextureDimension::k3d); - EXPECT_EQ(t.second, ast::AccessControl::kWriteOnly); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k3d); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kWriteOnly); EXPECT_FALSE(p->has_error()); } +TEST_F(ParserImplTest, StorageTextureType_ro_1d) { + auto* p = parser("texture_storage_ro_1d"); + auto t = p->storage_texture_type(); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k1d); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kReadOnly); + EXPECT_FALSE(p->has_error()); +} + +TEST_F(ParserImplTest, StorageTextureType_ro_1dArray) { + auto* p = parser("texture_storage_ro_1d_array"); + auto t = p->storage_texture_type(); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k1dArray); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kReadOnly); + EXPECT_FALSE(p->has_error()); +} + +TEST_F(ParserImplTest, StorageTextureType_ro_2d) { + auto* p = parser("texture_storage_ro_2d"); + auto t = p->storage_texture_type(); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k2d); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kReadOnly); + EXPECT_FALSE(p->has_error()); +} + +TEST_F(ParserImplTest, StorageTextureType_ro_2dArray) { + auto* p = parser("texture_storage_ro_2d_array"); + auto t = p->storage_texture_type(); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k2dArray); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kReadOnly); + EXPECT_FALSE(p->has_error()); +} + +TEST_F(ParserImplTest, StorageTextureType_ro_3d) { + auto* p = parser("texture_storage_ro_3d"); + auto t = p->storage_texture_type(); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k3d); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kReadOnly); + EXPECT_FALSE(p->has_error()); +} + +TEST_F(ParserImplTest, StorageTextureType_wo_1d) { + auto* p = parser("texture_storage_wo_1d"); + auto t = p->storage_texture_type(); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k1d); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kWriteOnly); + EXPECT_FALSE(p->has_error()); +} + +TEST_F(ParserImplTest, StorageTextureType_wo_1dArray) { + auto* p = parser("texture_storage_wo_1d_array"); + auto t = p->storage_texture_type(); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k1dArray); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kWriteOnly); + EXPECT_FALSE(p->has_error()); +} + +TEST_F(ParserImplTest, StorageTextureType_wo_2d) { + auto* p = parser("texture_storage_wo_2d"); + auto t = p->storage_texture_type(); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k2d); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kWriteOnly); + EXPECT_FALSE(p->has_error()); +} + +TEST_F(ParserImplTest, StorageTextureType_wo_2dArray) { + auto* p = parser("texture_storage_wo_2d_array"); + auto t = p->storage_texture_type(); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k2dArray); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kWriteOnly); + EXPECT_FALSE(p->has_error()); +} + +TEST_F(ParserImplTest, StorageTextureType_wo_3d) { + auto* p = parser("texture_storage_wo_3d"); + auto t = p->storage_texture_type(); + EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k3d); + EXPECT_EQ(std::get<1>(t), ast::AccessControl::kWriteOnly); + EXPECT_FALSE(p->has_error()); +} } // namespace } // namespace wgsl } // namespace reader diff --git a/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc b/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc index 00005ad517..ea04f553db 100644 --- a/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc +++ b/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc @@ -233,7 +233,8 @@ TEST_F(ParserImplTest, EXPECT_EQ(p->error(), "1:28: missing '>' for multisampled texture type"); } -TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Readonly1dR8Unorm) { +TEST_F(ParserImplTest, + TextureSamplerTypes_StorageTexture_Readonly1dR8Unorm_Old) { auto* p = parser("texture_ro_1d"); auto* t = p->texture_sampler_types(); ASSERT_FALSE(p->has_error()) << p->error(); @@ -247,7 +248,8 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Readonly1dR8Unorm) { EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k1d); } -TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR16Float) { +TEST_F(ParserImplTest, + TextureSamplerTypes_StorageTexture_Writeonly2dR16Float_Old) { auto* p = parser("texture_wo_2d"); auto* t = p->texture_sampler_types(); ASSERT_FALSE(p->has_error()) << p->error(); @@ -261,34 +263,91 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR16Float) { EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d); } -TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_InvalidType) { +TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_InvalidType_Old) { auto* p = parser("texture_ro_1d"); auto* t = p->texture_sampler_types(); EXPECT_EQ(t, nullptr); EXPECT_EQ(p->error(), "1:15: invalid format for storage texture type"); } -TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_MissingType) { +TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_MissingType_Old) { auto* p = parser("texture_wo_1d<>"); auto* t = p->texture_sampler_types(); EXPECT_EQ(t, nullptr); EXPECT_EQ(p->error(), "1:15: invalid format for storage texture type"); } -TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_MissingLessThan) { +TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_MissingLessThan_Old) { auto* p = parser("texture_ro_1d"); auto* t = p->texture_sampler_types(); EXPECT_EQ(t, nullptr); EXPECT_EQ(p->error(), "1:14: missing '<' for storage texture type"); } -TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_MissingGreaterThan) { +TEST_F(ParserImplTest, + TextureSamplerTypes_StorageTexture_MissingGreaterThan_Old) { auto* p = parser("texture_wo_1dtexture_sampler_types(); EXPECT_EQ(t, nullptr); EXPECT_EQ(p->error(), "1:22: missing '>' for storage texture type"); } +TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Readonly1dR8Unorm) { + auto* p = parser("texture_storage_ro_1d"); + auto* t = p->texture_sampler_types(); + ASSERT_FALSE(p->has_error()) << p->error(); + ASSERT_NE(t, nullptr); + ASSERT_TRUE(t->IsTexture()); + ASSERT_TRUE(t->AsTexture()->IsStorage()); + EXPECT_EQ(t->AsTexture()->AsStorage()->image_format(), + ast::type::ImageFormat::kR8Unorm); + EXPECT_EQ(t->AsTexture()->AsStorage()->access(), + ast::AccessControl::kReadOnly); + EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k1d); +} + +TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR16Float) { + auto* p = parser("texture_storage_wo_2d"); + auto* t = p->texture_sampler_types(); + ASSERT_FALSE(p->has_error()) << p->error(); + ASSERT_NE(t, nullptr); + ASSERT_TRUE(t->IsTexture()); + ASSERT_TRUE(t->AsTexture()->IsStorage()); + EXPECT_EQ(t->AsTexture()->AsStorage()->image_format(), + ast::type::ImageFormat::kR16Float); + EXPECT_EQ(t->AsTexture()->AsStorage()->access(), + ast::AccessControl::kWriteOnly); + EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d); +} + +TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_InvalidType) { + auto* p = parser("texture_storage_ro_1d"); + auto* t = p->texture_sampler_types(); + EXPECT_EQ(t, nullptr); + EXPECT_EQ(p->error(), "1:23: invalid format for storage texture type"); +} + +TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_MissingType) { + auto* p = parser("texture_storage_ro_1d<>"); + auto* t = p->texture_sampler_types(); + EXPECT_EQ(t, nullptr); + EXPECT_EQ(p->error(), "1:23: invalid format for storage texture type"); +} + +TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_MissingLessThan) { + auto* p = parser("texture_storage_ro_1d"); + auto* t = p->texture_sampler_types(); + EXPECT_EQ(t, nullptr); + EXPECT_EQ(p->error(), "1:22: missing '<' for storage texture type"); +} + +TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_MissingGreaterThan) { + auto* p = parser("texture_storage_ro_1dtexture_sampler_types(); + EXPECT_EQ(t, nullptr); + EXPECT_EQ(p->error(), "1:30: missing '>' for storage texture type"); +} + } // namespace } // namespace wgsl } // namespace reader diff --git a/src/reader/wgsl/token.cc b/src/reader/wgsl/token.cc index 7d4b3df713..4952d20f3f 100644 --- a/src/reader/wgsl/token.cc +++ b/src/reader/wgsl/token.cc @@ -290,15 +290,15 @@ std::string Token::TypeToName(Type type) { case Token::Type::kTextureMultisampled2d: return "texture_multisampled_2d"; case Token::Type::kTextureStorageReadonly1d: - return "texture_ro_1d"; + return "texture_storage_ro_1d"; case Token::Type::kTextureStorageReadonly1dArray: - return "texture_ro_1d_array"; + return "texture_storage_ro_1d_array"; case Token::Type::kTextureStorageReadonly2d: - return "texture_ro_2d"; + return "texture_storage_ro_2d"; case Token::Type::kTextureStorageReadonly2dArray: - return "texture_ro_2d_array"; + return "texture_storage_ro_2d_array"; case Token::Type::kTextureStorageReadonly3d: - return "texture_ro_3d"; + return "texture_storage_ro_3d"; case Token::Type::kTextureSampled1d: return "texture_1d"; case Token::Type::kTextureSampled1dArray: @@ -314,15 +314,15 @@ std::string Token::TypeToName(Type type) { case Token::Type::kTextureSampledCubeArray: return "texture_cube_array"; case Token::Type::kTextureStorageWriteonly1d: - return "texture_wo_1d"; + return "texture_storage_wo_1d"; case Token::Type::kTextureStorageWriteonly1dArray: - return "texture_wo_1d_array"; + return "texture_storage_wo_1d_array"; case Token::Type::kTextureStorageWriteonly2d: - return "texture_wo_2d"; + return "texture_storage_wo_2d"; case Token::Type::kTextureStorageWriteonly2dArray: - return "texture_wo_2d_array"; + return "texture_storage_wo_2d_array"; case Token::Type::kTextureStorageWriteonly3d: - return "texture_wo_3d"; + return "texture_storage_wo_3d"; case Token::Type::kTrue: return "true"; case Token::Type::kType: diff --git a/src/reader/wgsl/token.h b/src/reader/wgsl/token.h index 3f60c387fa..d0b2501a14 100644 --- a/src/reader/wgsl/token.h +++ b/src/reader/wgsl/token.h @@ -300,15 +300,15 @@ class Token { kTextureDepthCubeArray, /// A 'texture_multisampled_2d' kTextureMultisampled2d, - /// A 'texture_ro_1d' + /// A 'texture_storage_ro_1d' kTextureStorageReadonly1d, - /// A 'texture_ro_2d_array' + /// A 'texture_storage_ro_2d_array' kTextureStorageReadonly1dArray, - /// A 'texture_ro_2d' + /// A 'texture_storage_ro_2d' kTextureStorageReadonly2d, - /// A 'texture_ro_2d_array' + /// A 'texture_storage_ro_2d_array' kTextureStorageReadonly2dArray, - /// A 'texture_ro_3d' + /// A 'texture_storage_ro_3d' kTextureStorageReadonly3d, /// A 'texture_1d' kTextureSampled1d, @@ -689,23 +689,23 @@ class Token { bool IsTextureMultisampled2d() const { return type_ == Type::kTextureMultisampled2d; } - /// @returns true if token is a 'texture_ro_1d' + /// @returns true if token is a 'texture_storage_ro_1d' bool IsTextureStorageReadonly1d() const { return type_ == Type::kTextureStorageReadonly1d; } - /// @returns true if token is a 'texture_ro_1d_array' + /// @returns true if token is a 'texture_storage_ro_1d_array' bool IsTextureStorageReadonly1dArray() const { return type_ == Type::kTextureStorageReadonly1dArray; } - /// @returns true if token is a 'texture_ro_2d' + /// @returns true if token is a 'texture_storage_ro_2d' bool IsTextureStorageReadonly2d() const { return type_ == Type::kTextureStorageReadonly2d; } - /// @returns true if token is a 'texture_ro_2d_array' + /// @returns true if token is a 'texture_storage_ro_2d_array' bool IsTextureStorageReadonly2dArray() const { return type_ == Type::kTextureStorageReadonly2dArray; } - /// @returns true if token is a 'texture_ro_3d' + /// @returns true if token is a 'texture_storage_ro_3d' bool IsTextureStorageReadonly3d() const { return type_ == Type::kTextureStorageReadonly3d; } @@ -731,23 +731,23 @@ class Token { bool IsTextureSampledCubeArray() const { return type_ == Type::kTextureSampledCubeArray; } - /// @returns true if token is a 'texture_wo_1d' + /// @returns true if token is a 'texture_storage_wo_1d' bool IsTextureStorageWriteonly1d() const { return type_ == Type::kTextureStorageWriteonly1d; } - /// @returns true if token is a 'texture_wo_1d_array' + /// @returns true if token is a 'texture_storage_wo_1d_array' bool IsTextureStorageWriteonly1dArray() const { return type_ == Type::kTextureStorageWriteonly1dArray; } - /// @returns true if token is a 'texture_wo_2d' + /// @returns true if token is a 'texture_storage_wo_2d' bool IsTextureStorageWriteonly2d() const { return type_ == Type::kTextureStorageWriteonly2d; } - /// @returns true if token is a 'texture_wo_2d_array' + /// @returns true if token is a 'texture_storage_wo_2d_array' bool IsTextureStorageWriteonly2dArray() const { return type_ == Type::kTextureStorageWriteonly2dArray; } - /// @returns true if token is a 'texture_wo_3d' + /// @returns true if token is a 'texture_storage_wo_3d' bool IsTextureStorageWriteonly3d() const { return type_ == Type::kTextureStorageWriteonly3d; } diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index 6e6cdafa38..eee6edb8ca 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -463,8 +463,9 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { } else if (texture->IsMultisampled()) { out_ << "multisampled_"; } else if (texture->IsStorage()) { - auto* storage = texture->AsStorage(); + out_ << "storage_"; + auto* storage = texture->AsStorage(); if (storage->access() == ast::AccessControl::kReadOnly) { out_ << "ro_"; } else if (storage->access() == ast::AccessControl::kWriteOnly) { diff --git a/src/writer/wgsl/generator_impl_type_test.cc b/src/writer/wgsl/generator_impl_type_test.cc index 0566d2193d..ec5d0eefd0 100644 --- a/src/writer/wgsl/generator_impl_type_test.cc +++ b/src/writer/wgsl/generator_impl_type_test.cc @@ -394,38 +394,38 @@ INSTANTIATE_TEST_SUITE_P( testing::Values( StorageTextureData{ ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k1d, - ast::AccessControl::kReadOnly, "texture_ro_1d"}, + ast::AccessControl::kReadOnly, "texture_storage_ro_1d"}, StorageTextureData{ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k1dArray, ast::AccessControl::kReadOnly, - "texture_ro_1d_array"}, + "texture_storage_ro_1d_array"}, StorageTextureData{ ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k2d, - ast::AccessControl::kReadOnly, "texture_ro_2d"}, + ast::AccessControl::kReadOnly, "texture_storage_ro_2d"}, StorageTextureData{ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k2dArray, ast::AccessControl::kReadOnly, - "texture_ro_2d_array"}, + "texture_storage_ro_2d_array"}, StorageTextureData{ ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k3d, - ast::AccessControl::kReadOnly, "texture_ro_3d"}, + ast::AccessControl::kReadOnly, "texture_storage_ro_3d"}, StorageTextureData{ ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k1d, - ast::AccessControl::kWriteOnly, "texture_wo_1d"}, + ast::AccessControl::kWriteOnly, "texture_storage_wo_1d"}, StorageTextureData{ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k1dArray, ast::AccessControl::kWriteOnly, - "texture_wo_1d_array"}, + "texture_storage_wo_1d_array"}, StorageTextureData{ ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k2d, - ast::AccessControl::kWriteOnly, "texture_wo_2d"}, + ast::AccessControl::kWriteOnly, "texture_storage_wo_2d"}, StorageTextureData{ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k2dArray, ast::AccessControl::kWriteOnly, - "texture_wo_2d_array"}, + "texture_storage_wo_2d_array"}, StorageTextureData{ ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k3d, - ast::AccessControl::kWriteOnly, "texture_wo_3d"})); + ast::AccessControl::kWriteOnly, "texture_storage_wo_3d"})); struct ImageFormatData { ast::type::ImageFormat fmt;