aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler
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/compiler
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/compiler')
-rw-r--r--src/compiler/nir/nir_serialize.c19
-rw-r--r--src/compiler/nir/nir_serialize.h2
2 files changed, 18 insertions, 3 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);