<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 24, 2015 at 2:19 AM, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">st_glsl_to_tgsi and ir_to_mesa have handled conditional discards for a<br>
long time; the previous patch added that capability to i965.<br>
<br>
i965 (Haswell) shader-db stats:<br>
<br>
Without NIR:<br>
total instructions in shared programs: 5792133 -> 5776360 (-0.27%)<br>
instructions in affected programs: 737585 -> 721812 (-2.14%)<br>
helped: 6300<br>
HURT: 68<br>
GAINED: 2<br>
<br>
With NIR:<br>
total instructions in shared programs: 5787538 -> 5769569 (-0.31%)<br>
instructions in affected programs: 767843 -> 749874 (-2.34%)<br>
helped: 6522<br>
HURT: 35<br>
GAINED: 6<br></blockquote><div><br></div><div>What all do you have in that branch? Last I checked (10 minutes ago), NIR wasn't beating GLSL IR yet.<br></div><div>--Jason<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Signed-off-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
---<br>
src/glsl/Makefile.sources | 1 +<br>
src/glsl/glsl_parser_extras.cpp | 1 +<br>
src/glsl/ir_optimization.h | 1 +<br>
src/glsl/opt_conditional_discard.cpp | 81 ++++++++++++++++++++++++++++++++++++<br>
4 files changed, 84 insertions(+)<br>
create mode 100644 src/glsl/opt_conditional_discard.cpp<br>
<br>
diff --git a/src/glsl/Makefile.sources b/src/glsl/Makefile.sources<br>
index d0210d1..b876642 100644<br>
--- a/src/glsl/Makefile.sources<br>
+++ b/src/glsl/Makefile.sources<br>
@@ -157,6 +157,7 @@ LIBGLSL_FILES = \<br>
lower_ubo_reference.cpp \<br>
opt_algebraic.cpp \<br>
opt_array_splitting.cpp \<br>
+ opt_conditional_discard.cpp \<br>
opt_constant_folding.cpp \<br>
opt_constant_propagation.cpp \<br>
opt_constant_variable.cpp \<br>
diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp<br>
index 9f79313..f19804b 100644<br>
--- a/src/glsl/glsl_parser_extras.cpp<br>
+++ b/src/glsl/glsl_parser_extras.cpp<br>
@@ -1627,6 +1627,7 @@ do_common_optimization(exec_list *ir, bool linked,<br>
}<br>
progress = do_if_simplification(ir) || progress;<br>
progress = opt_flatten_nested_if_blocks(ir) || progress;<br>
+ progress = opt_conditional_discard(ir) || progress;<br>
progress = do_copy_propagation(ir) || progress;<br>
progress = do_copy_propagation_elements(ir) || progress;<br>
<br>
diff --git a/src/glsl/ir_optimization.h b/src/glsl/ir_optimization.h<br>
index 7eb861a..e6939f3 100644<br>
--- a/src/glsl/ir_optimization.h<br>
+++ b/src/glsl/ir_optimization.h<br>
@@ -77,6 +77,7 @@ bool do_common_optimization(exec_list *ir, bool linked,<br>
bool do_rebalance_tree(exec_list *instructions);<br>
bool do_algebraic(exec_list *instructions, bool native_integers,<br>
const struct gl_shader_compiler_options *options);<br>
+bool opt_conditional_discard(exec_list *instructions);<br>
bool do_constant_folding(exec_list *instructions);<br>
bool do_constant_variable(exec_list *instructions);<br>
bool do_constant_variable_unlinked(exec_list *instructions);<br>
diff --git a/src/glsl/opt_conditional_discard.cpp b/src/glsl/opt_conditional_discard.cpp<br>
new file mode 100644<br>
index 0000000..0905188<br>
--- /dev/null<br>
+++ b/src/glsl/opt_conditional_discard.cpp<br>
@@ -0,0 +1,81 @@<br>
+/*<br>
+ * Copyright © 2010 Intel Corporation<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
+ * DEALINGS IN THE SOFTWARE.<br>
+ */<br>
+<br>
+/**<br>
+ * \file opt_conditional_discard.cpp<br>
+ *<br>
+ * Replace<br>
+ *<br>
+ * if (cond) discard;<br>
+ *<br>
+ * with<br>
+ *<br>
+ * (discard <condition>)<br>
+ */<br>
+<br>
+#include "glsl_types.h"<br>
+#include "ir.h"<br>
+<br>
+namespace {<br>
+<br>
+class opt_conditional_discard_visitor : public ir_hierarchical_visitor {<br>
+public:<br>
+ opt_conditional_discard_visitor()<br>
+ {<br>
+ progress = false;<br>
+ }<br>
+<br>
+ ir_visitor_status visit_leave(ir_if *);<br>
+<br>
+ bool progress;<br>
+};<br>
+<br>
+} /* anonymous namespace */<br>
+<br>
+bool<br>
+opt_conditional_discard(exec_list *instructions)<br>
+{<br>
+ opt_conditional_discard_visitor v;<br>
+ v.run(instructions);<br>
+ return v.progress;<br>
+}<br>
+<br>
+ir_visitor_status<br>
+opt_conditional_discard_visitor::visit_leave(ir_if *ir)<br>
+{<br>
+ /* Look for "if (...) discard" with no else clause or extra statements. */<br>
+ if (ir->then_instructions.is_empty() ||<br>
+ !ir->then_instructions.head->next->is_tail_sentinel() ||<br>
+ !((ir_instruction *) ir->then_instructions.head)->as_discard() ||<br>
+ !ir->else_instructions.is_empty())<br>
+ return visit_continue;<br>
+<br>
+ /* Move the condition and replace the ir_if with the ir_discard. */<br>
+ ir_discard *discard = (ir_discard *) ir->then_instructions.head;<br>
+ discard->condition = ir->condition;<br>
+ ir->replace_with(discard);<br>
+<br>
+ progress = true;<br>
+<br>
+ return visit_continue;<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.2.2<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>