[Mesa-dev] [PATCH 08/20] nir: Add intrinsics from ARB_shader_ballot

Matt Turner mattst88 at gmail.com
Thu Jul 6 23:48:18 UTC 2017


---
 src/compiler/glsl/glsl_to_nir.cpp | 45 +++++++++++++++++++++++++++++++++++++++
 src/compiler/nir/nir_intrinsics.h | 13 +++++++++++
 2 files changed, 58 insertions(+)

diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp
index 43d7e07042..23632f27c2 100644
--- a/src/compiler/glsl/glsl_to_nir.cpp
+++ b/src/compiler/glsl/glsl_to_nir.cpp
@@ -808,6 +808,15 @@ nir_visitor::visit(ir_call *ir)
       case ir_intrinsic_vote_eq:
          op = nir_intrinsic_vote_eq;
          break;
+      case ir_intrinsic_ballot:
+         op = nir_intrinsic_ballot;
+         break;
+      case ir_intrinsic_read_invocation:
+         op = nir_intrinsic_read_invocation;
+         break;
+      case ir_intrinsic_read_first_invocation:
+         op = nir_intrinsic_read_first_invocation;
+         break;
       default:
          unreachable("not reached");
       }
@@ -1150,6 +1159,42 @@ nir_visitor::visit(ir_call *ir)
          nir_ssa_dest_init(&instr->instr, &instr->dest, 1, 32, NULL);
 
          instr->variables[0] = evaluate_deref(&instr->instr, ir->return_deref);
+         ir_instruction *value = (ir_instruction *)ir->actual_parameters.get_head();
+
+         instr->src[0] = nir_src_for_ssa(evaluate_rvalue(value->as_rvalue()));
+
+         nir_builder_instr_insert(&b, &instr->instr);
+         break;
+      }
+
+      case nir_intrinsic_ballot: {
+         nir_ssa_dest_init(&instr->instr, &instr->dest,
+                           ir->return_deref->type->vector_elements, 64, NULL);
+
+         ir_instruction *value = (ir_instruction *)ir->actual_parameters.get_head();
+         instr->src[0] = nir_src_for_ssa(evaluate_rvalue(value->as_rvalue()));
+
+         nir_builder_instr_insert(&b, &instr->instr);
+         break;
+      }
+      case nir_intrinsic_read_invocation: {
+         nir_ssa_dest_init(&instr->instr, &instr->dest,
+                           ir->return_deref->type->vector_elements, 32, NULL);
+         instr->num_components = ir->return_deref->type->vector_elements;
+
+         ir_instruction *value = (ir_instruction *)ir->actual_parameters.get_head();
+         instr->src[0] = nir_src_for_ssa(evaluate_rvalue(value->as_rvalue()));
+
+         ir_instruction *invocation = (ir_instruction *)value->get_next();
+         instr->src[1] = nir_src_for_ssa(evaluate_rvalue(invocation->as_rvalue()));
+
+         nir_builder_instr_insert(&b, &instr->instr);
+         break;
+      }
+      case nir_intrinsic_read_first_invocation: {
+         nir_ssa_dest_init(&instr->instr, &instr->dest,
+                           ir->return_deref->type->vector_elements, 32, NULL);
+         instr->num_components = ir->return_deref->type->vector_elements;
 
          ir_instruction *value = (ir_instruction *)ir->actual_parameters.get_head();
          instr->src[0] = nir_src_for_ssa(evaluate_rvalue(value->as_rvalue()));
diff --git a/src/compiler/nir/nir_intrinsics.h b/src/compiler/nir/nir_intrinsics.h
index 8a838df027..6c6ba4cf59 100644
--- a/src/compiler/nir/nir_intrinsics.h
+++ b/src/compiler/nir/nir_intrinsics.h
@@ -94,6 +94,19 @@ BARRIER(memory_barrier)
 INTRINSIC(shader_clock, 0, ARR(0), true, 2, 0, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
 
 /*
+ * Shader ballot intrinsics with semantics analogous to the
+ *
+ *    ballotARB()
+ *    readInvocationARB()
+ *    readFirstInvocationARB()
+ *
+ * GLSL functions from ARB_shader_ballot.
+ */
+INTRINSIC(ballot, 1, ARR(1), true, 1, 0, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
+INTRINSIC(read_invocation, 2, ARR(0, 1), true, 0, 0, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
+INTRINSIC(read_first_invocation, 1, ARR(0), true, 0, 0, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
+
+/*
  * Memory barrier with semantics analogous to the compute shader
  * groupMemoryBarrier(), memoryBarrierAtomicCounter(), memoryBarrierBuffer(),
  * memoryBarrierImage() and memoryBarrierShared() GLSL intrinsics.
-- 
2.13.0



More information about the mesa-dev mailing list