nir: Replace an odd comparison involving fmin of -b2f
[mesa.git] / src / compiler / nir / nir_serialize.c
index bb6a5d86f29014808b5098ad0a6d525a3916f34d..00df49c2ef3a5df1cff4489e8b3ae1b6eb793721 100644 (file)
@@ -137,7 +137,8 @@ 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));
-   blob_write_string(ctx->blob, var->name);
+   if (var->name)
+      blob_write_string(ctx->blob, var->name);
    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,
@@ -585,7 +586,8 @@ union packed_tex_data {
       unsigned component:2;
       unsigned has_texture_deref:1;
       unsigned has_sampler_deref:1;
-   };
+      unsigned unused:10; /* Mark unused for valgrind. */
+   } u;
 };
 
 static void
@@ -599,15 +601,15 @@ write_tex(write_ctx *ctx, const nir_tex_instr *tex)
 
    STATIC_ASSERT(sizeof(union packed_tex_data) == sizeof(uint32_t));
    union packed_tex_data packed = {
-      .sampler_dim = tex->sampler_dim,
-      .dest_type = tex->dest_type,
-      .coord_components = tex->coord_components,
-      .is_array = tex->is_array,
-      .is_shadow = tex->is_shadow,
-      .is_new_style_shadow = tex->is_new_style_shadow,
-      .component = tex->component,
-      .has_texture_deref = tex->texture != NULL,
-      .has_sampler_deref = tex->sampler != NULL,
+      .u.sampler_dim = tex->sampler_dim,
+      .u.dest_type = tex->dest_type,
+      .u.coord_components = tex->coord_components,
+      .u.is_array = tex->is_array,
+      .u.is_shadow = tex->is_shadow,
+      .u.is_new_style_shadow = tex->is_new_style_shadow,
+      .u.component = tex->component,
+      .u.has_texture_deref = tex->texture != NULL,
+      .u.has_sampler_deref = tex->sampler != NULL,
    };
    blob_write_uint32(ctx->blob, packed.u32);
 
@@ -636,13 +638,13 @@ read_tex(read_ctx *ctx)
 
    union packed_tex_data packed;
    packed.u32 = blob_read_uint32(ctx->blob);
-   tex->sampler_dim = packed.sampler_dim;
-   tex->dest_type = packed.dest_type;
-   tex->coord_components = packed.coord_components;
-   tex->is_array = packed.is_array;
-   tex->is_shadow = packed.is_shadow;
-   tex->is_new_style_shadow = packed.is_new_style_shadow;
-   tex->component = packed.component;
+   tex->sampler_dim = packed.u.sampler_dim;
+   tex->dest_type = packed.u.dest_type;
+   tex->coord_components = packed.u.coord_components;
+   tex->is_array = packed.u.is_array;
+   tex->is_shadow = packed.u.is_shadow;
+   tex->is_new_style_shadow = packed.u.is_new_style_shadow;
+   tex->component = packed.u.component;
 
    read_dest(ctx, &tex->dest, &tex->instr);
    for (unsigned i = 0; i < tex->num_srcs; i++) {
@@ -650,9 +652,9 @@ read_tex(read_ctx *ctx)
       read_src(ctx, &tex->src[i].src, &tex->instr);
    }
 
-   tex->texture = packed.has_texture_deref ?
+   tex->texture = packed.u.has_texture_deref ?
                   read_deref_chain(ctx, &tex->instr) : NULL;
-   tex->sampler = packed.has_sampler_deref ?
+   tex->sampler = packed.u.has_sampler_deref ?
                   read_deref_chain(ctx, &tex->instr) : NULL;
 
    return tex;
@@ -1199,3 +1201,22 @@ 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_init(&writer);
+   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_finish(&writer);
+
+   return ns;
+}