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:
parent
508d2491d0
commit
fcc0de0b86
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
[[stage(vertex)]]
|
||||
fn main() -> [[builtin(position), invariant]] vec4<f32> {
|
||||
return vec4<f32>();
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
SKIP: FAILED
|
||||
|
||||
../../src/writer/hlsl/generator_impl.cc:3056 internal compiler error: unhandled struct member attribute: invariant
|
||||
********************************************************************
|
||||
* The tint shader compiler has encountered an unexpected error. *
|
||||
* *
|
||||
* Please help us fix this issue by submitting a bug report at *
|
||||
* crbug.com/tint with the source program that triggered the bug. *
|
||||
********************************************************************
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
SKIP: FAILED
|
||||
|
||||
../../src/writer/msl/generator_impl.cc:1990 internal compiler error: unhandled struct member attribute: invariant
|
||||
********************************************************************
|
||||
* The tint shader compiler has encountered an unexpected error. *
|
||||
* *
|
||||
* Please help us fix this issue by submitting a bug report at *
|
||||
* crbug.com/tint with the source program that triggered the bug. *
|
||||
********************************************************************
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
SKIP: FAILED
|
||||
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main() -> [[builtin(position), invariant]] vec4<f32> {
|
||||
return vec4<f32>();
|
||||
}
|
||||
|
||||
Failed to generate: unknown decoration
|
|
@ -0,0 +1,4 @@
|
|||
[[stage(vertex)]]
|
||||
fn main() -> [[builtin(position), invariant]] vec4<f32> {
|
||||
return vec4<f32>();
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
struct Out {
|
||||
[[builtin(position), invariant]] pos : vec4<f32>;
|
||||
};
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main() -> Out {
|
||||
return Out();
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
SKIP: FAILED
|
||||
|
||||
../../src/writer/hlsl/generator_impl.cc:3056 internal compiler error: unhandled struct member attribute: invariant
|
||||
********************************************************************
|
||||
* The tint shader compiler has encountered an unexpected error. *
|
||||
* *
|
||||
* Please help us fix this issue by submitting a bug report at *
|
||||
* crbug.com/tint with the source program that triggered the bug. *
|
||||
********************************************************************
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
SKIP: FAILED
|
||||
|
||||
../../src/writer/msl/generator_impl.cc:1990 internal compiler error: unhandled struct member attribute: invariant
|
||||
********************************************************************
|
||||
* The tint shader compiler has encountered an unexpected error. *
|
||||
* *
|
||||
* Please help us fix this issue by submitting a bug report at *
|
||||
* crbug.com/tint with the source program that triggered the bug. *
|
||||
********************************************************************
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
SKIP: FAILED
|
||||
|
||||
|
||||
struct Out {
|
||||
[[builtin(position), invariant]]
|
||||
pos : vec4<f32>;
|
||||
};
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main() -> Out {
|
||||
return Out();
|
||||
}
|
||||
|
||||
Failed to generate: unknown decoration
|
|
@ -0,0 +1,9 @@
|
|||
struct Out {
|
||||
[[builtin(position), invariant]]
|
||||
pos : vec4<f32>;
|
||||
};
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main() -> Out {
|
||||
return Out();
|
||||
}
|
Loading…
Reference in New Issue