+static void
+vc4_setup_compiled_fs_inputs(struct vc4_context *vc4, struct vc4_compile *c,
+ struct vc4_compiled_shader *shader)
+{
+ struct vc4_fs_inputs inputs;
+
+ memset(&inputs, 0, sizeof(inputs));
+ inputs.input_slots = ralloc_array(shader,
+ struct vc4_varying_slot,
+ c->num_input_slots);
+
+ bool input_live[c->num_input_slots];
+
+ memset(input_live, 0, sizeof(input_live));
+ qir_for_each_inst_inorder(inst, c) {
+ for (int i = 0; i < qir_get_nsrc(inst); i++) {
+ if (inst->src[i].file == QFILE_VARY)
+ input_live[inst->src[i].index] = true;
+ }
+ }
+
+ for (int i = 0; i < c->num_input_slots; i++) {
+ struct vc4_varying_slot *slot = &c->input_slots[i];
+
+ if (!input_live[i])
+ continue;
+
+ /* Skip non-VS-output inputs. */
+ if (slot->slot == (uint8_t)~0)
+ continue;
+
+ if (slot->slot == VARYING_SLOT_COL0 ||
+ slot->slot == VARYING_SLOT_COL1 ||
+ slot->slot == VARYING_SLOT_BFC0 ||
+ slot->slot == VARYING_SLOT_BFC1) {
+ shader->color_inputs |= (1 << inputs.num_inputs);
+ }
+
+ inputs.input_slots[inputs.num_inputs] = *slot;
+ inputs.num_inputs++;
+ }
+ shader->num_inputs = inputs.num_inputs;
+
+ /* Add our set of inputs to the set of all inputs seen. This way, we
+ * can have a single pointer that identifies an FS inputs set,
+ * allowing VS to avoid recompiling when the FS is recompiled (or a
+ * new one is bound using separate shader objects) but the inputs
+ * don't change.
+ */
+ struct set_entry *entry = _mesa_set_search(vc4->fs_inputs_set, &inputs);
+ if (entry) {
+ shader->fs_inputs = entry->key;
+ ralloc_free(inputs.input_slots);
+ } else {
+ struct vc4_fs_inputs *alloc_inputs;
+
+ alloc_inputs = rzalloc(vc4->fs_inputs_set, struct vc4_fs_inputs);
+ memcpy(alloc_inputs, &inputs, sizeof(inputs));
+ ralloc_steal(alloc_inputs, inputs.input_slots);
+ _mesa_set_add(vc4->fs_inputs_set, alloc_inputs);
+
+ shader->fs_inputs = alloc_inputs;
+ }
+}
+