aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler/nir/nir_serialize.c
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2018-03-22 16:41:18 -0700
committerJason Ekstrand <[email protected]>2018-06-22 20:15:58 -0700
commitc11833ab24dcba26de1b0a5805e35a5d6761514e (patch)
tree724a419f448204358d7dd732d51b724dea80bc17 /src/compiler/nir/nir_serialize.c
parent58799b6a5b3e281365bce91fac2e54903fbd2c41 (diff)
nir,spirv: Rework function calls
This commit completely reworks function calls in NIR. Instead of having a set of variables for the parameters and return value, nir_call_instr now has simply has a number of sources which get mapped to load_param intrinsics inside the functions. It's up to the client API to build an ABI on top of that. In SPIR-V, out parameters are handled by passing the result of a deref through as an SSA value and storing to it. This virtue of this approach can be seen by how much it allows us to delete from core NIR. In particular, nir_inline_functions gets halved and goes from a fairly difficult pass to understand in detail to almost trivial. It also simplifies spirv_to_nir somewhat because NIR functions never were a good fit for SPIR-V. Unfortunately, there is no good way to do this without a mega-commit. Core NIR and SPIR-V have to be changed at the same time. This also requires changes to anv and radv because nir_inline_functions couldn't handle deref instructions before this change and can't work without them after this change. Acked-by: Rob Clark <[email protected]> Acked-by: Bas Nieuwenhuizen <[email protected]> Acked-by: Dave Airlie <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/compiler/nir/nir_serialize.c')
-rw-r--r--src/compiler/nir/nir_serialize.c44
1 files changed, 10 insertions, 34 deletions
diff --git a/src/compiler/nir/nir_serialize.c b/src/compiler/nir/nir_serialize.c
index 39f6d8298d7..37699109ab5 100644
--- a/src/compiler/nir/nir_serialize.c
+++ b/src/compiler/nir/nir_serialize.c
@@ -863,9 +863,7 @@ write_call(write_ctx *ctx, const nir_call_instr *call)
blob_write_intptr(ctx->blob, write_lookup_object(ctx, call->callee));
for (unsigned i = 0; i < call->num_params; i++)
- write_deref_chain(ctx, call->params[i]);
-
- write_deref_chain(ctx, call->return_deref);
+ write_src(ctx, &call->params[i]);
}
static nir_call_instr *
@@ -875,9 +873,7 @@ read_call(read_ctx *ctx)
nir_call_instr *call = nir_call_instr_create(ctx->nir, callee);
for (unsigned i = 0; i < call->num_params; i++)
- call->params[i] = read_deref_chain(ctx, &call->instr);
-
- call->return_deref = read_deref_chain(ctx, &call->instr);
+ read_src(ctx, &call->params[i], call);
return call;
}
@@ -1102,15 +1098,6 @@ write_function_impl(write_ctx *ctx, const nir_function_impl *fi)
write_reg_list(ctx, &fi->registers);
blob_write_uint32(ctx->blob, fi->reg_alloc);
- blob_write_uint32(ctx->blob, fi->num_params);
- for (unsigned i = 0; i < fi->num_params; i++) {
- write_variable(ctx, fi->params[i]);
- }
-
- blob_write_uint32(ctx->blob, !!(fi->return_var));
- if (fi->return_var)
- write_variable(ctx, fi->return_var);
-
write_cf_list(ctx, &fi->body);
write_fixup_phis(ctx);
}
@@ -1125,17 +1112,6 @@ read_function_impl(read_ctx *ctx, nir_function *fxn)
read_reg_list(ctx, &fi->registers);
fi->reg_alloc = blob_read_uint32(ctx->blob);
- fi->num_params = blob_read_uint32(ctx->blob);
- for (unsigned i = 0; i < fi->num_params; i++) {
- fi->params[i] = read_variable(ctx);
- }
-
- bool has_return = blob_read_uint32(ctx->blob);
- if (has_return)
- fi->return_var = read_variable(ctx);
- else
- fi->return_var = NULL;
-
read_cf_list(ctx, &fi->body);
read_fixup_phis(ctx);
@@ -1155,12 +1131,12 @@ write_function(write_ctx *ctx, const nir_function *fxn)
blob_write_uint32(ctx->blob, fxn->num_params);
for (unsigned i = 0; i < fxn->num_params; i++) {
- blob_write_uint32(ctx->blob, fxn->params[i].param_type);
- encode_type_to_blob(ctx->blob, fxn->params[i].type);
+ uint32_t val =
+ ((uint32_t)fxn->params[i].num_components) |
+ ((uint32_t)fxn->params[i].bit_size) << 8;
+ blob_write_uint32(ctx->blob, val);
}
- encode_type_to_blob(ctx->blob, fxn->return_type);
-
/* At first glance, it looks like we should write the function_impl here.
* However, call instructions need to be able to reference at least the
* function and those will get processed as we write the function_impls.
@@ -1179,12 +1155,12 @@ 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);
for (unsigned i = 0; i < fxn->num_params; i++) {
- fxn->params[i].param_type = blob_read_uint32(ctx->blob);
- fxn->params[i].type = decode_type_from_blob(ctx->blob);
+ uint32_t val = blob_read_uint32(ctx->blob);
+ fxn->params[i].num_components = val & 0xff;
+ fxn->params[i].bit_size = (val >> 8) & 0xff;
}
-
- fxn->return_type = decode_type_from_blob(ctx->blob);
}
void