nir: add a strip parameter to nir_serialize
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>
This commit is contained in:
parent
e6986bcb73
commit
dd4cc56ebd
|
@ -1090,8 +1090,20 @@ 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 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;
|
||||
|
@ -1145,6 +1157,9 @@ nir_serialize(struct blob *blob, const nir_shader *nir)
|
|||
|
||||
_mesa_hash_table_destroy(ctx.remap_table, NULL);
|
||||
util_dynarray_fini(&ctx.phi_fixups);
|
||||
|
||||
if (strip)
|
||||
ralloc_free(stripped);
|
||||
}
|
||||
|
||||
nir_shader *
|
||||
|
@ -1213,7 +1228,7 @@ nir_shader_serialize_deserialize(nir_shader *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);
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
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);
|
||||
|
|
|
@ -2019,22 +2019,15 @@ iris_create_uncompiled_shader(struct pipe_context *ctx,
|
|||
|
||||
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;
|
||||
|
|
|
@ -1004,11 +1004,6 @@ void si_lower_nir(struct si_shader_selector *sel)
|
|||
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,
|
||||
|
|
|
@ -59,7 +59,7 @@ void *si_get_ir_binary(struct si_shader_selector *sel, bool ngg, bool es)
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -779,7 +779,7 @@ anv_device_upload_nir(struct anv_device *device,
|
|||
struct blob blob;
|
||||
blob_init(&blob);
|
||||
|
||||
nir_serialize(&blob, nir);
|
||||
nir_serialize(&blob, nir, false);
|
||||
if (blob.out_of_memory) {
|
||||
blob_finish(&blob);
|
||||
return;
|
||||
|
|
|
@ -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, false);
|
||||
blob_overwrite_uint32(writer, size_offset, writer->size - nir_start);
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,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, false);
|
||||
copy_blob_to_driver_cache_blob(blob, prog);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue