[wgsl-reader][wgsl-writer] Support new sampled texture syntax.
This CL updates Tint to support the `texture_1d` format for sampled textures. This is alongside the old `texture_sampled_1d` to allow migration time. The WGSL writer will always output the new form when converting to WGSL. Bug: tint:286 Change-Id: I96f0308ad3c28ade96bcab7e24aa0b405e3c4f05 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31380 Commit-Queue: dan sinclair <dsinclair@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
parent
4ce7a93202
commit
a7e1492a6a
6
Doxyfile
6
Doxyfile
|
@ -241,12 +241,6 @@ TAB_SIZE = 2
|
|||
|
||||
ALIASES =
|
||||
|
||||
# This tag can be used to specify a number of word-keyword mappings (TCL only).
|
||||
# A mapping has the form "name=value". For example adding "class=itcl::class"
|
||||
# will allow you to use the command class in the itcl::class meaning.
|
||||
|
||||
TCL_SUBST =
|
||||
|
||||
# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources
|
||||
# only. Doxygen will then generate output that is more tailored for C. For
|
||||
# instance, some of the names that are used will be different. The list of all
|
||||
|
|
|
@ -669,6 +669,22 @@ Token Lexer::check_keyword(const Source& source, const std::string& str) {
|
|||
return {Token::Type::kStruct, source, "struct"};
|
||||
if (str == "switch")
|
||||
return {Token::Type::kSwitch, source, "switch"};
|
||||
if (str == "texture_1d")
|
||||
return {Token::Type::kTextureSampled1d, source, "texture_1d"};
|
||||
if (str == "texture_1d_array")
|
||||
return {Token::Type::kTextureSampled1dArray, source, "texture_1d_array"};
|
||||
if (str == "texture_2d")
|
||||
return {Token::Type::kTextureSampled2d, source, "texture_2d"};
|
||||
if (str == "texture_2d_array")
|
||||
return {Token::Type::kTextureSampled2dArray, source, "texture_2d_array"};
|
||||
if (str == "texture_3d")
|
||||
return {Token::Type::kTextureSampled3d, source, "texture_3d"};
|
||||
if (str == "texture_cube")
|
||||
return {Token::Type::kTextureSampledCube, source, "texture_cube"};
|
||||
if (str == "texture_cube_array") {
|
||||
return {Token::Type::kTextureSampledCubeArray, source,
|
||||
"texture_cube_array"};
|
||||
}
|
||||
if (str == "texture_depth_2d")
|
||||
return {Token::Type::kTextureDepth2d, source, "texture_depth_2d"};
|
||||
if (str == "texture_depth_2d_array") {
|
||||
|
@ -687,14 +703,16 @@ Token Lexer::check_keyword(const Source& source, const std::string& str) {
|
|||
}
|
||||
if (str == "texture_ro_1d")
|
||||
return {Token::Type::kTextureStorageReadonly1d, source, "texture_ro_1d"};
|
||||
if (str == "texture_ro_1d_array")
|
||||
if (str == "texture_ro_1d_array") {
|
||||
return {Token::Type::kTextureStorageReadonly1dArray, source,
|
||||
"texture_ro_1d_array"};
|
||||
}
|
||||
if (str == "texture_ro_2d")
|
||||
return {Token::Type::kTextureStorageReadonly2d, source, "texture_ro_2d"};
|
||||
if (str == "texture_ro_2d_array")
|
||||
if (str == "texture_ro_2d_array") {
|
||||
return {Token::Type::kTextureStorageReadonly2dArray, source,
|
||||
"texture_ro_2d_array"};
|
||||
}
|
||||
if (str == "texture_ro_3d")
|
||||
return {Token::Type::kTextureStorageReadonly3d, source, "texture_ro_3d"};
|
||||
if (str == "texture_sampled_1d")
|
||||
|
@ -719,14 +737,16 @@ Token Lexer::check_keyword(const Source& source, const std::string& str) {
|
|||
}
|
||||
if (str == "texture_wo_1d")
|
||||
return {Token::Type::kTextureStorageWriteonly1d, source, "texture_wo_1d"};
|
||||
if (str == "texture_wo_1d_array")
|
||||
if (str == "texture_wo_1d_array") {
|
||||
return {Token::Type::kTextureStorageWriteonly1dArray, source,
|
||||
"texture_wo_1d_array"};
|
||||
}
|
||||
if (str == "texture_wo_2d")
|
||||
return {Token::Type::kTextureStorageWriteonly2d, source, "texture_wo_2d"};
|
||||
if (str == "texture_wo_2d_array")
|
||||
if (str == "texture_wo_2d_array") {
|
||||
return {Token::Type::kTextureStorageWriteonly2dArray, source,
|
||||
"texture_wo_2d_array"};
|
||||
}
|
||||
if (str == "texture_wo_3d")
|
||||
return {Token::Type::kTextureStorageWriteonly3d, source, "texture_wo_3d"};
|
||||
if (str == "true")
|
||||
|
|
|
@ -554,6 +554,13 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
TokenData{"stride", Token::Type::kStride},
|
||||
TokenData{"struct", Token::Type::kStruct},
|
||||
TokenData{"switch", Token::Type::kSwitch},
|
||||
TokenData{"texture_1d", Token::Type::kTextureSampled1d},
|
||||
TokenData{"texture_1d_array", Token::Type::kTextureSampled1dArray},
|
||||
TokenData{"texture_2d", Token::Type::kTextureSampled2d},
|
||||
TokenData{"texture_2d_array", Token::Type::kTextureSampled2dArray},
|
||||
TokenData{"texture_3d", Token::Type::kTextureSampled3d},
|
||||
TokenData{"texture_cube", Token::Type::kTextureSampledCube},
|
||||
TokenData{"texture_cube_array", Token::Type::kTextureSampledCubeArray},
|
||||
TokenData{"texture_depth_2d", Token::Type::kTextureDepth2d},
|
||||
TokenData{"texture_depth_2d_array", Token::Type::kTextureDepth2dArray},
|
||||
TokenData{"texture_depth_cube", Token::Type::kTextureDepthCube},
|
||||
|
|
|
@ -533,27 +533,48 @@ TEST_F(ParserImplErrorTest, GlobalDeclConstExprMissingRParen) {
|
|||
" ^\n");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureMissingLessThan) {
|
||||
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureMissingLessThan_Old) {
|
||||
EXPECT("var x : texture_sampled_1d;",
|
||||
"test.wgsl:1:28 error: missing '<' for sampled texture type\n"
|
||||
"var x : texture_sampled_1d;\n"
|
||||
" ^\n");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureMissingGreaterThan) {
|
||||
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureMissingGreaterThan_Old) {
|
||||
EXPECT("var x : texture_sampled_1d<f32;",
|
||||
"test.wgsl:1:32 error: missing '>' for sampled texture type\n"
|
||||
"var x : texture_sampled_1d<f32;\n"
|
||||
" ^\n");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureInvalidSubtype) {
|
||||
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureInvalidSubtype_Old) {
|
||||
EXPECT("var x : texture_sampled_1d<1>;",
|
||||
"test.wgsl:1:28 error: invalid subtype for sampled texture type\n"
|
||||
"var x : texture_sampled_1d<1>;\n"
|
||||
" ^\n");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureMissingLessThan) {
|
||||
EXPECT("var x : texture_1d;",
|
||||
"test.wgsl:1:20 error: missing '<' for sampled texture type\n"
|
||||
"var x : texture_1d;\n"
|
||||
" ^\n");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureMissingGreaterThan) {
|
||||
EXPECT("var x : texture_1d<f32;",
|
||||
"test.wgsl:1:24 error: missing '>' for sampled texture type\n"
|
||||
"var x : texture_1d<f32;\n"
|
||||
" ^\n");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureInvalidSubtype) {
|
||||
EXPECT("var x : texture_1d<1>;",
|
||||
"test.wgsl:1:20 error: invalid subtype for sampled texture type\n"
|
||||
"var x : texture_1d<1>;\n"
|
||||
" ^\n");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplErrorTest, GlobalDeclMultisampledTextureMissingLessThan) {
|
||||
EXPECT("var x : texture_multisampled_2d;",
|
||||
"test.wgsl:1:33 error: missing '<' for multisampled texture type\n"
|
||||
|
|
|
@ -29,55 +29,104 @@ TEST_F(ParserImplTest, SampledTextureType_Invalid) {
|
|||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, SampledTextureType_1d) {
|
||||
TEST_F(ParserImplTest, SampledTextureType_1d_Old) {
|
||||
auto* p = parser("texture_sampled_1d");
|
||||
auto t = p->sampled_texture_type();
|
||||
EXPECT_EQ(t, ast::type::TextureDimension::k1d);
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, SampledTextureType_1dArray) {
|
||||
TEST_F(ParserImplTest, SampledTextureType_1dArray_Old) {
|
||||
auto* p = parser("texture_sampled_1d_array");
|
||||
auto t = p->sampled_texture_type();
|
||||
EXPECT_EQ(t, ast::type::TextureDimension::k1dArray);
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, SampledTextureType_2d) {
|
||||
TEST_F(ParserImplTest, SampledTextureType_2d_Old) {
|
||||
auto* p = parser("texture_sampled_2d");
|
||||
auto t = p->sampled_texture_type();
|
||||
EXPECT_EQ(t, ast::type::TextureDimension::k2d);
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, SampledTextureType_2dArray) {
|
||||
TEST_F(ParserImplTest, SampledTextureType_2dArray_Old) {
|
||||
auto* p = parser("texture_sampled_2d_array");
|
||||
auto t = p->sampled_texture_type();
|
||||
EXPECT_EQ(t, ast::type::TextureDimension::k2dArray);
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, SampledTextureType_3d) {
|
||||
TEST_F(ParserImplTest, SampledTextureType_3d_Old) {
|
||||
auto* p = parser("texture_sampled_3d");
|
||||
auto t = p->sampled_texture_type();
|
||||
EXPECT_EQ(t, ast::type::TextureDimension::k3d);
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, SampledTextureType_Cube) {
|
||||
TEST_F(ParserImplTest, SampledTextureType_Cube_Old) {
|
||||
auto* p = parser("texture_sampled_cube");
|
||||
auto t = p->sampled_texture_type();
|
||||
EXPECT_EQ(t, ast::type::TextureDimension::kCube);
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, SampledTextureType_kCubeArray) {
|
||||
TEST_F(ParserImplTest, SampledTextureType_kCubeArray_Old) {
|
||||
auto* p = parser("texture_sampled_cube_array");
|
||||
auto t = p->sampled_texture_type();
|
||||
EXPECT_EQ(t, ast::type::TextureDimension::kCubeArray);
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, SampledTextureType_1d) {
|
||||
auto* p = parser("texture_1d");
|
||||
auto t = p->sampled_texture_type();
|
||||
EXPECT_EQ(t, ast::type::TextureDimension::k1d);
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, SampledTextureType_1dArray) {
|
||||
auto* p = parser("texture_1d_array");
|
||||
auto t = p->sampled_texture_type();
|
||||
EXPECT_EQ(t, ast::type::TextureDimension::k1dArray);
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, SampledTextureType_2d) {
|
||||
auto* p = parser("texture_2d");
|
||||
auto t = p->sampled_texture_type();
|
||||
EXPECT_EQ(t, ast::type::TextureDimension::k2d);
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, SampledTextureType_2dArray) {
|
||||
auto* p = parser("texture_2d_array");
|
||||
auto t = p->sampled_texture_type();
|
||||
EXPECT_EQ(t, ast::type::TextureDimension::k2dArray);
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, SampledTextureType_3d) {
|
||||
auto* p = parser("texture_3d");
|
||||
auto t = p->sampled_texture_type();
|
||||
EXPECT_EQ(t, ast::type::TextureDimension::k3d);
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, SampledTextureType_Cube) {
|
||||
auto* p = parser("texture_cube");
|
||||
auto t = p->sampled_texture_type();
|
||||
EXPECT_EQ(t, ast::type::TextureDimension::kCube);
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, SampledTextureType_kCubeArray) {
|
||||
auto* p = parser("texture_cube_array");
|
||||
auto t = p->sampled_texture_type();
|
||||
EXPECT_EQ(t, ast::type::TextureDimension::kCubeArray);
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace wgsl
|
||||
} // namespace reader
|
||||
|
|
|
@ -59,7 +59,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_DepthTexture) {
|
|||
EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d);
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32) {
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32_Old) {
|
||||
auto* p = parser("texture_sampled_1d<f32>");
|
||||
auto* t = p->texture_sampler_types();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
|
@ -70,7 +70,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32) {
|
|||
EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k1d);
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) {
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32_Old) {
|
||||
auto* p = parser("texture_sampled_2d<i32>");
|
||||
auto* t = p->texture_sampler_types();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
|
@ -81,7 +81,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) {
|
|||
EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d);
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) {
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32_Old) {
|
||||
auto* p = parser("texture_sampled_3d<u32>");
|
||||
auto* t = p->texture_sampler_types();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
|
@ -92,7 +92,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) {
|
|||
EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k3d);
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_Invalid) {
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_Invalid_Old) {
|
||||
auto* p = parser("texture_sampled_1d<abc>");
|
||||
auto* t = p->texture_sampler_types();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
|
@ -100,7 +100,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_Invalid) {
|
|||
EXPECT_EQ(p->error(), "1:20: unknown constructed type 'abc'");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingType) {
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingType_Old) {
|
||||
auto* p = parser("texture_sampled_1d<>");
|
||||
auto* t = p->texture_sampler_types();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
|
@ -108,7 +108,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingType) {
|
|||
EXPECT_EQ(p->error(), "1:20: invalid subtype for sampled texture type");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingLessThan) {
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingLessThan_Old) {
|
||||
auto* p = parser("texture_sampled_1d");
|
||||
auto* t = p->texture_sampler_types();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
|
@ -116,7 +116,8 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingLessThan) {
|
|||
EXPECT_EQ(p->error(), "1:19: missing '<' for sampled texture type");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingGreaterThan) {
|
||||
TEST_F(ParserImplTest,
|
||||
TextureSamplerTypes_SampledTexture_MissingGreaterThan_Old) {
|
||||
auto* p = parser("texture_sampled_1d<u32");
|
||||
auto* t = p->texture_sampler_types();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
|
@ -124,6 +125,71 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingGreaterThan) {
|
|||
EXPECT_EQ(p->error(), "1:23: missing '>' for sampled texture type");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32) {
|
||||
auto* p = parser("texture_1d<f32>");
|
||||
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()->IsSampled());
|
||||
ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->IsF32());
|
||||
EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k1d);
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) {
|
||||
auto* p = parser("texture_2d<i32>");
|
||||
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()->IsSampled());
|
||||
ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->IsI32());
|
||||
EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d);
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) {
|
||||
auto* p = parser("texture_3d<u32>");
|
||||
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()->IsSampled());
|
||||
ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->IsU32());
|
||||
EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k3d);
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_Invalid) {
|
||||
auto* p = parser("texture_1d<abc>");
|
||||
auto* t = p->texture_sampler_types();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
EXPECT_EQ(t, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:12: unknown constructed type 'abc'");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingType) {
|
||||
auto* p = parser("texture_1d<>");
|
||||
auto* t = p->texture_sampler_types();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
EXPECT_EQ(t, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:12: invalid subtype for sampled texture type");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingLessThan) {
|
||||
auto* p = parser("texture_1d");
|
||||
auto* t = p->texture_sampler_types();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
EXPECT_EQ(t, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:11: missing '<' for sampled texture type");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingGreaterThan) {
|
||||
auto* p = parser("texture_1d<u32");
|
||||
auto* t = p->texture_sampler_types();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
EXPECT_EQ(t, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:15: missing '>' for sampled texture type");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_I32) {
|
||||
auto* p = parser("texture_multisampled_2d<i32>");
|
||||
auto* t = p->texture_sampler_types();
|
||||
|
|
|
@ -650,7 +650,7 @@ TEST_F(ParserImplTest, TypeDecl_Sampler) {
|
|||
ASSERT_FALSE(t->AsSampler()->IsComparison());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TypeDecl_Texture) {
|
||||
TEST_F(ParserImplTest, TypeDecl_Texture_Old) {
|
||||
auto* p = parser("texture_sampled_cube<f32>");
|
||||
|
||||
ast::type::F32Type f32;
|
||||
|
@ -665,6 +665,21 @@ TEST_F(ParserImplTest, TypeDecl_Texture) {
|
|||
ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->IsF32());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TypeDecl_Texture) {
|
||||
auto* p = parser("texture_cube<f32>");
|
||||
|
||||
ast::type::F32Type f32;
|
||||
auto* type = tm()->Get(std::make_unique<ast::type::SampledTextureType>(
|
||||
ast::type::TextureDimension::kCube, &f32));
|
||||
|
||||
auto* t = p->type_decl();
|
||||
ASSERT_NE(t, nullptr);
|
||||
EXPECT_EQ(t, type);
|
||||
ASSERT_TRUE(t->IsTexture());
|
||||
ASSERT_TRUE(t->AsTexture()->IsSampled());
|
||||
ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->IsF32());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace wgsl
|
||||
} // namespace reader
|
||||
|
|
|
@ -300,19 +300,19 @@ std::string Token::TypeToName(Type type) {
|
|||
case Token::Type::kTextureStorageReadonly3d:
|
||||
return "texture_ro_3d";
|
||||
case Token::Type::kTextureSampled1d:
|
||||
return "texture_sampled_1d";
|
||||
return "texture_1d";
|
||||
case Token::Type::kTextureSampled1dArray:
|
||||
return "texture_sampled_1d_array";
|
||||
return "texture_1d_array";
|
||||
case Token::Type::kTextureSampled2d:
|
||||
return "texture_sampled_2d";
|
||||
return "texture_2d";
|
||||
case Token::Type::kTextureSampled2dArray:
|
||||
return "texture_sampled_2d_array";
|
||||
return "texture_2d_array";
|
||||
case Token::Type::kTextureSampled3d:
|
||||
return "texture_sampled_3d";
|
||||
return "texture_3d";
|
||||
case Token::Type::kTextureSampledCube:
|
||||
return "texture_sampled_cube";
|
||||
return "texture_cube";
|
||||
case Token::Type::kTextureSampledCubeArray:
|
||||
return "texture_sampled_cube_array";
|
||||
return "texture_cube_array";
|
||||
case Token::Type::kTextureStorageWriteonly1d:
|
||||
return "texture_wo_1d";
|
||||
case Token::Type::kTextureStorageWriteonly1dArray:
|
||||
|
|
|
@ -310,19 +310,19 @@ class Token {
|
|||
kTextureStorageReadonly2dArray,
|
||||
/// A 'texture_ro_3d'
|
||||
kTextureStorageReadonly3d,
|
||||
/// A 'texture_sampled_1d'
|
||||
/// A 'texture_1d'
|
||||
kTextureSampled1d,
|
||||
/// A 'texture_sampled_1d_array'
|
||||
/// A 'texture_1d_array'
|
||||
kTextureSampled1dArray,
|
||||
/// A 'texture_sampled_2d'
|
||||
/// A 'texture_2d'
|
||||
kTextureSampled2d,
|
||||
/// A 'texture_sampled_2d_array'
|
||||
/// A 'texture_2d_array'
|
||||
kTextureSampled2dArray,
|
||||
/// A 'texture_sampled_3d'
|
||||
/// A 'texture_3d'
|
||||
kTextureSampled3d,
|
||||
/// A 'texture_sampled_cube'
|
||||
/// A 'texture_cube'
|
||||
kTextureSampledCube,
|
||||
/// A 'texture_sampled_cube_array'
|
||||
/// A 'texture_cube_array'
|
||||
kTextureSampledCubeArray,
|
||||
/// A 'texture_wo_1d'
|
||||
kTextureStorageWriteonly1d,
|
||||
|
@ -709,25 +709,25 @@ class Token {
|
|||
bool IsTextureStorageReadonly3d() const {
|
||||
return type_ == Type::kTextureStorageReadonly3d;
|
||||
}
|
||||
/// @returns true if token is a 'texture_sampled_1d'
|
||||
/// @returns true if token is a 'texture_1d'
|
||||
bool IsTextureSampled1d() const { return type_ == Type::kTextureSampled1d; }
|
||||
/// @returns true if token is a 'texture_sampled_1d_array'
|
||||
/// @returns true if token is a 'texture_1d_array'
|
||||
bool IsTextureSampled1dArray() const {
|
||||
return type_ == Type::kTextureSampled1dArray;
|
||||
}
|
||||
/// @returns true if token is a 'texture_sampled_2d'
|
||||
/// @returns true if token is a 'texture_2d'
|
||||
bool IsTextureSampled2d() const { return type_ == Type::kTextureSampled2d; }
|
||||
/// @returns true if token is a 'texture_sampled_2d_array'
|
||||
/// @returns true if token is a 'texture_2d_array'
|
||||
bool IsTextureSampled2dArray() const {
|
||||
return type_ == Type::kTextureSampled2dArray;
|
||||
}
|
||||
/// @returns true if token is a 'texture_sampled_3d'
|
||||
/// @returns true if token is a 'texture_3d'
|
||||
bool IsTextureSampled3d() const { return type_ == Type::kTextureSampled3d; }
|
||||
/// @returns true if token is a 'texture_sampled_cube'
|
||||
/// @returns true if token is a 'texture_cube'
|
||||
bool IsTextureSampledCube() const {
|
||||
return type_ == Type::kTextureSampledCube;
|
||||
}
|
||||
/// @returns true if token is a 'texture_sampled_cube_array'
|
||||
/// @returns true if token is a 'texture_cube_array'
|
||||
bool IsTextureSampledCubeArray() const {
|
||||
return type_ == Type::kTextureSampledCubeArray;
|
||||
}
|
||||
|
|
|
@ -459,7 +459,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) {
|
|||
if (texture->IsDepth()) {
|
||||
out_ << "depth_";
|
||||
} else if (texture->IsSampled()) {
|
||||
out_ << "sampled_";
|
||||
/* nothing to emit */
|
||||
} else if (texture->IsMultisampled()) {
|
||||
out_ << "multisampled_";
|
||||
} else if (texture->IsStorage()) {
|
||||
|
|
|
@ -318,16 +318,14 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
WgslGeneratorImplTest,
|
||||
WgslGenerator_SampledTextureTest,
|
||||
testing::Values(
|
||||
TextureData{ast::type::TextureDimension::k1d, "texture_sampled_1d"},
|
||||
TextureData{ast::type::TextureDimension::k1dArray,
|
||||
"texture_sampled_1d_array"},
|
||||
TextureData{ast::type::TextureDimension::k2d, "texture_sampled_2d"},
|
||||
TextureData{ast::type::TextureDimension::k2dArray,
|
||||
"texture_sampled_2d_array"},
|
||||
TextureData{ast::type::TextureDimension::k3d, "texture_sampled_3d"},
|
||||
TextureData{ast::type::TextureDimension::kCube, "texture_sampled_cube"},
|
||||
TextureData{ast::type::TextureDimension::k1d, "texture_1d"},
|
||||
TextureData{ast::type::TextureDimension::k1dArray, "texture_1d_array"},
|
||||
TextureData{ast::type::TextureDimension::k2d, "texture_2d"},
|
||||
TextureData{ast::type::TextureDimension::k2dArray, "texture_2d_array"},
|
||||
TextureData{ast::type::TextureDimension::k3d, "texture_3d"},
|
||||
TextureData{ast::type::TextureDimension::kCube, "texture_cube"},
|
||||
TextureData{ast::type::TextureDimension::kCubeArray,
|
||||
"texture_sampled_cube_array"}));
|
||||
"texture_cube_array"}));
|
||||
|
||||
using WgslGenerator_MultiampledTextureTest =
|
||||
testing::TestWithParam<TextureData>;
|
||||
|
|
Loading…
Reference in New Issue