diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index 50925f3ba3..82af4ccd41 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -1119,6 +1119,7 @@ ast::type::AliasType* ParserImpl::type_alias() { // | MAT4x2 LESS_THAN type_decl GREATER_THAN // | MAT4x3 LESS_THAN type_decl GREATER_THAN // | MAT4x4 LESS_THAN type_decl GREATER_THAN +// | texture_sampler_types ast::type::Type* ParserImpl::type_decl() { auto t = peek(); if (t.IsIdentifier()) { @@ -1172,6 +1173,15 @@ ast::type::Type* ParserImpl::type_decl() { t.IsMat4x4()) { return type_decl_matrix(t); } + + auto* texture_or_sampler = texture_sampler_types(); + if (has_error()) { + return nullptr; + } + if (texture_or_sampler != nullptr) { + return texture_or_sampler; + } + return nullptr; } diff --git a/src/reader/wgsl/parser_impl_type_decl_test.cc b/src/reader/wgsl/parser_impl_type_decl_test.cc index 785bbdd446..bb9a616b8c 100644 --- a/src/reader/wgsl/parser_impl_type_decl_test.cc +++ b/src/reader/wgsl/parser_impl_type_decl_test.cc @@ -20,6 +20,8 @@ #include "src/ast/type/i32_type.h" #include "src/ast/type/matrix_type.h" #include "src/ast/type/pointer_type.h" +#include "src/ast/type/sampled_texture_type.h" +#include "src/ast/type/sampler_type.h" #include "src/ast/type/struct_type.h" #include "src/ast/type/u32_type.h" #include "src/ast/type/vector_type.h" @@ -741,6 +743,34 @@ INSTANTIATE_TEST_SUITE_P(ParserImplTest, MatrixData{"mat4x3<>", 4, 3}, MatrixData{"mat4x4<>", 4, 4})); +TEST_F(ParserImplTest, TypeDecl_Sampler) { + auto* p = parser("sampler"); + + auto* type = tm()->Get(std::make_unique( + ast::type::SamplerKind::kSampler)); + + auto* t = p->type_decl(); + ASSERT_NE(t, nullptr); + EXPECT_EQ(t, type); + ASSERT_TRUE(t->IsSampler()); + ASSERT_FALSE(t->AsSampler()->IsComparison()); +} + +TEST_F(ParserImplTest, TypeDecl_Texture) { + auto* p = parser("texture_sampled_cube"); + + ast::type::F32Type f32; + auto* type = tm()->Get(std::make_unique( + 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