diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp index 5e47477c8d9..87c3683bde0 100644 --- a/src/compiler/glsl/glsl_to_nir.cpp +++ b/src/compiler/glsl/glsl_to_nir.cpp @@ -684,7 +684,7 @@ nir_visitor::create_function(ir_function_signature *ir) func->num_params = ir->parameters.length() + (ir->return_type != &glsl_type_builtin_void); - func->params = ralloc_array(shader, nir_parameter, func->num_params); + func->params = rzalloc_array(shader, nir_parameter, func->num_params); unsigned np = 0; if (ir->return_type != &glsl_type_builtin_void) { diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index e9f47e5a73b..88e3ed299b8 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -3650,6 +3650,9 @@ typedef struct { /* The type of the function param */ const struct glsl_type *type; + + /* Name if known, null if unknown */ + const char *name; } nir_parameter; typedef struct nir_function { diff --git a/src/compiler/nir/nir_clone.c b/src/compiler/nir/nir_clone.c index a8359fcd8da..aa797f8c942 100644 --- a/src/compiler/nir/nir_clone.c +++ b/src/compiler/nir/nir_clone.c @@ -708,6 +708,11 @@ nir_function_clone(nir_shader *ns, const nir_function *fxn) if (fxn->num_params) { nfxn->params = ralloc_array(ns, nir_parameter, fxn->num_params); memcpy(nfxn->params, fxn->params, sizeof(nir_parameter) * fxn->num_params); + + for (unsigned i = 0; i < fxn->num_params; ++i) { + if (fxn->params[i].name) + nfxn->params[i].name = ralloc_strdup(ns, fxn->params[i].name); + } } nfxn->is_entrypoint = fxn->is_entrypoint; nfxn->is_preamble = fxn->is_preamble; diff --git a/src/compiler/nir/nir_serialize.c b/src/compiler/nir/nir_serialize.c index 70138e43e79..5b237bc8a58 100644 --- a/src/compiler/nir/nir_serialize.c +++ b/src/compiler/nir/nir_serialize.c @@ -1988,7 +1988,15 @@ write_function(write_ctx *ctx, const nir_function *fxn) uint32_t val = ((uint32_t)fxn->params[i].num_components) | ((uint32_t)fxn->params[i].bit_size) << 8; + + bool has_name = fxn->params[i].name && !ctx->strip; + if (has_name) + val |= 0x10000; + blob_write_uint32(ctx->blob, val); + if (has_name) + blob_write_string(ctx->blob, fxn->params[i].name); + encode_type_to_blob(ctx->blob, fxn->params[i].type); blob_write_uint32(ctx->blob, encode_deref_modes(fxn->params[i].mode)); } @@ -2019,9 +2027,13 @@ read_function(read_ctx *ctx) read_add_object(ctx, fxn); fxn->num_params = blob_read_uint32(ctx->blob); - fxn->params = ralloc_array(fxn, nir_parameter, fxn->num_params); + fxn->params = rzalloc_array(fxn, nir_parameter, fxn->num_params); for (unsigned i = 0; i < fxn->num_params; i++) { uint32_t val = blob_read_uint32(ctx->blob); + bool has_name = (val & 0x10000); + if (has_name) + fxn->params[i].name = blob_read_string(ctx->blob); + fxn->params[i].num_components = val & 0xff; fxn->params[i].bit_size = (val >> 8) & 0xff; fxn->params[i].type = decode_type_from_blob(ctx->blob); diff --git a/src/compiler/spirv/vtn_cfg.c b/src/compiler/spirv/vtn_cfg.c index e1b9d21ecfc..3b7712ee9e7 100644 --- a/src/compiler/spirv/vtn_cfg.c +++ b/src/compiler/spirv/vtn_cfg.c @@ -280,7 +280,7 @@ vtn_cfg_handle_prepass_instruction(struct vtn_builder *b, SpvOp opcode, func->is_exported = b->func->linkage == SpvLinkageTypeExport; func->num_params = num_params; - func->params = ralloc_array(b->shader, nir_parameter, num_params); + func->params = rzalloc_array(b->shader, nir_parameter, num_params); unsigned idx = 0; if (func_type->return_type->base_type != vtn_base_type_void) {