aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler/nir
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2019-11-04 22:15:17 -0500
committerMarek Olšák <[email protected]>2019-11-23 00:02:10 -0500
commit75f7c388637917d796fdf86c645a03c31621c1ca (patch)
treec41536fab5f36cfacfc7ac8d09f42983dac5f85c /src/compiler/nir
parenta572ba673b16e10576b45f9dd84638c0a22ce166 (diff)
nir/serialize: pack load_const with non-64-bit constants better
v2: use blob_write_uint8/16 Reviewed-by: Jason Ekstrand <[email protected]> (v1) Reviewed-by: Connor Abbott <[email protected]>
Diffstat (limited to 'src/compiler/nir')
-rw-r--r--src/compiler/nir/nir_serialize.c48
1 files changed, 46 insertions, 2 deletions
diff --git a/src/compiler/nir/nir_serialize.c b/src/compiler/nir/nir_serialize.c
index 0fa5499657b..354a11b501f 100644
--- a/src/compiler/nir/nir_serialize.c
+++ b/src/compiler/nir/nir_serialize.c
@@ -908,7 +908,30 @@ write_load_const(write_ctx *ctx, const nir_load_const_instr *lc)
header.load_const.bit_size = encode_bit_size_3bits(lc->def.bit_size);
blob_write_uint32(ctx->blob, header.u32);
- blob_write_bytes(ctx->blob, lc->value, sizeof(*lc->value) * lc->def.num_components);
+
+ switch (lc->def.bit_size) {
+ case 64:
+ blob_write_bytes(ctx->blob, lc->value,
+ sizeof(*lc->value) * lc->def.num_components);
+ break;
+
+ case 32:
+ for (unsigned i = 0; i < lc->def.num_components; i++)
+ blob_write_uint32(ctx->blob, lc->value[i].u32);
+ break;
+
+ case 16:
+ for (unsigned i = 0; i < lc->def.num_components; i++)
+ blob_write_uint16(ctx->blob, lc->value[i].u16);
+ break;
+
+ default:
+ assert(lc->def.bit_size <= 8);
+ for (unsigned i = 0; i < lc->def.num_components; i++)
+ blob_write_uint8(ctx->blob, lc->value[i].u8);
+ break;
+ }
+
write_add_object(ctx, &lc->def);
}
@@ -919,7 +942,28 @@ read_load_const(read_ctx *ctx, union packed_instr header)
nir_load_const_instr_create(ctx->nir, header.load_const.last_component + 1,
decode_bit_size_3bits(header.load_const.bit_size));
- blob_copy_bytes(ctx->blob, lc->value, sizeof(*lc->value) * lc->def.num_components);
+ switch (lc->def.bit_size) {
+ case 64:
+ blob_copy_bytes(ctx->blob, lc->value, sizeof(*lc->value) * lc->def.num_components);
+ break;
+
+ case 32:
+ for (unsigned i = 0; i < lc->def.num_components; i++)
+ lc->value[i].u32 = blob_read_uint32(ctx->blob);
+ break;
+
+ case 16:
+ for (unsigned i = 0; i < lc->def.num_components; i++)
+ lc->value[i].u16 = blob_read_uint16(ctx->blob);
+ break;
+
+ default:
+ assert(lc->def.bit_size <= 8);
+ for (unsigned i = 0; i < lc->def.num_components; i++)
+ lc->value[i].u8 = blob_read_uint8(ctx->blob);
+ break;
+ }
+
read_add_object(ctx, &lc->def);
return lc;
}