+static void
+v3d_fs_set_prog_data(struct v3d_compile *c,
+ struct v3d_fs_prog_data *prog_data)
+{
+ v3d_set_fs_prog_data_inputs(c, prog_data);
+ prog_data->writes_z = (c->s->info.outputs_written &
+ (1 << FRAG_RESULT_DEPTH));
+ prog_data->discard = (c->s->info.fs.uses_discard ||
+ c->fs_key->sample_alpha_to_coverage);
+ prog_data->uses_center_w = c->uses_center_w;
+
+ /* If the shader has some side effects and hasn't allowed early
+ * fragment tests, disable them.
+ */
+ if (!c->s->info.fs.early_fragment_tests &&
+ (c->s->info.num_images ||
+ c->s->info.num_ssbos ||
+ c->s->info.num_abos)) {
+ prog_data->discard = true;
+ }
+}
+
+static void
+v3d_set_prog_data(struct v3d_compile *c,
+ struct v3d_prog_data *prog_data)
+{
+ prog_data->threads = c->threads;
+ prog_data->single_seg = !c->last_thrsw;
+ prog_data->spill_size = c->spill_size;
+
+ v3d_set_prog_data_uniforms(c, prog_data);
+ v3d_set_prog_data_ubo(c, prog_data);
+
+ if (c->s->info.stage == MESA_SHADER_VERTEX) {
+ v3d_vs_set_prog_data(c, (struct v3d_vs_prog_data *)prog_data);
+ } else {
+ assert(c->s->info.stage == MESA_SHADER_FRAGMENT);
+ v3d_fs_set_prog_data(c, (struct v3d_fs_prog_data *)prog_data);
+ }
+}
+
+static uint64_t *
+v3d_return_qpu_insts(struct v3d_compile *c, uint32_t *final_assembly_size)
+{
+ *final_assembly_size = c->qpu_inst_count * sizeof(uint64_t);
+
+ uint64_t *qpu_insts = malloc(*final_assembly_size);
+ if (!qpu_insts)
+ return NULL;
+
+ memcpy(qpu_insts, c->qpu_insts, *final_assembly_size);
+
+ vir_compile_destroy(c);
+
+ return qpu_insts;
+}
+
+static void
+v3d_nir_lower_vs_early(struct v3d_compile *c)
+{
+ /* Split our I/O vars and dead code eliminate the unused
+ * components.
+ */
+ NIR_PASS_V(c->s, nir_lower_io_to_scalar_early,
+ nir_var_shader_in | nir_var_shader_out);
+ uint64_t used_outputs[4] = {0};
+ for (int i = 0; i < c->vs_key->num_fs_inputs; i++) {
+ int slot = v3d_slot_get_slot(c->vs_key->fs_inputs[i]);
+ int comp = v3d_slot_get_component(c->vs_key->fs_inputs[i]);
+ used_outputs[comp] |= 1ull << slot;
+ }
+ NIR_PASS_V(c->s, nir_remove_unused_io_vars,
+ &c->s->outputs, used_outputs, NULL); /* demotes to globals */
+ NIR_PASS_V(c->s, nir_lower_global_vars_to_local);
+ v3d_optimize_nir(c->s);
+ NIR_PASS_V(c->s, nir_remove_dead_variables, nir_var_shader_in);
+ NIR_PASS_V(c->s, nir_lower_io, nir_var_shader_in | nir_var_shader_out,
+ type_size_vec4,
+ (nir_lower_io_options)0);
+}
+