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
27 #include "brw_dead_control_flow.h"
30 #include "main/macros.h"
31 #include "main/shaderobj.h"
32 #include "program/prog_print.h"
33 #include "program/prog_parameter.h"
36 #define MAX_INSTRUCTION (1 << 30)
43 * Common helper for constructing swizzles. When only a subset of
44 * channels of a vec4 are used, we don't want to reference the other
45 * channels, as that will tell optimization passes that those other
49 swizzle_for_size(int size
)
51 static const unsigned size_swizzles
[4] = {
52 BRW_SWIZZLE4(SWIZZLE_X
, SWIZZLE_X
, SWIZZLE_X
, SWIZZLE_X
),
53 BRW_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Y
, SWIZZLE_Y
),
54 BRW_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_Z
),
55 BRW_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_W
),
58 assert((size
>= 1) && (size
<= 4));
59 return size_swizzles
[size
- 1];
65 memset(this, 0, sizeof(*this));
67 this->file
= BAD_FILE
;
70 src_reg::src_reg(register_file file
, int reg
, const glsl_type
*type
)
76 if (type
&& (type
->is_scalar() || type
->is_vector() || type
->is_matrix()))
77 this->swizzle
= swizzle_for_size(type
->vector_elements
);
79 this->swizzle
= BRW_SWIZZLE_XYZW
;
82 /** Generic unset register constructor. */
88 src_reg::src_reg(float f
)
93 this->type
= BRW_REGISTER_TYPE_F
;
97 src_reg::src_reg(uint32_t u
)
102 this->type
= BRW_REGISTER_TYPE_UD
;
106 src_reg::src_reg(int32_t i
)
111 this->type
= BRW_REGISTER_TYPE_D
;
115 src_reg::src_reg(struct brw_reg reg
)
120 this->fixed_hw_reg
= reg
;
121 this->type
= reg
.type
;
124 src_reg::src_reg(dst_reg reg
)
128 this->file
= reg
.file
;
130 this->reg_offset
= reg
.reg_offset
;
131 this->type
= reg
.type
;
132 this->reladdr
= reg
.reladdr
;
133 this->fixed_hw_reg
= reg
.fixed_hw_reg
;
139 for (int i
= 0; i
< 4; i
++) {
140 if (!(reg
.writemask
& (1 << i
)))
143 swizzles
[next_chan
++] = last
= i
;
146 for (; next_chan
< 4; next_chan
++) {
147 swizzles
[next_chan
] = last
;
150 this->swizzle
= BRW_SWIZZLE4(swizzles
[0], swizzles
[1],
151 swizzles
[2], swizzles
[3]);
157 memset(this, 0, sizeof(*this));
158 this->file
= BAD_FILE
;
159 this->writemask
= WRITEMASK_XYZW
;
167 dst_reg::dst_reg(register_file file
, int reg
)
175 dst_reg::dst_reg(register_file file
, int reg
, const glsl_type
*type
,
182 this->type
= brw_type_for_base_type(type
);
183 this->writemask
= writemask
;
186 dst_reg::dst_reg(struct brw_reg reg
)
191 this->fixed_hw_reg
= reg
;
192 this->type
= reg
.type
;
195 dst_reg::dst_reg(src_reg reg
)
199 this->file
= reg
.file
;
201 this->reg_offset
= reg
.reg_offset
;
202 this->type
= reg
.type
;
203 /* How should we do writemasking when converting from a src_reg? It seems
204 * pretty obvious that for src.xxxx the caller wants to write to src.x, but
205 * what about for src.wx? Just special-case src.xxxx for now.
207 if (reg
.swizzle
== BRW_SWIZZLE_XXXX
)
208 this->writemask
= WRITEMASK_X
;
210 this->writemask
= WRITEMASK_XYZW
;
211 this->reladdr
= reg
.reladdr
;
212 this->fixed_hw_reg
= reg
.fixed_hw_reg
;
216 vec4_instruction::is_send_from_grf()
219 case SHADER_OPCODE_SHADER_TIME_ADD
:
220 case VS_OPCODE_PULL_CONSTANT_LOAD_GEN7
:
228 vec4_visitor::can_do_source_mods(vec4_instruction
*inst
)
230 if (brw
->gen
== 6 && inst
->is_math())
233 if (inst
->is_send_from_grf())
236 if (!inst
->can_do_source_mods())
243 * Returns how many MRFs an opcode will write over.
245 * Note that this is not the 0 or 1 implied writes in an actual gen
246 * instruction -- the generate_* functions generate additional MOVs
250 vec4_visitor::implied_mrf_writes(vec4_instruction
*inst
)
255 switch (inst
->opcode
) {
256 case SHADER_OPCODE_RCP
:
257 case SHADER_OPCODE_RSQ
:
258 case SHADER_OPCODE_SQRT
:
259 case SHADER_OPCODE_EXP2
:
260 case SHADER_OPCODE_LOG2
:
261 case SHADER_OPCODE_SIN
:
262 case SHADER_OPCODE_COS
:
264 case SHADER_OPCODE_INT_QUOTIENT
:
265 case SHADER_OPCODE_INT_REMAINDER
:
266 case SHADER_OPCODE_POW
:
268 case VS_OPCODE_URB_WRITE
:
270 case VS_OPCODE_PULL_CONSTANT_LOAD
:
272 case SHADER_OPCODE_GEN4_SCRATCH_READ
:
274 case SHADER_OPCODE_GEN4_SCRATCH_WRITE
:
276 case GS_OPCODE_URB_WRITE
:
277 case GS_OPCODE_THREAD_END
:
279 case SHADER_OPCODE_SHADER_TIME_ADD
:
281 case SHADER_OPCODE_TEX
:
282 case SHADER_OPCODE_TXL
:
283 case SHADER_OPCODE_TXD
:
284 case SHADER_OPCODE_TXF
:
285 case SHADER_OPCODE_TXF_CMS
:
286 case SHADER_OPCODE_TXF_MCS
:
287 case SHADER_OPCODE_TXS
:
288 case SHADER_OPCODE_TG4
:
289 case SHADER_OPCODE_TG4_OFFSET
:
290 return inst
->header_present
? 1 : 0;
291 case SHADER_OPCODE_UNTYPED_ATOMIC
:
292 case SHADER_OPCODE_UNTYPED_SURFACE_READ
:
295 assert(!"not reached");
301 src_reg::equals(src_reg
*r
)
303 return (file
== r
->file
&&
305 reg_offset
== r
->reg_offset
&&
307 negate
== r
->negate
&&
309 swizzle
== r
->swizzle
&&
310 !reladdr
&& !r
->reladdr
&&
311 memcmp(&fixed_hw_reg
, &r
->fixed_hw_reg
,
312 sizeof(fixed_hw_reg
)) == 0 &&
317 * Must be called after calculate_live_intervales() to remove unused
318 * writes to registers -- register allocation will fail otherwise
319 * because something deffed but not used won't be considered to
320 * interfere with other regs.
323 vec4_visitor::dead_code_eliminate()
325 bool progress
= false;
328 calculate_live_intervals();
330 foreach_list_safe(node
, &this->instructions
) {
331 vec4_instruction
*inst
= (vec4_instruction
*)node
;
333 if (inst
->dst
.file
== GRF
&& !inst
->has_side_effects()) {
334 assert(this->virtual_grf_end
[inst
->dst
.reg
] >= pc
);
335 if (this->virtual_grf_end
[inst
->dst
.reg
] == pc
) {
336 /* Don't dead code eliminate instructions that write to the
337 * accumulator as a side-effect. Instead just set the destination
338 * to the null register to free it.
340 switch (inst
->opcode
) {
341 case BRW_OPCODE_ADDC
:
342 case BRW_OPCODE_SUBB
:
343 case BRW_OPCODE_MACH
:
344 inst
->dst
= dst_reg(retype(brw_null_reg(), inst
->dst
.type
));
358 invalidate_live_intervals();
364 vec4_visitor::split_uniform_registers()
366 /* Prior to this, uniforms have been in an array sized according to
367 * the number of vector uniforms present, sparsely filled (so an
368 * aggregate results in reg indices being skipped over). Now we're
369 * going to cut those aggregates up so each .reg index is one
370 * vector. The goal is to make elimination of unused uniform
371 * components easier later.
373 foreach_list(node
, &this->instructions
) {
374 vec4_instruction
*inst
= (vec4_instruction
*)node
;
376 for (int i
= 0 ; i
< 3; i
++) {
377 if (inst
->src
[i
].file
!= UNIFORM
)
380 assert(!inst
->src
[i
].reladdr
);
382 inst
->src
[i
].reg
+= inst
->src
[i
].reg_offset
;
383 inst
->src
[i
].reg_offset
= 0;
387 /* Update that everything is now vector-sized. */
388 for (int i
= 0; i
< this->uniforms
; i
++) {
389 this->uniform_size
[i
] = 1;
394 vec4_visitor::pack_uniform_registers()
396 bool uniform_used
[this->uniforms
];
397 int new_loc
[this->uniforms
];
398 int new_chan
[this->uniforms
];
400 memset(uniform_used
, 0, sizeof(uniform_used
));
401 memset(new_loc
, 0, sizeof(new_loc
));
402 memset(new_chan
, 0, sizeof(new_chan
));
404 /* Find which uniform vectors are actually used by the program. We
405 * expect unused vector elements when we've moved array access out
406 * to pull constants, and from some GLSL code generators like wine.
408 foreach_list(node
, &this->instructions
) {
409 vec4_instruction
*inst
= (vec4_instruction
*)node
;
411 for (int i
= 0 ; i
< 3; i
++) {
412 if (inst
->src
[i
].file
!= UNIFORM
)
415 uniform_used
[inst
->src
[i
].reg
] = true;
419 int new_uniform_count
= 0;
421 /* Now, figure out a packing of the live uniform vectors into our
424 for (int src
= 0; src
< uniforms
; src
++) {
425 int size
= this->uniform_vector_size
[src
];
427 if (!uniform_used
[src
]) {
428 this->uniform_vector_size
[src
] = 0;
433 /* Find the lowest place we can slot this uniform in. */
434 for (dst
= 0; dst
< src
; dst
++) {
435 if (this->uniform_vector_size
[dst
] + size
<= 4)
444 new_chan
[src
] = this->uniform_vector_size
[dst
];
446 /* Move the references to the data */
447 for (int j
= 0; j
< size
; j
++) {
448 stage_prog_data
->param
[dst
* 4 + new_chan
[src
] + j
] =
449 stage_prog_data
->param
[src
* 4 + j
];
452 this->uniform_vector_size
[dst
] += size
;
453 this->uniform_vector_size
[src
] = 0;
456 new_uniform_count
= MAX2(new_uniform_count
, dst
+ 1);
459 this->uniforms
= new_uniform_count
;
461 /* Now, update the instructions for our repacked uniforms. */
462 foreach_list(node
, &this->instructions
) {
463 vec4_instruction
*inst
= (vec4_instruction
*)node
;
465 for (int i
= 0 ; i
< 3; i
++) {
466 int src
= inst
->src
[i
].reg
;
468 if (inst
->src
[i
].file
!= UNIFORM
)
471 inst
->src
[i
].reg
= new_loc
[src
];
473 int sx
= BRW_GET_SWZ(inst
->src
[i
].swizzle
, 0) + new_chan
[src
];
474 int sy
= BRW_GET_SWZ(inst
->src
[i
].swizzle
, 1) + new_chan
[src
];
475 int sz
= BRW_GET_SWZ(inst
->src
[i
].swizzle
, 2) + new_chan
[src
];
476 int sw
= BRW_GET_SWZ(inst
->src
[i
].swizzle
, 3) + new_chan
[src
];
477 inst
->src
[i
].swizzle
= BRW_SWIZZLE4(sx
, sy
, sz
, sw
);
483 src_reg::is_zero() const
488 if (type
== BRW_REGISTER_TYPE_F
) {
496 src_reg::is_one() const
501 if (type
== BRW_REGISTER_TYPE_F
) {
509 * Does algebraic optimizations (0 * a = 0, 1 * a = a, a + 0 = a).
511 * While GLSL IR also performs this optimization, we end up with it in
512 * our instruction stream for a couple of reasons. One is that we
513 * sometimes generate silly instructions, for example in array access
514 * where we'll generate "ADD offset, index, base" even if base is 0.
515 * The other is that GLSL IR's constant propagation doesn't track the
516 * components of aggregates, so some VS patterns (initialize matrix to
517 * 0, accumulate in vertex blending factors) end up breaking down to
518 * instructions involving 0.
521 vec4_visitor::opt_algebraic()
523 bool progress
= false;
525 foreach_list(node
, &this->instructions
) {
526 vec4_instruction
*inst
= (vec4_instruction
*)node
;
528 switch (inst
->opcode
) {
530 if (inst
->src
[1].is_zero()) {
531 inst
->opcode
= BRW_OPCODE_MOV
;
532 inst
->src
[1] = src_reg();
538 if (inst
->src
[1].is_zero()) {
539 inst
->opcode
= BRW_OPCODE_MOV
;
540 switch (inst
->src
[0].type
) {
541 case BRW_REGISTER_TYPE_F
:
542 inst
->src
[0] = src_reg(0.0f
);
544 case BRW_REGISTER_TYPE_D
:
545 inst
->src
[0] = src_reg(0);
547 case BRW_REGISTER_TYPE_UD
:
548 inst
->src
[0] = src_reg(0u);
551 assert(!"not reached");
552 inst
->src
[0] = src_reg(0.0f
);
555 inst
->src
[1] = src_reg();
557 } else if (inst
->src
[1].is_one()) {
558 inst
->opcode
= BRW_OPCODE_MOV
;
559 inst
->src
[1] = src_reg();
569 invalidate_live_intervals();
575 * Only a limited number of hardware registers may be used for push
576 * constants, so this turns access to the overflowed constants into
580 vec4_visitor::move_push_constants_to_pull_constants()
582 int pull_constant_loc
[this->uniforms
];
584 /* Only allow 32 registers (256 uniform components) as push constants,
585 * which is the limit on gen6.
587 int max_uniform_components
= 32 * 8;
588 if (this->uniforms
* 4 <= max_uniform_components
)
591 /* Make some sort of choice as to which uniforms get sent to pull
592 * constants. We could potentially do something clever here like
593 * look for the most infrequently used uniform vec4s, but leave
596 for (int i
= 0; i
< this->uniforms
* 4; i
+= 4) {
597 pull_constant_loc
[i
/ 4] = -1;
599 if (i
>= max_uniform_components
) {
600 const float **values
= &stage_prog_data
->param
[i
];
602 /* Try to find an existing copy of this uniform in the pull
603 * constants if it was part of an array access already.
605 for (unsigned int j
= 0; j
< stage_prog_data
->nr_pull_params
; j
+= 4) {
608 for (matches
= 0; matches
< 4; matches
++) {
609 if (stage_prog_data
->pull_param
[j
+ matches
] != values
[matches
])
614 pull_constant_loc
[i
/ 4] = j
/ 4;
619 if (pull_constant_loc
[i
/ 4] == -1) {
620 assert(stage_prog_data
->nr_pull_params
% 4 == 0);
621 pull_constant_loc
[i
/ 4] = stage_prog_data
->nr_pull_params
/ 4;
623 for (int j
= 0; j
< 4; j
++) {
624 stage_prog_data
->pull_param
[stage_prog_data
->nr_pull_params
++] =
631 /* Now actually rewrite usage of the things we've moved to pull
634 foreach_list_safe(node
, &this->instructions
) {
635 vec4_instruction
*inst
= (vec4_instruction
*)node
;
637 for (int i
= 0 ; i
< 3; i
++) {
638 if (inst
->src
[i
].file
!= UNIFORM
||
639 pull_constant_loc
[inst
->src
[i
].reg
] == -1)
642 int uniform
= inst
->src
[i
].reg
;
644 dst_reg temp
= dst_reg(this, glsl_type::vec4_type
);
646 emit_pull_constant_load(inst
, temp
, inst
->src
[i
],
647 pull_constant_loc
[uniform
]);
649 inst
->src
[i
].file
= temp
.file
;
650 inst
->src
[i
].reg
= temp
.reg
;
651 inst
->src
[i
].reg_offset
= temp
.reg_offset
;
652 inst
->src
[i
].reladdr
= NULL
;
656 /* Repack push constants to remove the now-unused ones. */
657 pack_uniform_registers();
661 * Sets the dependency control fields on instructions after register
662 * allocation and before the generator is run.
664 * When you have a sequence of instructions like:
666 * DP4 temp.x vertex uniform[0]
667 * DP4 temp.y vertex uniform[0]
668 * DP4 temp.z vertex uniform[0]
669 * DP4 temp.w vertex uniform[0]
671 * The hardware doesn't know that it can actually run the later instructions
672 * while the previous ones are in flight, producing stalls. However, we have
673 * manual fields we can set in the instructions that let it do so.
676 vec4_visitor::opt_set_dependency_control()
678 vec4_instruction
*last_grf_write
[BRW_MAX_GRF
];
679 uint8_t grf_channels_written
[BRW_MAX_GRF
];
680 vec4_instruction
*last_mrf_write
[BRW_MAX_GRF
];
681 uint8_t mrf_channels_written
[BRW_MAX_GRF
];
683 cfg_t
cfg(&instructions
);
685 assert(prog_data
->total_grf
||
686 !"Must be called after register allocation");
688 for (int i
= 0; i
< cfg
.num_blocks
; i
++) {
689 bblock_t
*bblock
= cfg
.blocks
[i
];
690 vec4_instruction
*inst
;
692 memset(last_grf_write
, 0, sizeof(last_grf_write
));
693 memset(last_mrf_write
, 0, sizeof(last_mrf_write
));
695 for (inst
= (vec4_instruction
*)bblock
->start
;
696 inst
!= (vec4_instruction
*)bblock
->end
->next
;
697 inst
= (vec4_instruction
*)inst
->next
) {
698 /* If we read from a register that we were doing dependency control
699 * on, don't do dependency control across the read.
701 for (int i
= 0; i
< 3; i
++) {
702 int reg
= inst
->src
[i
].reg
+ inst
->src
[i
].reg_offset
;
703 if (inst
->src
[i
].file
== GRF
) {
704 last_grf_write
[reg
] = NULL
;
705 } else if (inst
->src
[i
].file
== HW_REG
) {
706 memset(last_grf_write
, 0, sizeof(last_grf_write
));
709 assert(inst
->src
[i
].file
!= MRF
);
712 /* In the presence of send messages, totally interrupt dependency
713 * control. They're long enough that the chance of dependency
714 * control around them just doesn't matter.
717 memset(last_grf_write
, 0, sizeof(last_grf_write
));
718 memset(last_mrf_write
, 0, sizeof(last_mrf_write
));
722 /* It looks like setting dependency control on a predicated
723 * instruction hangs the GPU.
725 if (inst
->predicate
) {
726 memset(last_grf_write
, 0, sizeof(last_grf_write
));
727 memset(last_mrf_write
, 0, sizeof(last_mrf_write
));
731 /* Now, see if we can do dependency control for this instruction
732 * against a previous one writing to its destination.
734 int reg
= inst
->dst
.reg
+ inst
->dst
.reg_offset
;
735 if (inst
->dst
.file
== GRF
) {
736 if (last_grf_write
[reg
] &&
737 !(inst
->dst
.writemask
& grf_channels_written
[reg
])) {
738 last_grf_write
[reg
]->no_dd_clear
= true;
739 inst
->no_dd_check
= true;
741 grf_channels_written
[reg
] = 0;
744 last_grf_write
[reg
] = inst
;
745 grf_channels_written
[reg
] |= inst
->dst
.writemask
;
746 } else if (inst
->dst
.file
== MRF
) {
747 if (last_mrf_write
[reg
] &&
748 !(inst
->dst
.writemask
& mrf_channels_written
[reg
])) {
749 last_mrf_write
[reg
]->no_dd_clear
= true;
750 inst
->no_dd_check
= true;
752 mrf_channels_written
[reg
] = 0;
755 last_mrf_write
[reg
] = inst
;
756 mrf_channels_written
[reg
] |= inst
->dst
.writemask
;
757 } else if (inst
->dst
.reg
== HW_REG
) {
758 if (inst
->dst
.fixed_hw_reg
.file
== BRW_GENERAL_REGISTER_FILE
)
759 memset(last_grf_write
, 0, sizeof(last_grf_write
));
760 if (inst
->dst
.fixed_hw_reg
.file
== BRW_MESSAGE_REGISTER_FILE
)
761 memset(last_mrf_write
, 0, sizeof(last_mrf_write
));
768 vec4_instruction::can_reswizzle_dst(int dst_writemask
,
772 /* If this instruction sets anything not referenced by swizzle, then we'd
773 * totally break it when we reswizzle.
775 if (dst
.writemask
& ~swizzle_mask
)
784 /* Check if there happens to be no reswizzling required. */
785 for (int c
= 0; c
< 4; c
++) {
786 int bit
= 1 << BRW_GET_SWZ(swizzle
, c
);
787 /* Skip components of the swizzle not used by the dst. */
788 if (!(dst_writemask
& (1 << c
)))
791 /* We don't do the reswizzling yet, so just sanity check that we
802 * For any channels in the swizzle's source that were populated by this
803 * instruction, rewrite the instruction to put the appropriate result directly
806 * e.g. for swizzle=yywx, MUL a.xy b c -> MUL a.yy_x b.yy z.yy_x
809 vec4_instruction::reswizzle_dst(int dst_writemask
, int swizzle
)
811 int new_writemask
= 0;
817 for (int c
= 0; c
< 4; c
++) {
818 int bit
= 1 << BRW_GET_SWZ(swizzle
, c
);
819 /* Skip components of the swizzle not used by the dst. */
820 if (!(dst_writemask
& (1 << c
)))
822 /* If we were populating this component, then populate the
823 * corresponding channel of the new dst.
825 if (dst
.writemask
& bit
)
826 new_writemask
|= (1 << c
);
828 dst
.writemask
= new_writemask
;
831 for (int c
= 0; c
< 4; c
++) {
832 /* Skip components of the swizzle not used by the dst. */
833 if (!(dst_writemask
& (1 << c
)))
836 /* We don't do the reswizzling yet, so just sanity check that we
839 assert((1 << BRW_GET_SWZ(swizzle
, c
)) == (1 << c
));
846 * Tries to reduce extra MOV instructions by taking temporary GRFs that get
847 * just written and then MOVed into another reg and making the original write
848 * of the GRF write directly to the final destination instead.
851 vec4_visitor::opt_register_coalesce()
853 bool progress
= false;
856 calculate_live_intervals();
858 foreach_list_safe(node
, &this->instructions
) {
859 vec4_instruction
*inst
= (vec4_instruction
*)node
;
864 if (inst
->opcode
!= BRW_OPCODE_MOV
||
865 (inst
->dst
.file
!= GRF
&& inst
->dst
.file
!= MRF
) ||
867 inst
->src
[0].file
!= GRF
||
868 inst
->dst
.type
!= inst
->src
[0].type
||
869 inst
->src
[0].abs
|| inst
->src
[0].negate
|| inst
->src
[0].reladdr
)
872 bool to_mrf
= (inst
->dst
.file
== MRF
);
874 /* Can't coalesce this GRF if someone else was going to
877 if (this->virtual_grf_end
[inst
->src
[0].reg
] > ip
)
880 /* We need to check interference with the final destination between this
881 * instruction and the earliest instruction involved in writing the GRF
882 * we're eliminating. To do that, keep track of which of our source
883 * channels we've seen initialized.
885 bool chans_needed
[4] = {false, false, false, false};
886 int chans_remaining
= 0;
887 int swizzle_mask
= 0;
888 for (int i
= 0; i
< 4; i
++) {
889 int chan
= BRW_GET_SWZ(inst
->src
[0].swizzle
, i
);
891 if (!(inst
->dst
.writemask
& (1 << i
)))
894 swizzle_mask
|= (1 << chan
);
896 if (!chans_needed
[chan
]) {
897 chans_needed
[chan
] = true;
902 /* Now walk up the instruction stream trying to see if we can rewrite
903 * everything writing to the temporary to write into the destination
906 vec4_instruction
*scan_inst
;
907 for (scan_inst
= (vec4_instruction
*)inst
->prev
;
908 scan_inst
->prev
!= NULL
;
909 scan_inst
= (vec4_instruction
*)scan_inst
->prev
) {
910 if (scan_inst
->dst
.file
== GRF
&&
911 scan_inst
->dst
.reg
== inst
->src
[0].reg
&&
912 scan_inst
->dst
.reg_offset
== inst
->src
[0].reg_offset
) {
913 /* Found something writing to the reg we want to coalesce away. */
915 /* SEND instructions can't have MRF as a destination. */
920 /* gen6 math instructions must have the destination be
921 * GRF, so no compute-to-MRF for them.
923 if (scan_inst
->is_math()) {
929 /* If we can't handle the swizzle, bail. */
930 if (!scan_inst
->can_reswizzle_dst(inst
->dst
.writemask
,
931 inst
->src
[0].swizzle
,
936 /* Mark which channels we found unconditional writes for. */
937 if (!scan_inst
->predicate
) {
938 for (int i
= 0; i
< 4; i
++) {
939 if (scan_inst
->dst
.writemask
& (1 << i
) &&
941 chans_needed
[i
] = false;
947 if (chans_remaining
== 0)
951 /* We don't handle flow control here. Most computation of values
952 * that could be coalesced happens just before their use.
954 if (scan_inst
->opcode
== BRW_OPCODE_DO
||
955 scan_inst
->opcode
== BRW_OPCODE_WHILE
||
956 scan_inst
->opcode
== BRW_OPCODE_ELSE
||
957 scan_inst
->opcode
== BRW_OPCODE_ENDIF
) {
961 /* You can't read from an MRF, so if someone else reads our MRF's
962 * source GRF that we wanted to rewrite, that stops us. If it's a
963 * GRF we're trying to coalesce to, we don't actually handle
964 * rewriting sources so bail in that case as well.
966 bool interfered
= false;
967 for (int i
= 0; i
< 3; i
++) {
968 if (scan_inst
->src
[i
].file
== GRF
&&
969 scan_inst
->src
[i
].reg
== inst
->src
[0].reg
&&
970 scan_inst
->src
[i
].reg_offset
== inst
->src
[0].reg_offset
) {
977 /* If somebody else writes our destination here, we can't coalesce
980 if (scan_inst
->dst
.file
== inst
->dst
.file
&&
981 scan_inst
->dst
.reg
== inst
->dst
.reg
) {
985 /* Check for reads of the register we're trying to coalesce into. We
986 * can't go rewriting instructions above that to put some other value
987 * in the register instead.
989 if (to_mrf
&& scan_inst
->mlen
> 0) {
990 if (inst
->dst
.reg
>= scan_inst
->base_mrf
&&
991 inst
->dst
.reg
< scan_inst
->base_mrf
+ scan_inst
->mlen
) {
995 for (int i
= 0; i
< 3; i
++) {
996 if (scan_inst
->src
[i
].file
== inst
->dst
.file
&&
997 scan_inst
->src
[i
].reg
== inst
->dst
.reg
&&
998 scan_inst
->src
[i
].reg_offset
== inst
->src
[0].reg_offset
) {
1007 if (chans_remaining
== 0) {
1008 /* If we've made it here, we have an MOV we want to coalesce out, and
1009 * a scan_inst pointing to the earliest instruction involved in
1010 * computing the value. Now go rewrite the instruction stream
1014 while (scan_inst
!= inst
) {
1015 if (scan_inst
->dst
.file
== GRF
&&
1016 scan_inst
->dst
.reg
== inst
->src
[0].reg
&&
1017 scan_inst
->dst
.reg_offset
== inst
->src
[0].reg_offset
) {
1018 scan_inst
->reswizzle_dst(inst
->dst
.writemask
,
1019 inst
->src
[0].swizzle
);
1020 scan_inst
->dst
.file
= inst
->dst
.file
;
1021 scan_inst
->dst
.reg
= inst
->dst
.reg
;
1022 scan_inst
->dst
.reg_offset
= inst
->dst
.reg_offset
;
1023 scan_inst
->saturate
|= inst
->saturate
;
1025 scan_inst
= (vec4_instruction
*)scan_inst
->next
;
1033 invalidate_live_intervals();
1039 * Splits virtual GRFs requesting more than one contiguous physical register.
1041 * We initially create large virtual GRFs for temporary structures, arrays,
1042 * and matrices, so that the dereference visitor functions can add reg_offsets
1043 * to work their way down to the actual member being accessed. But when it
1044 * comes to optimization, we'd like to treat each register as individual
1045 * storage if possible.
1047 * So far, the only thing that might prevent splitting is a send message from
1051 vec4_visitor::split_virtual_grfs()
1053 int num_vars
= this->virtual_grf_count
;
1054 int new_virtual_grf
[num_vars
];
1055 bool split_grf
[num_vars
];
1057 memset(new_virtual_grf
, 0, sizeof(new_virtual_grf
));
1059 /* Try to split anything > 0 sized. */
1060 for (int i
= 0; i
< num_vars
; i
++) {
1061 split_grf
[i
] = this->virtual_grf_sizes
[i
] != 1;
1064 /* Check that the instructions are compatible with the registers we're trying
1067 foreach_list(node
, &this->instructions
) {
1068 vec4_instruction
*inst
= (vec4_instruction
*)node
;
1070 /* If there's a SEND message loading from a GRF on gen7+, it needs to be
1073 if (inst
->is_send_from_grf()) {
1074 for (int i
= 0; i
< 3; i
++) {
1075 if (inst
->src
[i
].file
== GRF
) {
1076 split_grf
[inst
->src
[i
].reg
] = false;
1082 /* Allocate new space for split regs. Note that the virtual
1083 * numbers will be contiguous.
1085 for (int i
= 0; i
< num_vars
; i
++) {
1089 new_virtual_grf
[i
] = virtual_grf_alloc(1);
1090 for (int j
= 2; j
< this->virtual_grf_sizes
[i
]; j
++) {
1091 int reg
= virtual_grf_alloc(1);
1092 assert(reg
== new_virtual_grf
[i
] + j
- 1);
1095 this->virtual_grf_sizes
[i
] = 1;
1098 foreach_list(node
, &this->instructions
) {
1099 vec4_instruction
*inst
= (vec4_instruction
*)node
;
1101 if (inst
->dst
.file
== GRF
&& split_grf
[inst
->dst
.reg
] &&
1102 inst
->dst
.reg_offset
!= 0) {
1103 inst
->dst
.reg
= (new_virtual_grf
[inst
->dst
.reg
] +
1104 inst
->dst
.reg_offset
- 1);
1105 inst
->dst
.reg_offset
= 0;
1107 for (int i
= 0; i
< 3; i
++) {
1108 if (inst
->src
[i
].file
== GRF
&& split_grf
[inst
->src
[i
].reg
] &&
1109 inst
->src
[i
].reg_offset
!= 0) {
1110 inst
->src
[i
].reg
= (new_virtual_grf
[inst
->src
[i
].reg
] +
1111 inst
->src
[i
].reg_offset
- 1);
1112 inst
->src
[i
].reg_offset
= 0;
1116 invalidate_live_intervals();
1120 vec4_visitor::dump_instruction(backend_instruction
*be_inst
)
1122 vec4_instruction
*inst
= (vec4_instruction
*)be_inst
;
1124 printf("%s", brw_instruction_name(inst
->opcode
));
1125 if (inst
->conditional_mod
) {
1126 printf("%s", conditional_modifier
[inst
->conditional_mod
]);
1130 switch (inst
->dst
.file
) {
1132 printf("vgrf%d.%d", inst
->dst
.reg
, inst
->dst
.reg_offset
);
1135 printf("m%d", inst
->dst
.reg
);
1138 if (inst
->dst
.fixed_hw_reg
.file
== BRW_ARCHITECTURE_REGISTER_FILE
) {
1139 switch (inst
->dst
.fixed_hw_reg
.nr
) {
1143 case BRW_ARF_ADDRESS
:
1144 printf("a0.%d", inst
->dst
.fixed_hw_reg
.subnr
);
1146 case BRW_ARF_ACCUMULATOR
:
1147 printf("acc%d", inst
->dst
.fixed_hw_reg
.subnr
);
1150 printf("f%d.%d", inst
->dst
.fixed_hw_reg
.nr
& 0xf,
1151 inst
->dst
.fixed_hw_reg
.subnr
);
1154 printf("arf%d.%d", inst
->dst
.fixed_hw_reg
.nr
& 0xf,
1155 inst
->dst
.fixed_hw_reg
.subnr
);
1159 printf("hw_reg%d", inst
->dst
.fixed_hw_reg
.nr
);
1161 if (inst
->dst
.fixed_hw_reg
.subnr
)
1162 printf("+%d", inst
->dst
.fixed_hw_reg
.subnr
);
1171 if (inst
->dst
.writemask
!= WRITEMASK_XYZW
) {
1173 if (inst
->dst
.writemask
& 1)
1175 if (inst
->dst
.writemask
& 2)
1177 if (inst
->dst
.writemask
& 4)
1179 if (inst
->dst
.writemask
& 8)
1182 printf(":%s, ", brw_reg_type_letters(inst
->dst
.type
));
1184 for (int i
= 0; i
< 3 && inst
->src
[i
].file
!= BAD_FILE
; i
++) {
1185 if (inst
->src
[i
].negate
)
1187 if (inst
->src
[i
].abs
)
1189 switch (inst
->src
[i
].file
) {
1191 printf("vgrf%d", inst
->src
[i
].reg
);
1194 printf("attr%d", inst
->src
[i
].reg
);
1197 printf("u%d", inst
->src
[i
].reg
);
1200 switch (inst
->src
[i
].type
) {
1201 case BRW_REGISTER_TYPE_F
:
1202 printf("%fF", inst
->src
[i
].imm
.f
);
1204 case BRW_REGISTER_TYPE_D
:
1205 printf("%dD", inst
->src
[i
].imm
.i
);
1207 case BRW_REGISTER_TYPE_UD
:
1208 printf("%uU", inst
->src
[i
].imm
.u
);
1216 if (inst
->src
[i
].fixed_hw_reg
.negate
)
1218 if (inst
->src
[i
].fixed_hw_reg
.abs
)
1220 if (inst
->src
[i
].fixed_hw_reg
.file
== BRW_ARCHITECTURE_REGISTER_FILE
) {
1221 switch (inst
->src
[i
].fixed_hw_reg
.nr
) {
1225 case BRW_ARF_ADDRESS
:
1226 printf("a0.%d", inst
->src
[i
].fixed_hw_reg
.subnr
);
1228 case BRW_ARF_ACCUMULATOR
:
1229 printf("acc%d", inst
->src
[i
].fixed_hw_reg
.subnr
);
1232 printf("f%d.%d", inst
->src
[i
].fixed_hw_reg
.nr
& 0xf,
1233 inst
->src
[i
].fixed_hw_reg
.subnr
);
1236 printf("arf%d.%d", inst
->src
[i
].fixed_hw_reg
.nr
& 0xf,
1237 inst
->src
[i
].fixed_hw_reg
.subnr
);
1241 printf("hw_reg%d", inst
->src
[i
].fixed_hw_reg
.nr
);
1243 if (inst
->src
[i
].fixed_hw_reg
.subnr
)
1244 printf("+%d", inst
->src
[i
].fixed_hw_reg
.subnr
);
1245 if (inst
->src
[i
].fixed_hw_reg
.abs
)
1256 if (virtual_grf_sizes
[inst
->src
[i
].reg
] != 1)
1257 printf(".%d", inst
->src
[i
].reg_offset
);
1259 if (inst
->src
[i
].file
!= IMM
) {
1260 static const char *chans
[4] = {"x", "y", "z", "w"};
1262 for (int c
= 0; c
< 4; c
++) {
1263 printf("%s", chans
[BRW_GET_SWZ(inst
->src
[i
].swizzle
, c
)]);
1267 if (inst
->src
[i
].abs
)
1270 if (inst
->src
[i
].file
!= IMM
) {
1271 printf(":%s", reg_encoding
[inst
->src
[i
].type
]);
1274 if (i
< 2 && inst
->src
[i
+ 1].file
!= BAD_FILE
)
1282 static inline struct brw_reg
1283 attribute_to_hw_reg(int attr
, bool interleaved
)
1286 return stride(brw_vec4_grf(attr
/ 2, (attr
% 2) * 4), 0, 4, 1);
1288 return brw_vec8_grf(attr
, 0);
1293 * Replace each register of type ATTR in this->instructions with a reference
1294 * to a fixed HW register.
1296 * If interleaved is true, then each attribute takes up half a register, with
1297 * register N containing attribute 2*N in its first half and attribute 2*N+1
1298 * in its second half (this corresponds to the payload setup used by geometry
1299 * shaders in "single" or "dual instanced" dispatch mode). If interleaved is
1300 * false, then each attribute takes up a whole register, with register N
1301 * containing attribute N (this corresponds to the payload setup used by
1302 * vertex shaders, and by geometry shaders in "dual object" dispatch mode).
1305 vec4_visitor::lower_attributes_to_hw_regs(const int *attribute_map
,
1308 foreach_list(node
, &this->instructions
) {
1309 vec4_instruction
*inst
= (vec4_instruction
*)node
;
1311 /* We have to support ATTR as a destination for GL_FIXED fixup. */
1312 if (inst
->dst
.file
== ATTR
) {
1313 int grf
= attribute_map
[inst
->dst
.reg
+ inst
->dst
.reg_offset
];
1315 /* All attributes used in the shader need to have been assigned a
1316 * hardware register by the caller
1320 struct brw_reg reg
= attribute_to_hw_reg(grf
, interleaved
);
1321 reg
.type
= inst
->dst
.type
;
1322 reg
.dw1
.bits
.writemask
= inst
->dst
.writemask
;
1324 inst
->dst
.file
= HW_REG
;
1325 inst
->dst
.fixed_hw_reg
= reg
;
1328 for (int i
= 0; i
< 3; i
++) {
1329 if (inst
->src
[i
].file
!= ATTR
)
1332 int grf
= attribute_map
[inst
->src
[i
].reg
+ inst
->src
[i
].reg_offset
];
1334 /* All attributes used in the shader need to have been assigned a
1335 * hardware register by the caller
1339 struct brw_reg reg
= attribute_to_hw_reg(grf
, interleaved
);
1340 reg
.dw1
.bits
.swizzle
= inst
->src
[i
].swizzle
;
1341 reg
.type
= inst
->src
[i
].type
;
1342 if (inst
->src
[i
].abs
)
1344 if (inst
->src
[i
].negate
)
1347 inst
->src
[i
].file
= HW_REG
;
1348 inst
->src
[i
].fixed_hw_reg
= reg
;
1354 vec4_vs_visitor::setup_attributes(int payload_reg
)
1357 int attribute_map
[VERT_ATTRIB_MAX
+ 1];
1358 memset(attribute_map
, 0, sizeof(attribute_map
));
1361 for (int i
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
1362 if (vs_prog_data
->inputs_read
& BITFIELD64_BIT(i
)) {
1363 attribute_map
[i
] = payload_reg
+ nr_attributes
;
1368 /* VertexID is stored by the VF as the last vertex element, but we
1369 * don't represent it with a flag in inputs_read, so we call it
1372 if (vs_prog_data
->uses_vertexid
) {
1373 attribute_map
[VERT_ATTRIB_MAX
] = payload_reg
+ nr_attributes
;
1377 lower_attributes_to_hw_regs(attribute_map
, false /* interleaved */);
1379 /* The BSpec says we always have to read at least one thing from
1380 * the VF, and it appears that the hardware wedges otherwise.
1382 if (nr_attributes
== 0)
1385 prog_data
->urb_read_length
= (nr_attributes
+ 1) / 2;
1387 unsigned vue_entries
=
1388 MAX2(nr_attributes
, prog_data
->vue_map
.num_slots
);
1391 prog_data
->urb_entry_size
= ALIGN(vue_entries
, 8) / 8;
1393 prog_data
->urb_entry_size
= ALIGN(vue_entries
, 4) / 4;
1395 return payload_reg
+ nr_attributes
;
1399 vec4_visitor::setup_uniforms(int reg
)
1401 prog_data
->dispatch_grf_start_reg
= reg
;
1403 /* The pre-gen6 VS requires that some push constants get loaded no
1404 * matter what, or the GPU would hang.
1406 if (brw
->gen
< 6 && this->uniforms
== 0) {
1407 this->uniform_vector_size
[this->uniforms
] = 1;
1409 stage_prog_data
->param
=
1410 reralloc(NULL
, stage_prog_data
->param
, const float *, 4);
1411 for (unsigned int i
= 0; i
< 4; i
++) {
1412 unsigned int slot
= this->uniforms
* 4 + i
;
1413 static float zero
= 0.0;
1414 stage_prog_data
->param
[slot
] = &zero
;
1420 reg
+= ALIGN(uniforms
, 2) / 2;
1423 stage_prog_data
->nr_params
= this->uniforms
* 4;
1425 prog_data
->curb_read_length
= reg
- prog_data
->dispatch_grf_start_reg
;
1431 vec4_vs_visitor::setup_payload(void)
1435 /* The payload always contains important data in g0, which contains
1436 * the URB handles that are passed on to the URB write at the end
1437 * of the thread. So, we always start push constants at g1.
1441 reg
= setup_uniforms(reg
);
1443 reg
= setup_attributes(reg
);
1445 this->first_non_payload_grf
= reg
;
1449 vec4_visitor::get_timestamp()
1451 assert(brw
->gen
>= 7);
1453 src_reg ts
= src_reg(brw_reg(BRW_ARCHITECTURE_REGISTER_FILE
,
1456 BRW_REGISTER_TYPE_UD
,
1457 BRW_VERTICAL_STRIDE_0
,
1459 BRW_HORIZONTAL_STRIDE_4
,
1463 dst_reg dst
= dst_reg(this, glsl_type::uvec4_type
);
1465 vec4_instruction
*mov
= emit(MOV(dst
, ts
));
1466 /* We want to read the 3 fields we care about (mostly field 0, but also 2)
1467 * even if it's not enabled in the dispatch.
1469 mov
->force_writemask_all
= true;
1471 return src_reg(dst
);
1475 vec4_visitor::emit_shader_time_begin()
1477 current_annotation
= "shader time start";
1478 shader_start_time
= get_timestamp();
1482 vec4_visitor::emit_shader_time_end()
1484 current_annotation
= "shader time end";
1485 src_reg shader_end_time
= get_timestamp();
1488 /* Check that there weren't any timestamp reset events (assuming these
1489 * were the only two timestamp reads that happened).
1491 src_reg reset_end
= shader_end_time
;
1492 reset_end
.swizzle
= BRW_SWIZZLE_ZZZZ
;
1493 vec4_instruction
*test
= emit(AND(dst_null_d(), reset_end
, src_reg(1u)));
1494 test
->conditional_mod
= BRW_CONDITIONAL_Z
;
1496 emit(IF(BRW_PREDICATE_NORMAL
));
1498 /* Take the current timestamp and get the delta. */
1499 shader_start_time
.negate
= true;
1500 dst_reg diff
= dst_reg(this, glsl_type::uint_type
);
1501 emit(ADD(diff
, shader_start_time
, shader_end_time
));
1503 /* If there were no instructions between the two timestamp gets, the diff
1504 * is 2 cycles. Remove that overhead, so I can forget about that when
1505 * trying to determine the time taken for single instructions.
1507 emit(ADD(diff
, src_reg(diff
), src_reg(-2u)));
1509 emit_shader_time_write(st_base
, src_reg(diff
));
1510 emit_shader_time_write(st_written
, src_reg(1u));
1511 emit(BRW_OPCODE_ELSE
);
1512 emit_shader_time_write(st_reset
, src_reg(1u));
1513 emit(BRW_OPCODE_ENDIF
);
1517 vec4_visitor::emit_shader_time_write(enum shader_time_shader_type type
,
1520 int shader_time_index
=
1521 brw_get_shader_time_index(brw
, shader_prog
, prog
, type
);
1524 dst_reg(this, glsl_type::get_array_instance(glsl_type::vec4_type
, 2));
1526 dst_reg offset
= dst
;
1530 offset
.type
= BRW_REGISTER_TYPE_UD
;
1531 emit(MOV(offset
, src_reg(shader_time_index
* SHADER_TIME_STRIDE
)));
1533 time
.type
= BRW_REGISTER_TYPE_UD
;
1534 emit(MOV(time
, src_reg(value
)));
1536 emit(SHADER_OPCODE_SHADER_TIME_ADD
, dst_reg(), src_reg(dst
));
1542 sanity_param_count
= prog
->Parameters
->NumParameters
;
1544 if (INTEL_DEBUG
& DEBUG_SHADER_TIME
)
1545 emit_shader_time_begin();
1547 assign_common_binding_table_offsets(0);
1551 /* Generate VS IR for main(). (the visitor only descends into
1552 * functions called "main").
1555 visit_instructions(shader
->base
.ir
);
1557 emit_program_code();
1561 if (key
->userclip_active
&& !prog
->UsesClipDistanceOut
)
1562 setup_uniform_clipplane_values();
1566 /* Before any optimization, push array accesses out to scratch
1567 * space where we need them to be. This pass may allocate new
1568 * virtual GRFs, so we want to do it early. It also makes sure
1569 * that we have reladdr computations available for CSE, since we'll
1570 * often do repeated subexpressions for those.
1573 move_grf_array_access_to_scratch();
1574 move_uniform_array_access_to_pull_constants();
1576 /* The ARB_vertex_program frontend emits pull constant loads directly
1577 * rather than using reladdr, so we don't need to walk through all the
1578 * instructions looking for things to move. There isn't anything.
1580 * We do still need to split things to vec4 size.
1582 split_uniform_registers();
1584 pack_uniform_registers();
1585 move_push_constants_to_pull_constants();
1586 split_virtual_grfs();
1591 progress
= dead_code_eliminate() || progress
;
1592 progress
= dead_control_flow_eliminate(this) || progress
;
1593 progress
= opt_copy_propagation() || progress
;
1594 progress
= opt_algebraic() || progress
;
1595 progress
= opt_register_coalesce() || progress
;
1605 /* Debug of register spilling: Go spill everything. */
1606 const int grf_count
= virtual_grf_count
;
1607 float spill_costs
[virtual_grf_count
];
1608 bool no_spill
[virtual_grf_count
];
1609 evaluate_spill_costs(spill_costs
, no_spill
);
1610 for (int i
= 0; i
< grf_count
; i
++) {
1617 while (!reg_allocate()) {
1622 opt_schedule_instructions();
1624 opt_set_dependency_control();
1626 /* If any state parameters were appended, then ParameterValues could have
1627 * been realloced, in which case the driver uniform storage set up by
1628 * _mesa_associate_uniform_storage() would point to freed memory. Make
1629 * sure that didn't happen.
1631 assert(sanity_param_count
== prog
->Parameters
->NumParameters
);
1636 } /* namespace brw */
1641 * Compile a vertex shader.
1643 * Returns the final assembly and the program's size.
1646 brw_vs_emit(struct brw_context
*brw
,
1647 struct gl_shader_program
*prog
,
1648 struct brw_vs_compile
*c
,
1649 struct brw_vs_prog_data
*prog_data
,
1651 unsigned *final_assembly_size
)
1653 bool start_busy
= false;
1654 double start_time
= 0;
1656 if (unlikely(brw
->perf_debug
)) {
1657 start_busy
= (brw
->batch
.last_bo
&&
1658 drm_intel_bo_busy(brw
->batch
.last_bo
));
1659 start_time
= get_time();
1662 struct brw_shader
*shader
= NULL
;
1664 shader
= (brw_shader
*) prog
->_LinkedShaders
[MESA_SHADER_VERTEX
];
1666 if (unlikely(INTEL_DEBUG
& DEBUG_VS
))
1667 brw_dump_ir(brw
, "vertex", prog
, &shader
->base
, &c
->vp
->program
.Base
);
1669 vec4_vs_visitor
v(brw
, c
, prog_data
, prog
, shader
, mem_ctx
);
1672 prog
->LinkStatus
= false;
1673 ralloc_strcat(&prog
->InfoLog
, v
.fail_msg
);
1676 _mesa_problem(NULL
, "Failed to compile vertex shader: %s\n",
1682 const unsigned *assembly
= NULL
;
1683 if (brw
->gen
>= 8) {
1684 gen8_vec4_generator
g(brw
, prog
, &c
->vp
->program
.Base
, &prog_data
->base
,
1685 mem_ctx
, INTEL_DEBUG
& DEBUG_VS
);
1686 assembly
= g
.generate_assembly(&v
.instructions
, final_assembly_size
);
1688 vec4_generator
g(brw
, prog
, &c
->vp
->program
.Base
, &prog_data
->base
,
1689 mem_ctx
, INTEL_DEBUG
& DEBUG_VS
);
1690 assembly
= g
.generate_assembly(&v
.instructions
, final_assembly_size
);
1693 if (unlikely(brw
->perf_debug
) && shader
) {
1694 if (shader
->compiled_once
) {
1695 brw_vs_debug_recompile(brw
, prog
, &c
->key
);
1697 if (start_busy
&& !drm_intel_bo_busy(brw
->batch
.last_bo
)) {
1698 perf_debug("VS compile took %.03f ms and stalled the GPU\n",
1699 (get_time() - start_time
) * 1000);
1701 shader
->compiled_once
= true;
1709 brw_vec4_setup_prog_key_for_precompile(struct gl_context
*ctx
,
1710 struct brw_vec4_prog_key
*key
,
1711 GLuint id
, struct gl_program
*prog
)
1713 key
->program_string_id
= id
;
1714 key
->clamp_vertex_color
= ctx
->API
== API_OPENGL_COMPAT
;
1716 unsigned sampler_count
= _mesa_fls(prog
->SamplersUsed
);
1717 for (unsigned i
= 0; i
< sampler_count
; i
++) {
1718 if (prog
->ShadowSamplers
& (1 << i
)) {
1719 /* Assume DEPTH_TEXTURE_MODE is the default: X, X, X, 1 */
1720 key
->tex
.swizzles
[i
] =
1721 MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_X
, SWIZZLE_X
, SWIZZLE_ONE
);
1723 /* Color sampler: assume no swizzling. */
1724 key
->tex
.swizzles
[i
] = SWIZZLE_XYZW
;