Merge commit 'origin/7.8'
[mesa.git] / src / mesa / drivers / dri / i965 / brw_sf_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/glheader.h"
34 #include "main/macros.h"
35 #include "main/enums.h"
36
37 #include "intel_batchbuffer.h"
38
39 #include "brw_defines.h"
40 #include "brw_context.h"
41 #include "brw_eu.h"
42 #include "brw_util.h"
43 #include "brw_sf.h"
44
45
46 static struct brw_reg get_vert_attr(struct brw_sf_compile *c,
47 struct brw_reg vert,
48 GLuint attr)
49 {
50 GLuint off = c->attr_to_idx[attr] / 2;
51 GLuint sub = c->attr_to_idx[attr] % 2;
52
53 return brw_vec4_grf(vert.nr + off, sub * 4);
54 }
55
56 static GLboolean have_attr(struct brw_sf_compile *c,
57 GLuint attr)
58 {
59 return (c->key.attrs & BITFIELD64_BIT(attr)) ? 1 : 0;
60 }
61
62 /***********************************************************************
63 * Twoside lighting
64 */
65 static void copy_bfc( struct brw_sf_compile *c,
66 struct brw_reg vert )
67 {
68 struct brw_compile *p = &c->func;
69 GLuint i;
70
71 for (i = 0; i < 2; i++) {
72 if (have_attr(c, VERT_RESULT_COL0+i) &&
73 have_attr(c, VERT_RESULT_BFC0+i))
74 brw_MOV(p,
75 get_vert_attr(c, vert, VERT_RESULT_COL0+i),
76 get_vert_attr(c, vert, VERT_RESULT_BFC0+i));
77 }
78 }
79
80
81 static void do_twoside_color( struct brw_sf_compile *c )
82 {
83 struct brw_compile *p = &c->func;
84 struct brw_instruction *if_insn;
85 GLuint backface_conditional = c->key.frontface_ccw ? BRW_CONDITIONAL_G : BRW_CONDITIONAL_L;
86
87 /* Already done in clip program:
88 */
89 if (c->key.primitive == SF_UNFILLED_TRIS)
90 return;
91
92 /* XXX: What happens if BFC isn't present? This could only happen
93 * for user-supplied vertex programs, as t_vp_build.c always does
94 * the right thing.
95 */
96 if (!(have_attr(c, VERT_RESULT_COL0) && have_attr(c, VERT_RESULT_BFC0)) &&
97 !(have_attr(c, VERT_RESULT_COL1) && have_attr(c, VERT_RESULT_BFC1)))
98 return;
99
100 /* Need to use BRW_EXECUTE_4 and also do an 4-wide compare in order
101 * to get all channels active inside the IF. In the clipping code
102 * we run with NoMask, so it's not an option and we can use
103 * BRW_EXECUTE_1 for all comparisions.
104 */
105 brw_push_insn_state(p);
106 brw_CMP(p, vec4(brw_null_reg()), backface_conditional, c->det, brw_imm_f(0));
107 if_insn = brw_IF(p, BRW_EXECUTE_4);
108 {
109 switch (c->nr_verts) {
110 case 3: copy_bfc(c, c->vert[2]);
111 case 2: copy_bfc(c, c->vert[1]);
112 case 1: copy_bfc(c, c->vert[0]);
113 }
114 }
115 brw_ENDIF(p, if_insn);
116 brw_pop_insn_state(p);
117 }
118
119
120
121 /***********************************************************************
122 * Flat shading
123 */
124
125 #define VERT_RESULT_COLOR_BITS (BITFIELD64_BIT(VERT_RESULT_COL0) | \
126 BITFIELD64_BIT(VERT_RESULT_COL1))
127
128 static void copy_colors( struct brw_sf_compile *c,
129 struct brw_reg dst,
130 struct brw_reg src)
131 {
132 struct brw_compile *p = &c->func;
133 GLuint i;
134
135 for (i = VERT_RESULT_COL0; i <= VERT_RESULT_COL1; i++) {
136 if (have_attr(c,i))
137 brw_MOV(p,
138 get_vert_attr(c, dst, i),
139 get_vert_attr(c, src, i));
140 }
141 }
142
143
144
145 /* Need to use a computed jump to copy flatshaded attributes as the
146 * vertices are ordered according to y-coordinate before reaching this
147 * point, so the PV could be anywhere.
148 */
149 static void do_flatshade_triangle( struct brw_sf_compile *c )
150 {
151 struct brw_compile *p = &c->func;
152 struct intel_context *intel = &p->brw->intel;
153 struct brw_reg ip = brw_ip_reg();
154 GLuint nr = brw_count_bits(c->key.attrs & VERT_RESULT_COLOR_BITS);
155 GLuint jmpi = 1;
156
157 if (!nr)
158 return;
159
160 /* Already done in clip program:
161 */
162 if (c->key.primitive == SF_UNFILLED_TRIS)
163 return;
164
165 if (intel->is_ironlake)
166 jmpi = 2;
167
168 brw_push_insn_state(p);
169
170 brw_MUL(p, c->pv, c->pv, brw_imm_d(jmpi*(nr*2+1)));
171 brw_JMPI(p, ip, ip, c->pv);
172
173 copy_colors(c, c->vert[1], c->vert[0]);
174 copy_colors(c, c->vert[2], c->vert[0]);
175 brw_JMPI(p, ip, ip, brw_imm_d(jmpi*(nr*4+1)));
176
177 copy_colors(c, c->vert[0], c->vert[1]);
178 copy_colors(c, c->vert[2], c->vert[1]);
179 brw_JMPI(p, ip, ip, brw_imm_d(jmpi*nr*2));
180
181 copy_colors(c, c->vert[0], c->vert[2]);
182 copy_colors(c, c->vert[1], c->vert[2]);
183
184 brw_pop_insn_state(p);
185 }
186
187
188 static void do_flatshade_line( struct brw_sf_compile *c )
189 {
190 struct brw_compile *p = &c->func;
191 struct intel_context *intel = &p->brw->intel;
192 struct brw_reg ip = brw_ip_reg();
193 GLuint nr = brw_count_bits(c->key.attrs & VERT_RESULT_COLOR_BITS);
194 GLuint jmpi = 1;
195
196 if (!nr)
197 return;
198
199 /* Already done in clip program:
200 */
201 if (c->key.primitive == SF_UNFILLED_TRIS)
202 return;
203
204 if (intel->is_ironlake)
205 jmpi = 2;
206
207 brw_push_insn_state(p);
208
209 brw_MUL(p, c->pv, c->pv, brw_imm_d(jmpi*(nr+1)));
210 brw_JMPI(p, ip, ip, c->pv);
211 copy_colors(c, c->vert[1], c->vert[0]);
212
213 brw_JMPI(p, ip, ip, brw_imm_ud(jmpi*nr));
214 copy_colors(c, c->vert[0], c->vert[1]);
215
216 brw_pop_insn_state(p);
217 }
218
219
220
221 /***********************************************************************
222 * Triangle setup.
223 */
224
225
226 static void alloc_regs( struct brw_sf_compile *c )
227 {
228 GLuint reg, i;
229
230 /* Values computed by fixed function unit:
231 */
232 c->pv = retype(brw_vec1_grf(1, 1), BRW_REGISTER_TYPE_D);
233 c->det = brw_vec1_grf(1, 2);
234 c->dx0 = brw_vec1_grf(1, 3);
235 c->dx2 = brw_vec1_grf(1, 4);
236 c->dy0 = brw_vec1_grf(1, 5);
237 c->dy2 = brw_vec1_grf(1, 6);
238
239 /* z and 1/w passed in seperately:
240 */
241 c->z[0] = brw_vec1_grf(2, 0);
242 c->inv_w[0] = brw_vec1_grf(2, 1);
243 c->z[1] = brw_vec1_grf(2, 2);
244 c->inv_w[1] = brw_vec1_grf(2, 3);
245 c->z[2] = brw_vec1_grf(2, 4);
246 c->inv_w[2] = brw_vec1_grf(2, 5);
247
248 /* The vertices:
249 */
250 reg = 3;
251 for (i = 0; i < c->nr_verts; i++) {
252 c->vert[i] = brw_vec8_grf(reg, 0);
253 reg += c->nr_attr_regs;
254 }
255
256 /* Temporaries, allocated after last vertex reg.
257 */
258 c->inv_det = brw_vec1_grf(reg, 0); reg++;
259 c->a1_sub_a0 = brw_vec8_grf(reg, 0); reg++;
260 c->a2_sub_a0 = brw_vec8_grf(reg, 0); reg++;
261 c->tmp = brw_vec8_grf(reg, 0); reg++;
262
263 /* Note grf allocation:
264 */
265 c->prog_data.total_grf = reg;
266
267
268 /* Outputs of this program - interpolation coefficients for
269 * rasterization:
270 */
271 c->m1Cx = brw_vec8_reg(BRW_MESSAGE_REGISTER_FILE, 1, 0);
272 c->m2Cy = brw_vec8_reg(BRW_MESSAGE_REGISTER_FILE, 2, 0);
273 c->m3C0 = brw_vec8_reg(BRW_MESSAGE_REGISTER_FILE, 3, 0);
274 }
275
276
277 static void copy_z_inv_w( struct brw_sf_compile *c )
278 {
279 struct brw_compile *p = &c->func;
280 GLuint i;
281
282 brw_push_insn_state(p);
283
284 /* Copy both scalars with a single MOV:
285 */
286 for (i = 0; i < c->nr_verts; i++)
287 brw_MOV(p, vec2(suboffset(c->vert[i], 2)), vec2(c->z[i]));
288
289 brw_pop_insn_state(p);
290 }
291
292
293 static void invert_det( struct brw_sf_compile *c)
294 {
295 /* Looks like we invert all 8 elements just to get 1/det in
296 * position 2 !?!
297 */
298 brw_math(&c->func,
299 c->inv_det,
300 BRW_MATH_FUNCTION_INV,
301 BRW_MATH_SATURATE_NONE,
302 0,
303 c->det,
304 BRW_MATH_DATA_SCALAR,
305 BRW_MATH_PRECISION_FULL);
306
307 }
308
309
310 static GLboolean calculate_masks( struct brw_sf_compile *c,
311 GLuint reg,
312 GLushort *pc,
313 GLushort *pc_persp,
314 GLushort *pc_linear)
315 {
316 GLboolean is_last_attr = (reg == c->nr_setup_regs - 1);
317 GLbitfield64 persp_mask;
318 GLbitfield64 linear_mask;
319
320 if (c->key.do_flat_shading || c->key.linear_color)
321 persp_mask = c->key.attrs & ~(FRAG_BIT_WPOS |
322 FRAG_BIT_COL0 |
323 FRAG_BIT_COL1);
324 else
325 persp_mask = c->key.attrs & ~(FRAG_BIT_WPOS);
326
327 if (c->key.do_flat_shading)
328 linear_mask = c->key.attrs & ~(FRAG_BIT_COL0|FRAG_BIT_COL1);
329 else
330 linear_mask = c->key.attrs;
331
332 *pc_persp = 0;
333 *pc_linear = 0;
334 *pc = 0xf;
335
336 if (persp_mask & BITFIELD64_BIT(c->idx_to_attr[reg*2]))
337 *pc_persp = 0xf;
338
339 if (linear_mask & BITFIELD64_BIT(c->idx_to_attr[reg*2]))
340 *pc_linear = 0xf;
341
342 /* Maybe only processs one attribute on the final round:
343 */
344 if (reg*2+1 < c->nr_setup_attrs) {
345 *pc |= 0xf0;
346
347 if (persp_mask & BITFIELD64_BIT(c->idx_to_attr[reg*2+1]))
348 *pc_persp |= 0xf0;
349
350 if (linear_mask & BITFIELD64_BIT(c->idx_to_attr[reg*2+1]))
351 *pc_linear |= 0xf0;
352 }
353
354 return is_last_attr;
355 }
356
357 /* Calculates the predicate control for which channels of a reg
358 * (containing 2 attrs) to do point sprite coordinate replacement on.
359 */
360 static uint16_t
361 calculate_point_sprite_mask(struct brw_sf_compile *c, GLuint reg)
362 {
363 int attr1, attr2;
364 uint16_t pc = 0;
365
366 attr1 = c->idx_to_attr[reg * 2];
367 if (attr1 >= VERT_RESULT_TEX0 && attr1 <= VERT_RESULT_TEX7) {
368 if (c->key.point_sprite_coord_replace & (1 << (attr1 - VERT_RESULT_TEX0)))
369 pc |= 0x0f;
370 }
371
372 if (reg * 2 + 1 < c->nr_setup_attrs) {
373 attr2 = c->idx_to_attr[reg * 2 + 1];
374 if (attr2 >= VERT_RESULT_TEX0 && attr2 <= VERT_RESULT_TEX7) {
375 if (c->key.point_sprite_coord_replace & (1 << (attr2 -
376 VERT_RESULT_TEX0)))
377 pc |= 0xf0;
378 }
379 }
380
381 return pc;
382 }
383
384
385
386 void brw_emit_tri_setup( struct brw_sf_compile *c, GLboolean allocate)
387 {
388 struct brw_compile *p = &c->func;
389 GLuint i;
390
391 c->nr_verts = 3;
392
393 if (allocate)
394 alloc_regs(c);
395
396 invert_det(c);
397 copy_z_inv_w(c);
398
399 if (c->key.do_twoside_color)
400 do_twoside_color(c);
401
402 if (c->key.do_flat_shading)
403 do_flatshade_triangle(c);
404
405
406 for (i = 0; i < c->nr_setup_regs; i++)
407 {
408 /* Pair of incoming attributes:
409 */
410 struct brw_reg a0 = offset(c->vert[0], i);
411 struct brw_reg a1 = offset(c->vert[1], i);
412 struct brw_reg a2 = offset(c->vert[2], i);
413 GLushort pc, pc_persp, pc_linear;
414 GLboolean last = calculate_masks(c, i, &pc, &pc_persp, &pc_linear);
415
416 if (pc_persp)
417 {
418 brw_set_predicate_control_flag_value(p, pc_persp);
419 brw_MUL(p, a0, a0, c->inv_w[0]);
420 brw_MUL(p, a1, a1, c->inv_w[1]);
421 brw_MUL(p, a2, a2, c->inv_w[2]);
422 }
423
424
425 /* Calculate coefficients for interpolated values:
426 */
427 if (pc_linear)
428 {
429 brw_set_predicate_control_flag_value(p, pc_linear);
430
431 brw_ADD(p, c->a1_sub_a0, a1, negate(a0));
432 brw_ADD(p, c->a2_sub_a0, a2, negate(a0));
433
434 /* calculate dA/dx
435 */
436 brw_MUL(p, brw_null_reg(), c->a1_sub_a0, c->dy2);
437 brw_MAC(p, c->tmp, c->a2_sub_a0, negate(c->dy0));
438 brw_MUL(p, c->m1Cx, c->tmp, c->inv_det);
439
440 /* calculate dA/dy
441 */
442 brw_MUL(p, brw_null_reg(), c->a2_sub_a0, c->dx0);
443 brw_MAC(p, c->tmp, c->a1_sub_a0, negate(c->dx2));
444 brw_MUL(p, c->m2Cy, c->tmp, c->inv_det);
445 }
446
447 {
448 brw_set_predicate_control_flag_value(p, pc);
449 /* start point for interpolation
450 */
451 brw_MOV(p, c->m3C0, a0);
452
453 /* Copy m0..m3 to URB. m0 is implicitly copied from r0 in
454 * the send instruction:
455 */
456 brw_urb_WRITE(p,
457 brw_null_reg(),
458 0,
459 brw_vec8_grf(0, 0), /* r0, will be copied to m0 */
460 0, /* allocate */
461 1, /* used */
462 4, /* msg len */
463 0, /* response len */
464 last, /* eot */
465 last, /* writes complete */
466 i*4, /* offset */
467 BRW_URB_SWIZZLE_TRANSPOSE); /* XXX: Swizzle control "SF to windower" */
468 }
469 }
470 }
471
472
473
474 void brw_emit_line_setup( struct brw_sf_compile *c, GLboolean allocate)
475 {
476 struct brw_compile *p = &c->func;
477 GLuint i;
478
479
480 c->nr_verts = 2;
481
482 if (allocate)
483 alloc_regs(c);
484
485 invert_det(c);
486 copy_z_inv_w(c);
487
488 if (c->key.do_flat_shading)
489 do_flatshade_line(c);
490
491 for (i = 0; i < c->nr_setup_regs; i++)
492 {
493 /* Pair of incoming attributes:
494 */
495 struct brw_reg a0 = offset(c->vert[0], i);
496 struct brw_reg a1 = offset(c->vert[1], i);
497 GLushort pc, pc_persp, pc_linear;
498 GLboolean last = calculate_masks(c, i, &pc, &pc_persp, &pc_linear);
499
500 if (pc_persp)
501 {
502 brw_set_predicate_control_flag_value(p, pc_persp);
503 brw_MUL(p, a0, a0, c->inv_w[0]);
504 brw_MUL(p, a1, a1, c->inv_w[1]);
505 }
506
507 /* Calculate coefficients for position, color:
508 */
509 if (pc_linear) {
510 brw_set_predicate_control_flag_value(p, pc_linear);
511
512 brw_ADD(p, c->a1_sub_a0, a1, negate(a0));
513
514 brw_MUL(p, c->tmp, c->a1_sub_a0, c->dx0);
515 brw_MUL(p, c->m1Cx, c->tmp, c->inv_det);
516
517 brw_MUL(p, c->tmp, c->a1_sub_a0, c->dy0);
518 brw_MUL(p, c->m2Cy, c->tmp, c->inv_det);
519 }
520
521 {
522 brw_set_predicate_control_flag_value(p, pc);
523
524 /* start point for interpolation
525 */
526 brw_MOV(p, c->m3C0, a0);
527
528 /* Copy m0..m3 to URB.
529 */
530 brw_urb_WRITE(p,
531 brw_null_reg(),
532 0,
533 brw_vec8_grf(0, 0),
534 0, /* allocate */
535 1, /* used */
536 4, /* msg len */
537 0, /* response len */
538 last, /* eot */
539 last, /* writes complete */
540 i*4, /* urb destination offset */
541 BRW_URB_SWIZZLE_TRANSPOSE);
542 }
543 }
544 }
545
546 void brw_emit_point_sprite_setup( struct brw_sf_compile *c, GLboolean allocate)
547 {
548 struct brw_compile *p = &c->func;
549 GLuint i;
550
551 c->nr_verts = 1;
552
553 if (allocate)
554 alloc_regs(c);
555
556 copy_z_inv_w(c);
557 for (i = 0; i < c->nr_setup_regs; i++)
558 {
559 struct brw_reg a0 = offset(c->vert[0], i);
560 GLushort pc, pc_persp, pc_linear, pc_coord_replace;
561 GLboolean last = calculate_masks(c, i, &pc, &pc_persp, &pc_linear);
562
563 pc_coord_replace = calculate_point_sprite_mask(c, i);
564 pc_persp &= ~pc_coord_replace;
565
566 if (pc_persp) {
567 brw_set_predicate_control_flag_value(p, pc_persp);
568 brw_MUL(p, a0, a0, c->inv_w[0]);
569 }
570
571 /* Point sprite coordinate replacement: A texcoord with this
572 * enabled gets replaced with the value (x, y, 0, 1) where x and
573 * y vary from 0 to 1 across the horizontal and vertical of the
574 * point.
575 */
576 if (pc_coord_replace) {
577 brw_set_predicate_control_flag_value(p, pc_coord_replace);
578 /* Caculate 1.0/PointWidth */
579 brw_math(&c->func,
580 c->tmp,
581 BRW_MATH_FUNCTION_INV,
582 BRW_MATH_SATURATE_NONE,
583 0,
584 c->dx0,
585 BRW_MATH_DATA_SCALAR,
586 BRW_MATH_PRECISION_FULL);
587
588 brw_set_access_mode(p, BRW_ALIGN_16);
589
590 /* dA/dx, dA/dy */
591 brw_MOV(p, c->m1Cx, brw_imm_f(0.0));
592 brw_MOV(p, c->m2Cy, brw_imm_f(0.0));
593 brw_MOV(p, brw_writemask(c->m1Cx, WRITEMASK_X), c->tmp);
594 if (c->key.sprite_origin_lower_left) {
595 brw_MOV(p, brw_writemask(c->m2Cy, WRITEMASK_Y), negate(c->tmp));
596 } else {
597 brw_MOV(p, brw_writemask(c->m2Cy, WRITEMASK_Y), c->tmp);
598 }
599
600 /* attribute constant offset */
601 brw_MOV(p, c->m3C0, brw_imm_f(0.0));
602 if (c->key.sprite_origin_lower_left) {
603 brw_MOV(p, brw_writemask(c->m3C0, WRITEMASK_YW), brw_imm_f(1.0));
604 } else {
605 brw_MOV(p, brw_writemask(c->m3C0, WRITEMASK_W), brw_imm_f(1.0));
606 }
607
608 brw_set_access_mode(p, BRW_ALIGN_1);
609 }
610
611 if (pc & ~pc_coord_replace) {
612 brw_set_predicate_control_flag_value(p, pc & ~pc_coord_replace);
613 brw_MOV(p, c->m1Cx, brw_imm_ud(0));
614 brw_MOV(p, c->m2Cy, brw_imm_ud(0));
615 brw_MOV(p, c->m3C0, a0); /* constant value */
616 }
617
618
619 brw_set_predicate_control_flag_value(p, pc);
620 /* Copy m0..m3 to URB. */
621 brw_urb_WRITE(p,
622 brw_null_reg(),
623 0,
624 brw_vec8_grf(0, 0),
625 0, /* allocate */
626 1, /* used */
627 4, /* msg len */
628 0, /* response len */
629 last, /* eot */
630 last, /* writes complete */
631 i*4, /* urb destination offset */
632 BRW_URB_SWIZZLE_TRANSPOSE);
633 }
634 }
635
636 /* Points setup - several simplifications as all attributes are
637 * constant across the face of the point (point sprites excluded!)
638 */
639 void brw_emit_point_setup( struct brw_sf_compile *c, GLboolean allocate)
640 {
641 struct brw_compile *p = &c->func;
642 GLuint i;
643
644 c->nr_verts = 1;
645
646 if (allocate)
647 alloc_regs(c);
648
649 copy_z_inv_w(c);
650
651 brw_MOV(p, c->m1Cx, brw_imm_ud(0)); /* zero - move out of loop */
652 brw_MOV(p, c->m2Cy, brw_imm_ud(0)); /* zero - move out of loop */
653
654 for (i = 0; i < c->nr_setup_regs; i++)
655 {
656 struct brw_reg a0 = offset(c->vert[0], i);
657 GLushort pc, pc_persp, pc_linear;
658 GLboolean last = calculate_masks(c, i, &pc, &pc_persp, &pc_linear);
659
660 if (pc_persp)
661 {
662 /* This seems odd as the values are all constant, but the
663 * fragment shader will be expecting it:
664 */
665 brw_set_predicate_control_flag_value(p, pc_persp);
666 brw_MUL(p, a0, a0, c->inv_w[0]);
667 }
668
669
670 /* The delta values are always zero, just send the starting
671 * coordinate. Again, this is to fit in with the interpolation
672 * code in the fragment shader.
673 */
674 {
675 brw_set_predicate_control_flag_value(p, pc);
676
677 brw_MOV(p, c->m3C0, a0); /* constant value */
678
679 /* Copy m0..m3 to URB.
680 */
681 brw_urb_WRITE(p,
682 brw_null_reg(),
683 0,
684 brw_vec8_grf(0, 0),
685 0, /* allocate */
686 1, /* used */
687 4, /* msg len */
688 0, /* response len */
689 last, /* eot */
690 last, /* writes complete */
691 i*4, /* urb destination offset */
692 BRW_URB_SWIZZLE_TRANSPOSE);
693 }
694 }
695 }
696
697 void brw_emit_anyprim_setup( struct brw_sf_compile *c )
698 {
699 struct brw_compile *p = &c->func;
700 struct brw_reg ip = brw_ip_reg();
701 struct brw_reg payload_prim = brw_uw1_reg(BRW_GENERAL_REGISTER_FILE, 1, 0);
702 struct brw_reg payload_attr = get_element_ud(brw_vec1_reg(BRW_GENERAL_REGISTER_FILE, 1, 0), 0);
703 struct brw_reg primmask;
704 struct brw_instruction *jmp;
705 struct brw_reg v1_null_ud = vec1(retype(brw_null_reg(), BRW_REGISTER_TYPE_UD));
706
707 GLuint saveflag;
708
709 c->nr_verts = 3;
710 alloc_regs(c);
711
712 primmask = retype(get_element(c->tmp, 0), BRW_REGISTER_TYPE_UD);
713
714 brw_MOV(p, primmask, brw_imm_ud(1));
715 brw_SHL(p, primmask, primmask, payload_prim);
716
717 brw_set_conditionalmod(p, BRW_CONDITIONAL_Z);
718 brw_AND(p, v1_null_ud, primmask, brw_imm_ud((1<<_3DPRIM_TRILIST) |
719 (1<<_3DPRIM_TRISTRIP) |
720 (1<<_3DPRIM_TRIFAN) |
721 (1<<_3DPRIM_TRISTRIP_REVERSE) |
722 (1<<_3DPRIM_POLYGON) |
723 (1<<_3DPRIM_RECTLIST) |
724 (1<<_3DPRIM_TRIFAN_NOSTIPPLE)));
725 jmp = brw_JMPI(p, ip, ip, brw_imm_d(0));
726 {
727 saveflag = p->flag_value;
728 brw_push_insn_state(p);
729 brw_emit_tri_setup( c, GL_FALSE );
730 brw_pop_insn_state(p);
731 p->flag_value = saveflag;
732 /* note - thread killed in subroutine, so must
733 * restore the flag which is changed when building
734 * the subroutine. fix #13240
735 */
736 }
737 brw_land_fwd_jump(p, jmp);
738
739 brw_set_conditionalmod(p, BRW_CONDITIONAL_Z);
740 brw_AND(p, v1_null_ud, primmask, brw_imm_ud((1<<_3DPRIM_LINELIST) |
741 (1<<_3DPRIM_LINESTRIP) |
742 (1<<_3DPRIM_LINELOOP) |
743 (1<<_3DPRIM_LINESTRIP_CONT) |
744 (1<<_3DPRIM_LINESTRIP_BF) |
745 (1<<_3DPRIM_LINESTRIP_CONT_BF)));
746 jmp = brw_JMPI(p, ip, ip, brw_imm_d(0));
747 {
748 saveflag = p->flag_value;
749 brw_push_insn_state(p);
750 brw_emit_line_setup( c, GL_FALSE );
751 brw_pop_insn_state(p);
752 p->flag_value = saveflag;
753 /* note - thread killed in subroutine */
754 }
755 brw_land_fwd_jump(p, jmp);
756
757 brw_set_conditionalmod(p, BRW_CONDITIONAL_Z);
758 brw_AND(p, v1_null_ud, payload_attr, brw_imm_ud(1<<BRW_SPRITE_POINT_ENABLE));
759 jmp = brw_JMPI(p, ip, ip, brw_imm_d(0));
760 {
761 saveflag = p->flag_value;
762 brw_push_insn_state(p);
763 brw_emit_point_sprite_setup( c, GL_FALSE );
764 brw_pop_insn_state(p);
765 p->flag_value = saveflag;
766 }
767 brw_land_fwd_jump(p, jmp);
768
769 brw_emit_point_setup( c, GL_FALSE );
770 }
771
772
773
774