2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics to
4 develop this 3D driver.
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:
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.
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.
26 **********************************************************************/
29 * Keith Whitwell <keithw@vmware.com>
37 #include "brw_structs.h"
38 #include "brw_defines.h"
40 #include "intel_asm_printer.h"
41 #include "program/prog_instruction.h"
47 #define BRW_EU_MAX_INSN_STACK 5
49 /* A helper for accessing the last instruction emitted. This makes it easy
50 * to set various bits on an instruction without having to create temporary
51 * variable and assign the emitted instruction to those.
53 #define brw_last_inst (&p->store[p->nr_insn - 1])
56 struct brw_instruction
*store
;
59 unsigned int next_insn_offset
;
63 /* Allow clients to push/pop instruction state:
65 struct brw_instruction stack
[BRW_EU_MAX_INSN_STACK
];
66 bool compressed_stack
[BRW_EU_MAX_INSN_STACK
];
67 struct brw_instruction
*current
;
69 bool single_program_flow
;
71 struct brw_context
*brw
;
73 /* Control flow stacks:
74 * - if_stack contains IF and ELSE instructions which must be patched
75 * (and popped) once the matching ENDIF instruction is encountered.
77 * Just store the instruction pointer(an index).
81 int if_stack_array_size
;
84 * loop_stack contains the instruction pointers of the starts of loops which
85 * must be patched (and popped) once the matching WHILE instruction is
90 * pre-gen6, the BREAK and CONT instructions had to tell how many IF/ENDIF
91 * blocks they were popping out of, to fix up the mask stack. This tracks
92 * the IF/ENDIF nesting in each current nested loop level.
94 int *if_depth_in_loop
;
96 int loop_stack_array_size
;
99 void brw_pop_insn_state( struct brw_compile
*p
);
100 void brw_push_insn_state( struct brw_compile
*p
);
101 void brw_set_default_mask_control( struct brw_compile
*p
, unsigned value
);
102 void brw_set_default_saturate( struct brw_compile
*p
, bool enable
);
103 void brw_set_default_access_mode( struct brw_compile
*p
, unsigned access_mode
);
104 void brw_set_default_compression_control(struct brw_compile
*p
, enum brw_compression c
);
105 void brw_set_default_predicate_control( struct brw_compile
*p
, unsigned pc
);
106 void brw_set_default_predicate_inverse(struct brw_compile
*p
, bool predicate_inverse
);
107 void brw_set_default_flag_reg(struct brw_compile
*p
, int reg
, int subreg
);
108 void brw_set_default_acc_write_control(struct brw_compile
*p
, unsigned value
);
110 void brw_init_compile(struct brw_context
*, struct brw_compile
*p
,
112 void brw_disassemble(struct brw_context
*brw
, void *assembly
,
113 int start
, int end
, FILE *out
);
114 const unsigned *brw_get_program( struct brw_compile
*p
, unsigned *sz
);
116 struct brw_instruction
*brw_next_insn(struct brw_compile
*p
, unsigned opcode
);
117 void brw_set_dest(struct brw_compile
*p
, struct brw_instruction
*insn
,
118 struct brw_reg dest
);
119 void brw_set_src0(struct brw_compile
*p
, struct brw_instruction
*insn
,
122 void gen6_resolve_implied_move(struct brw_compile
*p
,
124 unsigned msg_reg_nr
);
126 /* Helpers for regular instructions:
129 struct brw_instruction *brw_##OP(struct brw_compile *p, \
130 struct brw_reg dest, \
131 struct brw_reg src0);
134 struct brw_instruction *brw_##OP(struct brw_compile *p, \
135 struct brw_reg dest, \
136 struct brw_reg src0, \
137 struct brw_reg src1);
140 struct brw_instruction *brw_##OP(struct brw_compile *p, \
141 struct brw_reg dest, \
142 struct brw_reg src0, \
143 struct brw_reg src1, \
144 struct brw_reg src2);
147 void brw_##OP(struct brw_compile *p, struct brw_reg dest, struct brw_reg src0);
196 /* Helpers for SEND instruction:
198 void brw_set_sampler_message(struct brw_compile
*p
,
199 struct brw_instruction
*insn
,
200 unsigned binding_table_index
,
203 unsigned response_length
,
205 unsigned header_present
,
207 unsigned return_format
);
209 void brw_set_dp_read_message(struct brw_compile
*p
,
210 struct brw_instruction
*insn
,
211 unsigned binding_table_index
,
212 unsigned msg_control
,
214 unsigned target_cache
,
217 unsigned response_length
);
219 void brw_set_dp_write_message(struct brw_compile
*p
,
220 struct brw_instruction
*insn
,
221 unsigned binding_table_index
,
222 unsigned msg_control
,
226 unsigned last_render_target
,
227 unsigned response_length
,
228 unsigned end_of_thread
,
229 unsigned send_commit_msg
);
231 void brw_urb_WRITE(struct brw_compile
*p
,
235 enum brw_urb_write_flags flags
,
237 unsigned response_length
,
241 void brw_ff_sync(struct brw_compile
*p
,
246 unsigned response_length
,
249 void brw_svb_write(struct brw_compile
*p
,
253 unsigned binding_table_index
,
254 bool send_commit_msg
);
256 void brw_fb_WRITE(struct brw_compile
*p
,
260 unsigned msg_control
,
261 unsigned binding_table_index
,
263 unsigned response_length
,
265 bool header_present
);
267 void brw_SAMPLE(struct brw_compile
*p
,
271 unsigned binding_table_index
,
274 unsigned response_length
,
276 unsigned header_present
,
278 unsigned return_format
);
280 void brw_math( struct brw_compile
*p
,
286 unsigned precision
);
288 void brw_math2(struct brw_compile
*p
,
292 struct brw_reg src1
);
294 void brw_oword_block_read(struct brw_compile
*p
,
298 uint32_t bind_table_index
);
300 void brw_oword_block_read_scratch(struct brw_compile
*p
,
306 void brw_oword_block_write_scratch(struct brw_compile
*p
,
311 void gen7_block_read_scratch(struct brw_compile
*p
,
316 void brw_shader_time_add(struct brw_compile
*p
,
317 struct brw_reg payload
,
318 uint32_t surf_index
);
320 /* If/else/endif. Works by manipulating the execution flags on each
323 struct brw_instruction
*brw_IF(struct brw_compile
*p
,
324 unsigned execute_size
);
325 struct brw_instruction
*gen6_IF(struct brw_compile
*p
, uint32_t conditional
,
326 struct brw_reg src0
, struct brw_reg src1
);
328 void brw_ELSE(struct brw_compile
*p
);
329 void brw_ENDIF(struct brw_compile
*p
);
333 struct brw_instruction
*brw_DO(struct brw_compile
*p
,
334 unsigned execute_size
);
336 struct brw_instruction
*brw_WHILE(struct brw_compile
*p
);
338 struct brw_instruction
*brw_BREAK(struct brw_compile
*p
);
339 struct brw_instruction
*brw_CONT(struct brw_compile
*p
);
340 struct brw_instruction
*gen6_CONT(struct brw_compile
*p
);
341 struct brw_instruction
*gen6_HALT(struct brw_compile
*p
);
345 void brw_land_fwd_jump(struct brw_compile
*p
, int jmp_insn_idx
);
347 struct brw_instruction
*brw_JMPI(struct brw_compile
*p
, struct brw_reg index
,
348 unsigned predicate_control
);
350 void brw_NOP(struct brw_compile
*p
);
352 void brw_WAIT(struct brw_compile
*p
);
354 /* Special case: there is never a destination, execution size will be
357 void brw_CMP(struct brw_compile
*p
,
359 unsigned conditional
,
361 struct brw_reg src1
);
364 brw_untyped_atomic(struct brw_compile
*p
,
368 unsigned bind_table_index
,
370 unsigned response_length
);
373 brw_untyped_surface_read(struct brw_compile
*p
,
376 unsigned bind_table_index
,
378 unsigned response_length
);
380 /***********************************************************************
384 void brw_copy_indirect_to_indirect(struct brw_compile
*p
,
385 struct brw_indirect dst_ptr
,
386 struct brw_indirect src_ptr
,
389 void brw_copy_from_indirect(struct brw_compile
*p
,
391 struct brw_indirect ptr
,
394 void brw_copy4(struct brw_compile
*p
,
399 void brw_copy8(struct brw_compile
*p
,
404 void brw_math_invert( struct brw_compile
*p
,
408 void brw_set_src1(struct brw_compile
*p
,
409 struct brw_instruction
*insn
,
412 void brw_set_uip_jip(struct brw_compile
*p
);
414 uint32_t brw_swap_cmod(uint32_t cmod
);
416 /* brw_eu_compact.c */
417 void brw_init_compaction_tables(struct brw_context
*brw
);
418 void brw_compact_instructions(struct brw_compile
*p
, int start_offset
,
419 int num_annotations
, struct annotation
*annotation
);
420 void brw_uncompact_instruction(struct brw_context
*brw
,
421 struct brw_instruction
*dst
,
422 struct brw_compact_instruction
*src
);
423 bool brw_try_compact_instruction(struct brw_compile
*p
,
424 struct brw_compact_instruction
*dst
,
425 struct brw_instruction
*src
);
427 void brw_debug_compact_uncompact(struct brw_context
*brw
,
428 struct brw_instruction
*orig
,
429 struct brw_instruction
*uncompacted
);
432 next_offset(void *store
, int offset
)
434 struct brw_instruction
*insn
=
435 (struct brw_instruction
*)((char *)store
+ offset
);
437 if (insn
->header
.cmpt_control
)