2 * Copyright © 2011 Intel Corporation
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:
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
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
28 #include "brw_vec4_builder.h"
29 #include "brw_vec4_live_variables.h"
30 #include "brw_vec4_vs.h"
31 #include "brw_dead_control_flow.h"
32 #include "common/gen_debug.h"
33 #include "program/prog_parameter.h"
34 #include "util/u_math.h"
36 #define MAX_INSTRUCTION (1 << 30)
45 memset((void*)this, 0, sizeof(*this));
46 this->file
= BAD_FILE
;
47 this->type
= BRW_REGISTER_TYPE_UD
;
50 src_reg::src_reg(enum brw_reg_file file
, int nr
, const glsl_type
*type
)
56 if (type
&& (type
->is_scalar() || type
->is_vector() || type
->is_matrix()))
57 this->swizzle
= brw_swizzle_for_size(type
->vector_elements
);
59 this->swizzle
= BRW_SWIZZLE_XYZW
;
61 this->type
= brw_type_for_base_type(type
);
64 /** Generic unset register constructor. */
70 src_reg::src_reg(struct ::brw_reg reg
) :
77 src_reg::src_reg(const dst_reg
®
) :
80 this->reladdr
= reg
.reladdr
;
81 this->swizzle
= brw_swizzle_for_mask(reg
.writemask
);
87 memset((void*)this, 0, sizeof(*this));
88 this->file
= BAD_FILE
;
89 this->type
= BRW_REGISTER_TYPE_UD
;
90 this->writemask
= WRITEMASK_XYZW
;
98 dst_reg::dst_reg(enum brw_reg_file file
, int nr
)
106 dst_reg::dst_reg(enum brw_reg_file file
, int nr
, const glsl_type
*type
,
113 this->type
= brw_type_for_base_type(type
);
114 this->writemask
= writemask
;
117 dst_reg::dst_reg(enum brw_reg_file file
, int nr
, brw_reg_type type
,
125 this->writemask
= writemask
;
128 dst_reg::dst_reg(struct ::brw_reg reg
) :
132 this->reladdr
= NULL
;
135 dst_reg::dst_reg(const src_reg
®
) :
138 this->writemask
= brw_mask_for_swizzle(reg
.swizzle
);
139 this->reladdr
= reg
.reladdr
;
143 dst_reg::equals(const dst_reg
&r
) const
145 return (this->backend_reg::equals(r
) &&
146 (reladdr
== r
.reladdr
||
147 (reladdr
&& r
.reladdr
&& reladdr
->equals(*r
.reladdr
))));
151 vec4_instruction::is_send_from_grf()
154 case SHADER_OPCODE_SHADER_TIME_ADD
:
155 case VS_OPCODE_PULL_CONSTANT_LOAD_GEN7
:
156 case SHADER_OPCODE_UNTYPED_ATOMIC
:
157 case SHADER_OPCODE_UNTYPED_SURFACE_READ
:
158 case SHADER_OPCODE_UNTYPED_SURFACE_WRITE
:
159 case SHADER_OPCODE_TYPED_ATOMIC
:
160 case SHADER_OPCODE_TYPED_SURFACE_READ
:
161 case SHADER_OPCODE_TYPED_SURFACE_WRITE
:
162 case VEC4_OPCODE_URB_READ
:
163 case TCS_OPCODE_URB_WRITE
:
164 case TCS_OPCODE_RELEASE_INPUT
:
165 case SHADER_OPCODE_BARRIER
:
173 * Returns true if this instruction's sources and destinations cannot
174 * safely be the same register.
176 * In most cases, a register can be written over safely by the same
177 * instruction that is its last use. For a single instruction, the
178 * sources are dereferenced before writing of the destination starts
181 * However, there are a few cases where this can be problematic:
183 * - Virtual opcodes that translate to multiple instructions in the
184 * code generator: if src == dst and one instruction writes the
185 * destination before a later instruction reads the source, then
186 * src will have been clobbered.
188 * The register allocator uses this information to set up conflicts between
189 * GRF sources and the destination.
192 vec4_instruction::has_source_and_destination_hazard() const
195 case TCS_OPCODE_SET_INPUT_URB_OFFSETS
:
196 case TCS_OPCODE_SET_OUTPUT_URB_OFFSETS
:
197 case TES_OPCODE_ADD_INDIRECT_URB_OFFSET
:
200 /* 8-wide compressed DF operations are executed as two 4-wide operations,
201 * so we have a src/dst hazard if the first half of the instruction
202 * overwrites the source of the second half. Prevent this by marking
203 * compressed instructions as having src/dst hazards, so the register
204 * allocator assigns safe register regions for dst and srcs.
206 return size_written
> REG_SIZE
;
211 vec4_instruction::size_read(unsigned arg
) const
214 case SHADER_OPCODE_SHADER_TIME_ADD
:
215 case SHADER_OPCODE_UNTYPED_ATOMIC
:
216 case SHADER_OPCODE_UNTYPED_SURFACE_READ
:
217 case SHADER_OPCODE_UNTYPED_SURFACE_WRITE
:
218 case SHADER_OPCODE_TYPED_ATOMIC
:
219 case SHADER_OPCODE_TYPED_SURFACE_READ
:
220 case SHADER_OPCODE_TYPED_SURFACE_WRITE
:
221 case TCS_OPCODE_URB_WRITE
:
223 return mlen
* REG_SIZE
;
225 case VS_OPCODE_PULL_CONSTANT_LOAD_GEN7
:
227 return mlen
* REG_SIZE
;
233 switch (src
[arg
].file
) {
238 return 4 * type_sz(src
[arg
].type
);
240 /* XXX - Represent actual vertical stride. */
241 return exec_size
* type_sz(src
[arg
].type
);
246 vec4_instruction::can_do_source_mods(const struct gen_device_info
*devinfo
)
248 if (devinfo
->gen
== 6 && is_math())
251 if (is_send_from_grf())
254 if (!backend_instruction::can_do_source_mods())
261 vec4_instruction::can_do_cmod()
263 if (!backend_instruction::can_do_cmod())
266 /* The accumulator result appears to get used for the conditional modifier
267 * generation. When negating a UD value, there is a 33rd bit generated for
268 * the sign in the accumulator value, so now you can't check, for example,
269 * equality with a 32-bit value. See piglit fs-op-neg-uvec4.
271 for (unsigned i
= 0; i
< 3; i
++) {
272 if (src
[i
].file
!= BAD_FILE
&&
273 type_is_unsigned_int(src
[i
].type
) && src
[i
].negate
)
281 vec4_instruction::can_do_writemask(const struct gen_device_info
*devinfo
)
284 case SHADER_OPCODE_GEN4_SCRATCH_READ
:
285 case VEC4_OPCODE_DOUBLE_TO_F32
:
286 case VEC4_OPCODE_DOUBLE_TO_D32
:
287 case VEC4_OPCODE_DOUBLE_TO_U32
:
288 case VEC4_OPCODE_TO_DOUBLE
:
289 case VEC4_OPCODE_PICK_LOW_32BIT
:
290 case VEC4_OPCODE_PICK_HIGH_32BIT
:
291 case VEC4_OPCODE_SET_LOW_32BIT
:
292 case VEC4_OPCODE_SET_HIGH_32BIT
:
293 case VS_OPCODE_PULL_CONSTANT_LOAD
:
294 case VS_OPCODE_PULL_CONSTANT_LOAD_GEN7
:
295 case VS_OPCODE_SET_SIMD4X2_HEADER_GEN9
:
296 case TCS_OPCODE_SET_INPUT_URB_OFFSETS
:
297 case TCS_OPCODE_SET_OUTPUT_URB_OFFSETS
:
298 case TES_OPCODE_CREATE_INPUT_READ_HEADER
:
299 case TES_OPCODE_ADD_INDIRECT_URB_OFFSET
:
300 case VEC4_OPCODE_URB_READ
:
301 case SHADER_OPCODE_MOV_INDIRECT
:
304 /* The MATH instruction on Gen6 only executes in align1 mode, which does
305 * not support writemasking.
307 if (devinfo
->gen
== 6 && is_math())
318 vec4_instruction::can_change_types() const
320 return dst
.type
== src
[0].type
&&
321 !src
[0].abs
&& !src
[0].negate
&& !saturate
&&
322 (opcode
== BRW_OPCODE_MOV
||
323 (opcode
== BRW_OPCODE_SEL
&&
324 dst
.type
== src
[1].type
&&
325 predicate
!= BRW_PREDICATE_NONE
&&
326 !src
[1].abs
&& !src
[1].negate
));
330 * Returns how many MRFs an opcode will write over.
332 * Note that this is not the 0 or 1 implied writes in an actual gen
333 * instruction -- the generate_* functions generate additional MOVs
337 vec4_visitor::implied_mrf_writes(vec4_instruction
*inst
)
339 if (inst
->mlen
== 0 || inst
->is_send_from_grf())
342 switch (inst
->opcode
) {
343 case SHADER_OPCODE_RCP
:
344 case SHADER_OPCODE_RSQ
:
345 case SHADER_OPCODE_SQRT
:
346 case SHADER_OPCODE_EXP2
:
347 case SHADER_OPCODE_LOG2
:
348 case SHADER_OPCODE_SIN
:
349 case SHADER_OPCODE_COS
:
351 case SHADER_OPCODE_INT_QUOTIENT
:
352 case SHADER_OPCODE_INT_REMAINDER
:
353 case SHADER_OPCODE_POW
:
354 case TCS_OPCODE_THREAD_END
:
356 case VS_OPCODE_URB_WRITE
:
358 case VS_OPCODE_PULL_CONSTANT_LOAD
:
360 case SHADER_OPCODE_GEN4_SCRATCH_READ
:
362 case SHADER_OPCODE_GEN4_SCRATCH_WRITE
:
364 case GS_OPCODE_URB_WRITE
:
365 case GS_OPCODE_URB_WRITE_ALLOCATE
:
366 case GS_OPCODE_THREAD_END
:
368 case GS_OPCODE_FF_SYNC
:
370 case TCS_OPCODE_URB_WRITE
:
372 case SHADER_OPCODE_SHADER_TIME_ADD
:
374 case SHADER_OPCODE_TEX
:
375 case SHADER_OPCODE_TXL
:
376 case SHADER_OPCODE_TXD
:
377 case SHADER_OPCODE_TXF
:
378 case SHADER_OPCODE_TXF_CMS
:
379 case SHADER_OPCODE_TXF_CMS_W
:
380 case SHADER_OPCODE_TXF_MCS
:
381 case SHADER_OPCODE_TXS
:
382 case SHADER_OPCODE_TG4
:
383 case SHADER_OPCODE_TG4_OFFSET
:
384 case SHADER_OPCODE_SAMPLEINFO
:
385 case SHADER_OPCODE_GET_BUFFER_SIZE
:
386 return inst
->header_size
;
388 unreachable("not reached");
393 src_reg::equals(const src_reg
&r
) const
395 return (this->backend_reg::equals(r
) &&
396 !reladdr
&& !r
.reladdr
);
400 src_reg::negative_equals(const src_reg
&r
) const
402 return this->backend_reg::negative_equals(r
) &&
403 !reladdr
&& !r
.reladdr
;
407 vec4_visitor::opt_vector_float()
409 bool progress
= false;
411 foreach_block(block
, cfg
) {
412 int last_reg
= -1, last_offset
= -1;
413 enum brw_reg_file last_reg_file
= BAD_FILE
;
415 uint8_t imm
[4] = { 0 };
417 vec4_instruction
*imm_inst
[4];
418 unsigned writemask
= 0;
419 enum brw_reg_type dest_type
= BRW_REGISTER_TYPE_F
;
421 foreach_inst_in_block_safe(vec4_instruction
, inst
, block
) {
423 enum brw_reg_type need_type
;
425 /* Look for unconditional MOVs from an immediate with a partial
426 * writemask. Skip type-conversion MOVs other than integer 0,
427 * where the type doesn't matter. See if the immediate can be
428 * represented as a VF.
430 if (inst
->opcode
== BRW_OPCODE_MOV
&&
431 inst
->src
[0].file
== IMM
&&
432 inst
->predicate
== BRW_PREDICATE_NONE
&&
433 inst
->dst
.writemask
!= WRITEMASK_XYZW
&&
434 type_sz(inst
->src
[0].type
) < 8 &&
435 (inst
->src
[0].type
== inst
->dst
.type
|| inst
->src
[0].d
== 0)) {
437 vf
= brw_float_to_vf(inst
->src
[0].d
);
438 need_type
= BRW_REGISTER_TYPE_D
;
441 vf
= brw_float_to_vf(inst
->src
[0].f
);
442 need_type
= BRW_REGISTER_TYPE_F
;
448 /* If this wasn't a MOV, or the destination register doesn't match,
449 * or we have to switch destination types, then this breaks our
450 * sequence. Combine anything we've accumulated so far.
452 if (last_reg
!= inst
->dst
.nr
||
453 last_offset
!= inst
->dst
.offset
||
454 last_reg_file
!= inst
->dst
.file
||
455 (vf
> 0 && dest_type
!= need_type
)) {
457 if (inst_count
> 1) {
459 memcpy(&vf
, imm
, sizeof(vf
));
460 vec4_instruction
*mov
= MOV(imm_inst
[0]->dst
, brw_imm_vf(vf
));
461 mov
->dst
.type
= dest_type
;
462 mov
->dst
.writemask
= writemask
;
463 inst
->insert_before(block
, mov
);
465 for (int i
= 0; i
< inst_count
; i
++) {
466 imm_inst
[i
]->remove(block
);
475 dest_type
= BRW_REGISTER_TYPE_F
;
477 for (int i
= 0; i
< 4; i
++) {
482 /* Record this instruction's value (if it was representable). */
484 if ((inst
->dst
.writemask
& WRITEMASK_X
) != 0)
486 if ((inst
->dst
.writemask
& WRITEMASK_Y
) != 0)
488 if ((inst
->dst
.writemask
& WRITEMASK_Z
) != 0)
490 if ((inst
->dst
.writemask
& WRITEMASK_W
) != 0)
493 writemask
|= inst
->dst
.writemask
;
494 imm_inst
[inst_count
++] = inst
;
496 last_reg
= inst
->dst
.nr
;
497 last_offset
= inst
->dst
.offset
;
498 last_reg_file
= inst
->dst
.file
;
500 dest_type
= need_type
;
506 invalidate_live_intervals();
511 /* Replaces unused channels of a swizzle with channels that are used.
513 * For instance, this pass transforms
515 * mov vgrf4.yz, vgrf5.wxzy
519 * mov vgrf4.yz, vgrf5.xxzx
521 * This eliminates false uses of some channels, letting dead code elimination
522 * remove the instructions that wrote them.
525 vec4_visitor::opt_reduce_swizzle()
527 bool progress
= false;
529 foreach_block_and_inst_safe(block
, vec4_instruction
, inst
, cfg
) {
530 if (inst
->dst
.file
== BAD_FILE
||
531 inst
->dst
.file
== ARF
||
532 inst
->dst
.file
== FIXED_GRF
||
533 inst
->is_send_from_grf())
538 /* Determine which channels of the sources are read. */
539 switch (inst
->opcode
) {
540 case VEC4_OPCODE_PACK_BYTES
:
542 case BRW_OPCODE_DPH
: /* FINISHME: DPH reads only three channels of src0,
543 * but all four of src1.
545 swizzle
= brw_swizzle_for_size(4);
548 swizzle
= brw_swizzle_for_size(3);
551 swizzle
= brw_swizzle_for_size(2);
554 case VEC4_OPCODE_TO_DOUBLE
:
555 case VEC4_OPCODE_DOUBLE_TO_F32
:
556 case VEC4_OPCODE_DOUBLE_TO_D32
:
557 case VEC4_OPCODE_DOUBLE_TO_U32
:
558 case VEC4_OPCODE_PICK_LOW_32BIT
:
559 case VEC4_OPCODE_PICK_HIGH_32BIT
:
560 case VEC4_OPCODE_SET_LOW_32BIT
:
561 case VEC4_OPCODE_SET_HIGH_32BIT
:
562 swizzle
= brw_swizzle_for_size(4);
566 swizzle
= brw_swizzle_for_mask(inst
->dst
.writemask
);
570 /* Update sources' swizzles. */
571 for (int i
= 0; i
< 3; i
++) {
572 if (inst
->src
[i
].file
!= VGRF
&&
573 inst
->src
[i
].file
!= ATTR
&&
574 inst
->src
[i
].file
!= UNIFORM
)
577 const unsigned new_swizzle
=
578 brw_compose_swizzle(swizzle
, inst
->src
[i
].swizzle
);
579 if (inst
->src
[i
].swizzle
!= new_swizzle
) {
580 inst
->src
[i
].swizzle
= new_swizzle
;
587 invalidate_live_intervals();
593 vec4_visitor::split_uniform_registers()
595 /* Prior to this, uniforms have been in an array sized according to
596 * the number of vector uniforms present, sparsely filled (so an
597 * aggregate results in reg indices being skipped over). Now we're
598 * going to cut those aggregates up so each .nr index is one
599 * vector. The goal is to make elimination of unused uniform
600 * components easier later.
602 foreach_block_and_inst(block
, vec4_instruction
, inst
, cfg
) {
603 for (int i
= 0 ; i
< 3; i
++) {
604 if (inst
->src
[i
].file
!= UNIFORM
)
607 assert(!inst
->src
[i
].reladdr
);
609 inst
->src
[i
].nr
+= inst
->src
[i
].offset
/ 16;
610 inst
->src
[i
].offset
%= 16;
615 /* This function returns the register number where we placed the uniform */
617 set_push_constant_loc(const int nr_uniforms
, int *new_uniform_count
,
618 const int src
, const int size
, const int channel_size
,
619 int *new_loc
, int *new_chan
,
623 /* Find the lowest place we can slot this uniform in. */
624 for (dst
= 0; dst
< nr_uniforms
; dst
++) {
625 if (ALIGN(new_chans_used
[dst
], channel_size
) + size
<= 4)
629 assert(dst
< nr_uniforms
);
632 new_chan
[src
] = ALIGN(new_chans_used
[dst
], channel_size
);
633 new_chans_used
[dst
] = ALIGN(new_chans_used
[dst
], channel_size
) + size
;
635 *new_uniform_count
= MAX2(*new_uniform_count
, dst
+ 1);
640 vec4_visitor::pack_uniform_registers()
642 uint8_t chans_used
[this->uniforms
];
643 int new_loc
[this->uniforms
];
644 int new_chan
[this->uniforms
];
645 bool is_aligned_to_dvec4
[this->uniforms
];
646 int new_chans_used
[this->uniforms
];
647 int channel_sizes
[this->uniforms
];
649 memset(chans_used
, 0, sizeof(chans_used
));
650 memset(new_loc
, 0, sizeof(new_loc
));
651 memset(new_chan
, 0, sizeof(new_chan
));
652 memset(new_chans_used
, 0, sizeof(new_chans_used
));
653 memset(is_aligned_to_dvec4
, 0, sizeof(is_aligned_to_dvec4
));
654 memset(channel_sizes
, 0, sizeof(channel_sizes
));
656 /* Find which uniform vectors are actually used by the program. We
657 * expect unused vector elements when we've moved array access out
658 * to pull constants, and from some GLSL code generators like wine.
660 foreach_block_and_inst(block
, vec4_instruction
, inst
, cfg
) {
662 switch (inst
->opcode
) {
663 case VEC4_OPCODE_PACK_BYTES
:
675 readmask
= inst
->dst
.writemask
;
679 for (int i
= 0 ; i
< 3; i
++) {
680 if (inst
->src
[i
].file
!= UNIFORM
)
683 assert(type_sz(inst
->src
[i
].type
) % 4 == 0);
684 int channel_size
= type_sz(inst
->src
[i
].type
) / 4;
686 int reg
= inst
->src
[i
].nr
;
687 for (int c
= 0; c
< 4; c
++) {
688 if (!(readmask
& (1 << c
)))
691 unsigned channel
= BRW_GET_SWZ(inst
->src
[i
].swizzle
, c
) + 1;
692 unsigned used
= MAX2(chans_used
[reg
], channel
* channel_size
);
694 chans_used
[reg
] = used
;
695 channel_sizes
[reg
] = MAX2(channel_sizes
[reg
], channel_size
);
697 is_aligned_to_dvec4
[reg
] = true;
698 is_aligned_to_dvec4
[reg
+ 1] = true;
699 chans_used
[reg
+ 1] = used
- 4;
700 channel_sizes
[reg
+ 1] = MAX2(channel_sizes
[reg
+ 1], channel_size
);
705 if (inst
->opcode
== SHADER_OPCODE_MOV_INDIRECT
&&
706 inst
->src
[0].file
== UNIFORM
) {
707 assert(inst
->src
[2].file
== BRW_IMMEDIATE_VALUE
);
708 assert(inst
->src
[0].subnr
== 0);
710 unsigned bytes_read
= inst
->src
[2].ud
;
711 assert(bytes_read
% 4 == 0);
712 unsigned vec4s_read
= DIV_ROUND_UP(bytes_read
, 16);
714 /* We just mark every register touched by a MOV_INDIRECT as being
715 * fully used. This ensures that it doesn't broken up piecewise by
716 * the next part of our packing algorithm.
718 int reg
= inst
->src
[0].nr
;
719 int channel_size
= type_sz(inst
->src
[0].type
) / 4;
720 for (unsigned i
= 0; i
< vec4s_read
; i
++) {
721 chans_used
[reg
+ i
] = 4;
722 channel_sizes
[reg
+ i
] = MAX2(channel_sizes
[reg
+ i
], channel_size
);
727 int new_uniform_count
= 0;
729 /* As the uniforms are going to be reordered, take the data from a temporary
730 * copy of the original param[].
732 uint32_t *param
= ralloc_array(NULL
, uint32_t, stage_prog_data
->nr_params
);
733 memcpy(param
, stage_prog_data
->param
,
734 sizeof(uint32_t) * stage_prog_data
->nr_params
);
736 /* Now, figure out a packing of the live uniform vectors into our
737 * push constants. Start with dvec{3,4} because they are aligned to
738 * dvec4 size (2 vec4).
740 for (int src
= 0; src
< uniforms
; src
++) {
741 int size
= chans_used
[src
];
743 if (size
== 0 || !is_aligned_to_dvec4
[src
])
746 /* dvec3 are aligned to dvec4 size, apply the alignment of the size
747 * to 4 to avoid moving last component of a dvec3 to the available
748 * location at the end of a previous dvec3. These available locations
749 * could be filled by smaller variables in next loop.
751 size
= ALIGN(size
, 4);
752 int dst
= set_push_constant_loc(uniforms
, &new_uniform_count
,
753 src
, size
, channel_sizes
[src
],
756 /* Move the references to the data */
757 for (int j
= 0; j
< size
; j
++) {
758 stage_prog_data
->param
[dst
* 4 + new_chan
[src
] + j
] =
763 /* Continue with the rest of data, which is aligned to vec4. */
764 for (int src
= 0; src
< uniforms
; src
++) {
765 int size
= chans_used
[src
];
767 if (size
== 0 || is_aligned_to_dvec4
[src
])
770 int dst
= set_push_constant_loc(uniforms
, &new_uniform_count
,
771 src
, size
, channel_sizes
[src
],
774 /* Move the references to the data */
775 for (int j
= 0; j
< size
; j
++) {
776 stage_prog_data
->param
[dst
* 4 + new_chan
[src
] + j
] =
782 this->uniforms
= new_uniform_count
;
784 /* Now, update the instructions for our repacked uniforms. */
785 foreach_block_and_inst(block
, vec4_instruction
, inst
, cfg
) {
786 for (int i
= 0 ; i
< 3; i
++) {
787 int src
= inst
->src
[i
].nr
;
789 if (inst
->src
[i
].file
!= UNIFORM
)
792 int chan
= new_chan
[src
] / channel_sizes
[src
];
793 inst
->src
[i
].nr
= new_loc
[src
];
794 inst
->src
[i
].swizzle
+= BRW_SWIZZLE4(chan
, chan
, chan
, chan
);
800 * Does algebraic optimizations (0 * a = 0, 1 * a = a, a + 0 = a).
802 * While GLSL IR also performs this optimization, we end up with it in
803 * our instruction stream for a couple of reasons. One is that we
804 * sometimes generate silly instructions, for example in array access
805 * where we'll generate "ADD offset, index, base" even if base is 0.
806 * The other is that GLSL IR's constant propagation doesn't track the
807 * components of aggregates, so some VS patterns (initialize matrix to
808 * 0, accumulate in vertex blending factors) end up breaking down to
809 * instructions involving 0.
812 vec4_visitor::opt_algebraic()
814 bool progress
= false;
816 foreach_block_and_inst(block
, vec4_instruction
, inst
, cfg
) {
817 switch (inst
->opcode
) {
819 if (inst
->src
[0].file
!= IMM
)
822 if (inst
->saturate
) {
823 /* Full mixed-type saturates don't happen. However, we can end up
826 * mov.sat(8) g21<1>DF -1F
828 * Other mixed-size-but-same-base-type cases may also be possible.
830 if (inst
->dst
.type
!= inst
->src
[0].type
&&
831 inst
->dst
.type
!= BRW_REGISTER_TYPE_DF
&&
832 inst
->src
[0].type
!= BRW_REGISTER_TYPE_F
)
833 assert(!"unimplemented: saturate mixed types");
835 if (brw_saturate_immediate(inst
->src
[0].type
,
836 &inst
->src
[0].as_brw_reg())) {
837 inst
->saturate
= false;
844 if (inst
->src
[1].is_zero()) {
845 inst
->opcode
= BRW_OPCODE_MOV
;
846 inst
->src
[1] = src_reg();
851 case VEC4_OPCODE_UNPACK_UNIFORM
:
852 if (inst
->src
[0].file
!= UNIFORM
) {
853 inst
->opcode
= BRW_OPCODE_MOV
;
859 if (inst
->src
[1].is_zero()) {
860 inst
->opcode
= BRW_OPCODE_MOV
;
861 inst
->src
[1] = src_reg();
867 if (inst
->src
[1].is_zero()) {
868 inst
->opcode
= BRW_OPCODE_MOV
;
869 switch (inst
->src
[0].type
) {
870 case BRW_REGISTER_TYPE_F
:
871 inst
->src
[0] = brw_imm_f(0.0f
);
873 case BRW_REGISTER_TYPE_D
:
874 inst
->src
[0] = brw_imm_d(0);
876 case BRW_REGISTER_TYPE_UD
:
877 inst
->src
[0] = brw_imm_ud(0u);
880 unreachable("not reached");
882 inst
->src
[1] = src_reg();
884 } else if (inst
->src
[1].is_one()) {
885 inst
->opcode
= BRW_OPCODE_MOV
;
886 inst
->src
[1] = src_reg();
888 } else if (inst
->src
[1].is_negative_one()) {
889 inst
->opcode
= BRW_OPCODE_MOV
;
890 inst
->src
[0].negate
= !inst
->src
[0].negate
;
891 inst
->src
[1] = src_reg();
895 case SHADER_OPCODE_BROADCAST
:
896 if (is_uniform(inst
->src
[0]) ||
897 inst
->src
[1].is_zero()) {
898 inst
->opcode
= BRW_OPCODE_MOV
;
899 inst
->src
[1] = src_reg();
900 inst
->force_writemask_all
= true;
911 invalidate_live_intervals();
917 * Only a limited number of hardware registers may be used for push
918 * constants, so this turns access to the overflowed constants into
922 vec4_visitor::move_push_constants_to_pull_constants()
924 int pull_constant_loc
[this->uniforms
];
926 /* Only allow 32 registers (256 uniform components) as push constants,
927 * which is the limit on gen6.
929 * If changing this value, note the limitation about total_regs in
932 int max_uniform_components
= 32 * 8;
933 if (this->uniforms
* 4 <= max_uniform_components
)
936 /* Make some sort of choice as to which uniforms get sent to pull
937 * constants. We could potentially do something clever here like
938 * look for the most infrequently used uniform vec4s, but leave
941 for (int i
= 0; i
< this->uniforms
* 4; i
+= 4) {
942 pull_constant_loc
[i
/ 4] = -1;
944 if (i
>= max_uniform_components
) {
945 uint32_t *values
= &stage_prog_data
->param
[i
];
947 /* Try to find an existing copy of this uniform in the pull
948 * constants if it was part of an array access already.
950 for (unsigned int j
= 0; j
< stage_prog_data
->nr_pull_params
; j
+= 4) {
953 for (matches
= 0; matches
< 4; matches
++) {
954 if (stage_prog_data
->pull_param
[j
+ matches
] != values
[matches
])
959 pull_constant_loc
[i
/ 4] = j
/ 4;
964 if (pull_constant_loc
[i
/ 4] == -1) {
965 assert(stage_prog_data
->nr_pull_params
% 4 == 0);
966 pull_constant_loc
[i
/ 4] = stage_prog_data
->nr_pull_params
/ 4;
968 for (int j
= 0; j
< 4; j
++) {
969 stage_prog_data
->pull_param
[stage_prog_data
->nr_pull_params
++] =
976 /* Now actually rewrite usage of the things we've moved to pull
979 foreach_block_and_inst_safe(block
, vec4_instruction
, inst
, cfg
) {
980 for (int i
= 0 ; i
< 3; i
++) {
981 if (inst
->src
[i
].file
!= UNIFORM
||
982 pull_constant_loc
[inst
->src
[i
].nr
] == -1)
985 int uniform
= inst
->src
[i
].nr
;
987 const glsl_type
*temp_type
= type_sz(inst
->src
[i
].type
) == 8 ?
988 glsl_type::dvec4_type
: glsl_type::vec4_type
;
989 dst_reg temp
= dst_reg(this, temp_type
);
991 emit_pull_constant_load(block
, inst
, temp
, inst
->src
[i
],
992 pull_constant_loc
[uniform
], src_reg());
994 inst
->src
[i
].file
= temp
.file
;
995 inst
->src
[i
].nr
= temp
.nr
;
996 inst
->src
[i
].offset
%= 16;
997 inst
->src
[i
].reladdr
= NULL
;
1001 /* Repack push constants to remove the now-unused ones. */
1002 pack_uniform_registers();
1005 /* Conditions for which we want to avoid setting the dependency control bits */
1007 vec4_visitor::is_dep_ctrl_unsafe(const vec4_instruction
*inst
)
1009 #define IS_DWORD(reg) \
1010 (reg.type == BRW_REGISTER_TYPE_UD || \
1011 reg.type == BRW_REGISTER_TYPE_D)
1013 #define IS_64BIT(reg) (reg.file != BAD_FILE && type_sz(reg.type) == 8)
1015 /* From the Cherryview and Broadwell PRMs:
1017 * "When source or destination datatype is 64b or operation is integer DWord
1018 * multiply, DepCtrl must not be used."
1020 * SKL PRMs don't include this restriction, however, gen7 seems to be
1021 * affected, at least by the 64b restriction, since DepCtrl with double
1022 * precision instructions seems to produce GPU hangs in some cases.
1024 if (devinfo
->gen
== 8 || gen_device_info_is_9lp(devinfo
)) {
1025 if (inst
->opcode
== BRW_OPCODE_MUL
&&
1026 IS_DWORD(inst
->src
[0]) &&
1027 IS_DWORD(inst
->src
[1]))
1031 if (devinfo
->gen
>= 7 && devinfo
->gen
<= 8) {
1032 if (IS_64BIT(inst
->dst
) || IS_64BIT(inst
->src
[0]) ||
1033 IS_64BIT(inst
->src
[1]) || IS_64BIT(inst
->src
[2]))
1040 if (devinfo
->gen
>= 8) {
1041 if (inst
->opcode
== BRW_OPCODE_F32TO16
)
1047 * In the presence of send messages, totally interrupt dependency
1048 * control. They're long enough that the chance of dependency
1049 * control around them just doesn't matter.
1052 * From the Ivy Bridge PRM, volume 4 part 3.7, page 80:
1053 * When a sequence of NoDDChk and NoDDClr are used, the last instruction that
1054 * completes the scoreboard clear must have a non-zero execution mask. This
1055 * means, if any kind of predication can change the execution mask or channel
1056 * enable of the last instruction, the optimization must be avoided. This is
1057 * to avoid instructions being shot down the pipeline when no writes are
1061 * Dependency control does not work well over math instructions.
1062 * NB: Discovered empirically
1064 return (inst
->mlen
|| inst
->predicate
|| inst
->is_math());
1068 * Sets the dependency control fields on instructions after register
1069 * allocation and before the generator is run.
1071 * When you have a sequence of instructions like:
1073 * DP4 temp.x vertex uniform[0]
1074 * DP4 temp.y vertex uniform[0]
1075 * DP4 temp.z vertex uniform[0]
1076 * DP4 temp.w vertex uniform[0]
1078 * The hardware doesn't know that it can actually run the later instructions
1079 * while the previous ones are in flight, producing stalls. However, we have
1080 * manual fields we can set in the instructions that let it do so.
1083 vec4_visitor::opt_set_dependency_control()
1085 vec4_instruction
*last_grf_write
[BRW_MAX_GRF
];
1086 uint8_t grf_channels_written
[BRW_MAX_GRF
];
1087 vec4_instruction
*last_mrf_write
[BRW_MAX_GRF
];
1088 uint8_t mrf_channels_written
[BRW_MAX_GRF
];
1090 assert(prog_data
->total_grf
||
1091 !"Must be called after register allocation");
1093 foreach_block (block
, cfg
) {
1094 memset(last_grf_write
, 0, sizeof(last_grf_write
));
1095 memset(last_mrf_write
, 0, sizeof(last_mrf_write
));
1097 foreach_inst_in_block (vec4_instruction
, inst
, block
) {
1098 /* If we read from a register that we were doing dependency control
1099 * on, don't do dependency control across the read.
1101 for (int i
= 0; i
< 3; i
++) {
1102 int reg
= inst
->src
[i
].nr
+ inst
->src
[i
].offset
/ REG_SIZE
;
1103 if (inst
->src
[i
].file
== VGRF
) {
1104 last_grf_write
[reg
] = NULL
;
1105 } else if (inst
->src
[i
].file
== FIXED_GRF
) {
1106 memset(last_grf_write
, 0, sizeof(last_grf_write
));
1109 assert(inst
->src
[i
].file
!= MRF
);
1112 if (is_dep_ctrl_unsafe(inst
)) {
1113 memset(last_grf_write
, 0, sizeof(last_grf_write
));
1114 memset(last_mrf_write
, 0, sizeof(last_mrf_write
));
1118 /* Now, see if we can do dependency control for this instruction
1119 * against a previous one writing to its destination.
1121 int reg
= inst
->dst
.nr
+ inst
->dst
.offset
/ REG_SIZE
;
1122 if (inst
->dst
.file
== VGRF
|| inst
->dst
.file
== FIXED_GRF
) {
1123 if (last_grf_write
[reg
] &&
1124 last_grf_write
[reg
]->dst
.offset
== inst
->dst
.offset
&&
1125 !(inst
->dst
.writemask
& grf_channels_written
[reg
])) {
1126 last_grf_write
[reg
]->no_dd_clear
= true;
1127 inst
->no_dd_check
= true;
1129 grf_channels_written
[reg
] = 0;
1132 last_grf_write
[reg
] = inst
;
1133 grf_channels_written
[reg
] |= inst
->dst
.writemask
;
1134 } else if (inst
->dst
.file
== MRF
) {
1135 if (last_mrf_write
[reg
] &&
1136 last_mrf_write
[reg
]->dst
.offset
== inst
->dst
.offset
&&
1137 !(inst
->dst
.writemask
& mrf_channels_written
[reg
])) {
1138 last_mrf_write
[reg
]->no_dd_clear
= true;
1139 inst
->no_dd_check
= true;
1141 mrf_channels_written
[reg
] = 0;
1144 last_mrf_write
[reg
] = inst
;
1145 mrf_channels_written
[reg
] |= inst
->dst
.writemask
;
1152 vec4_instruction::can_reswizzle(const struct gen_device_info
*devinfo
,
1157 /* Gen6 MATH instructions can not execute in align16 mode, so swizzles
1160 if (devinfo
->gen
== 6 && is_math() && swizzle
!= BRW_SWIZZLE_XYZW
)
1163 /* We can't swizzle implicit accumulator access. We'd have to
1164 * reswizzle the producer of the accumulator value in addition
1165 * to the consumer (i.e. both MUL and MACH). Just skip this.
1167 if (reads_accumulator_implicitly())
1170 if (!can_do_writemask(devinfo
) && dst_writemask
!= WRITEMASK_XYZW
)
1173 /* If this instruction sets anything not referenced by swizzle, then we'd
1174 * totally break it when we reswizzle.
1176 if (dst
.writemask
& ~swizzle_mask
)
1182 for (int i
= 0; i
< 3; i
++) {
1183 if (src
[i
].is_accumulator())
1191 * For any channels in the swizzle's source that were populated by this
1192 * instruction, rewrite the instruction to put the appropriate result directly
1193 * in those channels.
1195 * e.g. for swizzle=yywx, MUL a.xy b c -> MUL a.yy_x b.yy z.yy_x
1198 vec4_instruction::reswizzle(int dst_writemask
, int swizzle
)
1200 /* Destination write mask doesn't correspond to source swizzle for the dot
1201 * product and pack_bytes instructions.
1203 if (opcode
!= BRW_OPCODE_DP4
&& opcode
!= BRW_OPCODE_DPH
&&
1204 opcode
!= BRW_OPCODE_DP3
&& opcode
!= BRW_OPCODE_DP2
&&
1205 opcode
!= VEC4_OPCODE_PACK_BYTES
) {
1206 for (int i
= 0; i
< 3; i
++) {
1207 if (src
[i
].file
== BAD_FILE
|| src
[i
].file
== IMM
)
1210 src
[i
].swizzle
= brw_compose_swizzle(swizzle
, src
[i
].swizzle
);
1214 /* Apply the specified swizzle and writemask to the original mask of
1215 * written components.
1217 dst
.writemask
= dst_writemask
&
1218 brw_apply_swizzle_to_mask(swizzle
, dst
.writemask
);
1222 * Tries to reduce extra MOV instructions by taking temporary GRFs that get
1223 * just written and then MOVed into another reg and making the original write
1224 * of the GRF write directly to the final destination instead.
1227 vec4_visitor::opt_register_coalesce()
1229 bool progress
= false;
1232 calculate_live_intervals();
1234 foreach_block_and_inst_safe (block
, vec4_instruction
, inst
, cfg
) {
1238 if (inst
->opcode
!= BRW_OPCODE_MOV
||
1239 (inst
->dst
.file
!= VGRF
&& inst
->dst
.file
!= MRF
) ||
1241 inst
->src
[0].file
!= VGRF
||
1242 inst
->dst
.type
!= inst
->src
[0].type
||
1243 inst
->src
[0].abs
|| inst
->src
[0].negate
|| inst
->src
[0].reladdr
)
1246 /* Remove no-op MOVs */
1247 if (inst
->dst
.file
== inst
->src
[0].file
&&
1248 inst
->dst
.nr
== inst
->src
[0].nr
&&
1249 inst
->dst
.offset
== inst
->src
[0].offset
) {
1250 bool is_nop_mov
= true;
1252 for (unsigned c
= 0; c
< 4; c
++) {
1253 if ((inst
->dst
.writemask
& (1 << c
)) == 0)
1256 if (BRW_GET_SWZ(inst
->src
[0].swizzle
, c
) != c
) {
1263 inst
->remove(block
);
1269 bool to_mrf
= (inst
->dst
.file
== MRF
);
1271 /* Can't coalesce this GRF if someone else was going to
1274 if (var_range_end(var_from_reg(alloc
, dst_reg(inst
->src
[0])), 8) > ip
)
1277 /* We need to check interference with the final destination between this
1278 * instruction and the earliest instruction involved in writing the GRF
1279 * we're eliminating. To do that, keep track of which of our source
1280 * channels we've seen initialized.
1282 const unsigned chans_needed
=
1283 brw_apply_inv_swizzle_to_mask(inst
->src
[0].swizzle
,
1284 inst
->dst
.writemask
);
1285 unsigned chans_remaining
= chans_needed
;
1287 /* Now walk up the instruction stream trying to see if we can rewrite
1288 * everything writing to the temporary to write into the destination
1291 vec4_instruction
*_scan_inst
= (vec4_instruction
*)inst
->prev
;
1292 foreach_inst_in_block_reverse_starting_from(vec4_instruction
, scan_inst
,
1294 _scan_inst
= scan_inst
;
1296 if (regions_overlap(inst
->src
[0], inst
->size_read(0),
1297 scan_inst
->dst
, scan_inst
->size_written
)) {
1298 /* Found something writing to the reg we want to coalesce away. */
1300 /* SEND instructions can't have MRF as a destination. */
1301 if (scan_inst
->mlen
)
1304 if (devinfo
->gen
== 6) {
1305 /* gen6 math instructions must have the destination be
1306 * VGRF, so no compute-to-MRF for them.
1308 if (scan_inst
->is_math()) {
1314 /* VS_OPCODE_UNPACK_FLAGS_SIMD4X2 generates a bunch of mov(1)
1315 * instructions, and this optimization pass is not capable of
1316 * handling that. Bail on these instructions and hope that some
1317 * later optimization pass can do the right thing after they are
1320 if (scan_inst
->opcode
== VS_OPCODE_UNPACK_FLAGS_SIMD4X2
)
1323 /* This doesn't handle saturation on the instruction we
1324 * want to coalesce away if the register types do not match.
1325 * But if scan_inst is a non type-converting 'mov', we can fix
1328 if (inst
->saturate
&&
1329 inst
->dst
.type
!= scan_inst
->dst
.type
&&
1330 !(scan_inst
->opcode
== BRW_OPCODE_MOV
&&
1331 scan_inst
->dst
.type
== scan_inst
->src
[0].type
))
1334 /* Only allow coalescing between registers of the same type size.
1335 * Otherwise we would need to make the pass aware of the fact that
1336 * channel sizes are different for single and double precision.
1338 if (type_sz(inst
->src
[0].type
) != type_sz(scan_inst
->src
[0].type
))
1341 /* Check that scan_inst writes the same amount of data as the
1342 * instruction, otherwise coalescing would lead to writing a
1343 * different (larger or smaller) region of the destination
1345 if (scan_inst
->size_written
!= inst
->size_written
)
1348 /* If we can't handle the swizzle, bail. */
1349 if (!scan_inst
->can_reswizzle(devinfo
, inst
->dst
.writemask
,
1350 inst
->src
[0].swizzle
,
1355 /* This only handles coalescing writes of 8 channels (1 register
1356 * for single-precision and 2 registers for double-precision)
1357 * starting at the source offset of the copy instruction.
1359 if (DIV_ROUND_UP(scan_inst
->size_written
,
1360 type_sz(scan_inst
->dst
.type
)) > 8 ||
1361 scan_inst
->dst
.offset
!= inst
->src
[0].offset
)
1364 /* Mark which channels we found unconditional writes for. */
1365 if (!scan_inst
->predicate
)
1366 chans_remaining
&= ~scan_inst
->dst
.writemask
;
1368 if (chans_remaining
== 0)
1372 /* You can't read from an MRF, so if someone else reads our MRF's
1373 * source GRF that we wanted to rewrite, that stops us. If it's a
1374 * GRF we're trying to coalesce to, we don't actually handle
1375 * rewriting sources so bail in that case as well.
1377 bool interfered
= false;
1378 for (int i
= 0; i
< 3; i
++) {
1379 if (regions_overlap(inst
->src
[0], inst
->size_read(0),
1380 scan_inst
->src
[i
], scan_inst
->size_read(i
)))
1386 /* If somebody else writes the same channels of our destination here,
1387 * we can't coalesce before that.
1389 if (regions_overlap(inst
->dst
, inst
->size_written
,
1390 scan_inst
->dst
, scan_inst
->size_written
) &&
1391 (inst
->dst
.writemask
& scan_inst
->dst
.writemask
) != 0) {
1395 /* Check for reads of the register we're trying to coalesce into. We
1396 * can't go rewriting instructions above that to put some other value
1397 * in the register instead.
1399 if (to_mrf
&& scan_inst
->mlen
> 0) {
1400 if (inst
->dst
.nr
>= scan_inst
->base_mrf
&&
1401 inst
->dst
.nr
< scan_inst
->base_mrf
+ scan_inst
->mlen
) {
1405 for (int i
= 0; i
< 3; i
++) {
1406 if (regions_overlap(inst
->dst
, inst
->size_written
,
1407 scan_inst
->src
[i
], scan_inst
->size_read(i
)))
1415 if (chans_remaining
== 0) {
1416 /* If we've made it here, we have an MOV we want to coalesce out, and
1417 * a scan_inst pointing to the earliest instruction involved in
1418 * computing the value. Now go rewrite the instruction stream
1421 vec4_instruction
*scan_inst
= _scan_inst
;
1422 while (scan_inst
!= inst
) {
1423 if (scan_inst
->dst
.file
== VGRF
&&
1424 scan_inst
->dst
.nr
== inst
->src
[0].nr
&&
1425 scan_inst
->dst
.offset
== inst
->src
[0].offset
) {
1426 scan_inst
->reswizzle(inst
->dst
.writemask
,
1427 inst
->src
[0].swizzle
);
1428 scan_inst
->dst
.file
= inst
->dst
.file
;
1429 scan_inst
->dst
.nr
= inst
->dst
.nr
;
1430 scan_inst
->dst
.offset
= inst
->dst
.offset
;
1431 if (inst
->saturate
&&
1432 inst
->dst
.type
!= scan_inst
->dst
.type
) {
1433 /* If we have reached this point, scan_inst is a non
1434 * type-converting 'mov' and we can modify its register types
1435 * to match the ones in inst. Otherwise, we could have an
1436 * incorrect saturation result.
1438 scan_inst
->dst
.type
= inst
->dst
.type
;
1439 scan_inst
->src
[0].type
= inst
->src
[0].type
;
1441 scan_inst
->saturate
|= inst
->saturate
;
1443 scan_inst
= (vec4_instruction
*)scan_inst
->next
;
1445 inst
->remove(block
);
1451 invalidate_live_intervals();
1457 * Eliminate FIND_LIVE_CHANNEL instructions occurring outside any control
1458 * flow. We could probably do better here with some form of divergence
1462 vec4_visitor::eliminate_find_live_channel()
1464 bool progress
= false;
1467 if (!brw_stage_has_packed_dispatch(devinfo
, stage
, stage_prog_data
)) {
1468 /* The optimization below assumes that channel zero is live on thread
1469 * dispatch, which may not be the case if the fixed function dispatches
1475 foreach_block_and_inst_safe(block
, vec4_instruction
, inst
, cfg
) {
1476 switch (inst
->opcode
) {
1482 case BRW_OPCODE_ENDIF
:
1483 case BRW_OPCODE_WHILE
:
1487 case SHADER_OPCODE_FIND_LIVE_CHANNEL
:
1489 inst
->opcode
= BRW_OPCODE_MOV
;
1490 inst
->src
[0] = brw_imm_d(0);
1491 inst
->force_writemask_all
= true;
1505 * Splits virtual GRFs requesting more than one contiguous physical register.
1507 * We initially create large virtual GRFs for temporary structures, arrays,
1508 * and matrices, so that the visitor functions can add offsets to work their
1509 * way down to the actual member being accessed. But when it comes to
1510 * optimization, we'd like to treat each register as individual storage if
1513 * So far, the only thing that might prevent splitting is a send message from
1517 vec4_visitor::split_virtual_grfs()
1519 int num_vars
= this->alloc
.count
;
1520 int new_virtual_grf
[num_vars
];
1521 bool split_grf
[num_vars
];
1523 memset(new_virtual_grf
, 0, sizeof(new_virtual_grf
));
1525 /* Try to split anything > 0 sized. */
1526 for (int i
= 0; i
< num_vars
; i
++) {
1527 split_grf
[i
] = this->alloc
.sizes
[i
] != 1;
1530 /* Check that the instructions are compatible with the registers we're trying
1533 foreach_block_and_inst(block
, vec4_instruction
, inst
, cfg
) {
1534 if (inst
->dst
.file
== VGRF
&& regs_written(inst
) > 1)
1535 split_grf
[inst
->dst
.nr
] = false;
1537 for (int i
= 0; i
< 3; i
++) {
1538 if (inst
->src
[i
].file
== VGRF
&& regs_read(inst
, i
) > 1)
1539 split_grf
[inst
->src
[i
].nr
] = false;
1543 /* Allocate new space for split regs. Note that the virtual
1544 * numbers will be contiguous.
1546 for (int i
= 0; i
< num_vars
; i
++) {
1550 new_virtual_grf
[i
] = alloc
.allocate(1);
1551 for (unsigned j
= 2; j
< this->alloc
.sizes
[i
]; j
++) {
1552 unsigned reg
= alloc
.allocate(1);
1553 assert(reg
== new_virtual_grf
[i
] + j
- 1);
1556 this->alloc
.sizes
[i
] = 1;
1559 foreach_block_and_inst(block
, vec4_instruction
, inst
, cfg
) {
1560 if (inst
->dst
.file
== VGRF
&& split_grf
[inst
->dst
.nr
] &&
1561 inst
->dst
.offset
/ REG_SIZE
!= 0) {
1562 inst
->dst
.nr
= (new_virtual_grf
[inst
->dst
.nr
] +
1563 inst
->dst
.offset
/ REG_SIZE
- 1);
1564 inst
->dst
.offset
%= REG_SIZE
;
1566 for (int i
= 0; i
< 3; i
++) {
1567 if (inst
->src
[i
].file
== VGRF
&& split_grf
[inst
->src
[i
].nr
] &&
1568 inst
->src
[i
].offset
/ REG_SIZE
!= 0) {
1569 inst
->src
[i
].nr
= (new_virtual_grf
[inst
->src
[i
].nr
] +
1570 inst
->src
[i
].offset
/ REG_SIZE
- 1);
1571 inst
->src
[i
].offset
%= REG_SIZE
;
1575 invalidate_live_intervals();
1579 vec4_visitor::dump_instruction(backend_instruction
*be_inst
)
1581 dump_instruction(be_inst
, stderr
);
1585 vec4_visitor::dump_instruction(backend_instruction
*be_inst
, FILE *file
)
1587 vec4_instruction
*inst
= (vec4_instruction
*)be_inst
;
1589 if (inst
->predicate
) {
1590 fprintf(file
, "(%cf%d.%d%s) ",
1591 inst
->predicate_inverse
? '-' : '+',
1592 inst
->flag_subreg
/ 2,
1593 inst
->flag_subreg
% 2,
1594 pred_ctrl_align16
[inst
->predicate
]);
1597 fprintf(file
, "%s(%d)", brw_instruction_name(devinfo
, inst
->opcode
),
1600 fprintf(file
, ".sat");
1601 if (inst
->conditional_mod
) {
1602 fprintf(file
, "%s", conditional_modifier
[inst
->conditional_mod
]);
1603 if (!inst
->predicate
&&
1604 (devinfo
->gen
< 5 || (inst
->opcode
!= BRW_OPCODE_SEL
&&
1605 inst
->opcode
!= BRW_OPCODE_CSEL
&&
1606 inst
->opcode
!= BRW_OPCODE_IF
&&
1607 inst
->opcode
!= BRW_OPCODE_WHILE
))) {
1608 fprintf(file
, ".f%d.%d", inst
->flag_subreg
/ 2, inst
->flag_subreg
% 2);
1613 switch (inst
->dst
.file
) {
1615 fprintf(file
, "vgrf%d", inst
->dst
.nr
);
1618 fprintf(file
, "g%d", inst
->dst
.nr
);
1621 fprintf(file
, "m%d", inst
->dst
.nr
);
1624 switch (inst
->dst
.nr
) {
1626 fprintf(file
, "null");
1628 case BRW_ARF_ADDRESS
:
1629 fprintf(file
, "a0.%d", inst
->dst
.subnr
);
1631 case BRW_ARF_ACCUMULATOR
:
1632 fprintf(file
, "acc%d", inst
->dst
.subnr
);
1635 fprintf(file
, "f%d.%d", inst
->dst
.nr
& 0xf, inst
->dst
.subnr
);
1638 fprintf(file
, "arf%d.%d", inst
->dst
.nr
& 0xf, inst
->dst
.subnr
);
1643 fprintf(file
, "(null)");
1648 unreachable("not reached");
1650 if (inst
->dst
.offset
||
1651 (inst
->dst
.file
== VGRF
&&
1652 alloc
.sizes
[inst
->dst
.nr
] * REG_SIZE
!= inst
->size_written
)) {
1653 const unsigned reg_size
= (inst
->dst
.file
== UNIFORM
? 16 : REG_SIZE
);
1654 fprintf(file
, "+%d.%d", inst
->dst
.offset
/ reg_size
,
1655 inst
->dst
.offset
% reg_size
);
1657 if (inst
->dst
.writemask
!= WRITEMASK_XYZW
) {
1659 if (inst
->dst
.writemask
& 1)
1661 if (inst
->dst
.writemask
& 2)
1663 if (inst
->dst
.writemask
& 4)
1665 if (inst
->dst
.writemask
& 8)
1668 fprintf(file
, ":%s", brw_reg_type_to_letters(inst
->dst
.type
));
1670 if (inst
->src
[0].file
!= BAD_FILE
)
1671 fprintf(file
, ", ");
1673 for (int i
= 0; i
< 3 && inst
->src
[i
].file
!= BAD_FILE
; i
++) {
1674 if (inst
->src
[i
].negate
)
1676 if (inst
->src
[i
].abs
)
1678 switch (inst
->src
[i
].file
) {
1680 fprintf(file
, "vgrf%d", inst
->src
[i
].nr
);
1683 fprintf(file
, "g%d.%d", inst
->src
[i
].nr
, inst
->src
[i
].subnr
);
1686 fprintf(file
, "attr%d", inst
->src
[i
].nr
);
1689 fprintf(file
, "u%d", inst
->src
[i
].nr
);
1692 switch (inst
->src
[i
].type
) {
1693 case BRW_REGISTER_TYPE_F
:
1694 fprintf(file
, "%fF", inst
->src
[i
].f
);
1696 case BRW_REGISTER_TYPE_DF
:
1697 fprintf(file
, "%fDF", inst
->src
[i
].df
);
1699 case BRW_REGISTER_TYPE_D
:
1700 fprintf(file
, "%dD", inst
->src
[i
].d
);
1702 case BRW_REGISTER_TYPE_UD
:
1703 fprintf(file
, "%uU", inst
->src
[i
].ud
);
1705 case BRW_REGISTER_TYPE_VF
:
1706 fprintf(file
, "[%-gF, %-gF, %-gF, %-gF]",
1707 brw_vf_to_float((inst
->src
[i
].ud
>> 0) & 0xff),
1708 brw_vf_to_float((inst
->src
[i
].ud
>> 8) & 0xff),
1709 brw_vf_to_float((inst
->src
[i
].ud
>> 16) & 0xff),
1710 brw_vf_to_float((inst
->src
[i
].ud
>> 24) & 0xff));
1713 fprintf(file
, "???");
1718 switch (inst
->src
[i
].nr
) {
1720 fprintf(file
, "null");
1722 case BRW_ARF_ADDRESS
:
1723 fprintf(file
, "a0.%d", inst
->src
[i
].subnr
);
1725 case BRW_ARF_ACCUMULATOR
:
1726 fprintf(file
, "acc%d", inst
->src
[i
].subnr
);
1729 fprintf(file
, "f%d.%d", inst
->src
[i
].nr
& 0xf, inst
->src
[i
].subnr
);
1732 fprintf(file
, "arf%d.%d", inst
->src
[i
].nr
& 0xf, inst
->src
[i
].subnr
);
1737 fprintf(file
, "(null)");
1740 unreachable("not reached");
1743 if (inst
->src
[i
].offset
||
1744 (inst
->src
[i
].file
== VGRF
&&
1745 alloc
.sizes
[inst
->src
[i
].nr
] * REG_SIZE
!= inst
->size_read(i
))) {
1746 const unsigned reg_size
= (inst
->src
[i
].file
== UNIFORM
? 16 : REG_SIZE
);
1747 fprintf(file
, "+%d.%d", inst
->src
[i
].offset
/ reg_size
,
1748 inst
->src
[i
].offset
% reg_size
);
1751 if (inst
->src
[i
].file
!= IMM
) {
1752 static const char *chans
[4] = {"x", "y", "z", "w"};
1754 for (int c
= 0; c
< 4; c
++) {
1755 fprintf(file
, "%s", chans
[BRW_GET_SWZ(inst
->src
[i
].swizzle
, c
)]);
1759 if (inst
->src
[i
].abs
)
1762 if (inst
->src
[i
].file
!= IMM
) {
1763 fprintf(file
, ":%s", brw_reg_type_to_letters(inst
->src
[i
].type
));
1766 if (i
< 2 && inst
->src
[i
+ 1].file
!= BAD_FILE
)
1767 fprintf(file
, ", ");
1770 if (inst
->force_writemask_all
)
1771 fprintf(file
, " NoMask");
1773 if (inst
->exec_size
!= 8)
1774 fprintf(file
, " group%d", inst
->group
);
1776 fprintf(file
, "\n");
1781 vec4_vs_visitor::setup_attributes(int payload_reg
)
1783 foreach_block_and_inst(block
, vec4_instruction
, inst
, cfg
) {
1784 for (int i
= 0; i
< 3; i
++) {
1785 if (inst
->src
[i
].file
== ATTR
) {
1786 assert(inst
->src
[i
].offset
% REG_SIZE
== 0);
1787 int grf
= payload_reg
+ inst
->src
[i
].nr
+
1788 inst
->src
[i
].offset
/ REG_SIZE
;
1790 struct brw_reg reg
= brw_vec8_grf(grf
, 0);
1791 reg
.swizzle
= inst
->src
[i
].swizzle
;
1792 reg
.type
= inst
->src
[i
].type
;
1793 reg
.abs
= inst
->src
[i
].abs
;
1794 reg
.negate
= inst
->src
[i
].negate
;
1800 return payload_reg
+ vs_prog_data
->nr_attribute_slots
;
1804 vec4_visitor::setup_uniforms(int reg
)
1806 prog_data
->base
.dispatch_grf_start_reg
= reg
;
1808 /* The pre-gen6 VS requires that some push constants get loaded no
1809 * matter what, or the GPU would hang.
1811 if (devinfo
->gen
< 6 && this->uniforms
== 0) {
1812 brw_stage_prog_data_add_params(stage_prog_data
, 4);
1813 for (unsigned int i
= 0; i
< 4; i
++) {
1814 unsigned int slot
= this->uniforms
* 4 + i
;
1815 stage_prog_data
->param
[slot
] = BRW_PARAM_BUILTIN_ZERO
;
1821 reg
+= ALIGN(uniforms
, 2) / 2;
1824 for (int i
= 0; i
< 4; i
++)
1825 reg
+= stage_prog_data
->ubo_ranges
[i
].length
;
1827 stage_prog_data
->nr_params
= this->uniforms
* 4;
1829 prog_data
->base
.curb_read_length
=
1830 reg
- prog_data
->base
.dispatch_grf_start_reg
;
1836 vec4_vs_visitor::setup_payload(void)
1840 /* The payload always contains important data in g0, which contains
1841 * the URB handles that are passed on to the URB write at the end
1842 * of the thread. So, we always start push constants at g1.
1846 reg
= setup_uniforms(reg
);
1848 reg
= setup_attributes(reg
);
1850 this->first_non_payload_grf
= reg
;
1854 vec4_visitor::lower_minmax()
1856 assert(devinfo
->gen
< 6);
1858 bool progress
= false;
1860 foreach_block_and_inst_safe(block
, vec4_instruction
, inst
, cfg
) {
1861 const vec4_builder
ibld(this, block
, inst
);
1863 if (inst
->opcode
== BRW_OPCODE_SEL
&&
1864 inst
->predicate
== BRW_PREDICATE_NONE
) {
1865 /* FIXME: Using CMP doesn't preserve the NaN propagation semantics of
1866 * the original SEL.L/GE instruction
1868 ibld
.CMP(ibld
.null_reg_d(), inst
->src
[0], inst
->src
[1],
1869 inst
->conditional_mod
);
1870 inst
->predicate
= BRW_PREDICATE_NORMAL
;
1871 inst
->conditional_mod
= BRW_CONDITIONAL_NONE
;
1878 invalidate_live_intervals();
1884 vec4_visitor::get_timestamp()
1886 assert(devinfo
->gen
>= 7);
1888 src_reg ts
= src_reg(brw_reg(BRW_ARCHITECTURE_REGISTER_FILE
,
1893 BRW_REGISTER_TYPE_UD
,
1894 BRW_VERTICAL_STRIDE_0
,
1896 BRW_HORIZONTAL_STRIDE_4
,
1900 dst_reg dst
= dst_reg(this, glsl_type::uvec4_type
);
1902 vec4_instruction
*mov
= emit(MOV(dst
, ts
));
1903 /* We want to read the 3 fields we care about (mostly field 0, but also 2)
1904 * even if it's not enabled in the dispatch.
1906 mov
->force_writemask_all
= true;
1908 return src_reg(dst
);
1912 vec4_visitor::emit_shader_time_begin()
1914 current_annotation
= "shader time start";
1915 shader_start_time
= get_timestamp();
1919 vec4_visitor::emit_shader_time_end()
1921 current_annotation
= "shader time end";
1922 src_reg shader_end_time
= get_timestamp();
1925 /* Check that there weren't any timestamp reset events (assuming these
1926 * were the only two timestamp reads that happened).
1928 src_reg reset_end
= shader_end_time
;
1929 reset_end
.swizzle
= BRW_SWIZZLE_ZZZZ
;
1930 vec4_instruction
*test
= emit(AND(dst_null_ud(), reset_end
, brw_imm_ud(1u)));
1931 test
->conditional_mod
= BRW_CONDITIONAL_Z
;
1933 emit(IF(BRW_PREDICATE_NORMAL
));
1935 /* Take the current timestamp and get the delta. */
1936 shader_start_time
.negate
= true;
1937 dst_reg diff
= dst_reg(this, glsl_type::uint_type
);
1938 emit(ADD(diff
, shader_start_time
, shader_end_time
));
1940 /* If there were no instructions between the two timestamp gets, the diff
1941 * is 2 cycles. Remove that overhead, so I can forget about that when
1942 * trying to determine the time taken for single instructions.
1944 emit(ADD(diff
, src_reg(diff
), brw_imm_ud(-2u)));
1946 emit_shader_time_write(0, src_reg(diff
));
1947 emit_shader_time_write(1, brw_imm_ud(1u));
1948 emit(BRW_OPCODE_ELSE
);
1949 emit_shader_time_write(2, brw_imm_ud(1u));
1950 emit(BRW_OPCODE_ENDIF
);
1954 vec4_visitor::emit_shader_time_write(int shader_time_subindex
, src_reg value
)
1957 dst_reg(this, glsl_type::get_array_instance(glsl_type::vec4_type
, 2));
1959 dst_reg offset
= dst
;
1961 time
.offset
+= REG_SIZE
;
1963 offset
.type
= BRW_REGISTER_TYPE_UD
;
1964 int index
= shader_time_index
* 3 + shader_time_subindex
;
1965 emit(MOV(offset
, brw_imm_d(index
* BRW_SHADER_TIME_STRIDE
)));
1967 time
.type
= BRW_REGISTER_TYPE_UD
;
1968 emit(MOV(time
, value
));
1970 vec4_instruction
*inst
=
1971 emit(SHADER_OPCODE_SHADER_TIME_ADD
, dst_reg(), src_reg(dst
));
1976 is_align1_df(vec4_instruction
*inst
)
1978 switch (inst
->opcode
) {
1979 case VEC4_OPCODE_DOUBLE_TO_F32
:
1980 case VEC4_OPCODE_DOUBLE_TO_D32
:
1981 case VEC4_OPCODE_DOUBLE_TO_U32
:
1982 case VEC4_OPCODE_TO_DOUBLE
:
1983 case VEC4_OPCODE_PICK_LOW_32BIT
:
1984 case VEC4_OPCODE_PICK_HIGH_32BIT
:
1985 case VEC4_OPCODE_SET_LOW_32BIT
:
1986 case VEC4_OPCODE_SET_HIGH_32BIT
:
1994 * Three source instruction must have a GRF/MRF destination register.
1995 * ARF NULL is not allowed. Fix that up by allocating a temporary GRF.
1998 vec4_visitor::fixup_3src_null_dest()
2000 bool progress
= false;
2002 foreach_block_and_inst_safe (block
, vec4_instruction
, inst
, cfg
) {
2003 if (inst
->is_3src(devinfo
) && inst
->dst
.is_null()) {
2004 const unsigned size_written
= type_sz(inst
->dst
.type
);
2005 const unsigned num_regs
= DIV_ROUND_UP(size_written
, REG_SIZE
);
2007 inst
->dst
= retype(dst_reg(VGRF
, alloc
.allocate(num_regs
)),
2014 invalidate_live_intervals();
2018 vec4_visitor::convert_to_hw_regs()
2020 foreach_block_and_inst(block
, vec4_instruction
, inst
, cfg
) {
2021 for (int i
= 0; i
< 3; i
++) {
2022 class src_reg
&src
= inst
->src
[i
];
2026 reg
= byte_offset(brw_vecn_grf(4, src
.nr
, 0), src
.offset
);
2027 reg
.type
= src
.type
;
2029 reg
.negate
= src
.negate
;
2034 reg
= stride(byte_offset(brw_vec4_grf(
2035 prog_data
->base
.dispatch_grf_start_reg
+
2036 src
.nr
/ 2, src
.nr
% 2 * 4),
2039 reg
.type
= src
.type
;
2041 reg
.negate
= src
.negate
;
2043 /* This should have been moved to pull constants. */
2044 assert(!src
.reladdr
);
2049 if (type_sz(src
.type
) == 8) {
2050 reg
= src
.as_brw_reg();
2059 /* Probably unused. */
2060 reg
= brw_null_reg();
2061 reg
= retype(reg
, src
.type
);
2066 unreachable("not reached");
2069 apply_logical_swizzle(®
, inst
, i
);
2072 /* From IVB PRM, vol4, part3, "General Restrictions on Regioning
2075 * "If ExecSize = Width and HorzStride ≠ 0, VertStride must be set
2076 * to Width * HorzStride."
2078 * We can break this rule with DF sources on DF align1
2079 * instructions, because the exec_size would be 4 and width is 4.
2080 * As we know we are not accessing to next GRF, it is safe to
2081 * set vstride to the formula given by the rule itself.
2083 if (is_align1_df(inst
) && (cvt(inst
->exec_size
) - 1) == src
.width
)
2084 src
.vstride
= src
.width
+ src
.hstride
;
2087 if (inst
->is_3src(devinfo
)) {
2088 /* 3-src instructions with scalar sources support arbitrary subnr,
2089 * but don't actually use swizzles. Convert swizzle into subnr.
2090 * Skip this for double-precision instructions: RepCtrl=1 is not
2091 * allowed for them and needs special handling.
2093 for (int i
= 0; i
< 3; i
++) {
2094 if (inst
->src
[i
].vstride
== BRW_VERTICAL_STRIDE_0
&&
2095 type_sz(inst
->src
[i
].type
) < 8) {
2096 assert(brw_is_single_value_swizzle(inst
->src
[i
].swizzle
));
2097 inst
->src
[i
].subnr
+= 4 * BRW_GET_SWZ(inst
->src
[i
].swizzle
, 0);
2102 dst_reg
&dst
= inst
->dst
;
2105 switch (inst
->dst
.file
) {
2107 reg
= byte_offset(brw_vec8_grf(dst
.nr
, 0), dst
.offset
);
2108 reg
.type
= dst
.type
;
2109 reg
.writemask
= dst
.writemask
;
2113 reg
= byte_offset(brw_message_reg(dst
.nr
), dst
.offset
);
2114 assert((reg
.nr
& ~BRW_MRF_COMPR4
) < BRW_MAX_MRF(devinfo
->gen
));
2115 reg
.type
= dst
.type
;
2116 reg
.writemask
= dst
.writemask
;
2121 reg
= dst
.as_brw_reg();
2125 reg
= brw_null_reg();
2126 reg
= retype(reg
, dst
.type
);
2132 unreachable("not reached");
2140 stage_uses_interleaved_attributes(unsigned stage
,
2141 enum shader_dispatch_mode dispatch_mode
)
2144 case MESA_SHADER_TESS_EVAL
:
2146 case MESA_SHADER_GEOMETRY
:
2147 return dispatch_mode
!= DISPATCH_MODE_4X2_DUAL_OBJECT
;
2154 * Get the closest native SIMD width supported by the hardware for instruction
2155 * \p inst. The instruction will be left untouched by
2156 * vec4_visitor::lower_simd_width() if the returned value matches the
2157 * instruction's original execution size.
2160 get_lowered_simd_width(const struct gen_device_info
*devinfo
,
2161 enum shader_dispatch_mode dispatch_mode
,
2162 unsigned stage
, const vec4_instruction
*inst
)
2164 /* Do not split some instructions that require special handling */
2165 switch (inst
->opcode
) {
2166 case SHADER_OPCODE_GEN4_SCRATCH_READ
:
2167 case SHADER_OPCODE_GEN4_SCRATCH_WRITE
:
2168 return inst
->exec_size
;
2173 unsigned lowered_width
= MIN2(16, inst
->exec_size
);
2175 /* We need to split some cases of double-precision instructions that write
2176 * 2 registers. We only need to care about this in gen7 because that is the
2177 * only hardware that implements fp64 in Align16.
2179 if (devinfo
->gen
== 7 && inst
->size_written
> REG_SIZE
) {
2180 /* Align16 8-wide double-precision SEL does not work well. Verified
2183 if (inst
->opcode
== BRW_OPCODE_SEL
&& type_sz(inst
->dst
.type
) == 8)
2184 lowered_width
= MIN2(lowered_width
, 4);
2186 /* HSW PRM, 3D Media GPGPU Engine, Region Alignment Rules for Direct
2187 * Register Addressing:
2189 * "When destination spans two registers, the source MUST span two
2192 for (unsigned i
= 0; i
< 3; i
++) {
2193 if (inst
->src
[i
].file
== BAD_FILE
)
2195 if (inst
->size_read(i
) <= REG_SIZE
)
2196 lowered_width
= MIN2(lowered_width
, 4);
2198 /* Interleaved attribute setups use a vertical stride of 0, which
2199 * makes them hit the associated instruction decompression bug in gen7.
2200 * Split them to prevent this.
2202 if (inst
->src
[i
].file
== ATTR
&&
2203 stage_uses_interleaved_attributes(stage
, dispatch_mode
))
2204 lowered_width
= MIN2(lowered_width
, 4);
2208 /* IvyBridge can manage a maximum of 4 DFs per SIMD4x2 instruction, since
2209 * it doesn't support compression in Align16 mode, no matter if it has
2210 * force_writemask_all enabled or disabled (the latter is affected by the
2211 * compressed instruction bug in gen7, which is another reason to enforce
2214 if (devinfo
->gen
== 7 && !devinfo
->is_haswell
&&
2215 (get_exec_type_size(inst
) == 8 || type_sz(inst
->dst
.type
) == 8))
2216 lowered_width
= MIN2(lowered_width
, 4);
2218 return lowered_width
;
2222 dst_src_regions_overlap(vec4_instruction
*inst
)
2224 if (inst
->size_written
== 0)
2227 unsigned dst_start
= inst
->dst
.offset
;
2228 unsigned dst_end
= dst_start
+ inst
->size_written
- 1;
2229 for (int i
= 0; i
< 3; i
++) {
2230 if (inst
->src
[i
].file
== BAD_FILE
)
2233 if (inst
->dst
.file
!= inst
->src
[i
].file
||
2234 inst
->dst
.nr
!= inst
->src
[i
].nr
)
2237 unsigned src_start
= inst
->src
[i
].offset
;
2238 unsigned src_end
= src_start
+ inst
->size_read(i
) - 1;
2240 if ((dst_start
>= src_start
&& dst_start
<= src_end
) ||
2241 (dst_end
>= src_start
&& dst_end
<= src_end
) ||
2242 (dst_start
<= src_start
&& dst_end
>= src_end
)) {
2251 vec4_visitor::lower_simd_width()
2253 bool progress
= false;
2255 foreach_block_and_inst_safe(block
, vec4_instruction
, inst
, cfg
) {
2256 const unsigned lowered_width
=
2257 get_lowered_simd_width(devinfo
, prog_data
->dispatch_mode
, stage
, inst
);
2258 assert(lowered_width
<= inst
->exec_size
);
2259 if (lowered_width
== inst
->exec_size
)
2262 /* We need to deal with source / destination overlaps when splitting.
2263 * The hardware supports reading from and writing to the same register
2264 * in the same instruction, but we need to be careful that each split
2265 * instruction we produce does not corrupt the source of the next.
2267 * The easiest way to handle this is to make the split instructions write
2268 * to temporaries if there is an src/dst overlap and then move from the
2269 * temporaries to the original destination. We also need to consider
2270 * instructions that do partial writes via align1 opcodes, in which case
2271 * we need to make sure that the we initialize the temporary with the
2272 * value of the instruction's dst.
2274 bool needs_temp
= dst_src_regions_overlap(inst
);
2275 for (unsigned n
= 0; n
< inst
->exec_size
/ lowered_width
; n
++) {
2276 unsigned channel_offset
= lowered_width
* n
;
2278 unsigned size_written
= lowered_width
* type_sz(inst
->dst
.type
);
2280 /* Create the split instruction from the original so that we copy all
2281 * relevant instruction fields, then set the width and calculate the
2282 * new dst/src regions.
2284 vec4_instruction
*linst
= new(mem_ctx
) vec4_instruction(*inst
);
2285 linst
->exec_size
= lowered_width
;
2286 linst
->group
= channel_offset
;
2287 linst
->size_written
= size_written
;
2289 /* Compute split dst region */
2292 unsigned num_regs
= DIV_ROUND_UP(size_written
, REG_SIZE
);
2293 dst
= retype(dst_reg(VGRF
, alloc
.allocate(num_regs
)),
2295 if (inst
->is_align1_partial_write()) {
2296 vec4_instruction
*copy
= MOV(dst
, src_reg(inst
->dst
));
2297 copy
->exec_size
= lowered_width
;
2298 copy
->group
= channel_offset
;
2299 copy
->size_written
= size_written
;
2300 inst
->insert_before(block
, copy
);
2303 dst
= horiz_offset(inst
->dst
, channel_offset
);
2307 /* Compute split source regions */
2308 for (int i
= 0; i
< 3; i
++) {
2309 if (linst
->src
[i
].file
== BAD_FILE
)
2312 bool is_interleaved_attr
=
2313 linst
->src
[i
].file
== ATTR
&&
2314 stage_uses_interleaved_attributes(stage
,
2315 prog_data
->dispatch_mode
);
2317 if (!is_uniform(linst
->src
[i
]) && !is_interleaved_attr
)
2318 linst
->src
[i
] = horiz_offset(linst
->src
[i
], channel_offset
);
2321 inst
->insert_before(block
, linst
);
2323 /* If we used a temporary to store the result of the split
2324 * instruction, copy the result to the original destination
2327 vec4_instruction
*mov
=
2328 MOV(offset(inst
->dst
, lowered_width
, n
), src_reg(dst
));
2329 mov
->exec_size
= lowered_width
;
2330 mov
->group
= channel_offset
;
2331 mov
->size_written
= size_written
;
2332 mov
->predicate
= inst
->predicate
;
2333 inst
->insert_before(block
, mov
);
2337 inst
->remove(block
);
2342 invalidate_live_intervals();
2347 static brw_predicate
2348 scalarize_predicate(brw_predicate predicate
, unsigned writemask
)
2350 if (predicate
!= BRW_PREDICATE_NORMAL
)
2353 switch (writemask
) {
2355 return BRW_PREDICATE_ALIGN16_REPLICATE_X
;
2357 return BRW_PREDICATE_ALIGN16_REPLICATE_Y
;
2359 return BRW_PREDICATE_ALIGN16_REPLICATE_Z
;
2361 return BRW_PREDICATE_ALIGN16_REPLICATE_W
;
2363 unreachable("invalid writemask");
2367 /* Gen7 has a hardware decompression bug that we can exploit to represent
2368 * handful of additional swizzles natively.
2371 is_gen7_supported_64bit_swizzle(vec4_instruction
*inst
, unsigned arg
)
2373 switch (inst
->src
[arg
].swizzle
) {
2374 case BRW_SWIZZLE_XXXX
:
2375 case BRW_SWIZZLE_YYYY
:
2376 case BRW_SWIZZLE_ZZZZ
:
2377 case BRW_SWIZZLE_WWWW
:
2378 case BRW_SWIZZLE_XYXY
:
2379 case BRW_SWIZZLE_YXYX
:
2380 case BRW_SWIZZLE_ZWZW
:
2381 case BRW_SWIZZLE_WZWZ
:
2388 /* 64-bit sources use regions with a width of 2. These 2 elements in each row
2389 * can be addressed using 32-bit swizzles (which is what the hardware supports)
2390 * but it also means that the swizzle we apply on the first two components of a
2391 * dvec4 is coupled with the swizzle we use for the last 2. In other words,
2392 * only some specific swizzle combinations can be natively supported.
2394 * FIXME: we can go an step further and implement even more swizzle
2395 * variations using only partial scalarization.
2397 * For more details see:
2398 * https://bugs.freedesktop.org/show_bug.cgi?id=92760#c82
2401 vec4_visitor::is_supported_64bit_region(vec4_instruction
*inst
, unsigned arg
)
2403 const src_reg
&src
= inst
->src
[arg
];
2404 assert(type_sz(src
.type
) == 8);
2406 /* Uniform regions have a vstride=0. Because we use 2-wide rows with
2407 * 64-bit regions it means that we cannot access components Z/W, so
2408 * return false for any such case. Interleaved attributes will also be
2409 * mapped to GRF registers with a vstride of 0, so apply the same
2412 if ((is_uniform(src
) ||
2413 (stage_uses_interleaved_attributes(stage
, prog_data
->dispatch_mode
) &&
2414 src
.file
== ATTR
)) &&
2415 (brw_mask_for_swizzle(src
.swizzle
) & 12))
2418 switch (src
.swizzle
) {
2419 case BRW_SWIZZLE_XYZW
:
2420 case BRW_SWIZZLE_XXZZ
:
2421 case BRW_SWIZZLE_YYWW
:
2422 case BRW_SWIZZLE_YXWZ
:
2425 return devinfo
->gen
== 7 && is_gen7_supported_64bit_swizzle(inst
, arg
);
2430 vec4_visitor::scalarize_df()
2432 bool progress
= false;
2434 foreach_block_and_inst_safe(block
, vec4_instruction
, inst
, cfg
) {
2435 /* Skip DF instructions that operate in Align1 mode */
2436 if (is_align1_df(inst
))
2439 /* Check if this is a double-precision instruction */
2440 bool is_double
= type_sz(inst
->dst
.type
) == 8;
2441 for (int arg
= 0; !is_double
&& arg
< 3; arg
++) {
2442 is_double
= inst
->src
[arg
].file
!= BAD_FILE
&&
2443 type_sz(inst
->src
[arg
].type
) == 8;
2449 /* Skip the lowering for specific regioning scenarios that we can
2452 bool skip_lowering
= true;
2454 /* XY and ZW writemasks operate in 32-bit, which means that they don't
2455 * have a native 64-bit representation and they should always be split.
2457 if (inst
->dst
.writemask
== WRITEMASK_XY
||
2458 inst
->dst
.writemask
== WRITEMASK_ZW
) {
2459 skip_lowering
= false;
2461 for (unsigned i
= 0; i
< 3; i
++) {
2462 if (inst
->src
[i
].file
== BAD_FILE
|| type_sz(inst
->src
[i
].type
) < 8)
2464 skip_lowering
= skip_lowering
&& is_supported_64bit_region(inst
, i
);
2471 /* Generate scalar instructions for each enabled channel */
2472 for (unsigned chan
= 0; chan
< 4; chan
++) {
2473 unsigned chan_mask
= 1 << chan
;
2474 if (!(inst
->dst
.writemask
& chan_mask
))
2477 vec4_instruction
*scalar_inst
= new(mem_ctx
) vec4_instruction(*inst
);
2479 for (unsigned i
= 0; i
< 3; i
++) {
2480 unsigned swz
= BRW_GET_SWZ(inst
->src
[i
].swizzle
, chan
);
2481 scalar_inst
->src
[i
].swizzle
= BRW_SWIZZLE4(swz
, swz
, swz
, swz
);
2484 scalar_inst
->dst
.writemask
= chan_mask
;
2486 if (inst
->predicate
!= BRW_PREDICATE_NONE
) {
2487 scalar_inst
->predicate
=
2488 scalarize_predicate(inst
->predicate
, chan_mask
);
2491 inst
->insert_before(block
, scalar_inst
);
2494 inst
->remove(block
);
2499 invalidate_live_intervals();
2505 vec4_visitor::lower_64bit_mad_to_mul_add()
2507 bool progress
= false;
2509 foreach_block_and_inst_safe(block
, vec4_instruction
, inst
, cfg
) {
2510 if (inst
->opcode
!= BRW_OPCODE_MAD
)
2513 if (type_sz(inst
->dst
.type
) != 8)
2516 dst_reg mul_dst
= dst_reg(this, glsl_type::dvec4_type
);
2518 /* Use the copy constructor so we copy all relevant instruction fields
2519 * from the original mad into the add and mul instructions
2521 vec4_instruction
*mul
= new(mem_ctx
) vec4_instruction(*inst
);
2522 mul
->opcode
= BRW_OPCODE_MUL
;
2524 mul
->src
[0] = inst
->src
[1];
2525 mul
->src
[1] = inst
->src
[2];
2526 mul
->src
[2].file
= BAD_FILE
;
2528 vec4_instruction
*add
= new(mem_ctx
) vec4_instruction(*inst
);
2529 add
->opcode
= BRW_OPCODE_ADD
;
2530 add
->src
[0] = src_reg(mul_dst
);
2531 add
->src
[1] = inst
->src
[0];
2532 add
->src
[2].file
= BAD_FILE
;
2534 inst
->insert_before(block
, mul
);
2535 inst
->insert_before(block
, add
);
2536 inst
->remove(block
);
2542 invalidate_live_intervals();
2547 /* The align16 hardware can only do 32-bit swizzle channels, so we need to
2548 * translate the logical 64-bit swizzle channels that we use in the Vec4 IR
2549 * to 32-bit swizzle channels in hardware registers.
2551 * @inst and @arg identify the original vec4 IR source operand we need to
2552 * translate the swizzle for and @hw_reg is the hardware register where we
2553 * will write the hardware swizzle to use.
2555 * This pass assumes that Align16/DF instructions have been fully scalarized
2556 * previously so there is just one 64-bit swizzle channel to deal with for any
2557 * given Vec4 IR source.
2560 vec4_visitor::apply_logical_swizzle(struct brw_reg
*hw_reg
,
2561 vec4_instruction
*inst
, int arg
)
2563 src_reg reg
= inst
->src
[arg
];
2565 if (reg
.file
== BAD_FILE
|| reg
.file
== BRW_IMMEDIATE_VALUE
)
2568 /* If this is not a 64-bit operand or this is a scalar instruction we don't
2569 * need to do anything about the swizzles.
2571 if(type_sz(reg
.type
) < 8 || is_align1_df(inst
)) {
2572 hw_reg
->swizzle
= reg
.swizzle
;
2576 /* Take the 64-bit logical swizzle channel and translate it to 32-bit */
2577 assert(brw_is_single_value_swizzle(reg
.swizzle
) ||
2578 is_supported_64bit_region(inst
, arg
));
2580 /* Apply the region <2, 2, 1> for GRF or <0, 2, 1> for uniforms, as align16
2581 * HW can only do 32-bit swizzle channels.
2583 hw_reg
->width
= BRW_WIDTH_2
;
2585 if (is_supported_64bit_region(inst
, arg
) &&
2586 !is_gen7_supported_64bit_swizzle(inst
, arg
)) {
2587 /* Supported 64-bit swizzles are those such that their first two
2588 * components, when expanded to 32-bit swizzles, match the semantics
2589 * of the original 64-bit swizzle with 2-wide row regioning.
2591 unsigned swizzle0
= BRW_GET_SWZ(reg
.swizzle
, 0);
2592 unsigned swizzle1
= BRW_GET_SWZ(reg
.swizzle
, 1);
2593 hw_reg
->swizzle
= BRW_SWIZZLE4(swizzle0
* 2, swizzle0
* 2 + 1,
2594 swizzle1
* 2, swizzle1
* 2 + 1);
2596 /* If we got here then we have one of the following:
2598 * 1. An unsupported swizzle, which should be single-value thanks to the
2599 * scalarization pass.
2601 * 2. A gen7 supported swizzle. These can be single-value or double-value
2602 * swizzles. If the latter, they are never cross-dvec2 channels. For
2603 * these we always need to activate the gen7 vstride=0 exploit.
2605 unsigned swizzle0
= BRW_GET_SWZ(reg
.swizzle
, 0);
2606 unsigned swizzle1
= BRW_GET_SWZ(reg
.swizzle
, 1);
2607 assert((swizzle0
< 2) == (swizzle1
< 2));
2609 /* To gain access to Z/W components we need to select the second half
2610 * of the register and then use a X/Y swizzle to select Z/W respectively.
2612 if (swizzle0
>= 2) {
2613 *hw_reg
= suboffset(*hw_reg
, 2);
2618 /* All gen7-specific supported swizzles require the vstride=0 exploit */
2619 if (devinfo
->gen
== 7 && is_gen7_supported_64bit_swizzle(inst
, arg
))
2620 hw_reg
->vstride
= BRW_VERTICAL_STRIDE_0
;
2622 /* Any 64-bit source with an offset at 16B is intended to address the
2623 * second half of a register and needs a vertical stride of 0 so we:
2625 * 1. Don't violate register region restrictions.
2626 * 2. Activate the gen7 instruction decompresion bug exploit when
2629 if (hw_reg
->subnr
% REG_SIZE
== 16) {
2630 assert(devinfo
->gen
== 7);
2631 hw_reg
->vstride
= BRW_VERTICAL_STRIDE_0
;
2634 hw_reg
->swizzle
= BRW_SWIZZLE4(swizzle0
* 2, swizzle0
* 2 + 1,
2635 swizzle1
* 2, swizzle1
* 2 + 1);
2642 if (shader_time_index
>= 0)
2643 emit_shader_time_begin();
2656 /* Before any optimization, push array accesses out to scratch
2657 * space where we need them to be. This pass may allocate new
2658 * virtual GRFs, so we want to do it early. It also makes sure
2659 * that we have reladdr computations available for CSE, since we'll
2660 * often do repeated subexpressions for those.
2662 move_grf_array_access_to_scratch();
2663 move_uniform_array_access_to_pull_constants();
2665 pack_uniform_registers();
2666 move_push_constants_to_pull_constants();
2667 split_virtual_grfs();
2669 #define OPT(pass, args...) ({ \
2671 bool this_progress = pass(args); \
2673 if (unlikely(INTEL_DEBUG & DEBUG_OPTIMIZER) && this_progress) { \
2674 char filename[64]; \
2675 snprintf(filename, 64, "%s-%s-%02d-%02d-" #pass, \
2676 stage_abbrev, nir->info.name, iteration, pass_num); \
2678 backend_shader::dump_instructions(filename); \
2681 progress = progress || this_progress; \
2686 if (unlikely(INTEL_DEBUG
& DEBUG_OPTIMIZER
)) {
2688 snprintf(filename
, 64, "%s-%s-00-00-start",
2689 stage_abbrev
, nir
->info
.name
);
2691 backend_shader::dump_instructions(filename
);
2702 OPT(opt_predicated_break
, this);
2703 OPT(opt_reduce_swizzle
);
2704 OPT(dead_code_eliminate
);
2705 OPT(dead_control_flow_eliminate
, this);
2706 OPT(opt_copy_propagation
);
2707 OPT(opt_cmod_propagation
);
2710 OPT(opt_register_coalesce
);
2711 OPT(eliminate_find_live_channel
);
2716 if (OPT(opt_vector_float
)) {
2718 OPT(opt_copy_propagation
, false);
2719 OPT(opt_copy_propagation
, true);
2720 OPT(dead_code_eliminate
);
2723 if (devinfo
->gen
<= 5 && OPT(lower_minmax
)) {
2724 OPT(opt_cmod_propagation
);
2726 OPT(opt_copy_propagation
);
2727 OPT(dead_code_eliminate
);
2730 if (OPT(lower_simd_width
)) {
2731 OPT(opt_copy_propagation
);
2732 OPT(dead_code_eliminate
);
2738 OPT(lower_64bit_mad_to_mul_add
);
2740 /* Run this before payload setup because tesselation shaders
2741 * rely on it to prevent cross dvec2 regioning on DF attributes
2742 * that are setup so that XY are on the second half of register and
2743 * ZW are in the first half of the next.
2749 if (unlikely(INTEL_DEBUG
& DEBUG_SPILL_VEC4
)) {
2750 /* Debug of register spilling: Go spill everything. */
2751 const int grf_count
= alloc
.count
;
2752 float spill_costs
[alloc
.count
];
2753 bool no_spill
[alloc
.count
];
2754 evaluate_spill_costs(spill_costs
, no_spill
);
2755 for (int i
= 0; i
< grf_count
; i
++) {
2761 /* We want to run this after spilling because 64-bit (un)spills need to
2762 * emit code to shuffle 64-bit data for the 32-bit scratch read/write
2763 * messages that can produce unsupported 64-bit swizzle regions.
2768 fixup_3src_null_dest();
2770 bool allocated_without_spills
= reg_allocate();
2772 if (!allocated_without_spills
) {
2773 compiler
->shader_perf_log(log_data
,
2774 "%s shader triggered register spilling. "
2775 "Try reducing the number of live vec4 values "
2776 "to improve performance.\n",
2779 while (!reg_allocate()) {
2784 /* We want to run this after spilling because 64-bit (un)spills need to
2785 * emit code to shuffle 64-bit data for the 32-bit scratch read/write
2786 * messages that can produce unsupported 64-bit swizzle regions.
2791 opt_schedule_instructions();
2793 opt_set_dependency_control();
2795 convert_to_hw_regs();
2797 if (last_scratch
> 0) {
2798 prog_data
->base
.total_scratch
=
2799 brw_get_scratch_size(last_scratch
* REG_SIZE
);
2805 } /* namespace brw */
2810 * Compile a vertex shader.
2812 * Returns the final assembly and the program's size.
2815 brw_compile_vs(const struct brw_compiler
*compiler
, void *log_data
,
2817 const struct brw_vs_prog_key
*key
,
2818 struct brw_vs_prog_data
*prog_data
,
2820 int shader_time_index
,
2823 const bool is_scalar
= compiler
->scalar_stage
[MESA_SHADER_VERTEX
];
2824 shader
= brw_nir_apply_sampler_key(shader
, compiler
, &key
->tex
, is_scalar
);
2826 const unsigned *assembly
= NULL
;
2828 if (prog_data
->base
.vue_map
.varying_to_slot
[VARYING_SLOT_EDGE
] != -1) {
2829 /* If the output VUE map contains VARYING_SLOT_EDGE then we need to copy
2830 * the edge flag from VERT_ATTRIB_EDGEFLAG. This will be done
2831 * automatically by brw_vec4_visitor::emit_urb_slot but we need to
2832 * ensure that prog_data->inputs_read is accurate.
2834 * In order to make late NIR passes aware of the change, we actually
2835 * whack shader->info.inputs_read instead. This is safe because we just
2836 * made a copy of the shader.
2839 assert(key
->copy_edgeflag
);
2840 shader
->info
.inputs_read
|= VERT_BIT_EDGEFLAG
;
2843 prog_data
->inputs_read
= shader
->info
.inputs_read
;
2844 prog_data
->double_inputs_read
= shader
->info
.vs
.double_inputs
;
2846 brw_nir_lower_vs_inputs(shader
, key
->gl_attrib_wa_flags
);
2847 brw_nir_lower_vue_outputs(shader
);
2848 shader
= brw_postprocess_nir(shader
, compiler
, is_scalar
);
2850 prog_data
->base
.clip_distance_mask
=
2851 ((1 << shader
->info
.clip_distance_array_size
) - 1);
2852 prog_data
->base
.cull_distance_mask
=
2853 ((1 << shader
->info
.cull_distance_array_size
) - 1) <<
2854 shader
->info
.clip_distance_array_size
;
2856 unsigned nr_attribute_slots
= util_bitcount64(prog_data
->inputs_read
);
2858 /* gl_VertexID and gl_InstanceID are system values, but arrive via an
2859 * incoming vertex attribute. So, add an extra slot.
2861 if (shader
->info
.system_values_read
&
2862 (BITFIELD64_BIT(SYSTEM_VALUE_FIRST_VERTEX
) |
2863 BITFIELD64_BIT(SYSTEM_VALUE_BASE_INSTANCE
) |
2864 BITFIELD64_BIT(SYSTEM_VALUE_VERTEX_ID_ZERO_BASE
) |
2865 BITFIELD64_BIT(SYSTEM_VALUE_INSTANCE_ID
))) {
2866 nr_attribute_slots
++;
2869 /* gl_DrawID and IsIndexedDraw share its very own vec4 */
2870 if (shader
->info
.system_values_read
&
2871 (BITFIELD64_BIT(SYSTEM_VALUE_DRAW_ID
) |
2872 BITFIELD64_BIT(SYSTEM_VALUE_IS_INDEXED_DRAW
))) {
2873 nr_attribute_slots
++;
2876 if (shader
->info
.system_values_read
&
2877 BITFIELD64_BIT(SYSTEM_VALUE_IS_INDEXED_DRAW
))
2878 prog_data
->uses_is_indexed_draw
= true;
2880 if (shader
->info
.system_values_read
&
2881 BITFIELD64_BIT(SYSTEM_VALUE_FIRST_VERTEX
))
2882 prog_data
->uses_firstvertex
= true;
2884 if (shader
->info
.system_values_read
&
2885 BITFIELD64_BIT(SYSTEM_VALUE_BASE_INSTANCE
))
2886 prog_data
->uses_baseinstance
= true;
2888 if (shader
->info
.system_values_read
&
2889 BITFIELD64_BIT(SYSTEM_VALUE_VERTEX_ID_ZERO_BASE
))
2890 prog_data
->uses_vertexid
= true;
2892 if (shader
->info
.system_values_read
&
2893 BITFIELD64_BIT(SYSTEM_VALUE_INSTANCE_ID
))
2894 prog_data
->uses_instanceid
= true;
2896 if (shader
->info
.system_values_read
&
2897 BITFIELD64_BIT(SYSTEM_VALUE_DRAW_ID
))
2898 prog_data
->uses_drawid
= true;
2900 /* The 3DSTATE_VS documentation lists the lower bound on "Vertex URB Entry
2901 * Read Length" as 1 in vec4 mode, and 0 in SIMD8 mode. Empirically, in
2902 * vec4 mode, the hardware appears to wedge unless we read something.
2905 prog_data
->base
.urb_read_length
=
2906 DIV_ROUND_UP(nr_attribute_slots
, 2);
2908 prog_data
->base
.urb_read_length
=
2909 DIV_ROUND_UP(MAX2(nr_attribute_slots
, 1), 2);
2911 prog_data
->nr_attribute_slots
= nr_attribute_slots
;
2913 /* Since vertex shaders reuse the same VUE entry for inputs and outputs
2914 * (overwriting the original contents), we need to make sure the size is
2915 * the larger of the two.
2917 const unsigned vue_entries
=
2918 MAX2(nr_attribute_slots
, (unsigned)prog_data
->base
.vue_map
.num_slots
);
2920 if (compiler
->devinfo
->gen
== 6) {
2921 prog_data
->base
.urb_entry_size
= DIV_ROUND_UP(vue_entries
, 8);
2923 prog_data
->base
.urb_entry_size
= DIV_ROUND_UP(vue_entries
, 4);
2924 /* On Cannonlake software shall not program an allocation size that
2925 * specifies a size that is a multiple of 3 64B (512-bit) cachelines.
2927 if (compiler
->devinfo
->gen
== 10 &&
2928 prog_data
->base
.urb_entry_size
% 3 == 0)
2929 prog_data
->base
.urb_entry_size
++;
2932 if (INTEL_DEBUG
& DEBUG_VS
) {
2933 fprintf(stderr
, "VS Output ");
2934 brw_print_vue_map(stderr
, &prog_data
->base
.vue_map
);
2938 prog_data
->base
.dispatch_mode
= DISPATCH_MODE_SIMD8
;
2940 fs_visitor
v(compiler
, log_data
, mem_ctx
, key
, &prog_data
->base
.base
,
2941 NULL
, /* prog; Only used for TEXTURE_RECTANGLE on gen < 8 */
2942 shader
, 8, shader_time_index
);
2945 *error_str
= ralloc_strdup(mem_ctx
, v
.fail_msg
);
2950 prog_data
->base
.base
.dispatch_grf_start_reg
= v
.payload
.num_regs
;
2952 fs_generator
g(compiler
, log_data
, mem_ctx
,
2953 &prog_data
->base
.base
, v
.promoted_constants
,
2954 v
.runtime_check_aads_emit
, MESA_SHADER_VERTEX
);
2955 if (INTEL_DEBUG
& DEBUG_VS
) {
2956 const char *debug_name
=
2957 ralloc_asprintf(mem_ctx
, "%s vertex shader %s",
2958 shader
->info
.label
? shader
->info
.label
:
2962 g
.enable_debug(debug_name
);
2964 g
.generate_code(v
.cfg
, 8);
2965 assembly
= g
.get_assembly();
2969 prog_data
->base
.dispatch_mode
= DISPATCH_MODE_4X2_DUAL_OBJECT
;
2971 vec4_vs_visitor
v(compiler
, log_data
, key
, prog_data
,
2972 shader
, mem_ctx
, shader_time_index
);
2975 *error_str
= ralloc_strdup(mem_ctx
, v
.fail_msg
);
2980 assembly
= brw_vec4_generate_assembly(compiler
, log_data
, mem_ctx
,
2981 shader
, &prog_data
->base
, v
.cfg
);