radv: Implement VK_AMD_shader_info
[mesa.git] / src / amd / vulkan / radv_pipeline_cache.c
index a75356b82297d6fd1020def92a2afdcb9fdc3c4b..441e2257d55c67fdf9f0925e74996c2d8ac59b33 100644 (file)
@@ -62,9 +62,11 @@ radv_pipeline_cache_init(struct radv_pipeline_cache *cache,
        cache->hash_table = malloc(byte_size);
 
        /* We don't consider allocation failure fatal, we just start with a 0-sized
-        * cache. */
+        * cache. Disable caching when we want to keep shader debug info, since
+        * we don't get the debug info on cached shaders. */
        if (cache->hash_table == NULL ||
-           (device->instance->debug_flags & RADV_DEBUG_NO_CACHE))
+           (device->instance->debug_flags & RADV_DEBUG_NO_CACHE) ||
+           device->keep_shader_info)
                cache->table_size = 0;
        else
                memset(cache->hash_table, 0, byte_size);
@@ -100,14 +102,14 @@ void
 radv_hash_shaders(unsigned char *hash,
                  const VkPipelineShaderStageCreateInfo **stages,
                  const struct radv_pipeline_layout *layout,
-                 const struct ac_shader_variant_key *keys,
+                 const struct radv_pipeline_key *key,
                  uint32_t flags)
 {
        struct mesa_sha1 ctx;
 
        _mesa_sha1_init(&ctx);
-       if (keys)
-               _mesa_sha1_update(&ctx, keys, sizeof(*keys) * MESA_SHADER_STAGES);
+       if (key)
+               _mesa_sha1_update(&ctx, key, sizeof(*key));
        if (layout)
                _mesa_sha1_update(&ctx, layout->sha1, sizeof(layout->sha1));
 
@@ -186,8 +188,11 @@ radv_create_shader_variants_from_pipeline_cache(struct radv_device *device,
        entry = radv_pipeline_cache_search_unlocked(cache, sha1);
 
        if (!entry) {
+               /* Again, don't cache when we want debug info, since this isn't
+                * present in the cache. */
                if (!device->physical_device->disk_cache ||
-                   (device->instance->debug_flags & RADV_DEBUG_NO_CACHE)) {
+                   (device->instance->debug_flags & RADV_DEBUG_NO_CACHE) ||
+                   device->keep_shader_info) {
                        pthread_mutex_unlock(&cache->mutex);
                        return false;
                }
@@ -231,6 +236,8 @@ radv_create_shader_variants_from_pipeline_cache(struct radv_device *device,
                        p += entry->code_sizes[i];
 
                        entry->variants[i] = variant;
+               } else if (entry->code_sizes[i]) {
+                       p += sizeof(struct cache_entry_variant_info) + entry->code_sizes[i];
                }
 
        }