i965/vs: Abort on unsupported opcodes rather than failing.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_vec4_emit.cpp
1 /* Copyright © 2011 Intel Corporation
2 *
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:
9 *
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
12 * Software.
13 *
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
20 * IN THE SOFTWARE.
21 */
22
23 #include "brw_vec4.h"
24
25 extern "C" {
26 #include "brw_eu.h"
27 #include "main/macros.h"
28 #include "program/prog_print.h"
29 #include "program/prog_parameter.h"
30 };
31
32 namespace brw {
33
34 struct brw_reg
35 vec4_instruction::get_dst(void)
36 {
37 struct brw_reg brw_reg;
38
39 switch (dst.file) {
40 case GRF:
41 brw_reg = brw_vec8_grf(dst.reg + dst.reg_offset, 0);
42 brw_reg = retype(brw_reg, dst.type);
43 brw_reg.dw1.bits.writemask = dst.writemask;
44 break;
45
46 case MRF:
47 brw_reg = brw_message_reg(dst.reg + dst.reg_offset);
48 brw_reg = retype(brw_reg, dst.type);
49 brw_reg.dw1.bits.writemask = dst.writemask;
50 break;
51
52 case HW_REG:
53 brw_reg = dst.fixed_hw_reg;
54 break;
55
56 case BAD_FILE:
57 brw_reg = brw_null_reg();
58 break;
59
60 default:
61 assert(!"not reached");
62 brw_reg = brw_null_reg();
63 break;
64 }
65 return brw_reg;
66 }
67
68 struct brw_reg
69 vec4_instruction::get_src(int i)
70 {
71 struct brw_reg brw_reg;
72
73 switch (src[i].file) {
74 case GRF:
75 brw_reg = brw_vec8_grf(src[i].reg + src[i].reg_offset, 0);
76 brw_reg = retype(brw_reg, src[i].type);
77 brw_reg.dw1.bits.swizzle = src[i].swizzle;
78 if (src[i].abs)
79 brw_reg = brw_abs(brw_reg);
80 if (src[i].negate)
81 brw_reg = negate(brw_reg);
82 break;
83
84 case IMM:
85 switch (src[i].type) {
86 case BRW_REGISTER_TYPE_F:
87 brw_reg = brw_imm_f(src[i].imm.f);
88 break;
89 case BRW_REGISTER_TYPE_D:
90 brw_reg = brw_imm_d(src[i].imm.i);
91 break;
92 case BRW_REGISTER_TYPE_UD:
93 brw_reg = brw_imm_ud(src[i].imm.u);
94 break;
95 default:
96 assert(!"not reached");
97 brw_reg = brw_null_reg();
98 break;
99 }
100 break;
101
102 case UNIFORM:
103 brw_reg = stride(brw_vec4_grf(1 + (src[i].reg + src[i].reg_offset) / 2,
104 ((src[i].reg + src[i].reg_offset) % 2) * 4),
105 0, 4, 1);
106 brw_reg = retype(brw_reg, src[i].type);
107 brw_reg.dw1.bits.swizzle = src[i].swizzle;
108 if (src[i].abs)
109 brw_reg = brw_abs(brw_reg);
110 if (src[i].negate)
111 brw_reg = negate(brw_reg);
112
113 /* This should have been moved to pull constants. */
114 assert(!src[i].reladdr);
115 break;
116
117 case HW_REG:
118 brw_reg = src[i].fixed_hw_reg;
119 break;
120
121 case BAD_FILE:
122 /* Probably unused. */
123 brw_reg = brw_null_reg();
124 break;
125 case ATTR:
126 default:
127 assert(!"not reached");
128 brw_reg = brw_null_reg();
129 break;
130 }
131
132 return brw_reg;
133 }
134
135 void
136 vec4_visitor::generate_math1_gen4(vec4_instruction *inst,
137 struct brw_reg dst,
138 struct brw_reg src)
139 {
140 brw_math(p,
141 dst,
142 brw_math_function(inst->opcode),
143 inst->base_mrf,
144 src,
145 BRW_MATH_DATA_VECTOR,
146 BRW_MATH_PRECISION_FULL);
147 }
148
149 static void
150 check_gen6_math_src_arg(struct brw_reg src)
151 {
152 /* Source swizzles are ignored. */
153 assert(!src.abs);
154 assert(!src.negate);
155 assert(src.dw1.bits.swizzle == BRW_SWIZZLE_XYZW);
156 }
157
158 void
159 vec4_visitor::generate_math1_gen6(vec4_instruction *inst,
160 struct brw_reg dst,
161 struct brw_reg src)
162 {
163 /* Can't do writemask because math can't be align16. */
164 assert(dst.dw1.bits.writemask == WRITEMASK_XYZW);
165 check_gen6_math_src_arg(src);
166
167 brw_set_access_mode(p, BRW_ALIGN_1);
168 brw_math(p,
169 dst,
170 brw_math_function(inst->opcode),
171 inst->base_mrf,
172 src,
173 BRW_MATH_DATA_SCALAR,
174 BRW_MATH_PRECISION_FULL);
175 brw_set_access_mode(p, BRW_ALIGN_16);
176 }
177
178 void
179 vec4_visitor::generate_math2_gen7(vec4_instruction *inst,
180 struct brw_reg dst,
181 struct brw_reg src0,
182 struct brw_reg src1)
183 {
184 brw_math2(p,
185 dst,
186 brw_math_function(inst->opcode),
187 src0, src1);
188 }
189
190 void
191 vec4_visitor::generate_math2_gen6(vec4_instruction *inst,
192 struct brw_reg dst,
193 struct brw_reg src0,
194 struct brw_reg src1)
195 {
196 /* Can't do writemask because math can't be align16. */
197 assert(dst.dw1.bits.writemask == WRITEMASK_XYZW);
198 /* Source swizzles are ignored. */
199 check_gen6_math_src_arg(src0);
200 check_gen6_math_src_arg(src1);
201
202 brw_set_access_mode(p, BRW_ALIGN_1);
203 brw_math2(p,
204 dst,
205 brw_math_function(inst->opcode),
206 src0, src1);
207 brw_set_access_mode(p, BRW_ALIGN_16);
208 }
209
210 void
211 vec4_visitor::generate_math2_gen4(vec4_instruction *inst,
212 struct brw_reg dst,
213 struct brw_reg src0,
214 struct brw_reg src1)
215 {
216 /* From the Ironlake PRM, Volume 4, Part 1, Section 6.1.13
217 * "Message Payload":
218 *
219 * "Operand0[7]. For the INT DIV functions, this operand is the
220 * denominator."
221 * ...
222 * "Operand1[7]. For the INT DIV functions, this operand is the
223 * numerator."
224 */
225 bool is_int_div = inst->opcode != SHADER_OPCODE_POW;
226 struct brw_reg &op0 = is_int_div ? src1 : src0;
227 struct brw_reg &op1 = is_int_div ? src0 : src1;
228
229 brw_push_insn_state(p);
230 brw_set_saturate(p, false);
231 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
232 brw_MOV(p, retype(brw_message_reg(inst->base_mrf + 1), op1.type), op1);
233 brw_pop_insn_state(p);
234
235 brw_math(p,
236 dst,
237 brw_math_function(inst->opcode),
238 inst->base_mrf,
239 op0,
240 BRW_MATH_DATA_VECTOR,
241 BRW_MATH_PRECISION_FULL);
242 }
243
244 void
245 vec4_visitor::generate_tex(vec4_instruction *inst,
246 struct brw_reg dst,
247 struct brw_reg src)
248 {
249 int msg_type = -1;
250
251 if (intel->gen >= 5) {
252 switch (inst->opcode) {
253 case SHADER_OPCODE_TEX:
254 case SHADER_OPCODE_TXL:
255 if (inst->shadow_compare) {
256 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LOD_COMPARE;
257 } else {
258 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LOD;
259 }
260 break;
261 case SHADER_OPCODE_TXD:
262 /* There is no sample_d_c message; comparisons are done manually. */
263 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_DERIVS;
264 break;
265 case SHADER_OPCODE_TXF:
266 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LD;
267 break;
268 case SHADER_OPCODE_TXS:
269 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_RESINFO;
270 break;
271 default:
272 assert(!"should not get here: invalid VS texture opcode");
273 break;
274 }
275 } else {
276 switch (inst->opcode) {
277 case SHADER_OPCODE_TEX:
278 case SHADER_OPCODE_TXL:
279 if (inst->shadow_compare) {
280 msg_type = BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_LOD_COMPARE;
281 assert(inst->mlen == 3);
282 } else {
283 msg_type = BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_LOD;
284 assert(inst->mlen == 2);
285 }
286 break;
287 case SHADER_OPCODE_TXD:
288 /* There is no sample_d_c message; comparisons are done manually. */
289 msg_type = BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_GRADIENTS;
290 assert(inst->mlen == 4);
291 break;
292 case SHADER_OPCODE_TXF:
293 msg_type = BRW_SAMPLER_MESSAGE_SIMD4X2_LD;
294 assert(inst->mlen == 2);
295 break;
296 case SHADER_OPCODE_TXS:
297 msg_type = BRW_SAMPLER_MESSAGE_SIMD4X2_RESINFO;
298 assert(inst->mlen == 2);
299 break;
300 default:
301 assert(!"should not get here: invalid VS texture opcode");
302 break;
303 }
304 }
305
306 assert(msg_type != -1);
307
308 /* Load the message header if present. If there's a texture offset, we need
309 * to set it up explicitly and load the offset bitfield. Otherwise, we can
310 * use an implied move from g0 to the first message register.
311 */
312 if (inst->texture_offset) {
313 /* Explicitly set up the message header by copying g0 to the MRF. */
314 brw_MOV(p, retype(brw_message_reg(inst->base_mrf), BRW_REGISTER_TYPE_UD),
315 retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD));
316
317 /* Then set the offset bits in DWord 2. */
318 brw_set_access_mode(p, BRW_ALIGN_1);
319 brw_MOV(p,
320 retype(brw_vec1_reg(BRW_MESSAGE_REGISTER_FILE, inst->base_mrf, 2),
321 BRW_REGISTER_TYPE_UD),
322 brw_imm_uw(inst->texture_offset));
323 brw_set_access_mode(p, BRW_ALIGN_16);
324 } else if (inst->header_present) {
325 /* Set up an implied move from g0 to the MRF. */
326 src = brw_vec8_grf(0, 0);
327 }
328
329 uint32_t return_format;
330
331 switch (dst.type) {
332 case BRW_REGISTER_TYPE_D:
333 return_format = BRW_SAMPLER_RETURN_FORMAT_SINT32;
334 break;
335 case BRW_REGISTER_TYPE_UD:
336 return_format = BRW_SAMPLER_RETURN_FORMAT_UINT32;
337 break;
338 default:
339 return_format = BRW_SAMPLER_RETURN_FORMAT_FLOAT32;
340 break;
341 }
342
343 brw_SAMPLE(p,
344 dst,
345 inst->base_mrf,
346 src,
347 SURF_INDEX_VS_TEXTURE(inst->sampler),
348 inst->sampler,
349 WRITEMASK_XYZW,
350 msg_type,
351 1, /* response length */
352 inst->mlen,
353 inst->header_present,
354 BRW_SAMPLER_SIMD_MODE_SIMD4X2,
355 return_format);
356 }
357
358 void
359 vec4_visitor::generate_urb_write(vec4_instruction *inst)
360 {
361 brw_urb_WRITE(p,
362 brw_null_reg(), /* dest */
363 inst->base_mrf, /* starting mrf reg nr */
364 brw_vec8_grf(0, 0), /* src */
365 false, /* allocate */
366 true, /* used */
367 inst->mlen,
368 0, /* response len */
369 inst->eot, /* eot */
370 inst->eot, /* writes complete */
371 inst->offset, /* urb destination offset */
372 BRW_URB_SWIZZLE_INTERLEAVE);
373 }
374
375 void
376 vec4_visitor::generate_oword_dual_block_offsets(struct brw_reg m1,
377 struct brw_reg index)
378 {
379 int second_vertex_offset;
380
381 if (intel->gen >= 6)
382 second_vertex_offset = 1;
383 else
384 second_vertex_offset = 16;
385
386 m1 = retype(m1, BRW_REGISTER_TYPE_D);
387
388 /* Set up M1 (message payload). Only the block offsets in M1.0 and
389 * M1.4 are used, and the rest are ignored.
390 */
391 struct brw_reg m1_0 = suboffset(vec1(m1), 0);
392 struct brw_reg m1_4 = suboffset(vec1(m1), 4);
393 struct brw_reg index_0 = suboffset(vec1(index), 0);
394 struct brw_reg index_4 = suboffset(vec1(index), 4);
395
396 brw_push_insn_state(p);
397 brw_set_mask_control(p, BRW_MASK_DISABLE);
398 brw_set_access_mode(p, BRW_ALIGN_1);
399
400 brw_MOV(p, m1_0, index_0);
401
402 if (index.file == BRW_IMMEDIATE_VALUE) {
403 index_4.dw1.ud += second_vertex_offset;
404 brw_MOV(p, m1_4, index_4);
405 } else {
406 brw_ADD(p, m1_4, index_4, brw_imm_d(second_vertex_offset));
407 }
408
409 brw_pop_insn_state(p);
410 }
411
412 void
413 vec4_visitor::generate_scratch_read(vec4_instruction *inst,
414 struct brw_reg dst,
415 struct brw_reg index)
416 {
417 struct brw_reg header = brw_vec8_grf(0, 0);
418
419 gen6_resolve_implied_move(p, &header, inst->base_mrf);
420
421 generate_oword_dual_block_offsets(brw_message_reg(inst->base_mrf + 1),
422 index);
423
424 uint32_t msg_type;
425
426 if (intel->gen >= 6)
427 msg_type = GEN6_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
428 else if (intel->gen == 5 || intel->is_g4x)
429 msg_type = G45_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
430 else
431 msg_type = BRW_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
432
433 /* Each of the 8 channel enables is considered for whether each
434 * dword is written.
435 */
436 struct brw_instruction *send = brw_next_insn(p, BRW_OPCODE_SEND);
437 brw_set_dest(p, send, dst);
438 brw_set_src0(p, send, header);
439 if (intel->gen < 6)
440 send->header.destreg__conditionalmod = inst->base_mrf;
441 brw_set_dp_read_message(p, send,
442 255, /* binding table index: stateless access */
443 BRW_DATAPORT_OWORD_DUAL_BLOCK_1OWORD,
444 msg_type,
445 BRW_DATAPORT_READ_TARGET_RENDER_CACHE,
446 2, /* mlen */
447 1 /* rlen */);
448 }
449
450 void
451 vec4_visitor::generate_scratch_write(vec4_instruction *inst,
452 struct brw_reg dst,
453 struct brw_reg src,
454 struct brw_reg index)
455 {
456 struct brw_reg header = brw_vec8_grf(0, 0);
457 bool write_commit;
458
459 /* If the instruction is predicated, we'll predicate the send, not
460 * the header setup.
461 */
462 brw_set_predicate_control(p, false);
463
464 gen6_resolve_implied_move(p, &header, inst->base_mrf);
465
466 generate_oword_dual_block_offsets(brw_message_reg(inst->base_mrf + 1),
467 index);
468
469 brw_MOV(p,
470 retype(brw_message_reg(inst->base_mrf + 2), BRW_REGISTER_TYPE_D),
471 retype(src, BRW_REGISTER_TYPE_D));
472
473 uint32_t msg_type;
474
475 if (intel->gen >= 7)
476 msg_type = GEN7_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE;
477 else if (intel->gen == 6)
478 msg_type = GEN6_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE;
479 else
480 msg_type = BRW_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE;
481
482 brw_set_predicate_control(p, inst->predicate);
483
484 /* Pre-gen6, we have to specify write commits to ensure ordering
485 * between reads and writes within a thread. Afterwards, that's
486 * guaranteed and write commits only matter for inter-thread
487 * synchronization.
488 */
489 if (intel->gen >= 6) {
490 write_commit = false;
491 } else {
492 /* The visitor set up our destination register to be g0. This
493 * means that when the next read comes along, we will end up
494 * reading from g0 and causing a block on the write commit. For
495 * write-after-read, we are relying on the value of the previous
496 * read being used (and thus blocking on completion) before our
497 * write is executed. This means we have to be careful in
498 * instruction scheduling to not violate this assumption.
499 */
500 write_commit = true;
501 }
502
503 /* Each of the 8 channel enables is considered for whether each
504 * dword is written.
505 */
506 struct brw_instruction *send = brw_next_insn(p, BRW_OPCODE_SEND);
507 brw_set_dest(p, send, dst);
508 brw_set_src0(p, send, header);
509 if (intel->gen < 6)
510 send->header.destreg__conditionalmod = inst->base_mrf;
511 brw_set_dp_write_message(p, send,
512 255, /* binding table index: stateless access */
513 BRW_DATAPORT_OWORD_DUAL_BLOCK_1OWORD,
514 msg_type,
515 3, /* mlen */
516 true, /* header present */
517 false, /* not a render target write */
518 write_commit, /* rlen */
519 false, /* eot */
520 write_commit);
521 }
522
523 void
524 vec4_visitor::generate_pull_constant_load(vec4_instruction *inst,
525 struct brw_reg dst,
526 struct brw_reg index,
527 struct brw_reg offset)
528 {
529 assert(index.file == BRW_IMMEDIATE_VALUE &&
530 index.type == BRW_REGISTER_TYPE_UD);
531 uint32_t surf_index = index.dw1.ud;
532
533 if (intel->gen == 7) {
534 gen6_resolve_implied_move(p, &offset, inst->base_mrf);
535 brw_instruction *insn = brw_next_insn(p, BRW_OPCODE_SEND);
536 brw_set_dest(p, insn, dst);
537 brw_set_src0(p, insn, offset);
538 brw_set_sampler_message(p, insn,
539 surf_index,
540 0, /* LD message ignores sampler unit */
541 GEN5_SAMPLER_MESSAGE_SAMPLE_LD,
542 1, /* rlen */
543 1, /* mlen */
544 false, /* no header */
545 BRW_SAMPLER_SIMD_MODE_SIMD4X2,
546 0);
547 return;
548 }
549
550 struct brw_reg header = brw_vec8_grf(0, 0);
551
552 gen6_resolve_implied_move(p, &header, inst->base_mrf);
553
554 brw_MOV(p, retype(brw_message_reg(inst->base_mrf + 1), BRW_REGISTER_TYPE_D),
555 offset);
556
557 uint32_t msg_type;
558
559 if (intel->gen >= 6)
560 msg_type = GEN6_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
561 else if (intel->gen == 5 || intel->is_g4x)
562 msg_type = G45_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
563 else
564 msg_type = BRW_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
565
566 /* Each of the 8 channel enables is considered for whether each
567 * dword is written.
568 */
569 struct brw_instruction *send = brw_next_insn(p, BRW_OPCODE_SEND);
570 brw_set_dest(p, send, dst);
571 brw_set_src0(p, send, header);
572 if (intel->gen < 6)
573 send->header.destreg__conditionalmod = inst->base_mrf;
574 brw_set_dp_read_message(p, send,
575 surf_index,
576 BRW_DATAPORT_OWORD_DUAL_BLOCK_1OWORD,
577 msg_type,
578 BRW_DATAPORT_READ_TARGET_DATA_CACHE,
579 2, /* mlen */
580 1 /* rlen */);
581 }
582
583 void
584 vec4_visitor::generate_vs_instruction(vec4_instruction *instruction,
585 struct brw_reg dst,
586 struct brw_reg *src)
587 {
588 vec4_instruction *inst = (vec4_instruction *)instruction;
589
590 switch (inst->opcode) {
591 case SHADER_OPCODE_RCP:
592 case SHADER_OPCODE_RSQ:
593 case SHADER_OPCODE_SQRT:
594 case SHADER_OPCODE_EXP2:
595 case SHADER_OPCODE_LOG2:
596 case SHADER_OPCODE_SIN:
597 case SHADER_OPCODE_COS:
598 if (intel->gen == 6) {
599 generate_math1_gen6(inst, dst, src[0]);
600 } else {
601 /* Also works for Gen7. */
602 generate_math1_gen4(inst, dst, src[0]);
603 }
604 break;
605
606 case SHADER_OPCODE_POW:
607 case SHADER_OPCODE_INT_QUOTIENT:
608 case SHADER_OPCODE_INT_REMAINDER:
609 if (intel->gen >= 7) {
610 generate_math2_gen7(inst, dst, src[0], src[1]);
611 } else if (intel->gen == 6) {
612 generate_math2_gen6(inst, dst, src[0], src[1]);
613 } else {
614 generate_math2_gen4(inst, dst, src[0], src[1]);
615 }
616 break;
617
618 case SHADER_OPCODE_TEX:
619 case SHADER_OPCODE_TXD:
620 case SHADER_OPCODE_TXF:
621 case SHADER_OPCODE_TXL:
622 case SHADER_OPCODE_TXS:
623 generate_tex(inst, dst, src[0]);
624 break;
625
626 case VS_OPCODE_URB_WRITE:
627 generate_urb_write(inst);
628 break;
629
630 case VS_OPCODE_SCRATCH_READ:
631 generate_scratch_read(inst, dst, src[0]);
632 break;
633
634 case VS_OPCODE_SCRATCH_WRITE:
635 generate_scratch_write(inst, dst, src[0], src[1]);
636 break;
637
638 case VS_OPCODE_PULL_CONSTANT_LOAD:
639 generate_pull_constant_load(inst, dst, src[0], src[1]);
640 break;
641
642 default:
643 if (inst->opcode < (int) ARRAY_SIZE(opcode_descs)) {
644 _mesa_problem(ctx, "Unsupported opcode in `%s' in VS\n",
645 opcode_descs[inst->opcode].name);
646 } else {
647 _mesa_problem(ctx, "Unsupported opcode %d in VS", inst->opcode);
648 }
649 abort();
650 }
651 }
652
653 void
654 vec4_visitor::generate_code()
655 {
656 int last_native_insn_offset = 0;
657 const char *last_annotation_string = NULL;
658 const void *last_annotation_ir = NULL;
659
660 if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
661 if (shader) {
662 printf("Native code for vertex shader %d:\n", prog->Name);
663 } else {
664 printf("Native code for vertex program %d:\n", c->vp->program.Base.Id);
665 }
666 }
667
668 foreach_list(node, &this->instructions) {
669 vec4_instruction *inst = (vec4_instruction *)node;
670 struct brw_reg src[3], dst;
671
672 if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
673 if (last_annotation_ir != inst->ir) {
674 last_annotation_ir = inst->ir;
675 if (last_annotation_ir) {
676 printf(" ");
677 if (shader) {
678 ((ir_instruction *) last_annotation_ir)->print();
679 } else {
680 const prog_instruction *vpi;
681 vpi = (const prog_instruction *) inst->ir;
682 printf("%d: ", (int)(vpi - vp->Base.Instructions));
683 _mesa_fprint_instruction_opt(stdout, vpi, 0,
684 PROG_PRINT_DEBUG, NULL);
685 }
686 printf("\n");
687 }
688 }
689 if (last_annotation_string != inst->annotation) {
690 last_annotation_string = inst->annotation;
691 if (last_annotation_string)
692 printf(" %s\n", last_annotation_string);
693 }
694 }
695
696 for (unsigned int i = 0; i < 3; i++) {
697 src[i] = inst->get_src(i);
698 }
699 dst = inst->get_dst();
700
701 brw_set_conditionalmod(p, inst->conditional_mod);
702 brw_set_predicate_control(p, inst->predicate);
703 brw_set_predicate_inverse(p, inst->predicate_inverse);
704 brw_set_saturate(p, inst->saturate);
705
706 switch (inst->opcode) {
707 case BRW_OPCODE_MOV:
708 brw_MOV(p, dst, src[0]);
709 break;
710 case BRW_OPCODE_ADD:
711 brw_ADD(p, dst, src[0], src[1]);
712 break;
713 case BRW_OPCODE_MUL:
714 brw_MUL(p, dst, src[0], src[1]);
715 break;
716 case BRW_OPCODE_MACH:
717 brw_set_acc_write_control(p, 1);
718 brw_MACH(p, dst, src[0], src[1]);
719 brw_set_acc_write_control(p, 0);
720 break;
721
722 case BRW_OPCODE_FRC:
723 brw_FRC(p, dst, src[0]);
724 break;
725 case BRW_OPCODE_RNDD:
726 brw_RNDD(p, dst, src[0]);
727 break;
728 case BRW_OPCODE_RNDE:
729 brw_RNDE(p, dst, src[0]);
730 break;
731 case BRW_OPCODE_RNDZ:
732 brw_RNDZ(p, dst, src[0]);
733 break;
734
735 case BRW_OPCODE_AND:
736 brw_AND(p, dst, src[0], src[1]);
737 break;
738 case BRW_OPCODE_OR:
739 brw_OR(p, dst, src[0], src[1]);
740 break;
741 case BRW_OPCODE_XOR:
742 brw_XOR(p, dst, src[0], src[1]);
743 break;
744 case BRW_OPCODE_NOT:
745 brw_NOT(p, dst, src[0]);
746 break;
747 case BRW_OPCODE_ASR:
748 brw_ASR(p, dst, src[0], src[1]);
749 break;
750 case BRW_OPCODE_SHR:
751 brw_SHR(p, dst, src[0], src[1]);
752 break;
753 case BRW_OPCODE_SHL:
754 brw_SHL(p, dst, src[0], src[1]);
755 break;
756
757 case BRW_OPCODE_CMP:
758 brw_CMP(p, dst, inst->conditional_mod, src[0], src[1]);
759 break;
760 case BRW_OPCODE_SEL:
761 brw_SEL(p, dst, src[0], src[1]);
762 break;
763
764 case BRW_OPCODE_DPH:
765 brw_DPH(p, dst, src[0], src[1]);
766 break;
767
768 case BRW_OPCODE_DP4:
769 brw_DP4(p, dst, src[0], src[1]);
770 break;
771
772 case BRW_OPCODE_DP3:
773 brw_DP3(p, dst, src[0], src[1]);
774 break;
775
776 case BRW_OPCODE_DP2:
777 brw_DP2(p, dst, src[0], src[1]);
778 break;
779
780 case BRW_OPCODE_IF:
781 if (inst->src[0].file != BAD_FILE) {
782 /* The instruction has an embedded compare (only allowed on gen6) */
783 assert(intel->gen == 6);
784 gen6_IF(p, inst->conditional_mod, src[0], src[1]);
785 } else {
786 struct brw_instruction *brw_inst = brw_IF(p, BRW_EXECUTE_8);
787 brw_inst->header.predicate_control = inst->predicate;
788 }
789 break;
790
791 case BRW_OPCODE_ELSE:
792 brw_ELSE(p);
793 break;
794 case BRW_OPCODE_ENDIF:
795 brw_ENDIF(p);
796 break;
797
798 case BRW_OPCODE_DO:
799 brw_DO(p, BRW_EXECUTE_8);
800 break;
801
802 case BRW_OPCODE_BREAK:
803 brw_BREAK(p);
804 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
805 break;
806 case BRW_OPCODE_CONTINUE:
807 /* FINISHME: We need to write the loop instruction support still. */
808 if (intel->gen >= 6)
809 gen6_CONT(p);
810 else
811 brw_CONT(p);
812 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
813 break;
814
815 case BRW_OPCODE_WHILE:
816 brw_WHILE(p);
817 break;
818
819 default:
820 generate_vs_instruction(inst, dst, src);
821 break;
822 }
823
824 if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
825 brw_dump_compile(p, stdout,
826 last_native_insn_offset, p->next_insn_offset);
827 }
828
829 last_native_insn_offset = p->next_insn_offset;
830 }
831
832 if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
833 printf("\n");
834 }
835
836 brw_set_uip_jip(p);
837
838 /* OK, while the INTEL_DEBUG=vs above is very nice for debugging VS
839 * emit issues, it doesn't get the jump distances into the output,
840 * which is often something we want to debug. So this is here in
841 * case you're doing that.
842 */
843 if (0 && unlikely(INTEL_DEBUG & DEBUG_VS)) {
844 brw_dump_compile(p, stdout, 0, p->next_insn_offset);
845 }
846 }
847
848 } /* namespace brw */