From e1409aead589d582f62a2526d2acaf03c704615f Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 28 May 2019 15:34:52 -0700 Subject: [PATCH] iris: Only store the SHA1 of the NIR in iris_uncompiled_shader Jason pointed out that we don't need to keep an entire copy of the serialized NIR around, we just need the SHA1. This does change our disk cache key to be taking a SHA1 of a SHA1, which is a bit odd, but should work out and be faster and use less memory. Reviewed-by: Jason Ekstrand --- src/gallium/drivers/iris/iris_context.h | 5 ++--- src/gallium/drivers/iris/iris_disk_cache.c | 11 ++++------- src/gallium/drivers/iris/iris_program.c | 4 +--- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/gallium/drivers/iris/iris_context.h b/src/gallium/drivers/iris/iris_context.h index fb4423957ca..42cad5e8551 100644 --- a/src/gallium/drivers/iris/iris_context.h +++ b/src/gallium/drivers/iris/iris_context.h @@ -260,9 +260,8 @@ struct iris_uncompiled_shader { struct pipe_stream_output_info stream_output; - /* The serialized NIR (for the disk cache) and size in bytes. */ - void *ir_cache_binary; - uint32_t ir_cache_binary_size; + /* A SHA1 of the serialized NIR for the disk cache. */ + unsigned char nir_sha1[20]; unsigned program_id; diff --git a/src/gallium/drivers/iris/iris_disk_cache.c b/src/gallium/drivers/iris/iris_disk_cache.c index 2b022aff66a..eac01048122 100644 --- a/src/gallium/drivers/iris/iris_disk_cache.c +++ b/src/gallium/drivers/iris/iris_disk_cache.c @@ -61,16 +61,13 @@ iris_disk_cache_compute_key(struct disk_cache *cache, memcpy(&prog_key, orig_prog_key, prog_key_size); brw_prog_key_set_id(&prog_key, stage, 0); - uint32_t data_size = prog_key_size + ish->ir_cache_binary_size; + uint8_t data[sizeof(prog_key) + sizeof(ish->nir_sha1)]; + uint32_t data_size = prog_key_size + sizeof(ish->nir_sha1); - void *data = malloc(data_size); - memcpy(data, &prog_key, prog_key_size); - memcpy(data + prog_key_size, ish->ir_cache_binary, - ish->ir_cache_binary_size); + memcpy(data, ish->nir_sha1, sizeof(ish->nir_sha1)); + memcpy(data + sizeof(ish->nir_sha1), &prog_key, prog_key_size); disk_cache_compute_key(cache, data, data_size, cache_key); - - free(data); } /** diff --git a/src/gallium/drivers/iris/iris_program.c b/src/gallium/drivers/iris/iris_program.c index a5cd987664f..60f45eec629 100644 --- a/src/gallium/drivers/iris/iris_program.c +++ b/src/gallium/drivers/iris/iris_program.c @@ -1506,9 +1506,7 @@ iris_create_uncompiled_shader(struct pipe_context *ctx, struct blob blob; blob_init(&blob); nir_serialize(&blob, ish->nir); - ish->ir_cache_binary = malloc(blob.size); - ish->ir_cache_binary_size = blob.size; - memcpy(ish->ir_cache_binary, blob.data, blob.size); + _mesa_sha1_compute(blob.data, blob.size, ish->nir_sha1); blob_finish(&blob); } -- 2.30.2