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)
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;
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);
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);