radv: move cache check inside insert and search functions
authorTimothy Arceri <tarceri@itsqueeze.com>
Wed, 15 Mar 2017 01:40:53 +0000 (12:40 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Fri, 17 Mar 2017 05:17:10 +0000 (16:17 +1100)
This will allow us to use fallback in-memory and on-disk caches
should the app not provide a pipeline cache.

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/vulkan/radv_pipeline.c
src/amd/vulkan/radv_pipeline_cache.c

index df763964970b6ce3861ee2ca7239492c1eaa5e63..13ae87c3c49a567e41f61e913ea18e828001dbde 100644 (file)
@@ -528,21 +528,19 @@ radv_pipeline_compile(struct radv_pipeline *pipeline,
                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,
@@ -559,7 +557,7 @@ radv_pipeline_compile(struct radv_pipeline *pipeline,
                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,
@@ -571,7 +569,7 @@ radv_pipeline_compile(struct radv_pipeline *pipeline,
        if (!module->nir)
                ralloc_free(nir);
 
-       if (variant && cache)
+       if (variant)
                variant = radv_pipeline_cache_insert_shader(cache, sha1, variant,
                                                            code, code_size);
 
index 83bf3cb6af4ae40a0ad636cd5e665584c8957070..5f6355f0d1a670981acc1954e342ec48058d9d23 100644 (file)
@@ -152,7 +152,10 @@ 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;
@@ -260,6 +263,9 @@ radv_pipeline_cache_insert_shader(struct radv_pipeline_cache *cache,
                                  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) {