wgsl: Implement invariant attribute

Make sure the other backends ICE on unrecognized attributes.

Add E2E tests, currently skipped for the other backends.

Bug: tint:772
Change-Id: I4e68d111ff79b19ebb6c574058a91debcb746011
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/57642
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
James Price
2021-07-12 12:28:52 +00:00
committed by Tint LUCI CQ
parent 508d2491d0
commit fcc0de0b86
15 changed files with 121 additions and 0 deletions

View File

@@ -24,6 +24,7 @@
#include "src/ast/external_texture.h"
#include "src/ast/fallthrough_statement.h"
#include "src/ast/if_statement.h"
#include "src/ast/invariant_decoration.h"
#include "src/ast/loop_statement.h"
#include "src/ast/override_decoration.h"
#include "src/ast/return_statement.h"
@@ -111,6 +112,7 @@ const char kBlockDecoration[] = "block";
const char kBuiltinDecoration[] = "builtin";
const char kGroupDecoration[] = "group";
const char kInterpolateDecoration[] = "interpolate";
const char kInvariantDecoration[] = "invariant";
const char kLocationDecoration[] = "location";
const char kOverrideDecoration[] = "override";
const char kSizeDecoration[] = "size";
@@ -3002,6 +3004,10 @@ Maybe<ast::Decoration*> ParserImpl::decoration() {
});
}
if (s == kInvariantDecoration) {
return create<ast::InvariantDecoration>(t.source());
}
if (s == kBuiltinDecoration) {
return expect_paren_block("builtin decoration", [&]() -> Result {
auto builtin = expect_builtin();

View File

@@ -61,6 +61,20 @@ TEST_F(ParserImplTest, FunctionHeader_DecoratedReturnType) {
EXPECT_EQ(loc->value(), 1u);
}
TEST_F(ParserImplTest, FunctionHeader_InvariantReturnType) {
auto p = parser("fn main() -> [[invariant]] f32");
auto f = p->function_header();
ASSERT_FALSE(p->has_error()) << p->error();
EXPECT_TRUE(f.matched);
EXPECT_FALSE(f.errored);
EXPECT_EQ(f->name, "main");
EXPECT_EQ(f->params.size(), 0u);
EXPECT_TRUE(f->return_type->Is<ast::F32>());
ASSERT_EQ(f->return_type_decorations.size(), 1u);
EXPECT_TRUE(f->return_type_decorations[0]->Is<ast::InvariantDecoration>());
}
TEST_F(ParserImplTest, FunctionHeader_DecoratedReturnType_WithArrayStride) {
auto p = parser("fn main() -> [[location(1), stride(16)]] array<f32, 4>");
auto f = p->function_header();

View File

@@ -3092,6 +3092,11 @@ bool GeneratorImpl::EmitStructType(const sem::Struct* str) {
return false;
}
pre += mod;
} else if (!deco->IsAnyOf<ast::StructMemberAlignDecoration,
ast::StructMemberSizeDecoration>()) {
TINT_ICE(Writer, diagnostics_)
<< "unhandled struct member attribute: " << deco->name();
}
}

View File

@@ -2134,6 +2134,11 @@ bool GeneratorImpl::EmitStructType(const sem::Struct* str) {
return false;
}
out << " [[" << attr << "]]";
} else if (!deco->IsAnyOf<ast::StructMemberOffsetDecoration,
ast::StructMemberAlignDecoration,
ast::StructMemberSizeDecoration>()) {
TINT_ICE(Writer, diagnostics_)
<< "unhandled struct member attribute: " << deco->name();
}
}

View File

@@ -30,6 +30,7 @@
#include "src/ast/i32.h"
#include "src/ast/internal_decoration.h"
#include "src/ast/interpolate_decoration.h"
#include "src/ast/invariant_decoration.h"
#include "src/ast/matrix.h"
#include "src/ast/module.h"
#include "src/ast/multisampled_texture.h"
@@ -676,6 +677,8 @@ bool GeneratorImpl::EmitDecorations(std::ostream& out,
out << ", " << interpolate->sampling();
}
out << ")";
} else if (deco->Is<ast::InvariantDecoration>()) {
out << "invariant";
} else if (auto* override_deco = deco->As<ast::OverrideDecoration>()) {
out << "override";
if (override_deco->HasValue()) {