diff options
Diffstat (limited to 'lib/mesa/src/freedreno/vulkan/tu_pipeline_cache.c')
-rw-r--r-- | lib/mesa/src/freedreno/vulkan/tu_pipeline_cache.c | 83 |
1 files changed, 63 insertions, 20 deletions
diff --git a/lib/mesa/src/freedreno/vulkan/tu_pipeline_cache.c b/lib/mesa/src/freedreno/vulkan/tu_pipeline_cache.c index 5cfc79fbf..b8b2ceda2 100644 --- a/lib/mesa/src/freedreno/vulkan/tu_pipeline_cache.c +++ b/lib/mesa/src/freedreno/vulkan/tu_pipeline_cache.c @@ -27,7 +27,6 @@ #include "util/disk_cache.h" #include "util/mesa-sha1.h" #include "util/u_atomic.h" -#include "vulkan/util/vk_util.h" struct cache_entry_variant_info { @@ -44,7 +43,7 @@ struct cache_entry char code[0]; }; -static void +void tu_pipeline_cache_init(struct tu_pipeline_cache *cache, struct tu_device *device) { @@ -67,7 +66,7 @@ tu_pipeline_cache_init(struct tu_pipeline_cache *cache, memset(cache->hash_table, 0, byte_size); } -static void +void tu_pipeline_cache_finish(struct tu_pipeline_cache *cache) { for (unsigned i = 0; i < cache->table_size; ++i) @@ -89,6 +88,41 @@ entry_size(struct cache_entry *entry) return ret; } +void +tu_hash_shaders(unsigned char *hash, + const VkPipelineShaderStageCreateInfo **stages, + const struct tu_pipeline_layout *layout, + const struct tu_pipeline_key *key, + uint32_t flags) +{ + struct mesa_sha1 ctx; + + _mesa_sha1_init(&ctx); + if (key) + _mesa_sha1_update(&ctx, key, sizeof(*key)); + if (layout) + _mesa_sha1_update(&ctx, layout->sha1, sizeof(layout->sha1)); + + for (int i = 0; i < MESA_SHADER_STAGES; ++i) { + if (stages[i]) { + TU_FROM_HANDLE(tu_shader_module, module, stages[i]->module); + const VkSpecializationInfo *spec_info = + stages[i]->pSpecializationInfo; + + _mesa_sha1_update(&ctx, module->sha1, sizeof(module->sha1)); + _mesa_sha1_update(&ctx, stages[i]->pName, strlen(stages[i]->pName)); + if (spec_info) { + _mesa_sha1_update( + &ctx, spec_info->pMapEntries, + spec_info->mapEntryCount * sizeof spec_info->pMapEntries[0]); + _mesa_sha1_update(&ctx, spec_info->pData, spec_info->dataSize); + } + } + } + _mesa_sha1_update(&ctx, &flags, 4); + _mesa_sha1_final(&ctx, hash); +} + static struct cache_entry * tu_pipeline_cache_search_unlocked(struct tu_pipeline_cache *cache, const unsigned char *sha1) @@ -162,7 +196,7 @@ tu_pipeline_cache_grow(struct tu_pipeline_cache *cache) table = malloc(byte_size); if (table == NULL) - return vk_error(cache, VK_ERROR_OUT_OF_HOST_MEMORY); + return vk_error(cache->device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); cache->hash_table = table; cache->table_size = table_size; @@ -197,13 +231,22 @@ tu_pipeline_cache_add_entry(struct tu_pipeline_cache *cache, tu_pipeline_cache_set_entry(cache, entry); } -static void +struct cache_header +{ + uint32_t header_size; + uint32_t header_version; + uint32_t vendor_id; + uint32_t device_id; + uint8_t uuid[VK_UUID_SIZE]; +}; + +void tu_pipeline_cache_load(struct tu_pipeline_cache *cache, const void *data, size_t size) { struct tu_device *device = cache->device; - struct vk_pipeline_cache_header header; + struct cache_header header; if (size < sizeof(header)) return; @@ -212,9 +255,9 @@ tu_pipeline_cache_load(struct tu_pipeline_cache *cache, return; if (header.header_version != VK_PIPELINE_CACHE_HEADER_VERSION_ONE) return; - if (header.vendor_id != 0x5143) + if (header.vendor_id != 0 /* TODO */) return; - if (header.device_id != device->physical_device->dev_id.chip_id) + if (header.device_id != 0 /* TODO */) return; if (memcmp(header.uuid, device->physical_device->cache_uuid, VK_UUID_SIZE) != 0) @@ -242,7 +285,7 @@ tu_pipeline_cache_load(struct tu_pipeline_cache *cache, } } -VKAPI_ATTR VkResult VKAPI_CALL +VkResult tu_CreatePipelineCache(VkDevice _device, const VkPipelineCacheCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, @@ -254,15 +297,15 @@ tu_CreatePipelineCache(VkDevice _device, assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO); assert(pCreateInfo->flags == 0); - cache = vk_object_alloc(&device->vk, pAllocator, sizeof(*cache), - VK_OBJECT_TYPE_PIPELINE_CACHE); + cache = vk_alloc2(&device->alloc, pAllocator, sizeof(*cache), 8, + VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (cache == NULL) - return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); + return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); if (pAllocator) cache->alloc = *pAllocator; else - cache->alloc = device->vk.alloc; + cache->alloc = device->alloc; tu_pipeline_cache_init(cache, device); @@ -276,7 +319,7 @@ tu_CreatePipelineCache(VkDevice _device, return VK_SUCCESS; } -VKAPI_ATTR void VKAPI_CALL +void tu_DestroyPipelineCache(VkDevice _device, VkPipelineCache _cache, const VkAllocationCallbacks *pAllocator) @@ -288,10 +331,10 @@ tu_DestroyPipelineCache(VkDevice _device, return; tu_pipeline_cache_finish(cache); - vk_object_free(&device->vk, pAllocator, cache); + vk_free2(&device->alloc, pAllocator, cache); } -VKAPI_ATTR VkResult VKAPI_CALL +VkResult tu_GetPipelineCacheData(VkDevice _device, VkPipelineCache _cache, size_t *pDataSize, @@ -299,7 +342,7 @@ tu_GetPipelineCacheData(VkDevice _device, { TU_FROM_HANDLE(tu_device, device, _device); TU_FROM_HANDLE(tu_pipeline_cache, cache, _cache); - struct vk_pipeline_cache_header *header; + struct cache_header *header; VkResult result = VK_SUCCESS; pthread_mutex_lock(&cache->mutex); @@ -319,8 +362,8 @@ tu_GetPipelineCacheData(VkDevice _device, header = p; header->header_size = sizeof(*header); header->header_version = VK_PIPELINE_CACHE_HEADER_VERSION_ONE; - header->vendor_id = 0x5143; - header->device_id = device->physical_device->dev_id.chip_id; + header->vendor_id = 0 /* TODO */; + header->device_id = 0 /* TODO */; memcpy(header->uuid, device->physical_device->cache_uuid, VK_UUID_SIZE); p += header->header_size; @@ -361,7 +404,7 @@ tu_pipeline_cache_merge(struct tu_pipeline_cache *dst, } } -VKAPI_ATTR VkResult VKAPI_CALL +VkResult tu_MergePipelineCaches(VkDevice _device, VkPipelineCache destCache, uint32_t srcCacheCount, |