g3dvl: Use sobel filter for chroma interpolation
[mesa/nouveau-pmpeg.git] / src / glsl / ir_hv_accept.cpp
blob0e78fda81fdd4ed27db4f1723870dd00d624bf9c
1 /*
2 * Copyright © 2010 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 #include "ir.h"
26 /**
27 * \file ir_hv_accept.cpp
28 * Implementations of all hierarchical visitor accept methods for IR
29 * instructions.
32 /**
33 * Process a list of nodes using a hierarchical vistor.
35 * If statement_list is true (the default), this is a list of statements, so
36 * v->base_ir will be set to point to each statement just before iterating
37 * over it, and restored after iteration is complete. If statement_list is
38 * false, this is a list that appears inside a statement (e.g. a parameter
39 * list), so v->base_ir will be left alone.
41 * \warning
42 * This function will operate correctly if a node being processed is removed
43 * from the list. However, if nodes are added to the list after the node being
44 * processed, some of the added nodes may not be processed.
46 ir_visitor_status
47 visit_list_elements(ir_hierarchical_visitor *v, exec_list *l,
48 bool statement_list)
50 ir_instruction *prev_base_ir = v->base_ir;
52 foreach_list_safe(n, l) {
53 ir_instruction *const ir = (ir_instruction *) n;
54 if (statement_list)
55 v->base_ir = ir;
56 ir_visitor_status s = ir->accept(v);
58 if (s != visit_continue)
59 return s;
61 if (statement_list)
62 v->base_ir = prev_base_ir;
64 return visit_continue;
68 ir_visitor_status
69 ir_variable::accept(ir_hierarchical_visitor *v)
71 return v->visit(this);
75 ir_visitor_status
76 ir_loop::accept(ir_hierarchical_visitor *v)
78 ir_visitor_status s = v->visit_enter(this);
80 if (s != visit_continue)
81 return (s == visit_continue_with_parent) ? visit_continue : s;
83 s = visit_list_elements(v, &this->body_instructions);
84 if (s == visit_stop)
85 return s;
87 if (s != visit_continue_with_parent) {
88 if (this->from) {
89 s = this->from->accept(v);
90 if (s != visit_continue)
91 return (s == visit_continue_with_parent) ? visit_continue : s;
94 if (this->to) {
95 s = this->to->accept(v);
96 if (s != visit_continue)
97 return (s == visit_continue_with_parent) ? visit_continue : s;
100 if (this->increment) {
101 s = this->increment->accept(v);
102 if (s != visit_continue)
103 return (s == visit_continue_with_parent) ? visit_continue : s;
107 return v->visit_leave(this);
111 ir_visitor_status
112 ir_loop_jump::accept(ir_hierarchical_visitor *v)
114 return v->visit(this);
118 ir_visitor_status
119 ir_function_signature::accept(ir_hierarchical_visitor *v)
121 ir_visitor_status s = v->visit_enter(this);
122 if (s != visit_continue)
123 return (s == visit_continue_with_parent) ? visit_continue : s;
125 s = visit_list_elements(v, &this->parameters);
126 if (s == visit_stop)
127 return s;
129 s = visit_list_elements(v, &this->body);
130 return (s == visit_stop) ? s : v->visit_leave(this);
134 ir_visitor_status
135 ir_function::accept(ir_hierarchical_visitor *v)
137 ir_visitor_status s = v->visit_enter(this);
138 if (s != visit_continue)
139 return (s == visit_continue_with_parent) ? visit_continue : s;
141 s = visit_list_elements(v, &this->signatures, false);
142 return (s == visit_stop) ? s : v->visit_leave(this);
146 ir_visitor_status
147 ir_expression::accept(ir_hierarchical_visitor *v)
149 ir_visitor_status s = v->visit_enter(this);
151 if (s != visit_continue)
152 return (s == visit_continue_with_parent) ? visit_continue : s;
154 for (unsigned i = 0; i < this->get_num_operands(); i++) {
155 switch (this->operands[i]->accept(v)) {
156 case visit_continue:
157 break;
159 case visit_continue_with_parent:
160 // I wish for Java's labeled break-statement here.
161 goto done;
163 case visit_stop:
164 return s;
168 done:
169 return v->visit_leave(this);
172 ir_visitor_status
173 ir_texture::accept(ir_hierarchical_visitor *v)
175 ir_visitor_status s = v->visit_enter(this);
176 if (s != visit_continue)
177 return (s == visit_continue_with_parent) ? visit_continue : s;
179 s = this->sampler->accept(v);
180 if (s != visit_continue)
181 return (s == visit_continue_with_parent) ? visit_continue : s;
183 if (this->coordinate) {
184 s = this->coordinate->accept(v);
185 if (s != visit_continue)
186 return (s == visit_continue_with_parent) ? visit_continue : s;
189 if (this->projector) {
190 s = this->projector->accept(v);
191 if (s != visit_continue)
192 return (s == visit_continue_with_parent) ? visit_continue : s;
195 if (this->shadow_comparitor) {
196 s = this->shadow_comparitor->accept(v);
197 if (s != visit_continue)
198 return (s == visit_continue_with_parent) ? visit_continue : s;
201 if (this->offset) {
202 s = this->offset->accept(v);
203 if (s != visit_continue)
204 return (s == visit_continue_with_parent) ? visit_continue : s;
207 switch (this->op) {
208 case ir_tex:
209 break;
210 case ir_txb:
211 s = this->lod_info.bias->accept(v);
212 if (s != visit_continue)
213 return (s == visit_continue_with_parent) ? visit_continue : s;
214 break;
215 case ir_txl:
216 case ir_txf:
217 case ir_txs:
218 s = this->lod_info.lod->accept(v);
219 if (s != visit_continue)
220 return (s == visit_continue_with_parent) ? visit_continue : s;
221 break;
222 case ir_txd:
223 s = this->lod_info.grad.dPdx->accept(v);
224 if (s != visit_continue)
225 return (s == visit_continue_with_parent) ? visit_continue : s;
227 s = this->lod_info.grad.dPdy->accept(v);
228 if (s != visit_continue)
229 return (s == visit_continue_with_parent) ? visit_continue : s;
230 break;
233 return (s == visit_stop) ? s : v->visit_leave(this);
237 ir_visitor_status
238 ir_swizzle::accept(ir_hierarchical_visitor *v)
240 ir_visitor_status s = v->visit_enter(this);
241 if (s != visit_continue)
242 return (s == visit_continue_with_parent) ? visit_continue : s;
244 s = this->val->accept(v);
245 return (s == visit_stop) ? s : v->visit_leave(this);
249 ir_visitor_status
250 ir_dereference_variable::accept(ir_hierarchical_visitor *v)
252 return v->visit(this);
256 ir_visitor_status
257 ir_dereference_array::accept(ir_hierarchical_visitor *v)
259 ir_visitor_status s = v->visit_enter(this);
260 if (s != visit_continue)
261 return (s == visit_continue_with_parent) ? visit_continue : s;
263 /* The array index is not the target of the assignment, so clear the
264 * 'in_assignee' flag. Restore it after returning from the array index.
266 const bool was_in_assignee = v->in_assignee;
267 v->in_assignee = false;
268 s = this->array_index->accept(v);
269 v->in_assignee = was_in_assignee;
271 if (s != visit_continue)
272 return (s == visit_continue_with_parent) ? visit_continue : s;
274 s = this->array->accept(v);
275 return (s == visit_stop) ? s : v->visit_leave(this);
279 ir_visitor_status
280 ir_dereference_record::accept(ir_hierarchical_visitor *v)
282 ir_visitor_status s = v->visit_enter(this);
283 if (s != visit_continue)
284 return (s == visit_continue_with_parent) ? visit_continue : s;
286 s = this->record->accept(v);
287 return (s == visit_stop) ? s : v->visit_leave(this);
291 ir_visitor_status
292 ir_assignment::accept(ir_hierarchical_visitor *v)
294 ir_visitor_status s = v->visit_enter(this);
295 if (s != visit_continue)
296 return (s == visit_continue_with_parent) ? visit_continue : s;
298 v->in_assignee = true;
299 s = this->lhs->accept(v);
300 v->in_assignee = false;
301 if (s != visit_continue)
302 return (s == visit_continue_with_parent) ? visit_continue : s;
304 s = this->rhs->accept(v);
305 if (s != visit_continue)
306 return (s == visit_continue_with_parent) ? visit_continue : s;
308 if (this->condition)
309 s = this->condition->accept(v);
311 return (s == visit_stop) ? s : v->visit_leave(this);
315 ir_visitor_status
316 ir_constant::accept(ir_hierarchical_visitor *v)
318 return v->visit(this);
322 ir_visitor_status
323 ir_call::accept(ir_hierarchical_visitor *v)
325 ir_visitor_status s = v->visit_enter(this);
326 if (s != visit_continue)
327 return (s == visit_continue_with_parent) ? visit_continue : s;
329 s = visit_list_elements(v, &this->actual_parameters, false);
330 if (s == visit_stop)
331 return s;
333 return v->visit_leave(this);
337 ir_visitor_status
338 ir_return::accept(ir_hierarchical_visitor *v)
340 ir_visitor_status s = v->visit_enter(this);
341 if (s != visit_continue)
342 return (s == visit_continue_with_parent) ? visit_continue : s;
344 ir_rvalue *val = this->get_value();
345 if (val) {
346 s = val->accept(v);
347 if (s != visit_continue)
348 return (s == visit_continue_with_parent) ? visit_continue : s;
351 return v->visit_leave(this);
355 ir_visitor_status
356 ir_discard::accept(ir_hierarchical_visitor *v)
358 ir_visitor_status s = v->visit_enter(this);
359 if (s != visit_continue)
360 return (s == visit_continue_with_parent) ? visit_continue : s;
362 if (this->condition != NULL) {
363 s = this->condition->accept(v);
364 if (s != visit_continue)
365 return (s == visit_continue_with_parent) ? visit_continue : s;
368 return v->visit_leave(this);
372 ir_visitor_status
373 ir_if::accept(ir_hierarchical_visitor *v)
375 ir_visitor_status s = v->visit_enter(this);
376 if (s != visit_continue)
377 return (s == visit_continue_with_parent) ? visit_continue : s;
379 s = this->condition->accept(v);
380 if (s != visit_continue)
381 return (s == visit_continue_with_parent) ? visit_continue : s;
383 if (s != visit_continue_with_parent) {
384 s = visit_list_elements(v, &this->then_instructions);
385 if (s == visit_stop)
386 return s;
389 if (s != visit_continue_with_parent) {
390 s = visit_list_elements(v, &this->else_instructions);
391 if (s == visit_stop)
392 return s;
395 return v->visit_leave(this);