Skip to content

Commit

Permalink
Canonicalize index-ordering of entry point attributes
Browse files Browse the repository at this point in the history
This makes the output of entry point IO canonicalization deterministic.
This fixes unit test failures in some environments.

Change-Id: I013f147bb00515b2f87eb952c00f957b1a0a4261
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/165941
Auto-Submit: David Neto <[email protected]>
Kokoro: Kokoro <[email protected]>
Reviewed-by: James Price <[email protected]>
Commit-Queue: James Price <[email protected]>
  • Loading branch information
dneto0 authored and Dawn LUCI CQ committed Dec 15, 2023
1 parent 6e88861 commit 3bb3c53
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/tint/lang/wgsl/ast/transform/canonicalize_entry_point_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,8 @@ struct CanonicalizeEntryPointIO::State {

/// Comparison function used to reorder struct members such that all members with
/// color attributes appear first (ordered by color slot), then location attributes (ordered by
/// location slot), followed by those with builtin attributes (ordered by BuiltinOrder).
/// location slot), then index attributes (ordered by index slot), followed by those with
/// builtin attributes (ordered by BuiltinOrder).
/// @param x a struct member
/// @param y another struct member
/// @returns true if a comes before b
Expand All @@ -575,6 +576,15 @@ struct CanonicalizeEntryPointIO::State {
return x.location.has_value();
}

if (x.index.has_value() && y.index.has_value()) {
// Both have index attributes: smallest goes first.
return x.index < y.index;
}
if (x.index.has_value() != y.index.has_value()) {
// The member with the index goes first
return x.index.has_value();
}

{
auto* x_blt = GetAttribute<BuiltinAttribute>(x.member->attributes);
auto* y_blt = GetAttribute<BuiltinAttribute>(y.member->attributes);
Expand Down Expand Up @@ -635,8 +645,8 @@ struct CanonicalizeEntryPointIO::State {
wrapper_struct_output_members.Push({
/* member */ b.Member(name, outval.type, std::move(outval.attributes)),
/* location */ outval.location,
/* index */ outval.index,
/* color */ std::nullopt,
/* index */ std::nullopt,
});
assignments.Push(b.Assign(b.MemberAccessor(wrapper_result, name), outval.value));
}
Expand Down

0 comments on commit 3bb3c53

Please sign in to comment.