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>
38 #include "brw_defines.h"
40 #include "intel_asm_annotation.h"
46 #define BRW_EU_MAX_INSN_STACK 5
48 /* A helper for accessing the last instruction emitted. This makes it easy
49 * to set various bits on an instruction without having to create temporary
50 * variable and assign the emitted instruction to those.
52 #define brw_last_inst (&p->store[p->nr_insn - 1])
58 unsigned int next_insn_offset
;
62 /* Allow clients to push/pop instruction state:
64 brw_inst stack
[BRW_EU_MAX_INSN_STACK
];
65 bool compressed_stack
[BRW_EU_MAX_INSN_STACK
];
68 bool single_program_flow
;
69 const struct gen_device_info
*devinfo
;
71 /* Control flow stacks:
72 * - if_stack contains IF and ELSE instructions which must be patched
73 * (and popped) once the matching ENDIF instruction is encountered.
75 * Just store the instruction pointer(an index).
79 int if_stack_array_size
;
82 * loop_stack contains the instruction pointers of the starts of loops which
83 * must be patched (and popped) once the matching WHILE instruction is
88 * pre-gen6, the BREAK and CONT instructions had to tell how many IF/ENDIF
89 * blocks they were popping out of, to fix up the mask stack. This tracks
90 * the IF/ENDIF nesting in each current nested loop level.
92 int *if_depth_in_loop
;
94 int loop_stack_array_size
;
97 void brw_pop_insn_state( struct brw_codegen
*p
);
98 void brw_push_insn_state( struct brw_codegen
*p
);
99 void brw_set_default_exec_size(struct brw_codegen
*p
, unsigned value
);
100 void brw_set_default_mask_control( struct brw_codegen
*p
, unsigned value
);
101 void brw_set_default_saturate( struct brw_codegen
*p
, bool enable
);
102 void brw_set_default_access_mode( struct brw_codegen
*p
, unsigned access_mode
);
103 void brw_inst_set_compression(const struct gen_device_info
*devinfo
,
104 brw_inst
*inst
, bool on
);
105 void brw_set_default_compression(struct brw_codegen
*p
, bool on
);
106 void brw_inst_set_group(const struct gen_device_info
*devinfo
,
107 brw_inst
*inst
, unsigned group
);
108 void brw_set_default_group(struct brw_codegen
*p
, unsigned group
);
109 void brw_set_default_compression_control(struct brw_codegen
*p
, enum brw_compression c
);
110 void brw_set_default_predicate_control( struct brw_codegen
*p
, unsigned pc
);
111 void brw_set_default_predicate_inverse(struct brw_codegen
*p
, bool predicate_inverse
);
112 void brw_set_default_flag_reg(struct brw_codegen
*p
, int reg
, int subreg
);
113 void brw_set_default_acc_write_control(struct brw_codegen
*p
, unsigned value
);
115 void brw_init_codegen(const struct gen_device_info
*, struct brw_codegen
*p
,
117 void brw_disassemble(const struct gen_device_info
*devinfo
, void *assembly
,
118 int start
, int end
, FILE *out
);
119 const unsigned *brw_get_program( struct brw_codegen
*p
, unsigned *sz
);
121 brw_inst
*brw_next_insn(struct brw_codegen
*p
, unsigned opcode
);
122 void brw_set_dest(struct brw_codegen
*p
, brw_inst
*insn
, struct brw_reg dest
);
123 void brw_set_src0(struct brw_codegen
*p
, brw_inst
*insn
, struct brw_reg reg
);
125 void gen6_resolve_implied_move(struct brw_codegen
*p
,
127 unsigned msg_reg_nr
);
129 /* Helpers for regular instructions:
132 brw_inst *brw_##OP(struct brw_codegen *p, \
133 struct brw_reg dest, \
134 struct brw_reg src0);
137 brw_inst *brw_##OP(struct brw_codegen *p, \
138 struct brw_reg dest, \
139 struct brw_reg src0, \
140 struct brw_reg src1);
143 brw_inst *brw_##OP(struct brw_codegen *p, \
144 struct brw_reg dest, \
145 struct brw_reg src0, \
146 struct brw_reg src1, \
147 struct brw_reg src2);
150 void brw_##OP(struct brw_codegen *p, struct brw_reg dest, struct brw_reg src0);
200 /* Helpers for SEND instruction:
202 void brw_set_sampler_message(struct brw_codegen
*p
,
204 unsigned binding_table_index
,
207 unsigned response_length
,
209 unsigned header_present
,
211 unsigned return_format
);
213 void brw_set_message_descriptor(struct brw_codegen
*p
,
215 enum brw_message_target sfid
,
217 unsigned response_length
,
221 void brw_set_dp_read_message(struct brw_codegen
*p
,
223 unsigned binding_table_index
,
224 unsigned msg_control
,
226 unsigned target_cache
,
229 unsigned response_length
);
231 void brw_set_dp_write_message(struct brw_codegen
*p
,
233 unsigned binding_table_index
,
234 unsigned msg_control
,
236 unsigned target_cache
,
239 unsigned last_render_target
,
240 unsigned response_length
,
241 unsigned end_of_thread
,
242 unsigned send_commit_msg
);
244 void brw_urb_WRITE(struct brw_codegen
*p
,
248 enum brw_urb_write_flags flags
,
250 unsigned response_length
,
255 * Send message to shared unit \p sfid with a possibly indirect descriptor \p
256 * desc. If \p desc is not an immediate it will be transparently loaded to an
257 * address register using an OR instruction. The returned instruction can be
258 * passed as argument to the usual brw_set_*_message() functions in order to
259 * specify any additional descriptor bits -- If \p desc is an immediate this
260 * will be the SEND instruction itself, otherwise it will be the OR
264 brw_send_indirect_message(struct brw_codegen
*p
,
267 struct brw_reg payload
,
268 struct brw_reg desc
);
270 void brw_ff_sync(struct brw_codegen
*p
,
275 unsigned response_length
,
278 void brw_svb_write(struct brw_codegen
*p
,
282 unsigned binding_table_index
,
283 bool send_commit_msg
);
285 void brw_fb_WRITE(struct brw_codegen
*p
,
286 struct brw_reg payload
,
287 struct brw_reg implied_header
,
288 unsigned msg_control
,
289 unsigned binding_table_index
,
291 unsigned response_length
,
293 bool last_render_target
,
294 bool header_present
);
296 brw_inst
*gen9_fb_READ(struct brw_codegen
*p
,
298 struct brw_reg payload
,
299 unsigned binding_table_index
,
301 unsigned response_length
,
304 void brw_SAMPLE(struct brw_codegen
*p
,
308 unsigned binding_table_index
,
311 unsigned response_length
,
313 unsigned header_present
,
315 unsigned return_format
);
317 void brw_adjust_sampler_state_pointer(struct brw_codegen
*p
,
318 struct brw_reg header
,
319 struct brw_reg sampler_index
);
321 void gen4_math(struct brw_codegen
*p
,
326 unsigned precision
);
328 void gen6_math(struct brw_codegen
*p
,
332 struct brw_reg src1
);
334 void brw_oword_block_read(struct brw_codegen
*p
,
338 uint32_t bind_table_index
);
340 unsigned brw_scratch_surface_idx(const struct brw_codegen
*p
);
342 void brw_oword_block_read_scratch(struct brw_codegen
*p
,
348 void brw_oword_block_write_scratch(struct brw_codegen
*p
,
353 void gen7_block_read_scratch(struct brw_codegen
*p
,
358 void brw_shader_time_add(struct brw_codegen
*p
,
359 struct brw_reg payload
,
360 uint32_t surf_index
);
363 * Return the generation-specific jump distance scaling factor.
365 * Given the number of instructions to jump, we need to scale by
366 * some number to obtain the actual jump distance to program in an
369 static inline unsigned
370 brw_jump_scale(const struct gen_device_info
*devinfo
)
372 /* Broadwell measures jump targets in bytes. */
373 if (devinfo
->gen
>= 8)
376 /* Ironlake and later measure jump targets in 64-bit data chunks (in order
377 * (to support compaction), so each 128-bit instruction requires 2 chunks.
379 if (devinfo
->gen
>= 5)
382 /* Gen4 simply uses the number of 128-bit instructions. */
386 void brw_barrier(struct brw_codegen
*p
, struct brw_reg src
);
388 /* If/else/endif. Works by manipulating the execution flags on each
391 brw_inst
*brw_IF(struct brw_codegen
*p
, unsigned execute_size
);
392 brw_inst
*gen6_IF(struct brw_codegen
*p
, enum brw_conditional_mod conditional
,
393 struct brw_reg src0
, struct brw_reg src1
);
395 void brw_ELSE(struct brw_codegen
*p
);
396 void brw_ENDIF(struct brw_codegen
*p
);
400 brw_inst
*brw_DO(struct brw_codegen
*p
, unsigned execute_size
);
402 brw_inst
*brw_WHILE(struct brw_codegen
*p
);
404 brw_inst
*brw_BREAK(struct brw_codegen
*p
);
405 brw_inst
*brw_CONT(struct brw_codegen
*p
);
406 brw_inst
*gen6_HALT(struct brw_codegen
*p
);
410 void brw_land_fwd_jump(struct brw_codegen
*p
, int jmp_insn_idx
);
412 brw_inst
*brw_JMPI(struct brw_codegen
*p
, struct brw_reg index
,
413 unsigned predicate_control
);
415 void brw_NOP(struct brw_codegen
*p
);
417 void brw_WAIT(struct brw_codegen
*p
);
419 /* Special case: there is never a destination, execution size will be
422 void brw_CMP(struct brw_codegen
*p
,
424 unsigned conditional
,
426 struct brw_reg src1
);
429 brw_untyped_atomic(struct brw_codegen
*p
,
431 struct brw_reg payload
,
432 struct brw_reg surface
,
435 bool response_expected
);
438 brw_untyped_surface_read(struct brw_codegen
*p
,
440 struct brw_reg payload
,
441 struct brw_reg surface
,
443 unsigned num_channels
);
446 brw_untyped_surface_write(struct brw_codegen
*p
,
447 struct brw_reg payload
,
448 struct brw_reg surface
,
450 unsigned num_channels
);
453 brw_typed_atomic(struct brw_codegen
*p
,
455 struct brw_reg payload
,
456 struct brw_reg surface
,
459 bool response_expected
);
462 brw_typed_surface_read(struct brw_codegen
*p
,
464 struct brw_reg payload
,
465 struct brw_reg surface
,
467 unsigned num_channels
);
470 brw_typed_surface_write(struct brw_codegen
*p
,
471 struct brw_reg payload
,
472 struct brw_reg surface
,
474 unsigned num_channels
);
477 brw_memory_fence(struct brw_codegen
*p
,
481 brw_pixel_interpolator_query(struct brw_codegen
*p
,
488 unsigned response_length
);
491 brw_find_live_channel(struct brw_codegen
*p
,
493 struct brw_reg mask
);
496 brw_broadcast(struct brw_codegen
*p
,
501 /***********************************************************************
505 void brw_copy_indirect_to_indirect(struct brw_codegen
*p
,
506 struct brw_indirect dst_ptr
,
507 struct brw_indirect src_ptr
,
510 void brw_copy_from_indirect(struct brw_codegen
*p
,
512 struct brw_indirect ptr
,
515 void brw_copy4(struct brw_codegen
*p
,
520 void brw_copy8(struct brw_codegen
*p
,
525 void brw_math_invert( struct brw_codegen
*p
,
529 void brw_set_src1(struct brw_codegen
*p
, brw_inst
*insn
, struct brw_reg reg
);
531 void brw_set_uip_jip(struct brw_codegen
*p
, int start_offset
);
533 enum brw_conditional_mod
brw_negate_cmod(uint32_t cmod
);
534 enum brw_conditional_mod
brw_swap_cmod(uint32_t cmod
);
536 /* brw_eu_compact.c */
537 void brw_init_compaction_tables(const struct gen_device_info
*devinfo
);
538 void brw_compact_instructions(struct brw_codegen
*p
, int start_offset
,
539 int num_annotations
, struct annotation
*annotation
);
540 void brw_uncompact_instruction(const struct gen_device_info
*devinfo
,
541 brw_inst
*dst
, brw_compact_inst
*src
);
542 bool brw_try_compact_instruction(const struct gen_device_info
*devinfo
,
543 brw_compact_inst
*dst
, brw_inst
*src
);
545 void brw_debug_compact_uncompact(const struct gen_device_info
*devinfo
,
546 brw_inst
*orig
, brw_inst
*uncompacted
);
548 /* brw_eu_validate.c */
549 bool brw_validate_instructions(const struct brw_codegen
*p
, int start_offset
,
550 struct annotation_info
*annotation
);
553 next_offset(const struct gen_device_info
*devinfo
, void *store
, int offset
)
555 brw_inst
*insn
= (brw_inst
*)((char *)store
+ offset
);
557 if (brw_inst_cmpt_control(devinfo
, insn
))
564 /* The union is an implementation detail used by brw_opcode_desc() to handle
565 * opcodes that have been reused for different instructions across hardware
568 * The gens field acts as a tag. If it is non-zero, name points to a string
569 * containing the instruction mnemonic. If it is zero, the table field is
570 * valid and either points to a secondary opcode_desc table with 'size'
571 * elements or is NULL and no such instruction exists for the opcode.
579 const struct opcode_desc
*table
;
587 const struct opcode_desc
*
588 brw_opcode_desc(const struct gen_device_info
*devinfo
, enum opcode opcode
);
591 is_3src(const struct gen_device_info
*devinfo
, enum opcode opcode
)
593 const struct opcode_desc
*desc
= brw_opcode_desc(devinfo
, opcode
);
594 return desc
&& desc
->nsrc
== 3;
597 /** Maximum SEND message length */
598 #define BRW_MAX_MSG_LENGTH 15
600 /** First MRF register used by pull loads */
601 #define FIRST_SPILL_MRF(gen) ((gen) == 6 ? 21 : 13)
603 /** First MRF register used by spills */
604 #define FIRST_PULL_LOAD_MRF(gen) ((gen) == 6 ? 16 : 13)