X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fdrivers%2Fsvga%2Fsvga_screen_cache.c;h=82d2ebce9768b7be0c7240f9ce45ed6a7c67ed9f;hb=2094b75c688b412ca5b7183e6a0da2b03ec4403f;hp=eaa589c4c2697402a21e6950b92a09edb3432315;hpb=45078e8890a6709390007d0fce8d6ed1be5ad5c0;p=mesa.git diff --git a/src/gallium/drivers/svga/svga_screen_cache.c b/src/gallium/drivers/svga/svga_screen_cache.c index eaa589c4c26..82d2ebce976 100644 --- a/src/gallium/drivers/svga/svga_screen_cache.c +++ b/src/gallium/drivers/svga/svga_screen_cache.c @@ -25,13 +25,14 @@ #include "util/u_math.h" #include "util/u_memory.h" -#include "util/u_hash.h" +#include "util/crc32.h" #include "svga_debug.h" #include "svga_format.h" #include "svga_winsys.h" #include "svga_screen.h" #include "svga_screen_cache.h" +#include "svga_context.h" #define SVGA_SURFACE_CACHE_ENABLED 1 @@ -104,7 +105,7 @@ svga_screen_cache_lookup(struct svga_screen *svgascreen, bucket = svga_screen_cache_bucket(key); - pipe_mutex_lock(cache->mutex); + mtx_lock(&cache->mutex); curr = cache->bucket[bucket].next; next = curr->next; @@ -154,7 +155,7 @@ svga_screen_cache_lookup(struct svga_screen *svgascreen, next = curr->next; } - pipe_mutex_unlock(cache->mutex); + mtx_unlock(&cache->mutex); if (SVGA_DEBUG & DEBUG_DMA) debug_printf("%s: cache %s after %u tries (bucket %d)\n", __FUNCTION__, @@ -226,12 +227,12 @@ svga_screen_cache_add(struct svga_screen *svgascreen, surf_size = surface_size(key); *p_handle = NULL; - pipe_mutex_lock(cache->mutex); + mtx_lock(&cache->mutex); if (surf_size >= SVGA_HOST_SURFACE_CACHE_BYTES) { /* this surface is too large to cache, just free it */ sws->surface_reference(sws, &handle, NULL); - pipe_mutex_unlock(cache->mutex); + mtx_unlock(&cache->mutex); return; } @@ -249,7 +250,7 @@ svga_screen_cache_add(struct svga_screen *svgascreen, * just discard this surface. */ sws->surface_reference(sws, &handle, NULL); - pipe_mutex_unlock(cache->mutex); + mtx_unlock(&cache->mutex); return; } } @@ -300,7 +301,7 @@ svga_screen_cache_add(struct svga_screen *svgascreen, sws->surface_reference(sws, &handle, NULL); } - pipe_mutex_unlock(cache->mutex); + mtx_unlock(&cache->mutex); } @@ -310,6 +311,7 @@ svga_screen_cache_add(struct svga_screen *svgascreen, */ void svga_screen_cache_flush(struct svga_screen *svgascreen, + struct svga_context *svga, struct pipe_fence_handle *fence) { struct svga_host_surface_cache *cache = &svgascreen->cache; @@ -318,21 +320,21 @@ svga_screen_cache_flush(struct svga_screen *svgascreen, struct list_head *curr, *next; unsigned bucket; - pipe_mutex_lock(cache->mutex); + mtx_lock(&cache->mutex); - /* Loop over entries in the validated list */ - curr = cache->validated.next; + /* Loop over entries in the invalidated list */ + curr = cache->invalidated.next; next = curr->next; - while (curr != &cache->validated) { + while (curr != &cache->invalidated) { entry = LIST_ENTRY(struct svga_host_surface_cache_entry, curr, head); assert(entry->handle); if (sws->surface_is_flushed(sws, entry->handle)) { - /* remove entry from LRU list */ + /* remove entry from the invalidated list */ LIST_DEL(&entry->head); - svgascreen->sws->fence_reference(svgascreen->sws, &entry->fence, fence); + sws->fence_reference(sws, &entry->fence, fence); /* Add entry to the unused list */ LIST_ADD(&entry->head, &cache->unused); @@ -346,7 +348,31 @@ svga_screen_cache_flush(struct svga_screen *svgascreen, next = curr->next; } - pipe_mutex_unlock(cache->mutex); + curr = cache->validated.next; + next = curr->next; + while (curr != &cache->validated) { + entry = LIST_ENTRY(struct svga_host_surface_cache_entry, curr, head); + + assert(entry->handle); + + if (sws->surface_is_flushed(sws, entry->handle)) { + /* remove entry from the validated list */ + LIST_DEL(&entry->head); + + /* 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); + + /* add the entry to the invalidated list */ + LIST_ADD(&entry->head, &cache->invalidated); + } + + curr = next; + next = curr->next; + } + + mtx_unlock(&cache->mutex); } @@ -371,11 +397,10 @@ svga_screen_cache_cleanup(struct svga_screen *svgascreen) } if (cache->entries[i].fence) - svgascreen->sws->fence_reference(svgascreen->sws, - &cache->entries[i].fence, NULL); + sws->fence_reference(sws, &cache->entries[i].fence, NULL); } - pipe_mutex_destroy(cache->mutex); + mtx_destroy(&cache->mutex); } @@ -387,7 +412,7 @@ svga_screen_cache_init(struct svga_screen *svgascreen) assert(cache->total_size == 0); - pipe_mutex_init(cache->mutex); + (void) mtx_init(&cache->mutex, mtx_plain); for (i = 0; i < SVGA_HOST_SURFACE_CACHE_BUCKETS; ++i) LIST_INITHEAD(&cache->bucket[i]); @@ -396,6 +421,8 @@ svga_screen_cache_init(struct svga_screen *svgascreen) LIST_INITHEAD(&cache->validated); + LIST_INITHEAD(&cache->invalidated); + LIST_INITHEAD(&cache->empty); for (i = 0; i < SVGA_HOST_SURFACE_CACHE_SIZE; ++i) LIST_ADDTAIL(&cache->entries[i].head, &cache->empty); @@ -410,10 +437,12 @@ svga_screen_cache_init(struct svga_screen *svgascreen) * allocate a new surface. * \param bind_flags bitmask of PIPE_BIND_x flags * \param usage one of PIPE_USAGE_x values + * \param validated return True if the surface is a reused surface */ struct svga_winsys_surface * svga_screen_surface_create(struct svga_screen *svgascreen, unsigned bind_flags, enum pipe_resource_usage usage, + boolean *validated, struct svga_host_surface_cache_key *key) { struct svga_winsys_screen *sws = svgascreen->sws; @@ -487,6 +516,7 @@ svga_screen_surface_create(struct svga_screen *svgascreen, key->numMipLevels, key->numFaces, key->arraySize); + *validated = TRUE; } } @@ -513,6 +543,8 @@ svga_screen_surface_create(struct svga_screen *svgascreen, key->size.width, key->size.height, key->size.depth); + + *validated = FALSE; } return handle;