[Mesa-dev] [PATCH 6/4] radv: make use of on-disk cache

Timothy Arceri tarceri at itsqueeze.com
Wed Mar 15 05:57:44 UTC 2017


If the app provided and in-memory pipeline caches don't contain
what we are looking for then we fallback to the on-disk cache.
---
 src/amd/vulkan/radv_pipeline_cache.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/amd/vulkan/radv_pipeline_cache.c b/src/amd/vulkan/radv_pipeline_cache.c
index 3a58f6a..ffcb8e5 100644
--- a/src/amd/vulkan/radv_pipeline_cache.c
+++ b/src/amd/vulkan/radv_pipeline_cache.c
@@ -16,20 +16,21 @@
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  * IN THE SOFTWARE.
  */
 
 #include "util/mesa-sha1.h"
 #include "util/debug.h"
+#include "util/disk_cache.h"
 #include "radv_private.h"
 
 #include "ac_nir_to_llvm.h"
 
 struct cache_entry {
 	union {
 		unsigned char sha1[20];
 		uint32_t sha1_dw[5];
 	};
 	uint32_t code_size;
@@ -152,22 +153,28 @@ radv_create_shader_variant_from_pipeline_cache(struct radv_device *device,
 					       struct radv_pipeline_cache *cache,
 					       const unsigned char *sha1)
 {
 	struct cache_entry *entry = NULL;
 
 	if (cache)
 		entry = radv_pipeline_cache_search(cache, sha1);
 	else
 		entry = radv_pipeline_cache_search(device->mem_cache, sha1);
 
-	if (!entry)
-		return NULL;
+	if (!entry) {
+		size_t entry_size;
+		entry = (struct cache_entry *)
+			disk_cache_get(device->physical_device->disk_cache,
+				       sha1, &entry_size);
+		if (!entry)
+			return NULL;
+	}
 
 	if (!entry->variant) {
 		struct radv_shader_variant *variant;
 
 		variant = calloc(1, sizeof(struct radv_shader_variant));
 		if (!variant)
 			return NULL;
 
 		variant->config = entry->config;
 		variant->info = entry->variant_info;
@@ -294,20 +301,22 @@ radv_pipeline_cache_insert_shader(struct radv_device *device,
 	memcpy(entry->code, code, code_size);
 	entry->config = variant->config;
 	entry->variant_info = variant->info;
 	entry->rsrc1 = variant->rsrc1;
 	entry->rsrc2 = variant->rsrc2;
 	entry->code_size = code_size;
 	entry->variant = variant;
 	__sync_fetch_and_add(&variant->ref_count, 1);
 
 	radv_pipeline_cache_add_entry(cache, entry);
+	disk_cache_put(device->physical_device->disk_cache,
+		       sha1, entry, sizeof(*entry) + code_size);
 
 	cache->modified = true;
 	pthread_mutex_unlock(&cache->mutex);
 	return variant;
 }
 
 struct cache_header {
 	uint32_t header_size;
 	uint32_t header_version;
 	uint32_t vendor_id;
-- 
2.9.3



More information about the mesa-dev mailing list