+/**
+ * Chooses an index in the shader_time buffer and sets up tracking information
+ * for our printouts.
+ *
+ * Note that this holds on to references to the underlying programs, which may
+ * change their lifetimes compared to normal operation.
+ */
+int
+brw_get_shader_time_index(struct brw_context *brw,
+ struct gl_shader_program *shader_prog,
+ struct gl_program *prog,
+ enum shader_time_shader_type type)
+{
+ struct gl_context *ctx = &brw->intel.ctx;
+
+ int shader_time_index = brw->shader_time.num_entries++;
+ assert(shader_time_index < brw->shader_time.max_entries);
+ brw->shader_time.types[shader_time_index] = type;
+
+ _mesa_reference_shader_program(ctx,
+ &brw->shader_time.shader_programs[shader_time_index],
+ shader_prog);
+
+ _mesa_reference_program(ctx,
+ &brw->shader_time.programs[shader_time_index],
+ prog);
+
+ return shader_time_index;
+}
+