summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2019-11-07 19:24:57 -0500
committerMarek Olšák <[email protected]>2019-11-19 18:02:06 -0500
commit3a8d6868897c7dfe72bac09c1eddd551144ca751 (patch)
treea416b2e23d6005de22600da1f5461879db1d43c7 /src/mesa
parentdb0c89d4bffa01ab15dfa819dbb518739131e1a9 (diff)
st/mesa: call nir_serialize only once per shader
It was called twice. Acked-by: Pierre-Eric Pelloux-Prayer <[email protected]>
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/state_tracker/st_program.c23
-rw-r--r--src/mesa/state_tracker/st_program.h3
-rw-r--r--src/mesa/state_tracker/st_shader_cache.c21
3 files changed, 25 insertions, 22 deletions
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
@@ -2069,6 +2069,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)
{
struct st_program *stp = (struct st_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
@@ -353,6 +353,9 @@ 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);
#ifdef __cplusplus
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);
}