[Mesa-dev] [PATCH] nir/serialize: Make preserving names optional

apinheiro apinheiro at igalia.com
Fri Mar 8 11:00:53 UTC 2019


Reviewed-by: Alejandro PiƱeiro <apinheiro at igalia.com>

Out of curiosity: right now it is always used as true (so maintain 
current behaviour). How it is intended to be used? With an envvar?

On 7/3/19 22:38, Jason Ekstrand wrote:
> ---
>   src/compiler/nir/nir_serialize.c              | 56 ++++++++++++-------
>   src/compiler/nir/nir_serialize.h              |  3 +-
>   .../drivers/radeonsi/si_state_shaders.c       |  2 +-
>   src/intel/vulkan/anv_pipeline_cache.c         |  2 +-
>   .../drivers/dri/i965/brw_program_binary.c     |  2 +-
>   src/mesa/state_tracker/st_shader_cache.c      |  2 +-
>   6 files changed, 42 insertions(+), 25 deletions(-)
>
> diff --git a/src/compiler/nir/nir_serialize.c b/src/compiler/nir/nir_serialize.c
> index 743eeaed3d5..ad094beb1f4 100644
> --- a/src/compiler/nir/nir_serialize.c
> +++ b/src/compiler/nir/nir_serialize.c
> @@ -42,6 +42,9 @@ typedef struct {
>      /* the next index to assign to a NIR in-memory object */
>      uintptr_t next_idx;
>   
> +   /* Whether or not to preserve variable and SSA def names */
> +   bool preserve_names;
> +
>      /* Array of write_phi_fixup structs representing phi sources that need to
>       * be resolved in the second pass.
>       */
> @@ -136,9 +139,13 @@ write_variable(write_ctx *ctx, const nir_variable *var)
>   {
>      write_add_object(ctx, var);
>      encode_type_to_blob(ctx->blob, var->type);
> -   blob_write_uint32(ctx->blob, !!(var->name));
> -   if (var->name)
> -      blob_write_string(ctx->blob, var->name);
> +   if (ctx->preserve_names) {
> +      blob_write_uint32(ctx->blob, !!(var->name));
> +      if (var->name)
> +         blob_write_string(ctx->blob, var->name);
> +   } else {
> +      blob_write_uint32(ctx->blob, 0);
> +   }
>      blob_write_bytes(ctx->blob, (uint8_t *) &var->data, sizeof(var->data));
>      blob_write_uint32(ctx->blob, var->num_state_slots);
>      blob_write_bytes(ctx->blob, (uint8_t *) var->state_slots,
> @@ -224,9 +231,13 @@ write_register(write_ctx *ctx, const nir_register *reg)
>      blob_write_uint32(ctx->blob, reg->bit_size);
>      blob_write_uint32(ctx->blob, reg->num_array_elems);
>      blob_write_uint32(ctx->blob, reg->index);
> -   blob_write_uint32(ctx->blob, !!(reg->name));
> -   if (reg->name)
> -      blob_write_string(ctx->blob, reg->name);
> +   if (ctx->preserve_names) {
> +      blob_write_uint32(ctx->blob, !!(reg->name));
> +      if (reg->name)
> +         blob_write_string(ctx->blob, reg->name);
> +   } else {
> +      blob_write_uint32(ctx->blob, 0);
> +   }
>      blob_write_uint32(ctx->blob, reg->is_global << 1 | reg->is_packed);
>   }
>   
> @@ -327,7 +338,7 @@ write_dest(write_ctx *ctx, const nir_dest *dst)
>   {
>      uint32_t val = dst->is_ssa;
>      if (dst->is_ssa) {
> -      val |= !!(dst->ssa.name) << 1;
> +      val |= (ctx->preserve_names && dst->ssa.name) << 1;
>         val |= dst->ssa.num_components << 2;
>         val |= dst->ssa.bit_size << 5;
>      } else {
> @@ -336,7 +347,7 @@ write_dest(write_ctx *ctx, const nir_dest *dst)
>      blob_write_uint32(ctx->blob, val);
>      if (dst->is_ssa) {
>         write_add_object(ctx, &dst->ssa);
> -      if (dst->ssa.name)
> +      if (ctx->preserve_names && dst->ssa.name)
>            blob_write_string(ctx->blob, dst->ssa.name);
>      } else {
>         blob_write_intptr(ctx->blob, write_lookup_object(ctx, dst->reg.reg));
> @@ -1079,28 +1090,33 @@ 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 preserve_names)
>   {
>      write_ctx ctx;
>      ctx.remap_table = _mesa_pointer_hash_table_create(NULL);
>      ctx.next_idx = 0;
>      ctx.blob = blob;
>      ctx.nir = nir;
> +   ctx.preserve_names = preserve_names;
>      util_dynarray_init(&ctx.phi_fixups, NULL);
>   
>      size_t idx_size_offset = blob_reserve_intptr(blob);
>   
>      struct shader_info info = nir->info;
> -   uint32_t strings = 0;
> -   if (info.name)
> -      strings |= 0x1;
> -   if (info.label)
> -      strings |= 0x2;
> -   blob_write_uint32(blob, strings);
> -   if (info.name)
> -      blob_write_string(blob, info.name);
> -   if (info.label)
> -      blob_write_string(blob, info.label);
> +   if (ctx.preserve_names) {
> +      uint32_t strings = 0;
> +      if (info.name)
> +         strings |= 0x1;
> +      if (info.label)
> +         strings |= 0x2;
> +      blob_write_uint32(blob, strings);
> +      if (info.name)
> +         blob_write_string(blob, info.name);
> +      if (info.label)
> +         blob_write_string(blob, info.label);
> +   } else {
> +      blob_write_uint32(blob, 0);
> +   }
>      info.name = info.label = NULL;
>      blob_write_bytes(blob, (uint8_t *) &info, sizeof(info));
>   
> @@ -1204,7 +1220,7 @@ nir_shader_serialize_deserialize(void *mem_ctx, nir_shader *s)
>   
>      struct blob writer;
>      blob_init(&writer);
> -   nir_serialize(&writer, s);
> +   nir_serialize(&writer, s, true);
>      ralloc_free(s);
>   
>      struct blob_reader reader;
> diff --git a/src/compiler/nir/nir_serialize.h b/src/compiler/nir/nir_serialize.h
> index f77d8e367ff..22e5fa88ee1 100644
> --- a/src/compiler/nir/nir_serialize.h
> +++ b/src/compiler/nir/nir_serialize.h
> @@ -31,7 +31,8 @@
>   extern "C" {
>   #endif
>   
> -void nir_serialize(struct blob *blob, const nir_shader *nir);
> +void nir_serialize(struct blob *blob, const nir_shader *nir, bool
> +                   preserve_names);
>   nir_shader *nir_deserialize(void *mem_ctx,
>                               const struct nir_shader_compiler_options *options,
>                               struct blob_reader *blob);
> diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c b/src/gallium/drivers/radeonsi/si_state_shaders.c
> index 5bdfd4f6ac1..9b8af3d9ffd 100644
> --- a/src/gallium/drivers/radeonsi/si_state_shaders.c
> +++ b/src/gallium/drivers/radeonsi/si_state_shaders.c
> @@ -58,7 +58,7 @@ void *si_get_ir_binary(struct si_shader_selector *sel)
>   		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;
>   	}
> diff --git a/src/intel/vulkan/anv_pipeline_cache.c b/src/intel/vulkan/anv_pipeline_cache.c
> index ecdd4da73ca..17745438114 100644
> --- a/src/intel/vulkan/anv_pipeline_cache.c
> +++ b/src/intel/vulkan/anv_pipeline_cache.c
> @@ -753,7 +753,7 @@ anv_device_upload_nir(struct anv_device *device,
>         struct blob blob;
>         blob_init(&blob);
>   
> -      nir_serialize(&blob, nir);
> +      nir_serialize(&blob, nir, true);
>         if (blob.out_of_memory) {
>            blob_finish(&blob);
>            return;
> diff --git a/src/mesa/drivers/dri/i965/brw_program_binary.c b/src/mesa/drivers/dri/i965/brw_program_binary.c
> index 1298d9e765e..0538707fbb9 100644
> --- a/src/mesa/drivers/dri/i965/brw_program_binary.c
> +++ b/src/mesa/drivers/dri/i965/brw_program_binary.c
> @@ -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, true);
>      blob_overwrite_uint32(writer, size_offset, writer->size - nir_start);
>   }
>   
> diff --git a/src/mesa/state_tracker/st_shader_cache.c b/src/mesa/state_tracker/st_shader_cache.c
> index c82ce3eaa2d..a436b695a6c 100644
> --- a/src/mesa/state_tracker/st_shader_cache.c
> +++ b/src/mesa/state_tracker/st_shader_cache.c
> @@ -66,7 +66,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, true);
>      copy_blob_to_driver_cache_blob(blob, prog);
>   }
>   


More information about the mesa-dev mailing list