summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2019-10-09 13:27:07 -0400
committerMarek Olšák <[email protected]>2019-10-10 15:47:07 -0400
commitdd4cc56ebd05074848b1817493f5058e0c1cd9e9 (patch)
tree5299b9cc0ac06aea50026d2b97cad25c35172db9 /src
parente6986bcb733d87518cad13a5e9ef116d26eadbc0 (diff)
nir: add a strip parameter to nir_serialize
so that drivers don't have to call nir_strip manually. Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Rob Clark <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/compiler/nir/nir_serialize.c19
-rw-r--r--src/compiler/nir/nir_serialize.h2
-rw-r--r--src/gallium/drivers/iris/iris_program.c13
-rw-r--r--src/gallium/drivers/radeonsi/si_shader_nir.c5
-rw-r--r--src/gallium/drivers/radeonsi/si_state_shaders.c2
-rw-r--r--src/intel/vulkan/anv_pipeline_cache.c2
-rw-r--r--src/mesa/drivers/dri/i965/brw_program_binary.c2
-rw-r--r--src/mesa/state_tracker/st_shader_cache.c2
8 files changed, 25 insertions, 22 deletions
diff --git a/src/compiler/nir/nir_serialize.c b/src/compiler/nir/nir_serialize.c
index 0a953c8daf4..b7b44f6af88 100644
--- a/src/compiler/nir/nir_serialize.c
+++ b/src/compiler/nir/nir_serialize.c
@@ -1090,8 +1090,20 @@ read_function(read_ctx *ctx)
}
void
-nir_serialize(struct blob *blob, const nir_shader *nir)
+nir_serialize(struct blob *blob, const nir_shader *nir, bool strip)
{
+ nir_shader *stripped = NULL;
+
+ if (strip) {
+ /* Drop unnecessary information (like variable names), so the serialized
+ * NIR is smaller, and also to let us detect more isomorphic shaders
+ * when hashing, increasing cache hits.
+ */
+ stripped = nir_shader_clone(NULL, nir);
+ nir_strip(stripped);
+ nir = stripped;
+ }
+
write_ctx ctx;
ctx.remap_table = _mesa_pointer_hash_table_create(NULL);
ctx.next_idx = 0;
@@ -1145,6 +1157,9 @@ nir_serialize(struct blob *blob, const nir_shader *nir)
_mesa_hash_table_destroy(ctx.remap_table, NULL);
util_dynarray_fini(&ctx.phi_fixups);
+
+ if (strip)
+ ralloc_free(stripped);
}
nir_shader *
@@ -1213,7 +1228,7 @@ nir_shader_serialize_deserialize(nir_shader *shader)
struct blob writer;
blob_init(&writer);
- nir_serialize(&writer, shader);
+ nir_serialize(&writer, shader, false);
/* Delete all of dest's ralloc children but leave dest alone */
void *dead_ctx = ralloc_context(NULL);
diff --git a/src/compiler/nir/nir_serialize.h b/src/compiler/nir/nir_serialize.h
index 528988f5e4a..e813f2c7477 100644
--- a/src/compiler/nir/nir_serialize.h
+++ b/src/compiler/nir/nir_serialize.h
@@ -31,7 +31,7 @@
extern "C" {
#endif
-void nir_serialize(struct blob *blob, const nir_shader *nir);
+void nir_serialize(struct blob *blob, const nir_shader *nir, bool strip);
nir_shader *nir_deserialize(void *mem_ctx,
const struct nir_shader_compiler_options *options,
struct blob_reader *blob);
diff --git a/src/gallium/drivers/iris/iris_program.c b/src/gallium/drivers/iris/iris_program.c
index 886cdff56b6..2670bc28579 100644
--- a/src/gallium/drivers/iris/iris_program.c
+++ b/src/gallium/drivers/iris/iris_program.c
@@ -2019,22 +2019,15 @@ iris_create_uncompiled_shader(struct pipe_context *ctx,
if (screen->disk_cache) {
/* Serialize the NIR to a binary blob that we can hash for the disk
- * cache. First, drop unnecessary information (like variable names)
+ * cache. Drop unnecessary information (like variable names)
* so the serialized NIR is smaller, and also to let us detect more
- * isomorphic shaders when hashing, increasing cache hits. We clone
- * the NIR before stripping away this info because it can be useful
- * when inspecting and debugging shaders.
+ * isomorphic shaders when hashing, increasing cache hits.
*/
- nir_shader *clone = nir_shader_clone(NULL, nir);
- nir_strip(clone);
-
struct blob blob;
blob_init(&blob);
- nir_serialize(&blob, clone);
+ nir_serialize(&blob, nir, true);
_mesa_sha1_compute(blob.data, blob.size, ish->nir_sha1);
blob_finish(&blob);
-
- ralloc_free(clone);
}
return ish;
diff --git a/src/gallium/drivers/radeonsi/si_shader_nir.c b/src/gallium/drivers/radeonsi/si_shader_nir.c
index 6c267bbdafa..e97e5ccb07b 100644
--- a/src/gallium/drivers/radeonsi/si_shader_nir.c
+++ b/src/gallium/drivers/radeonsi/si_shader_nir.c
@@ -1004,11 +1004,6 @@ void si_lower_nir(struct si_shader_selector *sel)
si_nir_opts(sel->nir);
NIR_PASS_V(sel->nir, nir_lower_bool_to_int32);
-
- /* Strip the resulting shader so that the shader cache is more likely
- * to hit from other similar shaders.
- */
- nir_strip(sel->nir);
}
static void declare_nir_input_vs(struct si_shader_context *ctx,
diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c b/src/gallium/drivers/radeonsi/si_state_shaders.c
index 04443db7a44..b2071a21b31 100644
--- a/src/gallium/drivers/radeonsi/si_state_shaders.c
+++ b/src/gallium/drivers/radeonsi/si_state_shaders.c
@@ -59,7 +59,7 @@ void *si_get_ir_binary(struct si_shader_selector *sel, bool ngg, bool es)
assert(sel->nir);
blob_init(&blob);
- nir_serialize(&blob, sel->nir);
+ nir_serialize(&blob, sel->nir, true);
ir_binary = blob.data;
ir_size = blob.size;
}
diff --git a/src/intel/vulkan/anv_pipeline_cache.c b/src/intel/vulkan/anv_pipeline_cache.c
index 9c315d5f44c..e1d48b879b0 100644
--- a/src/intel/vulkan/anv_pipeline_cache.c
+++ b/src/intel/vulkan/anv_pipeline_cache.c
@@ -779,7 +779,7 @@ anv_device_upload_nir(struct anv_device *device,
struct blob blob;
blob_init(&blob);
- nir_serialize(&blob, nir);
+ nir_serialize(&blob, nir, false);
if (blob.out_of_memory) {
blob_finish(&blob);
return;
diff --git a/src/mesa/drivers/dri/i965/brw_program_binary.c b/src/mesa/drivers/dri/i965/brw_program_binary.c
index bf875341e21..a126f863ae2 100644
--- a/src/mesa/drivers/dri/i965/brw_program_binary.c
+++ b/src/mesa/drivers/dri/i965/brw_program_binary.c
@@ -132,7 +132,7 @@ serialize_nir_part(struct blob *writer, struct gl_program *prog)
blob_write_uint32(writer, NIR_PART);
intptr_t size_offset = blob_reserve_uint32(writer);
size_t nir_start = writer->size;
- nir_serialize(writer, prog->nir);
+ nir_serialize(writer, prog->nir, false);
blob_overwrite_uint32(writer, size_offset, writer->size - nir_start);
}
diff --git a/src/mesa/state_tracker/st_shader_cache.c b/src/mesa/state_tracker/st_shader_cache.c
index ae1602310db..a56e9fa354c 100644
--- a/src/mesa/state_tracker/st_shader_cache.c
+++ b/src/mesa/state_tracker/st_shader_cache.c
@@ -67,7 +67,7 @@ write_tgsi_to_cache(struct blob *blob, const struct tgsi_token *tokens,
static void
write_nir_to_cache(struct blob *blob, struct gl_program *prog)
{
- nir_serialize(blob, prog->nir);
+ nir_serialize(blob, prog->nir, false);
copy_blob_to_driver_cache_blob(blob, prog);
}