From e448fff0da5844ecb888d4c53c1310e09f21cc42 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Thu, 8 Jun 2023 10:23:52 -0700 Subject: [PATCH] [Impeller] sort all vertex inputs by location. (flutter/engine#42664) Fixes https://github.com/flutter/flutter/issues/128283 Why doesn't this happen elsewhere? might depend on how spirv compiles shaders or the order they run in. Long term fix is https://github.com/flutter/engine/pull/42628 which computes all offset data in the compiler ![flutter_04](https://github.com/flutter/engine/assets/8975114/645c5db6-4f2f-42f7-af8f-6230bba72b2b) --- engine/src/flutter/impeller/renderer/vertex_descriptor.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/engine/src/flutter/impeller/renderer/vertex_descriptor.cc b/engine/src/flutter/impeller/renderer/vertex_descriptor.cc index 97dff83913..b9c1511cbc 100644 --- a/engine/src/flutter/impeller/renderer/vertex_descriptor.cc +++ b/engine/src/flutter/impeller/renderer/vertex_descriptor.cc @@ -17,6 +17,14 @@ bool VertexDescriptor::SetStageInputs( for (size_t i = 0; i < count; i++) { inputs_.emplace_back(*stage_inputs[i]); } + // TODO(jonahwilliams): vulkan shader stage needed sorting too. Remove once + // autogenerated headers include offset information. + // See: https://github.com/flutter/flutter/issues/116168 + auto compare_locations = [](ShaderStageIOSlot a, ShaderStageIOSlot b) { + return a.location < b.location; + }; + std::sort(inputs_.begin(), inputs_.end(), compare_locations); + return true; }