glsl: Handle conditional discards in lower_discard_flow().
authorKenneth Graunke <kenneth@whitecape.org>
Tue, 24 Feb 2015 07:12:39 +0000 (23:12 -0800)
committerKenneth Graunke <kenneth@whitecape.org>
Tue, 24 Feb 2015 23:24:52 +0000 (15:24 -0800)
This pass wasn't prepared to handle conditional discards.

Instead of initializing the "discarded" temporary to "true", set it to
the condition.  Then, refer to the variable for the condition, to avoid
duplicating the expression tree.

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/lower_discard_flow.cpp

index 1bc56d79e988810dc8647f5ad6007860c11fa4e2..ee45bf2215580d60e8e085f447ea634d6b2ff438 100644 (file)
@@ -90,7 +90,14 @@ ir_visitor_status
 lower_discard_flow_visitor::visit_enter(ir_discard *ir)
 {
    ir_dereference *lhs = new(mem_ctx) ir_dereference_variable(discarded);
-   ir_rvalue *rhs = new(mem_ctx) ir_constant(true);
+   ir_rvalue *rhs;
+   if (ir->condition) {
+      /* discarded <- condition, use (var_ref discarded) as the condition */
+      rhs = ir->condition;
+      ir->condition = new(mem_ctx) ir_dereference_variable(discarded);
+   } else {
+      rhs = new(mem_ctx) ir_constant(true);
+   }
    ir_assignment *assign = new(mem_ctx) ir_assignment(lhs, rhs);
    ir->insert_before(assign);