intel/nir: Use nir control flow helpers
authorConnor Abbott <cwabbott0@gmail.com>
Tue, 9 Apr 2019 20:16:26 +0000 (22:16 +0200)
committerMarge Bot <eric+marge@anholt.net>
Wed, 30 Sep 2020 15:47:51 +0000 (15:47 +0000)
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6866>

src/intel/blorp/blorp_blit.c
src/intel/compiler/brw_nir_tcs_workarounds.c

index 3aac0ab..e783277 100644 (file)
@@ -564,9 +564,6 @@ blorp_nir_combine_samples(nir_builder *b, struct brw_blorp_blit_vars *v,
                           nir_alu_type dst_type,
                           enum blorp_filter filter)
 {
-   /* If non-null, this is the outer-most if statement */
-   nir_if *outer_if = NULL;
-
    nir_variable *color =
       nir_local_variable_create(b->impl, glsl_vec4_type(), "color");
 
@@ -603,6 +600,10 @@ blorp_nir_combine_samples(nir_builder *b, struct brw_blorp_blit_vars *v,
       unreachable("Invalid filter");
    }
 
+   /* If true, we inserted an if statement that we need to pop at at the end.
+    */
+   bool inserted_if = false;
+
    /* We add together samples using a binary tree structure, e.g. for 4x MSAA:
     *
     *   result = ((sample[0] + sample[1]) + (sample[2] + sample[3])) / 4
@@ -674,15 +675,11 @@ blorp_nir_combine_samples(nir_builder *b, struct brw_blorp_blit_vars *v,
          nir_ssa_def *mcs_clear =
             blorp_nir_mcs_is_clear_color(b, mcs, tex_samples);
 
-         nir_if *if_stmt = nir_if_create(b->shader);
-         if_stmt->condition = nir_src_for_ssa(nir_ior(b, mcs_zero, mcs_clear));
-         nir_cf_node_insert(b->cursor, &if_stmt->cf_node);
-
-         b->cursor = nir_after_cf_list(&if_stmt->then_list);
+         nir_push_if(b, nir_ior(b, mcs_zero, mcs_clear));
          nir_store_var(b, color, texture_data[0], 0xf);
 
-         b->cursor = nir_after_cf_list(&if_stmt->else_list);
-         outer_if = if_stmt;
+         nir_push_else(b, NULL);
+         inserted_if = true;
       }
 
       for (int j = 0; j < count_trailing_one_bits(i); j++) {
@@ -708,8 +705,8 @@ blorp_nir_combine_samples(nir_builder *b, struct brw_blorp_blit_vars *v,
 
    nir_store_var(b, color, texture_data[0], 0xf);
 
-   if (outer_if)
-      b->cursor = nir_after_cf_node(&outer_if->cf_node);
+   if (inserted_if)
+      nir_pop_if(b, NULL);
 
    return nir_load_var(b, color);
 }
index 174cf6e..ac2a90b 100644 (file)
@@ -100,12 +100,7 @@ emit_quads_workaround(nir_builder *b, nir_block *block)
        nir_ior(b, nir_bany(b, nir_flt(b, nir_imm_float(b, 1.0f), outer)),
                   nir_bany(b, nir_flt(b, nir_imm_float(b, 1.0f), inner)));
 
-   nir_if *if_stmt = nir_if_create(b->shader);
-   if_stmt->condition = nir_src_for_ssa(any_greater_than_1);
-   nir_builder_cf_insert(b, &if_stmt->cf_node);
-
-   /* Fill out the new then-block */
-   b->cursor = nir_after_cf_list(&if_stmt->then_list);
+   nir_push_if(b, any_greater_than_1);
 
    inner = nir_bcsel(b, nir_fge(b, nir_imm_float(b, 1.0f), inner),
                         nir_imm_float(b, 2.0f), inner);
@@ -118,6 +113,8 @@ emit_quads_workaround(nir_builder *b, nir_block *block)
    store->src[0] = nir_src_for_ssa(inner);
    store->src[1] = nir_src_for_ssa(nir_imm_int(b, 0));
    nir_builder_instr_insert(b, &store->instr);
+
+   nir_pop_if(b, NULL);
 }
 
 void