nir: add a strip parameter to nir_serialize
authorMarek Olšák <marek.olsak@amd.com>
Wed, 9 Oct 2019 17:27:07 +0000 (13:27 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Thu, 10 Oct 2019 19:47:07 +0000 (15:47 -0400)
so that drivers don't have to call nir_strip manually.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Rob Clark <robdclark@gmail.com>
src/compiler/nir/nir_serialize.c
src/compiler/nir/nir_serialize.h
src/gallium/drivers/iris/iris_program.c
src/gallium/drivers/radeonsi/si_shader_nir.c
src/gallium/drivers/radeonsi/si_state_shaders.c
src/intel/vulkan/anv_pipeline_cache.c
src/mesa/drivers/dri/i965/brw_program_binary.c
src/mesa/state_tracker/st_shader_cache.c

index 0a953c8..b7b44f6 100644 (file)
@@ -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);
index 528988f..e813f2c 100644 (file)
@@ -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);
index 886cdff..2670bc2 100644 (file)
@@ -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;
index 6c267bb..e97e5cc 100644 (file)
@@ -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,
index 04443db..b2071a2 100644 (file)
@@ -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;
        }
index 9c315d5..e1d48b8 100644 (file)
@@ -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;
index bf87534..a126f86 100644 (file)
@@ -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);
 }
 
index ae16023..a56e9fa 100644 (file)
@@ -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);
 }