Mesa (master): nir: Don't replace the nir_shader when NIR_TEST_SERIALIZE=1

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jun 5 20:07:40 UTC 2019


Module: Mesa
Branch: master
Commit: fe2fc30cb559f7ef99c07bd219c057b011242cb4
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=fe2fc30cb559f7ef99c07bd219c057b011242cb4

Author: Jason Ekstrand <jason at jlekstrand.net>
Date:   Tue Jun  4 17:50:22 2019 -0500

nir: Don't replace the nir_shader when NIR_TEST_SERIALIZE=1

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=108957
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Rob Clark <robdclark at chromium.org>

---

 src/compiler/nir/nir.h           |  5 ++---
 src/compiler/nir/nir_serialize.c | 21 ++++++++++++++-------
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 12be397ff19..7930e164acb 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2920,7 +2920,7 @@ nir_variable *nir_variable_clone(const nir_variable *c, nir_shader *shader);
 
 void nir_shader_replace(nir_shader *dest, nir_shader *src);
 
-nir_shader *nir_shader_serialize_deserialize(void *mem_ctx, nir_shader *s);
+void nir_shader_serialize_deserialize(nir_shader *s);
 
 #ifndef NDEBUG
 void nir_validate_shader(nir_shader *shader, const char *when);
@@ -2995,8 +2995,7 @@ static inline bool should_print_nir(void) { return false; }
       nir_shader_replace(nir, clone);                                \
    }                                                                 \
    if (should_serialize_deserialize_nir()) {                         \
-      void *mem_ctx = ralloc_parent(nir);                            \
-      nir = nir_shader_serialize_deserialize(mem_ctx, nir);          \
+      nir_shader_serialize_deserialize(nir);                         \
    }                                                                 \
 } while (0)
 
diff --git a/src/compiler/nir/nir_serialize.c b/src/compiler/nir/nir_serialize.c
index e9e84bf8aaa..43a39ac1a5a 100644
--- a/src/compiler/nir/nir_serialize.c
+++ b/src/compiler/nir/nir_serialize.c
@@ -1202,21 +1202,28 @@ nir_deserialize(void *mem_ctx,
    return ctx.nir;
 }
 
-nir_shader *
-nir_shader_serialize_deserialize(void *mem_ctx, nir_shader *s)
+void
+nir_shader_serialize_deserialize(nir_shader *shader)
 {
-   const struct nir_shader_compiler_options *options = s->options;
+   const struct nir_shader_compiler_options *options = shader->options;
 
    struct blob writer;
    blob_init(&writer);
-   nir_serialize(&writer, s);
-   ralloc_free(s);
+   nir_serialize(&writer, shader);
+
+   /* Delete all of dest's ralloc children but leave dest alone */
+   void *dead_ctx = ralloc_context(NULL);
+   ralloc_adopt(dead_ctx, shader);
+   ralloc_free(dead_ctx);
+
+   dead_ctx = ralloc_context(NULL);
 
    struct blob_reader reader;
    blob_reader_init(&reader, writer.data, writer.size);
-   nir_shader *ns = nir_deserialize(mem_ctx, options, &reader);
+   nir_shader *copy = nir_deserialize(dead_ctx, options, &reader);
 
    blob_finish(&writer);
 
-   return ns;
+   nir_shader_replace(shader, copy);
+   ralloc_free(dead_ctx);
 }




More information about the mesa-commit mailing list