[Mesa-dev] [PATCH 8/8] nir: Add hooks for testing serialization

Jason Ekstrand jason at jlekstrand.net
Sat Sep 16 01:41:20 UTC 2017


On Fri, Sep 15, 2017 at 6:39 PM, Jason Ekstrand <jason at jlekstrand.net>
wrote:

> ---
>  src/compiler/nir/nir.h           | 17 +++++++++++++++++
>  src/compiler/nir/nir_serialize.c | 18 ++++++++++++++++++
>  2 files changed, 35 insertions(+)
>
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index e6104fc..57cd0d9 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -2298,6 +2298,8 @@ nir_variable *nir_variable_clone(const nir_variable
> *c, nir_shader *shader);
>  nir_deref *nir_deref_clone(const nir_deref *deref, void *mem_ctx);
>  nir_deref_var *nir_deref_var_clone(const nir_deref_var *deref, void
> *mem_ctx);
>
> +nir_shader *nir_shader_serialize_deserialize(void *mem_ctx, nir_shader
> *s);
> +
>  #ifdef DEBUG
>  void nir_validate_shader(nir_shader *shader);
>  void nir_metadata_set_validation_flag(nir_shader *shader);
> @@ -2314,6 +2316,16 @@ should_clone_nir(void)
>  }
>
>  static inline bool
> +should_serialize_deserialize_nir(void)
> +{
> +   static int test_serialize = -1;
> +   if (test_serialize < 0)
> +      test_serialize = env_var_as_boolean("NIR_TEST_SERIALIZE", true);
>

This should default to false, of course.  Fixed locally.


> +
> +   return test_serialize;
> +}
> +
> +static inline bool
>  should_print_nir(void)
>  {
>     static int should_print = -1;
> @@ -2327,6 +2339,7 @@ static inline void nir_validate_shader(nir_shader
> *shader) { (void) shader; }
>  static inline void nir_metadata_set_validation_flag(nir_shader *shader)
> { (void) shader; }
>  static inline void nir_metadata_check_validation_flag(nir_shader
> *shader) { (void) shader; }
>  static inline bool should_clone_nir(void) { return false; }
> +static inline bool should_serialize_deserialize_nir(void) { return
> false; }
>  static inline bool should_print_nir(void) { return false; }
>  #endif /* DEBUG */
>
> @@ -2338,6 +2351,10 @@ static inline bool should_print_nir(void) { return
> false; }
>        ralloc_free(nir);                                              \
>        nir = clone;                                                   \
>     }                                                                 \
> +   if (should_serialize_deserialize_nir()) {                         \
> +      void *mem_ctx = ralloc_parent(nir);                            \
> +      nir = nir_shader_serialize_deserialize(mem_ctx, nir);          \
> +   }                                                                 \
>  } while (0)
>
>  #define NIR_PASS(progress, nir, pass, ...) _PASS(nir,                \
> diff --git a/src/compiler/nir/nir_serialize.c b/src/compiler/nir/nir_
> serialize.c
> index 6091ce3..60c8f61 100644
> --- a/src/compiler/nir/nir_serialize.c
> +++ b/src/compiler/nir/nir_serialize.c
> @@ -1193,3 +1193,21 @@ nir_deserialize(void *mem_ctx,
>
>     return ctx.nir;
>  }
> +
> +nir_shader *
> +nir_shader_serialize_deserialize(void *mem_ctx, nir_shader *s)
> +{
> +   const struct nir_shader_compiler_options *options = s->options;
> +
> +   struct blob *writer = blob_create();
> +   nir_serialize(writer, s);
> +   ralloc_free(s);
> +
> +   struct blob_reader reader;
> +   blob_reader_init(&reader, writer->data, writer->size);
> +   nir_shader *ns = nir_deserialize(mem_ctx, options, &reader);
> +
> +   blob_destroy(writer);
> +
> +   return ns;
> +}
> --
> 2.5.0.400.gff86faf
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170915/ee8918c6/attachment.html>


More information about the mesa-dev mailing list