i965: Fix a "discards 'const' qualifier" warning.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_eu.h
1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics to
4 develop this 3D driver.
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial
16 portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **********************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keithw@vmware.com>
30 */
31
32
33 #ifndef BRW_EU_H
34 #define BRW_EU_H
35
36 #include <stdbool.h>
37 #include "brw_structs.h"
38 #include "brw_defines.h"
39 #include "brw_reg.h"
40 #include "program/prog_instruction.h"
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 #define BRW_EU_MAX_INSN_STACK 5
47
48 struct brw_compile {
49 struct brw_instruction *store;
50 int store_size;
51 unsigned nr_insn;
52 unsigned int next_insn_offset;
53
54 void *mem_ctx;
55
56 /* Allow clients to push/pop instruction state:
57 */
58 struct brw_instruction stack[BRW_EU_MAX_INSN_STACK];
59 bool compressed_stack[BRW_EU_MAX_INSN_STACK];
60 struct brw_instruction *current;
61
62 unsigned flag_value;
63 bool single_program_flow;
64 bool compressed;
65 struct brw_context *brw;
66
67 /* Control flow stacks:
68 * - if_stack contains IF and ELSE instructions which must be patched
69 * (and popped) once the matching ENDIF instruction is encountered.
70 *
71 * Just store the instruction pointer(an index).
72 */
73 int *if_stack;
74 int if_stack_depth;
75 int if_stack_array_size;
76
77 /**
78 * loop_stack contains the instruction pointers of the starts of loops which
79 * must be patched (and popped) once the matching WHILE instruction is
80 * encountered.
81 */
82 int *loop_stack;
83 /**
84 * pre-gen6, the BREAK and CONT instructions had to tell how many IF/ENDIF
85 * blocks they were popping out of, to fix up the mask stack. This tracks
86 * the IF/ENDIF nesting in each current nested loop level.
87 */
88 int *if_depth_in_loop;
89 int loop_stack_depth;
90 int loop_stack_array_size;
91 };
92
93 void brw_pop_insn_state( struct brw_compile *p );
94 void brw_push_insn_state( struct brw_compile *p );
95 void brw_set_mask_control( struct brw_compile *p, unsigned value );
96 void brw_set_saturate( struct brw_compile *p, bool enable );
97 void brw_set_access_mode( struct brw_compile *p, unsigned access_mode );
98 void brw_set_compression_control(struct brw_compile *p, enum brw_compression c);
99 void brw_set_predicate_control_flag_value( struct brw_compile *p, unsigned value );
100 void brw_set_predicate_control( struct brw_compile *p, unsigned pc );
101 void brw_set_predicate_inverse(struct brw_compile *p, bool predicate_inverse);
102 void brw_set_conditionalmod( struct brw_compile *p, unsigned conditional );
103 void brw_set_flag_reg(struct brw_compile *p, int reg, int subreg);
104 void brw_set_acc_write_control(struct brw_compile *p, unsigned value);
105
106 void brw_init_compile(struct brw_context *, struct brw_compile *p,
107 void *mem_ctx);
108 void brw_disassemble(struct brw_context *brw, void *assembly,
109 int start, int end, FILE *out);
110 const unsigned *brw_get_program( struct brw_compile *p, unsigned *sz );
111
112 struct brw_instruction *brw_next_insn(struct brw_compile *p, unsigned opcode);
113 void brw_set_dest(struct brw_compile *p, struct brw_instruction *insn,
114 struct brw_reg dest);
115 void brw_set_src0(struct brw_compile *p, struct brw_instruction *insn,
116 struct brw_reg reg);
117
118 void gen6_resolve_implied_move(struct brw_compile *p,
119 struct brw_reg *src,
120 unsigned msg_reg_nr);
121
122 /* Helpers for regular instructions:
123 */
124 #define ALU1(OP) \
125 struct brw_instruction *brw_##OP(struct brw_compile *p, \
126 struct brw_reg dest, \
127 struct brw_reg src0);
128
129 #define ALU2(OP) \
130 struct brw_instruction *brw_##OP(struct brw_compile *p, \
131 struct brw_reg dest, \
132 struct brw_reg src0, \
133 struct brw_reg src1);
134
135 #define ALU3(OP) \
136 struct brw_instruction *brw_##OP(struct brw_compile *p, \
137 struct brw_reg dest, \
138 struct brw_reg src0, \
139 struct brw_reg src1, \
140 struct brw_reg src2);
141
142 #define ROUND(OP) \
143 void brw_##OP(struct brw_compile *p, struct brw_reg dest, struct brw_reg src0);
144
145 ALU1(MOV)
146 ALU2(SEL)
147 ALU1(NOT)
148 ALU2(AND)
149 ALU2(OR)
150 ALU2(XOR)
151 ALU2(SHR)
152 ALU2(SHL)
153 ALU2(ASR)
154 ALU1(F32TO16)
155 ALU1(F16TO32)
156 ALU2(JMPI)
157 ALU2(ADD)
158 ALU2(AVG)
159 ALU2(MUL)
160 ALU1(FRC)
161 ALU1(RNDD)
162 ALU2(MAC)
163 ALU2(MACH)
164 ALU1(LZD)
165 ALU2(DP4)
166 ALU2(DPH)
167 ALU2(DP3)
168 ALU2(DP2)
169 ALU2(LINE)
170 ALU2(PLN)
171 ALU3(MAD)
172 ALU3(LRP)
173 ALU1(BFREV)
174 ALU3(BFE)
175 ALU2(BFI1)
176 ALU3(BFI2)
177 ALU1(FBH)
178 ALU1(FBL)
179 ALU1(CBIT)
180 ALU2(ADDC)
181 ALU2(SUBB)
182 ALU2(MAC)
183
184 ROUND(RNDZ)
185 ROUND(RNDE)
186
187 #undef ALU1
188 #undef ALU2
189 #undef ALU3
190 #undef ROUND
191
192
193 /* Helpers for SEND instruction:
194 */
195 void brw_set_sampler_message(struct brw_compile *p,
196 struct brw_instruction *insn,
197 unsigned binding_table_index,
198 unsigned sampler,
199 unsigned msg_type,
200 unsigned response_length,
201 unsigned msg_length,
202 unsigned header_present,
203 unsigned simd_mode,
204 unsigned return_format);
205
206 void brw_set_dp_read_message(struct brw_compile *p,
207 struct brw_instruction *insn,
208 unsigned binding_table_index,
209 unsigned msg_control,
210 unsigned msg_type,
211 unsigned target_cache,
212 unsigned msg_length,
213 bool header_present,
214 unsigned response_length);
215
216 void brw_set_dp_write_message(struct brw_compile *p,
217 struct brw_instruction *insn,
218 unsigned binding_table_index,
219 unsigned msg_control,
220 unsigned msg_type,
221 unsigned msg_length,
222 bool header_present,
223 unsigned last_render_target,
224 unsigned response_length,
225 unsigned end_of_thread,
226 unsigned send_commit_msg);
227
228 void brw_urb_WRITE(struct brw_compile *p,
229 struct brw_reg dest,
230 unsigned msg_reg_nr,
231 struct brw_reg src0,
232 enum brw_urb_write_flags flags,
233 unsigned msg_length,
234 unsigned response_length,
235 unsigned offset,
236 unsigned swizzle);
237
238 void brw_ff_sync(struct brw_compile *p,
239 struct brw_reg dest,
240 unsigned msg_reg_nr,
241 struct brw_reg src0,
242 bool allocate,
243 unsigned response_length,
244 bool eot);
245
246 void brw_svb_write(struct brw_compile *p,
247 struct brw_reg dest,
248 unsigned msg_reg_nr,
249 struct brw_reg src0,
250 unsigned binding_table_index,
251 bool send_commit_msg);
252
253 void brw_fb_WRITE(struct brw_compile *p,
254 int dispatch_width,
255 unsigned msg_reg_nr,
256 struct brw_reg src0,
257 unsigned msg_control,
258 unsigned binding_table_index,
259 unsigned msg_length,
260 unsigned response_length,
261 bool eot,
262 bool header_present);
263
264 void brw_SAMPLE(struct brw_compile *p,
265 struct brw_reg dest,
266 unsigned msg_reg_nr,
267 struct brw_reg src0,
268 unsigned binding_table_index,
269 unsigned sampler,
270 unsigned msg_type,
271 unsigned response_length,
272 unsigned msg_length,
273 unsigned header_present,
274 unsigned simd_mode,
275 unsigned return_format);
276
277 void brw_math( struct brw_compile *p,
278 struct brw_reg dest,
279 unsigned function,
280 unsigned msg_reg_nr,
281 struct brw_reg src,
282 unsigned data_type,
283 unsigned precision );
284
285 void brw_math2(struct brw_compile *p,
286 struct brw_reg dest,
287 unsigned function,
288 struct brw_reg src0,
289 struct brw_reg src1);
290
291 void brw_oword_block_read(struct brw_compile *p,
292 struct brw_reg dest,
293 struct brw_reg mrf,
294 uint32_t offset,
295 uint32_t bind_table_index);
296
297 void brw_oword_block_read_scratch(struct brw_compile *p,
298 struct brw_reg dest,
299 struct brw_reg mrf,
300 int num_regs,
301 unsigned offset);
302
303 void brw_oword_block_write_scratch(struct brw_compile *p,
304 struct brw_reg mrf,
305 int num_regs,
306 unsigned offset);
307
308 void gen7_block_read_scratch(struct brw_compile *p,
309 struct brw_reg dest,
310 int num_regs,
311 unsigned offset);
312
313 void brw_shader_time_add(struct brw_compile *p,
314 struct brw_reg payload,
315 uint32_t surf_index);
316
317 /* If/else/endif. Works by manipulating the execution flags on each
318 * channel.
319 */
320 struct brw_instruction *brw_IF(struct brw_compile *p,
321 unsigned execute_size);
322 struct brw_instruction *gen6_IF(struct brw_compile *p, uint32_t conditional,
323 struct brw_reg src0, struct brw_reg src1);
324
325 void brw_ELSE(struct brw_compile *p);
326 void brw_ENDIF(struct brw_compile *p);
327
328 /* DO/WHILE loops:
329 */
330 struct brw_instruction *brw_DO(struct brw_compile *p,
331 unsigned execute_size);
332
333 struct brw_instruction *brw_WHILE(struct brw_compile *p);
334
335 struct brw_instruction *brw_BREAK(struct brw_compile *p);
336 struct brw_instruction *brw_CONT(struct brw_compile *p);
337 struct brw_instruction *gen6_CONT(struct brw_compile *p);
338 struct brw_instruction *gen6_HALT(struct brw_compile *p);
339 /* Forward jumps:
340 */
341 void brw_land_fwd_jump(struct brw_compile *p, int jmp_insn_idx);
342
343
344
345 void brw_NOP(struct brw_compile *p);
346
347 void brw_WAIT(struct brw_compile *p);
348
349 /* Special case: there is never a destination, execution size will be
350 * taken from src0:
351 */
352 void brw_CMP(struct brw_compile *p,
353 struct brw_reg dest,
354 unsigned conditional,
355 struct brw_reg src0,
356 struct brw_reg src1);
357
358 void
359 brw_untyped_atomic(struct brw_compile *p,
360 struct brw_reg dest,
361 struct brw_reg mrf,
362 unsigned atomic_op,
363 unsigned bind_table_index,
364 unsigned msg_length,
365 unsigned response_length);
366
367 void
368 brw_untyped_surface_read(struct brw_compile *p,
369 struct brw_reg dest,
370 struct brw_reg mrf,
371 unsigned bind_table_index,
372 unsigned msg_length,
373 unsigned response_length);
374
375 /***********************************************************************
376 * brw_eu_util.c:
377 */
378
379 void brw_copy_indirect_to_indirect(struct brw_compile *p,
380 struct brw_indirect dst_ptr,
381 struct brw_indirect src_ptr,
382 unsigned count);
383
384 void brw_copy_from_indirect(struct brw_compile *p,
385 struct brw_reg dst,
386 struct brw_indirect ptr,
387 unsigned count);
388
389 void brw_copy4(struct brw_compile *p,
390 struct brw_reg dst,
391 struct brw_reg src,
392 unsigned count);
393
394 void brw_copy8(struct brw_compile *p,
395 struct brw_reg dst,
396 struct brw_reg src,
397 unsigned count);
398
399 void brw_math_invert( struct brw_compile *p,
400 struct brw_reg dst,
401 struct brw_reg src);
402
403 void brw_set_src1(struct brw_compile *p,
404 struct brw_instruction *insn,
405 struct brw_reg reg);
406
407 void brw_set_uip_jip(struct brw_compile *p);
408
409 uint32_t brw_swap_cmod(uint32_t cmod);
410
411 /* brw_eu_compact.c */
412 void brw_init_compaction_tables(struct brw_context *brw);
413 void brw_compact_instructions(struct brw_compile *p);
414 void brw_uncompact_instruction(struct brw_context *brw,
415 struct brw_instruction *dst,
416 struct brw_compact_instruction *src);
417 bool brw_try_compact_instruction(struct brw_compile *p,
418 struct brw_compact_instruction *dst,
419 struct brw_instruction *src);
420
421 void brw_debug_compact_uncompact(struct brw_context *brw,
422 struct brw_instruction *orig,
423 struct brw_instruction *uncompacted);
424
425 #ifdef __cplusplus
426 }
427 #endif
428
429 #endif