Tint: parse @input_attachment_index
Bug: 341117913
Change-Id: I1cf43f5df1f85623294d8c113cdb817fa78720df
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/189521
Commit-Queue: Quyen Le <lehoangquyen@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/src/tint/lang/wgsl/reader/parser/parser.cc b/src/tint/lang/wgsl/reader/parser/parser.cc
index 3eddee4..b85555e 100644
--- a/src/tint/lang/wgsl/reader/parser/parser.cc
+++ b/src/tint/lang/wgsl/reader/parser/parser.cc
@@ -45,6 +45,7 @@
#include "src/tint/lang/wgsl/ast/id_attribute.h"
#include "src/tint/lang/wgsl/ast/if_statement.h"
#include "src/tint/lang/wgsl/ast/increment_decrement_statement.h"
+#include "src/tint/lang/wgsl/ast/input_attachment_index_attribute.h"
#include "src/tint/lang/wgsl/ast/invariant_attribute.h"
#include "src/tint/lang/wgsl/ast/loop_statement.h"
#include "src/tint/lang/wgsl/ast/return_statement.h"
@@ -3100,6 +3101,8 @@
return create<ast::GroupAttribute>(t.source(), args[0]);
case core::Attribute::kId:
return create<ast::IdAttribute>(t.source(), args[0]);
+ case core::Attribute::kInputAttachmentIndex:
+ return create<ast::InputAttachmentIndexAttribute>(t.source(), args[0]);
case core::Attribute::kInterpolate:
return create<ast::InterpolateAttribute>(t.source(), args[0],
args.Length() == 2 ? args[1] : nullptr);
diff --git a/src/tint/lang/wgsl/reader/parser/variable_attribute_test.cc b/src/tint/lang/wgsl/reader/parser/variable_attribute_test.cc
index e7c48e4..c61f47d 100644
--- a/src/tint/lang/wgsl/reader/parser/variable_attribute_test.cc
+++ b/src/tint/lang/wgsl/reader/parser/variable_attribute_test.cc
@@ -647,5 +647,48 @@
EXPECT_EQ(p->error(), "1:7: expected expression for group");
}
+TEST_F(WGSLParserTest, Attribute_InputAttachmentIndex) {
+ auto p = parser("input_attachment_index(4)");
+ auto attr = p->attribute();
+ EXPECT_TRUE(attr.matched);
+ EXPECT_FALSE(attr.errored);
+ ASSERT_NE(attr.value, nullptr);
+ auto* var_attr = attr.value->As<ast::Attribute>();
+ ASSERT_FALSE(p->has_error());
+ ASSERT_NE(var_attr, nullptr);
+ ASSERT_TRUE(var_attr->Is<ast::InputAttachmentIndexAttribute>());
+
+ auto* group = var_attr->As<ast::InputAttachmentIndexAttribute>();
+ ASSERT_TRUE(group->expr->Is<ast::IntLiteralExpression>());
+ auto* expr = group->expr->As<ast::IntLiteralExpression>();
+ EXPECT_EQ(expr->value, 4);
+ EXPECT_EQ(expr->suffix, ast::IntLiteralExpression::Suffix::kNone);
+}
+
+TEST_F(WGSLParserTest, Attribute_InputAttachmentIndex_expression) {
+ auto p = parser("input_attachment_index(4 + 5)");
+ auto attr = p->attribute();
+ EXPECT_TRUE(attr.matched);
+ EXPECT_FALSE(attr.errored);
+ ASSERT_NE(attr.value, nullptr);
+ auto* var_attr = attr.value->As<ast::Attribute>();
+ ASSERT_FALSE(p->has_error());
+ ASSERT_NE(var_attr, nullptr);
+ ASSERT_TRUE(var_attr->Is<ast::InputAttachmentIndexAttribute>());
+
+ auto* group = var_attr->As<ast::InputAttachmentIndexAttribute>();
+ ASSERT_TRUE(group->expr->Is<ast::BinaryExpression>());
+ auto* expr = group->expr->As<ast::BinaryExpression>();
+
+ EXPECT_EQ(core::BinaryOp::kAdd, expr->op);
+ auto* v = expr->lhs->As<ast::IntLiteralExpression>();
+ ASSERT_NE(nullptr, v);
+ EXPECT_EQ(v->value, 4u);
+
+ v = expr->rhs->As<ast::IntLiteralExpression>();
+ ASSERT_NE(nullptr, v);
+ EXPECT_EQ(v->value, 5u);
+}
+
} // namespace
} // namespace tint::wgsl::reader