From: Eric Anholt Date: Tue, 17 May 2016 22:30:59 +0000 (-0700) Subject: vc4: Switch to using nir_load_front_face. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=62087cb9b80c271139370a242841def40cfdabae;p=mesa.git vc4: Switch to using nir_load_front_face. 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. --- diff --git a/src/gallium/drivers/vc4/vc4_nir_lower_io.c b/src/gallium/drivers/vc4/vc4_nir_lower_io.c index 261c00dc449..2b4ad9c5ea6 100644 --- a/src/gallium/drivers/vc4/vc4_nir_lower_io.c +++ b/src/gallium/drivers/vc4/vc4_nir_lower_io.c @@ -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); diff --git a/src/gallium/drivers/vc4/vc4_program.c b/src/gallium/drivers/vc4/vc4_program.c index 34420aaa975..0a7bcb0374c 100644 --- a/src/gallium/drivers/vc4/vc4_program.c +++ b/src/gallium/drivers/vc4/vc4_program.c @@ -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]);