i965/blorp: wrap brw_IF/ELSE/ENDIF() into eu-emitter
[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_context.h"
28 #include "brw_eu.h"
29
30 class brw_blorp_eu_emitter
31 {
32 protected:
33 explicit brw_blorp_eu_emitter(struct brw_context *brw);
34 ~brw_blorp_eu_emitter();
35
36 const unsigned *get_program(unsigned *program_size, FILE *dump_file);
37
38 void emit_kill_if_outside_rect(const struct brw_reg &x,
39 const struct brw_reg &y,
40 const struct brw_reg &dst_x0,
41 const struct brw_reg &dst_x1,
42 const struct brw_reg &dst_y0,
43 const struct brw_reg &dst_y1);
44
45 void emit_texture_lookup(const struct brw_reg &dst,
46 enum opcode op,
47 unsigned base_mrf,
48 unsigned msg_length);
49
50 void emit_render_target_write(const struct brw_reg &src0,
51 unsigned msg_reg_nr,
52 unsigned msg_length,
53 bool use_header);
54
55 void emit_combine(enum opcode combine_opcode,
56 const struct brw_reg &dst,
57 const struct brw_reg &src_1,
58 const struct brw_reg &src_2);
59
60 inline void emit_cond_mov(const struct brw_reg &x,
61 const struct brw_reg &y,
62 int op,
63 const struct brw_reg &dst,
64 const struct brw_reg &src)
65 {
66 brw_CMP(&func, vec16(brw_null_reg()), op, x, y);
67 brw_MOV(&func, dst, src);
68 brw_set_predicate_control(&func, BRW_PREDICATE_NONE);
69 }
70
71 inline void emit_if_eq_mov(const struct brw_reg &x, unsigned y,
72 const struct brw_reg &dst, unsigned src)
73 {
74 emit_cond_mov(x, brw_imm_d(y), BRW_CONDITIONAL_EQ, dst, brw_imm_d(src));
75 }
76
77 inline void emit_mov(const struct brw_reg& dst, const struct brw_reg& src)
78 {
79 brw_MOV(&func, dst, src);
80 }
81
82 inline void emit_mov_8(const struct brw_reg& dst, const struct brw_reg& src)
83 {
84 brw_set_compression_control(&func, BRW_COMPRESSION_NONE);
85 emit_mov(dst, src);
86 brw_set_compression_control(&func, BRW_COMPRESSION_COMPRESSED);
87 }
88
89 inline void emit_and(const struct brw_reg& dst,
90 const struct brw_reg& src1,
91 const struct brw_reg& src2)
92 {
93 brw_AND(&func, dst, src1, src2);
94 }
95
96 inline void emit_add(const struct brw_reg& dst,
97 const struct brw_reg& src1,
98 const struct brw_reg& src2)
99 {
100 brw_ADD(&func, dst, src1, src2);
101 }
102
103 inline void emit_add_8(const struct brw_reg& dst,
104 const struct brw_reg& src1,
105 const struct brw_reg& src2)
106 {
107 brw_set_compression_control(&func, BRW_COMPRESSION_NONE);
108 emit_add(dst, src1, src2);
109 brw_set_compression_control(&func, BRW_COMPRESSION_COMPRESSED);
110 }
111
112 inline void emit_mul(const struct brw_reg& dst,
113 const struct brw_reg& src1,
114 const struct brw_reg& src2)
115 {
116 brw_MUL(&func, dst, src1, src2);
117 }
118
119 inline void emit_shr(const struct brw_reg& dst,
120 const struct brw_reg& src1,
121 const struct brw_reg& src2)
122 {
123 brw_SHR(&func, dst, src1, src2);
124 }
125
126 inline void emit_shl(const struct brw_reg& dst,
127 const struct brw_reg& src1,
128 const struct brw_reg& src2)
129 {
130 brw_SHL(&func, dst, src1, src2);
131 }
132
133 inline void emit_or(const struct brw_reg& dst,
134 const struct brw_reg& src1,
135 const struct brw_reg& src2)
136 {
137 brw_OR(&func, dst, src1, src2);
138 }
139
140 inline void emit_frc(const struct brw_reg& dst,
141 const struct brw_reg& src)
142 {
143 brw_FRC(&func, dst, src);
144 }
145
146 inline void emit_rndd(const struct brw_reg& dst,
147 const struct brw_reg& src)
148 {
149 brw_RNDD(&func, dst, src);
150 }
151
152 inline void emit_cmp_if(int op,
153 const struct brw_reg &x,
154 const struct brw_reg &y)
155 {
156 brw_CMP(&func, vec16(brw_null_reg()), op, x, y);
157 brw_IF(&func, BRW_EXECUTE_16);
158 }
159
160 inline void emit_else(void)
161 {
162 brw_ELSE(&func);
163 }
164
165 inline void emit_endif(void)
166 {
167 brw_ENDIF(&func);
168 }
169
170 void *mem_ctx;
171 struct brw_compile func;
172 };
173
174 #endif /* BRW_BLORP_BLIT_EU_H */