aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorMark Janes <[email protected]>2019-11-20 14:05:41 -0800
committerMark Janes <[email protected]>2019-11-20 15:22:32 -0800
commitf1f19b6445f5dcb25aaef6baa140580889ab06b6 (patch)
tree96acafa6ac2ac4ba18c56292b2ea9713324da4ba /src/mesa
parent721d82cf061a11e158a19badaf7a8ad70e43ac2b (diff)
Revert "st/mesa: call nir_serialize only once per shader"
This reverts commit 3a8d6868897c7dfe72bac09c1eddd551144ca751. Acked-by: Marek Olšák <[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, 22 insertions, 25 deletions
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
@@ -2069,20 +2069,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)
{
struct st_program *stp = (struct st_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
@@ -353,9 +353,6 @@ 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 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);
}