8ed6d6b38a5934c4d8c378544c2820c76f07ec45
[mesa.git] / src / mesa / drivers / dri / i965 / brw_blorp_blit_eu.h
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 DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #ifndef BRW_BLORP_BLIT_EU_H
25 #define BRW_BLORP_BLIT_EU_H
26
27 #include "brw_fs.h"
28
29 class brw_blorp_eu_emitter
30 {
31 protected:
32 explicit brw_blorp_eu_emitter(struct brw_context *brw, bool debug_flag);
33 ~brw_blorp_eu_emitter();
34
35 const unsigned *get_program(unsigned *program_size);
36
37 void emit_kill_if_outside_rect(const struct brw_reg &x,
38 const struct brw_reg &y,
39 const struct brw_reg &dst_x0,
40 const struct brw_reg &dst_x1,
41 const struct brw_reg &dst_y0,
42 const struct brw_reg &dst_y1);
43
44 void emit_texture_lookup(const struct brw_reg &dst,
45 enum opcode op,
46 unsigned base_mrf,
47 unsigned msg_length);
48
49 void emit_render_target_write(const struct brw_reg &src0,
50 int msg_reg_nr,
51 unsigned msg_length,
52 bool use_header);
53
54 void emit_combine(enum opcode combine_opcode,
55 const struct brw_reg &dst,
56 const struct brw_reg &src_1,
57 const struct brw_reg &src_2);
58
59 inline void emit_cond_mov(const struct brw_reg &x,
60 const struct brw_reg &y,
61 enum brw_conditional_mod op,
62 const struct brw_reg &dst,
63 const struct brw_reg &src)
64 {
65 emit_cmp(op, x, y);
66
67 fs_inst *mv = new (mem_ctx) fs_inst(BRW_OPCODE_MOV, 16, dst, src);
68 mv->predicate = BRW_PREDICATE_NORMAL;
69 insts.push_tail(mv);
70 }
71
72 inline void emit_if_eq_mov(const struct brw_reg &x, unsigned y,
73 const struct brw_reg &dst, unsigned src)
74 {
75 emit_cond_mov(x, brw_imm_d(y), BRW_CONDITIONAL_EQ, dst, brw_imm_d(src));
76 }
77
78 inline void emit_lrp(const struct brw_reg &dst,
79 const struct brw_reg &src1,
80 const struct brw_reg &src2,
81 const struct brw_reg &src3)
82 {
83 insts.push_tail(
84 new (mem_ctx) fs_inst(BRW_OPCODE_LRP, 16, dst, src1, src2, src3));
85 }
86
87 inline void emit_mad(const struct brw_reg &dst,
88 const struct brw_reg &src1,
89 const struct brw_reg &src2,
90 const struct brw_reg &src3)
91 {
92 insts.push_tail(
93 new (mem_ctx) fs_inst(BRW_OPCODE_MAD, 16, dst, src1, src2, src3));
94 }
95
96 inline void emit_min(const struct brw_reg& dst,
97 const struct brw_reg& src1,
98 const struct brw_reg& src2)
99 {
100 fs_inst *inst = new (mem_ctx) fs_inst(BRW_OPCODE_SEL, 16, dst, src1, src2);
101 inst->conditional_mod = BRW_CONDITIONAL_L;
102 insts.push_tail(inst);
103 }
104
105 inline void emit_max(const struct brw_reg& dst,
106 const struct brw_reg& src1,
107 const struct brw_reg& src2)
108 {
109 fs_inst *inst = new (mem_ctx) fs_inst(BRW_OPCODE_SEL, 16, dst, src1, src2);
110 inst->conditional_mod = BRW_CONDITIONAL_GE;
111 insts.push_tail(inst);
112 }
113
114 inline void emit_mov(const struct brw_reg& dst, const struct brw_reg& src)
115 {
116 insts.push_tail(new (mem_ctx) fs_inst(BRW_OPCODE_MOV, 16, dst, src));
117 }
118
119 inline void emit_mov_8(const struct brw_reg& dst, const struct brw_reg& src)
120 {
121 insts.push_tail(new (mem_ctx) fs_inst(BRW_OPCODE_MOV, 8, dst, src));
122 }
123
124 inline void emit_and(const struct brw_reg& dst,
125 const struct brw_reg& src1,
126 const struct brw_reg& src2)
127 {
128 insts.push_tail(new (mem_ctx) fs_inst(BRW_OPCODE_AND, 16, dst, src1, src2));
129 }
130
131 inline void emit_add(const struct brw_reg& dst,
132 const struct brw_reg& src1,
133 const struct brw_reg& src2)
134 {
135 insts.push_tail(new (mem_ctx) fs_inst(BRW_OPCODE_ADD, 16, dst, src1, src2));
136 }
137
138 inline void emit_add_8(const struct brw_reg& dst,
139 const struct brw_reg& src1,
140 const struct brw_reg& src2)
141 {
142 insts.push_tail(new (mem_ctx) fs_inst(BRW_OPCODE_ADD, 8, dst, src1, src2));
143 }
144
145 inline void emit_mul(const struct brw_reg& dst,
146 const struct brw_reg& src1,
147 const struct brw_reg& src2)
148 {
149 insts.push_tail(new (mem_ctx) fs_inst(BRW_OPCODE_MUL, 16, dst, src1, src2));
150 }
151
152 inline void emit_shr(const struct brw_reg& dst,
153 const struct brw_reg& src1,
154 const struct brw_reg& src2)
155 {
156 insts.push_tail(new (mem_ctx) fs_inst(BRW_OPCODE_SHR, 16, dst, src1, src2));
157 }
158
159 inline void emit_shl(const struct brw_reg& dst,
160 const struct brw_reg& src1,
161 const struct brw_reg& src2)
162 {
163 insts.push_tail(new (mem_ctx) fs_inst(BRW_OPCODE_SHL, 16, dst, src1, src2));
164 }
165
166 inline void emit_or(const struct brw_reg& dst,
167 const struct brw_reg& src1,
168 const struct brw_reg& src2)
169 {
170 insts.push_tail(new (mem_ctx) fs_inst(BRW_OPCODE_OR, 16, dst, src1, src2));
171 }
172
173 inline void emit_frc(const struct brw_reg& dst,
174 const struct brw_reg& src)
175 {
176 insts.push_tail(new (mem_ctx) fs_inst(BRW_OPCODE_FRC, 16, dst, src));
177 }
178
179 inline void emit_rndd(const struct brw_reg& dst,
180 const struct brw_reg& src)
181 {
182 insts.push_tail(new (mem_ctx) fs_inst(BRW_OPCODE_RNDD, 16, dst, src));
183 }
184
185 inline void emit_cmp_if(enum brw_conditional_mod op,
186 const struct brw_reg &x,
187 const struct brw_reg &y)
188 {
189 emit_cmp(op, x, y);
190 insts.push_tail(new (mem_ctx) fs_inst(BRW_OPCODE_IF, 16));
191 }
192
193 inline void emit_else(void)
194 {
195 insts.push_tail(new (mem_ctx) fs_inst(BRW_OPCODE_ELSE, 16));
196 }
197
198 inline void emit_endif(void)
199 {
200 insts.push_tail(new (mem_ctx) fs_inst(BRW_OPCODE_ENDIF, 16));
201 }
202
203 private:
204 fs_inst *emit_cmp(enum brw_conditional_mod op, const struct brw_reg &x,
205 const struct brw_reg &y);
206
207 void *mem_ctx;
208 exec_list insts;
209 fs_generator generator;
210 };
211
212 #endif /* BRW_BLORP_BLIT_EU_H */