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()
67 pipeline_cache_lock(struct v3dv_pipeline_cache *cache) in pipeline_cache_lock() argument
69 if (!cache->externally_synchronized) in pipeline_cache_lock()
70 pthread_mutex_lock(&cache->mutex); in pipeline_cache_lock()
74 pipeline_cache_unlock(struct v3dv_pipeline_cache *cache) in pipeline_cache_unlock() argument
76 if (!cache->externally_synchronized) in pipeline_cache_unlock()
77 pthread_mutex_unlock(&cache->mutex); in pipeline_cache_unlock()
82 struct v3dv_pipeline_cache *cache, in v3dv_pipeline_cache_upload_nir() argument
86 if (!cache || !cache->nir_cache) in v3dv_pipeline_cache_upload_nir()
89 if (cache->nir_stats.count > V3DV_MAX_PIPELINE_CACHE_ENTRIES) in v3dv_pipeline_cache_upload_nir()
92 pipeline_cache_lock(cache); in v3dv_pipeline_cache_upload_nir()
94 _mesa_hash_table_search(cache->nir_cache, sha1_key); in v3dv_pipeline_cache_upload_nir()
95 pipeline_cache_unlock(cache); in v3dv_pipeline_cache_upload_nir()
108 pipeline_cache_lock(cache); in v3dv_pipeline_cache_upload_nir()
113 entry = _mesa_hash_table_search(cache->nir_cache, sha1_key); in v3dv_pipeline_cache_upload_nir()
116 pipeline_cache_unlock(cache); in v3dv_pipeline_cache_upload_nir()
121 ralloc_size(cache->nir_cache, sizeof(*snir) + blob.size); in v3dv_pipeline_cache_upload_nir()
128 cache->nir_stats.count++; in v3dv_pipeline_cache_upload_nir()
132 fprintf(stderr, "pipeline cache %p, new nir entry %s\n", cache, sha1buf); in v3dv_pipeline_cache_upload_nir()
134 cache_dump_stats(cache); in v3dv_pipeline_cache_upload_nir()
137 _mesa_hash_table_insert(cache->nir_cache, snir->sha1_key, snir); in v3dv_pipeline_cache_upload_nir()
139 pipeline_cache_unlock(cache); in v3dv_pipeline_cache_upload_nir()
144 struct v3dv_pipeline_cache *cache, in v3dv_pipeline_cache_search_for_nir() argument
148 if (!cache || !cache->nir_cache) in v3dv_pipeline_cache_search_for_nir()
155 fprintf(stderr, "pipeline cache %p, search for nir %s\n", cache, sha1buf); in v3dv_pipeline_cache_search_for_nir()
160 pipeline_cache_lock(cache); in v3dv_pipeline_cache_search_for_nir()
162 _mesa_hash_table_search(cache->nir_cache, sha1_key); in v3dv_pipeline_cache_search_for_nir()
165 pipeline_cache_unlock(cache); in v3dv_pipeline_cache_search_for_nir()
173 * after cache creation in v3dv_pipeline_cache_search_for_nir()
179 cache->nir_stats.hit++; in v3dv_pipeline_cache_search_for_nir()
181 fprintf(stderr, "\tnir cache hit: %p\n", nir); in v3dv_pipeline_cache_search_for_nir()
183 cache_dump_stats(cache); in v3dv_pipeline_cache_search_for_nir()
189 cache->nir_stats.miss++; in v3dv_pipeline_cache_search_for_nir()
191 fprintf(stderr, "\tnir cache miss\n"); in v3dv_pipeline_cache_search_for_nir()
193 cache_dump_stats(cache); in v3dv_pipeline_cache_search_for_nir()
200 v3dv_pipeline_cache_init(struct v3dv_pipeline_cache *cache, in v3dv_pipeline_cache_init() argument
205 cache->device = device; in v3dv_pipeline_cache_init()
206 pthread_mutex_init(&cache->mutex, NULL); in v3dv_pipeline_cache_init()
209 cache->nir_cache = _mesa_hash_table_create(NULL, sha1_hash_func, in v3dv_pipeline_cache_init()
211 cache->nir_stats.miss = 0; in v3dv_pipeline_cache_init()
212 cache->nir_stats.hit = 0; in v3dv_pipeline_cache_init()
213 cache->nir_stats.count = 0; in v3dv_pipeline_cache_init()
215 cache->cache = _mesa_hash_table_create(NULL, sha1_hash_func, in v3dv_pipeline_cache_init()
217 cache->stats.miss = 0; in v3dv_pipeline_cache_init()
218 cache->stats.hit = 0; in v3dv_pipeline_cache_init()
219 cache->stats.count = 0; in v3dv_pipeline_cache_init()
221 cache->externally_synchronized = flags & in v3dv_pipeline_cache_init()
224 cache->nir_cache = NULL; in v3dv_pipeline_cache_init()
225 cache->cache = NULL; in v3dv_pipeline_cache_init()
231 v3dv_pipeline_shared_data_create_from_blob(struct v3dv_pipeline_cache *cache,
235 pipeline_cache_upload_shared_data(struct v3dv_pipeline_cache *cache,
249 v3dv_pipeline_cache_search_for_pipeline(struct v3dv_pipeline_cache *cache, in v3dv_pipeline_cache_search_for_pipeline() argument
253 if (!cache || !cache->cache) in v3dv_pipeline_cache_search_for_pipeline()
260 fprintf(stderr, "pipeline cache %p, search pipeline with key %s\n", cache, sha1buf); in v3dv_pipeline_cache_search_for_pipeline()
263 pipeline_cache_lock(cache); in v3dv_pipeline_cache_search_for_pipeline()
266 _mesa_hash_table_search(cache->cache, sha1_key); in v3dv_pipeline_cache_search_for_pipeline()
273 cache->stats.hit++; in v3dv_pipeline_cache_search_for_pipeline()
278 cache_dump_stats(cache); in v3dv_pipeline_cache_search_for_pipeline()
284 pipeline_cache_unlock(cache); in v3dv_pipeline_cache_search_for_pipeline()
289 cache->stats.miss++; in v3dv_pipeline_cache_search_for_pipeline()
293 cache_dump_stats(cache); in v3dv_pipeline_cache_search_for_pipeline()
296 pipeline_cache_unlock(cache); in v3dv_pipeline_cache_search_for_pipeline()
299 struct v3dv_device *device = cache->device; in v3dv_pipeline_cache_search_for_pipeline()
301 /* Note that the on-disk-cache can be independently disabled, while keeping in v3dv_pipeline_cache_search_for_pipeline()
302 * the pipeline cache working, by using the environment variable in v3dv_pipeline_cache_search_for_pipeline()
317 fprintf(stderr, "\ton-disk-cache hit\n"); in v3dv_pipeline_cache_search_for_pipeline()
320 shared_data = v3dv_pipeline_shared_data_create_from_blob(cache, &blob); in v3dv_pipeline_cache_search_for_pipeline()
324 if (cache) in v3dv_pipeline_cache_search_for_pipeline()
325 pipeline_cache_upload_shared_data(cache, shared_data, true); in v3dv_pipeline_cache_search_for_pipeline()
330 fprintf(stderr, "\ton-disk-cache miss\n"); in v3dv_pipeline_cache_search_for_pipeline()
364 v3dv_pipeline_shared_data_new(struct v3dv_pipeline_cache *cache, in v3dv_pipeline_shared_data_new() argument
373 * and unref by both the pipeline and the pipeline cache, so we can't in v3dv_pipeline_shared_data_new()
374 * ensure that the cache or pipeline alloc will be available on the last in v3dv_pipeline_shared_data_new()
378 vk_zalloc2(&cache->device->vk.alloc, NULL, size, 8, in v3dv_pipeline_shared_data_new()
392 struct v3dv_bo *bo = v3dv_bo_alloc(cache->device, total_assembly_size, in v3dv_pipeline_shared_data_new()
396 v3dv_pipeline_shared_data_unref(cache->device, new_entry); in v3dv_pipeline_shared_data_new()
400 bool ok = v3dv_bo_map(cache->device, bo, total_assembly_size); in v3dv_pipeline_shared_data_new()
403 v3dv_pipeline_shared_data_unref(cache->device, new_entry); in v3dv_pipeline_shared_data_new()
415 pipeline_cache_upload_shared_data(struct v3dv_pipeline_cache *cache, in pipeline_cache_upload_shared_data() argument
421 if (!cache || !cache->cache) in pipeline_cache_upload_shared_data()
424 if (cache->stats.count > V3DV_MAX_PIPELINE_CACHE_ENTRIES) in pipeline_cache_upload_shared_data()
427 pipeline_cache_lock(cache); in pipeline_cache_upload_shared_data()
429 _mesa_hash_table_search(cache->cache, shared_data->sha1_key); in pipeline_cache_upload_shared_data()
432 pipeline_cache_unlock(cache); in pipeline_cache_upload_shared_data()
437 _mesa_hash_table_insert(cache->cache, shared_data->sha1_key, shared_data); in pipeline_cache_upload_shared_data()
438 cache->stats.count++; in pipeline_cache_upload_shared_data()
443 fprintf(stderr, "pipeline cache %p, new cache entry with sha1 key %s:%p\n\n", in pipeline_cache_upload_shared_data()
444 cache, sha1buf, shared_data); in pipeline_cache_upload_shared_data()
446 cache_dump_stats(cache); in pipeline_cache_upload_shared_data()
449 pipeline_cache_unlock(cache); in pipeline_cache_upload_shared_data()
452 /* If we are being called from a on-disk-cache hit, we can skip writing to in pipeline_cache_upload_shared_data()
453 * the disk cache in pipeline_cache_upload_shared_data()
458 struct v3dv_device *device = cache->device; in pipeline_cache_upload_shared_data()
472 fprintf(stderr, "on-disk-cache, new cache entry with sha1 key %s:%p\n\n", in pipeline_cache_upload_shared_data()
485 struct v3dv_pipeline_cache *cache) in v3dv_pipeline_cache_upload_pipeline() argument
487 pipeline_cache_upload_shared_data(cache, pipeline->shared_data, false); in v3dv_pipeline_cache_upload_pipeline()
491 serialized_nir_create_from_blob(struct v3dv_pipeline_cache *cache, in serialized_nir_create_from_blob() argument
501 ralloc_size(cache->nir_cache, sizeof(*snir) + snir_size); in serialized_nir_create_from_blob()
561 v3dv_pipeline_shared_data_create_from_blob(struct v3dv_pipeline_cache *cache, in v3dv_pipeline_shared_data_create_from_blob() argument
578 maps[stage] = vk_zalloc2(&cache->device->vk.alloc, NULL, in v3dv_pipeline_shared_data_create_from_blob()
600 shader_variant_create_from_blob(cache->device, blob); in v3dv_pipeline_shared_data_create_from_blob()
611 return v3dv_pipeline_shared_data_new(cache, sha1_key, maps, variants, in v3dv_pipeline_shared_data_create_from_blob()
616 pipeline_cache_load(struct v3dv_pipeline_cache *cache, in pipeline_cache_load() argument
620 struct v3dv_device *device = cache->device; in pipeline_cache_load()
624 if (cache->cache == NULL || cache->nir_cache == NULL) in pipeline_cache_load()
651 serialized_nir_create_from_blob(cache, &blob); in pipeline_cache_load()
656 _mesa_hash_table_insert(cache->nir_cache, snir->sha1_key, snir); in pipeline_cache_load()
657 cache->nir_stats.count++; in pipeline_cache_load()
666 v3dv_pipeline_shared_data_create_from_blob(cache, &blob); in pipeline_cache_load()
670 _mesa_hash_table_insert(cache->cache, cache_entry->sha1_key, cache_entry); in pipeline_cache_load()
671 cache->stats.count++; in pipeline_cache_load()
675 fprintf(stderr, "pipeline cache %p, loaded %i nir shaders and " in pipeline_cache_load()
676 "%i entries\n", cache, nir_count, count); in pipeline_cache_load()
678 cache_dump_stats(cache); in pipeline_cache_load()
689 struct v3dv_pipeline_cache *cache; in v3dv_CreatePipelineCache() local
693 cache = vk_object_zalloc(&device->vk, pAllocator, in v3dv_CreatePipelineCache()
694 sizeof(*cache), in v3dv_CreatePipelineCache()
697 if (cache == NULL) in v3dv_CreatePipelineCache()
700 v3dv_pipeline_cache_init(cache, device, pCreateInfo->flags, in v3dv_CreatePipelineCache()
704 pipeline_cache_load(cache, in v3dv_CreatePipelineCache()
709 *pPipelineCache = v3dv_pipeline_cache_to_handle(cache); in v3dv_CreatePipelineCache()
715 v3dv_pipeline_cache_finish(struct v3dv_pipeline_cache *cache) in v3dv_pipeline_cache_finish() argument
717 pthread_mutex_destroy(&cache->mutex); in v3dv_pipeline_cache_finish()
720 cache_dump_stats(cache); in v3dv_pipeline_cache_finish()
722 if (cache->nir_cache) { in v3dv_pipeline_cache_finish()
723 hash_table_foreach(cache->nir_cache, entry) in v3dv_pipeline_cache_finish()
726 _mesa_hash_table_destroy(cache->nir_cache, NULL); in v3dv_pipeline_cache_finish()
729 if (cache->cache) { in v3dv_pipeline_cache_finish()
730 hash_table_foreach(cache->cache, entry) { in v3dv_pipeline_cache_finish()
733 v3dv_pipeline_shared_data_unref(cache->device, cache_entry); in v3dv_pipeline_cache_finish()
736 _mesa_hash_table_destroy(cache->cache, NULL); in v3dv_pipeline_cache_finish()
746 V3DV_FROM_HANDLE(v3dv_pipeline_cache, cache, _cache); in v3dv_DestroyPipelineCache()
748 if (!cache) in v3dv_DestroyPipelineCache()
751 v3dv_pipeline_cache_finish(cache); in v3dv_DestroyPipelineCache()
753 vk_object_free(&device->vk, pAllocator, cache); in v3dv_DestroyPipelineCache()
764 if (!dst->cache || !dst->nir_cache) in v3dv_MergePipelineCaches()
769 if (!src->cache || !src->nir_cache) in v3dv_MergePipelineCaches()
780 * convenient to create and store on the cache, but requires to do a in v3dv_MergePipelineCaches()
797 fprintf(stderr, "pipeline cache %p, added nir entry %s " in v3dv_MergePipelineCaches()
798 "from pipeline cache %p\n", in v3dv_MergePipelineCaches()
805 hash_table_foreach(src->cache, entry) { in v3dv_MergePipelineCaches()
809 if (_mesa_hash_table_search(dst->cache, cache_entry->sha1_key)) in v3dv_MergePipelineCaches()
813 _mesa_hash_table_insert(dst->cache, cache_entry->sha1_key, cache_entry); in v3dv_MergePipelineCaches()
820 fprintf(stderr, "pipeline cache %p, added entry %s " in v3dv_MergePipelineCaches()
821 "from pipeline cache %p\n", in v3dv_MergePipelineCaches()
928 V3DV_FROM_HANDLE(v3dv_pipeline_cache, cache, _cache); in v3dv_GetPipelineCacheData()
940 pipeline_cache_lock(cache); in v3dv_GetPipelineCacheData()
958 if (cache->nir_cache) { in v3dv_GetPipelineCacheData()
959 hash_table_foreach(cache->nir_cache, entry) { in v3dv_GetPipelineCacheData()
985 if (cache->cache) { in v3dv_GetPipelineCacheData()
986 hash_table_foreach(cache->cache, entry) { in v3dv_GetPipelineCacheData()
1007 assert(count <= cache->stats.count); in v3dv_GetPipelineCacheData()
1008 fprintf(stderr, "GetPipelineCacheData: serializing cache %p, " in v3dv_GetPipelineCacheData()
1011 cache, nir_count, count, (uint32_t) *pDataSize); in v3dv_GetPipelineCacheData()
1017 pipeline_cache_unlock(cache); in v3dv_GetPipelineCacheData()