v3d: Use nir_remove_unused_io_vars to handle binner shader output DCE

We were doing this late after nir_lower_io, but we can just reuse the core
code.  By doing it at this stage, we won't even set up the VS attributes
as inputs, reducing our VPM size.
This commit is contained in:
Eric Anholt 2018-09-26 09:22:51 -07:00
parent c152c79d5e
commit cc54e1acf9
3 changed files with 14 additions and 46 deletions

View file

@ -51,44 +51,6 @@ replace_intrinsic_with_vec(nir_builder *b, nir_intrinsic_instr *intr,
nir_instr_remove(&intr->instr);
}
static void
v3d_nir_lower_output(struct v3d_compile *c, nir_builder *b,
nir_intrinsic_instr *intr)
{
nir_variable *output_var = NULL;
nir_foreach_variable(var, &c->s->outputs) {
if (var->data.driver_location == nir_intrinsic_base(intr)) {
output_var = var;
break;
}
}
assert(output_var);
if (c->vs_key) {
int slot = output_var->data.location;
bool used = false;
switch (slot) {
case VARYING_SLOT_PSIZ:
case VARYING_SLOT_POS:
used = true;
break;
default:
for (int i = 0; i < c->vs_key->num_fs_inputs; i++) {
if (v3d_slot_get_slot(c->vs_key->fs_inputs[i]) == slot) {
used = true;
break;
}
}
break;
}
if (!used)
nir_instr_remove(&intr->instr);
}
}
static void
v3d_nir_lower_uniform(struct v3d_compile *c, nir_builder *b,
nir_intrinsic_instr *intr)
@ -135,10 +97,6 @@ v3d_nir_lower_io_instr(struct v3d_compile *c, nir_builder *b,
case nir_intrinsic_load_input:
break;
case nir_intrinsic_store_output:
v3d_nir_lower_output(c, b, intr);
break;
case nir_intrinsic_load_uniform:
v3d_nir_lower_uniform(c, b, intr);
break;

View file

@ -719,13 +719,23 @@ uint64_t *v3d_compile_vs(const struct v3d_compiler *compiler,
c->vs_key = key;
/* Split our input vars and dead code eliminate the unused
/* Split our I/O vars and dead code eliminate the unused
* components.
*/
NIR_PASS_V(c->s, nir_lower_io_to_scalar_early, nir_var_shader_in);
NIR_PASS_V(c->s, nir_lower_io_to_scalar_early,
nir_var_shader_in | nir_var_shader_out);
uint64_t used_outputs[4] = {0};
for (int i = 0; i < c->vs_key->num_fs_inputs; i++) {
int slot = v3d_slot_get_slot(c->vs_key->fs_inputs[i]);
int comp = v3d_slot_get_component(c->vs_key->fs_inputs[i]);
used_outputs[comp] |= 1ull << slot;
}
NIR_PASS_V(c->s, nir_remove_unused_io_vars,
&c->s->outputs, used_outputs, NULL); /* demotes to globals */
NIR_PASS_V(c->s, nir_lower_global_vars_to_local);
v3d_optimize_nir(c->s);
NIR_PASS_V(c->s, nir_remove_dead_variables, nir_var_shader_in);
NIR_PASS_V(c->s, nir_lower_io, nir_var_shader_in,
NIR_PASS_V(c->s, nir_lower_io, nir_var_shader_in | nir_var_shader_out,
type_size_vec4,
(nir_lower_io_options)0);

View file

@ -212,7 +212,7 @@ v3d_shader_state_create(struct pipe_context *pctx,
nir_variable_mode lower_mode = nir_var_all & ~nir_var_uniform;
if (s->info.stage == MESA_SHADER_VERTEX)
lower_mode &= ~nir_var_shader_in;
lower_mode &= ~(nir_var_shader_in | nir_var_shader_out);
NIR_PASS_V(s, nir_lower_io, lower_mode,
type_size,
(nir_lower_io_options)0);