mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 08:27:05 +00:00
writer/spirv: Implement invariant attribute
Bug: tint:772 Change-Id: I94f8e95f7c1206f33dbf4defba2d22d95a5cfb1e Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/57643 Reviewed-by: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Tint LUCI CQ
parent
762c81b4eb
commit
88b8e2f289
@@ -145,9 +145,9 @@ void Spirv::HandleEntryPointIOTypes(CloneContext& ctx) const {
|
||||
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()),
|
||||
@@ -316,9 +316,9 @@ Symbol Spirv::HoistToInputVariables(
|
||||
// Base case: create a global variable and return.
|
||||
ast::DecorationList new_decorations =
|
||||
RemoveDecorations(&ctx, 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_decorations.push_back(
|
||||
ctx.dst->ASTNodes().Create<ast::DisableValidationDecoration>(
|
||||
@@ -382,9 +382,9 @@ void Spirv::HoistToOutputVariables(CloneContext& ctx,
|
||||
// Create a global variable.
|
||||
ast::DecorationList new_decorations =
|
||||
RemoveDecorations(&ctx, 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_decorations.push_back(
|
||||
ctx.dst->ASTNodes().Create<ast::DisableValidationDecoration>(
|
||||
|
||||
@@ -601,6 +601,58 @@ fn frag_main() {
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(SpirvTest, HandleEntryPointIOTypes_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>;
|
||||
};
|
||||
|
||||
[[builtin(position), invariant, internal(disable_validation__ignore_storage_class)]] var<out> tint_symbol_1 : vec4<f32>;
|
||||
|
||||
fn tint_symbol_2(tint_symbol : VertexOut) {
|
||||
tint_symbol_1 = tint_symbol.pos;
|
||||
}
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main1() {
|
||||
tint_symbol_2(VertexOut());
|
||||
return;
|
||||
}
|
||||
|
||||
[[builtin(position), invariant, internal(disable_validation__ignore_storage_class)]] var<out> tint_symbol_4 : vec4<f32>;
|
||||
|
||||
fn tint_symbol_5(tint_symbol_3 : vec4<f32>) {
|
||||
tint_symbol_4 = tint_symbol_3;
|
||||
}
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main2() {
|
||||
tint_symbol_5(vec4<f32>());
|
||||
return;
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<Spirv>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(SpirvTest, HandleEntryPointIOTypes_StructLayoutDecorations) {
|
||||
auto* src = R"(
|
||||
[[block]]
|
||||
|
||||
Reference in New Issue
Block a user