Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5564 | serge | 1 | /* |
2 | * Copyright © 2013 Intel Corporation |
||
3 | * |
||
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: |
||
10 | * |
||
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. |
||
14 | * |
||
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. |
||
22 | */ |
||
23 | |||
24 | /** |
||
25 | * \file brw_lower_unnormalized_offset.cpp |
||
26 | * |
||
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. |
||
30 | * |
||
31 | * \author Chris Forbes |
||
32 | */ |
||
33 | |||
34 | #include "glsl/glsl_types.h" |
||
35 | #include "glsl/ir.h" |
||
36 | #include "glsl/ir_builder.h" |
||
37 | |||
38 | using namespace ir_builder; |
||
39 | |||
40 | class brw_lower_unnormalized_offset_visitor : public ir_hierarchical_visitor { |
||
41 | public: |
||
42 | brw_lower_unnormalized_offset_visitor() |
||
43 | { |
||
44 | progress = false; |
||
45 | } |
||
46 | |||
47 | ir_visitor_status visit_leave(ir_texture *ir); |
||
48 | |||
49 | bool progress; |
||
50 | }; |
||
51 | |||
52 | ir_visitor_status |
||
53 | brw_lower_unnormalized_offset_visitor::visit_leave(ir_texture *ir) |
||
54 | { |
||
55 | if (!ir->offset) |
||
56 | return visit_continue; |
||
57 | |||
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; |
||
61 | } |
||
62 | else if (ir->op != ir_txf) { |
||
63 | return visit_continue; |
||
64 | } |
||
65 | |||
66 | void *mem_ctx = ralloc_parent(ir); |
||
67 | |||
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. |
||
73 | */ |
||
74 | ir_variable *var = new(mem_ctx) ir_variable(ir->coordinate->type, |
||
75 | "coordinate", |
||
76 | ir_var_temporary); |
||
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)); |
||
82 | |||
83 | ir->coordinate = new(mem_ctx) ir_dereference_variable(var); |
||
84 | } else { |
||
85 | ir->coordinate = add(ir->coordinate, i2f(ir->offset)); |
||
86 | } |
||
87 | |||
88 | ir->offset = NULL; |
||
89 | |||
90 | progress = true; |
||
91 | return visit_continue; |
||
92 | } |
||
93 | |||
94 | extern "C" { |
||
95 | |||
96 | bool |
||
97 | brw_do_lower_unnormalized_offset(exec_list *instructions) |
||
98 | { |
||
99 | brw_lower_unnormalized_offset_visitor v; |
||
100 | |||
101 | visit_list_elements(&v, instructions); |
||
102 | |||
103 | return v.progress; |
||
104 | } |
||
105 | |||
106 | }><> |