Mesa (main): zink: check for error when initializing util_queue

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri May 13 20:03:52 UTC 2022


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

Author: Greg Depoire--Ferrer <greg.depoire at gmail.com>
Date:   Fri Feb 18 01:05:25 2022 +0100

zink: check for error when initializing util_queue

When the call to util_queue_init indicates a failure, handle it by
disabling the associated feature (disk cache and thread dispatch) and
telling the user about it.

Signed-off-by: Greg Depoire--Ferrer <greg.depoire at gmail.com>
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15071>

---

 src/gallium/drivers/zink/zink_screen.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_screen.c b/src/gallium/drivers/zink/zink_screen.c
index 0f381a5ab1c..02505bc86ea 100644
--- a/src/gallium/drivers/zink/zink_screen.c
+++ b/src/gallium/drivers/zink/zink_screen.c
@@ -155,7 +155,7 @@ get_video_mem(struct zink_screen *screen)
    return size;
 }
 
-static void
+static bool
 disk_cache_init(struct zink_screen *screen)
 {
 #ifdef ENABLE_SHADER_CACHE
@@ -163,11 +163,25 @@ disk_cache_init(struct zink_screen *screen)
    snprintf(buf, sizeof(buf), "zink_%x04x", screen->info.props.vendorID);
 
    screen->disk_cache = disk_cache_create(buf, screen->info.props.deviceName, 0);
-   if (screen->disk_cache) {
-      util_queue_init(&screen->cache_put_thread, "zcq", 8, 1, UTIL_QUEUE_INIT_RESIZE_IF_FULL, screen);
-      util_queue_init(&screen->cache_get_thread, "zcfq", 8, 4, UTIL_QUEUE_INIT_RESIZE_IF_FULL, screen);
+   if (!screen->disk_cache)
+      return false;
+
+   if (!util_queue_init(&screen->cache_put_thread, "zcq", 8, 1, UTIL_QUEUE_INIT_RESIZE_IF_FULL, screen) ||
+      !util_queue_init(&screen->cache_get_thread, "zcfq", 8, 4,
+         UTIL_QUEUE_INIT_RESIZE_IF_FULL, screen)) {
+      mesa_loge("zink: Failed to create disk cache queue\n");
+
+      disk_cache_destroy(screen->disk_cache);
+      screen->disk_cache = NULL;
+
+      util_queue_destroy(&screen->cache_put_thread);
+      util_queue_destroy(&screen->cache_get_thread);
+
+      return false;
    }
 #endif
+
+   return true;
 }
 
 
@@ -2107,8 +2121,10 @@ zink_internal_create_screen(const struct pipe_screen_config *config)
       goto fail;
    }
 
-   if (screen->threaded)
-      util_queue_init(&screen->flush_queue, "zfq", 8, 1, UTIL_QUEUE_INIT_RESIZE_IF_FULL, screen);
+   if (screen->threaded && !util_queue_init(&screen->flush_queue, "zfq", 8, 1, UTIL_QUEUE_INIT_RESIZE_IF_FULL, screen)) {
+      mesa_loge("zink: Failed to create flush queue.\n");
+      goto fail;
+   }
 
    zink_internal_setup_moltenvk(screen);
    if (!screen->info.have_KHR_timeline_semaphore) {
@@ -2191,7 +2207,8 @@ zink_internal_create_screen(const struct pipe_screen_config *config)
    zink_screen_fence_init(&screen->base);
 
    zink_screen_init_compiler(screen);
-   disk_cache_init(screen);
+   if (!disk_cache_init(screen))
+      goto fail;
    populate_format_props(screen);
    pre_hash_descriptor_states(screen);
 



More information about the mesa-commit mailing list