[Mesa-dev] [PATCH v5 26/34] nvir/nir: implement vote and ballot

Karol Herbst kherbst at redhat.com
Tue Feb 20 21:02:44 UTC 2018


v2: add vote_eq support
    use the new subop intrinsic helper
    add ballot
v3: add read_(first_)invocation

Signed-off-by: Karol Herbst <kherbst at redhat.com>
---
 .../drivers/nouveau/codegen/nv50_ir_from_nir.cpp   | 41 ++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp
index a563c3e0a2..ad9865159f 100644
--- a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp
+++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp
@@ -433,6 +433,12 @@ int
 Converter::getSubOp(nir_intrinsic_op op)
 {
    switch (op) {
+   case nir_intrinsic_vote_all:
+      return NV50_IR_SUBOP_VOTE_ALL;
+   case nir_intrinsic_vote_any:
+      return NV50_IR_SUBOP_VOTE_ANY;
+   case nir_intrinsic_vote_eq:
+      return NV50_IR_SUBOP_VOTE_UNI;
    default:
       ERROR("couldn't get subop for nir_intrinsic_op %u\n", op);
       assert(false);
@@ -1742,6 +1748,41 @@ Converter::visit(nir_intrinsic_instr *insn)
       loadImm(newDefs[0], 32u);
       break;
    }
+   case nir_intrinsic_vote_all:
+   case nir_intrinsic_vote_any:
+   case nir_intrinsic_vote_eq: {
+      LValues &newDefs = convert(&insn->dest);
+      Value *pred = new_LValue(func, FILE_PREDICATE);
+      mkCmp(OP_SET, CC_NE, TYPE_U32, pred, TYPE_U32, getSrc(&insn->src[0], 0), zero);
+      mkOp1(OP_VOTE, TYPE_U32, pred, pred)->subOp = getSubOp(op);
+      mkCvt(OP_CVT, TYPE_U32, newDefs[0], TYPE_U8, pred);
+      break;
+   }
+   case nir_intrinsic_ballot: {
+      LValues &newDefs = convert(&insn->dest);
+      Value *pred = new_LValue(func, FILE_PREDICATE);
+      mkCmp(OP_SET, CC_NE, TYPE_U32, pred, TYPE_U32, getSrc(&insn->src[0], 0), zero);
+      Instruction *ballot = mkOp1(OP_VOTE, TYPE_U32, getSSA(), pred);
+      ballot->subOp = NV50_IR_SUBOP_VOTE_ANY;
+      mkOp2(OP_MERGE, TYPE_U64, newDefs[0], ballot->getDef(0), loadImm(getSSA(), 0));
+      break;
+   }
+   case nir_intrinsic_read_first_invocation:
+   case nir_intrinsic_read_invocation: {
+      LValues &newDefs = convert(&insn->dest);
+      const DataType dType = getDType(insn);
+      Value *tmp = getScratch();
+
+      if (op == nir_intrinsic_read_first_invocation) {
+         mkOp1(OP_VOTE, TYPE_U32, tmp, mkImm(1))->subOp = NV50_IR_SUBOP_VOTE_ANY;
+         mkOp2(OP_EXTBF, TYPE_U32, tmp, tmp, mkImm(0x2000))->subOp = NV50_IR_SUBOP_EXTBF_REV;
+         mkOp1(OP_BFIND, TYPE_U32, tmp, tmp)->subOp = NV50_IR_SUBOP_BFIND_SAMT;
+      } else
+         tmp = getSrc(&insn->src[1], 0);
+
+      mkOp3(OP_SHFL, dType, newDefs[0], getSrc(&insn->src[0], 0), tmp, mkImm(0x1f))->subOp = NV50_IR_SUBOP_SHFL_IDX;
+      break;
+   }
    default:
       ERROR("unknown nir_intrinsic_op %s\n", nir_intrinsic_infos[op].name);
       return false;
-- 
2.14.3



More information about the mesa-dev mailing list