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>
39 #include "brw_eu_defines.h"
41 #include "brw_disasm_info.h"
47 #define BRW_EU_MAX_INSN_STACK 5
49 struct brw_insn_state
{
50 /* One of BRW_EXECUTE_* */
53 /* Group in units of channels */
56 /* Compression control on gen4-5 */
59 /* One of BRW_MASK_* */
60 unsigned mask_control
:1;
62 /* Scheduling info for Gen12+ */
67 /* One of BRW_ALIGN_* */
68 unsigned access_mode
:1;
70 /* One of BRW_PREDICATE_* */
71 enum brw_predicate predicate
:4;
75 /* Flag subreg. Bottom bit is subreg, top bit is reg */
76 unsigned flag_subreg
:2;
78 bool acc_wr_control
:1;
82 /* A helper for accessing the last instruction emitted. This makes it easy
83 * to set various bits on an instruction without having to create temporary
84 * variable and assign the emitted instruction to those.
86 #define brw_last_inst (&p->store[p->nr_insn - 1])
92 unsigned int next_insn_offset
;
96 /* Allow clients to push/pop instruction state:
98 struct brw_insn_state stack
[BRW_EU_MAX_INSN_STACK
];
99 struct brw_insn_state
*current
;
101 /** Whether or not the user wants automatic exec sizes
103 * If true, codegen will try to automatically infer the exec size of an
104 * instruction from the width of the destination register. If false, it
105 * will take whatever is set by brw_set_default_exec_size verbatim.
107 * This is set to true by default in brw_init_codegen.
109 bool automatic_exec_sizes
;
111 bool single_program_flow
;
112 const struct gen_device_info
*devinfo
;
114 /* Control flow stacks:
115 * - if_stack contains IF and ELSE instructions which must be patched
116 * (and popped) once the matching ENDIF instruction is encountered.
118 * Just store the instruction pointer(an index).
122 int if_stack_array_size
;
125 * loop_stack contains the instruction pointers of the starts of loops which
126 * must be patched (and popped) once the matching WHILE instruction is
131 * pre-gen6, the BREAK and CONT instructions had to tell how many IF/ENDIF
132 * blocks they were popping out of, to fix up the mask stack. This tracks
133 * the IF/ENDIF nesting in each current nested loop level.
135 int *if_depth_in_loop
;
136 int loop_stack_depth
;
137 int loop_stack_array_size
;
140 void brw_pop_insn_state( struct brw_codegen
*p
);
141 void brw_push_insn_state( struct brw_codegen
*p
);
142 unsigned brw_get_default_exec_size(struct brw_codegen
*p
);
143 unsigned brw_get_default_group(struct brw_codegen
*p
);
144 unsigned brw_get_default_access_mode(struct brw_codegen
*p
);
145 struct tgl_swsb
brw_get_default_swsb(struct brw_codegen
*p
);
146 void brw_set_default_exec_size(struct brw_codegen
*p
, unsigned value
);
147 void brw_set_default_mask_control( struct brw_codegen
*p
, unsigned value
);
148 void brw_set_default_saturate( struct brw_codegen
*p
, bool enable
);
149 void brw_set_default_access_mode( struct brw_codegen
*p
, unsigned access_mode
);
150 void brw_inst_set_compression(const struct gen_device_info
*devinfo
,
151 brw_inst
*inst
, bool on
);
152 void brw_set_default_compression(struct brw_codegen
*p
, bool on
);
153 void brw_inst_set_group(const struct gen_device_info
*devinfo
,
154 brw_inst
*inst
, unsigned group
);
155 void brw_set_default_group(struct brw_codegen
*p
, unsigned group
);
156 void brw_set_default_compression_control(struct brw_codegen
*p
, enum brw_compression c
);
157 void brw_set_default_predicate_control(struct brw_codegen
*p
, enum brw_predicate pc
);
158 void brw_set_default_predicate_inverse(struct brw_codegen
*p
, bool predicate_inverse
);
159 void brw_set_default_flag_reg(struct brw_codegen
*p
, int reg
, int subreg
);
160 void brw_set_default_acc_write_control(struct brw_codegen
*p
, unsigned value
);
161 void brw_set_default_swsb(struct brw_codegen
*p
, struct tgl_swsb value
);
163 void brw_init_codegen(const struct gen_device_info
*, struct brw_codegen
*p
,
165 int brw_disassemble_inst(FILE *file
, const struct gen_device_info
*devinfo
,
166 const struct brw_inst
*inst
, bool is_compacted
);
167 void brw_disassemble(const struct gen_device_info
*devinfo
,
168 const void *assembly
, int start
, int end
, FILE *out
);
169 const unsigned *brw_get_program( struct brw_codegen
*p
, unsigned *sz
);
171 bool brw_try_override_assembly(struct brw_codegen
*p
, int start_offset
,
172 const char *identifier
);
174 brw_inst
*brw_next_insn(struct brw_codegen
*p
, unsigned opcode
);
175 void brw_set_dest(struct brw_codegen
*p
, brw_inst
*insn
, struct brw_reg dest
);
176 void brw_set_src0(struct brw_codegen
*p
, brw_inst
*insn
, struct brw_reg reg
);
178 void gen6_resolve_implied_move(struct brw_codegen
*p
,
180 unsigned msg_reg_nr
);
182 /* Helpers for regular instructions:
185 brw_inst *brw_##OP(struct brw_codegen *p, \
186 struct brw_reg dest, \
187 struct brw_reg src0);
190 brw_inst *brw_##OP(struct brw_codegen *p, \
191 struct brw_reg dest, \
192 struct brw_reg src0, \
193 struct brw_reg src1);
196 brw_inst *brw_##OP(struct brw_codegen *p, \
197 struct brw_reg dest, \
198 struct brw_reg src0, \
199 struct brw_reg src1, \
200 struct brw_reg src2);
203 void brw_##OP(struct brw_codegen *p, struct brw_reg dest, struct brw_reg src0);
256 /* Helpers for SEND instruction:
260 * Construct a message descriptor immediate with the specified common
261 * descriptor controls.
263 static inline uint32_t
264 brw_message_desc(const struct gen_device_info
*devinfo
,
266 unsigned response_length
,
269 if (devinfo
->gen
>= 5) {
270 return (SET_BITS(msg_length
, 28, 25) |
271 SET_BITS(response_length
, 24, 20) |
272 SET_BITS(header_present
, 19, 19));
274 return (SET_BITS(msg_length
, 23, 20) |
275 SET_BITS(response_length
, 19, 16));
279 static inline unsigned
280 brw_message_desc_mlen(const struct gen_device_info
*devinfo
, uint32_t desc
)
282 if (devinfo
->gen
>= 5)
283 return GET_BITS(desc
, 28, 25);
285 return GET_BITS(desc
, 23, 20);
288 static inline unsigned
289 brw_message_desc_rlen(const struct gen_device_info
*devinfo
, uint32_t desc
)
291 if (devinfo
->gen
>= 5)
292 return GET_BITS(desc
, 24, 20);
294 return GET_BITS(desc
, 19, 16);
298 brw_message_desc_header_present(ASSERTED
const struct gen_device_info
*devinfo
,
301 assert(devinfo
->gen
>= 5);
302 return GET_BITS(desc
, 19, 19);
305 static inline unsigned
306 brw_message_ex_desc(UNUSED
const struct gen_device_info
*devinfo
,
307 unsigned ex_msg_length
)
309 return SET_BITS(ex_msg_length
, 9, 6);
312 static inline unsigned
313 brw_message_ex_desc_ex_mlen(UNUSED
const struct gen_device_info
*devinfo
,
316 return GET_BITS(ex_desc
, 9, 6);
320 * Construct a message descriptor immediate with the specified sampler
323 static inline uint32_t
324 brw_sampler_desc(const struct gen_device_info
*devinfo
,
325 unsigned binding_table_index
,
329 unsigned return_format
)
331 const unsigned desc
= (SET_BITS(binding_table_index
, 7, 0) |
332 SET_BITS(sampler
, 11, 8));
333 if (devinfo
->gen
>= 7)
334 return (desc
| SET_BITS(msg_type
, 16, 12) |
335 SET_BITS(simd_mode
, 18, 17));
336 else if (devinfo
->gen
>= 5)
337 return (desc
| SET_BITS(msg_type
, 15, 12) |
338 SET_BITS(simd_mode
, 17, 16));
339 else if (devinfo
->is_g4x
)
340 return desc
| SET_BITS(msg_type
, 15, 12);
342 return (desc
| SET_BITS(return_format
, 13, 12) |
343 SET_BITS(msg_type
, 15, 14));
346 static inline unsigned
347 brw_sampler_desc_binding_table_index(UNUSED
const struct gen_device_info
*devinfo
,
350 return GET_BITS(desc
, 7, 0);
353 static inline unsigned
354 brw_sampler_desc_sampler(UNUSED
const struct gen_device_info
*devinfo
, uint32_t desc
)
356 return GET_BITS(desc
, 11, 8);
359 static inline unsigned
360 brw_sampler_desc_msg_type(const struct gen_device_info
*devinfo
, uint32_t desc
)
362 if (devinfo
->gen
>= 7)
363 return GET_BITS(desc
, 16, 12);
364 else if (devinfo
->gen
>= 5 || devinfo
->is_g4x
)
365 return GET_BITS(desc
, 15, 12);
367 return GET_BITS(desc
, 15, 14);
370 static inline unsigned
371 brw_sampler_desc_simd_mode(const struct gen_device_info
*devinfo
, uint32_t desc
)
373 assert(devinfo
->gen
>= 5);
374 if (devinfo
->gen
>= 7)
375 return GET_BITS(desc
, 18, 17);
377 return GET_BITS(desc
, 17, 16);
380 static inline unsigned
381 brw_sampler_desc_return_format(ASSERTED
const struct gen_device_info
*devinfo
,
384 assert(devinfo
->gen
== 4 && !devinfo
->is_g4x
);
385 return GET_BITS(desc
, 13, 12);
389 * Construct a message descriptor for the dataport
391 static inline uint32_t
392 brw_dp_desc(const struct gen_device_info
*devinfo
,
393 unsigned binding_table_index
,
395 unsigned msg_control
)
397 /* Prior to gen6, things are too inconsistent; use the dp_read/write_desc
400 assert(devinfo
->gen
>= 6);
401 const unsigned desc
= SET_BITS(binding_table_index
, 7, 0);
402 if (devinfo
->gen
>= 8) {
403 return (desc
| SET_BITS(msg_control
, 13, 8) |
404 SET_BITS(msg_type
, 18, 14));
405 } else if (devinfo
->gen
>= 7) {
406 return (desc
| SET_BITS(msg_control
, 13, 8) |
407 SET_BITS(msg_type
, 17, 14));
409 return (desc
| SET_BITS(msg_control
, 12, 8) |
410 SET_BITS(msg_type
, 16, 13));
414 static inline unsigned
415 brw_dp_desc_binding_table_index(UNUSED
const struct gen_device_info
*devinfo
,
418 return GET_BITS(desc
, 7, 0);
421 static inline unsigned
422 brw_dp_desc_msg_type(const struct gen_device_info
*devinfo
, uint32_t desc
)
424 assert(devinfo
->gen
>= 6);
425 if (devinfo
->gen
>= 8)
426 return GET_BITS(desc
, 18, 14);
427 else if (devinfo
->gen
>= 7)
428 return GET_BITS(desc
, 17, 14);
430 return GET_BITS(desc
, 16, 13);
433 static inline unsigned
434 brw_dp_desc_msg_control(const struct gen_device_info
*devinfo
, uint32_t desc
)
436 assert(devinfo
->gen
>= 6);
437 if (devinfo
->gen
>= 7)
438 return GET_BITS(desc
, 13, 8);
440 return GET_BITS(desc
, 12, 8);
444 * Construct a message descriptor immediate with the specified dataport read
447 static inline uint32_t
448 brw_dp_read_desc(const struct gen_device_info
*devinfo
,
449 unsigned binding_table_index
,
450 unsigned msg_control
,
452 unsigned target_cache
)
454 if (devinfo
->gen
>= 6)
455 return brw_dp_desc(devinfo
, binding_table_index
, msg_type
, msg_control
);
456 else if (devinfo
->gen
>= 5 || devinfo
->is_g4x
)
457 return (SET_BITS(binding_table_index
, 7, 0) |
458 SET_BITS(msg_control
, 10, 8) |
459 SET_BITS(msg_type
, 13, 11) |
460 SET_BITS(target_cache
, 15, 14));
462 return (SET_BITS(binding_table_index
, 7, 0) |
463 SET_BITS(msg_control
, 11, 8) |
464 SET_BITS(msg_type
, 13, 12) |
465 SET_BITS(target_cache
, 15, 14));
468 static inline unsigned
469 brw_dp_read_desc_msg_type(const struct gen_device_info
*devinfo
, uint32_t desc
)
471 if (devinfo
->gen
>= 6)
472 return brw_dp_desc_msg_type(devinfo
, desc
);
473 else if (devinfo
->gen
>= 5 || devinfo
->is_g4x
)
474 return GET_BITS(desc
, 13, 11);
476 return GET_BITS(desc
, 13, 12);
479 static inline unsigned
480 brw_dp_read_desc_msg_control(const struct gen_device_info
*devinfo
,
483 if (devinfo
->gen
>= 6)
484 return brw_dp_desc_msg_control(devinfo
, desc
);
485 else if (devinfo
->gen
>= 5 || devinfo
->is_g4x
)
486 return GET_BITS(desc
, 10, 8);
488 return GET_BITS(desc
, 11, 8);
492 * Construct a message descriptor immediate with the specified dataport write
495 static inline uint32_t
496 brw_dp_write_desc(const struct gen_device_info
*devinfo
,
497 unsigned binding_table_index
,
498 unsigned msg_control
,
500 unsigned last_render_target
,
501 unsigned send_commit_msg
)
503 assert(devinfo
->gen
<= 6 || !send_commit_msg
);
504 if (devinfo
->gen
>= 6)
505 return brw_dp_desc(devinfo
, binding_table_index
, msg_type
, msg_control
) |
506 SET_BITS(last_render_target
, 12, 12) |
507 SET_BITS(send_commit_msg
, 17, 17);
509 return (SET_BITS(binding_table_index
, 7, 0) |
510 SET_BITS(msg_control
, 11, 8) |
511 SET_BITS(last_render_target
, 11, 11) |
512 SET_BITS(msg_type
, 14, 12) |
513 SET_BITS(send_commit_msg
, 15, 15));
516 static inline unsigned
517 brw_dp_write_desc_msg_type(const struct gen_device_info
*devinfo
,
520 if (devinfo
->gen
>= 6)
521 return brw_dp_desc_msg_type(devinfo
, desc
);
523 return GET_BITS(desc
, 14, 12);
526 static inline unsigned
527 brw_dp_write_desc_msg_control(const struct gen_device_info
*devinfo
,
530 if (devinfo
->gen
>= 6)
531 return brw_dp_desc_msg_control(devinfo
, desc
);
533 return GET_BITS(desc
, 11, 8);
537 brw_dp_write_desc_last_render_target(const struct gen_device_info
*devinfo
,
540 if (devinfo
->gen
>= 6)
541 return GET_BITS(desc
, 12, 12);
543 return GET_BITS(desc
, 11, 11);
547 brw_dp_write_desc_write_commit(const struct gen_device_info
*devinfo
,
550 assert(devinfo
->gen
<= 6);
551 if (devinfo
->gen
>= 6)
552 return GET_BITS(desc
, 17, 17);
554 return GET_BITS(desc
, 15, 15);
558 * Construct a message descriptor immediate with the specified dataport
559 * surface function controls.
561 static inline uint32_t
562 brw_dp_surface_desc(const struct gen_device_info
*devinfo
,
564 unsigned msg_control
)
566 assert(devinfo
->gen
>= 7);
567 /* We'll OR in the binding table index later */
568 return brw_dp_desc(devinfo
, 0, msg_type
, msg_control
);
571 static inline uint32_t
572 brw_dp_untyped_atomic_desc(const struct gen_device_info
*devinfo
,
573 unsigned exec_size
, /**< 0 for SIMD4x2 */
575 bool response_expected
)
577 assert(exec_size
<= 8 || exec_size
== 16);
580 if (devinfo
->gen
>= 8 || devinfo
->is_haswell
) {
582 msg_type
= HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP
;
584 msg_type
= HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP_SIMD4X2
;
587 msg_type
= GEN7_DATAPORT_DC_UNTYPED_ATOMIC_OP
;
590 const unsigned msg_control
=
591 SET_BITS(atomic_op
, 3, 0) |
592 SET_BITS(0 < exec_size
&& exec_size
<= 8, 4, 4) |
593 SET_BITS(response_expected
, 5, 5);
595 return brw_dp_surface_desc(devinfo
, msg_type
, msg_control
);
598 static inline uint32_t
599 brw_dp_untyped_atomic_float_desc(const struct gen_device_info
*devinfo
,
602 bool response_expected
)
604 assert(exec_size
<= 8 || exec_size
== 16);
605 assert(devinfo
->gen
>= 9);
607 assert(exec_size
> 0);
608 const unsigned msg_type
= GEN9_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_FLOAT_OP
;
610 const unsigned msg_control
=
611 SET_BITS(atomic_op
, 1, 0) |
612 SET_BITS(exec_size
<= 8, 4, 4) |
613 SET_BITS(response_expected
, 5, 5);
615 return brw_dp_surface_desc(devinfo
, msg_type
, msg_control
);
618 static inline unsigned
619 brw_mdc_cmask(unsigned num_channels
)
621 /* See also MDC_CMASK in the SKL PRM Vol 2d. */
622 return 0xf & (0xf << num_channels
);
625 static inline uint32_t
626 brw_dp_untyped_surface_rw_desc(const struct gen_device_info
*devinfo
,
627 unsigned exec_size
, /**< 0 for SIMD4x2 */
628 unsigned num_channels
,
631 assert(exec_size
<= 8 || exec_size
== 16);
635 if (devinfo
->gen
>= 8 || devinfo
->is_haswell
) {
636 msg_type
= HSW_DATAPORT_DC_PORT1_UNTYPED_SURFACE_WRITE
;
638 msg_type
= GEN7_DATAPORT_DC_UNTYPED_SURFACE_WRITE
;
642 if (devinfo
->gen
>= 8 || devinfo
->is_haswell
) {
643 msg_type
= HSW_DATAPORT_DC_PORT1_UNTYPED_SURFACE_READ
;
645 msg_type
= GEN7_DATAPORT_DC_UNTYPED_SURFACE_READ
;
649 /* SIMD4x2 is only valid for read messages on IVB; use SIMD8 instead */
650 if (write
&& devinfo
->gen
== 7 && !devinfo
->is_haswell
&& exec_size
== 0)
653 /* See also MDC_SM3 in the SKL PRM Vol 2d. */
654 const unsigned simd_mode
= exec_size
== 0 ? 0 : /* SIMD4x2 */
655 exec_size
<= 8 ? 2 : 1;
657 const unsigned msg_control
=
658 SET_BITS(brw_mdc_cmask(num_channels
), 3, 0) |
659 SET_BITS(simd_mode
, 5, 4);
661 return brw_dp_surface_desc(devinfo
, msg_type
, msg_control
);
664 static inline unsigned
665 brw_mdc_ds(unsigned bit_size
)
669 return GEN7_BYTE_SCATTERED_DATA_ELEMENT_BYTE
;
671 return GEN7_BYTE_SCATTERED_DATA_ELEMENT_WORD
;
673 return GEN7_BYTE_SCATTERED_DATA_ELEMENT_DWORD
;
675 unreachable("Unsupported bit_size for byte scattered messages");
679 static inline uint32_t
680 brw_dp_byte_scattered_rw_desc(const struct gen_device_info
*devinfo
,
685 assert(exec_size
<= 8 || exec_size
== 16);
687 assert(devinfo
->gen
> 7 || devinfo
->is_haswell
);
688 const unsigned msg_type
=
689 write
? HSW_DATAPORT_DC_PORT0_BYTE_SCATTERED_WRITE
:
690 HSW_DATAPORT_DC_PORT0_BYTE_SCATTERED_READ
;
692 assert(exec_size
> 0);
693 const unsigned msg_control
=
694 SET_BITS(exec_size
== 16, 0, 0) |
695 SET_BITS(brw_mdc_ds(bit_size
), 3, 2);
697 return brw_dp_surface_desc(devinfo
, msg_type
, msg_control
);
700 static inline uint32_t
701 brw_dp_a64_untyped_surface_rw_desc(const struct gen_device_info
*devinfo
,
702 unsigned exec_size
, /**< 0 for SIMD4x2 */
703 unsigned num_channels
,
706 assert(exec_size
<= 8 || exec_size
== 16);
707 assert(devinfo
->gen
>= 8);
710 write
? GEN8_DATAPORT_DC_PORT1_A64_UNTYPED_SURFACE_WRITE
:
711 GEN8_DATAPORT_DC_PORT1_A64_UNTYPED_SURFACE_READ
;
713 /* See also MDC_SM3 in the SKL PRM Vol 2d. */
714 const unsigned simd_mode
= exec_size
== 0 ? 0 : /* SIMD4x2 */
715 exec_size
<= 8 ? 2 : 1;
717 const unsigned msg_control
=
718 SET_BITS(brw_mdc_cmask(num_channels
), 3, 0) |
719 SET_BITS(simd_mode
, 5, 4);
721 return brw_dp_desc(devinfo
, BRW_BTI_STATELESS
, msg_type
, msg_control
);
725 * Calculate the data size (see MDC_A64_DS in the "Structures" volume of the
728 static inline uint32_t
729 brw_mdc_a64_ds(unsigned elems
)
737 unreachable("Unsupported elmeent count for A64 scattered message");
741 static inline uint32_t
742 brw_dp_a64_byte_scattered_rw_desc(const struct gen_device_info
*devinfo
,
743 unsigned exec_size
, /**< 0 for SIMD4x2 */
747 assert(exec_size
<= 8 || exec_size
== 16);
748 assert(devinfo
->gen
>= 8);
751 write
? GEN8_DATAPORT_DC_PORT1_A64_SCATTERED_WRITE
:
752 GEN9_DATAPORT_DC_PORT1_A64_SCATTERED_READ
;
754 const unsigned msg_control
=
755 SET_BITS(GEN8_A64_SCATTERED_SUBTYPE_BYTE
, 1, 0) |
756 SET_BITS(brw_mdc_a64_ds(bit_size
/ 8), 3, 2) |
757 SET_BITS(exec_size
== 16, 4, 4);
759 return brw_dp_desc(devinfo
, BRW_BTI_STATELESS
, msg_type
, msg_control
);
762 static inline uint32_t
763 brw_dp_a64_untyped_atomic_desc(const struct gen_device_info
*devinfo
,
764 ASSERTED
unsigned exec_size
, /**< 0 for SIMD4x2 */
767 bool response_expected
)
769 assert(exec_size
== 8);
770 assert(devinfo
->gen
>= 8);
771 assert(bit_size
== 32 || bit_size
== 64);
773 const unsigned msg_type
= GEN8_DATAPORT_DC_PORT1_A64_UNTYPED_ATOMIC_OP
;
775 const unsigned msg_control
=
776 SET_BITS(atomic_op
, 3, 0) |
777 SET_BITS(bit_size
== 64, 4, 4) |
778 SET_BITS(response_expected
, 5, 5);
780 return brw_dp_desc(devinfo
, BRW_BTI_STATELESS
, msg_type
, msg_control
);
783 static inline uint32_t
784 brw_dp_a64_untyped_atomic_float_desc(const struct gen_device_info
*devinfo
,
785 ASSERTED
unsigned exec_size
,
787 bool response_expected
)
789 assert(exec_size
== 8);
790 assert(devinfo
->gen
>= 9);
792 assert(exec_size
> 0);
793 const unsigned msg_type
= GEN9_DATAPORT_DC_PORT1_A64_UNTYPED_ATOMIC_FLOAT_OP
;
795 const unsigned msg_control
=
796 SET_BITS(atomic_op
, 1, 0) |
797 SET_BITS(response_expected
, 5, 5);
799 return brw_dp_desc(devinfo
, BRW_BTI_STATELESS
, msg_type
, msg_control
);
802 static inline uint32_t
803 brw_dp_typed_atomic_desc(const struct gen_device_info
*devinfo
,
807 bool response_expected
)
809 assert(exec_size
> 0 || exec_group
== 0);
810 assert(exec_group
% 8 == 0);
813 if (devinfo
->gen
>= 8 || devinfo
->is_haswell
) {
814 if (exec_size
== 0) {
815 msg_type
= HSW_DATAPORT_DC_PORT1_TYPED_ATOMIC_OP_SIMD4X2
;
817 msg_type
= HSW_DATAPORT_DC_PORT1_TYPED_ATOMIC_OP
;
820 /* SIMD4x2 typed surface R/W messages only exist on HSW+ */
821 assert(exec_size
> 0);
822 msg_type
= GEN7_DATAPORT_RC_TYPED_ATOMIC_OP
;
825 const bool high_sample_mask
= (exec_group
/ 8) % 2 == 1;
827 const unsigned msg_control
=
828 SET_BITS(atomic_op
, 3, 0) |
829 SET_BITS(high_sample_mask
, 4, 4) |
830 SET_BITS(response_expected
, 5, 5);
832 return brw_dp_surface_desc(devinfo
, msg_type
, msg_control
);
835 static inline uint32_t
836 brw_dp_typed_surface_rw_desc(const struct gen_device_info
*devinfo
,
839 unsigned num_channels
,
842 assert(exec_size
> 0 || exec_group
== 0);
843 assert(exec_group
% 8 == 0);
845 /* Typed surface reads and writes don't support SIMD16 */
846 assert(exec_size
<= 8);
850 if (devinfo
->gen
>= 8 || devinfo
->is_haswell
) {
851 msg_type
= HSW_DATAPORT_DC_PORT1_TYPED_SURFACE_WRITE
;
853 msg_type
= GEN7_DATAPORT_RC_TYPED_SURFACE_WRITE
;
856 if (devinfo
->gen
>= 8 || devinfo
->is_haswell
) {
857 msg_type
= HSW_DATAPORT_DC_PORT1_TYPED_SURFACE_READ
;
859 msg_type
= GEN7_DATAPORT_RC_TYPED_SURFACE_READ
;
863 /* See also MDC_SG3 in the SKL PRM Vol 2d. */
864 unsigned msg_control
;
865 if (devinfo
->gen
>= 8 || devinfo
->is_haswell
) {
866 /* See also MDC_SG3 in the SKL PRM Vol 2d. */
867 const unsigned slot_group
= exec_size
== 0 ? 0 : /* SIMD4x2 */
868 1 + ((exec_group
/ 8) % 2);
871 SET_BITS(brw_mdc_cmask(num_channels
), 3, 0) |
872 SET_BITS(slot_group
, 5, 4);
874 /* SIMD4x2 typed surface R/W messages only exist on HSW+ */
875 assert(exec_size
> 0);
876 const unsigned slot_group
= ((exec_group
/ 8) % 2);
879 SET_BITS(brw_mdc_cmask(num_channels
), 3, 0) |
880 SET_BITS(slot_group
, 5, 5);
883 return brw_dp_surface_desc(devinfo
, msg_type
, msg_control
);
887 * Construct a message descriptor immediate with the specified pixel
888 * interpolator function controls.
890 static inline uint32_t
891 brw_pixel_interp_desc(UNUSED
const struct gen_device_info
*devinfo
,
897 return (SET_BITS(slot_group
, 11, 11) |
898 SET_BITS(msg_type
, 13, 12) |
899 SET_BITS(!!noperspective
, 14, 14) |
900 SET_BITS(simd_mode
, 16, 16));
903 void brw_urb_WRITE(struct brw_codegen
*p
,
907 enum brw_urb_write_flags flags
,
909 unsigned response_length
,
914 * Send message to shared unit \p sfid with a possibly indirect descriptor \p
915 * desc. If \p desc is not an immediate it will be transparently loaded to an
916 * address register using an OR instruction.
919 brw_send_indirect_message(struct brw_codegen
*p
,
922 struct brw_reg payload
,
928 brw_send_indirect_split_message(struct brw_codegen
*p
,
931 struct brw_reg payload0
,
932 struct brw_reg payload1
,
935 struct brw_reg ex_desc
,
936 unsigned ex_desc_imm
,
939 void brw_ff_sync(struct brw_codegen
*p
,
944 unsigned response_length
,
947 void brw_svb_write(struct brw_codegen
*p
,
951 unsigned binding_table_index
,
952 bool send_commit_msg
);
954 brw_inst
*brw_fb_WRITE(struct brw_codegen
*p
,
955 struct brw_reg payload
,
956 struct brw_reg implied_header
,
957 unsigned msg_control
,
958 unsigned binding_table_index
,
960 unsigned response_length
,
962 bool last_render_target
,
963 bool header_present
);
965 brw_inst
*gen9_fb_READ(struct brw_codegen
*p
,
967 struct brw_reg payload
,
968 unsigned binding_table_index
,
970 unsigned response_length
,
973 void brw_SAMPLE(struct brw_codegen
*p
,
977 unsigned binding_table_index
,
980 unsigned response_length
,
982 unsigned header_present
,
984 unsigned return_format
);
986 void brw_adjust_sampler_state_pointer(struct brw_codegen
*p
,
987 struct brw_reg header
,
988 struct brw_reg sampler_index
);
990 void gen4_math(struct brw_codegen
*p
,
995 unsigned precision
);
997 void gen6_math(struct brw_codegen
*p
,
1000 struct brw_reg src0
,
1001 struct brw_reg src1
);
1003 void brw_oword_block_read(struct brw_codegen
*p
,
1004 struct brw_reg dest
,
1007 uint32_t bind_table_index
);
1009 unsigned brw_scratch_surface_idx(const struct brw_codegen
*p
);
1011 void brw_oword_block_read_scratch(struct brw_codegen
*p
,
1012 struct brw_reg dest
,
1017 void brw_oword_block_write_scratch(struct brw_codegen
*p
,
1022 void gen7_block_read_scratch(struct brw_codegen
*p
,
1023 struct brw_reg dest
,
1027 void brw_shader_time_add(struct brw_codegen
*p
,
1028 struct brw_reg payload
,
1029 uint32_t surf_index
);
1032 * Return the generation-specific jump distance scaling factor.
1034 * Given the number of instructions to jump, we need to scale by
1035 * some number to obtain the actual jump distance to program in an
1038 static inline unsigned
1039 brw_jump_scale(const struct gen_device_info
*devinfo
)
1041 /* Broadwell measures jump targets in bytes. */
1042 if (devinfo
->gen
>= 8)
1045 /* Ironlake and later measure jump targets in 64-bit data chunks (in order
1046 * (to support compaction), so each 128-bit instruction requires 2 chunks.
1048 if (devinfo
->gen
>= 5)
1051 /* Gen4 simply uses the number of 128-bit instructions. */
1055 void brw_barrier(struct brw_codegen
*p
, struct brw_reg src
);
1057 /* If/else/endif. Works by manipulating the execution flags on each
1060 brw_inst
*brw_IF(struct brw_codegen
*p
, unsigned execute_size
);
1061 brw_inst
*gen6_IF(struct brw_codegen
*p
, enum brw_conditional_mod conditional
,
1062 struct brw_reg src0
, struct brw_reg src1
);
1064 void brw_ELSE(struct brw_codegen
*p
);
1065 void brw_ENDIF(struct brw_codegen
*p
);
1069 brw_inst
*brw_DO(struct brw_codegen
*p
, unsigned execute_size
);
1071 brw_inst
*brw_WHILE(struct brw_codegen
*p
);
1073 brw_inst
*brw_BREAK(struct brw_codegen
*p
);
1074 brw_inst
*brw_CONT(struct brw_codegen
*p
);
1075 brw_inst
*gen6_HALT(struct brw_codegen
*p
);
1079 void brw_land_fwd_jump(struct brw_codegen
*p
, int jmp_insn_idx
);
1081 brw_inst
*brw_JMPI(struct brw_codegen
*p
, struct brw_reg index
,
1082 unsigned predicate_control
);
1084 void brw_NOP(struct brw_codegen
*p
);
1086 void brw_WAIT(struct brw_codegen
*p
);
1088 void brw_SYNC(struct brw_codegen
*p
, enum tgl_sync_function func
);
1090 /* Special case: there is never a destination, execution size will be
1093 void brw_CMP(struct brw_codegen
*p
,
1094 struct brw_reg dest
,
1095 unsigned conditional
,
1096 struct brw_reg src0
,
1097 struct brw_reg src1
);
1100 brw_untyped_atomic(struct brw_codegen
*p
,
1102 struct brw_reg payload
,
1103 struct brw_reg surface
,
1105 unsigned msg_length
,
1106 bool response_expected
,
1107 bool header_present
);
1110 brw_untyped_surface_read(struct brw_codegen
*p
,
1112 struct brw_reg payload
,
1113 struct brw_reg surface
,
1114 unsigned msg_length
,
1115 unsigned num_channels
);
1118 brw_untyped_surface_write(struct brw_codegen
*p
,
1119 struct brw_reg payload
,
1120 struct brw_reg surface
,
1121 unsigned msg_length
,
1122 unsigned num_channels
,
1123 bool header_present
);
1126 brw_memory_fence(struct brw_codegen
*p
,
1129 enum opcode send_op
,
1134 brw_pixel_interpolator_query(struct brw_codegen
*p
,
1135 struct brw_reg dest
,
1139 struct brw_reg data
,
1140 unsigned msg_length
,
1141 unsigned response_length
);
1144 brw_find_live_channel(struct brw_codegen
*p
,
1146 struct brw_reg mask
);
1149 brw_broadcast(struct brw_codegen
*p
,
1152 struct brw_reg idx
);
1155 brw_float_controls_mode(struct brw_codegen
*p
,
1156 unsigned mode
, unsigned mask
);
1158 /***********************************************************************
1162 void brw_copy_indirect_to_indirect(struct brw_codegen
*p
,
1163 struct brw_indirect dst_ptr
,
1164 struct brw_indirect src_ptr
,
1167 void brw_copy_from_indirect(struct brw_codegen
*p
,
1169 struct brw_indirect ptr
,
1172 void brw_copy4(struct brw_codegen
*p
,
1177 void brw_copy8(struct brw_codegen
*p
,
1182 void brw_math_invert( struct brw_codegen
*p
,
1184 struct brw_reg src
);
1186 void brw_set_src1(struct brw_codegen
*p
, brw_inst
*insn
, struct brw_reg reg
);
1188 void brw_set_desc_ex(struct brw_codegen
*p
, brw_inst
*insn
,
1189 unsigned desc
, unsigned ex_desc
);
1192 brw_set_desc(struct brw_codegen
*p
, brw_inst
*insn
, unsigned desc
)
1194 brw_set_desc_ex(p
, insn
, desc
, 0);
1197 void brw_set_uip_jip(struct brw_codegen
*p
, int start_offset
);
1199 enum brw_conditional_mod
brw_negate_cmod(enum brw_conditional_mod cmod
);
1200 enum brw_conditional_mod
brw_swap_cmod(enum brw_conditional_mod cmod
);
1202 /* brw_eu_compact.c */
1203 void brw_init_compaction_tables(const struct gen_device_info
*devinfo
);
1204 void brw_compact_instructions(struct brw_codegen
*p
, int start_offset
,
1205 struct disasm_info
*disasm
);
1206 void brw_uncompact_instruction(const struct gen_device_info
*devinfo
,
1207 brw_inst
*dst
, brw_compact_inst
*src
);
1208 bool brw_try_compact_instruction(const struct gen_device_info
*devinfo
,
1209 brw_compact_inst
*dst
, const brw_inst
*src
);
1211 void brw_debug_compact_uncompact(const struct gen_device_info
*devinfo
,
1212 brw_inst
*orig
, brw_inst
*uncompacted
);
1214 /* brw_eu_validate.c */
1215 bool brw_validate_instructions(const struct gen_device_info
*devinfo
,
1216 const void *assembly
, int start_offset
, int end_offset
,
1217 struct disasm_info
*disasm
);
1220 next_offset(const struct gen_device_info
*devinfo
, void *store
, int offset
)
1222 brw_inst
*insn
= (brw_inst
*)((char *)store
+ offset
);
1224 if (brw_inst_cmpt_control(devinfo
, insn
))
1230 struct opcode_desc
{
1239 const struct opcode_desc
*
1240 brw_opcode_desc(const struct gen_device_info
*devinfo
, enum opcode opcode
);
1242 const struct opcode_desc
*
1243 brw_opcode_desc_from_hw(const struct gen_device_info
*devinfo
, unsigned hw
);
1245 static inline unsigned
1246 brw_opcode_encode(const struct gen_device_info
*devinfo
, enum opcode opcode
)
1248 return brw_opcode_desc(devinfo
, opcode
)->hw
;
1251 static inline enum opcode
1252 brw_opcode_decode(const struct gen_device_info
*devinfo
, unsigned hw
)
1254 const struct opcode_desc
*desc
= brw_opcode_desc_from_hw(devinfo
, hw
);
1255 return desc
? (enum opcode
)desc
->ir
: BRW_OPCODE_ILLEGAL
;
1259 brw_inst_set_opcode(const struct gen_device_info
*devinfo
,
1260 brw_inst
*inst
, enum opcode opcode
)
1262 brw_inst_set_hw_opcode(devinfo
, inst
, brw_opcode_encode(devinfo
, opcode
));
1265 static inline enum opcode
1266 brw_inst_opcode(const struct gen_device_info
*devinfo
, const brw_inst
*inst
)
1268 return brw_opcode_decode(devinfo
, brw_inst_hw_opcode(devinfo
, inst
));
1272 is_3src(const struct gen_device_info
*devinfo
, enum opcode opcode
)
1274 const struct opcode_desc
*desc
= brw_opcode_desc(devinfo
, opcode
);
1275 return desc
&& desc
->nsrc
== 3;
1278 /** Maximum SEND message length */
1279 #define BRW_MAX_MSG_LENGTH 15
1281 /** First MRF register used by pull loads */
1282 #define FIRST_SPILL_MRF(gen) ((gen) == 6 ? 21 : 13)
1284 /** First MRF register used by spills */
1285 #define FIRST_PULL_LOAD_MRF(gen) ((gen) == 6 ? 16 : 13)