vc4: Implement live intervals using a CFG.
[mesa.git] / src / gallium / drivers / vc4 / vc4_nir_lower_io.c
index d0391c0262e10592412fbe1fb990b195cdc6056c..2b4ad9c5ea6dddd08e0caa02a37a04981fe1009c 100644 (file)
@@ -98,7 +98,7 @@ vc4_nir_get_vattr_channel_vpm(struct vc4_compile *c,
                 &desc->channel[swiz];
         nir_ssa_def *temp;
 
-        if (swiz > UTIL_FORMAT_SWIZZLE_W) {
+        if (swiz > PIPE_SWIZZLE_W) {
                 return vc4_nir_get_swizzled_channel(b, vpm_reads, swiz);
         } else if (chan->size == 32 && chan->type == UTIL_FORMAT_TYPE_FLOAT) {
                 return vc4_nir_get_swizzled_channel(b, vpm_reads, swiz);
@@ -274,11 +274,15 @@ vc4_nir_lower_fs_input(struct vc4_compile *c, nir_builder *b,
         }
 
         if (input_var->data.location == VARYING_SLOT_FACE) {
-                dests[0] = nir_fsub(b,
-                                    nir_imm_float(b, 1.0),
-                                    nir_fmul(b,
-                                             nir_i2f(b, dests[0]),
-                                             nir_imm_float(b, 2.0)));
+                /* TGSI-to-NIR's front face.  Convert to using the system
+                 * value boolean instead.
+                 */
+                nir_ssa_def *face =
+                        nir_load_system_value(b,
+                                              nir_intrinsic_load_front_face,
+                                              0);
+                dests[0] = nir_bcsel(b, face, nir_imm_float(b, 1.0),
+                                     nir_imm_float(b, -1.0));
                 dests[1] = nir_imm_float(b, 0.0);
                 dests[2] = nir_imm_float(b, 0.0);
                 dests[3] = nir_imm_float(b, 1.0);
@@ -428,25 +432,15 @@ vc4_nir_lower_io_instr(struct vc4_compile *c, nir_builder *b,
 }
 
 static bool
-vc4_nir_lower_io_block(nir_block *block, void *arg)
+vc4_nir_lower_io_impl(struct vc4_compile *c, nir_function_impl *impl)
 {
-        struct vc4_compile *c = arg;
-        nir_function_impl *impl =
-                nir_cf_node_get_function(&block->cf_node);
-
         nir_builder b;
         nir_builder_init(&b, impl);
 
-        nir_foreach_instr_safe(block, instr)
-                vc4_nir_lower_io_instr(c, &b, instr);
-
-        return true;
-}
-
-static bool
-vc4_nir_lower_io_impl(struct vc4_compile *c, nir_function_impl *impl)
-{
-        nir_foreach_block(impl, vc4_nir_lower_io_block, c);
+        nir_foreach_block(block, impl) {
+                nir_foreach_instr_safe(instr, block)
+                        vc4_nir_lower_io_instr(c, &b, instr);
+        }
 
         nir_metadata_preserve(impl, nir_metadata_block_index |
                               nir_metadata_dominance);
@@ -455,9 +449,9 @@ vc4_nir_lower_io_impl(struct vc4_compile *c, nir_function_impl *impl)
 }
 
 void
-vc4_nir_lower_io(struct vc4_compile *c)
+vc4_nir_lower_io(nir_shader *s, struct vc4_compile *c)
 {
-        nir_foreach_function(c->s, function) {
+        nir_foreach_function(function, s) {
                 if (function->impl)
                         vc4_nir_lower_io_impl(c, function->impl);
         }