f55414e12211b56fb6ea3b66fadbf57e6f5effad
[mesa.git] / src / mesa / drivers / dri / i965 / brw_vs_emit.c
1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial
16 portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **********************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32
33 #include "main/macros.h"
34 #include "program/program.h"
35 #include "program/prog_parameter.h"
36 #include "program/prog_print.h"
37 #include "brw_context.h"
38 #include "brw_vs.h"
39
40 /* Return the SrcReg index of the channels that can be immediate float operands
41 * instead of usage of PROGRAM_CONSTANT values through push/pull.
42 */
43 static GLboolean
44 brw_vs_arg_can_be_immediate(enum prog_opcode opcode, int arg)
45 {
46 int opcode_array[] = {
47 [OPCODE_ADD] = 2,
48 [OPCODE_CMP] = 3,
49 [OPCODE_DP3] = 2,
50 [OPCODE_DP4] = 2,
51 [OPCODE_DPH] = 2,
52 [OPCODE_MAX] = 2,
53 [OPCODE_MIN] = 2,
54 [OPCODE_MUL] = 2,
55 [OPCODE_SEQ] = 2,
56 [OPCODE_SGE] = 2,
57 [OPCODE_SGT] = 2,
58 [OPCODE_SLE] = 2,
59 [OPCODE_SLT] = 2,
60 [OPCODE_SNE] = 2,
61 [OPCODE_XPD] = 2,
62 };
63
64 /* These opcodes get broken down in a way that allow two
65 * args to be immediates.
66 */
67 if (opcode == OPCODE_MAD || opcode == OPCODE_LRP) {
68 if (arg == 1 || arg == 2)
69 return GL_TRUE;
70 }
71
72 if (opcode > ARRAY_SIZE(opcode_array))
73 return GL_FALSE;
74
75 return arg == opcode_array[opcode] - 1;
76 }
77
78 static struct brw_reg get_tmp( struct brw_vs_compile *c )
79 {
80 struct brw_reg tmp = brw_vec8_grf(c->last_tmp, 0);
81
82 if (++c->last_tmp > c->prog_data.total_grf)
83 c->prog_data.total_grf = c->last_tmp;
84
85 return tmp;
86 }
87
88 static void release_tmp( struct brw_vs_compile *c, struct brw_reg tmp )
89 {
90 if (tmp.nr == c->last_tmp-1)
91 c->last_tmp--;
92 }
93
94 static void release_tmps( struct brw_vs_compile *c )
95 {
96 c->last_tmp = c->first_tmp;
97 }
98
99
100 /**
101 * Preallocate GRF register before code emit.
102 * Do things as simply as possible. Allocate and populate all regs
103 * ahead of time.
104 */
105 static void brw_vs_alloc_regs( struct brw_vs_compile *c )
106 {
107 struct intel_context *intel = &c->func.brw->intel;
108 GLuint i, reg = 0, mrf;
109 int attributes_in_vue;
110
111 /* Determine whether to use a real constant buffer or use a block
112 * of GRF registers for constants. The later is faster but only
113 * works if everything fits in the GRF.
114 * XXX this heuristic/check may need some fine tuning...
115 */
116 if (c->vp->program.Base.Parameters->NumParameters +
117 c->vp->program.Base.NumTemporaries + 20 > BRW_MAX_GRF)
118 c->vp->use_const_buffer = GL_TRUE;
119 else
120 c->vp->use_const_buffer = GL_FALSE;
121
122 /*printf("use_const_buffer = %d\n", c->vp->use_const_buffer);*/
123
124 /* r0 -- reserved as usual
125 */
126 c->r0 = brw_vec8_grf(reg, 0);
127 reg++;
128
129 /* User clip planes from curbe:
130 */
131 if (c->key.nr_userclip) {
132 for (i = 0; i < c->key.nr_userclip; i++) {
133 c->userplane[i] = stride( brw_vec4_grf(reg+3+i/2, (i%2) * 4), 0, 4, 1);
134 }
135
136 /* Deal with curbe alignment:
137 */
138 reg += ((6 + c->key.nr_userclip + 3) / 4) * 2;
139 }
140
141 /* Vertex program parameters from curbe:
142 */
143 if (c->vp->use_const_buffer) {
144 int max_constant = BRW_MAX_GRF - 20 - c->vp->program.Base.NumTemporaries;
145 int constant = 0;
146
147 /* We've got more constants than we can load with the push
148 * mechanism. This is often correlated with reladdr loads where
149 * we should probably be using a pull mechanism anyway to avoid
150 * excessive reading. However, the pull mechanism is slow in
151 * general. So, we try to allocate as many non-reladdr-loaded
152 * constants through the push buffer as we can before giving up.
153 */
154 memset(c->constant_map, -1, c->vp->program.Base.Parameters->NumParameters);
155 for (i = 0;
156 i < c->vp->program.Base.NumInstructions && constant < max_constant;
157 i++) {
158 struct prog_instruction *inst = &c->vp->program.Base.Instructions[i];
159 int arg;
160
161 for (arg = 0; arg < 3 && constant < max_constant; arg++) {
162 if ((inst->SrcReg[arg].File != PROGRAM_STATE_VAR &&
163 inst->SrcReg[arg].File != PROGRAM_CONSTANT &&
164 inst->SrcReg[arg].File != PROGRAM_UNIFORM &&
165 inst->SrcReg[arg].File != PROGRAM_ENV_PARAM &&
166 inst->SrcReg[arg].File != PROGRAM_LOCAL_PARAM) ||
167 inst->SrcReg[arg].RelAddr)
168 continue;
169
170 if (c->constant_map[inst->SrcReg[arg].Index] == -1) {
171 c->constant_map[inst->SrcReg[arg].Index] = constant++;
172 }
173 }
174 }
175
176 for (i = 0; i < constant; i++) {
177 c->regs[PROGRAM_STATE_VAR][i] = stride( brw_vec4_grf(reg+i/2,
178 (i%2) * 4),
179 0, 4, 1);
180 }
181 reg += (constant + 1) / 2;
182 c->prog_data.curb_read_length = reg - 1;
183 /* XXX 0 causes a bug elsewhere... */
184 c->prog_data.nr_params = MAX2(constant * 4, 4);
185 }
186 else {
187 /* use a section of the GRF for constants */
188 GLuint nr_params = c->vp->program.Base.Parameters->NumParameters;
189 for (i = 0; i < nr_params; i++) {
190 c->regs[PROGRAM_STATE_VAR][i] = stride( brw_vec4_grf(reg+i/2, (i%2) * 4), 0, 4, 1);
191 }
192 reg += (nr_params + 1) / 2;
193 c->prog_data.curb_read_length = reg - 1;
194
195 c->prog_data.nr_params = nr_params * 4;
196 }
197
198 /* Allocate input regs:
199 */
200 c->nr_inputs = 0;
201 for (i = 0; i < VERT_ATTRIB_MAX; i++) {
202 if (c->prog_data.inputs_read & (1 << i)) {
203 c->nr_inputs++;
204 c->regs[PROGRAM_INPUT][i] = brw_vec8_grf(reg, 0);
205 reg++;
206 }
207 }
208 /* If there are no inputs, we'll still be reading one attribute's worth
209 * because it's required -- see urb_read_length setting.
210 */
211 if (c->nr_inputs == 0)
212 reg++;
213
214 /* Allocate outputs. The non-position outputs go straight into message regs.
215 */
216 c->nr_outputs = 0;
217 c->first_output = reg;
218 c->first_overflow_output = 0;
219
220 if (intel->gen >= 6)
221 mrf = 4;
222 else if (intel->gen == 5)
223 mrf = 8;
224 else
225 mrf = 4;
226
227 for (i = 0; i < VERT_RESULT_MAX; i++) {
228 if (c->prog_data.outputs_written & BITFIELD64_BIT(i)) {
229 c->nr_outputs++;
230 assert(i < Elements(c->regs[PROGRAM_OUTPUT]));
231 if (i == VERT_RESULT_HPOS) {
232 c->regs[PROGRAM_OUTPUT][i] = brw_vec8_grf(reg, 0);
233 reg++;
234 }
235 else if (i == VERT_RESULT_PSIZ) {
236 c->regs[PROGRAM_OUTPUT][i] = brw_vec8_grf(reg, 0);
237 reg++;
238 mrf++; /* just a placeholder? XXX fix later stages & remove this */
239 }
240 else {
241 /* Two restrictions on our compute-to-MRF here. The
242 * message length for all SEND messages is restricted to
243 * [1,15], so we can't use mrf 15, as that means a length
244 * of 16.
245 *
246 * Additionally, URB writes are aligned to URB rows, so we
247 * need to put an even number of registers of URB data in
248 * each URB write so that the later write is aligned. A
249 * message length of 15 means 1 message header reg plus 14
250 * regs of URB data.
251 *
252 * For attributes beyond the compute-to-MRF, we compute to
253 * GRFs and they will be written in the second URB_WRITE.
254 */
255 if (mrf < 15) {
256 c->regs[PROGRAM_OUTPUT][i] = brw_message_reg(mrf);
257 mrf++;
258 }
259 else {
260 if (!c->first_overflow_output)
261 c->first_overflow_output = i;
262 c->regs[PROGRAM_OUTPUT][i] = brw_vec8_grf(reg, 0);
263 reg++;
264 }
265 }
266 }
267 }
268
269 /* Allocate program temporaries:
270 */
271 for (i = 0; i < c->vp->program.Base.NumTemporaries; i++) {
272 c->regs[PROGRAM_TEMPORARY][i] = brw_vec8_grf(reg, 0);
273 reg++;
274 }
275
276 /* Address reg(s). Don't try to use the internal address reg until
277 * deref time.
278 */
279 for (i = 0; i < c->vp->program.Base.NumAddressRegs; i++) {
280 c->regs[PROGRAM_ADDRESS][i] = brw_reg(BRW_GENERAL_REGISTER_FILE,
281 reg,
282 0,
283 BRW_REGISTER_TYPE_D,
284 BRW_VERTICAL_STRIDE_8,
285 BRW_WIDTH_8,
286 BRW_HORIZONTAL_STRIDE_1,
287 BRW_SWIZZLE_XXXX,
288 WRITEMASK_X);
289 reg++;
290 }
291
292 if (c->vp->use_const_buffer) {
293 for (i = 0; i < 3; i++) {
294 c->current_const[i].index = -1;
295 c->current_const[i].reg = brw_vec8_grf(reg, 0);
296 reg++;
297 }
298 }
299
300 for (i = 0; i < 128; i++) {
301 if (c->output_regs[i].used_in_src) {
302 c->output_regs[i].reg = brw_vec8_grf(reg, 0);
303 reg++;
304 }
305 }
306
307 if (c->needs_stack) {
308 c->stack = brw_uw16_reg(BRW_GENERAL_REGISTER_FILE, reg, 0);
309 reg += 2;
310 }
311
312 /* Some opcodes need an internal temporary:
313 */
314 c->first_tmp = reg;
315 c->last_tmp = reg; /* for allocation purposes */
316
317 /* Each input reg holds data from two vertices. The
318 * urb_read_length is the number of registers read from *each*
319 * vertex urb, so is half the amount:
320 */
321 c->prog_data.urb_read_length = (c->nr_inputs + 1) / 2;
322 /* Setting this field to 0 leads to undefined behavior according to the
323 * the VS_STATE docs. Our VUEs will always have at least one attribute
324 * sitting in them, even if it's padding.
325 */
326 if (c->prog_data.urb_read_length == 0)
327 c->prog_data.urb_read_length = 1;
328
329 /* The VS VUEs are shared by VF (outputting our inputs) and VS, so size
330 * them to fit the biggest thing they need to.
331 */
332 attributes_in_vue = MAX2(c->nr_outputs, c->nr_inputs);
333
334 /* See emit_vertex_write() for where the VUE's overhead on top of the
335 * attributes comes from.
336 */
337 if (intel->gen >= 6)
338 c->prog_data.urb_entry_size = (attributes_in_vue + 2 + 7) / 8;
339 else if (intel->gen == 5)
340 c->prog_data.urb_entry_size = (attributes_in_vue + 6 + 3) / 4;
341 else
342 c->prog_data.urb_entry_size = (attributes_in_vue + 2 + 3) / 4;
343
344 c->prog_data.total_grf = reg;
345
346 if (INTEL_DEBUG & DEBUG_VS) {
347 printf("%s NumAddrRegs %d\n", __FUNCTION__, c->vp->program.Base.NumAddressRegs);
348 printf("%s NumTemps %d\n", __FUNCTION__, c->vp->program.Base.NumTemporaries);
349 printf("%s reg = %d\n", __FUNCTION__, reg);
350 }
351 }
352
353
354 /**
355 * If an instruction uses a temp reg both as a src and the dest, we
356 * sometimes need to allocate an intermediate temporary.
357 */
358 static void unalias1( struct brw_vs_compile *c,
359 struct brw_reg dst,
360 struct brw_reg arg0,
361 void (*func)( struct brw_vs_compile *,
362 struct brw_reg,
363 struct brw_reg ))
364 {
365 if (dst.file == arg0.file && dst.nr == arg0.nr) {
366 struct brw_compile *p = &c->func;
367 struct brw_reg tmp = brw_writemask(get_tmp(c), dst.dw1.bits.writemask);
368 func(c, tmp, arg0);
369 brw_MOV(p, dst, tmp);
370 release_tmp(c, tmp);
371 }
372 else {
373 func(c, dst, arg0);
374 }
375 }
376
377 /**
378 * \sa unalias2
379 * Checkes if 2-operand instruction needs an intermediate temporary.
380 */
381 static void unalias2( struct brw_vs_compile *c,
382 struct brw_reg dst,
383 struct brw_reg arg0,
384 struct brw_reg arg1,
385 void (*func)( struct brw_vs_compile *,
386 struct brw_reg,
387 struct brw_reg,
388 struct brw_reg ))
389 {
390 if ((dst.file == arg0.file && dst.nr == arg0.nr) ||
391 (dst.file == arg1.file && dst.nr == arg1.nr)) {
392 struct brw_compile *p = &c->func;
393 struct brw_reg tmp = brw_writemask(get_tmp(c), dst.dw1.bits.writemask);
394 func(c, tmp, arg0, arg1);
395 brw_MOV(p, dst, tmp);
396 release_tmp(c, tmp);
397 }
398 else {
399 func(c, dst, arg0, arg1);
400 }
401 }
402
403 /**
404 * \sa unalias2
405 * Checkes if 3-operand instruction needs an intermediate temporary.
406 */
407 static void unalias3( struct brw_vs_compile *c,
408 struct brw_reg dst,
409 struct brw_reg arg0,
410 struct brw_reg arg1,
411 struct brw_reg arg2,
412 void (*func)( struct brw_vs_compile *,
413 struct brw_reg,
414 struct brw_reg,
415 struct brw_reg,
416 struct brw_reg ))
417 {
418 if ((dst.file == arg0.file && dst.nr == arg0.nr) ||
419 (dst.file == arg1.file && dst.nr == arg1.nr) ||
420 (dst.file == arg2.file && dst.nr == arg2.nr)) {
421 struct brw_compile *p = &c->func;
422 struct brw_reg tmp = brw_writemask(get_tmp(c), dst.dw1.bits.writemask);
423 func(c, tmp, arg0, arg1, arg2);
424 brw_MOV(p, dst, tmp);
425 release_tmp(c, tmp);
426 }
427 else {
428 func(c, dst, arg0, arg1, arg2);
429 }
430 }
431
432 static void emit_sop( struct brw_vs_compile *c,
433 struct brw_reg dst,
434 struct brw_reg arg0,
435 struct brw_reg arg1,
436 GLuint cond)
437 {
438 struct brw_compile *p = &c->func;
439
440 brw_MOV(p, dst, brw_imm_f(0.0f));
441 brw_CMP(p, brw_null_reg(), cond, arg0, arg1);
442 brw_MOV(p, dst, brw_imm_f(1.0f));
443 brw_set_predicate_control_flag_value(p, 0xff);
444 }
445
446 static void emit_seq( struct brw_vs_compile *c,
447 struct brw_reg dst,
448 struct brw_reg arg0,
449 struct brw_reg arg1 )
450 {
451 emit_sop(c, dst, arg0, arg1, BRW_CONDITIONAL_EQ);
452 }
453
454 static void emit_sne( struct brw_vs_compile *c,
455 struct brw_reg dst,
456 struct brw_reg arg0,
457 struct brw_reg arg1 )
458 {
459 emit_sop(c, dst, arg0, arg1, BRW_CONDITIONAL_NEQ);
460 }
461 static void emit_slt( struct brw_vs_compile *c,
462 struct brw_reg dst,
463 struct brw_reg arg0,
464 struct brw_reg arg1 )
465 {
466 emit_sop(c, dst, arg0, arg1, BRW_CONDITIONAL_L);
467 }
468
469 static void emit_sle( struct brw_vs_compile *c,
470 struct brw_reg dst,
471 struct brw_reg arg0,
472 struct brw_reg arg1 )
473 {
474 emit_sop(c, dst, arg0, arg1, BRW_CONDITIONAL_LE);
475 }
476
477 static void emit_sgt( struct brw_vs_compile *c,
478 struct brw_reg dst,
479 struct brw_reg arg0,
480 struct brw_reg arg1 )
481 {
482 emit_sop(c, dst, arg0, arg1, BRW_CONDITIONAL_G);
483 }
484
485 static void emit_sge( struct brw_vs_compile *c,
486 struct brw_reg dst,
487 struct brw_reg arg0,
488 struct brw_reg arg1 )
489 {
490 emit_sop(c, dst, arg0, arg1, BRW_CONDITIONAL_GE);
491 }
492
493 static void emit_cmp( struct brw_compile *p,
494 struct brw_reg dst,
495 struct brw_reg arg0,
496 struct brw_reg arg1,
497 struct brw_reg arg2 )
498 {
499 brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_L, arg0, brw_imm_f(0));
500 brw_SEL(p, dst, arg1, arg2);
501 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
502 }
503
504 static void emit_max( struct brw_compile *p,
505 struct brw_reg dst,
506 struct brw_reg arg0,
507 struct brw_reg arg1 )
508 {
509 brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_GE, arg0, arg1);
510 brw_SEL(p, dst, arg0, arg1);
511 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
512 }
513
514 static void emit_min( struct brw_compile *p,
515 struct brw_reg dst,
516 struct brw_reg arg0,
517 struct brw_reg arg1 )
518 {
519 brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_L, arg0, arg1);
520 brw_SEL(p, dst, arg0, arg1);
521 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
522 }
523
524
525 static void emit_math1( struct brw_vs_compile *c,
526 GLuint function,
527 struct brw_reg dst,
528 struct brw_reg arg0,
529 GLuint precision)
530 {
531 /* There are various odd behaviours with SEND on the simulator. In
532 * addition there are documented issues with the fact that the GEN4
533 * processor doesn't do dependency control properly on SEND
534 * results. So, on balance, this kludge to get around failures
535 * with writemasked math results looks like it might be necessary
536 * whether that turns out to be a simulator bug or not:
537 */
538 struct brw_compile *p = &c->func;
539 struct intel_context *intel = &p->brw->intel;
540 struct brw_reg tmp = dst;
541 GLboolean need_tmp = (intel->gen < 6 &&
542 (dst.dw1.bits.writemask != 0xf ||
543 dst.file != BRW_GENERAL_REGISTER_FILE));
544
545 if (need_tmp)
546 tmp = get_tmp(c);
547
548 brw_math(p,
549 tmp,
550 function,
551 BRW_MATH_SATURATE_NONE,
552 2,
553 arg0,
554 BRW_MATH_DATA_SCALAR,
555 precision);
556
557 if (need_tmp) {
558 brw_MOV(p, dst, tmp);
559 release_tmp(c, tmp);
560 }
561 }
562
563
564 static void emit_math2( struct brw_vs_compile *c,
565 GLuint function,
566 struct brw_reg dst,
567 struct brw_reg arg0,
568 struct brw_reg arg1,
569 GLuint precision)
570 {
571 struct brw_compile *p = &c->func;
572 struct intel_context *intel = &p->brw->intel;
573 struct brw_reg tmp = dst;
574 GLboolean need_tmp = (intel->gen < 6 &&
575 (dst.dw1.bits.writemask != 0xf ||
576 dst.file != BRW_GENERAL_REGISTER_FILE));
577
578 if (need_tmp)
579 tmp = get_tmp(c);
580
581 brw_MOV(p, brw_message_reg(3), arg1);
582
583 brw_math(p,
584 tmp,
585 function,
586 BRW_MATH_SATURATE_NONE,
587 2,
588 arg0,
589 BRW_MATH_DATA_SCALAR,
590 precision);
591
592 if (need_tmp) {
593 brw_MOV(p, dst, tmp);
594 release_tmp(c, tmp);
595 }
596 }
597
598
599 static void emit_exp_noalias( struct brw_vs_compile *c,
600 struct brw_reg dst,
601 struct brw_reg arg0 )
602 {
603 struct brw_compile *p = &c->func;
604
605
606 if (dst.dw1.bits.writemask & WRITEMASK_X) {
607 struct brw_reg tmp = get_tmp(c);
608 struct brw_reg tmp_d = retype(tmp, BRW_REGISTER_TYPE_D);
609
610 /* tmp_d = floor(arg0.x) */
611 brw_RNDD(p, tmp_d, brw_swizzle1(arg0, 0));
612
613 /* result[0] = 2.0 ^ tmp */
614
615 /* Adjust exponent for floating point:
616 * exp += 127
617 */
618 brw_ADD(p, brw_writemask(tmp_d, WRITEMASK_X), tmp_d, brw_imm_d(127));
619
620 /* Install exponent and sign.
621 * Excess drops off the edge:
622 */
623 brw_SHL(p, brw_writemask(retype(dst, BRW_REGISTER_TYPE_D), WRITEMASK_X),
624 tmp_d, brw_imm_d(23));
625
626 release_tmp(c, tmp);
627 }
628
629 if (dst.dw1.bits.writemask & WRITEMASK_Y) {
630 /* result[1] = arg0.x - floor(arg0.x) */
631 brw_FRC(p, brw_writemask(dst, WRITEMASK_Y), brw_swizzle1(arg0, 0));
632 }
633
634 if (dst.dw1.bits.writemask & WRITEMASK_Z) {
635 /* As with the LOG instruction, we might be better off just
636 * doing a taylor expansion here, seeing as we have to do all
637 * the prep work.
638 *
639 * If mathbox partial precision is too low, consider also:
640 * result[3] = result[0] * EXP(result[1])
641 */
642 emit_math1(c,
643 BRW_MATH_FUNCTION_EXP,
644 brw_writemask(dst, WRITEMASK_Z),
645 brw_swizzle1(arg0, 0),
646 BRW_MATH_PRECISION_FULL);
647 }
648
649 if (dst.dw1.bits.writemask & WRITEMASK_W) {
650 /* result[3] = 1.0; */
651 brw_MOV(p, brw_writemask(dst, WRITEMASK_W), brw_imm_f(1));
652 }
653 }
654
655
656 static void emit_log_noalias( struct brw_vs_compile *c,
657 struct brw_reg dst,
658 struct brw_reg arg0 )
659 {
660 struct brw_compile *p = &c->func;
661 struct brw_reg tmp = dst;
662 struct brw_reg tmp_ud = retype(tmp, BRW_REGISTER_TYPE_UD);
663 struct brw_reg arg0_ud = retype(arg0, BRW_REGISTER_TYPE_UD);
664 GLboolean need_tmp = (dst.dw1.bits.writemask != 0xf ||
665 dst.file != BRW_GENERAL_REGISTER_FILE);
666
667 if (need_tmp) {
668 tmp = get_tmp(c);
669 tmp_ud = retype(tmp, BRW_REGISTER_TYPE_UD);
670 }
671
672 /* Perform mant = frexpf(fabsf(x), &exp), adjust exp and mnt
673 * according to spec:
674 *
675 * These almost look likey they could be joined up, but not really
676 * practical:
677 *
678 * result[0].f = (x.i & ((1<<31)-1) >> 23) - 127
679 * result[1].i = (x.i & ((1<<23)-1) + (127<<23)
680 */
681 if (dst.dw1.bits.writemask & WRITEMASK_XZ) {
682 brw_AND(p,
683 brw_writemask(tmp_ud, WRITEMASK_X),
684 brw_swizzle1(arg0_ud, 0),
685 brw_imm_ud((1U<<31)-1));
686
687 brw_SHR(p,
688 brw_writemask(tmp_ud, WRITEMASK_X),
689 tmp_ud,
690 brw_imm_ud(23));
691
692 brw_ADD(p,
693 brw_writemask(tmp, WRITEMASK_X),
694 retype(tmp_ud, BRW_REGISTER_TYPE_D), /* does it matter? */
695 brw_imm_d(-127));
696 }
697
698 if (dst.dw1.bits.writemask & WRITEMASK_YZ) {
699 brw_AND(p,
700 brw_writemask(tmp_ud, WRITEMASK_Y),
701 brw_swizzle1(arg0_ud, 0),
702 brw_imm_ud((1<<23)-1));
703
704 brw_OR(p,
705 brw_writemask(tmp_ud, WRITEMASK_Y),
706 tmp_ud,
707 brw_imm_ud(127<<23));
708 }
709
710 if (dst.dw1.bits.writemask & WRITEMASK_Z) {
711 /* result[2] = result[0] + LOG2(result[1]); */
712
713 /* Why bother? The above is just a hint how to do this with a
714 * taylor series. Maybe we *should* use a taylor series as by
715 * the time all the above has been done it's almost certainly
716 * quicker than calling the mathbox, even with low precision.
717 *
718 * Options are:
719 * - result[0] + mathbox.LOG2(result[1])
720 * - mathbox.LOG2(arg0.x)
721 * - result[0] + inline_taylor_approx(result[1])
722 */
723 emit_math1(c,
724 BRW_MATH_FUNCTION_LOG,
725 brw_writemask(tmp, WRITEMASK_Z),
726 brw_swizzle1(tmp, 1),
727 BRW_MATH_PRECISION_FULL);
728
729 brw_ADD(p,
730 brw_writemask(tmp, WRITEMASK_Z),
731 brw_swizzle1(tmp, 2),
732 brw_swizzle1(tmp, 0));
733 }
734
735 if (dst.dw1.bits.writemask & WRITEMASK_W) {
736 /* result[3] = 1.0; */
737 brw_MOV(p, brw_writemask(tmp, WRITEMASK_W), brw_imm_f(1));
738 }
739
740 if (need_tmp) {
741 brw_MOV(p, dst, tmp);
742 release_tmp(c, tmp);
743 }
744 }
745
746
747 /* Need to unalias - consider swizzles: r0 = DST r0.xxxx r1
748 */
749 static void emit_dst_noalias( struct brw_vs_compile *c,
750 struct brw_reg dst,
751 struct brw_reg arg0,
752 struct brw_reg arg1)
753 {
754 struct brw_compile *p = &c->func;
755
756 /* There must be a better way to do this:
757 */
758 if (dst.dw1.bits.writemask & WRITEMASK_X)
759 brw_MOV(p, brw_writemask(dst, WRITEMASK_X), brw_imm_f(1.0));
760 if (dst.dw1.bits.writemask & WRITEMASK_Y)
761 brw_MUL(p, brw_writemask(dst, WRITEMASK_Y), arg0, arg1);
762 if (dst.dw1.bits.writemask & WRITEMASK_Z)
763 brw_MOV(p, brw_writemask(dst, WRITEMASK_Z), arg0);
764 if (dst.dw1.bits.writemask & WRITEMASK_W)
765 brw_MOV(p, brw_writemask(dst, WRITEMASK_W), arg1);
766 }
767
768
769 static void emit_xpd( struct brw_compile *p,
770 struct brw_reg dst,
771 struct brw_reg t,
772 struct brw_reg u)
773 {
774 brw_MUL(p, brw_null_reg(), brw_swizzle(t, 1,2,0,3), brw_swizzle(u,2,0,1,3));
775 brw_MAC(p, dst, negate(brw_swizzle(t, 2,0,1,3)), brw_swizzle(u,1,2,0,3));
776 }
777
778
779 static void emit_lit_noalias( struct brw_vs_compile *c,
780 struct brw_reg dst,
781 struct brw_reg arg0 )
782 {
783 struct brw_compile *p = &c->func;
784 struct brw_instruction *if_insn;
785 struct brw_reg tmp = dst;
786 GLboolean need_tmp = (dst.file != BRW_GENERAL_REGISTER_FILE);
787
788 if (need_tmp)
789 tmp = get_tmp(c);
790
791 brw_MOV(p, brw_writemask(dst, WRITEMASK_YZ), brw_imm_f(0));
792 brw_MOV(p, brw_writemask(dst, WRITEMASK_XW), brw_imm_f(1));
793
794 /* Need to use BRW_EXECUTE_8 and also do an 8-wide compare in order
795 * to get all channels active inside the IF. In the clipping code
796 * we run with NoMask, so it's not an option and we can use
797 * BRW_EXECUTE_1 for all comparisions.
798 */
799 brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_G, brw_swizzle1(arg0,0), brw_imm_f(0));
800 if_insn = brw_IF(p, BRW_EXECUTE_8);
801 {
802 brw_MOV(p, brw_writemask(dst, WRITEMASK_Y), brw_swizzle1(arg0,0));
803
804 brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_G, brw_swizzle1(arg0,1), brw_imm_f(0));
805 brw_MOV(p, brw_writemask(tmp, WRITEMASK_Z), brw_swizzle1(arg0,1));
806 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
807
808 emit_math2(c,
809 BRW_MATH_FUNCTION_POW,
810 brw_writemask(dst, WRITEMASK_Z),
811 brw_swizzle1(tmp, 2),
812 brw_swizzle1(arg0, 3),
813 BRW_MATH_PRECISION_PARTIAL);
814 }
815
816 brw_ENDIF(p, if_insn);
817
818 release_tmp(c, tmp);
819 }
820
821 static void emit_lrp_noalias(struct brw_vs_compile *c,
822 struct brw_reg dst,
823 struct brw_reg arg0,
824 struct brw_reg arg1,
825 struct brw_reg arg2)
826 {
827 struct brw_compile *p = &c->func;
828
829 brw_ADD(p, dst, negate(arg0), brw_imm_f(1.0));
830 brw_MUL(p, brw_null_reg(), dst, arg2);
831 brw_MAC(p, dst, arg0, arg1);
832 }
833
834 /** 3 or 4-component vector normalization */
835 static void emit_nrm( struct brw_vs_compile *c,
836 struct brw_reg dst,
837 struct brw_reg arg0,
838 int num_comps)
839 {
840 struct brw_compile *p = &c->func;
841 struct brw_reg tmp = get_tmp(c);
842
843 /* tmp = dot(arg0, arg0) */
844 if (num_comps == 3)
845 brw_DP3(p, tmp, arg0, arg0);
846 else
847 brw_DP4(p, tmp, arg0, arg0);
848
849 /* tmp = 1 / sqrt(tmp) */
850 emit_math1(c, BRW_MATH_FUNCTION_RSQ, tmp, tmp, BRW_MATH_PRECISION_FULL);
851
852 /* dst = arg0 * tmp */
853 brw_MUL(p, dst, arg0, tmp);
854
855 release_tmp(c, tmp);
856 }
857
858
859 static struct brw_reg
860 get_constant(struct brw_vs_compile *c,
861 const struct prog_instruction *inst,
862 GLuint argIndex)
863 {
864 const struct prog_src_register *src = &inst->SrcReg[argIndex];
865 struct brw_compile *p = &c->func;
866 struct brw_reg const_reg = c->current_const[argIndex].reg;
867
868 assert(argIndex < 3);
869
870 if (c->current_const[argIndex].index != src->Index) {
871 /* Keep track of the last constant loaded in this slot, for reuse. */
872 c->current_const[argIndex].index = src->Index;
873
874 #if 0
875 printf(" fetch const[%d] for arg %d into reg %d\n",
876 src->Index, argIndex, c->current_const[argIndex].reg.nr);
877 #endif
878 /* need to fetch the constant now */
879 brw_dp_READ_4_vs(p,
880 const_reg, /* writeback dest */
881 16 * src->Index, /* byte offset */
882 SURF_INDEX_VERT_CONST_BUFFER /* binding table index */
883 );
884 }
885
886 /* replicate lower four floats into upper half (to get XYZWXYZW) */
887 const_reg = stride(const_reg, 0, 4, 0);
888 const_reg.subnr = 0;
889
890 return const_reg;
891 }
892
893 static struct brw_reg
894 get_reladdr_constant(struct brw_vs_compile *c,
895 const struct prog_instruction *inst,
896 GLuint argIndex)
897 {
898 const struct prog_src_register *src = &inst->SrcReg[argIndex];
899 struct brw_compile *p = &c->func;
900 struct brw_reg const_reg = c->current_const[argIndex].reg;
901 struct brw_reg addrReg = c->regs[PROGRAM_ADDRESS][0];
902
903 assert(argIndex < 3);
904
905 /* Can't reuse a reladdr constant load. */
906 c->current_const[argIndex].index = -1;
907
908 #if 0
909 printf(" fetch const[a0.x+%d] for arg %d into reg %d\n",
910 src->Index, argIndex, c->current_const[argIndex].reg.nr);
911 #endif
912
913 /* fetch the first vec4 */
914 brw_dp_READ_4_vs_relative(p,
915 const_reg, /* writeback dest */
916 addrReg, /* address register */
917 16 * src->Index, /* byte offset */
918 SURF_INDEX_VERT_CONST_BUFFER /* binding table index */
919 );
920
921 return const_reg;
922 }
923
924
925
926 /* TODO: relative addressing!
927 */
928 static struct brw_reg get_reg( struct brw_vs_compile *c,
929 gl_register_file file,
930 GLuint index )
931 {
932 switch (file) {
933 case PROGRAM_TEMPORARY:
934 case PROGRAM_INPUT:
935 case PROGRAM_OUTPUT:
936 assert(c->regs[file][index].nr != 0);
937 return c->regs[file][index];
938 case PROGRAM_STATE_VAR:
939 case PROGRAM_CONSTANT:
940 case PROGRAM_UNIFORM:
941 assert(c->regs[PROGRAM_STATE_VAR][index].nr != 0);
942 return c->regs[PROGRAM_STATE_VAR][index];
943 case PROGRAM_ADDRESS:
944 assert(index == 0);
945 return c->regs[file][index];
946
947 case PROGRAM_UNDEFINED: /* undef values */
948 return brw_null_reg();
949
950 case PROGRAM_LOCAL_PARAM:
951 case PROGRAM_ENV_PARAM:
952 case PROGRAM_WRITE_ONLY:
953 default:
954 assert(0);
955 return brw_null_reg();
956 }
957 }
958
959
960 /**
961 * Indirect addressing: get reg[[arg] + offset].
962 */
963 static struct brw_reg deref( struct brw_vs_compile *c,
964 struct brw_reg arg,
965 GLint offset)
966 {
967 struct brw_compile *p = &c->func;
968 struct brw_reg tmp = vec4(get_tmp(c));
969 struct brw_reg addr_reg = c->regs[PROGRAM_ADDRESS][0];
970 struct brw_reg vp_address = retype(vec1(addr_reg), BRW_REGISTER_TYPE_UW);
971 GLuint byte_offset = arg.nr * 32 + arg.subnr + offset * 16;
972 struct brw_reg indirect = brw_vec4_indirect(0,0);
973
974 {
975 brw_push_insn_state(p);
976 brw_set_access_mode(p, BRW_ALIGN_1);
977
978 /* This is pretty clunky - load the address register twice and
979 * fetch each 4-dword value in turn. There must be a way to do
980 * this in a single pass, but I couldn't get it to work.
981 */
982 brw_ADD(p, brw_address_reg(0), vp_address, brw_imm_d(byte_offset));
983 brw_MOV(p, tmp, indirect);
984
985 brw_ADD(p, brw_address_reg(0), suboffset(vp_address, 8), brw_imm_d(byte_offset));
986 brw_MOV(p, suboffset(tmp, 4), indirect);
987
988 brw_pop_insn_state(p);
989 }
990
991 /* NOTE: tmp not released */
992 return vec8(tmp);
993 }
994
995
996 /**
997 * Get brw reg corresponding to the instruction's [argIndex] src reg.
998 * TODO: relative addressing!
999 */
1000 static struct brw_reg
1001 get_src_reg( struct brw_vs_compile *c,
1002 const struct prog_instruction *inst,
1003 GLuint argIndex )
1004 {
1005 const GLuint file = inst->SrcReg[argIndex].File;
1006 const GLint index = inst->SrcReg[argIndex].Index;
1007 const GLboolean relAddr = inst->SrcReg[argIndex].RelAddr;
1008
1009 if (brw_vs_arg_can_be_immediate(inst->Opcode, argIndex)) {
1010 const struct prog_src_register *src = &inst->SrcReg[argIndex];
1011
1012 if (src->Swizzle == MAKE_SWIZZLE4(SWIZZLE_ZERO,
1013 SWIZZLE_ZERO,
1014 SWIZZLE_ZERO,
1015 SWIZZLE_ZERO)) {
1016 return brw_imm_f(0.0f);
1017 } else if (src->Swizzle == MAKE_SWIZZLE4(SWIZZLE_ONE,
1018 SWIZZLE_ONE,
1019 SWIZZLE_ONE,
1020 SWIZZLE_ONE)) {
1021 if (src->Negate)
1022 return brw_imm_f(-1.0F);
1023 else
1024 return brw_imm_f(1.0F);
1025 } else if (src->File == PROGRAM_CONSTANT) {
1026 const struct gl_program_parameter_list *params;
1027 float f;
1028 int component = -1;
1029
1030 switch (src->Swizzle) {
1031 case SWIZZLE_XXXX:
1032 component = 0;
1033 break;
1034 case SWIZZLE_YYYY:
1035 component = 1;
1036 break;
1037 case SWIZZLE_ZZZZ:
1038 component = 2;
1039 break;
1040 case SWIZZLE_WWWW:
1041 component = 3;
1042 break;
1043 }
1044
1045 if (component >= 0) {
1046 params = c->vp->program.Base.Parameters;
1047 f = params->ParameterValues[src->Index][component];
1048
1049 if (src->Abs)
1050 f = fabs(f);
1051 if (src->Negate)
1052 f = -f;
1053 return brw_imm_f(f);
1054 }
1055 }
1056 }
1057
1058 switch (file) {
1059 case PROGRAM_TEMPORARY:
1060 case PROGRAM_INPUT:
1061 case PROGRAM_OUTPUT:
1062 if (relAddr) {
1063 return deref(c, c->regs[file][0], index);
1064 }
1065 else {
1066 assert(c->regs[file][index].nr != 0);
1067 return c->regs[file][index];
1068 }
1069
1070 case PROGRAM_STATE_VAR:
1071 case PROGRAM_CONSTANT:
1072 case PROGRAM_UNIFORM:
1073 case PROGRAM_ENV_PARAM:
1074 case PROGRAM_LOCAL_PARAM:
1075 if (c->vp->use_const_buffer) {
1076 if (!relAddr && c->constant_map[index] != -1) {
1077 assert(c->regs[PROGRAM_STATE_VAR][c->constant_map[index]].nr != 0);
1078 return c->regs[PROGRAM_STATE_VAR][c->constant_map[index]];
1079 } else if (relAddr)
1080 return get_reladdr_constant(c, inst, argIndex);
1081 else
1082 return get_constant(c, inst, argIndex);
1083 }
1084 else if (relAddr) {
1085 return deref(c, c->regs[PROGRAM_STATE_VAR][0], index);
1086 }
1087 else {
1088 assert(c->regs[PROGRAM_STATE_VAR][index].nr != 0);
1089 return c->regs[PROGRAM_STATE_VAR][index];
1090 }
1091 case PROGRAM_ADDRESS:
1092 assert(index == 0);
1093 return c->regs[file][index];
1094
1095 case PROGRAM_UNDEFINED:
1096 /* this is a normal case since we loop over all three src args */
1097 return brw_null_reg();
1098
1099 case PROGRAM_WRITE_ONLY:
1100 default:
1101 assert(0);
1102 return brw_null_reg();
1103 }
1104 }
1105
1106
1107 static void emit_arl( struct brw_vs_compile *c,
1108 struct brw_reg dst,
1109 struct brw_reg arg0 )
1110 {
1111 struct brw_compile *p = &c->func;
1112 struct brw_reg tmp = dst;
1113 GLboolean need_tmp = (dst.file != BRW_GENERAL_REGISTER_FILE);
1114
1115 if (need_tmp)
1116 tmp = get_tmp(c);
1117
1118 brw_RNDD(p, tmp, arg0); /* tmp = round(arg0) */
1119 brw_MUL(p, dst, tmp, brw_imm_d(16)); /* dst = tmp * 16 */
1120
1121 if (need_tmp)
1122 release_tmp(c, tmp);
1123 }
1124
1125
1126 /**
1127 * Return the brw reg for the given instruction's src argument.
1128 * Will return mangled results for SWZ op. The emit_swz() function
1129 * ignores this result and recalculates taking extended swizzles into
1130 * account.
1131 */
1132 static struct brw_reg get_arg( struct brw_vs_compile *c,
1133 const struct prog_instruction *inst,
1134 GLuint argIndex )
1135 {
1136 const struct prog_src_register *src = &inst->SrcReg[argIndex];
1137 struct brw_reg reg;
1138
1139 if (src->File == PROGRAM_UNDEFINED)
1140 return brw_null_reg();
1141
1142 reg = get_src_reg(c, inst, argIndex);
1143
1144 /* Convert 3-bit swizzle to 2-bit.
1145 */
1146 reg.dw1.bits.swizzle = BRW_SWIZZLE4(GET_SWZ(src->Swizzle, 0),
1147 GET_SWZ(src->Swizzle, 1),
1148 GET_SWZ(src->Swizzle, 2),
1149 GET_SWZ(src->Swizzle, 3));
1150
1151 /* Note this is ok for non-swizzle instructions:
1152 */
1153 reg.negate = src->Negate ? 1 : 0;
1154
1155 return reg;
1156 }
1157
1158
1159 /**
1160 * Get brw register for the given program dest register.
1161 */
1162 static struct brw_reg get_dst( struct brw_vs_compile *c,
1163 struct prog_dst_register dst )
1164 {
1165 struct brw_reg reg;
1166
1167 switch (dst.File) {
1168 case PROGRAM_TEMPORARY:
1169 case PROGRAM_OUTPUT:
1170 assert(c->regs[dst.File][dst.Index].nr != 0);
1171 reg = c->regs[dst.File][dst.Index];
1172 break;
1173 case PROGRAM_ADDRESS:
1174 assert(dst.Index == 0);
1175 reg = c->regs[dst.File][dst.Index];
1176 break;
1177 case PROGRAM_UNDEFINED:
1178 /* we may hit this for OPCODE_END, OPCODE_KIL, etc */
1179 reg = brw_null_reg();
1180 break;
1181 default:
1182 assert(0);
1183 reg = brw_null_reg();
1184 }
1185
1186 reg.dw1.bits.writemask = dst.WriteMask;
1187
1188 return reg;
1189 }
1190
1191
1192 static void emit_swz( struct brw_vs_compile *c,
1193 struct brw_reg dst,
1194 const struct prog_instruction *inst)
1195 {
1196 const GLuint argIndex = 0;
1197 const struct prog_src_register src = inst->SrcReg[argIndex];
1198 struct brw_compile *p = &c->func;
1199 GLuint zeros_mask = 0;
1200 GLuint ones_mask = 0;
1201 GLuint src_mask = 0;
1202 GLubyte src_swz[4];
1203 GLboolean need_tmp = (src.Negate &&
1204 dst.file != BRW_GENERAL_REGISTER_FILE);
1205 struct brw_reg tmp = dst;
1206 GLuint i;
1207
1208 if (need_tmp)
1209 tmp = get_tmp(c);
1210
1211 for (i = 0; i < 4; i++) {
1212 if (dst.dw1.bits.writemask & (1<<i)) {
1213 GLubyte s = GET_SWZ(src.Swizzle, i);
1214 switch (s) {
1215 case SWIZZLE_X:
1216 case SWIZZLE_Y:
1217 case SWIZZLE_Z:
1218 case SWIZZLE_W:
1219 src_mask |= 1<<i;
1220 src_swz[i] = s;
1221 break;
1222 case SWIZZLE_ZERO:
1223 zeros_mask |= 1<<i;
1224 break;
1225 case SWIZZLE_ONE:
1226 ones_mask |= 1<<i;
1227 break;
1228 }
1229 }
1230 }
1231
1232 /* Do src first, in case dst aliases src:
1233 */
1234 if (src_mask) {
1235 struct brw_reg arg0;
1236
1237 arg0 = get_src_reg(c, inst, argIndex);
1238
1239 arg0 = brw_swizzle(arg0,
1240 src_swz[0], src_swz[1],
1241 src_swz[2], src_swz[3]);
1242
1243 brw_MOV(p, brw_writemask(tmp, src_mask), arg0);
1244 }
1245
1246 if (zeros_mask)
1247 brw_MOV(p, brw_writemask(tmp, zeros_mask), brw_imm_f(0));
1248
1249 if (ones_mask)
1250 brw_MOV(p, brw_writemask(tmp, ones_mask), brw_imm_f(1));
1251
1252 if (src.Negate)
1253 brw_MOV(p, brw_writemask(tmp, src.Negate), negate(tmp));
1254
1255 if (need_tmp) {
1256 brw_MOV(p, dst, tmp);
1257 release_tmp(c, tmp);
1258 }
1259 }
1260
1261
1262 /**
1263 * Post-vertex-program processing. Send the results to the URB.
1264 */
1265 static void emit_vertex_write( struct brw_vs_compile *c)
1266 {
1267 struct brw_compile *p = &c->func;
1268 struct brw_context *brw = p->brw;
1269 struct intel_context *intel = &brw->intel;
1270 struct brw_reg pos = c->regs[PROGRAM_OUTPUT][VERT_RESULT_HPOS];
1271 struct brw_reg ndc;
1272 int eot;
1273 GLuint len_vertex_header = 2;
1274
1275 if (c->key.copy_edgeflag) {
1276 brw_MOV(p,
1277 get_reg(c, PROGRAM_OUTPUT, VERT_RESULT_EDGE),
1278 get_reg(c, PROGRAM_INPUT, VERT_ATTRIB_EDGEFLAG));
1279 }
1280
1281 if (intel->gen < 6) {
1282 /* Build ndc coords */
1283 ndc = get_tmp(c);
1284 /* ndc = 1.0 / pos.w */
1285 emit_math1(c, BRW_MATH_FUNCTION_INV, ndc, brw_swizzle1(pos, 3), BRW_MATH_PRECISION_FULL);
1286 /* ndc.xyz = pos * ndc */
1287 brw_MUL(p, brw_writemask(ndc, WRITEMASK_XYZ), pos, ndc);
1288 }
1289
1290 /* Update the header for point size, user clipping flags, and -ve rhw
1291 * workaround.
1292 */
1293 if ((c->prog_data.outputs_written & BITFIELD64_BIT(VERT_RESULT_PSIZ)) ||
1294 c->key.nr_userclip || brw->has_negative_rhw_bug)
1295 {
1296 struct brw_reg header1 = retype(get_tmp(c), BRW_REGISTER_TYPE_UD);
1297 GLuint i;
1298
1299 brw_MOV(p, header1, brw_imm_ud(0));
1300
1301 brw_set_access_mode(p, BRW_ALIGN_16);
1302
1303 if (c->prog_data.outputs_written & BITFIELD64_BIT(VERT_RESULT_PSIZ)) {
1304 struct brw_reg psiz = c->regs[PROGRAM_OUTPUT][VERT_RESULT_PSIZ];
1305 brw_MUL(p, brw_writemask(header1, WRITEMASK_W), brw_swizzle1(psiz, 0), brw_imm_f(1<<11));
1306 brw_AND(p, brw_writemask(header1, WRITEMASK_W), header1, brw_imm_ud(0x7ff<<8));
1307 }
1308
1309 for (i = 0; i < c->key.nr_userclip; i++) {
1310 brw_set_conditionalmod(p, BRW_CONDITIONAL_L);
1311 brw_DP4(p, brw_null_reg(), pos, c->userplane[i]);
1312 brw_OR(p, brw_writemask(header1, WRITEMASK_W), header1, brw_imm_ud(1<<i));
1313 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
1314 }
1315
1316 /* i965 clipping workaround:
1317 * 1) Test for -ve rhw
1318 * 2) If set,
1319 * set ndc = (0,0,0,0)
1320 * set ucp[6] = 1
1321 *
1322 * Later, clipping will detect ucp[6] and ensure the primitive is
1323 * clipped against all fixed planes.
1324 */
1325 if (brw->has_negative_rhw_bug) {
1326 brw_CMP(p,
1327 vec8(brw_null_reg()),
1328 BRW_CONDITIONAL_L,
1329 brw_swizzle1(ndc, 3),
1330 brw_imm_f(0));
1331
1332 brw_OR(p, brw_writemask(header1, WRITEMASK_W), header1, brw_imm_ud(1<<6));
1333 brw_MOV(p, ndc, brw_imm_f(0));
1334 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
1335 }
1336
1337 brw_set_access_mode(p, BRW_ALIGN_1); /* why? */
1338 brw_MOV(p, retype(brw_message_reg(1), BRW_REGISTER_TYPE_UD), header1);
1339 brw_set_access_mode(p, BRW_ALIGN_16);
1340
1341 release_tmp(c, header1);
1342 }
1343 else {
1344 brw_MOV(p, retype(brw_message_reg(1), BRW_REGISTER_TYPE_UD), brw_imm_ud(0));
1345 }
1346
1347 /* Emit the (interleaved) headers for the two vertices - an 8-reg
1348 * of zeros followed by two sets of NDC coordinates:
1349 */
1350 brw_set_access_mode(p, BRW_ALIGN_1);
1351
1352 /* The VUE layout is documented in Volume 2a. */
1353 if (intel->gen >= 6) {
1354 /* There are 8 or 16 DWs (D0-D15) in VUE header on Sandybridge:
1355 * dword 0-3 (m1) of the header is indices, point width, clip flags.
1356 * dword 4-7 (m2) is the 4D space position
1357 * dword 8-15 (m3,m4) of the vertex header is the user clip distance if
1358 * enabled. We don't use it, so skip it.
1359 * m3 is the first vertex element data we fill, which is the vertex
1360 * position.
1361 */
1362 brw_MOV(p, brw_message_reg(2), pos);
1363 brw_MOV(p, brw_message_reg(3), pos);
1364 len_vertex_header = 2;
1365 } else if (intel->gen == 5) {
1366 /* There are 20 DWs (D0-D19) in VUE header on Ironlake:
1367 * dword 0-3 (m1) of the header is indices, point width, clip flags.
1368 * dword 4-7 (m2) is the ndc position (set above)
1369 * dword 8-11 (m3) of the vertex header is the 4D space position
1370 * dword 12-19 (m4,m5) of the vertex header is the user clip distance.
1371 * m6 is a pad so that the vertex element data is aligned
1372 * m7 is the first vertex data we fill, which is the vertex position.
1373 */
1374 brw_MOV(p, brw_message_reg(2), ndc);
1375 brw_MOV(p, brw_message_reg(3), pos);
1376 brw_MOV(p, brw_message_reg(7), pos);
1377 len_vertex_header = 6;
1378 } else {
1379 /* There are 8 dwords in VUE header pre-Ironlake:
1380 * dword 0-3 (m1) is indices, point width, clip flags.
1381 * dword 4-7 (m2) is ndc position (set above)
1382 *
1383 * dword 8-11 (m3) is the first vertex data, which we always have be the
1384 * vertex position.
1385 */
1386 brw_MOV(p, brw_message_reg(2), ndc);
1387 brw_MOV(p, brw_message_reg(3), pos);
1388 len_vertex_header = 2;
1389 }
1390
1391 eot = (c->first_overflow_output == 0);
1392
1393 brw_urb_WRITE(p,
1394 brw_null_reg(), /* dest */
1395 0, /* starting mrf reg nr */
1396 c->r0, /* src */
1397 0, /* allocate */
1398 1, /* used */
1399 MIN2(c->nr_outputs + 1 + len_vertex_header, (BRW_MAX_MRF-1)), /* msg len */
1400 0, /* response len */
1401 eot, /* eot */
1402 eot, /* writes complete */
1403 0, /* urb destination offset */
1404 BRW_URB_SWIZZLE_INTERLEAVE);
1405
1406 if (c->first_overflow_output > 0) {
1407 /* Not all of the vertex outputs/results fit into the MRF.
1408 * Move the overflowed attributes from the GRF to the MRF and
1409 * issue another brw_urb_WRITE().
1410 */
1411 GLuint i, mrf = 1;
1412 for (i = c->first_overflow_output; i < VERT_RESULT_MAX; i++) {
1413 if (c->prog_data.outputs_written & BITFIELD64_BIT(i)) {
1414 /* move from GRF to MRF */
1415 brw_MOV(p, brw_message_reg(mrf), c->regs[PROGRAM_OUTPUT][i]);
1416 mrf++;
1417 }
1418 }
1419
1420 brw_urb_WRITE(p,
1421 brw_null_reg(), /* dest */
1422 0, /* starting mrf reg nr */
1423 c->r0, /* src */
1424 0, /* allocate */
1425 1, /* used */
1426 mrf, /* msg len */
1427 0, /* response len */
1428 1, /* eot */
1429 1, /* writes complete */
1430 14 / 2, /* urb destination offset */
1431 BRW_URB_SWIZZLE_INTERLEAVE);
1432 }
1433 }
1434
1435 static GLboolean
1436 accumulator_contains(struct brw_vs_compile *c, struct brw_reg val)
1437 {
1438 struct brw_compile *p = &c->func;
1439 struct brw_instruction *prev_insn = &p->store[p->nr_insn - 1];
1440
1441 if (p->nr_insn == 0)
1442 return GL_FALSE;
1443
1444 if (val.address_mode != BRW_ADDRESS_DIRECT)
1445 return GL_FALSE;
1446
1447 switch (prev_insn->header.opcode) {
1448 case BRW_OPCODE_MOV:
1449 case BRW_OPCODE_MAC:
1450 case BRW_OPCODE_MUL:
1451 if (prev_insn->header.access_mode == BRW_ALIGN_16 &&
1452 prev_insn->header.execution_size == val.width &&
1453 prev_insn->bits1.da1.dest_reg_file == val.file &&
1454 prev_insn->bits1.da1.dest_reg_type == val.type &&
1455 prev_insn->bits1.da1.dest_address_mode == val.address_mode &&
1456 prev_insn->bits1.da1.dest_reg_nr == val.nr &&
1457 prev_insn->bits1.da16.dest_subreg_nr == val.subnr / 16 &&
1458 prev_insn->bits1.da16.dest_writemask == 0xf)
1459 return GL_TRUE;
1460 else
1461 return GL_FALSE;
1462 default:
1463 return GL_FALSE;
1464 }
1465 }
1466
1467 static uint32_t
1468 get_predicate(const struct prog_instruction *inst)
1469 {
1470 if (inst->DstReg.CondMask == COND_TR)
1471 return BRW_PREDICATE_NONE;
1472
1473 /* All of GLSL only produces predicates for COND_NE and one channel per
1474 * vector. Fail badly if someone starts doing something else, as it might
1475 * mean infinite looping or something.
1476 *
1477 * We'd like to support all the condition codes, but our hardware doesn't
1478 * quite match the Mesa IR, which is modeled after the NV extensions. For
1479 * those, the instruction may update the condition codes or not, then any
1480 * later instruction may use one of those condition codes. For gen4, the
1481 * instruction may update the flags register based on one of the condition
1482 * codes output by the instruction, and then further instructions may
1483 * predicate on that. We can probably support this, but it won't
1484 * necessarily be easy.
1485 */
1486 assert(inst->DstReg.CondMask == COND_NE);
1487
1488 switch (inst->DstReg.CondSwizzle) {
1489 case SWIZZLE_XXXX:
1490 return BRW_PREDICATE_ALIGN16_REPLICATE_X;
1491 case SWIZZLE_YYYY:
1492 return BRW_PREDICATE_ALIGN16_REPLICATE_Y;
1493 case SWIZZLE_ZZZZ:
1494 return BRW_PREDICATE_ALIGN16_REPLICATE_Z;
1495 case SWIZZLE_WWWW:
1496 return BRW_PREDICATE_ALIGN16_REPLICATE_W;
1497 default:
1498 _mesa_problem(NULL, "Unexpected predicate: 0x%08x\n",
1499 inst->DstReg.CondMask);
1500 return BRW_PREDICATE_NORMAL;
1501 }
1502 }
1503
1504 /* Emit the vertex program instructions here.
1505 */
1506 void brw_vs_emit(struct brw_vs_compile *c )
1507 {
1508 #define MAX_IF_DEPTH 32
1509 #define MAX_LOOP_DEPTH 32
1510 struct brw_compile *p = &c->func;
1511 struct brw_context *brw = p->brw;
1512 struct intel_context *intel = &brw->intel;
1513 const GLuint nr_insns = c->vp->program.Base.NumInstructions;
1514 GLuint insn, if_depth = 0, loop_depth = 0;
1515 struct brw_instruction *if_inst[MAX_IF_DEPTH], *loop_inst[MAX_LOOP_DEPTH] = { 0 };
1516 const struct brw_indirect stack_index = brw_indirect(0, 0);
1517 GLuint index;
1518 GLuint file;
1519
1520 if (INTEL_DEBUG & DEBUG_VS) {
1521 printf("vs-mesa:\n");
1522 _mesa_print_program(&c->vp->program.Base);
1523 printf("\n");
1524 }
1525
1526 brw_set_compression_control(p, BRW_COMPRESSION_NONE);
1527 brw_set_access_mode(p, BRW_ALIGN_16);
1528
1529 for (insn = 0; insn < nr_insns; insn++) {
1530 GLuint i;
1531 struct prog_instruction *inst = &c->vp->program.Base.Instructions[insn];
1532
1533 /* Message registers can't be read, so copy the output into GRF
1534 * register if they are used in source registers
1535 */
1536 for (i = 0; i < 3; i++) {
1537 struct prog_src_register *src = &inst->SrcReg[i];
1538 GLuint index = src->Index;
1539 GLuint file = src->File;
1540 if (file == PROGRAM_OUTPUT && index != VERT_RESULT_HPOS)
1541 c->output_regs[index].used_in_src = GL_TRUE;
1542 }
1543
1544 switch (inst->Opcode) {
1545 case OPCODE_CAL:
1546 case OPCODE_RET:
1547 c->needs_stack = GL_TRUE;
1548 break;
1549 default:
1550 break;
1551 }
1552 }
1553
1554 /* Static register allocation
1555 */
1556 brw_vs_alloc_regs(c);
1557
1558 if (c->needs_stack)
1559 brw_MOV(p, get_addr_reg(stack_index), brw_address(c->stack));
1560
1561 for (insn = 0; insn < nr_insns; insn++) {
1562
1563 const struct prog_instruction *inst = &c->vp->program.Base.Instructions[insn];
1564 struct brw_reg args[3], dst;
1565 GLuint i;
1566
1567 #if 0
1568 printf("%d: ", insn);
1569 _mesa_print_instruction(inst);
1570 #endif
1571
1572 /* Get argument regs. SWZ is special and does this itself.
1573 */
1574 if (inst->Opcode != OPCODE_SWZ)
1575 for (i = 0; i < 3; i++) {
1576 const struct prog_src_register *src = &inst->SrcReg[i];
1577 index = src->Index;
1578 file = src->File;
1579 if (file == PROGRAM_OUTPUT && c->output_regs[index].used_in_src)
1580 args[i] = c->output_regs[index].reg;
1581 else
1582 args[i] = get_arg(c, inst, i);
1583 }
1584
1585 /* Get dest regs. Note that it is possible for a reg to be both
1586 * dst and arg, given the static allocation of registers. So
1587 * care needs to be taken emitting multi-operation instructions.
1588 */
1589 index = inst->DstReg.Index;
1590 file = inst->DstReg.File;
1591 if (file == PROGRAM_OUTPUT && c->output_regs[index].used_in_src)
1592 dst = c->output_regs[index].reg;
1593 else
1594 dst = get_dst(c, inst->DstReg);
1595
1596 if (inst->SaturateMode != SATURATE_OFF) {
1597 _mesa_problem(NULL, "Unsupported saturate %d in vertex shader",
1598 inst->SaturateMode);
1599 }
1600
1601 switch (inst->Opcode) {
1602 case OPCODE_ABS:
1603 brw_MOV(p, dst, brw_abs(args[0]));
1604 break;
1605 case OPCODE_ADD:
1606 brw_ADD(p, dst, args[0], args[1]);
1607 break;
1608 case OPCODE_COS:
1609 emit_math1(c, BRW_MATH_FUNCTION_COS, dst, args[0], BRW_MATH_PRECISION_FULL);
1610 break;
1611 case OPCODE_DP3:
1612 brw_DP3(p, dst, args[0], args[1]);
1613 break;
1614 case OPCODE_DP4:
1615 brw_DP4(p, dst, args[0], args[1]);
1616 break;
1617 case OPCODE_DPH:
1618 brw_DPH(p, dst, args[0], args[1]);
1619 break;
1620 case OPCODE_NRM3:
1621 emit_nrm(c, dst, args[0], 3);
1622 break;
1623 case OPCODE_NRM4:
1624 emit_nrm(c, dst, args[0], 4);
1625 break;
1626 case OPCODE_DST:
1627 unalias2(c, dst, args[0], args[1], emit_dst_noalias);
1628 break;
1629 case OPCODE_EXP:
1630 unalias1(c, dst, args[0], emit_exp_noalias);
1631 break;
1632 case OPCODE_EX2:
1633 emit_math1(c, BRW_MATH_FUNCTION_EXP, dst, args[0], BRW_MATH_PRECISION_FULL);
1634 break;
1635 case OPCODE_ARL:
1636 emit_arl(c, dst, args[0]);
1637 break;
1638 case OPCODE_FLR:
1639 brw_RNDD(p, dst, args[0]);
1640 break;
1641 case OPCODE_FRC:
1642 brw_FRC(p, dst, args[0]);
1643 break;
1644 case OPCODE_LOG:
1645 unalias1(c, dst, args[0], emit_log_noalias);
1646 break;
1647 case OPCODE_LG2:
1648 emit_math1(c, BRW_MATH_FUNCTION_LOG, dst, args[0], BRW_MATH_PRECISION_FULL);
1649 break;
1650 case OPCODE_LIT:
1651 unalias1(c, dst, args[0], emit_lit_noalias);
1652 break;
1653 case OPCODE_LRP:
1654 unalias3(c, dst, args[0], args[1], args[2], emit_lrp_noalias);
1655 break;
1656 case OPCODE_MAD:
1657 if (!accumulator_contains(c, args[2]))
1658 brw_MOV(p, brw_acc_reg(), args[2]);
1659 brw_MAC(p, dst, args[0], args[1]);
1660 break;
1661 case OPCODE_CMP:
1662 emit_cmp(p, dst, args[0], args[1], args[2]);
1663 break;
1664 case OPCODE_MAX:
1665 emit_max(p, dst, args[0], args[1]);
1666 break;
1667 case OPCODE_MIN:
1668 emit_min(p, dst, args[0], args[1]);
1669 break;
1670 case OPCODE_MOV:
1671 brw_MOV(p, dst, args[0]);
1672 break;
1673 case OPCODE_MUL:
1674 brw_MUL(p, dst, args[0], args[1]);
1675 break;
1676 case OPCODE_POW:
1677 emit_math2(c, BRW_MATH_FUNCTION_POW, dst, args[0], args[1], BRW_MATH_PRECISION_FULL);
1678 break;
1679 case OPCODE_RCP:
1680 emit_math1(c, BRW_MATH_FUNCTION_INV, dst, args[0], BRW_MATH_PRECISION_FULL);
1681 break;
1682 case OPCODE_RSQ:
1683 emit_math1(c, BRW_MATH_FUNCTION_RSQ, dst, args[0], BRW_MATH_PRECISION_FULL);
1684 break;
1685
1686 case OPCODE_SEQ:
1687 unalias2(c, dst, args[0], args[1], emit_seq);
1688 break;
1689 case OPCODE_SIN:
1690 emit_math1(c, BRW_MATH_FUNCTION_SIN, dst, args[0], BRW_MATH_PRECISION_FULL);
1691 break;
1692 case OPCODE_SNE:
1693 unalias2(c, dst, args[0], args[1], emit_sne);
1694 break;
1695 case OPCODE_SGE:
1696 unalias2(c, dst, args[0], args[1], emit_sge);
1697 break;
1698 case OPCODE_SGT:
1699 unalias2(c, dst, args[0], args[1], emit_sgt);
1700 break;
1701 case OPCODE_SLT:
1702 unalias2(c, dst, args[0], args[1], emit_slt);
1703 break;
1704 case OPCODE_SLE:
1705 unalias2(c, dst, args[0], args[1], emit_sle);
1706 break;
1707 case OPCODE_SUB:
1708 brw_ADD(p, dst, args[0], negate(args[1]));
1709 break;
1710 case OPCODE_SWZ:
1711 /* The args[0] value can't be used here as it won't have
1712 * correctly encoded the full swizzle:
1713 */
1714 emit_swz(c, dst, inst);
1715 break;
1716 case OPCODE_TRUNC:
1717 /* round toward zero */
1718 brw_RNDZ(p, dst, args[0]);
1719 break;
1720 case OPCODE_XPD:
1721 emit_xpd(p, dst, args[0], args[1]);
1722 break;
1723 case OPCODE_IF:
1724 assert(if_depth < MAX_IF_DEPTH);
1725 if_inst[if_depth] = brw_IF(p, BRW_EXECUTE_8);
1726 /* Note that brw_IF smashes the predicate_control field. */
1727 if_inst[if_depth]->header.predicate_control = get_predicate(inst);
1728 if_depth++;
1729 break;
1730 case OPCODE_ELSE:
1731 assert(if_depth > 0);
1732 if_inst[if_depth-1] = brw_ELSE(p, if_inst[if_depth-1]);
1733 break;
1734 case OPCODE_ENDIF:
1735 assert(if_depth > 0);
1736 brw_ENDIF(p, if_inst[--if_depth]);
1737 break;
1738 case OPCODE_BGNLOOP:
1739 loop_inst[loop_depth++] = brw_DO(p, BRW_EXECUTE_8);
1740 break;
1741 case OPCODE_BRK:
1742 brw_set_predicate_control(p, get_predicate(inst));
1743 brw_BREAK(p);
1744 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
1745 break;
1746 case OPCODE_CONT:
1747 brw_set_predicate_control(p, get_predicate(inst));
1748 brw_CONT(p);
1749 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
1750 break;
1751 case OPCODE_ENDLOOP:
1752 {
1753 struct brw_instruction *inst0, *inst1;
1754 GLuint br = 1;
1755
1756 loop_depth--;
1757
1758 if (intel->gen == 5)
1759 br = 2;
1760
1761 inst0 = inst1 = brw_WHILE(p, loop_inst[loop_depth]);
1762 /* patch all the BREAK/CONT instructions from last BEGINLOOP */
1763 while (inst0 > loop_inst[loop_depth]) {
1764 inst0--;
1765 if (inst0->header.opcode == BRW_OPCODE_BREAK &&
1766 inst0->bits3.if_else.jump_count == 0) {
1767 inst0->bits3.if_else.jump_count = br * (inst1 - inst0 + 1);
1768 inst0->bits3.if_else.pop_count = 0;
1769 }
1770 else if (inst0->header.opcode == BRW_OPCODE_CONTINUE &&
1771 inst0->bits3.if_else.jump_count == 0) {
1772 inst0->bits3.if_else.jump_count = br * (inst1 - inst0);
1773 inst0->bits3.if_else.pop_count = 0;
1774 }
1775 }
1776 }
1777 break;
1778 case OPCODE_BRA:
1779 brw_set_predicate_control(p, get_predicate(inst));
1780 brw_ADD(p, brw_ip_reg(), brw_ip_reg(), brw_imm_d(1*16));
1781 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
1782 break;
1783 case OPCODE_CAL:
1784 brw_set_access_mode(p, BRW_ALIGN_1);
1785 brw_ADD(p, deref_1d(stack_index, 0), brw_ip_reg(), brw_imm_d(3*16));
1786 brw_set_access_mode(p, BRW_ALIGN_16);
1787 brw_ADD(p, get_addr_reg(stack_index),
1788 get_addr_reg(stack_index), brw_imm_d(4));
1789 brw_save_call(p, inst->Comment, p->nr_insn);
1790 brw_ADD(p, brw_ip_reg(), brw_ip_reg(), brw_imm_d(1*16));
1791 break;
1792 case OPCODE_RET:
1793 brw_ADD(p, get_addr_reg(stack_index),
1794 get_addr_reg(stack_index), brw_imm_d(-4));
1795 brw_set_access_mode(p, BRW_ALIGN_1);
1796 brw_MOV(p, brw_ip_reg(), deref_1d(stack_index, 0));
1797 brw_set_access_mode(p, BRW_ALIGN_16);
1798 break;
1799 case OPCODE_END:
1800 emit_vertex_write(c);
1801 break;
1802 case OPCODE_PRINT:
1803 /* no-op */
1804 break;
1805 case OPCODE_BGNSUB:
1806 brw_save_label(p, inst->Comment, p->nr_insn);
1807 break;
1808 case OPCODE_ENDSUB:
1809 /* no-op */
1810 break;
1811 default:
1812 _mesa_problem(NULL, "Unsupported opcode %i (%s) in vertex shader",
1813 inst->Opcode, inst->Opcode < MAX_OPCODE ?
1814 _mesa_opcode_string(inst->Opcode) :
1815 "unknown");
1816 }
1817
1818 /* Set the predication update on the last instruction of the native
1819 * instruction sequence.
1820 *
1821 * This would be problematic if it was set on a math instruction,
1822 * but that shouldn't be the case with the current GLSL compiler.
1823 */
1824 if (inst->CondUpdate) {
1825 struct brw_instruction *hw_insn = &p->store[p->nr_insn - 1];
1826
1827 assert(hw_insn->header.destreg__conditionalmod == 0);
1828 hw_insn->header.destreg__conditionalmod = BRW_CONDITIONAL_NZ;
1829 }
1830
1831 if ((inst->DstReg.File == PROGRAM_OUTPUT)
1832 && (inst->DstReg.Index != VERT_RESULT_HPOS)
1833 && c->output_regs[inst->DstReg.Index].used_in_src) {
1834 brw_MOV(p, get_dst(c, inst->DstReg), dst);
1835 }
1836
1837 /* Result color clamping.
1838 *
1839 * When destination register is an output register and
1840 * it's primary/secondary front/back color, we have to clamp
1841 * the result to [0,1]. This is done by enabling the
1842 * saturation bit for the last instruction.
1843 *
1844 * We don't use brw_set_saturate() as it modifies
1845 * p->current->header.saturate, which affects all the subsequent
1846 * instructions. Instead, we directly modify the header
1847 * of the last (already stored) instruction.
1848 */
1849 if (inst->DstReg.File == PROGRAM_OUTPUT) {
1850 if ((inst->DstReg.Index == VERT_RESULT_COL0)
1851 || (inst->DstReg.Index == VERT_RESULT_COL1)
1852 || (inst->DstReg.Index == VERT_RESULT_BFC0)
1853 || (inst->DstReg.Index == VERT_RESULT_BFC1)) {
1854 p->store[p->nr_insn-1].header.saturate = 1;
1855 }
1856 }
1857
1858 release_tmps(c);
1859 }
1860
1861 brw_resolve_cals(p);
1862
1863 brw_optimize(p);
1864
1865 if (INTEL_DEBUG & DEBUG_VS) {
1866 int i;
1867
1868 printf("vs-native:\n");
1869 for (i = 0; i < p->nr_insn; i++)
1870 brw_disasm(stderr, &p->store[i], intel->gen);
1871 printf("\n");
1872 }
1873 }