2 * Copyright © 2013 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
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.
25 * \file lower_offset_array.cpp
27 * IR lower pass to decompose ir_texture ir_tg4 with an array of offsets
28 * into four ir_tg4s with a single ivec2 offset, select the .w component of each,
29 * and return those four values packed into a gvec4.
31 * \author Chris Forbes <chrisf@ijw.co.nz>
34 #include "glsl_types.h"
36 #include "ir_builder.h"
37 #include "ir_optimization.h"
38 #include "ir_rvalue_visitor.h"
40 using namespace ir_builder
;
42 class lower_offset_array_visitor
: public ir_rvalue_visitor
{
44 lower_offset_array_visitor()
49 void handle_rvalue(ir_rvalue
**rv
);
55 lower_offset_array_visitor::handle_rvalue(ir_rvalue
**rv
)
57 if (*rv
== NULL
|| (*rv
)->ir_type
!= ir_type_texture
)
60 ir_texture
*ir
= (ir_texture
*) *rv
;
61 if (ir
->op
!= ir_tg4
|| !ir
->offset
|| !ir
->offset
->type
->is_array())
64 void *mem_ctx
= ralloc_parent(ir
);
67 new (mem_ctx
) ir_variable(ir
->type
, "result", ir_var_temporary
);
68 base_ir
->insert_before(var
);
70 for (int i
= 0; i
< 4; i
++) {
71 ir_texture
*tex
= ir
->clone(mem_ctx
, NULL
);
72 tex
->offset
= new (mem_ctx
) ir_dereference_array(tex
->offset
,
73 new (mem_ctx
) ir_constant(i
));
75 base_ir
->insert_before(assign(var
, swizzle_w(tex
), 1 << i
));
78 *rv
= new (mem_ctx
) ir_dereference_variable(var
);
84 lower_offset_arrays(exec_list
*instructions
)
86 lower_offset_array_visitor v
;
88 visit_list_elements(&v
, instructions
);