summaryrefslogtreecommitdiffstats
path: root/src/compiler/nir
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/nir')
-rw-r--r--src/compiler/nir/nir.c55
-rw-r--r--src/compiler/nir/nir.h35
-rw-r--r--src/compiler/nir/nir_builder.h16
-rw-r--r--src/compiler/nir/nir_clone.c15
-rw-r--r--src/compiler/nir/nir_inline_functions.c193
-rw-r--r--src/compiler/nir/nir_intrinsics.py4
-rw-r--r--src/compiler/nir/nir_print.c63
-rw-r--r--src/compiler/nir/nir_remove_dead_variables.c20
-rw-r--r--src/compiler/nir/nir_serialize.c44
-rw-r--r--src/compiler/nir/nir_sweep.c4
-rw-r--r--src/compiler/nir/nir_validate.c38
11 files changed, 110 insertions, 377 deletions
diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index d1404e82fb4..18bf7635e21 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -127,10 +127,6 @@ nir_shader_add_variable(nir_shader *shader, nir_variable *var)
assert(!"nir_shader_add_variable cannot be used for local variables");
break;
- case nir_var_param:
- assert(!"nir_shader_add_variable cannot be used for function parameters");
- break;
-
case nir_var_global:
exec_list_push_tail(&shader->globals, &var->node);
break;
@@ -207,7 +203,6 @@ nir_function_create(nir_shader *shader, const char *name)
func->shader = shader;
func->num_params = 0;
func->params = NULL;
- func->return_type = glsl_void_type();
func->impl = NULL;
return func;
@@ -291,9 +286,6 @@ nir_function_impl_create_bare(nir_shader *shader)
exec_list_make_empty(&impl->body);
exec_list_make_empty(&impl->registers);
exec_list_make_empty(&impl->locals);
- impl->num_params = 0;
- impl->params = NULL;
- impl->return_var = NULL;
impl->reg_alloc = 0;
impl->ssa_alloc = 0;
impl->valid_metadata = nir_metadata_none;
@@ -322,26 +314,6 @@ nir_function_impl_create(nir_function *function)
function->impl = impl;
impl->function = function;
- impl->num_params = function->num_params;
- impl->params = ralloc_array(function->shader,
- nir_variable *, impl->num_params);
-
- for (unsigned i = 0; i < impl->num_params; i++) {
- impl->params[i] = rzalloc(function->shader, nir_variable);
- impl->params[i]->type = function->params[i].type;
- impl->params[i]->data.mode = nir_var_param;
- impl->params[i]->data.location = i;
- }
-
- if (!glsl_type_is_void(function->return_type)) {
- impl->return_var = rzalloc(function->shader, nir_variable);
- impl->return_var->type = function->return_type;
- impl->return_var->data.mode = nir_var_param;
- impl->return_var->data.location = -1;
- } else {
- impl->return_var = NULL;
- }
-
return impl;
}
@@ -539,13 +511,16 @@ nir_intrinsic_instr_create(nir_shader *shader, nir_intrinsic_op op)
nir_call_instr *
nir_call_instr_create(nir_shader *shader, nir_function *callee)
{
- nir_call_instr *instr = ralloc(shader, nir_call_instr);
- instr_init(&instr->instr, nir_instr_type_call);
+ const unsigned num_params = callee->num_params;
+ nir_call_instr *instr =
+ rzalloc_size(shader, sizeof(*instr) +
+ num_params * sizeof(instr->params[0]));
+ instr_init(&instr->instr, nir_instr_type_call);
instr->callee = callee;
- instr->num_params = callee->num_params;
- instr->params = ralloc_array(instr, nir_deref_var *, instr->num_params);
- instr->return_deref = NULL;
+ instr->num_params = num_params;
+ for (unsigned i = 0; i < num_params; i++)
+ src_init(&instr->params[i]);
return instr;
}
@@ -1441,6 +1416,17 @@ visit_intrinsic_src(nir_intrinsic_instr *instr, nir_foreach_src_cb cb,
}
static bool
+visit_call_src(nir_call_instr *instr, nir_foreach_src_cb cb, void *state)
+{
+ for (unsigned i = 0; i < instr->num_params; i++) {
+ if (!visit_src(&instr->params[i], cb, state))
+ return false;
+ }
+
+ return true;
+}
+
+static bool
visit_phi_src(nir_phi_instr *instr, nir_foreach_src_cb cb, void *state)
{
nir_foreach_phi_src(src, instr) {
@@ -1500,7 +1486,8 @@ nir_foreach_src(nir_instr *instr, nir_foreach_src_cb cb, void *state)
return false;
break;
case nir_instr_type_call:
- /* Call instructions have no regular sources */
+ if (!visit_call_src(nir_instr_as_call(instr), cb, state))
+ return false;
break;
case nir_instr_type_load_const:
/* Constant load instructions have no regular sources */
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 9e4aa1df5bd..6642977fa3e 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -99,7 +99,6 @@ typedef enum {
nir_var_uniform = (1 << 4),
nir_var_shader_storage = (1 << 5),
nir_var_system_value = (1 << 6),
- nir_var_param = (1 << 7),
nir_var_shared = (1 << 8),
nir_var_all = ~0,
} nir_variable_mode;
@@ -392,7 +391,7 @@ typedef struct nir_variable {
static inline bool
nir_variable_is_global(const nir_variable *var)
{
- return var->data.mode != nir_var_local && var->data.mode != nir_var_param;
+ return var->data.mode != nir_var_local;
}
typedef struct nir_register {
@@ -1052,11 +1051,10 @@ nir_deref_instr_to_deref(nir_deref_instr *instr, void *mem_ctx);
typedef struct {
nir_instr instr;
- unsigned num_params;
- nir_deref_var **params;
- nir_deref_var *return_deref;
-
struct nir_function *callee;
+
+ unsigned num_params;
+ nir_src params[];
} nir_call_instr;
#include "nir_intrinsics.h"
@@ -1200,6 +1198,11 @@ typedef enum {
*/
NIR_INTRINSIC_CLUSTER_SIZE = 11,
+ /**
+ * Parameter index for a load_param intrinsic
+ */
+ NIR_INTRINSIC_PARAM_IDX = 12,
+
NIR_INTRINSIC_NUM_INDEX_FLAGS,
} nir_intrinsic_index_flag;
@@ -1292,6 +1295,7 @@ INTRINSIC_IDX_ACCESSORS(component, COMPONENT, unsigned)
INTRINSIC_IDX_ACCESSORS(interp_mode, INTERP_MODE, unsigned)
INTRINSIC_IDX_ACCESSORS(reduction_op, REDUCTION_OP, unsigned)
INTRINSIC_IDX_ACCESSORS(cluster_size, CLUSTER_SIZE, unsigned)
+INTRINSIC_IDX_ACCESSORS(param_idx, PARAM_IDX, unsigned)
/**
* \group texture information
@@ -1847,13 +1851,6 @@ typedef struct {
/** list for all local variables in the function */
struct exec_list locals;
- /** array of variables used as parameters */
- unsigned num_params;
- nir_variable **params;
-
- /** variable used to hold the result of the function */
- nir_variable *return_var;
-
/** list of local registers in the function */
struct exec_list registers;
@@ -1964,15 +1961,9 @@ nir_loop_last_block(nir_loop *loop)
return nir_cf_node_as_block(exec_node_data(nir_cf_node, tail, node));
}
-typedef enum {
- nir_parameter_in,
- nir_parameter_out,
- nir_parameter_inout,
-} nir_parameter_type;
-
typedef struct {
- nir_parameter_type param_type;
- const struct glsl_type *type;
+ uint8_t num_components;
+ uint8_t bit_size;
} nir_parameter;
typedef struct nir_function {
@@ -1983,7 +1974,6 @@ typedef struct nir_function {
unsigned num_params;
nir_parameter *params;
- const struct glsl_type *return_type;
/** The implementation of this function.
*
@@ -2164,7 +2154,6 @@ nir_shader_get_entrypoint(nir_shader *shader)
assert(exec_list_length(&shader->functions) == 1);
struct exec_node *func_node = exec_list_get_head(&shader->functions);
nir_function *func = exec_node_data(nir_function, func_node, node);
- assert(func->return_type == glsl_void_type());
assert(func->num_params == 0);
assert(func->impl);
return func->impl;
diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
index da7a501fa85..6a40e84c55f 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -843,6 +843,22 @@ nir_copy_var(nir_builder *build, nir_variable *dest, nir_variable *src)
nir_builder_instr_insert(build, &copy->instr);
}
+static inline nir_ssa_def *
+nir_load_param(nir_builder *build, uint32_t param_idx)
+{
+ assert(param_idx < build->impl->function->num_params);
+ nir_parameter *param = &build->impl->function->params[param_idx];
+
+ nir_intrinsic_instr *load =
+ nir_intrinsic_instr_create(build->shader, nir_intrinsic_load_param);
+ nir_intrinsic_set_param_idx(load, param_idx);
+ load->num_components = param->num_components;
+ nir_ssa_dest_init(&load->instr, &load->dest,
+ param->num_components, param->bit_size, NULL);
+ nir_builder_instr_insert(build, &load->instr);
+ return &load->dest.ssa;
+}
+
#include "nir_builder_opcodes.h"
static inline nir_ssa_def *
diff --git a/src/compiler/nir/nir_clone.c b/src/compiler/nir/nir_clone.c
index 76121d05a7e..4769fbd8bf9 100644
--- a/src/compiler/nir/nir_clone.c
+++ b/src/compiler/nir/nir_clone.c
@@ -536,10 +536,7 @@ clone_call(clone_state *state, const nir_call_instr *call)
nir_call_instr *ncall = nir_call_instr_create(state->ns, ncallee);
for (unsigned i = 0; i < ncall->num_params; i++)
- ncall->params[i] = clone_deref_var(state, call->params[i], &ncall->instr);
-
- ncall->return_deref = clone_deref_var(state, call->return_deref,
- &ncall->instr);
+ __clone_src(state, ncall, &ncall->params[i], &call->params[i]);
return ncall;
}
@@ -721,14 +718,6 @@ clone_function_impl(clone_state *state, const nir_function_impl *fi)
clone_reg_list(state, &nfi->registers, &fi->registers);
nfi->reg_alloc = fi->reg_alloc;
- nfi->num_params = fi->num_params;
- nfi->params = ralloc_array(state->ns, nir_variable *, fi->num_params);
- for (unsigned i = 0; i < fi->num_params; i++) {
- nfi->params[i] = clone_variable(state, fi->params[i]);
- }
- if (fi->return_var)
- nfi->return_var = clone_variable(state, fi->return_var);
-
assert(list_empty(&state->phi_srcs));
clone_cf_list(state, &nfi->body, &fi->body);
@@ -770,8 +759,6 @@ clone_function(clone_state *state, const nir_function *fxn, nir_shader *ns)
nfxn->params = ralloc_array(state->ns, nir_parameter, fxn->num_params);
memcpy(nfxn->params, fxn->params, sizeof(nir_parameter) * fxn->num_params);
- nfxn->return_type = fxn->return_type;
-
/* At first glance, it looks like we should clone the function_impl here.
* However, call instructions need to be able to reference at least the
* function and those will get processed as we clone the function_impls.
diff --git a/src/compiler/nir/nir_inline_functions.c b/src/compiler/nir/nir_inline_functions.c
index b91e7bc86da..06c90d93956 100644
--- a/src/compiler/nir/nir_inline_functions.c
+++ b/src/compiler/nir/nir_inline_functions.c
@@ -24,126 +24,10 @@
#include "nir.h"
#include "nir_builder.h"
#include "nir_control_flow.h"
+#include "nir_vla.h"
static bool inline_function_impl(nir_function_impl *impl, struct set *inlined);
-static void
-convert_deref_to_param_deref(nir_instr *instr, nir_deref_var **deref,
- nir_call_instr *call)
-{
- /* This isn't a parameter, just return the deref */
- if ((*deref)->var->data.mode != nir_var_param)
- return;
-
- int param_idx = (*deref)->var->data.location;
-
- nir_deref_var *call_deref;
- if (param_idx >= 0) {
- assert(param_idx < call->callee->num_params);
- call_deref = call->params[param_idx];
- } else {
- call_deref = call->return_deref;
- }
- assert(call_deref);
-
- /* Now we make a new deref by concatenating the deref in the call's
- * parameter with the deref we were given.
- */
- nir_deref_var *new_deref = nir_deref_var_clone(call_deref, instr);
- nir_deref *new_tail = nir_deref_tail(&new_deref->deref);
- new_tail->child = (*deref)->deref.child;
- ralloc_steal(new_tail, new_tail->child);
- *deref = new_deref;
-}
-
-static void
-rewrite_param_derefs(nir_instr *instr, nir_call_instr *call)
-{
- switch (instr->type) {
- case nir_instr_type_intrinsic: {
- nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
-
- for (unsigned i = 0;
- i < nir_intrinsic_infos[intrin->intrinsic].num_variables; i++) {
- convert_deref_to_param_deref(instr, &intrin->variables[i], call);
- }
- break;
- }
-
- case nir_instr_type_tex: {
- nir_tex_instr *tex = nir_instr_as_tex(instr);
- if (tex->texture)
- convert_deref_to_param_deref(&tex->instr, &tex->texture, call);
- if (tex->sampler)
- convert_deref_to_param_deref(&tex->instr, &tex->sampler, call);
- break;
- }
-
- default:
- break; /* Nothing else has derefs */
- }
-}
-
-static void
-lower_param_to_local(nir_variable *param, nir_function_impl *impl, bool write)
-{
- if (param->data.mode != nir_var_param)
- return;
-
- nir_parameter_type param_type;
- if (param->data.location >= 0) {
- assert(param->data.location < impl->num_params);
- param_type = impl->function->params[param->data.location].param_type;
- } else {
- /* Return variable */
- param_type = nir_parameter_out;
- }
-
- if ((write && param_type == nir_parameter_in) ||
- (!write && param_type == nir_parameter_out)) {
- /* In this case, we need a shadow copy. Turn it into a local */
- param->data.mode = nir_var_local;
- exec_list_push_tail(&impl->locals, &param->node);
- }
-}
-
-static bool
-lower_params_to_locals_block(nir_block *block, nir_function_impl *impl)
-{
- nir_foreach_instr(instr, block) {
- if (instr->type != nir_instr_type_intrinsic)
- continue;
-
- nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
-
- switch (intrin->intrinsic) {
- case nir_intrinsic_store_var:
- lower_param_to_local(intrin->variables[0]->var, impl, true);
- break;
-
- case nir_intrinsic_copy_var:
- lower_param_to_local(intrin->variables[0]->var, impl, true);
- lower_param_to_local(intrin->variables[1]->var, impl, false);
- break;
-
- case nir_intrinsic_load_var:
- /* All other intrinsics which access variables (image_load_store)
- * do so in a read-only fasion.
- */
- for (unsigned i = 0;
- i < nir_intrinsic_infos[intrin->intrinsic].num_variables; i++) {
- lower_param_to_local(intrin->variables[i]->var, impl, false);
- }
- break;
-
- default:
- continue;
- }
- }
-
- return true;
-}
-
static bool
inline_functions_block(nir_block *block, nir_builder *b,
struct set *inlined)
@@ -171,42 +55,43 @@ inline_functions_block(nir_block *block, nir_builder *b,
nir_function_impl_clone(call->callee->impl);
callee_copy->function = call->callee;
- /* Add copies of all in parameters */
- assert(call->num_params == callee_copy->num_params);
-
exec_list_append(&b->impl->locals, &callee_copy->locals);
exec_list_append(&b->impl->registers, &callee_copy->registers);
b->cursor = nir_before_instr(&call->instr);
- /* We now need to tie the two functions together using the
- * parameters. There are two ways we do this: One is to turn the
- * parameter into a local variable and do a shadow-copy. The other
- * is to treat the parameter as a "proxy" and rewrite derefs to use
- * the actual variable that comes from the call instruction. We
- * implement both schemes. The first is needed in the case where we
- * have an in parameter that we write or similar. The second case is
- * needed for handling things such as images and uniforms properly.
+ /* Rewrite all of the uses of the callee's parameters to use the call
+ * instructions sources. In order to ensure that the "load" happens
+ * here and not later (for register sources), we make sure to convert it
+ * to an SSA value first.
*/
-
- /* Figure out when we need to lower to a shadow local */
- nir_foreach_block(block, callee_copy) {
- lower_params_to_locals_block(block, callee_copy);
- }
-
- for (unsigned i = 0; i < callee_copy->num_params; i++) {
- nir_variable *param = callee_copy->params[i];
-
- if (param->data.mode == nir_var_local &&
- call->callee->params[i].param_type != nir_parameter_out) {
- nir_copy_deref_var(b, nir_deref_var_create(b->shader, param),
- call->params[i]);
- }
+ const unsigned num_params = call->num_params;
+ NIR_VLA(nir_ssa_def *, params, num_params);
+ for (unsigned i = 0; i < num_params; i++) {
+ params[i] = nir_ssa_for_src(b, call->params[i],
+ call->callee->params[i].num_components);
}
nir_foreach_block(block, callee_copy) {
- nir_foreach_instr(instr, block)
- rewrite_param_derefs(instr, call);
+ nir_foreach_instr_safe(instr, block) {
+ if (instr->type != nir_instr_type_intrinsic)
+ continue;
+
+ nir_intrinsic_instr *load = nir_instr_as_intrinsic(instr);
+ if (load->intrinsic != nir_intrinsic_load_param)
+ continue;
+
+ unsigned param_idx = nir_intrinsic_param_idx(load);
+ assert(param_idx < num_params);
+ assert(load->dest.is_ssa);
+ nir_ssa_def_rewrite_uses(&load->dest.ssa,
+ nir_src_for_ssa(params[param_idx]));
+
+ /* Remove any left-over load_param intrinsics because they're soon
+ * to be in another function and therefore no longer valid.
+ */
+ nir_instr_remove(&load->instr);
+ }
}
/* Pluck the body out of the function and place it here */
@@ -214,26 +99,6 @@ inline_functions_block(nir_block *block, nir_builder *b,
nir_cf_list_extract(&body, &callee_copy->body);
nir_cf_reinsert(&body, b->cursor);
- b->cursor = nir_before_instr(&call->instr);
-
- /* Add copies of all out parameters and the return */
- assert(call->num_params == callee_copy->num_params);
- for (unsigned i = 0; i < callee_copy->num_params; i++) {
- nir_variable *param = callee_copy->params[i];
-
- if (param->data.mode == nir_var_local &&
- call->callee->params[i].param_type != nir_parameter_in) {
- nir_copy_deref_var(b, call->params[i],
- nir_deref_var_create(b->shader, param));
- }
- }
- if (!glsl_type_is_void(call->callee->return_type) &&
- callee_copy->return_var->data.mode == nir_var_local) {
- nir_copy_deref_var(b, call->return_deref,
- nir_deref_var_create(b->shader,
- callee_copy->return_var));
- }
-
nir_instr_remove(&call->instr);
}
diff --git a/src/compiler/nir/nir_intrinsics.py b/src/compiler/nir/nir_intrinsics.py
index 1d9a76a32ef..785441c6682 100644
--- a/src/compiler/nir/nir_intrinsics.py
+++ b/src/compiler/nir/nir_intrinsics.py
@@ -102,6 +102,8 @@ INTERP_MODE = "NIR_INTRINSIC_INTERP_MODE"
REDUCTION_OP = "NIR_INTRINSIC_REDUCTION_OP"
# Cluster size for reduction operations
CLUSTER_SIZE = "NIR_INTRINSIC_CLUSTER_SIZE"
+# Parameter index for a load_param intrinsic
+PARAM_IDX = "NIR_INTRINSIC_PARAM_IDX"
#
# Possible flags:
@@ -120,6 +122,8 @@ def intrinsic(name, src_comp=[], dest_comp=-1, num_vars=0, indices=[],
intrinsic("nop", flags=[CAN_ELIMINATE])
+intrinsic("load_param", dest_comp=0, indices=[PARAM_IDX], flags=[CAN_ELIMINATE])
+
intrinsic("load_var", dest_comp=0, num_vars=1, flags=[CAN_ELIMINATE])
intrinsic("store_var", src_comp=[0], num_vars=1, indices=[WRMASK])
intrinsic("copy_var", num_vars=2)
diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c
index d034d53531f..28dbe729561 100644
--- a/src/compiler/nir/nir_print.c
+++ b/src/compiler/nir/nir_print.c
@@ -408,7 +408,6 @@ get_variable_mode_str(nir_variable_mode mode, bool want_local_global_mode)
return "system";
case nir_var_shared:
return "shared";
- case nir_var_param:
case nir_var_global:
return want_local_global_mode ? "global" : "";
case nir_var_local:
@@ -649,14 +648,6 @@ print_var(nir_variable *var, print_state *state)
}
static void
-print_arg(nir_variable *var, print_state *state)
-{
- FILE *fp = state->fp;
- fprintf(fp, "%s %s", glsl_get_type_name(var->type),
- get_var_name(var, state));
-}
-
-static void
print_deref_var(nir_deref_var *deref, print_state *state)
{
print_var(deref->var, state);
@@ -777,6 +768,7 @@ print_intrinsic_instr(nir_intrinsic_instr *instr, print_state *state)
[NIR_INTRINSIC_INTERP_MODE] = "interp_mode",
[NIR_INTRINSIC_REDUCTION_OP] = "reduction_op",
[NIR_INTRINSIC_CLUSTER_SIZE] = "cluster_size",
+ [NIR_INTRINSIC_PARAM_IDX] = "param_idx",
};
for (unsigned idx = 1; idx < NIR_INTRINSIC_NUM_INDEX_FLAGS; idx++) {
if (!info->index_map[idx])
@@ -976,14 +968,7 @@ print_call_instr(nir_call_instr *instr, print_state *state)
if (i != 0)
fprintf(fp, ", ");
- print_deref(instr->params[i], state);
- }
-
- if (instr->return_deref != NULL) {
- if (instr->num_params != 0)
- fprintf(fp, ", ");
- fprintf(fp, "returning ");
- print_deref(instr->return_deref, state);
+ print_src(&instr->params[i], state);
}
}
@@ -1258,20 +1243,6 @@ print_function_impl(nir_function_impl *impl, print_state *state)
fprintf(fp, "\nimpl %s ", impl->function->name);
- for (unsigned i = 0; i < impl->num_params; i++) {
- if (i != 0)
- fprintf(fp, ", ");
-
- print_arg(impl->params[i], state);
- }
-
- if (impl->return_var != NULL) {
- if (impl->num_params != 0)
- fprintf(fp, ", ");
- fprintf(fp, "returning ");
- print_arg(impl->return_var, state);
- }
-
fprintf(fp, "{\n");
nir_foreach_variable(var, &impl->locals) {
@@ -1298,34 +1269,8 @@ print_function(nir_function *function, print_state *state)
{
FILE *fp = state->fp;
- fprintf(fp, "decl_function %s ", function->name);
-
- for (unsigned i = 0; i < function->num_params; i++) {
- if (i != 0)
- fprintf(fp, ", ");
-
- switch (function->params[i].param_type) {
- case nir_parameter_in:
- fprintf(fp, "in ");
- break;
- case nir_parameter_out:
- fprintf(fp, "out ");
- break;
- case nir_parameter_inout:
- fprintf(fp, "inout ");
- break;
- default:
- unreachable("Invalid parameter type");
- }
-
- fprintf(fp, "%s", glsl_get_type_name(function->params[i].type));
- }
-
- if (function->return_type != NULL) {
- if (function->num_params != 0)
- fprintf(fp, ", ");
- fprintf(fp, "returning %s", glsl_get_type_name(function->return_type));
- }
+ fprintf(fp, "decl_function %s (%d params)", function->name,
+ function->num_params);
fprintf(fp, "\n");
diff --git a/src/compiler/nir/nir_remove_dead_variables.c b/src/compiler/nir/nir_remove_dead_variables.c
index 89e544f9e1f..41dddd9387f 100644
--- a/src/compiler/nir/nir_remove_dead_variables.c
+++ b/src/compiler/nir/nir_remove_dead_variables.c
@@ -52,7 +52,7 @@ deref_used_for_not_store(nir_deref_instr *deref)
default:
/* If it's used by any other instruction type (most likely a texture
- * instruction), consider it used.
+ * or call instruction), consider it used.
*/
return true;
}
@@ -114,20 +114,6 @@ add_var_use_intrinsic(nir_intrinsic_instr *instr, struct set *live,
}
static void
-add_var_use_call(nir_call_instr *instr, struct set *live)
-{
- if (instr->return_deref != NULL) {
- nir_variable *var = instr->return_deref->var;
- _mesa_set_add(live, var);
- }
-
- for (unsigned i = 0; i < instr->num_params; i++) {
- nir_variable *var = instr->params[i]->var;
- _mesa_set_add(live, var);
- }
-}
-
-static void
add_var_use_tex(nir_tex_instr *instr, struct set *live)
{
if (instr->texture != NULL) {
@@ -158,10 +144,6 @@ add_var_use_shader(nir_shader *shader, struct set *live, nir_variable_mode modes
modes);
break;
- case nir_instr_type_call:
- add_var_use_call(nir_instr_as_call(instr), live);
- break;
-
case nir_instr_type_tex:
add_var_use_tex(nir_instr_as_tex(instr), live);
break;
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
diff --git a/src/compiler/nir/nir_sweep.c b/src/compiler/nir/nir_sweep.c
index 0f1debce3ad..b14bf139c1b 100644
--- a/src/compiler/nir/nir_sweep.c
+++ b/src/compiler/nir/nir_sweep.c
@@ -118,10 +118,6 @@ sweep_impl(nir_shader *nir, nir_function_impl *impl)
{
ralloc_steal(nir, impl);
- ralloc_steal(nir, impl->params);
- for (unsigned i = 0; i < impl->num_params; i++)
- ralloc_steal(nir, impl->params[i]);
- ralloc_steal(nir, impl->return_var);
steal_list(nir, nir_variable, &impl->locals);
steal_list(nir, nir_register, &impl->registers);
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);