From: Mark Janes Date: Wed, 20 Nov 2019 22:05:41 +0000 (-0800) Subject: Revert "st/mesa: call nir_serialize only once per shader" X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f1f19b6445f5dcb25aaef6baa140580889ab06b6;p=mesa.git Revert "st/mesa: call nir_serialize only once per shader" This reverts commit 3a8d6868897c7dfe72bac09c1eddd551144ca751. Acked-by: Marek Olšák --- diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index f842b6b5d44..5b0cc4a6a36 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -2068,20 +2068,6 @@ st_precompile_shader_variant(struct st_context *st, } } -void -st_serialize_nir(struct st_program *stp) -{ - if (!stp->nir_binary) { - struct blob blob; - size_t size; - - blob_init(&blob); - nir_serialize(&blob, stp->Base.nir, false); - blob_finish_get_buffer(&blob, &stp->nir_binary, &size); - stp->nir_size = size; - } -} - void st_finalize_program(struct st_context *st, struct gl_program *prog) { @@ -2106,7 +2092,14 @@ st_finalize_program(struct st_context *st, struct gl_program *prog) * to save memory. */ if (prog->nir) { - st_serialize_nir(stp); + /* Serialize NIR. */ + struct blob blob; + blob_init(&blob); + nir_serialize(&blob, prog->nir, false); + stp->nir_binary = malloc(blob.size); + memcpy(stp->nir_binary, blob.data, blob.size); + stp->nir_size = blob.size; + blob_finish(&blob); /* Free NIR. */ assert(stp->state.ir.nir == prog->nir); diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index eb6eff46471..cb085d18bd7 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -352,9 +352,6 @@ extern bool st_translate_common_program(struct st_context *st, struct st_program *stp); -extern void -st_serialize_nir(struct st_program *stp); - extern void st_finalize_program(struct st_context *st, struct gl_program *prog); diff --git a/src/mesa/state_tracker/st_shader_cache.c b/src/mesa/state_tracker/st_shader_cache.c index 2d630c65aea..474ab4e1a0e 100644 --- a/src/mesa/state_tracker/st_shader_cache.c +++ b/src/mesa/state_tracker/st_shader_cache.c @@ -70,13 +70,20 @@ 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) { - struct st_program *stp = (struct st_program *)prog; - - st_serialize_nir(stp); - - blob_write_intptr(blob, stp->nir_size); - blob_write_bytes(blob, stp->nir_binary, stp->nir_size); - + if (prog->nir) { + /* Reserve intptr_t to store the size. intptr_t is also the alignment + * of NIR in the blob, so the NIR size computation will be trivial. + */ + size_t offset = blob_reserve_intptr(blob); + nir_serialize(blob, prog->nir, false); + + unsigned nir_size = blob->size - offset - sizeof(intptr_t); + *(uintptr_t *)(blob->data + offset) = nir_size; + } else { + struct st_program *stp = (struct st_program *)prog; + blob_write_intptr(blob, stp->nir_size); + blob_write_bytes(blob, stp->nir_binary, stp->nir_size); + } copy_blob_to_driver_cache_blob(blob, prog); }