mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 08:27:05 +00:00
writer/msl: Implement invariant attribute
Report whether one was generated so that Dawn knows to use the `-fpreserve-invariance` compiler option. Bug: tint:772 Change-Id: Ife1eb05265646727dc864f12f983781af4df3777 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/57644 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Tint LUCI CQ
parent
fd5829e5ea
commit
2c2aa2a76a
@@ -84,9 +84,9 @@ void CanonicalizeEntryPointIO::Run(CloneContext& ctx,
|
||||
for (auto* member : struct_ty->members()) {
|
||||
ast::DecorationList new_decorations = RemoveDecorations(
|
||||
&ctx, member->decorations(), [](const ast::Decoration* deco) {
|
||||
return deco
|
||||
->IsAnyOf<ast::BuiltinDecoration, ast::InterpolateDecoration,
|
||||
ast::LocationDecoration>();
|
||||
return deco->IsAnyOf<
|
||||
ast::BuiltinDecoration, ast::InterpolateDecoration,
|
||||
ast::InvariantDecoration, ast::LocationDecoration>();
|
||||
});
|
||||
new_struct_members.push_back(
|
||||
ctx.dst->Member(ctx.Clone(member->symbol()),
|
||||
@@ -156,9 +156,9 @@ void CanonicalizeEntryPointIO::Run(CloneContext& ctx,
|
||||
ast::DecorationList new_decorations = RemoveDecorations(
|
||||
&ctx, member->Declaration()->decorations(),
|
||||
[](const ast::Decoration* deco) {
|
||||
return !deco->IsAnyOf<ast::BuiltinDecoration,
|
||||
ast::InterpolateDecoration,
|
||||
ast::LocationDecoration>();
|
||||
return !deco->IsAnyOf<
|
||||
ast::BuiltinDecoration, ast::InterpolateDecoration,
|
||||
ast::InvariantDecoration, ast::LocationDecoration>();
|
||||
});
|
||||
|
||||
if (cfg->builtin_style == BuiltinStyle::kParameter &&
|
||||
@@ -246,9 +246,9 @@ void CanonicalizeEntryPointIO::Run(CloneContext& ctx,
|
||||
ast::DecorationList new_decorations = RemoveDecorations(
|
||||
&ctx, member->Declaration()->decorations(),
|
||||
[](const ast::Decoration* deco) {
|
||||
return !deco->IsAnyOf<ast::BuiltinDecoration,
|
||||
ast::InterpolateDecoration,
|
||||
ast::LocationDecoration>();
|
||||
return !deco->IsAnyOf<
|
||||
ast::BuiltinDecoration, ast::InterpolateDecoration,
|
||||
ast::InvariantDecoration, ast::LocationDecoration>();
|
||||
});
|
||||
auto symbol = ctx.Clone(member->Declaration()->symbol());
|
||||
auto* member_ty = ctx.Clone(member->Declaration()->type());
|
||||
|
||||
@@ -691,6 +691,58 @@ fn frag_main(tint_symbol_2 : tint_symbol_3) {
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(CanonicalizeEntryPointIOTest, InvariantAttributes) {
|
||||
auto* src = R"(
|
||||
struct VertexOut {
|
||||
[[builtin(position), invariant]] pos : vec4<f32>;
|
||||
};
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main1() -> VertexOut {
|
||||
return VertexOut();
|
||||
}
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main2() -> [[builtin(position), invariant]] vec4<f32> {
|
||||
return vec4<f32>();
|
||||
}
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct VertexOut {
|
||||
pos : vec4<f32>;
|
||||
};
|
||||
|
||||
struct tint_symbol {
|
||||
[[builtin(position), invariant]]
|
||||
pos : vec4<f32>;
|
||||
};
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main1() -> tint_symbol {
|
||||
let tint_symbol_1 : VertexOut = VertexOut();
|
||||
return tint_symbol(tint_symbol_1.pos);
|
||||
}
|
||||
|
||||
struct tint_symbol_2 {
|
||||
[[builtin(position), invariant]]
|
||||
value : vec4<f32>;
|
||||
};
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main2() -> tint_symbol_2 {
|
||||
return tint_symbol_2(vec4<f32>());
|
||||
}
|
||||
)";
|
||||
|
||||
DataMap data;
|
||||
data.Add<CanonicalizeEntryPointIO::Config>(
|
||||
CanonicalizeEntryPointIO::BuiltinStyle::kStructMember);
|
||||
auto got = Run<CanonicalizeEntryPointIO>(src, data);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(CanonicalizeEntryPointIOTest, Struct_LayoutDecorations) {
|
||||
auto* src = R"(
|
||||
[[block]]
|
||||
|
||||
Reference in New Issue
Block a user