+}
+
+uint32_t
+v3d_prog_data_size(gl_shader_stage stage)
+{
+ static const int prog_data_size[] = {
+ [MESA_SHADER_VERTEX] = sizeof(struct v3d_vs_prog_data),
+ [MESA_SHADER_GEOMETRY] = sizeof(struct v3d_gs_prog_data),
+ [MESA_SHADER_FRAGMENT] = sizeof(struct v3d_fs_prog_data),
+ [MESA_SHADER_COMPUTE] = sizeof(struct v3d_compute_prog_data),
+ };
+
+ assert(stage >= 0 &&
+ stage < ARRAY_SIZE(prog_data_size) &&
+ prog_data_size[stage]);
+
+ return prog_data_size[stage];
+}
+
+uint64_t *v3d_compile(const struct v3d_compiler *compiler,
+ struct v3d_key *key,
+ struct v3d_prog_data **out_prog_data,
+ nir_shader *s,
+ void (*debug_output)(const char *msg,
+ void *debug_output_data),
+ void *debug_output_data,
+ int program_id, int variant_id,
+ uint32_t *final_assembly_size)
+{
+ struct v3d_compile *c;
+
+ for (int i = 0; true; i++) {
+ c = vir_compile_init(compiler, key, s,
+ debug_output, debug_output_data,
+ program_id, variant_id,
+ i > 0 /* fallback_scheduler */);
+
+ v3d_attempt_compile(c);
+
+ if (i > 0 ||
+ c->compilation_result !=
+ V3D_COMPILATION_FAILED_REGISTER_ALLOCATION)
+ break;
+
+ char *debug_msg;
+ int ret = asprintf(&debug_msg,
+ "Using fallback scheduler for %s",
+ vir_get_stage_name(c));
+
+ if (ret >= 0) {
+ if (unlikely(V3D_DEBUG & V3D_DEBUG_PERF))
+ fprintf(stderr, "%s\n", debug_msg);
+
+ c->debug_output(debug_msg, c->debug_output_data);
+ free(debug_msg);
+ }
+
+ vir_compile_destroy(c);
+ }
+
+ struct v3d_prog_data *prog_data;
+
+ prog_data = rzalloc_size(NULL, v3d_prog_data_size(c->s->info.stage));