tint/writer/wgsl: Handle diagnostic attributes

Bug: tint:1809
Change-Id: Id2176eff808b24bdb0e31c3eb397c32219ed59e7
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/117570
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
James Price 2023-01-24 21:01:36 +00:00
parent 8dd35110c2
commit 75326f88e6
2 changed files with 17 additions and 0 deletions

View File

@ -797,6 +797,9 @@ bool GeneratorImpl::EmitAttributes(std::ostream& out,
out << "builtin(" << builtin->builtin << ")";
return true;
},
[&](const ast::DiagnosticAttribute* diagnostic) {
return EmitDiagnosticControl(out, diagnostic->control);
},
[&](const ast::InterpolateAttribute* interpolate) {
out << "interpolate(" << interpolate->type;
if (interpolate->sampling != ast::InterpolationSampling::kUndefined) {

View File

@ -30,5 +30,19 @@ TEST_F(WgslGeneratorImplTest, Emit_DiagnosticDirective) {
)");
}
TEST_F(WgslGeneratorImplTest, Emit_DiagnosticAttribute) {
auto* attr =
DiagnosticAttribute(ast::DiagnosticSeverity::kError, Expr("chromium_unreachable_code"));
Func("foo", {}, ty.void_(), {}, utils::Vector{attr});
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate());
EXPECT_EQ(gen.result(), R"(@diagnostic(error, chromium_unreachable_code)
fn foo() {
}
)");
}
} // namespace
} // namespace tint::writer::wgsl