[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 <dsinclair@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
dan sinclair 2020-11-04 22:19:33 +00:00 committed by Commit Bot service account
parent 88dc2a4895
commit eff1fb88fc
10 changed files with 314 additions and 77 deletions

View File

@ -735,6 +735,46 @@ Token Lexer::check_keyword(const Source& source, const std::string& str) {
return {Token::Type::kTextureSampledCubeArray, source, return {Token::Type::kTextureSampledCubeArray, source,
"texture_sampled_cube_array"}; "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") if (str == "texture_wo_1d")
return {Token::Type::kTextureStorageWriteonly1d, source, "texture_wo_1d"}; return {Token::Type::kTextureStorageWriteonly1d, source, "texture_wo_1d"};
if (str == "texture_wo_1d_array") { if (str == "texture_wo_1d_array") {

View File

@ -575,6 +575,26 @@ INSTANTIATE_TEST_SUITE_P(
TokenData{"texture_ro_2d_array", TokenData{"texture_ro_2d_array",
Token::Type::kTextureStorageReadonly2dArray}, Token::Type::kTextureStorageReadonly2dArray},
TokenData{"texture_ro_3d", Token::Type::kTextureStorageReadonly3d}, 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", Token::Type::kTextureSampled1d},
TokenData{"texture_sampled_1d_array", TokenData{"texture_sampled_1d_array",
Token::Type::kTextureSampled1dArray}, Token::Type::kTextureSampled1dArray},

View File

@ -541,6 +541,16 @@ ast::type::TextureDimension ParserImpl::multisampled_texture_type() {
// | TEXTURE_WO_2D // | TEXTURE_WO_2D
// | TEXTURE_WO_2D_ARRAY // | TEXTURE_WO_2D_ARRAY
// | TEXTURE_WO_3D // | 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<ast::type::TextureDimension, ast::AccessControl> std::pair<ast::type::TextureDimension, ast::AccessControl>
ParserImpl::storage_texture_type() { ParserImpl::storage_texture_type() {
if (match(Token::Type::kTextureStorageReadonly1d)) if (match(Token::Type::kTextureStorageReadonly1d))

View File

@ -595,27 +595,55 @@ TEST_F(ParserImplErrorTest, GlobalDeclMultisampledTextureInvalidSubtype) {
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingLessThan) { TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingLessThan_Old) {
EXPECT("var x : texture_ro_2d;", EXPECT("var x : texture_ro_2d;",
"test.wgsl:1:23 error: missing '<' for storage texture type\n" "test.wgsl:1:23 error: missing '<' for storage texture type\n"
"var x : texture_ro_2d;\n" "var x : texture_ro_2d;\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingGreaterThan) { TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingGreaterThan_Old) {
EXPECT("var x : texture_ro_2d<r8uint;", EXPECT("var x : texture_ro_2d<r8uint;",
"test.wgsl:1:30 error: missing '>' for storage texture type\n" "test.wgsl:1:30 error: missing '>' for storage texture type\n"
"var x : texture_ro_2d<r8uint;\n" "var x : texture_ro_2d<r8uint;\n"
" ^\n"); " ^\n");
} }
TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingInvalidSubtype) { TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingInvalidSubtype_Old) {
EXPECT("var x : texture_ro_2d<1>;", EXPECT("var x : texture_ro_2d<1>;",
"test.wgsl:1:23 error: invalid format for storage texture type\n" "test.wgsl:1:23 error: invalid format for storage texture type\n"
"var x : texture_ro_2d<1>;\n" "var x : texture_ro_2d<1>;\n"
" ^\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<r8uint;",
"test.wgsl:1:38 error: missing '>' for storage texture type\n"
"var x : texture_storage_ro_2d<r8uint;\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingSubtype) {
EXPECT("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) { TEST_F(ParserImplErrorTest, GlobalDeclStructDecoMissingStruct) {
EXPECT("[[block]];", EXPECT("[[block]];",
"test.wgsl:1:10 error: expected declaration after decorations\n" "test.wgsl:1:10 error: expected declaration after decorations\n"

View File

@ -25,91 +25,170 @@ namespace {
TEST_F(ParserImplTest, StorageTextureType_Invalid) { TEST_F(ParserImplTest, StorageTextureType_Invalid) {
auto* p = parser("abc"); auto* p = parser("abc");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::kNone); EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::kNone);
EXPECT_EQ(t.second, ast::AccessControl::kReadOnly); EXPECT_EQ(std::get<1>(t), ast::AccessControl::kReadOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
TEST_F(ParserImplTest, StorageTextureType_Readonly1d) { TEST_F(ParserImplTest, StorageTextureType_Readonly1d_Old) {
auto* p = parser("texture_ro_1d"); auto* p = parser("texture_ro_1d");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::k1d); EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k1d);
EXPECT_EQ(t.second, ast::AccessControl::kReadOnly); EXPECT_EQ(std::get<1>(t), ast::AccessControl::kReadOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
TEST_F(ParserImplTest, StorageTextureType_Readonly1dArray) { TEST_F(ParserImplTest, StorageTextureType_Readonly1dArray_Old) {
auto* p = parser("texture_ro_1d_array"); auto* p = parser("texture_ro_1d_array");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::k1dArray); EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k1dArray);
EXPECT_EQ(t.second, ast::AccessControl::kReadOnly); EXPECT_EQ(std::get<1>(t), ast::AccessControl::kReadOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
TEST_F(ParserImplTest, StorageTextureType_Readonly2d) { TEST_F(ParserImplTest, StorageTextureType_Readonly2d_Old) {
auto* p = parser("texture_ro_2d"); auto* p = parser("texture_ro_2d");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::k2d); EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k2d);
EXPECT_EQ(t.second, ast::AccessControl::kReadOnly); EXPECT_EQ(std::get<1>(t), ast::AccessControl::kReadOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
TEST_F(ParserImplTest, StorageTextureType_Readonly2dArray) { TEST_F(ParserImplTest, StorageTextureType_Readonly2dArray_Old) {
auto* p = parser("texture_ro_2d_array"); auto* p = parser("texture_ro_2d_array");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::k2dArray); EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k2dArray);
EXPECT_EQ(t.second, ast::AccessControl::kReadOnly); EXPECT_EQ(std::get<1>(t), ast::AccessControl::kReadOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
TEST_F(ParserImplTest, StorageTextureType_Readonly3d) { TEST_F(ParserImplTest, StorageTextureType_Readonly3d_Old) {
auto* p = parser("texture_ro_3d"); auto* p = parser("texture_ro_3d");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::k3d); EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k3d);
EXPECT_EQ(t.second, ast::AccessControl::kReadOnly); EXPECT_EQ(std::get<1>(t), ast::AccessControl::kReadOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
TEST_F(ParserImplTest, StorageTextureType_Writeonly1d) { TEST_F(ParserImplTest, StorageTextureType_Writeonly1d_Old) {
auto* p = parser("texture_wo_1d"); auto* p = parser("texture_wo_1d");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::k1d); EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k1d);
EXPECT_EQ(t.second, ast::AccessControl::kWriteOnly); EXPECT_EQ(std::get<1>(t), ast::AccessControl::kWriteOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
TEST_F(ParserImplTest, StorageTextureType_Writeonly1dArray) { TEST_F(ParserImplTest, StorageTextureType_Writeonly1dArray_Old) {
auto* p = parser("texture_wo_1d_array"); auto* p = parser("texture_wo_1d_array");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::k1dArray); EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k1dArray);
EXPECT_EQ(t.second, ast::AccessControl::kWriteOnly); EXPECT_EQ(std::get<1>(t), ast::AccessControl::kWriteOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
TEST_F(ParserImplTest, StorageTextureType_Writeonly2d) { TEST_F(ParserImplTest, StorageTextureType_Writeonly2d_Old) {
auto* p = parser("texture_wo_2d"); auto* p = parser("texture_wo_2d");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::k2d); EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k2d);
EXPECT_EQ(t.second, ast::AccessControl::kWriteOnly); EXPECT_EQ(std::get<1>(t), ast::AccessControl::kWriteOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
TEST_F(ParserImplTest, StorageTextureType_Writeonly2dArray) { TEST_F(ParserImplTest, StorageTextureType_Writeonly2dArray_Old) {
auto* p = parser("texture_wo_2d_array"); auto* p = parser("texture_wo_2d_array");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::k2dArray); EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k2dArray);
EXPECT_EQ(t.second, ast::AccessControl::kWriteOnly); EXPECT_EQ(std::get<1>(t), ast::AccessControl::kWriteOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
TEST_F(ParserImplTest, StorageTextureType_Writeonly3d) { TEST_F(ParserImplTest, StorageTextureType_Writeonly3d_Old) {
auto* p = parser("texture_wo_3d"); auto* p = parser("texture_wo_3d");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::k3d); EXPECT_EQ(std::get<0>(t), ast::type::TextureDimension::k3d);
EXPECT_EQ(t.second, ast::AccessControl::kWriteOnly); EXPECT_EQ(std::get<1>(t), ast::AccessControl::kWriteOnly);
EXPECT_FALSE(p->has_error()); 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
} // namespace wgsl } // namespace wgsl
} // namespace reader } // namespace reader

View File

@ -233,7 +233,8 @@ TEST_F(ParserImplTest,
EXPECT_EQ(p->error(), "1:28: missing '>' for multisampled texture type"); 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<r8unorm>"); auto* p = parser("texture_ro_1d<r8unorm>");
auto* t = p->texture_sampler_types(); auto* t = p->texture_sampler_types();
ASSERT_FALSE(p->has_error()) << p->error(); 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); 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<r16float>"); auto* p = parser("texture_wo_2d<r16float>");
auto* t = p->texture_sampler_types(); auto* t = p->texture_sampler_types();
ASSERT_FALSE(p->has_error()) << p->error(); 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); 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<abc>"); auto* p = parser("texture_ro_1d<abc>");
auto* t = p->texture_sampler_types(); auto* t = p->texture_sampler_types();
EXPECT_EQ(t, nullptr); EXPECT_EQ(t, nullptr);
EXPECT_EQ(p->error(), "1:15: invalid format for storage texture type"); 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* p = parser("texture_wo_1d<>");
auto* t = p->texture_sampler_types(); auto* t = p->texture_sampler_types();
EXPECT_EQ(t, nullptr); EXPECT_EQ(t, nullptr);
EXPECT_EQ(p->error(), "1:15: invalid format for storage texture type"); 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* p = parser("texture_ro_1d");
auto* t = p->texture_sampler_types(); auto* t = p->texture_sampler_types();
EXPECT_EQ(t, nullptr); EXPECT_EQ(t, nullptr);
EXPECT_EQ(p->error(), "1:14: missing '<' for storage texture type"); 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_1d<r8unorm"); auto* p = parser("texture_wo_1d<r8unorm");
auto* t = p->texture_sampler_types(); auto* t = p->texture_sampler_types();
EXPECT_EQ(t, nullptr); EXPECT_EQ(t, nullptr);
EXPECT_EQ(p->error(), "1:22: missing '>' for storage texture type"); EXPECT_EQ(p->error(), "1:22: missing '>' for storage texture type");
} }
TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Readonly1dR8Unorm) {
auto* p = parser("texture_storage_ro_1d<r8unorm>");
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<r16float>");
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<abc>");
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_1d<r8unorm");
auto* t = p->texture_sampler_types();
EXPECT_EQ(t, nullptr);
EXPECT_EQ(p->error(), "1:30: missing '>' for storage texture type");
}
} // namespace } // namespace
} // namespace wgsl } // namespace wgsl
} // namespace reader } // namespace reader

View File

@ -290,15 +290,15 @@ std::string Token::TypeToName(Type type) {
case Token::Type::kTextureMultisampled2d: case Token::Type::kTextureMultisampled2d:
return "texture_multisampled_2d"; return "texture_multisampled_2d";
case Token::Type::kTextureStorageReadonly1d: case Token::Type::kTextureStorageReadonly1d:
return "texture_ro_1d"; return "texture_storage_ro_1d";
case Token::Type::kTextureStorageReadonly1dArray: case Token::Type::kTextureStorageReadonly1dArray:
return "texture_ro_1d_array"; return "texture_storage_ro_1d_array";
case Token::Type::kTextureStorageReadonly2d: case Token::Type::kTextureStorageReadonly2d:
return "texture_ro_2d"; return "texture_storage_ro_2d";
case Token::Type::kTextureStorageReadonly2dArray: case Token::Type::kTextureStorageReadonly2dArray:
return "texture_ro_2d_array"; return "texture_storage_ro_2d_array";
case Token::Type::kTextureStorageReadonly3d: case Token::Type::kTextureStorageReadonly3d:
return "texture_ro_3d"; return "texture_storage_ro_3d";
case Token::Type::kTextureSampled1d: case Token::Type::kTextureSampled1d:
return "texture_1d"; return "texture_1d";
case Token::Type::kTextureSampled1dArray: case Token::Type::kTextureSampled1dArray:
@ -314,15 +314,15 @@ std::string Token::TypeToName(Type type) {
case Token::Type::kTextureSampledCubeArray: case Token::Type::kTextureSampledCubeArray:
return "texture_cube_array"; return "texture_cube_array";
case Token::Type::kTextureStorageWriteonly1d: case Token::Type::kTextureStorageWriteonly1d:
return "texture_wo_1d"; return "texture_storage_wo_1d";
case Token::Type::kTextureStorageWriteonly1dArray: case Token::Type::kTextureStorageWriteonly1dArray:
return "texture_wo_1d_array"; return "texture_storage_wo_1d_array";
case Token::Type::kTextureStorageWriteonly2d: case Token::Type::kTextureStorageWriteonly2d:
return "texture_wo_2d"; return "texture_storage_wo_2d";
case Token::Type::kTextureStorageWriteonly2dArray: case Token::Type::kTextureStorageWriteonly2dArray:
return "texture_wo_2d_array"; return "texture_storage_wo_2d_array";
case Token::Type::kTextureStorageWriteonly3d: case Token::Type::kTextureStorageWriteonly3d:
return "texture_wo_3d"; return "texture_storage_wo_3d";
case Token::Type::kTrue: case Token::Type::kTrue:
return "true"; return "true";
case Token::Type::kType: case Token::Type::kType:

View File

@ -300,15 +300,15 @@ class Token {
kTextureDepthCubeArray, kTextureDepthCubeArray,
/// A 'texture_multisampled_2d' /// A 'texture_multisampled_2d'
kTextureMultisampled2d, kTextureMultisampled2d,
/// A 'texture_ro_1d' /// A 'texture_storage_ro_1d'
kTextureStorageReadonly1d, kTextureStorageReadonly1d,
/// A 'texture_ro_2d_array' /// A 'texture_storage_ro_2d_array'
kTextureStorageReadonly1dArray, kTextureStorageReadonly1dArray,
/// A 'texture_ro_2d' /// A 'texture_storage_ro_2d'
kTextureStorageReadonly2d, kTextureStorageReadonly2d,
/// A 'texture_ro_2d_array' /// A 'texture_storage_ro_2d_array'
kTextureStorageReadonly2dArray, kTextureStorageReadonly2dArray,
/// A 'texture_ro_3d' /// A 'texture_storage_ro_3d'
kTextureStorageReadonly3d, kTextureStorageReadonly3d,
/// A 'texture_1d' /// A 'texture_1d'
kTextureSampled1d, kTextureSampled1d,
@ -689,23 +689,23 @@ class Token {
bool IsTextureMultisampled2d() const { bool IsTextureMultisampled2d() const {
return type_ == Type::kTextureMultisampled2d; 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 { bool IsTextureStorageReadonly1d() const {
return type_ == Type::kTextureStorageReadonly1d; 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 { bool IsTextureStorageReadonly1dArray() const {
return type_ == Type::kTextureStorageReadonly1dArray; 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 { bool IsTextureStorageReadonly2d() const {
return type_ == Type::kTextureStorageReadonly2d; 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 { bool IsTextureStorageReadonly2dArray() const {
return type_ == Type::kTextureStorageReadonly2dArray; 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 { bool IsTextureStorageReadonly3d() const {
return type_ == Type::kTextureStorageReadonly3d; return type_ == Type::kTextureStorageReadonly3d;
} }
@ -731,23 +731,23 @@ class Token {
bool IsTextureSampledCubeArray() const { bool IsTextureSampledCubeArray() const {
return type_ == Type::kTextureSampledCubeArray; 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 { bool IsTextureStorageWriteonly1d() const {
return type_ == Type::kTextureStorageWriteonly1d; 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 { bool IsTextureStorageWriteonly1dArray() const {
return type_ == Type::kTextureStorageWriteonly1dArray; 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 { bool IsTextureStorageWriteonly2d() const {
return type_ == Type::kTextureStorageWriteonly2d; 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 { bool IsTextureStorageWriteonly2dArray() const {
return type_ == Type::kTextureStorageWriteonly2dArray; 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 { bool IsTextureStorageWriteonly3d() const {
return type_ == Type::kTextureStorageWriteonly3d; return type_ == Type::kTextureStorageWriteonly3d;
} }

View File

@ -463,8 +463,9 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) {
} else if (texture->IsMultisampled()) { } else if (texture->IsMultisampled()) {
out_ << "multisampled_"; out_ << "multisampled_";
} else if (texture->IsStorage()) { } else if (texture->IsStorage()) {
auto* storage = texture->AsStorage(); out_ << "storage_";
auto* storage = texture->AsStorage();
if (storage->access() == ast::AccessControl::kReadOnly) { if (storage->access() == ast::AccessControl::kReadOnly) {
out_ << "ro_"; out_ << "ro_";
} else if (storage->access() == ast::AccessControl::kWriteOnly) { } else if (storage->access() == ast::AccessControl::kWriteOnly) {

View File

@ -394,38 +394,38 @@ INSTANTIATE_TEST_SUITE_P(
testing::Values( testing::Values(
StorageTextureData{ StorageTextureData{
ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k1d, ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k1d,
ast::AccessControl::kReadOnly, "texture_ro_1d<r8unorm>"}, ast::AccessControl::kReadOnly, "texture_storage_ro_1d<r8unorm>"},
StorageTextureData{ast::type::ImageFormat::kR8Unorm, StorageTextureData{ast::type::ImageFormat::kR8Unorm,
ast::type::TextureDimension::k1dArray, ast::type::TextureDimension::k1dArray,
ast::AccessControl::kReadOnly, ast::AccessControl::kReadOnly,
"texture_ro_1d_array<r8unorm>"}, "texture_storage_ro_1d_array<r8unorm>"},
StorageTextureData{ StorageTextureData{
ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k2d, ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k2d,
ast::AccessControl::kReadOnly, "texture_ro_2d<r8unorm>"}, ast::AccessControl::kReadOnly, "texture_storage_ro_2d<r8unorm>"},
StorageTextureData{ast::type::ImageFormat::kR8Unorm, StorageTextureData{ast::type::ImageFormat::kR8Unorm,
ast::type::TextureDimension::k2dArray, ast::type::TextureDimension::k2dArray,
ast::AccessControl::kReadOnly, ast::AccessControl::kReadOnly,
"texture_ro_2d_array<r8unorm>"}, "texture_storage_ro_2d_array<r8unorm>"},
StorageTextureData{ StorageTextureData{
ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k3d, ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k3d,
ast::AccessControl::kReadOnly, "texture_ro_3d<r8unorm>"}, ast::AccessControl::kReadOnly, "texture_storage_ro_3d<r8unorm>"},
StorageTextureData{ StorageTextureData{
ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k1d, ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k1d,
ast::AccessControl::kWriteOnly, "texture_wo_1d<r8unorm>"}, ast::AccessControl::kWriteOnly, "texture_storage_wo_1d<r8unorm>"},
StorageTextureData{ast::type::ImageFormat::kR8Unorm, StorageTextureData{ast::type::ImageFormat::kR8Unorm,
ast::type::TextureDimension::k1dArray, ast::type::TextureDimension::k1dArray,
ast::AccessControl::kWriteOnly, ast::AccessControl::kWriteOnly,
"texture_wo_1d_array<r8unorm>"}, "texture_storage_wo_1d_array<r8unorm>"},
StorageTextureData{ StorageTextureData{
ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k2d, ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k2d,
ast::AccessControl::kWriteOnly, "texture_wo_2d<r8unorm>"}, ast::AccessControl::kWriteOnly, "texture_storage_wo_2d<r8unorm>"},
StorageTextureData{ast::type::ImageFormat::kR8Unorm, StorageTextureData{ast::type::ImageFormat::kR8Unorm,
ast::type::TextureDimension::k2dArray, ast::type::TextureDimension::k2dArray,
ast::AccessControl::kWriteOnly, ast::AccessControl::kWriteOnly,
"texture_wo_2d_array<r8unorm>"}, "texture_storage_wo_2d_array<r8unorm>"},
StorageTextureData{ StorageTextureData{
ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k3d, ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k3d,
ast::AccessControl::kWriteOnly, "texture_wo_3d<r8unorm>"})); ast::AccessControl::kWriteOnly, "texture_storage_wo_3d<r8unorm>"}));
struct ImageFormatData { struct ImageFormatData {
ast::type::ImageFormat fmt; ast::type::ImageFormat fmt;