This will allow us to use fallback in-memory and on-disk caches should the app not provide a pipeline cache. --- src/amd/vulkan/radv_pipeline.c | 28 +++++++++++++--------------- src/amd/vulkan/radv_pipeline_cache.c | 8 +++++++- 2 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/src/amd/vulkan/radv_pipeline.c b/src/amd/vulkan/radv_pipeline.c index df76396..13ae87c 100644 --- a/src/amd/vulkan/radv_pipeline.c +++ b/src/amd/vulkan/radv_pipeline.c @@ -521,64 +521,62 @@ radv_pipeline_compile(struct radv_pipeline *pipeline, if (module->nir) _mesa_sha1_compute(module->nir->info->name, strlen(module->nir->info->name), module->sha1); radv_hash_shader(sha1, module, entrypoint, spec_info, layout, key, 0); if (stage == MESA_SHADER_GEOMETRY) radv_hash_shader(gs_copy_sha1, module, entrypoint, spec_info, layout, key, 1); - if (cache) { - variant = radv_create_shader_variant_from_pipeline_cache(pipeline->device, - cache, - sha1); + variant = radv_create_shader_variant_from_pipeline_cache(pipeline->device, + cache, + sha1); - if (stage == MESA_SHADER_GEOMETRY) { - pipeline->gs_copy_shader = - radv_create_shader_variant_from_pipeline_cache( - pipeline->device, - cache, - gs_copy_sha1); - } - if (variant) - return variant; + if (stage == MESA_SHADER_GEOMETRY) { + pipeline->gs_copy_shader = + radv_create_shader_variant_from_pipeline_cache( + pipeline->device, + cache, + gs_copy_sha1); } + if (variant) + return variant; nir = radv_shader_compile_to_nir(pipeline->device, module, entrypoint, stage, spec_info, dump); if (nir == NULL) return NULL; variant = radv_shader_variant_create(pipeline->device, nir, layout, key, &code, &code_size, dump); if (stage == MESA_SHADER_GEOMETRY) { void *gs_copy_code = NULL; unsigned gs_copy_code_size = 0; pipeline->gs_copy_shader = radv_pipeline_create_gs_copy_shader( pipeline, nir, &gs_copy_code, &gs_copy_code_size, dump); - if (pipeline->gs_copy_shader && cache) { + if (pipeline->gs_copy_shader) { pipeline->gs_copy_shader = radv_pipeline_cache_insert_shader(cache, gs_copy_sha1, pipeline->gs_copy_shader, gs_copy_code, gs_copy_code_size); } } if (!module->nir) ralloc_free(nir); - if (variant && cache) + if (variant) variant = radv_pipeline_cache_insert_shader(cache, sha1, variant, code, code_size); if (code) free(code); return variant; } static VkResult radv_pipeline_scratch_init(struct radv_device *device, diff --git a/src/amd/vulkan/radv_pipeline_cache.c b/src/amd/vulkan/radv_pipeline_cache.c index 30f2dc1..5b7e1c4 100644 --- a/src/amd/vulkan/radv_pipeline_cache.c +++ b/src/amd/vulkan/radv_pipeline_cache.c @@ -145,21 +145,24 @@ radv_pipeline_cache_search(struct radv_pipeline_cache *cache, pthread_mutex_unlock(&cache->mutex); return entry; } struct radv_shader_variant * radv_create_shader_variant_from_pipeline_cache(struct radv_device *device, struct radv_pipeline_cache *cache, const unsigned char *sha1) { - struct cache_entry *entry = radv_pipeline_cache_search(cache, sha1); + struct cache_entry *entry = NULL; + + if (cache) + entry = radv_pipeline_cache_search(cache, sha1); if (!entry) return NULL; if (!entry->variant) { struct radv_shader_variant *variant; variant = calloc(1, sizeof(struct radv_shader_variant)); if (!variant) return NULL; @@ -253,20 +256,23 @@ radv_pipeline_cache_add_entry(struct radv_pipeline_cache *cache, if (cache->kernel_count < cache->table_size / 2) radv_pipeline_cache_set_entry(cache, entry); } struct radv_shader_variant * radv_pipeline_cache_insert_shader(struct radv_pipeline_cache *cache, const unsigned char *sha1, struct radv_shader_variant *variant, const void *code, unsigned code_size) { + if (!cache) + return variant; + pthread_mutex_lock(&cache->mutex); struct cache_entry *entry = radv_pipeline_cache_search_unlocked(cache, sha1); if (entry) { if (entry->variant) { radv_shader_variant_destroy(cache->device, variant); variant = entry->variant; } else { entry->variant = variant; } __sync_fetch_and_add(&variant->ref_count, 1); -- 2.9.3 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev