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 brw_lower_unnormalized_offset.cpp
27 * IR lower pass to convert a texture offset into an adjusted coordinate,
28 * for use with unnormalized coordinates. At least the gather4* messages
29 * on Ivybridge and Haswell make a mess with nonzero offsets.
31 * \author Chris Forbes <chrisf@ijw.co.nz>
34 #include "glsl/glsl_types.h"
36 #include "glsl/ir_builder.h"
38 using namespace ir_builder
;
40 class brw_lower_unnormalized_offset_visitor
: public ir_hierarchical_visitor
{
42 brw_lower_unnormalized_offset_visitor()
47 ir_visitor_status
visit_leave(ir_texture
*ir
);
53 brw_lower_unnormalized_offset_visitor::visit_leave(ir_texture
*ir
)
56 return visit_continue
;
58 if (ir
->op
== ir_tg4
|| ir
->op
== ir_tex
) {
59 if (ir
->sampler
->type
->sampler_dimensionality
!= GLSL_SAMPLER_DIM_RECT
)
60 return visit_continue
;
62 else if (ir
->op
!= ir_txf
) {
63 return visit_continue
;
66 void *mem_ctx
= ralloc_parent(ir
);
68 if (ir
->op
== ir_txf
) {
69 /* It appears that the ld instruction used for txf does its
70 * address bounds check before adding in the offset. To work
71 * around this, just add the integer offset to the integer texel
72 * coordinate, and don't put the offset in the header.
74 ir_variable
*var
= new(mem_ctx
) ir_variable(ir
->coordinate
->type
,
77 base_ir
->insert_before(var
);
78 base_ir
->insert_before(assign(var
, ir
->coordinate
));
79 base_ir
->insert_before(assign(var
,
80 add(swizzle_for_size(var
, ir
->offset
->type
->vector_elements
), ir
->offset
),
81 (1 << ir
->offset
->type
->vector_elements
) - 1));
83 ir
->coordinate
= new(mem_ctx
) ir_dereference_variable(var
);
85 ir
->coordinate
= add(ir
->coordinate
, i2f(ir
->offset
));
91 return visit_continue
;
97 brw_do_lower_unnormalized_offset(exec_list
*instructions
)
99 brw_lower_unnormalized_offset_visitor v
;
101 visit_list_elements(&v
, instructions
);