nv50/ir: Add nv50_ir_prog_info serialize

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>
This commit is contained in:
Mark Menzynski 2020-01-28 13:11:31 +01:00 committed by Marge Bot
parent 3e99af66b4
commit 82dd683a3c
2 changed files with 43 additions and 0 deletions

View 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 *);

View 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)