Lines Matching full:cache
55 cache_dump_stats(struct v3dv_pipeline_cache *cache) in cache_dump_stats() argument
57 fprintf(stderr, " NIR cache entries: %d\n", cache->nir_stats.count); in cache_dump_stats()
58 fprintf(stderr, " NIR cache miss count: %d\n", cache->nir_stats.miss); in cache_dump_stats()
59 fprintf(stderr, " NIR cache hit count: %d\n", cache->nir_stats.hit); in cache_dump_stats()
61 fprintf(stderr, " cache entries: %d\n", cache->stats.count); in cache_dump_stats()
62 fprintf(stderr, " cache miss count: %d\n", cache->stats.miss); in cache_dump_stats()
63 fprintf(stderr, " cache hit count: %d\n", cache->stats.hit); in cache_dump_stats()
65 fprintf(stderr, " on-disk cache hit count: %d\n", cache->stats.on_disk_hit); in cache_dump_stats()
69 pipeline_cache_lock(struct v3dv_pipeline_cache *cache) in pipeline_cache_lock() argument
71 if (!cache->externally_synchronized) in pipeline_cache_lock()
72 mtx_lock(&cache->mutex); in pipeline_cache_lock()
76 pipeline_cache_unlock(struct v3dv_pipeline_cache *cache) in pipeline_cache_unlock() argument
78 if (!cache->externally_synchronized) in pipeline_cache_unlock()
79 mtx_unlock(&cache->mutex); in pipeline_cache_unlock()
84 struct v3dv_pipeline_cache *cache, in v3dv_pipeline_cache_upload_nir() argument
88 if (!cache || !cache->nir_cache) in v3dv_pipeline_cache_upload_nir()
91 if (cache->nir_stats.count > V3DV_MAX_PIPELINE_CACHE_ENTRIES) in v3dv_pipeline_cache_upload_nir()
94 pipeline_cache_lock(cache); in v3dv_pipeline_cache_upload_nir()
96 _mesa_hash_table_search(cache->nir_cache, sha1_key); in v3dv_pipeline_cache_upload_nir()
97 pipeline_cache_unlock(cache); in v3dv_pipeline_cache_upload_nir()
110 pipeline_cache_lock(cache); in v3dv_pipeline_cache_upload_nir()
115 entry = _mesa_hash_table_search(cache->nir_cache, sha1_key); in v3dv_pipeline_cache_upload_nir()
118 pipeline_cache_unlock(cache); in v3dv_pipeline_cache_upload_nir()
123 ralloc_size(cache->nir_cache, sizeof(*snir) + blob.size); in v3dv_pipeline_cache_upload_nir()
130 cache->nir_stats.count++; in v3dv_pipeline_cache_upload_nir()
134 fprintf(stderr, "pipeline cache %p, new nir entry %s\n", cache, sha1buf); in v3dv_pipeline_cache_upload_nir()
136 cache_dump_stats(cache); in v3dv_pipeline_cache_upload_nir()
139 _mesa_hash_table_insert(cache->nir_cache, snir->sha1_key, snir); in v3dv_pipeline_cache_upload_nir()
141 pipeline_cache_unlock(cache); in v3dv_pipeline_cache_upload_nir()
146 struct v3dv_pipeline_cache *cache, in v3dv_pipeline_cache_search_for_nir() argument
150 if (!cache || !cache->nir_cache) in v3dv_pipeline_cache_search_for_nir()
157 fprintf(stderr, "pipeline cache %p, search for nir %s\n", cache, sha1buf); in v3dv_pipeline_cache_search_for_nir()
162 pipeline_cache_lock(cache); in v3dv_pipeline_cache_search_for_nir()
164 _mesa_hash_table_search(cache->nir_cache, sha1_key); in v3dv_pipeline_cache_search_for_nir()
167 pipeline_cache_unlock(cache); in v3dv_pipeline_cache_search_for_nir()
175 * after cache creation in v3dv_pipeline_cache_search_for_nir()
181 cache->nir_stats.hit++; in v3dv_pipeline_cache_search_for_nir()
183 fprintf(stderr, "[v3dv nir cache] hit: %p\n", nir); in v3dv_pipeline_cache_search_for_nir()
185 cache_dump_stats(cache); in v3dv_pipeline_cache_search_for_nir()
191 cache->nir_stats.miss++; in v3dv_pipeline_cache_search_for_nir()
193 fprintf(stderr, "[v3dv nir cache] miss\n"); in v3dv_pipeline_cache_search_for_nir()
195 cache_dump_stats(cache); in v3dv_pipeline_cache_search_for_nir()
202 v3dv_pipeline_cache_init(struct v3dv_pipeline_cache *cache, in v3dv_pipeline_cache_init() argument
207 cache->device = device; in v3dv_pipeline_cache_init()
208 mtx_init(&cache->mutex, mtx_plain); in v3dv_pipeline_cache_init()
211 cache->nir_cache = _mesa_hash_table_create(NULL, sha1_hash_func, in v3dv_pipeline_cache_init()
213 cache->nir_stats.miss = 0; in v3dv_pipeline_cache_init()
214 cache->nir_stats.hit = 0; in v3dv_pipeline_cache_init()
215 cache->nir_stats.count = 0; in v3dv_pipeline_cache_init()
217 cache->cache = _mesa_hash_table_create(NULL, sha1_hash_func, in v3dv_pipeline_cache_init()
219 cache->stats.miss = 0; in v3dv_pipeline_cache_init()
220 cache->stats.hit = 0; in v3dv_pipeline_cache_init()
221 cache->stats.count = 0; in v3dv_pipeline_cache_init()
223 cache->externally_synchronized = flags & in v3dv_pipeline_cache_init()
226 cache->nir_cache = NULL; in v3dv_pipeline_cache_init()
227 cache->cache = NULL; in v3dv_pipeline_cache_init()
233 v3dv_pipeline_shared_data_create_from_blob(struct v3dv_pipeline_cache *cache,
237 pipeline_cache_upload_shared_data(struct v3dv_pipeline_cache *cache,
251 v3dv_pipeline_cache_search_for_pipeline(struct v3dv_pipeline_cache *cache, in v3dv_pipeline_cache_search_for_pipeline() argument
255 if (!cache || !cache->cache) in v3dv_pipeline_cache_search_for_pipeline()
262 fprintf(stderr, "pipeline cache %p, search pipeline with key %s\n", cache, sha1buf); in v3dv_pipeline_cache_search_for_pipeline()
265 pipeline_cache_lock(cache); in v3dv_pipeline_cache_search_for_pipeline()
268 _mesa_hash_table_search(cache->cache, sha1_key); in v3dv_pipeline_cache_search_for_pipeline()
275 cache->stats.hit++; in v3dv_pipeline_cache_search_for_pipeline()
278 fprintf(stderr, "[v3dv cache] hit: %p\n", cache_entry); in v3dv_pipeline_cache_search_for_pipeline()
280 cache_dump_stats(cache); in v3dv_pipeline_cache_search_for_pipeline()
286 pipeline_cache_unlock(cache); in v3dv_pipeline_cache_search_for_pipeline()
291 cache->stats.miss++; in v3dv_pipeline_cache_search_for_pipeline()
293 fprintf(stderr, "[v3dv cache] miss\n"); in v3dv_pipeline_cache_search_for_pipeline()
295 cache_dump_stats(cache); in v3dv_pipeline_cache_search_for_pipeline()
298 pipeline_cache_unlock(cache); in v3dv_pipeline_cache_search_for_pipeline()
301 struct v3dv_device *device = cache->device; in v3dv_pipeline_cache_search_for_pipeline()
303 /* Note that the on-disk-cache can be independently disabled, while keeping in v3dv_pipeline_cache_search_for_pipeline()
304 * the pipeline cache working, by using the environment variable in v3dv_pipeline_cache_search_for_pipeline()
317 fprintf(stderr, "[v3dv on-disk cache] %s %s\n", in v3dv_pipeline_cache_search_for_pipeline()
327 shared_data = v3dv_pipeline_shared_data_create_from_blob(cache, &blob); in v3dv_pipeline_cache_search_for_pipeline()
335 cache->stats.on_disk_hit++; in v3dv_pipeline_cache_search_for_pipeline()
336 if (cache) in v3dv_pipeline_cache_search_for_pipeline()
337 pipeline_cache_upload_shared_data(cache, shared_data, true); in v3dv_pipeline_cache_search_for_pipeline()
373 v3dv_pipeline_shared_data_new(struct v3dv_pipeline_cache *cache, in v3dv_pipeline_shared_data_new() argument
382 * and unref by both the pipeline and the pipeline cache, so we can't in v3dv_pipeline_shared_data_new()
383 * ensure that the cache or pipeline alloc will be available on the last in v3dv_pipeline_shared_data_new()
387 vk_zalloc2(&cache->device->vk.alloc, NULL, size, 8, in v3dv_pipeline_shared_data_new()
401 struct v3dv_bo *bo = v3dv_bo_alloc(cache->device, total_assembly_size, in v3dv_pipeline_shared_data_new()
408 bool ok = v3dv_bo_map(cache->device, bo, total_assembly_size); in v3dv_pipeline_shared_data_new()
421 v3dv_pipeline_shared_data_unref(cache->device, new_entry); in v3dv_pipeline_shared_data_new()
426 pipeline_cache_upload_shared_data(struct v3dv_pipeline_cache *cache, in pipeline_cache_upload_shared_data() argument
432 if (!cache || !cache->cache) in pipeline_cache_upload_shared_data()
435 if (cache->stats.count > V3DV_MAX_PIPELINE_CACHE_ENTRIES) in pipeline_cache_upload_shared_data()
438 pipeline_cache_lock(cache); in pipeline_cache_upload_shared_data()
441 /* If this is being called from the disk cache, we already know that the in pipeline_cache_upload_shared_data()
445 entry = _mesa_hash_table_search(cache->cache, shared_data->sha1_key); in pipeline_cache_upload_shared_data()
448 pipeline_cache_unlock(cache); in pipeline_cache_upload_shared_data()
453 _mesa_hash_table_insert(cache->cache, shared_data->sha1_key, shared_data); in pipeline_cache_upload_shared_data()
454 cache->stats.count++; in pipeline_cache_upload_shared_data()
459 fprintf(stderr, "pipeline cache %p, new cache entry with sha1 key %s:%p\n\n", in pipeline_cache_upload_shared_data()
460 cache, sha1buf, shared_data); in pipeline_cache_upload_shared_data()
462 cache_dump_stats(cache); in pipeline_cache_upload_shared_data()
465 pipeline_cache_unlock(cache); in pipeline_cache_upload_shared_data()
468 /* If we are being called from a on-disk-cache hit, we can skip writing to in pipeline_cache_upload_shared_data()
469 * the disk cache in pipeline_cache_upload_shared_data()
474 struct v3dv_device *device = cache->device; in pipeline_cache_upload_shared_data()
486 fprintf(stderr, "[v3dv on-disk cache] storing %s\n", sha1buf); in pipeline_cache_upload_shared_data()
499 struct v3dv_pipeline_cache *cache) in v3dv_pipeline_cache_upload_pipeline() argument
501 pipeline_cache_upload_shared_data(cache, pipeline->shared_data, false); in v3dv_pipeline_cache_upload_pipeline()
505 serialized_nir_create_from_blob(struct v3dv_pipeline_cache *cache, in serialized_nir_create_from_blob() argument
515 ralloc_size(cache->nir_cache, sizeof(*snir) + snir_size); in serialized_nir_create_from_blob()
575 v3dv_pipeline_shared_data_create_from_blob(struct v3dv_pipeline_cache *cache, in v3dv_pipeline_shared_data_create_from_blob() argument
593 maps[stage] = vk_zalloc2(&cache->device->vk.alloc, NULL, in v3dv_pipeline_shared_data_create_from_blob()
613 shader_variant_create_from_blob(cache->device, blob); in v3dv_pipeline_shared_data_create_from_blob()
625 v3dv_pipeline_shared_data_new(cache, sha1_key, maps, variants, in v3dv_pipeline_shared_data_create_from_blob()
636 vk_free2(&cache->device->vk.alloc, NULL, maps[i]); in v3dv_pipeline_shared_data_create_from_blob()
638 v3dv_shader_variant_destroy(cache->device, variants[i]); in v3dv_pipeline_shared_data_create_from_blob()
644 pipeline_cache_load(struct v3dv_pipeline_cache *cache, in pipeline_cache_load() argument
648 struct v3dv_device *device = cache->device; in pipeline_cache_load()
652 if (cache->cache == NULL || cache->nir_cache == NULL) in pipeline_cache_load()
679 serialized_nir_create_from_blob(cache, &blob); in pipeline_cache_load()
684 _mesa_hash_table_insert(cache->nir_cache, snir->sha1_key, snir); in pipeline_cache_load()
685 cache->nir_stats.count++; in pipeline_cache_load()
694 v3dv_pipeline_shared_data_create_from_blob(cache, &blob); in pipeline_cache_load()
698 _mesa_hash_table_insert(cache->cache, cache_entry->sha1_key, cache_entry); in pipeline_cache_load()
699 cache->stats.count++; in pipeline_cache_load()
703 fprintf(stderr, "pipeline cache %p, loaded %i nir shaders and " in pipeline_cache_load()
704 "%i entries\n", cache, nir_count, count); in pipeline_cache_load()
706 cache_dump_stats(cache); in pipeline_cache_load()
717 struct v3dv_pipeline_cache *cache; in v3dv_CreatePipelineCache() local
721 cache = vk_object_zalloc(&device->vk, pAllocator, in v3dv_CreatePipelineCache()
722 sizeof(*cache), in v3dv_CreatePipelineCache()
725 if (cache == NULL) in v3dv_CreatePipelineCache()
728 v3dv_pipeline_cache_init(cache, device, pCreateInfo->flags, in v3dv_CreatePipelineCache()
732 pipeline_cache_load(cache, in v3dv_CreatePipelineCache()
737 *pPipelineCache = v3dv_pipeline_cache_to_handle(cache); in v3dv_CreatePipelineCache()
743 v3dv_pipeline_cache_finish(struct v3dv_pipeline_cache *cache) in v3dv_pipeline_cache_finish() argument
745 mtx_destroy(&cache->mutex); in v3dv_pipeline_cache_finish()
748 cache_dump_stats(cache); in v3dv_pipeline_cache_finish()
750 if (cache->nir_cache) { in v3dv_pipeline_cache_finish()
751 hash_table_foreach(cache->nir_cache, entry) in v3dv_pipeline_cache_finish()
754 _mesa_hash_table_destroy(cache->nir_cache, NULL); in v3dv_pipeline_cache_finish()
757 if (cache->cache) { in v3dv_pipeline_cache_finish()
758 hash_table_foreach(cache->cache, entry) { in v3dv_pipeline_cache_finish()
761 v3dv_pipeline_shared_data_unref(cache->device, cache_entry); in v3dv_pipeline_cache_finish()
764 _mesa_hash_table_destroy(cache->cache, NULL); in v3dv_pipeline_cache_finish()
774 V3DV_FROM_HANDLE(v3dv_pipeline_cache, cache, _cache); in v3dv_DestroyPipelineCache()
776 if (!cache) in v3dv_DestroyPipelineCache()
779 v3dv_pipeline_cache_finish(cache); in v3dv_DestroyPipelineCache()
781 vk_object_free(&device->vk, pAllocator, cache); in v3dv_DestroyPipelineCache()
792 if (!dst->cache || !dst->nir_cache) in v3dv_MergePipelineCaches()
797 if (!src->cache || !src->nir_cache) in v3dv_MergePipelineCaches()
808 * convenient to create and store on the cache, but requires to do a in v3dv_MergePipelineCaches()
825 fprintf(stderr, "pipeline cache %p, added nir entry %s " in v3dv_MergePipelineCaches()
826 "from pipeline cache %p\n", in v3dv_MergePipelineCaches()
833 hash_table_foreach(src->cache, entry) { in v3dv_MergePipelineCaches()
837 if (_mesa_hash_table_search(dst->cache, cache_entry->sha1_key)) in v3dv_MergePipelineCaches()
841 _mesa_hash_table_insert(dst->cache, cache_entry->sha1_key, cache_entry); in v3dv_MergePipelineCaches()
848 fprintf(stderr, "pipeline cache %p, added entry %s " in v3dv_MergePipelineCaches()
849 "from pipeline cache %p\n", in v3dv_MergePipelineCaches()
956 V3DV_FROM_HANDLE(v3dv_pipeline_cache, cache, _cache); in v3dv_GetPipelineCacheData()
968 pipeline_cache_lock(cache); in v3dv_GetPipelineCacheData()
986 if (cache->nir_cache) { in v3dv_GetPipelineCacheData()
987 hash_table_foreach(cache->nir_cache, entry) { in v3dv_GetPipelineCacheData()
1013 if (cache->cache) { in v3dv_GetPipelineCacheData()
1014 hash_table_foreach(cache->cache, entry) { in v3dv_GetPipelineCacheData()
1035 assert(count <= cache->stats.count); in v3dv_GetPipelineCacheData()
1036 fprintf(stderr, "GetPipelineCacheData: serializing cache %p, " in v3dv_GetPipelineCacheData()
1039 cache, nir_count, count, (uint32_t) *pDataSize); in v3dv_GetPipelineCacheData()
1045 pipeline_cache_unlock(cache); in v3dv_GetPipelineCacheData()