+static bool
+key_debug(struct brw_context *brw, const char *name, int a, int b)
+{
+ if (a != b) {
+ perf_debug(" %s %d->%d\n", name, a, b);
+ return true;
+ }
+ return false;
+}
+
+void
+brw_vs_debug_recompile(struct brw_context *brw,
+ struct gl_shader_program *prog,
+ const struct brw_vs_prog_key *key)
+{
+ struct brw_cache_item *c = NULL;
+ const struct brw_vs_prog_key *old_key = NULL;
+ bool found = false;
+
+ perf_debug("Recompiling vertex shader for program %d\n", prog->Name);
+
+ for (unsigned int i = 0; i < brw->cache.size; i++) {
+ for (c = brw->cache.items[i]; c; c = c->next) {
+ if (c->cache_id == BRW_VS_PROG) {
+ old_key = c->key;
+
+ if (old_key->base.program_string_id == key->base.program_string_id)
+ break;
+ }
+ }
+ if (c)
+ break;
+ }
+
+ if (!c) {
+ perf_debug(" Didn't find previous compile in the shader cache for "
+ "debug\n");
+ return;
+ }
+
+ for (unsigned int i = 0; i < VERT_ATTRIB_MAX; i++) {
+ found |= key_debug(brw, "Vertex attrib w/a flags",
+ old_key->gl_attrib_wa_flags[i],
+ key->gl_attrib_wa_flags[i]);
+ }
+
+ found |= key_debug(brw, "user clip flags",
+ old_key->base.userclip_active, key->base.userclip_active);
+
+ found |= key_debug(brw, "user clipping planes as push constants",
+ old_key->base.nr_userclip_plane_consts,
+ key->base.nr_userclip_plane_consts);
+
+ found |= key_debug(brw, "copy edgeflag",
+ old_key->copy_edgeflag, key->copy_edgeflag);
+ found |= key_debug(brw, "PointCoord replace",
+ old_key->point_coord_replace, key->point_coord_replace);
+ found |= key_debug(brw, "vertex color clamping",
+ old_key->base.clamp_vertex_color, key->base.clamp_vertex_color);
+
+ found |= brw_debug_recompile_sampler_key(brw, &old_key->base.tex,
+ &key->base.tex);
+
+ if (!found) {
+ perf_debug(" Something else\n");
+ }
+}
+
+
+void
+brw_setup_vec4_key_clip_info(struct brw_context *brw,
+ struct brw_vec4_prog_key *key,
+ bool program_uses_clip_distance)
+{
+ struct gl_context *ctx = &brw->ctx;
+
+ key->userclip_active = (ctx->Transform.ClipPlanesEnabled != 0);
+ if (key->userclip_active && !program_uses_clip_distance) {
+ key->nr_userclip_plane_consts
+ = _mesa_logbase2(ctx->Transform.ClipPlanesEnabled) + 1;
+ }
+}
+