Lines Matching full:cache
51 radv_pipeline_cache_init(struct radv_pipeline_cache *cache, in radv_pipeline_cache_init() argument
54 cache->device = device; in radv_pipeline_cache_init()
55 pthread_mutex_init(&cache->mutex, NULL); in radv_pipeline_cache_init()
57 cache->modified = false; in radv_pipeline_cache_init()
58 cache->kernel_count = 0; in radv_pipeline_cache_init()
59 cache->total_size = 0; in radv_pipeline_cache_init()
60 cache->table_size = 1024; in radv_pipeline_cache_init()
61 const size_t byte_size = cache->table_size * sizeof(cache->hash_table[0]); in radv_pipeline_cache_init()
62 cache->hash_table = malloc(byte_size); in radv_pipeline_cache_init()
65 * cache. Disable caching when we want to keep shader debug info, since in radv_pipeline_cache_init()
67 if (cache->hash_table == NULL || in radv_pipeline_cache_init()
70 cache->table_size = 0; in radv_pipeline_cache_init()
72 memset(cache->hash_table, 0, byte_size); in radv_pipeline_cache_init()
76 radv_pipeline_cache_finish(struct radv_pipeline_cache *cache) in radv_pipeline_cache_finish() argument
78 for (unsigned i = 0; i < cache->table_size; ++i) in radv_pipeline_cache_finish()
79 if (cache->hash_table[i]) { in radv_pipeline_cache_finish()
81 if (cache->hash_table[i]->variants[j]) in radv_pipeline_cache_finish()
82 radv_shader_variant_destroy(cache->device, in radv_pipeline_cache_finish()
83 cache->hash_table[i]->variants[j]); in radv_pipeline_cache_finish()
85 vk_free(&cache->alloc, cache->hash_table[i]); in radv_pipeline_cache_finish()
87 pthread_mutex_destroy(&cache->mutex); in radv_pipeline_cache_finish()
88 free(cache->hash_table); in radv_pipeline_cache_finish()
136 radv_pipeline_cache_search_unlocked(struct radv_pipeline_cache *cache, in radv_pipeline_cache_search_unlocked() argument
139 const uint32_t mask = cache->table_size - 1; in radv_pipeline_cache_search_unlocked()
142 if (cache->table_size == 0) in radv_pipeline_cache_search_unlocked()
145 for (uint32_t i = 0; i < cache->table_size; i++) { in radv_pipeline_cache_search_unlocked()
147 struct cache_entry *entry = cache->hash_table[index]; in radv_pipeline_cache_search_unlocked()
161 radv_pipeline_cache_search(struct radv_pipeline_cache *cache, in radv_pipeline_cache_search() argument
166 pthread_mutex_lock(&cache->mutex); in radv_pipeline_cache_search()
168 entry = radv_pipeline_cache_search_unlocked(cache, sha1); in radv_pipeline_cache_search()
170 pthread_mutex_unlock(&cache->mutex); in radv_pipeline_cache_search()
176 radv_pipeline_cache_set_entry(struct radv_pipeline_cache *cache, in radv_pipeline_cache_set_entry() argument
179 const uint32_t mask = cache->table_size - 1; in radv_pipeline_cache_set_entry()
183 assert(cache->kernel_count < cache->table_size / 2); in radv_pipeline_cache_set_entry()
185 for (uint32_t i = 0; i < cache->table_size; i++) { in radv_pipeline_cache_set_entry()
187 if (!cache->hash_table[index]) { in radv_pipeline_cache_set_entry()
188 cache->hash_table[index] = entry; in radv_pipeline_cache_set_entry()
193 cache->total_size += entry_size(entry); in radv_pipeline_cache_set_entry()
194 cache->kernel_count++; in radv_pipeline_cache_set_entry()
199 radv_pipeline_cache_grow(struct radv_pipeline_cache *cache) in radv_pipeline_cache_grow() argument
201 const uint32_t table_size = cache->table_size * 2; in radv_pipeline_cache_grow()
202 const uint32_t old_table_size = cache->table_size; in radv_pipeline_cache_grow()
203 const size_t byte_size = table_size * sizeof(cache->hash_table[0]); in radv_pipeline_cache_grow()
205 struct cache_entry **old_table = cache->hash_table; in radv_pipeline_cache_grow()
211 cache->hash_table = table; in radv_pipeline_cache_grow()
212 cache->table_size = table_size; in radv_pipeline_cache_grow()
213 cache->kernel_count = 0; in radv_pipeline_cache_grow()
214 cache->total_size = 0; in radv_pipeline_cache_grow()
216 memset(cache->hash_table, 0, byte_size); in radv_pipeline_cache_grow()
222 radv_pipeline_cache_set_entry(cache, entry); in radv_pipeline_cache_grow()
231 radv_pipeline_cache_add_entry(struct radv_pipeline_cache *cache, in radv_pipeline_cache_add_entry() argument
234 if (cache->kernel_count == cache->table_size / 2) in radv_pipeline_cache_add_entry()
235 radv_pipeline_cache_grow(cache); in radv_pipeline_cache_add_entry()
240 if (cache->kernel_count < cache->table_size / 2) in radv_pipeline_cache_add_entry()
241 radv_pipeline_cache_set_entry(cache, entry); in radv_pipeline_cache_add_entry()
246 struct radv_pipeline_cache *cache, in radv_create_shader_variants_from_pipeline_cache() argument
252 if (!cache) in radv_create_shader_variants_from_pipeline_cache()
253 cache = device->mem_cache; in radv_create_shader_variants_from_pipeline_cache()
255 pthread_mutex_lock(&cache->mutex); in radv_create_shader_variants_from_pipeline_cache()
257 entry = radv_pipeline_cache_search_unlocked(cache, sha1); in radv_create_shader_variants_from_pipeline_cache()
260 /* Again, don't cache when we want debug info, since this isn't in radv_create_shader_variants_from_pipeline_cache()
261 * present in the cache. */ in radv_create_shader_variants_from_pipeline_cache()
265 pthread_mutex_unlock(&cache->mutex); in radv_create_shader_variants_from_pipeline_cache()
276 pthread_mutex_unlock(&cache->mutex); in radv_create_shader_variants_from_pipeline_cache()
280 struct cache_entry *new_entry = vk_alloc(&cache->alloc, size, 8, in radv_create_shader_variants_from_pipeline_cache()
284 pthread_mutex_unlock(&cache->mutex); in radv_create_shader_variants_from_pipeline_cache()
292 radv_pipeline_cache_add_entry(cache, new_entry); in radv_create_shader_variants_from_pipeline_cache()
304 pthread_mutex_unlock(&cache->mutex); in radv_create_shader_variants_from_pipeline_cache()
334 pthread_mutex_unlock(&cache->mutex); in radv_create_shader_variants_from_pipeline_cache()
340 struct radv_pipeline_cache *cache, in radv_pipeline_cache_insert_shaders() argument
346 if (!cache) in radv_pipeline_cache_insert_shaders()
347 cache = device->mem_cache; in radv_pipeline_cache_insert_shaders()
349 pthread_mutex_lock(&cache->mutex); in radv_pipeline_cache_insert_shaders()
350 struct cache_entry *entry = radv_pipeline_cache_search_unlocked(cache, sha1); in radv_pipeline_cache_insert_shaders()
354 radv_shader_variant_destroy(cache->device, variants[i]); in radv_pipeline_cache_insert_shaders()
362 pthread_mutex_unlock(&cache->mutex); in radv_pipeline_cache_insert_shaders()
371 entry = vk_alloc(&cache->alloc, size, 8, in radv_pipeline_cache_insert_shaders()
374 pthread_mutex_unlock(&cache->mutex); in radv_pipeline_cache_insert_shaders()
402 /* Always add cache items to disk. This will allow collection of in radv_pipeline_cache_insert_shaders()
404 * implements its own pipeline cache. in radv_pipeline_cache_insert_shaders()
414 /* We delay setting the variant so we have reproducible disk cache in radv_pipeline_cache_insert_shaders()
425 radv_pipeline_cache_add_entry(cache, entry); in radv_pipeline_cache_insert_shaders()
427 cache->modified = true; in radv_pipeline_cache_insert_shaders()
428 pthread_mutex_unlock(&cache->mutex); in radv_pipeline_cache_insert_shaders()
441 radv_pipeline_cache_load(struct radv_pipeline_cache *cache, in radv_pipeline_cache_load() argument
444 struct radv_device *device = cache->device; in radv_pipeline_cache_load()
471 dest_entry = vk_alloc(&cache->alloc, size, in radv_pipeline_cache_load()
477 radv_pipeline_cache_add_entry(cache, dest_entry); in radv_pipeline_cache_load()
490 struct radv_pipeline_cache *cache; in radv_CreatePipelineCache() local
495 cache = vk_alloc2(&device->alloc, pAllocator, in radv_CreatePipelineCache()
496 sizeof(*cache), 8, in radv_CreatePipelineCache()
498 if (cache == NULL) in radv_CreatePipelineCache()
502 cache->alloc = *pAllocator; in radv_CreatePipelineCache()
504 cache->alloc = device->alloc; in radv_CreatePipelineCache()
506 radv_pipeline_cache_init(cache, device); in radv_CreatePipelineCache()
509 radv_pipeline_cache_load(cache, in radv_CreatePipelineCache()
514 *pPipelineCache = radv_pipeline_cache_to_handle(cache); in radv_CreatePipelineCache()
525 RADV_FROM_HANDLE(radv_pipeline_cache, cache, _cache); in radv_DestroyPipelineCache()
527 if (!cache) in radv_DestroyPipelineCache()
529 radv_pipeline_cache_finish(cache); in radv_DestroyPipelineCache()
531 vk_free2(&device->alloc, pAllocator, cache); in radv_DestroyPipelineCache()
541 RADV_FROM_HANDLE(radv_pipeline_cache, cache, _cache); in radv_GetPipelineCacheData()
545 pthread_mutex_lock(&cache->mutex); in radv_GetPipelineCacheData()
547 const size_t size = sizeof(*header) + cache->total_size; in radv_GetPipelineCacheData()
549 pthread_mutex_unlock(&cache->mutex); in radv_GetPipelineCacheData()
554 pthread_mutex_unlock(&cache->mutex); in radv_GetPipelineCacheData()
568 for (uint32_t i = 0; i < cache->table_size; i++) { in radv_GetPipelineCacheData()
569 if (!cache->hash_table[i]) in radv_GetPipelineCacheData()
571 entry = cache->hash_table[i]; in radv_GetPipelineCacheData()
585 pthread_mutex_unlock(&cache->mutex); in radv_GetPipelineCacheData()