#include "svga_screen.h"
#include "svga_screen_cache.h"
#include "svga_context.h"
-
+#include "svga_cmd.h"
#define SVGA_SURFACE_CACHE_ENABLED 1
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
total_size += img_size;
}
- total_size *= key->numFaces;
+ total_size *= key->numFaces * key->arraySize * MAX2(1, key->sampleCount);
return total_size;
}
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;
}
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 */
/* 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 (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
+ * 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 = SVGA3D_InvalidateGBSurface(svga->swc, entry->handle);
+ assert(ret == PIPE_OK);
+ }
/* add the entry to the invalidated list */
LIST_ADD(&entry->head, &cache->invalidated);
key->cachable);
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
}
if (!handle) {
+ /* Unable to recycle surface, allocate a new one */
unsigned usage = 0;
if (!key->cachable)
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,