nv50/ir: Add nv50_ir_prog_info serialize
authorMark Menzynski <mmenzyns@redhat.com>
Tue, 28 Jan 2020 12:11:31 +0000 (13:11 +0100)
committerMarge Bot <eric+marge@anholt.net>
Tue, 25 Aug 2020 18:56:37 +0000 (18:56 +0000)
Adds a function for serializing a nv50_ir_prog_info structure, which is
needed for shader caching.

v2 (Karol): strip nir when serializing

Signed-off-by: Mark Menzynski <mmenzyns@redhat.com>
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4264>

src/gallium/drivers/nouveau/codegen/nv50_ir_driver.h
src/gallium/drivers/nouveau/codegen/nv50_ir_serialize.cpp

index 2b8ffb5cd0bffa8fa3f8842a7dfe92c75292aa94..c36e990735d81eec914d2108bcc4059162630fed 100644 (file)
@@ -270,6 +270,10 @@ namespace nv50_ir
 extern void
 nv50_ir_prog_info_out_print(struct nv50_ir_prog_info_out *);
 
+/* Serialize a nv50_ir_prog_info structure and save it into blob */
+extern bool
+nv50_ir_prog_info_serialize(struct blob *, struct nv50_ir_prog_info *);
+
 /* Serialize a nv50_ir_prog_info_out structure and save it into blob */
 extern bool MUST_CHECK
 nv50_ir_prog_info_out_serialize(struct blob *, struct nv50_ir_prog_info_out *);
index 41f151ac28397a0f43892d4c1c8fcedee9dd634b..682a2014a749283acccf85882601c9ec01574ee4 100644 (file)
@@ -18,6 +18,45 @@ enum FixupApplyFunc {
    FLIP_GV100,
 };
 
+extern bool
+nv50_ir_prog_info_serialize(struct blob *blob, struct nv50_ir_prog_info *info)
+{
+   blob_write_uint32(blob, info->bin.smemSize);
+   blob_write_uint16(blob, info->target);
+   blob_write_uint8(blob, info->type);
+   blob_write_uint8(blob, info->optLevel);
+   blob_write_uint8(blob, info->dbgFlags);
+   blob_write_uint8(blob, info->omitLineNum);
+   blob_write_uint8(blob, info->bin.sourceRep);
+
+   switch(info->bin.sourceRep) {
+      case PIPE_SHADER_IR_TGSI: {
+         struct tgsi_token *tokens = (struct tgsi_token *)info->bin.source;
+         unsigned int num_tokens = tgsi_num_tokens(tokens);
+
+         blob_write_uint32(blob, num_tokens);
+         blob_write_bytes(blob, tokens, num_tokens * sizeof(struct tgsi_token));
+         break;
+      }
+      case PIPE_SHADER_IR_NIR: {
+         struct nir_shader *nir = (struct nir_shader *)info->bin.source;
+         nir_serialize(blob, nir, true);
+         break;
+      }
+      default:
+         ERROR("unhandled info->bin.sourceRep switch case\n");
+         assert(false);
+         return false;
+   }
+
+   if (info->type == PIPE_SHADER_COMPUTE)
+      blob_write_bytes(blob, &info->prop.cp, sizeof(info->prop.cp));
+
+   blob_write_bytes(blob, &info->io, sizeof(info->io));
+
+   return true;
+}
+
 extern bool
 nv50_ir_prog_info_out_serialize(struct blob *blob,
                                 struct nv50_ir_prog_info_out *info_out)