diff options
author | Jason Ekstrand <[email protected]> | 2018-03-22 16:41:18 -0700 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2018-06-22 20:15:58 -0700 |
commit | c11833ab24dcba26de1b0a5805e35a5d6761514e (patch) | |
tree | 724a419f448204358d7dd732d51b724dea80bc17 /src/compiler/nir/nir_validate.c | |
parent | 58799b6a5b3e281365bce91fac2e54903fbd2c41 (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_validate.c')
-rw-r--r-- | src/compiler/nir/nir_validate.c | 38 |
1 files changed, 12 insertions, 26 deletions
diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c index 5144886c926..ffee4b54621 100644 --- a/src/compiler/nir/nir_validate.c +++ b/src/compiler/nir/nir_validate.c @@ -547,6 +547,15 @@ validate_intrinsic_instr(nir_intrinsic_instr *instr, validate_state *state) unsigned dest_bit_size = 0; unsigned src_bit_sizes[NIR_INTRINSIC_MAX_INPUTS] = { 0, }; switch (instr->intrinsic) { + case nir_intrinsic_load_param: { + unsigned param_idx = nir_intrinsic_param_idx(instr); + validate_assert(state, param_idx < state->impl->function->num_params); + nir_parameter *param = &state->impl->function->params[param_idx]; + validate_assert(state, instr->num_components == param->num_components); + dest_bit_size = param->bit_size; + break; + } + case nir_intrinsic_load_deref: { nir_deref_instr *src = nir_src_as_deref(instr->src[0]); validate_assert(state, glsl_type_is_vector_or_scalar(src->type) || @@ -669,18 +678,12 @@ validate_tex_instr(nir_tex_instr *instr, validate_state *state) static void validate_call_instr(nir_call_instr *instr, validate_state *state) { - if (instr->return_deref == NULL) { - validate_assert(state, glsl_type_is_void(instr->callee->return_type)); - } else { - validate_assert(state, instr->return_deref->deref.type == instr->callee->return_type); - validate_deref_var(instr, instr->return_deref, state); - } - validate_assert(state, instr->num_params == instr->callee->num_params); for (unsigned i = 0; i < instr->num_params; i++) { - validate_assert(state, instr->callee->params[i].type == instr->params[i]->deref.type); - validate_deref_var(instr, instr->params[i], state); + validate_src(&instr->params[i], state, + instr->callee->params[i].bit_size, + instr->callee->params[i].num_components); } } @@ -1167,23 +1170,6 @@ validate_function_impl(nir_function_impl *impl, validate_state *state) validate_assert(state, impl->function->impl == impl); validate_assert(state, impl->cf_node.parent == NULL); - validate_assert(state, impl->num_params == impl->function->num_params); - for (unsigned i = 0; i < impl->num_params; i++) { - validate_assert(state, impl->params[i]->type == impl->function->params[i].type); - validate_assert(state, impl->params[i]->data.mode == nir_var_param); - validate_assert(state, impl->params[i]->data.location == i); - validate_var_decl(impl->params[i], false, state); - } - - if (glsl_type_is_void(impl->function->return_type)) { - validate_assert(state, impl->return_var == NULL); - } else { - validate_assert(state, impl->return_var->type == impl->function->return_type); - validate_assert(state, impl->return_var->data.mode == nir_var_param); - validate_assert(state, impl->return_var->data.location == -1); - validate_var_decl(impl->return_var, false, state); - } - validate_assert(state, exec_list_is_empty(&impl->end_block->instr_list)); validate_assert(state, impl->end_block->successors[0] == NULL); validate_assert(state, impl->end_block->successors[1] == NULL); |