nir: Introduce nir_intrinsic_discard_if.
authorKenneth Graunke <kenneth@whitecape.org>
Tue, 24 Feb 2015 07:47:00 +0000 (23:47 -0800)
committerKenneth Graunke <kenneth@whitecape.org>
Tue, 24 Feb 2015 23:24:52 +0000 (15:24 -0800)
This is a conditional discard, which takes a boolean source.

Note that we don't generate ir_discard::condition today, so this
shouldn't break drivers (since none implement this intrinsic yet).

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/glsl/nir/glsl_to_nir.cpp
src/glsl/nir/nir_intrinsics.h

index 544d0d93282191872deee22afe3fc51c60177e37..adef19c80a25e9cac8460dfe12ab8d80af55d6cf 100644 (file)
@@ -563,8 +563,14 @@ nir_visitor::visit(ir_discard *ir)
     * discards will be immediately followed by a return.
     */
 
-   nir_intrinsic_instr *discard =
-      nir_intrinsic_instr_create(this->shader, nir_intrinsic_discard);
+   nir_intrinsic_instr *discard;
+   if (ir->condition) {
+      discard = nir_intrinsic_instr_create(this->shader,
+                                           nir_intrinsic_discard_if);
+      discard->src[0] = evaluate_rvalue(ir->condition);
+   } else {
+      discard = nir_intrinsic_instr_create(this->shader, nir_intrinsic_discard);
+   }
    nir_instr_insert_after_cf_list(this->cf_node_list, &discard->instr);
 }
 
index d94866c859737bc37c8c767d6c1758291d227ebd..3bf102fc15ce46c62fec5aae1e22c3aa10f19d72 100644 (file)
@@ -68,6 +68,8 @@ INTRINSIC(interp_var_at_offset, 1, ARR(2), true, 0, 1, 0,
 #define BARRIER(name) INTRINSIC(name, 0, ARR(), false, 0, 0, 0, 0)
 
 BARRIER(discard)
+/** A conditional discard, with a single boolean source. */
+INTRINSIC(discard_if, 1, ARR(1), false, 0, 0, 0, 0)
 
 INTRINSIC(emit_vertex,   0, ARR(), false, 0, 0, 1, 0)
 INTRINSIC(end_primitive, 0, ARR(), false, 0, 0, 1, 0)