From c90f221e0a1f89332189dd5ec79dccf6b251ecf5 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Thu, 28 Jun 2018 19:16:19 -0700 Subject: nir: Add a concept of constant data associated with a shader This commit adds a concept to NIR of having a blob of constant data associated with a shader. Instead of being a UBO or uniform that can be manipulated by the client, this constant data considered part of the shader and remains constant across all invocations of the given shader until the end of time. To access this constant data from the shader, we add a new load_constant intrinsic. The intention is that drivers will eventually lower load_constant intrinsics to load_ubo, load_uniform, or something similar. Constant data will be used by the optimization pass in the next commit but this concept may also be useful for OpenCL. v2 (Jason Ekstrand): - Rename num_constants to constant_data_size (anholt) Reviewed-by: Timothy Arceri Reviewed-by: Iago Toral Quiroga Reviewed-by: Kenneth Graunke --- src/compiler/nir/nir_serialize.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/compiler/nir/nir_serialize.c') diff --git a/src/compiler/nir/nir_serialize.c b/src/compiler/nir/nir_serialize.c index cc4bf23aa0f..6a30738c2d7 100644 --- a/src/compiler/nir/nir_serialize.c +++ b/src/compiler/nir/nir_serialize.c @@ -1116,6 +1116,10 @@ nir_serialize(struct blob *blob, const nir_shader *nir) write_function_impl(&ctx, fxn->impl); } + blob_write_uint32(blob, nir->constant_data_size); + if (nir->constant_data_size > 0) + blob_write_bytes(blob, nir->constant_data, nir->constant_data_size); + *(uintptr_t *)(blob->data + idx_size_offset) = ctx.next_idx; _mesa_hash_table_destroy(ctx.remap_table, NULL); @@ -1169,6 +1173,14 @@ nir_deserialize(void *mem_ctx, nir_foreach_function(fxn, ctx.nir) fxn->impl = read_function_impl(&ctx, fxn); + ctx.nir->constant_data_size = blob_read_uint32(blob); + if (ctx.nir->constant_data_size > 0) { + ctx.nir->constant_data = + ralloc_size(ctx.nir, ctx.nir->constant_data_size); + blob_copy_bytes(blob, ctx.nir->constant_data, + ctx.nir->constant_data_size); + } + free(ctx.idx_table); return ctx.nir; -- cgit v1.2.3