nir: Support vec8/vec16 in nir_lower_bit_size
[mesa.git] / src / compiler / nir / nir_schedule.c
index 8428f867cccd306c7418303f97cd3628b317667c..9fa02547dc16d6eb5bcf5eede0521c7bf3285b96 100644 (file)
@@ -114,6 +114,9 @@ typedef struct {
     * pressure-prioritizing scheduling heuristic.
     */
    int threshold;
+
+   /* Mask of stages that share memory for inputs and outputs */
+   unsigned stages_with_shared_io_memory;
 } nir_schedule_scoreboard;
 
 /* When walking the instructions in reverse, we use this flag to swap
@@ -122,10 +125,8 @@ typedef struct {
 enum direction { F, R };
 
 typedef struct {
-   nir_shader *shader;
+   nir_schedule_scoreboard *scoreboard;
 
-   /* Map from nir_instr to nir_schedule_node * */
-   struct hash_table *instr_map;
    /* Map from nir_register to nir_schedule_node * */
    struct hash_table *reg_map;
 
@@ -245,8 +246,9 @@ nir_schedule_reg_src_deps(nir_src *src, void *in_state)
       return true;
    nir_schedule_node *dst_n = entry->data;
 
-   nir_schedule_node *src_n = nir_schedule_get_node(state->instr_map,
-                                                    src->parent_instr);
+   nir_schedule_node *src_n =
+      nir_schedule_get_node(state->scoreboard->instr_map,
+                            src->parent_instr);
 
    add_dep(state, dst_n, src_n);
 
@@ -261,8 +263,9 @@ nir_schedule_reg_dest_deps(nir_dest *dest, void *in_state)
    if (dest->is_ssa)
       return true;
 
-   nir_schedule_node *dest_n = nir_schedule_get_node(state->instr_map,
-                                                     dest->reg.parent_instr);
+   nir_schedule_node *dest_n =
+      nir_schedule_get_node(state->scoreboard->instr_map,
+                            dest->reg.parent_instr);
 
    struct hash_entry *entry = _mesa_hash_table_search(state->reg_map,
                                                       dest->reg.reg);
@@ -281,10 +284,11 @@ static bool
 nir_schedule_ssa_deps(nir_ssa_def *def, void *in_state)
 {
    nir_deps_state *state = in_state;
-   nir_schedule_node *def_n = nir_schedule_get_node(state->instr_map, def->parent_instr);
+   struct hash_table *instr_map = state->scoreboard->instr_map;
+   nir_schedule_node *def_n = nir_schedule_get_node(instr_map, def->parent_instr);
 
    nir_foreach_use(src, def) {
-      nir_schedule_node *use_n = nir_schedule_get_node(state->instr_map,
+      nir_schedule_node *use_n = nir_schedule_get_node(instr_map,
                                                        src->parent_instr);
 
       add_read_dep(state, def_n, use_n);
@@ -297,7 +301,8 @@ static void
 nir_schedule_intrinsic_deps(nir_deps_state *state,
                             nir_intrinsic_instr *instr)
 {
-   nir_schedule_node *n = nir_schedule_get_node(state->instr_map, &instr->instr);
+   nir_schedule_node *n = nir_schedule_get_node(state->scoreboard->instr_map,
+                                                &instr->instr);
 
    switch (instr->intrinsic) {
    case nir_intrinsic_load_uniform:
@@ -321,10 +326,11 @@ nir_schedule_intrinsic_deps(nir_deps_state *state,
       break;
 
    case nir_intrinsic_store_output:
-      /* For some non-FS shader stages, or for some hardware, output stores
-       * affect the same shared memory as input loads.
+      /* For some hardware and stages, output stores affect the same shared
+       * memory as input loads.
        */
-      if (state->shader->info.stage != MESA_SHADER_FRAGMENT)
+      if ((state->scoreboard->stages_with_shared_io_memory &
+           (1 << state->scoreboard->shader->info.stage)))
          add_write_dep(state, &state->load_input, n);
 
       /* Make sure that preceding discards stay before the store_output */
@@ -333,6 +339,7 @@ nir_schedule_intrinsic_deps(nir_deps_state *state,
       break;
 
    case nir_intrinsic_load_input:
+   case nir_intrinsic_load_per_vertex_input:
       add_read_dep(state, state->load_input, n);
       break;
 
@@ -437,9 +444,8 @@ static void
 calculate_forward_deps(nir_schedule_scoreboard *scoreboard, nir_block *block)
 {
    nir_deps_state state = {
-      .shader = scoreboard->shader,
+      .scoreboard = scoreboard,
       .dir = F,
-      .instr_map = scoreboard->instr_map,
       .reg_map = _mesa_pointer_hash_table_create(NULL),
    };
 
@@ -456,9 +462,8 @@ static void
 calculate_reverse_deps(nir_schedule_scoreboard *scoreboard, nir_block *block)
 {
    nir_deps_state state = {
-      .shader = scoreboard->shader,
+      .scoreboard = scoreboard,
       .dir = R,
-      .instr_map = scoreboard->instr_map,
       .reg_map = _mesa_pointer_hash_table_create(NULL),
    };
 
@@ -978,14 +983,17 @@ nir_schedule_ssa_def_init_scoreboard(nir_ssa_def *def, void *state)
 }
 
 static nir_schedule_scoreboard *
-nir_schedule_get_scoreboard(nir_shader *shader, int threshold)
+nir_schedule_get_scoreboard(nir_shader *shader,
+                            const nir_schedule_options *options)
 {
    nir_schedule_scoreboard *scoreboard = rzalloc(NULL, nir_schedule_scoreboard);
 
    scoreboard->shader = shader;
    scoreboard->live_values = _mesa_pointer_set_create(scoreboard);
    scoreboard->remaining_uses = _mesa_pointer_hash_table_create(scoreboard);
-   scoreboard->threshold = threshold;
+   scoreboard->threshold = options->threshold;
+   scoreboard->stages_with_shared_io_memory =
+      options->stages_with_shared_io_memory;
    scoreboard->pressure = 0;
 
    nir_foreach_function(function, shader) {
@@ -1062,10 +1070,11 @@ nir_schedule_validate_uses(nir_schedule_scoreboard *scoreboard)
  * tune.
  */
 void
-nir_schedule(nir_shader *shader, int threshold)
+nir_schedule(nir_shader *shader,
+             const nir_schedule_options *options)
 {
    nir_schedule_scoreboard *scoreboard = nir_schedule_get_scoreboard(shader,
-                                                                     threshold);
+                                                                     options);
 
    if (debug) {
       fprintf(stderr, "NIR shader before scheduling:\n");