From 1468a4f1f3a2e4c98c5d857a636233c356922807 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 19 Nov 2019 08:19:34 +1000 Subject: [PATCH] nir/serialize: fix serializing functions with no implementations. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Store a flag stating if there was an implmentation, and use fxn->impl as a temporary flag between deserializsation stages. Reviewed-by: Marek Olšák Reviewed-by: Karol Herbst Reviewed-by: Jason Ekstrand --- src/compiler/nir/nir_serialize.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/compiler/nir/nir_serialize.c b/src/compiler/nir/nir_serialize.c index 5df498405d0..18398545220 100644 --- a/src/compiler/nir/nir_serialize.c +++ b/src/compiler/nir/nir_serialize.c @@ -25,6 +25,7 @@ #include "nir_control_flow.h" #include "util/u_dynarray.h" +#define NIR_SERIALIZE_FUNC_HAS_IMPL ((void *)(intptr_t)1) #define MAX_OBJECT_IDS (1 << 30) typedef struct { @@ -1072,6 +1073,8 @@ write_function(write_ctx *ctx, const nir_function *fxn) uint32_t flags = fxn->is_entrypoint; if (fxn->name) flags |= 0x2; + if (fxn->impl) + flags |= 0x4; blob_write_uint32(ctx->blob, flags); if (fxn->name) blob_write_string(ctx->blob, fxn->name); @@ -1113,6 +1116,8 @@ read_function(read_ctx *ctx) } fxn->is_entrypoint = flags & 0x1; + if (flags & 0x4) + fxn->impl = NIR_SERIALIZE_FUNC_HAS_IMPL; } void @@ -1172,7 +1177,8 @@ nir_serialize(struct blob *blob, const nir_shader *nir, bool strip) } nir_foreach_function(fxn, nir) { - write_function_impl(&ctx, fxn->impl); + if (fxn->impl) + write_function_impl(&ctx, fxn->impl); } blob_write_uint32(blob, nir->constant_data_size); @@ -1231,8 +1237,10 @@ nir_deserialize(void *mem_ctx, for (unsigned i = 0; i < num_functions; i++) read_function(&ctx); - nir_foreach_function(fxn, ctx.nir) - fxn->impl = read_function_impl(&ctx, fxn); + nir_foreach_function(fxn, ctx.nir) { + if (fxn->impl == NIR_SERIALIZE_FUNC_HAS_IMPL) + fxn->impl = read_function_impl(&ctx, fxn); + } ctx.nir->constant_data_size = blob_read_uint32(blob); if (ctx.nir->constant_data_size > 0) { -- 2.30.2