[Mesa-dev] [PATCH 1/2] i965/nir: Factor out code to convert a nir_src to a flag register

Jason Ekstrand jason at jlekstrand.net
Mon Mar 16 21:21:39 PDT 2015


---
 src/mesa/drivers/dri/i965/brw_fs.h       |  1 +
 src/mesa/drivers/dri/i965/brw_fs_nir.cpp | 16 ++++++++++------
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h
index 08c2b89..105973e 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.h
+++ b/src/mesa/drivers/dri/i965/brw_fs.h
@@ -364,6 +364,7 @@ public:
    void nir_emit_texture(nir_tex_instr *instr);
    void nir_emit_jump(nir_jump_instr *instr);
    fs_reg get_nir_src(nir_src src, brw_reg_type type);
+   void get_nir_src_as_flag(nir_src src, unsigned comp);
    fs_reg get_nir_dest(nir_dest dest);
    void emit_percomp(fs_inst *inst, unsigned wr_mask);
 
diff --git a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
index 4ca07e3..492767b 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
@@ -506,10 +506,7 @@ fs_visitor::nir_emit_cf_list(exec_list *list)
 void
 fs_visitor::nir_emit_if(nir_if *if_stmt)
 {
-   /* first, put the condition into f0 */
-   fs_inst *inst = emit(MOV(reg_null_d, get_nir_src(if_stmt->condition,
-                                                    BRW_REGISTER_TYPE_UD)));
-   inst->conditional_mod = BRW_CONDITIONAL_NZ;
+   get_nir_src_as_flag(if_stmt->condition, 0);
 
    emit(IF(BRW_PREDICATE_NORMAL));
 
@@ -1247,8 +1244,7 @@ fs_visitor::nir_emit_alu(nir_alu_instr *instr)
    case nir_op_bcsel:
       if (optimize_frontfacing_ternary(instr, result))
          return;
-
-      emit(CMP(reg_null_d, op[0], fs_reg(0), BRW_CONDITIONAL_NZ));
+      get_nir_src_as_flag(instr->src[0].src, instr->src[0].swizzle[0]);
       inst = emit(SEL(result, op[1], op[2]));
       inst->predicate = BRW_PREDICATE_NORMAL;
       break;
@@ -1287,6 +1283,14 @@ fs_visitor::get_nir_src(nir_src src, brw_reg_type type)
    }
 }
 
+void
+fs_visitor::get_nir_src_as_flag(nir_src src, unsigned comp)
+{
+   fs_reg cond_src = get_nir_src(src, BRW_REGISTER_TYPE_UD);
+   fs_inst *inst = emit(MOV(reg_null_d, offset(cond_src, comp)));
+   inst->conditional_mod = BRW_CONDITIONAL_NZ;
+}
+
 fs_reg
 fs_visitor::get_nir_dest(nir_dest dest)
 {
-- 
2.3.2



More information about the mesa-dev mailing list