Lines Matching full:cache
47 radv_pipeline_cache_lock(struct radv_pipeline_cache *cache) in radv_pipeline_cache_lock() argument
49 if (cache->flags & VK_PIPELINE_CACHE_CREATE_EXTERNALLY_SYNCHRONIZED_BIT_EXT) in radv_pipeline_cache_lock()
52 pthread_mutex_lock(&cache->mutex); in radv_pipeline_cache_lock()
56 radv_pipeline_cache_unlock(struct radv_pipeline_cache *cache) in radv_pipeline_cache_unlock() argument
58 if (cache->flags & VK_PIPELINE_CACHE_CREATE_EXTERNALLY_SYNCHRONIZED_BIT_EXT) in radv_pipeline_cache_unlock()
61 pthread_mutex_unlock(&cache->mutex); in radv_pipeline_cache_unlock()
65 radv_pipeline_cache_init(struct radv_pipeline_cache *cache, in radv_pipeline_cache_init() argument
68 cache->device = device; in radv_pipeline_cache_init()
69 pthread_mutex_init(&cache->mutex, NULL); in radv_pipeline_cache_init()
70 cache->flags = 0; in radv_pipeline_cache_init()
72 cache->modified = false; in radv_pipeline_cache_init()
73 cache->kernel_count = 0; in radv_pipeline_cache_init()
74 cache->total_size = 0; in radv_pipeline_cache_init()
75 cache->table_size = 1024; in radv_pipeline_cache_init()
76 const size_t byte_size = cache->table_size * sizeof(cache->hash_table[0]); in radv_pipeline_cache_init()
77 cache->hash_table = malloc(byte_size); in radv_pipeline_cache_init()
80 * cache. Disable caching when we want to keep shader debug info, since in radv_pipeline_cache_init()
82 if (cache->hash_table == NULL || in radv_pipeline_cache_init()
84 cache->table_size = 0; in radv_pipeline_cache_init()
86 memset(cache->hash_table, 0, byte_size); in radv_pipeline_cache_init()
90 radv_pipeline_cache_finish(struct radv_pipeline_cache *cache) in radv_pipeline_cache_finish() argument
92 for (unsigned i = 0; i < cache->table_size; ++i) in radv_pipeline_cache_finish()
93 if (cache->hash_table[i]) { in radv_pipeline_cache_finish()
95 if (cache->hash_table[i]->variants[j]) in radv_pipeline_cache_finish()
96 radv_shader_variant_destroy(cache->device, in radv_pipeline_cache_finish()
97 cache->hash_table[i]->variants[j]); in radv_pipeline_cache_finish()
99 vk_free(&cache->alloc, cache->hash_table[i]); in radv_pipeline_cache_finish()
101 pthread_mutex_destroy(&cache->mutex); in radv_pipeline_cache_finish()
102 free(cache->hash_table); in radv_pipeline_cache_finish()
151 radv_pipeline_cache_search_unlocked(struct radv_pipeline_cache *cache, in radv_pipeline_cache_search_unlocked() argument
154 const uint32_t mask = cache->table_size - 1; in radv_pipeline_cache_search_unlocked()
157 if (cache->table_size == 0) in radv_pipeline_cache_search_unlocked()
160 for (uint32_t i = 0; i < cache->table_size; i++) { in radv_pipeline_cache_search_unlocked()
162 struct cache_entry *entry = cache->hash_table[index]; in radv_pipeline_cache_search_unlocked()
176 radv_pipeline_cache_search(struct radv_pipeline_cache *cache, in radv_pipeline_cache_search() argument
181 radv_pipeline_cache_lock(cache); in radv_pipeline_cache_search()
183 entry = radv_pipeline_cache_search_unlocked(cache, sha1); in radv_pipeline_cache_search()
185 radv_pipeline_cache_unlock(cache); in radv_pipeline_cache_search()
191 radv_pipeline_cache_set_entry(struct radv_pipeline_cache *cache, in radv_pipeline_cache_set_entry() argument
194 const uint32_t mask = cache->table_size - 1; in radv_pipeline_cache_set_entry()
198 assert(cache->kernel_count < cache->table_size / 2); in radv_pipeline_cache_set_entry()
200 for (uint32_t i = 0; i < cache->table_size; i++) { in radv_pipeline_cache_set_entry()
202 if (!cache->hash_table[index]) { in radv_pipeline_cache_set_entry()
203 cache->hash_table[index] = entry; in radv_pipeline_cache_set_entry()
208 cache->total_size += entry_size(entry); in radv_pipeline_cache_set_entry()
209 cache->kernel_count++; in radv_pipeline_cache_set_entry()
214 radv_pipeline_cache_grow(struct radv_pipeline_cache *cache) in radv_pipeline_cache_grow() argument
216 const uint32_t table_size = cache->table_size * 2; in radv_pipeline_cache_grow()
217 const uint32_t old_table_size = cache->table_size; in radv_pipeline_cache_grow()
218 const size_t byte_size = table_size * sizeof(cache->hash_table[0]); in radv_pipeline_cache_grow()
220 struct cache_entry **old_table = cache->hash_table; in radv_pipeline_cache_grow()
224 return vk_error(cache->device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); in radv_pipeline_cache_grow()
226 cache->hash_table = table; in radv_pipeline_cache_grow()
227 cache->table_size = table_size; in radv_pipeline_cache_grow()
228 cache->kernel_count = 0; in radv_pipeline_cache_grow()
229 cache->total_size = 0; in radv_pipeline_cache_grow()
231 memset(cache->hash_table, 0, byte_size); in radv_pipeline_cache_grow()
237 radv_pipeline_cache_set_entry(cache, entry); in radv_pipeline_cache_grow()
246 radv_pipeline_cache_add_entry(struct radv_pipeline_cache *cache, in radv_pipeline_cache_add_entry() argument
249 if (cache->kernel_count == cache->table_size / 2) in radv_pipeline_cache_add_entry()
250 radv_pipeline_cache_grow(cache); in radv_pipeline_cache_add_entry()
255 if (cache->kernel_count < cache->table_size / 2) in radv_pipeline_cache_add_entry()
256 radv_pipeline_cache_set_entry(cache, entry); in radv_pipeline_cache_add_entry()
270 struct radv_pipeline_cache *cache, in radv_create_shader_variants_from_pipeline_cache() argument
277 if (!cache) { in radv_create_shader_variants_from_pipeline_cache()
278 cache = device->mem_cache; in radv_create_shader_variants_from_pipeline_cache()
282 radv_pipeline_cache_lock(cache); in radv_create_shader_variants_from_pipeline_cache()
284 entry = radv_pipeline_cache_search_unlocked(cache, sha1); in radv_create_shader_variants_from_pipeline_cache()
289 /* Don't cache when we want debug info, since this isn't in radv_create_shader_variants_from_pipeline_cache()
290 * present in the cache. in radv_create_shader_variants_from_pipeline_cache()
293 radv_pipeline_cache_unlock(cache); in radv_create_shader_variants_from_pipeline_cache()
305 radv_pipeline_cache_unlock(cache); in radv_create_shader_variants_from_pipeline_cache()
309 struct cache_entry *new_entry = vk_alloc(&cache->alloc, size, 8, in radv_create_shader_variants_from_pipeline_cache()
313 radv_pipeline_cache_unlock(cache); in radv_create_shader_variants_from_pipeline_cache()
322 cache != device->mem_cache) in radv_create_shader_variants_from_pipeline_cache()
323 radv_pipeline_cache_add_entry(cache, new_entry); in radv_create_shader_variants_from_pipeline_cache()
345 cache == device->mem_cache) in radv_create_shader_variants_from_pipeline_cache()
346 vk_free(&cache->alloc, entry); in radv_create_shader_variants_from_pipeline_cache()
353 radv_pipeline_cache_unlock(cache); in radv_create_shader_variants_from_pipeline_cache()
359 struct radv_pipeline_cache *cache, in radv_pipeline_cache_insert_shaders() argument
364 if (!cache) in radv_pipeline_cache_insert_shaders()
365 cache = device->mem_cache; in radv_pipeline_cache_insert_shaders()
367 radv_pipeline_cache_lock(cache); in radv_pipeline_cache_insert_shaders()
368 struct cache_entry *entry = radv_pipeline_cache_search_unlocked(cache, sha1); in radv_pipeline_cache_insert_shaders()
372 radv_shader_variant_destroy(cache->device, variants[i]); in radv_pipeline_cache_insert_shaders()
380 radv_pipeline_cache_unlock(cache); in radv_pipeline_cache_insert_shaders()
384 /* Don't cache when we want debug info, since this isn't in radv_pipeline_cache_insert_shaders()
385 * present in the cache. in radv_pipeline_cache_insert_shaders()
388 radv_pipeline_cache_unlock(cache); in radv_pipeline_cache_insert_shaders()
399 entry = vk_alloc(&cache->alloc, size, 8, in radv_pipeline_cache_insert_shaders()
402 radv_pipeline_cache_unlock(cache); in radv_pipeline_cache_insert_shaders()
421 /* Always add cache items to disk. This will allow collection of in radv_pipeline_cache_insert_shaders()
423 * implements its own pipeline cache. in radv_pipeline_cache_insert_shaders()
435 cache == device->mem_cache) { in radv_pipeline_cache_insert_shaders()
436 vk_free2(&cache->alloc, NULL, entry); in radv_pipeline_cache_insert_shaders()
437 radv_pipeline_cache_unlock(cache); in radv_pipeline_cache_insert_shaders()
441 /* We delay setting the variant so we have reproducible disk cache in radv_pipeline_cache_insert_shaders()
452 radv_pipeline_cache_add_entry(cache, entry); in radv_pipeline_cache_insert_shaders()
454 cache->modified = true; in radv_pipeline_cache_insert_shaders()
455 radv_pipeline_cache_unlock(cache); in radv_pipeline_cache_insert_shaders()
460 radv_pipeline_cache_load(struct radv_pipeline_cache *cache, in radv_pipeline_cache_load() argument
463 struct radv_device *device = cache->device; in radv_pipeline_cache_load()
490 dest_entry = vk_alloc(&cache->alloc, size, in radv_pipeline_cache_load()
496 radv_pipeline_cache_add_entry(cache, dest_entry); in radv_pipeline_cache_load()
511 struct radv_pipeline_cache *cache; in radv_CreatePipelineCache() local
515 cache = vk_alloc2(&device->vk.alloc, pAllocator, in radv_CreatePipelineCache()
516 sizeof(*cache), 8, in radv_CreatePipelineCache()
518 if (cache == NULL) in radv_CreatePipelineCache()
521 vk_object_base_init(&device->vk, &cache->base, in radv_CreatePipelineCache()
525 cache->alloc = *pAllocator; in radv_CreatePipelineCache()
527 cache->alloc = device->vk.alloc; in radv_CreatePipelineCache()
529 radv_pipeline_cache_init(cache, device); in radv_CreatePipelineCache()
530 cache->flags = pCreateInfo->flags; in radv_CreatePipelineCache()
533 radv_pipeline_cache_load(cache, in radv_CreatePipelineCache()
538 *pPipelineCache = radv_pipeline_cache_to_handle(cache); in radv_CreatePipelineCache()
549 RADV_FROM_HANDLE(radv_pipeline_cache, cache, _cache); in radv_DestroyPipelineCache()
551 if (!cache) in radv_DestroyPipelineCache()
553 radv_pipeline_cache_finish(cache); in radv_DestroyPipelineCache()
555 vk_object_base_finish(&cache->base); in radv_DestroyPipelineCache()
556 vk_free2(&device->vk.alloc, pAllocator, cache); in radv_DestroyPipelineCache()
566 RADV_FROM_HANDLE(radv_pipeline_cache, cache, _cache); in radv_GetPipelineCacheData()
570 radv_pipeline_cache_lock(cache); in radv_GetPipelineCacheData()
572 const size_t size = sizeof(*header) + cache->total_size; in radv_GetPipelineCacheData()
574 radv_pipeline_cache_unlock(cache); in radv_GetPipelineCacheData()
579 radv_pipeline_cache_unlock(cache); in radv_GetPipelineCacheData()
593 for (uint32_t i = 0; i < cache->table_size; i++) { in radv_GetPipelineCacheData()
594 if (!cache->hash_table[i]) in radv_GetPipelineCacheData()
596 entry = cache->hash_table[i]; in radv_GetPipelineCacheData()
610 radv_pipeline_cache_unlock(cache); in radv_GetPipelineCacheData()