vc4: Switch to using nir_load_front_face.
authorEric Anholt <eric@anholt.net>
Tue, 17 May 2016 22:30:59 +0000 (15:30 -0700)
committerEric Anholt <eric@anholt.net>
Wed, 18 May 2016 01:07:39 +0000 (18:07 -0700)
This will be generated by glsl_to_nir, and it turns out that this is a
more code-efficient path than the floating point math, anyway.

No change on shader-db, but drops an instruction in piglit's
glsl-fs-frontfacing.

src/gallium/drivers/vc4/vc4_nir_lower_io.c
src/gallium/drivers/vc4/vc4_program.c

index 261c00dc449640842fab1114ea3f9423dc67bc2f..2b4ad9c5ea6dddd08e0caa02a37a04981fe1009c 100644 (file)
@@ -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);
index 34420aaa97580d70e9fac86c5340b9bd9540c6ce..0a7bcb0374c12fd19577bad1d4c0429ab54e8ef6 100644 (file)
@@ -1387,10 +1387,6 @@ ntq_setup_inputs(struct vc4_compile *c)
                 if (c->stage == QSTAGE_FRAG) {
                         if (var->data.location == VARYING_SLOT_POS) {
                                 emit_fragcoord_input(c, loc);
-                        } else if (var->data.location == VARYING_SLOT_FACE) {
-                                c->inputs[loc * 4 + 0] =
-                                        qir_ITOF(c, qir_reg(QFILE_FRAG_REV_FLAG,
-                                                            0));
                         } else if (var->data.location >= VARYING_SLOT_VAR0 &&
                                    (c->fs_key->point_sprite_mask &
                                     (1 << (var->data.location -
@@ -1546,6 +1542,15 @@ ntq_emit_intrinsic(struct vc4_compile *c, nir_intrinsic_instr *instr)
                 *dest = qir_uniform(c, QUNIFORM_SAMPLE_MASK, 0);
                 break;
 
+        case nir_intrinsic_load_front_face:
+                /* The register contains 0 (front) or 1 (back), and we need to
+                 * turn it into a NIR bool where true means front.
+                 */
+                *dest = qir_ADD(c,
+                                qir_uniform_ui(c, -1),
+                                qir_reg(QFILE_FRAG_REV_FLAG, 0));
+                break;
+
         case nir_intrinsic_load_input:
                 assert(instr->num_components == 1);
                 const_offset = nir_src_as_const_value(instr->src[0]);