radeonsi: add an initial dump_debug_state implementation dumping shaders
[mesa.git] / src / gallium / drivers / svga / svga_screen_cache.c
index 9350feeb8610a16b92124d130f60145781df073d..3c765394a88423a804e0d252e08b056d8d3fb76e 100644 (file)
@@ -76,7 +76,7 @@ surface_size(const struct svga_host_surface_cache_key *key)
 /**
  * Compute the bucket for this key.
  */
-static INLINE unsigned
+static inline unsigned
 svga_screen_cache_bucket(const struct svga_host_surface_cache_key *key)
 {
    return util_hash_crc32(key, sizeof *key) % SVGA_HOST_SURFACE_CACHE_BUCKETS;
@@ -88,7 +88,7 @@ svga_screen_cache_bucket(const struct svga_host_surface_cache_key *key)
  * found, remove it from the cache and return the surface pointer.
  * Return NULL otherwise.
  */
-static INLINE struct svga_winsys_surface *
+static struct svga_winsys_surface *
 svga_screen_cache_lookup(struct svga_screen *svgascreen,
                          const struct svga_host_surface_cache_key *key)
 {
@@ -194,10 +194,10 @@ svga_screen_cache_shrink(struct svga_screen *svgascreen,
 }
 
 
-/*
+/**
  * Transfers a handle reference.
  */
-static INLINE void
+static void
 svga_screen_cache_add(struct svga_screen *svgascreen,
                       const struct svga_host_surface_cache_key *key,
                       struct svga_winsys_surface **p_handle)
@@ -210,7 +210,6 @@ svga_screen_cache_add(struct svga_screen *svgascreen,
    
    assert(key->cachable);
 
-   assert(handle);
    if (!handle)
       return;
    
@@ -331,6 +330,10 @@ svga_screen_cache_flush(struct svga_screen *svgascreen,
 }
 
 
+/**
+ * Free all the surfaces in the cache.
+ * Called when destroying the svga screen object.
+ */
 void
 svga_screen_cache_cleanup(struct svga_screen *svgascreen)
 {
@@ -381,6 +384,11 @@ svga_screen_cache_init(struct svga_screen *svgascreen)
 }
 
 
+/**
+ * Allocate a new host-side surface.  If the surface is marked as cachable,
+ * first try re-using a surface in the cache of freed surfaces.  Otherwise,
+ * allocate a new surface.
+ */
 struct svga_winsys_surface *
 svga_screen_surface_create(struct svga_screen *svgascreen,
                            struct svga_host_surface_cache_key *key)
@@ -441,6 +449,8 @@ svga_screen_surface_create(struct svga_screen *svgascreen,
       handle = sws->surface_create(sws,
                                    key->flags,
                                    key->format,
+                                   key->cachable ?
+                                   0 : SVGA_SURFACE_USAGE_SHARED,
                                    key->size,
                                    key->numFaces,
                                    key->numMipLevels);
@@ -457,6 +467,10 @@ svga_screen_surface_create(struct svga_screen *svgascreen,
 }
 
 
+/**
+ * Release a surface.  We don't actually free the surface- we put
+ * it into the cache of freed surfaces (if it's cachable).
+ */
 void
 svga_screen_surface_destroy(struct svga_screen *svgascreen,
                             const struct svga_host_surface_cache_key *key,
@@ -477,3 +491,37 @@ svga_screen_surface_destroy(struct svga_screen *svgascreen,
       sws->surface_reference(sws, p_handle, NULL);
    }
 }
+
+
+/**
+ * Print/dump the contents of the screen cache.  For debugging.
+ */
+void
+svga_screen_cache_dump(const struct svga_screen *svgascreen)
+{
+   const struct svga_host_surface_cache *cache = &svgascreen->cache;
+   unsigned bucket;
+   unsigned count = 0;
+
+   debug_printf("svga3d surface cache:\n");
+   for (bucket = 0; bucket < SVGA_HOST_SURFACE_CACHE_BUCKETS; bucket++) {
+      struct list_head *curr;
+      curr = cache->bucket[bucket].next;
+      while (curr && curr != &cache->bucket[bucket]) {
+         struct svga_host_surface_cache_entry *entry =
+            LIST_ENTRY(struct svga_host_surface_cache_entry,
+                       curr, bucket_head);
+         if (entry->key.format != 37) {
+            debug_printf("  %u x %u x %u format %u\n",
+                         entry->key.size.width,
+                         entry->key.size.height,
+                         entry->key.size.depth,
+                         entry->key.format);
+         }
+         curr = curr->next;
+         count++;
+      }
+   }
+
+   debug_printf("%u surfaces, %u bytes\n", count, cache->total_size);
+}