From 142162529233680631a246c8920e66d02ee4e94b Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Wed, 11 Oct 2017 12:00:27 +1100 Subject: [PATCH] radv: create on-disk shader cache This is the drivers on-disk cache intended to be used as a fallback as opposed to the pipeline cache provided by apps. Reviewed-by: Bas Nieuwenhuizen --- src/amd/vulkan/radv_device.c | 13 +++++++++++++ src/amd/vulkan/radv_private.h | 6 ++++++ src/util/disk_cache.h | 15 +++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index d414d8ca85b..23f5e70321d 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -352,6 +352,18 @@ radv_physical_device_init(struct radv_physical_device *device, goto fail; } + /* These flags affect shader compilation. */ + uint64_t shader_env_flags = + (device->instance->perftest_flags & RADV_PERFTEST_SISCHED ? 0x1 : 0) | + (device->instance->debug_flags & RADV_DEBUG_UNSAFE_MATH ? 0x2 : 0); + + /* The gpu id is already embeded in the uuid so we just pass "radv" + * when creating the cache. + */ + char buf[VK_UUID_SIZE + 1]; + disk_cache_format_hex_id(buf, device->cache_uuid, VK_UUID_SIZE); + device->disk_cache = disk_cache_create("radv", buf, shader_env_flags); + result = radv_extensions_register(instance, &device->extensions, common_device_extensions, @@ -402,6 +414,7 @@ radv_physical_device_finish(struct radv_physical_device *device) radv_extensions_finish(device->instance, &device->extensions); radv_finish_wsi(device); device->ws->destroy(device->ws); + disk_cache_destroy(device->disk_cache); close(device->local_fd); } diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index 548952faa97..e673527811f 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -277,6 +277,12 @@ struct radv_physical_device { bool has_rbplus; /* if RB+ register exist */ bool rbplus_allowed; /* if RB+ is allowed */ + + + /* This is the drivers on-disk cache used as a fallback as opposed to + * the pipeline cache defined by apps. + */ + struct disk_cache * disk_cache; }; struct radv_instance { diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h index d2e4d9a69c7..488b297ead2 100644 --- a/src/util/disk_cache.h +++ b/src/util/disk_cache.h @@ -65,6 +65,21 @@ struct cache_item_metadata { struct disk_cache; +static inline char * +disk_cache_format_hex_id(char *buf, const uint8_t *hex_id, unsigned size) +{ + static const char hex_digits[] = "0123456789abcdef"; + unsigned i; + + for (i = 0; i < size; i += 2) { + buf[i] = hex_digits[hex_id[i >> 1] >> 4]; + buf[i + 1] = hex_digits[hex_id[i >> 1] & 0x0f]; + } + buf[i] = '\0'; + + return buf; +} + static inline bool disk_cache_get_function_timestamp(void *ptr, uint32_t* timestamp) { -- 2.30.2