+/* If there are empty components in the slot compact the remaining components
+ * as close to component 0 as possible. This will make it easier to fill the
+ * empty components with components from a different slot in a following pass.
+ */
+static void
+compact_components(nir_shader *producer, nir_shader *consumer,
+ struct assigned_comps *assigned_comps,
+ bool default_to_smooth_interp)
+{
+ struct exec_list *input_list = &consumer->inputs;
+ struct exec_list *output_list = &producer->outputs;
+ struct varying_loc remap[MAX_VARYINGS_INCL_PATCH][4] = {{{0}, {0}}};
+ struct varying_component *varying_comp_info;
+ unsigned varying_comp_info_size;
+
+ /* Gather varying component info */
+ gather_varying_component_info(consumer, &varying_comp_info,
+ &varying_comp_info_size,
+ default_to_smooth_interp);
+
+ /* Sort varying components. */
+ qsort(varying_comp_info, varying_comp_info_size,
+ sizeof(struct varying_component), cmp_varying_component);
+
+ unsigned cursor = 0;
+ unsigned comp = 0;
+
+ /* Set the remap array based on the sorted components */
+ for (unsigned i = 0; i < varying_comp_info_size; i++ ) {
+ struct varying_component *info = &varying_comp_info[i];
+
+ assert(info->is_patch || cursor < MAX_VARYING);
+ if (info->is_patch) {
+ /* The list should be sorted with all non-patch inputs first followed
+ * by patch inputs. When we hit our first patch input, we need to
+ * reset the cursor to MAX_VARYING so we put them in the right slot.
+ */
+ if (cursor < MAX_VARYING) {
+ cursor = MAX_VARYING;
+ comp = 0;
+ }