i965: Use sample barycentric coordinates with per sample shading
[mesa.git] / src / mesa / drivers / dri / i965 / brw_lower_offset_array.cpp
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_offset_array.cpp
26 *
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.
30 *
31 * \author Chris Forbes <chrisf@ijw.co.nz>
32 */
33
34 #include "glsl/glsl_types.h"
35 #include "glsl/ir.h"
36 #include "glsl/ir_builder.h"
37 #include "glsl/ir_rvalue_visitor.h"
38
39 using namespace ir_builder;
40
41 class brw_lower_offset_array_visitor : public ir_rvalue_visitor {
42 public:
43 brw_lower_offset_array_visitor()
44 {
45 progress = false;
46 }
47
48 void handle_rvalue(ir_rvalue **rv);
49
50 bool progress;
51 };
52
53 void
54 brw_lower_offset_array_visitor::handle_rvalue(ir_rvalue **rv)
55 {
56 if (*rv == NULL || (*rv)->ir_type != ir_type_texture)
57 return;
58
59 ir_texture *ir = (ir_texture *) *rv;
60 if (ir->op != ir_tg4 || !ir->offset || !ir->offset->type->is_array())
61 return;
62
63 void *mem_ctx = ralloc_parent(ir);
64
65 ir_variable *var = new (mem_ctx) ir_variable(ir->type, "result", ir_var_auto);
66 base_ir->insert_before(var);
67
68 for (int i = 0; i < 4; i++) {
69 ir_texture *tex = ir->clone(mem_ctx, NULL);
70 tex->offset = new (mem_ctx) ir_dereference_array(tex->offset,
71 new (mem_ctx) ir_constant(i));
72
73 base_ir->insert_before(assign(var, swizzle_w(tex), 1 << i));
74 }
75
76 *rv = new (mem_ctx) ir_dereference_variable(var);
77
78 progress = true;
79 }
80
81 extern "C" {
82
83 bool
84 brw_do_lower_offset_arrays(exec_list *instructions)
85 {
86 brw_lower_offset_array_visitor v;
87
88 visit_list_elements(&v, instructions);
89
90 return v.progress;
91 }
92
93 }