HLSL-IR: Use stable_sort to sort members in ShaderIO
Because we may add two members with the same kClipDistances attribute, we need to make sure the relative ordering of the two members remains the same.
Bug: 364865292
Change-Id: Iea56c3236e7e29ec9ef3de464b08dff22941cf08
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/212355
Auto-Submit: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
diff --git a/src/tint/lang/hlsl/writer/raise/shader_io.cc b/src/tint/lang/hlsl/writer/raise/shader_io.cc
index 3a68b5c..51ddf5f 100644
--- a/src/tint/lang/hlsl/writer/raise/shader_io.cc
+++ b/src/tint/lang/hlsl/writer/raise/shader_io.cc
@@ -213,8 +213,10 @@
input_indices.Resize(input_data.Length());
// Sort the struct members to satisfy HLSL interfacing matching rules.
- std::sort(input_data.begin(), input_data.end(),
- [&](auto& x, auto& y) { return StructMemberComparator(x, y); });
+ // We use stable_sort so that two members with the same attributes maintain their relative
+ // ordering (e.g. kClipDistance).
+ std::stable_sort(input_data.begin(), input_data.end(),
+ [&](auto& x, auto& y) { return StructMemberComparator(x, y); });
Vector<core::type::Manager::StructMemberDesc, 4> input_struct_members;
for (auto& input : input_data) {