[Mesa-dev] [PATCH] anv: Rework the pipeline cache UUID

Jason Ekstrand jason at jlekstrand.net
Tue Feb 14 23:52:40 UTC 2017


The new version does a SHA1 sum of the timestamp together with the
device PCI ID.  This fixes a theoretical bug where, if you moved a drive
between machines, you could end up trying to use a pipeline cache from
one platform with a different platform.  Now we'll reject any cache that
is targeted at different hardware.

Cc: "13.0 17.0" <mesa-stable at lists.freedesktop.org>
---
 src/intel/vulkan/anv_device.c | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 82c2d6f..4e06670 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -31,6 +31,7 @@
 #include <fcntl.h>
 
 #include "anv_private.h"
+#include "util/mesa-sha1.h"
 #include "util/strtod.h"
 #include "util/debug.h"
 
@@ -69,17 +70,30 @@ anv_get_function_timestamp(void *ptr, uint32_t* timestamp)
    return true;
 }
 
-static bool
-anv_device_get_cache_uuid(void *uuid)
+static VkResult
+anv_physical_device_init_uuid(struct anv_physical_device *device)
 {
    uint32_t timestamp;
+   if (!anv_get_function_timestamp(anv_physical_device_init_uuid, &timestamp)) {
+      return vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
+                        "cannot generate UUID");
+   }
 
-   memset(uuid, 0, VK_UUID_SIZE);
-   if (!anv_get_function_timestamp(anv_device_get_cache_uuid, &timestamp))
-      return false;
+   unsigned char sha1[20];
+   struct mesa_sha1 *sha1_ctx = _mesa_sha1_init();
+   if (sha1_ctx == NULL) {
+      return vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
+                       "cannot generate UUID");
+   }
 
-   snprintf(uuid, VK_UUID_SIZE, "anv-%d", timestamp);
-   return true;
+   _mesa_sha1_update(sha1_ctx, &timestamp, sizeof(timestamp));
+   _mesa_sha1_update(sha1_ctx, &device->chipset_id, sizeof(device->chipset_id));
+
+   _mesa_sha1_final(sha1_ctx, sha1);
+
+   memcpy(device->uuid, sha1, VK_UUID_SIZE);
+
+   return VK_SUCCESS;
 }
 
 static VkResult
@@ -163,11 +177,11 @@ anv_physical_device_init(struct anv_physical_device *device,
       goto fail;
    }
 
-   if (!anv_device_get_cache_uuid(device->uuid)) {
-      result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
-                         "cannot generate UUID");
+   /* Initialize the physical device UUID */
+   result = anv_physical_device_init_uuid(device);
+   if (result != VK_SUCCESS)
       goto fail;
-   }
+
    bool swizzled = anv_gem_get_bit6_swizzle(fd, I915_TILING_X);
 
    /* GENs prior to 8 do not support EU/Subslice info */
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list