[Mesa-dev] [PATCH v3 5/8] nv50/ir: Add nv50_ir_prog_info serialize

Mark Menzynski mmenzyns at redhat.com
Fri Mar 27 15:33:21 UTC 2020


Adds a function for serializing a nv50_ir_prog_info structure, which is
needed for shader caching.

Signed-off-by: Mark Menzynski <mmenzyns at redhat.com>
---
 .../drivers/nouveau/codegen/nv50_ir_driver.h  |  4 ++
 .../nouveau/codegen/nv50_ir_serialize.cpp     | 42 +++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_driver.h b/src/gallium/drivers/nouveau/codegen/nv50_ir_driver.h
index 1bfaa8483ca..d33c6b6b83c 100644
--- a/src/gallium/drivers/nouveau/codegen/nv50_ir_driver.h
+++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_driver.h
@@ -278,6 +278,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 *);
diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_serialize.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_serialize.cpp
index 52ceb66947f..e9d1d0b3215 100644
--- a/src/gallium/drivers/nouveau/codegen/nv50_ir_serialize.cpp
+++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_serialize.cpp
@@ -16,6 +16,48 @@ enum FixupApplyFunc {
    FLIP_GM107
 };
 
+extern bool
+nv50_ir_prog_info_serialize(struct blob *blob, struct nv50_ir_prog_info *info)
+{
+   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_uint32(blob, info->bin.smemSize);
+   blob_write_uint16(blob, info->bin.maxOutput);
+   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, false);
+         break;
+      }
+      default:
+         assert(!"unhandled info->bin.sourceRep switch case");
+         return false;
+   }
+
+   blob_write_uint16(blob, info->immd.bufSize);
+   blob_write_bytes(blob, info->immd.buf, info->immd.bufSize * sizeof(*info->immd.buf));
+   blob_write_uint16(blob, info->immd.count);
+   blob_write_bytes(blob, info->immd.data, info->immd.count * sizeof(*info->immd.data));
+   blob_write_bytes(blob, info->immd.type, info->immd.count * 16); // for each vec4 (128 bit)
+   blob_write_bytes(blob, &info->prop, sizeof(info->prop));
+   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)
-- 
2.24.1



More information about the mesa-dev mailing list