r600/sfn: Use nir_foreach_variable_with_modes in IO vectorization
authorJason Ekstrand <jason@jlekstrand.net>
Tue, 21 Jul 2020 23:21:56 +0000 (18:21 -0500)
committerMarge Bot <eric+marge@anholt.net>
Wed, 29 Jul 2020 17:38:58 +0000 (17:38 +0000)
Reviewed-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5966>

src/gallium/drivers/r600/sfn/sfn_nir_lower_fs_out_to_vector.cpp
src/gallium/drivers/r600/sfn/sfn_nir_vectorize_vs_inputs.c

index 818c1f2256664a83f4f1f2961b1afba79edcf0ea..f45a490c895a0ff79071a3b3570d0e4db744aa27 100644 (file)
@@ -84,7 +84,7 @@ protected:
    InstrSet m_block_io;
    int m_next_index;
 private:
-   virtual exec_list *get_io_list(nir_shader *shader) const  = 0;
+   virtual nir_variable_mode get_io_mode(nir_shader *shader) const  = 0;
    virtual bool instr_can_rewrite_type(nir_intrinsic_instr *intr) const  = 0;
    virtual bool var_can_rewrite_slot(nir_variable *var) const = 0;
    virtual void create_new_io(nir_builder *b, nir_intrinsic_instr *intr, nir_variable *var,
@@ -98,7 +98,7 @@ public:
    NirLowerFSOutToVector();
 
 private:
-   exec_list *get_io_list(nir_shader *shader) const  override;
+   nir_variable_mode get_io_mode(nir_shader *shader) const  override;
    bool var_can_rewrite_slot(nir_variable *var) const override;
    void create_new_io(nir_builder *b, nir_intrinsic_instr *intr, nir_variable *var,
                          nir_ssa_def **srcs, unsigned first_comp, unsigned num_comps) override;
@@ -150,17 +150,20 @@ bool NirLowerIOToVector::run(nir_function_impl *impl)
 
 void NirLowerIOToVector::create_new_io_vars(nir_shader *shader)
 {
-   struct exec_list *io_list = get_io_list(shader);
-   if (exec_list_is_empty(io_list))
-      return;
+   nir_variable_mode mode = get_io_mode(shader);
 
-   nir_foreach_variable(var, io_list) {
+   bool can_rewrite_vars = false;
+   nir_foreach_variable_with_modes(var, shader, mode) {
       if (var_can_rewrite(var)) {
+         can_rewrite_vars = true;
          unsigned loc = var->data.location - m_base_slot;
          m_vars[loc][var->data.location_frac] = var;
       }
    }
 
+   if (!can_rewrite_vars)
+      return;
+
    /* We don't handle combining vars of different type e.g. different array
     * lengths.
     */
@@ -385,9 +388,9 @@ bool NirLowerIOToVector::vec_instr_stack_pop(nir_builder *b, InstrSubSet &ir_set
    return true;
 }
 
-exec_list *NirLowerFSOutToVector::get_io_list(nir_shader *shader) const
+nir_variable_mode NirLowerFSOutToVector::get_io_mode(nir_shader *shader) const
 {
-   return &shader->outputs;
+   return nir_var_shader_out;
 }
 
 void
index 16e43b79c0f7cb96eaec78007d92b1ad394a0f31..053d3e7930644e2119abcd68a75e42c18b129b2c 100644 (file)
@@ -376,19 +376,21 @@ r600_variables_can_merge(const nir_variable *lhs, const nir_variable *rhs)
 }
 
 static void
-r600_create_new_io_vars(nir_shader *shader, struct exec_list *io_list,
+r600_create_new_io_vars(nir_shader *shader, nir_variable_mode mode,
                    nir_variable *vars[16][4])
 {
-   if (exec_list_is_empty(io_list))
-      return;
-
-   nir_foreach_variable(var, io_list) {
+   bool can_rewrite_vars = false;
+   nir_foreach_variable_with_modes(var, shader, mode) {
       if (r600_variable_can_rewrite(var)) {
+         can_rewrite_vars = true;
          unsigned loc = r600_correct_location(var);
          vars[loc][var->data.location_frac] = var;
       }
    }
 
+   if (!can_rewrite_vars)
+      return;
+
    /* We don't handle combining vars of different type e.g. different array
     * lengths.
     */
@@ -432,7 +434,7 @@ r600_vectorize_io_impl(nir_function_impl *impl)
    nir_shader *shader = impl->function->shader;
    nir_variable *updated_vars[16][4] = {0};
 
-   r600_create_new_io_vars(shader, &shader->inputs, updated_vars);
+   r600_create_new_io_vars(shader, nir_var_shader_in, updated_vars);
 
    struct set *instr_set = r600_vec_instr_set_create();
    bool progress = r600_vectorize_block(&b, nir_start_block(impl), instr_set,