From 43759bff1c0455a157308976b709e4f486de7d1a Mon Sep 17 00:00:00 2001 From: Tomek Ponitka Date: Tue, 15 Sep 2020 18:35:43 +0000 Subject: [PATCH] [wgsl-reader] Adding texture_sampler_types to type_decl Bug: tint:147 Change-Id: Ib806d5c434e98632a83ad8802a3a0aeea609c8c2 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28125 Reviewed-by: dan sinclair Commit-Queue: dan sinclair --- src/reader/wgsl/parser_impl.cc | 10 +++++++ src/reader/wgsl/parser_impl_type_decl_test.cc | 30 +++++++++++++++++++ 2 files changed, 40 insertions(+) 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