1 /* Copyright © 2011 Intel Corporation
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include "glsl/ir_print_visitor.h"
28 #include "main/macros.h"
36 vec4_visitor::setup_attributes(int payload_reg)
39 int attribute_map[VERT_ATTRIB_MAX + 1];
42 for (int i = 0; i < VERT_ATTRIB_MAX; i++) {
43 if (prog_data->inputs_read & BITFIELD64_BIT(i)) {
44 attribute_map[i] = payload_reg + nr_attributes;
49 /* VertexID is stored by the VF as the last vertex element, but we
50 * don't represent it with a flag in inputs_read, so we call it
53 if (prog_data->uses_vertexid) {
54 attribute_map[VERT_ATTRIB_MAX] = payload_reg + nr_attributes;
58 foreach_list(node, &this->instructions) {
59 vec4_instruction *inst = (vec4_instruction *)node;
61 /* We have to support ATTR as a destination for GL_FIXED fixup. */
62 if (inst->dst.file == ATTR) {
63 int grf = attribute_map[inst->dst.reg + inst->dst.reg_offset];
65 struct brw_reg reg = brw_vec8_grf(grf, 0);
66 reg.dw1.bits.writemask = inst->dst.writemask;
68 inst->dst.file = HW_REG;
69 inst->dst.fixed_hw_reg = reg;
72 for (int i = 0; i < 3; i++) {
73 if (inst->src[i].file != ATTR)
76 int grf = attribute_map[inst->src[i].reg + inst->src[i].reg_offset];
78 struct brw_reg reg = brw_vec8_grf(grf, 0);
79 reg.dw1.bits.swizzle = inst->src[i].swizzle;
80 reg.type = inst->src[i].type;
83 if (inst->src[i].negate)
86 inst->src[i].file = HW_REG;
87 inst->src[i].fixed_hw_reg = reg;
91 /* The BSpec says we always have to read at least one thing from
92 * the VF, and it appears that the hardware wedges otherwise.
94 if (nr_attributes == 0)
97 prog_data->urb_read_length = (nr_attributes + 1) / 2;
99 unsigned vue_entries = MAX2(nr_attributes, c->prog_data.vue_map.num_slots);
102 c->prog_data.urb_entry_size = ALIGN(vue_entries, 8) / 8;
104 c->prog_data.urb_entry_size = ALIGN(vue_entries, 4) / 4;
106 return payload_reg + nr_attributes;
110 vec4_visitor::setup_uniforms(int reg)
112 /* The pre-gen6 VS requires that some push constants get loaded no
113 * matter what, or the GPU would hang.
115 if (intel->gen < 6 && this->uniforms == 0) {
116 this->uniform_vector_size[this->uniforms] = 1;
118 for (unsigned int i = 0; i < 4; i++) {
119 unsigned int slot = this->uniforms * 4 + i;
120 static float zero = 0.0;
121 c->prog_data.param[slot] = &zero;
127 reg += ALIGN(uniforms, 2) / 2;
130 c->prog_data.nr_params = this->uniforms * 4;
132 c->prog_data.curb_read_length = reg - 1;
133 c->prog_data.uses_new_param_layout = true;
139 vec4_visitor::setup_payload(void)
143 /* The payload always contains important data in g0, which contains
144 * the URB handles that are passed on to the URB write at the end
145 * of the thread. So, we always start push constants at g1.
149 reg = setup_uniforms(reg);
151 reg = setup_attributes(reg);
153 this->first_non_payload_grf = reg;
157 vec4_instruction::get_dst(void)
159 struct brw_reg brw_reg;
163 brw_reg = brw_vec8_grf(dst.reg + dst.reg_offset, 0);
164 brw_reg = retype(brw_reg, dst.type);
165 brw_reg.dw1.bits.writemask = dst.writemask;
169 brw_reg = brw_message_reg(dst.reg + dst.reg_offset);
170 brw_reg = retype(brw_reg, dst.type);
171 brw_reg.dw1.bits.writemask = dst.writemask;
175 brw_reg = dst.fixed_hw_reg;
179 brw_reg = brw_null_reg();
183 assert(!"not reached");
184 brw_reg = brw_null_reg();
191 vec4_instruction::get_src(int i)
193 struct brw_reg brw_reg;
195 switch (src[i].file) {
197 brw_reg = brw_vec8_grf(src[i].reg + src[i].reg_offset, 0);
198 brw_reg = retype(brw_reg, src[i].type);
199 brw_reg.dw1.bits.swizzle = src[i].swizzle;
201 brw_reg = brw_abs(brw_reg);
203 brw_reg = negate(brw_reg);
207 switch (src[i].type) {
208 case BRW_REGISTER_TYPE_F:
209 brw_reg = brw_imm_f(src[i].imm.f);
211 case BRW_REGISTER_TYPE_D:
212 brw_reg = brw_imm_d(src[i].imm.i);
214 case BRW_REGISTER_TYPE_UD:
215 brw_reg = brw_imm_ud(src[i].imm.u);
218 assert(!"not reached");
219 brw_reg = brw_null_reg();
225 brw_reg = stride(brw_vec4_grf(1 + (src[i].reg + src[i].reg_offset) / 2,
226 ((src[i].reg + src[i].reg_offset) % 2) * 4),
228 brw_reg = retype(brw_reg, src[i].type);
229 brw_reg.dw1.bits.swizzle = src[i].swizzle;
231 brw_reg = brw_abs(brw_reg);
233 brw_reg = negate(brw_reg);
235 /* This should have been moved to pull constants. */
236 assert(!src[i].reladdr);
240 brw_reg = src[i].fixed_hw_reg;
244 /* Probably unused. */
245 brw_reg = brw_null_reg();
249 assert(!"not reached");
250 brw_reg = brw_null_reg();
258 vec4_visitor::generate_math1_gen4(vec4_instruction *inst,
264 brw_math_function(inst->opcode),
267 BRW_MATH_DATA_VECTOR,
268 BRW_MATH_PRECISION_FULL);
272 check_gen6_math_src_arg(struct brw_reg src)
274 /* Source swizzles are ignored. */
277 assert(src.dw1.bits.swizzle == BRW_SWIZZLE_XYZW);
281 vec4_visitor::generate_math1_gen6(vec4_instruction *inst,
285 /* Can't do writemask because math can't be align16. */
286 assert(dst.dw1.bits.writemask == WRITEMASK_XYZW);
287 check_gen6_math_src_arg(src);
289 brw_set_access_mode(p, BRW_ALIGN_1);
292 brw_math_function(inst->opcode),
295 BRW_MATH_DATA_SCALAR,
296 BRW_MATH_PRECISION_FULL);
297 brw_set_access_mode(p, BRW_ALIGN_16);
301 vec4_visitor::generate_math2_gen7(vec4_instruction *inst,
308 brw_math_function(inst->opcode),
313 vec4_visitor::generate_math2_gen6(vec4_instruction *inst,
318 /* Can't do writemask because math can't be align16. */
319 assert(dst.dw1.bits.writemask == WRITEMASK_XYZW);
320 /* Source swizzles are ignored. */
321 check_gen6_math_src_arg(src0);
322 check_gen6_math_src_arg(src1);
324 brw_set_access_mode(p, BRW_ALIGN_1);
327 brw_math_function(inst->opcode),
329 brw_set_access_mode(p, BRW_ALIGN_16);
333 vec4_visitor::generate_math2_gen4(vec4_instruction *inst,
338 /* From the Ironlake PRM, Volume 4, Part 1, Section 6.1.13
341 * "Operand0[7]. For the INT DIV functions, this operand is the
344 * "Operand1[7]. For the INT DIV functions, this operand is the
347 bool is_int_div = inst->opcode != SHADER_OPCODE_POW;
348 struct brw_reg &op0 = is_int_div ? src1 : src0;
349 struct brw_reg &op1 = is_int_div ? src0 : src1;
351 brw_push_insn_state(p);
352 brw_set_saturate(p, false);
353 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
354 brw_MOV(p, retype(brw_message_reg(inst->base_mrf + 1), op1.type), op1);
355 brw_pop_insn_state(p);
359 brw_math_function(inst->opcode),
362 BRW_MATH_DATA_VECTOR,
363 BRW_MATH_PRECISION_FULL);
367 vec4_visitor::generate_tex(vec4_instruction *inst,
373 if (intel->gen >= 5) {
374 switch (inst->opcode) {
375 case SHADER_OPCODE_TEX:
376 case SHADER_OPCODE_TXL:
377 if (inst->shadow_compare) {
378 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LOD_COMPARE;
380 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LOD;
383 case SHADER_OPCODE_TXD:
384 if (inst->shadow_compare) {
385 /* Gen7.5+. Otherwise, lowered by brw_lower_texture_gradients(). */
386 assert(intel->is_haswell);
387 msg_type = HSW_SAMPLER_MESSAGE_SAMPLE_DERIV_COMPARE;
389 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_DERIVS;
392 case SHADER_OPCODE_TXF:
393 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LD;
395 case SHADER_OPCODE_TXS:
396 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_RESINFO;
399 assert(!"should not get here: invalid VS texture opcode");
403 switch (inst->opcode) {
404 case SHADER_OPCODE_TEX:
405 case SHADER_OPCODE_TXL:
406 if (inst->shadow_compare) {
407 msg_type = BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_LOD_COMPARE;
408 assert(inst->mlen == 3);
410 msg_type = BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_LOD;
411 assert(inst->mlen == 2);
414 case SHADER_OPCODE_TXD:
415 /* There is no sample_d_c message; comparisons are done manually. */
416 msg_type = BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_GRADIENTS;
417 assert(inst->mlen == 4);
419 case SHADER_OPCODE_TXF:
420 msg_type = BRW_SAMPLER_MESSAGE_SIMD4X2_LD;
421 assert(inst->mlen == 2);
423 case SHADER_OPCODE_TXS:
424 msg_type = BRW_SAMPLER_MESSAGE_SIMD4X2_RESINFO;
425 assert(inst->mlen == 2);
428 assert(!"should not get here: invalid VS texture opcode");
433 assert(msg_type != -1);
435 /* Load the message header if present. If there's a texture offset, we need
436 * to set it up explicitly and load the offset bitfield. Otherwise, we can
437 * use an implied move from g0 to the first message register.
439 if (inst->texture_offset) {
440 /* Explicitly set up the message header by copying g0 to the MRF. */
441 brw_MOV(p, retype(brw_message_reg(inst->base_mrf), BRW_REGISTER_TYPE_UD),
442 retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD));
444 /* Then set the offset bits in DWord 2. */
445 brw_set_access_mode(p, BRW_ALIGN_1);
447 retype(brw_vec1_reg(BRW_MESSAGE_REGISTER_FILE, inst->base_mrf, 2),
448 BRW_REGISTER_TYPE_UD),
449 brw_imm_uw(inst->texture_offset));
450 brw_set_access_mode(p, BRW_ALIGN_16);
451 } else if (inst->header_present) {
452 /* Set up an implied move from g0 to the MRF. */
453 src = brw_vec8_grf(0, 0);
456 uint32_t return_format;
459 case BRW_REGISTER_TYPE_D:
460 return_format = BRW_SAMPLER_RETURN_FORMAT_SINT32;
462 case BRW_REGISTER_TYPE_UD:
463 return_format = BRW_SAMPLER_RETURN_FORMAT_UINT32;
466 return_format = BRW_SAMPLER_RETURN_FORMAT_FLOAT32;
474 SURF_INDEX_VS_TEXTURE(inst->sampler),
478 1, /* response length */
480 inst->header_present,
481 BRW_SAMPLER_SIMD_MODE_SIMD4X2,
486 vec4_visitor::generate_urb_write(vec4_instruction *inst)
489 brw_null_reg(), /* dest */
490 inst->base_mrf, /* starting mrf reg nr */
491 brw_vec8_grf(0, 0), /* src */
492 false, /* allocate */
495 0, /* response len */
497 inst->eot, /* writes complete */
498 inst->offset, /* urb destination offset */
499 BRW_URB_SWIZZLE_INTERLEAVE);
503 vec4_visitor::generate_oword_dual_block_offsets(struct brw_reg m1,
504 struct brw_reg index)
506 int second_vertex_offset;
509 second_vertex_offset = 1;
511 second_vertex_offset = 16;
513 m1 = retype(m1, BRW_REGISTER_TYPE_D);
515 /* Set up M1 (message payload). Only the block offsets in M1.0 and
516 * M1.4 are used, and the rest are ignored.
518 struct brw_reg m1_0 = suboffset(vec1(m1), 0);
519 struct brw_reg m1_4 = suboffset(vec1(m1), 4);
520 struct brw_reg index_0 = suboffset(vec1(index), 0);
521 struct brw_reg index_4 = suboffset(vec1(index), 4);
523 brw_push_insn_state(p);
524 brw_set_mask_control(p, BRW_MASK_DISABLE);
525 brw_set_access_mode(p, BRW_ALIGN_1);
527 brw_MOV(p, m1_0, index_0);
529 brw_set_predicate_inverse(p, true);
530 if (index.file == BRW_IMMEDIATE_VALUE) {
531 index_4.dw1.ud += second_vertex_offset;
532 brw_MOV(p, m1_4, index_4);
534 brw_ADD(p, m1_4, index_4, brw_imm_d(second_vertex_offset));
537 brw_pop_insn_state(p);
541 vec4_visitor::generate_scratch_read(vec4_instruction *inst,
543 struct brw_reg index)
545 struct brw_reg header = brw_vec8_grf(0, 0);
547 gen6_resolve_implied_move(p, &header, inst->base_mrf);
549 generate_oword_dual_block_offsets(brw_message_reg(inst->base_mrf + 1),
555 msg_type = GEN6_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
556 else if (intel->gen == 5 || intel->is_g4x)
557 msg_type = G45_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
559 msg_type = BRW_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
561 /* Each of the 8 channel enables is considered for whether each
564 struct brw_instruction *send = brw_next_insn(p, BRW_OPCODE_SEND);
565 brw_set_dest(p, send, dst);
566 brw_set_src0(p, send, header);
568 send->header.destreg__conditionalmod = inst->base_mrf;
569 brw_set_dp_read_message(p, send,
570 255, /* binding table index: stateless access */
571 BRW_DATAPORT_OWORD_DUAL_BLOCK_1OWORD,
573 BRW_DATAPORT_READ_TARGET_RENDER_CACHE,
579 vec4_visitor::generate_scratch_write(vec4_instruction *inst,
582 struct brw_reg index)
584 struct brw_reg header = brw_vec8_grf(0, 0);
587 /* If the instruction is predicated, we'll predicate the send, not
590 brw_set_predicate_control(p, false);
592 gen6_resolve_implied_move(p, &header, inst->base_mrf);
594 generate_oword_dual_block_offsets(brw_message_reg(inst->base_mrf + 1),
598 retype(brw_message_reg(inst->base_mrf + 2), BRW_REGISTER_TYPE_D),
599 retype(src, BRW_REGISTER_TYPE_D));
604 msg_type = GEN7_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE;
605 else if (intel->gen == 6)
606 msg_type = GEN6_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE;
608 msg_type = BRW_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE;
610 brw_set_predicate_control(p, inst->predicate);
612 /* Pre-gen6, we have to specify write commits to ensure ordering
613 * between reads and writes within a thread. Afterwards, that's
614 * guaranteed and write commits only matter for inter-thread
617 if (intel->gen >= 6) {
618 write_commit = false;
620 /* The visitor set up our destination register to be g0. This
621 * means that when the next read comes along, we will end up
622 * reading from g0 and causing a block on the write commit. For
623 * write-after-read, we are relying on the value of the previous
624 * read being used (and thus blocking on completion) before our
625 * write is executed. This means we have to be careful in
626 * instruction scheduling to not violate this assumption.
631 /* Each of the 8 channel enables is considered for whether each
634 struct brw_instruction *send = brw_next_insn(p, BRW_OPCODE_SEND);
635 brw_set_dest(p, send, dst);
636 brw_set_src0(p, send, header);
638 send->header.destreg__conditionalmod = inst->base_mrf;
639 brw_set_dp_write_message(p, send,
640 255, /* binding table index: stateless access */
641 BRW_DATAPORT_OWORD_DUAL_BLOCK_1OWORD,
644 true, /* header present */
645 false, /* not a render target write */
646 write_commit, /* rlen */
652 vec4_visitor::generate_pull_constant_load(vec4_instruction *inst,
654 struct brw_reg index,
655 struct brw_reg offset)
657 assert(index.file == BRW_IMMEDIATE_VALUE &&
658 index.type == BRW_REGISTER_TYPE_UD);
659 uint32_t surf_index = index.dw1.ud;
661 if (intel->gen == 7) {
662 gen6_resolve_implied_move(p, &offset, inst->base_mrf);
663 brw_instruction *insn = brw_next_insn(p, BRW_OPCODE_SEND);
664 brw_set_dest(p, insn, dst);
665 brw_set_src0(p, insn, offset);
666 brw_set_sampler_message(p, insn,
668 0, /* LD message ignores sampler unit */
669 GEN5_SAMPLER_MESSAGE_SAMPLE_LD,
672 false, /* no header */
673 BRW_SAMPLER_SIMD_MODE_SIMD4X2,
678 struct brw_reg header = brw_vec8_grf(0, 0);
680 gen6_resolve_implied_move(p, &header, inst->base_mrf);
682 brw_MOV(p, retype(brw_message_reg(inst->base_mrf + 1), BRW_REGISTER_TYPE_D),
688 msg_type = GEN6_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
689 else if (intel->gen == 5 || intel->is_g4x)
690 msg_type = G45_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
692 msg_type = BRW_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
694 /* Each of the 8 channel enables is considered for whether each
697 struct brw_instruction *send = brw_next_insn(p, BRW_OPCODE_SEND);
698 brw_set_dest(p, send, dst);
699 brw_set_src0(p, send, header);
701 send->header.destreg__conditionalmod = inst->base_mrf;
702 brw_set_dp_read_message(p, send,
704 BRW_DATAPORT_OWORD_DUAL_BLOCK_1OWORD,
706 BRW_DATAPORT_READ_TARGET_DATA_CACHE,
712 vec4_visitor::generate_vs_instruction(vec4_instruction *instruction,
716 vec4_instruction *inst = (vec4_instruction *)instruction;
718 switch (inst->opcode) {
719 case SHADER_OPCODE_RCP:
720 case SHADER_OPCODE_RSQ:
721 case SHADER_OPCODE_SQRT:
722 case SHADER_OPCODE_EXP2:
723 case SHADER_OPCODE_LOG2:
724 case SHADER_OPCODE_SIN:
725 case SHADER_OPCODE_COS:
726 if (intel->gen == 6) {
727 generate_math1_gen6(inst, dst, src[0]);
729 /* Also works for Gen7. */
730 generate_math1_gen4(inst, dst, src[0]);
734 case SHADER_OPCODE_POW:
735 case SHADER_OPCODE_INT_QUOTIENT:
736 case SHADER_OPCODE_INT_REMAINDER:
737 if (intel->gen >= 7) {
738 generate_math2_gen7(inst, dst, src[0], src[1]);
739 } else if (intel->gen == 6) {
740 generate_math2_gen6(inst, dst, src[0], src[1]);
742 generate_math2_gen4(inst, dst, src[0], src[1]);
746 case SHADER_OPCODE_TEX:
747 case SHADER_OPCODE_TXD:
748 case SHADER_OPCODE_TXF:
749 case SHADER_OPCODE_TXL:
750 case SHADER_OPCODE_TXS:
751 generate_tex(inst, dst, src[0]);
754 case VS_OPCODE_URB_WRITE:
755 generate_urb_write(inst);
758 case VS_OPCODE_SCRATCH_READ:
759 generate_scratch_read(inst, dst, src[0]);
762 case VS_OPCODE_SCRATCH_WRITE:
763 generate_scratch_write(inst, dst, src[0], src[1]);
766 case VS_OPCODE_PULL_CONSTANT_LOAD:
767 generate_pull_constant_load(inst, dst, src[0], src[1]);
771 if (inst->opcode < (int)ARRAY_SIZE(brw_opcodes)) {
772 fail("unsupported opcode in `%s' in VS\n",
773 brw_opcodes[inst->opcode].name);
775 fail("Unsupported opcode %d in VS", inst->opcode);
783 if (c->key.userclip_active && !c->key.uses_clip_distance)
784 setup_uniform_clipplane_values();
786 /* Generate VS IR for main(). (the visitor only descends into
787 * functions called "main").
789 visit_instructions(shader->ir);
793 /* Before any optimization, push array accesses out to scratch
794 * space where we need them to be. This pass may allocate new
795 * virtual GRFs, so we want to do it early. It also makes sure
796 * that we have reladdr computations available for CSE, since we'll
797 * often do repeated subexpressions for those.
799 move_grf_array_access_to_scratch();
800 move_uniform_array_access_to_pull_constants();
801 pack_uniform_registers();
802 move_push_constants_to_pull_constants();
807 progress = dead_code_eliminate() || progress;
808 progress = opt_copy_propagation() || progress;
809 progress = opt_algebraic() || progress;
810 progress = opt_compute_to_mrf() || progress;
820 /* Debug of register spilling: Go spill everything. */
821 const int grf_count = virtual_grf_count;
822 float spill_costs[virtual_grf_count];
823 bool no_spill[virtual_grf_count];
824 evaluate_spill_costs(spill_costs, no_spill);
825 for (int i = 0; i < grf_count; i++) {
837 brw_set_access_mode(p, BRW_ALIGN_16);
845 vec4_visitor::generate_code()
847 int last_native_inst = 0;
848 const char *last_annotation_string = NULL;
849 ir_instruction *last_annotation_ir = NULL;
851 if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
852 printf("Native code for vertex shader %d:\n", prog->Name);
855 foreach_list(node, &this->instructions) {
856 vec4_instruction *inst = (vec4_instruction *)node;
857 struct brw_reg src[3], dst;
859 if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
860 if (last_annotation_ir != inst->ir) {
861 last_annotation_ir = inst->ir;
862 if (last_annotation_ir) {
864 last_annotation_ir->print();
868 if (last_annotation_string != inst->annotation) {
869 last_annotation_string = inst->annotation;
870 if (last_annotation_string)
871 printf(" %s\n", last_annotation_string);
875 for (unsigned int i = 0; i < 3; i++) {
876 src[i] = inst->get_src(i);
878 dst = inst->get_dst();
880 brw_set_conditionalmod(p, inst->conditional_mod);
881 brw_set_predicate_control(p, inst->predicate);
882 brw_set_predicate_inverse(p, inst->predicate_inverse);
883 brw_set_saturate(p, inst->saturate);
885 switch (inst->opcode) {
887 brw_MOV(p, dst, src[0]);
890 brw_ADD(p, dst, src[0], src[1]);
893 brw_MUL(p, dst, src[0], src[1]);
895 case BRW_OPCODE_MACH:
896 brw_set_acc_write_control(p, 1);
897 brw_MACH(p, dst, src[0], src[1]);
898 brw_set_acc_write_control(p, 0);
902 brw_FRC(p, dst, src[0]);
904 case BRW_OPCODE_RNDD:
905 brw_RNDD(p, dst, src[0]);
907 case BRW_OPCODE_RNDE:
908 brw_RNDE(p, dst, src[0]);
910 case BRW_OPCODE_RNDZ:
911 brw_RNDZ(p, dst, src[0]);
915 brw_AND(p, dst, src[0], src[1]);
918 brw_OR(p, dst, src[0], src[1]);
921 brw_XOR(p, dst, src[0], src[1]);
924 brw_NOT(p, dst, src[0]);
927 brw_ASR(p, dst, src[0], src[1]);
930 brw_SHR(p, dst, src[0], src[1]);
933 brw_SHL(p, dst, src[0], src[1]);
937 brw_CMP(p, dst, inst->conditional_mod, src[0], src[1]);
940 brw_SEL(p, dst, src[0], src[1]);
944 brw_DP4(p, dst, src[0], src[1]);
948 brw_DP3(p, dst, src[0], src[1]);
952 brw_DP2(p, dst, src[0], src[1]);
956 if (inst->src[0].file != BAD_FILE) {
957 /* The instruction has an embedded compare (only allowed on gen6) */
958 assert(intel->gen == 6);
959 gen6_IF(p, inst->conditional_mod, src[0], src[1]);
961 struct brw_instruction *brw_inst = brw_IF(p, BRW_EXECUTE_8);
962 brw_inst->header.predicate_control = inst->predicate;
966 case BRW_OPCODE_ELSE:
969 case BRW_OPCODE_ENDIF:
974 brw_DO(p, BRW_EXECUTE_8);
977 case BRW_OPCODE_BREAK:
979 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
981 case BRW_OPCODE_CONTINUE:
982 /* FINISHME: We need to write the loop instruction support still. */
987 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
990 case BRW_OPCODE_WHILE:
995 generate_vs_instruction(inst, dst, src);
999 if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
1000 for (unsigned int i = last_native_inst; i < p->nr_insn; i++) {
1002 printf("0x%08x 0x%08x 0x%08x 0x%08x ",
1003 ((uint32_t *)&p->store[i])[3],
1004 ((uint32_t *)&p->store[i])[2],
1005 ((uint32_t *)&p->store[i])[1],
1006 ((uint32_t *)&p->store[i])[0]);
1008 brw_disasm(stdout, &p->store[i], intel->gen);
1012 last_native_inst = p->nr_insn;
1015 if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
1021 /* OK, while the INTEL_DEBUG=vs above is very nice for debugging VS
1022 * emit issues, it doesn't get the jump distances into the output,
1023 * which is often something we want to debug. So this is here in
1024 * case you're doing that.
1027 if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
1028 for (unsigned int i = 0; i < p->nr_insn; i++) {
1029 printf("0x%08x 0x%08x 0x%08x 0x%08x ",
1030 ((uint32_t *)&p->store[i])[3],
1031 ((uint32_t *)&p->store[i])[2],
1032 ((uint32_t *)&p->store[i])[1],
1033 ((uint32_t *)&p->store[i])[0]);
1034 brw_disasm(stdout, &p->store[i], intel->gen);
1043 brw_vs_emit(struct gl_shader_program *prog, struct brw_vs_compile *c)
1045 struct brw_context *brw = c->func.brw;
1046 struct intel_context *intel = &c->func.brw->intel;
1047 bool start_busy = false;
1048 float start_time = 0;
1053 if (unlikely(INTEL_DEBUG & DEBUG_PERF)) {
1054 start_busy = (intel->batch.last_bo &&
1055 drm_intel_bo_busy(intel->batch.last_bo));
1056 start_time = get_time();
1059 struct brw_shader *shader =
1060 (brw_shader *) prog->_LinkedShaders[MESA_SHADER_VERTEX];
1064 if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
1065 printf("GLSL IR for native vertex shader %d:\n", prog->Name);
1066 _mesa_print_ir(shader->ir, NULL);
1070 if (unlikely(INTEL_DEBUG & DEBUG_PERF)) {
1071 if (shader->compiled_once) {
1072 brw_vs_debug_recompile(brw, prog, &c->key);
1074 if (start_busy && !drm_intel_bo_busy(intel->batch.last_bo)) {
1075 perf_debug("VS compile took %.03f ms and stalled the GPU\n",
1076 (get_time() - start_time) * 1000);
1080 vec4_visitor v(c, prog, shader);
1082 prog->LinkStatus = false;
1083 ralloc_strcat(&prog->InfoLog, v.fail_msg);
1087 shader->compiled_once = true;
1094 } /* namespace brw */