mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-21 07:10:09 +01:00
nir: add names to function parameters
SPIR-V has this information. We should try to preserve it. Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32208>
This commit is contained in:
parent
61862b209e
commit
3da8444be5
5 changed files with 23 additions and 3 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue