Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: media-libs/mesa/files/7.9-optimize-discards.patch

Issue 5925002: Switch to Mesa 7.9. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/chromiumos-overlay.git@master
Patch Set: Switch to Mesa 7.9 version 2. Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 Backport of the following to 7.9:
2
3 Module: Mesa
4 Branch: master
5 Commit: 9a1d063c6d679c2155f5eb80f1cb94368d36bf2c
6 URL:
7 http://cgit.freedesktop.org/mesa/mesa/commit/?id=9a1d063c6d679c2155f5eb80f1cb943 68d36bf2c
8
9 Author: Kenneth Graunke <kenn...@whitecape.org>
10 Date: Wed Nov 24 22:02:26 2010 -0800
11
12 glsl: Add an optimization pass to simplify discards.
13
14 NOTE: This is a candidate for the 7.9 branch.
15
16 diff -Naurp Mesa-7.9.orig/src/glsl/Makefile Mesa-7.9.work/src/glsl/Makefile
17 --- Mesa-7.9.orig/src/glsl/Makefile 2010-12-07 18:22:17.511752000 -0800
18 +++ Mesa-7.9.work/src/glsl/Makefile 2010-12-13 10:54:43.571340000 -0800
19 @@ -78,6 +78,7 @@ CXX_SOURCES = \
20 lower_noise.cpp \
21 lower_variable_index_to_cond_assign.cpp \
22 opt_redundant_jumps.cpp \
23 + opt_discard_simplification.cpp \
24 s_expression.cpp
25
26 LIBS = \
27 diff -Naurp Mesa-7.9.orig/src/glsl/SConscript Mesa-7.9.work/src/glsl/SConscript
28 --- Mesa-7.9.orig/src/glsl/SConscript 2010-12-07 18:22:17.518757000 -0800
29 +++ Mesa-7.9.work/src/glsl/SConscript 2010-12-13 10:57:23.191339000 -0800
30 @@ -75,6 +75,7 @@ sources = [
31 'lower_noise.cpp',
32 'lower_variable_index_to_cond_assign.cpp',
33 'opt_redundant_jumps.cpp',
34 + 'opt_discard_simplification.cpp',
35 's_expression.cpp',
36 ]
37
38 diff -Naurp Mesa-7.9.orig/src/glsl/glsl_parser_extras.cpp Mesa-7.9.work/src/glsl /glsl_parser_extras.cpp
39 --- Mesa-7.9.orig/src/glsl/glsl_parser_extras.cpp 2010-12-07 18:22:17.6397 97000 -0800
40 +++ Mesa-7.9.work/src/glsl/glsl_parser_extras.cpp 2010-12-13 10:54:15.4356 25000 -0800
41 @@ -702,6 +702,7 @@ do_common_optimization(exec_list *ir, bo
42 }
43 progress = do_structure_splitting(ir) || progress;
44 progress = do_if_simplification(ir) || progress;
45 + progress = do_discard_simplification(ir) || progress;
46 progress = do_copy_propagation(ir) || progress;
47 if (linked)
48 progress = do_dead_code(ir) || progress;
49 diff -Naurp Mesa-7.9.orig/src/glsl/ir_optimization.h Mesa-7.9.work/src/glsl/ir_o ptimization.h
50 --- Mesa-7.9.orig/src/glsl/ir_optimization.h 2010-12-07 18:22:17.556757000 -0 800
51 +++ Mesa-7.9.work/src/glsl/ir_optimization.h 2010-12-13 10:54:15.445620000 -0 800
52 @@ -45,6 +45,7 @@ bool do_explog_to_explog2(exec_list *ins
53 bool do_function_inlining(exec_list *instructions);
54 bool do_lower_jumps(exec_list *instructions, bool pull_out_jumps = true, bool l ower_sub_return = true, bool lower_main_return = false, bool lower_continue = fa lse, bool lower_break = false);
55 bool do_if_simplification(exec_list *instructions);
56 +bool do_discard_simplification(exec_list *instructions);
57 bool do_if_to_cond_assign(exec_list *instructions);
58 bool do_mat_op_to_vec(exec_list *instructions);
59 bool do_mod_to_fract(exec_list *instructions);
60 diff -Naurp Mesa-7.9.orig/src/glsl/opt_discard_simplification.cpp Mesa-7.9.work/ src/glsl/opt_discard_simplification.cpp
61 --- Mesa-7.9.orig/src/glsl/opt_discard_simplification.cpp 1969-12-31 16:00 :00.000000000 -0800
62 +++ Mesa-7.9.work/src/glsl/opt_discard_simplification.cpp 2010-12-13 10:54 :15.451643000 -0800
63 @@ -0,0 +1,180 @@
64 +/*
65 + * Copyright © 2010 Intel Corporation
66 + *
67 + * Permission is hereby granted, free of charge, to any person obtaining a
68 + * copy of this software and associated documentation files (the "Software"),
69 + * to deal in the Software without restriction, including without limitation
70 + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
71 + * and/or sell copies of the Software, and to permit persons to whom the
72 + * Software is furnished to do so, subject to the following conditions:
73 + *
74 + * The above copyright notice and this permission notice (including the next
75 + * paragraph) shall be included in all copies or substantial portions of the
76 + * Software.
77 + *
78 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
79 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
80 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
81 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
82 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
83 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
84 + * DEALINGS IN THE SOFTWARE.
85 + */
86 +
87 +/**
88 + * \file opt_discard_simplification.cpp
89 + *
90 + * This pass simplifies if-statements and loops containing unconditional
91 + * discards.
92 + *
93 + * Case 1: Both branches contain unconditional discards:
94 + * -----------------------------------------------------
95 + *
96 + * if (cond) {
97 + * s1;
98 + * discard;
99 + * s2;
100 + * } else {
101 + * s3;
102 + * discard;
103 + * s4;
104 + * }
105 + *
106 + * becomes:
107 + *
108 + * discard
109 + *
110 + * Case 2: The "then" clause contains an unconditional discard:
111 + * ------------------------------------------------------------
112 + *
113 + * if (cond) {
114 + * s1;
115 + * discard;
116 + * s2;
117 + * } else {
118 + * s3;
119 + * }
120 + *
121 + * becomes:
122 + *
123 + * if (cond) {
124 + * discard;
125 + * } else {
126 + * s3;
127 + * }
128 + *
129 + * Case 3: The "else" clause contains an unconditional discard:
130 + * ------------------------------------------------------------
131 + *
132 + * if (cond) {
133 + * s1;
134 + * } else {
135 + * s2;
136 + * discard;
137 + * s3;
138 + * }
139 + *
140 + * becomes:
141 + *
142 + * if (cond) {
143 + * s1;
144 + * } else {
145 + * discard;
146 + * }
147 + */
148 +
149 +#include "glsl_types.h"
150 +#include "ir.h"
151 +
152 +class discard_simplifier : public ir_hierarchical_visitor {
153 +public:
154 + discard_simplifier()
155 + {
156 + this->progress = false;
157 + }
158 +
159 + ir_visitor_status visit_enter(ir_if *);
160 + ir_visitor_status visit_enter(ir_loop *);
161 +
162 + bool progress;
163 +};
164 +
165 +static ir_discard *
166 +find_unconditional_discard(exec_list &instructions)
167 +{
168 + foreach_list(n, &instructions) {
169 + ir_discard *ir = ((ir_instruction *) n)->as_discard();
170 + if (ir != NULL && ir->condition == NULL)
171 + return ir;
172 + }
173 + return NULL;
174 +}
175 +
176 +static bool
177 +is_only_instruction(ir_discard *discard)
178 +{
179 + return (discard->prev->is_head_sentinel() &&
180 + discard->next->is_tail_sentinel());
181 +}
182 +
183 +ir_visitor_status
184 +discard_simplifier::visit_enter(ir_if *ir)
185 +{
186 + ir_discard *then_discard = find_unconditional_discard(ir->then_instructions) ;
187 + ir_discard *else_discard = find_unconditional_discard(ir->else_instructions) ;
188 +
189 + if (then_discard == NULL && else_discard == NULL)
190 + return visit_continue;
191 +
192 + /* If both branches result in discard, replace whole if with discard. */
193 + if (then_discard != NULL && else_discard != NULL) {
194 + this->progress = true;
195 + ir->replace_with(then_discard);
196 + return visit_continue_with_parent;
197 + }
198 +
199 + /* Otherwise, one branch has a discard. */
200 + if (then_discard != NULL && !is_only_instruction(then_discard)) {
201 + this->progress = true;
202 + ir->then_instructions.make_empty();
203 + ir->then_instructions.push_tail(then_discard);
204 + } else if (else_discard != NULL && !is_only_instruction(else_discard)) {
205 + this->progress = true;
206 + ir->else_instructions.make_empty();
207 + ir->else_instructions.push_tail(else_discard);
208 + }
209 +
210 + visit_list_elements(this, &ir->then_instructions);
211 + return visit_continue_with_parent;
212 +}
213 +
214 +ir_visitor_status
215 +discard_simplifier::visit_enter(ir_loop *ir)
216 +{
217 + ir_discard *discard = find_unconditional_discard(ir->body_instructions);
218 +
219 + if (discard) {
220 + ir->replace_with(discard);
221 + return visit_continue_with_parent;
222 + }
223 +
224 + return visit_continue;
225 +}
226 +
227 +bool
228 +do_discard_simplification(exec_list *instructions)
229 +{
230 + /* Look for a top-level unconditional discard */
231 + ir_discard *discard = find_unconditional_discard(*instructions);
232 + if (discard != NULL) {
233 + instructions->make_empty();
234 + instructions->push_tail(discard);
235 + return true;
236 + }
237 +
238 + discard_simplifier v;
239 +
240 + visit_list_elements(&v, instructions);
241 +
242 + return v.progress;
243 +}
OLDNEW
« no previous file with comments | « media-libs/mesa/files/7.9-glsl-vector-compare.patch ('k') | media-libs/mesa/files/7.9-remove-discard-from-lower_jumps.patch » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698