[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 <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc
index 50925f3..82af4cc 100644
--- a/src/reader/wgsl/parser_impl.cc
+++ b/src/reader/wgsl/parser_impl.cc
@@ -1119,6 +1119,7 @@
// | 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 @@
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 785bbdd..bb9a616 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 @@
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::SamplerType>(
+ 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<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