Merge branch 'mesa_7_6_branch'
[mesa.git] / src / mesa / drivers / dri / i965 / brw_state_cache.c
index e40d7a04164f50110f8070bedb4d60b6f7c01cb5..c262e1db8b9e83641d789b0adb61e37a783fde54 100644 (file)
@@ -517,6 +517,41 @@ brw_clear_cache(struct brw_context *brw, struct brw_cache *cache)
    brw->state.dirty.cache |= ~0;
 }
 
+/* Clear all entries from the cache that point to the given bo.
+ *
+ * This lets us release memory for reuse earlier for known-dead buffers,
+ * at the cost of walking the entire hash table.
+ */
+void
+brw_state_cache_bo_delete(struct brw_cache *cache, dri_bo *bo)
+{
+   struct brw_cache_item **prev;
+   GLuint i;
+
+   if (INTEL_DEBUG & DEBUG_STATE)
+      _mesa_printf("%s\n", __FUNCTION__);
+
+   for (i = 0; i < cache->size; i++) {
+      for (prev = &cache->items[i]; *prev;) {
+        struct brw_cache_item *c = *prev;
+
+        if (drm_intel_bo_references(c->bo, bo)) {
+           int j;
+
+           *prev = c->next;
+
+           for (j = 0; j < c->nr_reloc_bufs; j++)
+              dri_bo_unreference(c->reloc_bufs[j]);
+           dri_bo_unreference(c->bo);
+           free((void *)c->key);
+           free(c);
+           cache->n_items--;
+        } else {
+           prev = &c->next;
+        }
+      }
+   }
+}
 
 void
 brw_state_cache_check_size(struct brw_context *brw)