From: Marek Olšák Date: Fri, 8 Nov 2019 00:24:57 +0000 (-0500) Subject: st/mesa: call nir_serialize only once per shader X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3a8d6868897c7dfe72bac09c1eddd551144ca751;p=mesa.git st/mesa: call nir_serialize only once per shader It was called twice. Acked-by: Pierre-Eric Pelloux-Prayer --- diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 5b0cc4a6a36..f842b6b5d44 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -2068,6 +2068,20 @@ 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) { @@ -2092,14 +2106,7 @@ st_finalize_program(struct st_context *st, struct gl_program *prog) * to save memory. */ if (prog->nir) { - /* 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); + st_serialize_nir(stp); /* 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 cb085d18bd7..eb6eff46471 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -352,6 +352,9 @@ 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 474ab4e1a0e..2d630c65aea 100644 --- a/src/mesa/state_tracker/st_shader_cache.c +++ b/src/mesa/state_tracker/st_shader_cache.c @@ -70,20 +70,13 @@ 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) { - 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); - } + 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); + copy_blob_to_driver_cache_blob(blob, prog); }