}
}
-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)
{
* 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);
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);
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);
}