nvc0/ir: fix TargetNVC0::insnCanLoadOffset()
[mesa.git] / src / gallium / drivers / svga / svga_screen_cache.c
index 82d2ebce9768b7be0c7240f9ce45ed6a7c67ed9f..0c2b594de002a75c4d18c61d0887f81e39a6d16e 100644 (file)
@@ -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;
 }
@@ -362,7 +363,21 @@ 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.
           */
-         svga->swc->surface_invalidate(svga->swc, entry->handle);
+         if (svga->swc->surface_invalidate(svga->swc, entry->handle) != PIPE_OK) {
+            MAYBE_UNUSED enum pipe_error ret;
+
+            /* Even though surface invalidation here is done after the command
+             * buffer is flushed, it is still possible that it will
+             * fail because there might be just enough of this command that is
+             * filling up the command buffer, so in this case we will call
+             * the winsys flush directly to flush the buffer.
+             * Note, we don't want to call svga_context_flush() here because
+             * this function itself is called inside svga_context_flush().
+             */
+            svga->swc->flush(svga->swc, NULL);
+            ret = svga->swc->surface_invalidate(svga->swc, entry->handle);
+            assert(ret == PIPE_OK);
+         }
 
          /* add the entry to the invalidated list */
          LIST_ADD(&entry->head, &cache->invalidated);
@@ -461,6 +476,7 @@ svga_screen_surface_create(struct svga_screen *svgascreen,
             key->cachable);
 
    if (cachable) {
+      /* Try to re-cycle a previously freed, cached surface */
       if (key->format == SVGA3D_BUFFER) {
          SVGA3dSurfaceFlags hint_flag;
 
@@ -521,6 +537,7 @@ svga_screen_surface_create(struct svga_screen *svgascreen,
    }
 
    if (!handle) {
+      /* Unable to recycle surface, allocate a new one */
       unsigned usage = 0;
 
       if (!key->cachable)