so that drivers don't have to call nir_strip manually.
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Rob Clark <robdclark@gmail.com>
}
void
-nir_serialize(struct blob *blob, const nir_shader *nir)
+nir_serialize(struct blob *blob, const nir_shader *nir, bool strip)
{
+ nir_shader *stripped = NULL;
+
+ if (strip) {
+ /* Drop unnecessary information (like variable names), so the serialized
+ * NIR is smaller, and also to let us detect more isomorphic shaders
+ * when hashing, increasing cache hits.
+ */
+ stripped = nir_shader_clone(NULL, nir);
+ nir_strip(stripped);
+ nir = stripped;
+ }
+
write_ctx ctx;
ctx.remap_table = _mesa_pointer_hash_table_create(NULL);
ctx.next_idx = 0;
_mesa_hash_table_destroy(ctx.remap_table, NULL);
util_dynarray_fini(&ctx.phi_fixups);
+
+ if (strip)
+ ralloc_free(stripped);
}
nir_shader *
struct blob writer;
blob_init(&writer);
- nir_serialize(&writer, shader);
+ nir_serialize(&writer, shader, false);
/* Delete all of dest's ralloc children but leave dest alone */
void *dead_ctx = ralloc_context(NULL);
extern "C" {
#endif
-void nir_serialize(struct blob *blob, const nir_shader *nir);
+void nir_serialize(struct blob *blob, const nir_shader *nir, bool strip);
nir_shader *nir_deserialize(void *mem_ctx,
const struct nir_shader_compiler_options *options,
struct blob_reader *blob);
if (screen->disk_cache) {
/* Serialize the NIR to a binary blob that we can hash for the disk
- * cache. First, drop unnecessary information (like variable names)
+ * cache. Drop unnecessary information (like variable names)
* so the serialized NIR is smaller, and also to let us detect more
- * isomorphic shaders when hashing, increasing cache hits. We clone
- * the NIR before stripping away this info because it can be useful
- * when inspecting and debugging shaders.
+ * isomorphic shaders when hashing, increasing cache hits.
*/
- nir_shader *clone = nir_shader_clone(NULL, nir);
- nir_strip(clone);
-
struct blob blob;
blob_init(&blob);
- nir_serialize(&blob, clone);
+ nir_serialize(&blob, nir, true);
_mesa_sha1_compute(blob.data, blob.size, ish->nir_sha1);
blob_finish(&blob);
-
- ralloc_free(clone);
}
return ish;
si_nir_opts(sel->nir);
NIR_PASS_V(sel->nir, nir_lower_bool_to_int32);
-
- /* Strip the resulting shader so that the shader cache is more likely
- * to hit from other similar shaders.
- */
- nir_strip(sel->nir);
}
static void declare_nir_input_vs(struct si_shader_context *ctx,
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;
}
struct blob blob;
blob_init(&blob);
- nir_serialize(&blob, nir);
+ nir_serialize(&blob, nir, false);
if (blob.out_of_memory) {
blob_finish(&blob);
return;
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, false);
blob_overwrite_uint32(writer, size_offset, writer->size - nir_start);
}
static void
write_nir_to_cache(struct blob *blob, struct gl_program *prog)
{
- nir_serialize(blob, prog->nir);
+ nir_serialize(blob, prog->nir, false);
copy_blob_to_driver_cache_blob(blob, prog);
}