util: remove LIST_ADD macro
[mesa.git] / src / gallium / drivers / svga / svga_screen_cache.c
index 0816ff68c8acce4608809503b5955fe0f33066b1..6d77b55c4f47b17b4f2415228223f3138e46c318 100644 (file)
@@ -33,7 +33,7 @@
 #include "svga_screen.h"
 #include "svga_screen_cache.h"
 #include "svga_context.h"
-
+#include "svga_cmd.h"
 
 #define SVGA_SURFACE_CACHE_ENABLED 1
 
@@ -48,6 +48,7 @@ surface_size(const struct svga_host_surface_cache_key *key)
 
    assert(key->numMipLevels > 0);
    assert(key->numFaces > 0);
+   assert(key->arraySize > 0);
 
    if (key->format == SVGA3D_BUFFER) {
       /* Special case: we don't want to count vertex/index buffers
@@ -68,7 +69,7 @@ surface_size(const struct svga_host_surface_cache_key *key)
       total_size += img_size;
    }
 
-   total_size *= key->numFaces;
+   total_size *= key->numFaces * key->arraySize * MAX2(1, key->sampleCount);
 
    return total_size;
 }
@@ -138,7 +139,7 @@ svga_screen_cache_lookup(struct svga_screen *svgascreen,
          LIST_DEL(&entry->head);
 
          /* Add the cache entry (but not the surface!) to the empty list */
-         LIST_ADD(&entry->head, &cache->empty);
+         list_add(&entry->head, &cache->empty);
 
          /* update the cache size */
          surf_size = surface_size(&entry->key);
@@ -193,7 +194,7 @@ svga_screen_cache_shrink(struct svga_screen *svgascreen,
 
          LIST_DEL(&entry->bucket_head);
          LIST_DEL(&entry->head);
-         LIST_ADD(&entry->head, &cache->empty);
+         list_add(&entry->head, &cache->empty);
 
          if (cache->total_size <= target_size) {
             /* all done */
@@ -290,7 +291,12 @@ svga_screen_cache_add(struct svga_screen *svgascreen,
 
       SVGA_DBG(DEBUG_CACHE|DEBUG_DMA,
                "cache sid %p\n", entry->handle);
-      LIST_ADD(&entry->head, &cache->validated);
+
+      /* If we don't have gb objects, we don't need to invalidate. */
+      if (sws->have_gb_objects)
+         list_add(&entry->head, &cache->validated);
+      else
+         list_add(&entry->head, &cache->invalidated);
 
       cache->total_size += surf_size;
    }
@@ -337,11 +343,11 @@ svga_screen_cache_flush(struct svga_screen *svgascreen,
          sws->fence_reference(sws, &entry->fence, fence);
 
          /* Add entry to the unused list */
-         LIST_ADD(&entry->head, &cache->unused);
+         list_add(&entry->head, &cache->unused);
 
          /* Add entry to the hash table bucket */
          bucket = svga_screen_cache_bucket(&entry->key);
-         LIST_ADD(&entry->bucket_head, &cache->bucket[bucket]);
+         list_add(&entry->bucket_head, &cache->bucket[bucket]);
       }
 
       curr = next;
@@ -354,6 +360,7 @@ svga_screen_cache_flush(struct svga_screen *svgascreen,
       entry = LIST_ENTRY(struct svga_host_surface_cache_entry, curr, head);
 
       assert(entry->handle);
+      assert(svga_have_gb_objects(svga));
 
       if (sws->surface_is_flushed(sws, entry->handle)) {
          /* remove entry from the validated list */
@@ -362,8 +369,8 @@ svga_screen_cache_flush(struct svga_screen *svgascreen,
          /* It is now safe to invalidate the surface content.
           * It will be done using the current context.
           */
-         if (svga->swc->surface_invalidate(svga->swc, entry->handle) != PIPE_OK) {
-            enum pipe_error ret;
+         if (SVGA3D_InvalidateGBSurface(svga->swc, entry->handle) != PIPE_OK) {
+            ASSERTED enum pipe_error ret;
 
             /* Even though surface invalidation here is done after the command
              * buffer is flushed, it is still possible that it will
@@ -374,12 +381,12 @@ svga_screen_cache_flush(struct svga_screen *svgascreen,
              * this function itself is called inside svga_context_flush().
              */
             svga->swc->flush(svga->swc, NULL);
-            ret = svga->swc->surface_invalidate(svga->swc, entry->handle);
+            ret = SVGA3D_InvalidateGBSurface(svga->swc, entry->handle);
             assert(ret == PIPE_OK);
          }
 
          /* add the entry to the invalidated list */
-         LIST_ADD(&entry->head, &cache->invalidated);
+         list_add(&entry->head, &cache->invalidated);
       }
 
       curr = next;
@@ -429,17 +436,17 @@ svga_screen_cache_init(struct svga_screen *svgascreen)
    (void) mtx_init(&cache->mutex, mtx_plain);
 
    for (i = 0; i < SVGA_HOST_SURFACE_CACHE_BUCKETS; ++i)
-      LIST_INITHEAD(&cache->bucket[i]);
+      list_inithead(&cache->bucket[i]);
 
-   LIST_INITHEAD(&cache->unused);
+   list_inithead(&cache->unused);
 
-   LIST_INITHEAD(&cache->validated);
+   list_inithead(&cache->validated);
 
-   LIST_INITHEAD(&cache->invalidated);
+   list_inithead(&cache->invalidated);
 
-   LIST_INITHEAD(&cache->empty);
+   list_inithead(&cache->empty);
    for (i = 0; i < SVGA_HOST_SURFACE_CACHE_SIZE; ++i)
-      LIST_ADDTAIL(&cache->entries[i].head, &cache->empty);
+      list_addtail(&cache->entries[i].head, &cache->empty);
 
    return PIPE_OK;
 }
@@ -477,7 +484,7 @@ svga_screen_surface_create(struct svga_screen *svgascreen,
    if (cachable) {
       /* Try to re-cycle a previously freed, cached surface */
       if (key->format == SVGA3D_BUFFER) {
-         SVGA3dSurfaceFlags hint_flag;
+         SVGA3dSurfaceAllFlags hint_flag;
 
          /* For buffers, round the buffer size up to the nearest power
           * of two to increase the probability of cache hits.  Keep
@@ -543,6 +550,8 @@ svga_screen_surface_create(struct svga_screen *svgascreen,
          usage |= SVGA_SURFACE_USAGE_SHARED;
       if (key->scanout)
          usage |= SVGA_SURFACE_USAGE_SCANOUT;
+      if (key->coherent)
+         usage |= SVGA_SURFACE_USAGE_COHERENT;
 
       handle = sws->surface_create(sws,
                                    key->flags,