<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Sep 15, 2017 at 6:39 PM, Jason Ekstrand <span dir="ltr"><<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">---<br>
src/compiler/nir/nir.h | 17 +++++++++++++++++<br>
src/compiler/nir/nir_<wbr>serialize.c | 18 ++++++++++++++++++<br>
2 files changed, 35 insertions(+)<br>
<br>
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h<br>
index e6104fc..57cd0d9 100644<br>
--- a/src/compiler/nir/nir.h<br>
+++ b/src/compiler/nir/nir.h<br>
@@ -2298,6 +2298,8 @@ nir_variable *nir_variable_clone(const nir_variable *c, nir_shader *shader);<br>
nir_deref *nir_deref_clone(const nir_deref *deref, void *mem_ctx);<br>
nir_deref_var *nir_deref_var_clone(const nir_deref_var *deref, void *mem_ctx);<br>
<br>
+nir_shader *nir_shader_serialize_<wbr>deserialize(void *mem_ctx, nir_shader *s);<br>
+<br>
#ifdef DEBUG<br>
void nir_validate_shader(nir_shader *shader);<br>
void nir_metadata_set_validation_<wbr>flag(nir_shader *shader);<br>
@@ -2314,6 +2316,16 @@ should_clone_nir(void)<br>
}<br>
<br>
static inline bool<br>
+should_serialize_deserialize_<wbr>nir(void)<br>
+{<br>
+ static int test_serialize = -1;<br>
+ if (test_serialize < 0)<br>
+ test_serialize = env_var_as_boolean("NIR_TEST_<wbr>SERIALIZE", true);<br></blockquote><div><br></div><div>This should default to false, of course. Fixed locally.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+ return test_serialize;<br>
+}<br>
+<br>
+static inline bool<br>
should_print_nir(void)<br>
{<br>
static int should_print = -1;<br>
@@ -2327,6 +2339,7 @@ static inline void nir_validate_shader(nir_shader *shader) { (void) shader; }<br>
static inline void nir_metadata_set_validation_<wbr>flag(nir_shader *shader) { (void) shader; }<br>
static inline void nir_metadata_check_validation_<wbr>flag(nir_shader *shader) { (void) shader; }<br>
static inline bool should_clone_nir(void) { return false; }<br>
+static inline bool should_serialize_deserialize_<wbr>nir(void) { return false; }<br>
static inline bool should_print_nir(void) { return false; }<br>
#endif /* DEBUG */<br>
<br>
@@ -2338,6 +2351,10 @@ static inline bool should_print_nir(void) { return false; }<br>
ralloc_free(nir); \<br>
nir = clone; \<br>
} \<br>
+ if (should_serialize_deserialize_<wbr>nir()) { \<br>
+ void *mem_ctx = ralloc_parent(nir); \<br>
+ nir = nir_shader_serialize_<wbr>deserialize(mem_ctx, nir); \<br>
+ } \<br>
} while (0)<br>
<br>
#define NIR_PASS(progress, nir, pass, ...) _PASS(nir, \<br>
diff --git a/src/compiler/nir/nir_<wbr>serialize.c b/src/compiler/nir/nir_<wbr>serialize.c<br>
index 6091ce3..60c8f61 100644<br>
--- a/src/compiler/nir/nir_<wbr>serialize.c<br>
+++ b/src/compiler/nir/nir_<wbr>serialize.c<br>
@@ -1193,3 +1193,21 @@ nir_deserialize(void *mem_ctx,<br>
<br>
return ctx.nir;<br>
}<br>
+<br>
+nir_shader *<br>
+nir_shader_serialize_<wbr>deserialize(void *mem_ctx, nir_shader *s)<br>
+{<br>
+ const struct nir_shader_compiler_options *options = s->options;<br>
+<br>
+ struct blob *writer = blob_create();<br>
+ nir_serialize(writer, s);<br>
+ ralloc_free(s);<br>
+<br>
+ struct blob_reader reader;<br>
+ blob_reader_init(&reader, writer->data, writer->size);<br>
+ nir_shader *ns = nir_deserialize(mem_ctx, options, &reader);<br>
+<br>
+ blob_destroy(writer);<br>
+<br>
+ return ns;<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.5.0.400.gff86faf<br>
<br>
</font></span></blockquote></div><br></div></div>