Module: Mesa
Branch: main
Commit: 66d4dbd960e695d4b7db11a9fd57d3225079605f
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=66d4dbd960e695d4b7db11a9fd57d3225079605f

Author: Rob Clark <[email protected]>
Date:   Sat Apr  1 07:38:40 2023 -0700

util/disk_cache: Move blob_put_cb to the async queue

Move deflate and put to the queue for the blob cache case.  This moves
the overhead out of the app thread when storing new shaders.

Signed-off-by: Rob Clark <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22248>

---

 src/util/disk_cache.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index cd338f8b353..c4872e59ee2 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -426,6 +426,10 @@ destroy_put_job_nocopy(void *job, void *gdata, int 
thread_index)
    destroy_put_job(job, gdata, thread_index);
 }
 
+static void
+blob_put_compressed(struct disk_cache *cache, const cache_key key,
+         const void *data, size_t size);
+
 static void
 cache_put(void *job, void *gdata, int thread_index)
 {
@@ -435,7 +439,9 @@ cache_put(void *job, void *gdata, int thread_index)
    char *filename = NULL;
    struct disk_cache_put_job *dc_job = (struct disk_cache_put_job *) job;
 
-   if (dc_job->cache->type == DISK_CACHE_SINGLE_FILE) {
+   if (dc_job->cache->blob_put_cb) {
+      blob_put_compressed(dc_job->cache, dc_job->key, dc_job->data, 
dc_job->size);
+   } else if (dc_job->cache->type == DISK_CACHE_SINGLE_FILE) {
       disk_cache_write_item_to_disk_foz(dc_job);
    } else if (dc_job->cache->type == DISK_CACHE_DATABASE) {
       disk_cache_db_write_item_to_disk(dc_job);
@@ -546,11 +552,6 @@ disk_cache_put(struct disk_cache *cache, const cache_key 
key,
                const void *data, size_t size,
                struct cache_item_metadata *cache_item_metadata)
 {
-   if (cache->blob_put_cb) {
-      blob_put_compressed(cache, key, data, size);
-      return;
-   }
-
    if (!util_queue_is_initialized(&cache->cache_queue))
       return;
 
@@ -569,12 +570,6 @@ disk_cache_put_nocopy(struct disk_cache *cache, const 
cache_key key,
                       void *data, size_t size,
                       struct cache_item_metadata *cache_item_metadata)
 {
-   if (cache->blob_put_cb) {
-      blob_put_compressed(cache, key, data, size);
-      free(data);
-      return;
-   }
-
    if (!util_queue_is_initialized(&cache->cache_queue)) {
       free(data);
       return;
@@ -691,6 +686,7 @@ disk_cache_set_callbacks(struct disk_cache *cache, 
disk_cache_put_cb put,
 {
    cache->blob_put_cb = put;
    cache->blob_get_cb = get;
+   disk_cache_init_queue(cache);
 }
 
 #endif /* ENABLE_SHADER_CACHE */

Reply via email to