llvmpipe: reintroduce SET_STATE binner command
[mesa.git] / src / gallium / drivers / llvmpipe / lp_setup_tri.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * 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, sub license, 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 portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /*
29 * Binning code for triangles
30 */
31
32 #include "util/u_math.h"
33 #include "util/u_memory.h"
34 #include "util/u_rect.h"
35 #include "lp_perf.h"
36 #include "lp_setup_context.h"
37 #include "lp_setup_coef.h"
38 #include "lp_rast.h"
39 #include "lp_state_fs.h"
40
41 #define NUM_CHANNELS 4
42
43
44
45 static INLINE int
46 subpixel_snap(float a)
47 {
48 return util_iround(FIXED_ONE * a);
49 }
50
51 static INLINE float
52 fixed_to_float(int a)
53 {
54 return a * (1.0 / FIXED_ONE);
55 }
56
57
58
59
60
61
62
63 /**
64 * Alloc space for a new triangle plus the input.a0/dadx/dady arrays
65 * immediately after it.
66 * The memory is allocated from the per-scene pool, not per-tile.
67 * \param tri_size returns number of bytes allocated
68 * \param nr_inputs number of fragment shader inputs
69 * \return pointer to triangle space
70 */
71 struct lp_rast_triangle *
72 lp_setup_alloc_triangle(struct lp_scene *scene,
73 unsigned nr_inputs,
74 unsigned nr_planes,
75 unsigned *tri_size)
76 {
77 unsigned input_array_sz = NUM_CHANNELS * (nr_inputs + 1) * sizeof(float);
78 struct lp_rast_triangle *tri;
79 unsigned tri_bytes, bytes;
80 char *inputs;
81
82 tri_bytes = align(Offset(struct lp_rast_triangle, plane[nr_planes]), 16);
83 bytes = tri_bytes + (3 * input_array_sz);
84
85 tri = lp_scene_alloc_aligned( scene, bytes, 16 );
86
87 if (tri) {
88 inputs = ((char *)tri) + tri_bytes;
89 tri->inputs.a0 = (float (*)[4]) inputs;
90 tri->inputs.dadx = (float (*)[4]) (inputs + input_array_sz);
91 tri->inputs.dady = (float (*)[4]) (inputs + 2 * input_array_sz);
92
93 *tri_size = bytes;
94 }
95
96 return tri;
97 }
98
99 void
100 lp_setup_print_vertex(struct lp_setup_context *setup,
101 const char *name,
102 const float (*v)[4])
103 {
104 int i, j;
105
106 debug_printf(" wpos (%s[0]) xyzw %f %f %f %f\n",
107 name,
108 v[0][0], v[0][1], v[0][2], v[0][3]);
109
110 for (i = 0; i < setup->fs.nr_inputs; i++) {
111 const float *in = v[setup->fs.input[i].src_index];
112
113 debug_printf(" in[%d] (%s[%d]) %s%s%s%s ",
114 i,
115 name, setup->fs.input[i].src_index,
116 (setup->fs.input[i].usage_mask & 0x1) ? "x" : " ",
117 (setup->fs.input[i].usage_mask & 0x2) ? "y" : " ",
118 (setup->fs.input[i].usage_mask & 0x4) ? "z" : " ",
119 (setup->fs.input[i].usage_mask & 0x8) ? "w" : " ");
120
121 for (j = 0; j < 4; j++)
122 if (setup->fs.input[i].usage_mask & (1<<j))
123 debug_printf("%.5f ", in[j]);
124
125 debug_printf("\n");
126 }
127 }
128
129
130 /**
131 * Print triangle vertex attribs (for debug).
132 */
133 void
134 lp_setup_print_triangle(struct lp_setup_context *setup,
135 const float (*v0)[4],
136 const float (*v1)[4],
137 const float (*v2)[4])
138 {
139 debug_printf("triangle\n");
140
141 {
142 const float ex = v0[0][0] - v2[0][0];
143 const float ey = v0[0][1] - v2[0][1];
144 const float fx = v1[0][0] - v2[0][0];
145 const float fy = v1[0][1] - v2[0][1];
146
147 /* det = cross(e,f).z */
148 const float det = ex * fy - ey * fx;
149 if (det < 0.0f)
150 debug_printf(" - ccw\n");
151 else if (det > 0.0f)
152 debug_printf(" - cw\n");
153 else
154 debug_printf(" - zero area\n");
155 }
156
157 lp_setup_print_vertex(setup, "v0", v0);
158 lp_setup_print_vertex(setup, "v1", v1);
159 lp_setup_print_vertex(setup, "v2", v2);
160 }
161
162
163 #define MAX_PLANES 8
164 static unsigned
165 lp_rast_tri_tab[MAX_PLANES+1] = {
166 0, /* should be impossible */
167 LP_RAST_OP_TRIANGLE_1,
168 LP_RAST_OP_TRIANGLE_2,
169 LP_RAST_OP_TRIANGLE_3,
170 LP_RAST_OP_TRIANGLE_4,
171 LP_RAST_OP_TRIANGLE_5,
172 LP_RAST_OP_TRIANGLE_6,
173 LP_RAST_OP_TRIANGLE_7,
174 LP_RAST_OP_TRIANGLE_8
175 };
176
177
178
179 /**
180 * The primitive covers the whole tile- shade whole tile.
181 *
182 * \param tx, ty the tile position in tiles, not pixels
183 */
184 static boolean
185 lp_setup_whole_tile(struct lp_setup_context *setup,
186 const struct lp_rast_shader_inputs *inputs,
187 int tx, int ty)
188 {
189 struct lp_scene *scene = setup->scene;
190
191 LP_COUNT(nr_fully_covered_64);
192
193 /* if variant is opaque and scissor doesn't effect the tile */
194 if (inputs->opaque) {
195 if (!scene->fb.zsbuf) {
196 /*
197 * All previous rendering will be overwritten so reset the bin.
198 */
199 lp_scene_bin_reset( scene, tx, ty );
200 }
201
202 LP_COUNT(nr_shade_opaque_64);
203 return lp_scene_bin_cmd_with_state( scene, tx, ty,
204 setup->fs.stored,
205 LP_RAST_OP_SHADE_TILE_OPAQUE,
206 lp_rast_arg_inputs(inputs) );
207 } else {
208 LP_COUNT(nr_shade_64);
209 return lp_scene_bin_cmd_with_state( scene, tx, ty,
210 setup->fs.stored,
211 LP_RAST_OP_SHADE_TILE,
212 lp_rast_arg_inputs(inputs) );
213 }
214 }
215
216
217 /**
218 * Do basic setup for triangle rasterization and determine which
219 * framebuffer tiles are touched. Put the triangle in the scene's
220 * bins for the tiles which we overlap.
221 */
222 static boolean
223 do_triangle_ccw(struct lp_setup_context *setup,
224 const float (*v0)[4],
225 const float (*v1)[4],
226 const float (*v2)[4],
227 boolean frontfacing )
228 {
229 struct lp_scene *scene = setup->scene;
230 struct lp_rast_triangle *tri;
231 int x[3];
232 int y[3];
233 struct u_rect bbox;
234 unsigned tri_bytes;
235 int i;
236 int nr_planes = 3;
237
238 if (0)
239 lp_setup_print_triangle(setup, v0, v1, v2);
240
241 if (setup->scissor_test) {
242 nr_planes = 7;
243 }
244 else {
245 nr_planes = 3;
246 }
247
248 /* x/y positions in fixed point */
249 x[0] = subpixel_snap(v0[0][0] - setup->pixel_offset);
250 x[1] = subpixel_snap(v1[0][0] - setup->pixel_offset);
251 x[2] = subpixel_snap(v2[0][0] - setup->pixel_offset);
252 y[0] = subpixel_snap(v0[0][1] - setup->pixel_offset);
253 y[1] = subpixel_snap(v1[0][1] - setup->pixel_offset);
254 y[2] = subpixel_snap(v2[0][1] - setup->pixel_offset);
255
256
257 /* Bounding rectangle (in pixels) */
258 {
259 /* Yes this is necessary to accurately calculate bounding boxes
260 * with the two fill-conventions we support. GL (normally) ends
261 * up needing a bottom-left fill convention, which requires
262 * slightly different rounding.
263 */
264 int adj = (setup->pixel_offset != 0) ? 1 : 0;
265
266 bbox.x0 = (MIN3(x[0], x[1], x[2]) + (FIXED_ONE-1)) >> FIXED_ORDER;
267 bbox.x1 = (MAX3(x[0], x[1], x[2]) + (FIXED_ONE-1)) >> FIXED_ORDER;
268 bbox.y0 = (MIN3(y[0], y[1], y[2]) + (FIXED_ONE-1) + adj) >> FIXED_ORDER;
269 bbox.y1 = (MAX3(y[0], y[1], y[2]) + (FIXED_ONE-1) + adj) >> FIXED_ORDER;
270
271 /* Inclusive coordinates:
272 */
273 bbox.x1--;
274 bbox.y1--;
275 }
276
277 if (bbox.x1 < bbox.x0 ||
278 bbox.y1 < bbox.y0) {
279 if (0) debug_printf("empty bounding box\n");
280 LP_COUNT(nr_culled_tris);
281 return TRUE;
282 }
283
284 if (!u_rect_test_intersection(&setup->draw_region, &bbox)) {
285 if (0) debug_printf("offscreen\n");
286 LP_COUNT(nr_culled_tris);
287 return TRUE;
288 }
289
290 u_rect_find_intersection(&setup->draw_region, &bbox);
291
292 tri = lp_setup_alloc_triangle(scene,
293 setup->fs.nr_inputs,
294 nr_planes,
295 &tri_bytes);
296 if (!tri)
297 return FALSE;
298
299 #ifdef DEBUG
300 tri->v[0][0] = v0[0][0];
301 tri->v[1][0] = v1[0][0];
302 tri->v[2][0] = v2[0][0];
303 tri->v[0][1] = v0[0][1];
304 tri->v[1][1] = v1[0][1];
305 tri->v[2][1] = v2[0][1];
306 #endif
307
308 tri->plane[0].dcdy = x[0] - x[1];
309 tri->plane[1].dcdy = x[1] - x[2];
310 tri->plane[2].dcdy = x[2] - x[0];
311
312 tri->plane[0].dcdx = y[0] - y[1];
313 tri->plane[1].dcdx = y[1] - y[2];
314 tri->plane[2].dcdx = y[2] - y[0];
315
316 LP_COUNT(nr_tris);
317
318 /* Setup parameter interpolants:
319 */
320 lp_setup_tri_coef( setup, &tri->inputs, v0, v1, v2, frontfacing );
321
322 tri->inputs.facing = frontfacing ? 1.0F : -1.0F;
323 tri->inputs.disable = FALSE;
324 tri->inputs.opaque = setup->fs.current.variant->opaque;
325
326
327 for (i = 0; i < 3; i++) {
328 struct lp_rast_plane *plane = &tri->plane[i];
329
330 /* half-edge constants, will be interated over the whole render
331 * target.
332 */
333 plane->c = plane->dcdx * x[i] - plane->dcdy * y[i];
334
335 /* correct for top-left vs. bottom-left fill convention.
336 *
337 * note that we're overloading gl_rasterization_rules to mean
338 * both (0.5,0.5) pixel centers *and* bottom-left filling
339 * convention.
340 *
341 * GL actually has a top-left filling convention, but GL's
342 * notion of "top" differs from gallium's...
343 *
344 * Also, sometimes (in FBO cases) GL will render upside down
345 * to its usual method, in which case it will probably want
346 * to use the opposite, top-left convention.
347 */
348 if (plane->dcdx < 0) {
349 /* both fill conventions want this - adjust for left edges */
350 plane->c++;
351 }
352 else if (plane->dcdx == 0) {
353 if (setup->pixel_offset == 0) {
354 /* correct for top-left fill convention:
355 */
356 if (plane->dcdy > 0) plane->c++;
357 }
358 else {
359 /* correct for bottom-left fill convention:
360 */
361 if (plane->dcdy < 0) plane->c++;
362 }
363 }
364
365 plane->dcdx *= FIXED_ONE;
366 plane->dcdy *= FIXED_ONE;
367
368 /* find trivial reject offsets for each edge for a single-pixel
369 * sized block. These will be scaled up at each recursive level to
370 * match the active blocksize. Scaling in this way works best if
371 * the blocks are square.
372 */
373 plane->eo = 0;
374 if (plane->dcdx < 0) plane->eo -= plane->dcdx;
375 if (plane->dcdy > 0) plane->eo += plane->dcdy;
376
377 /* Calculate trivial accept offsets from the above.
378 */
379 plane->ei = plane->dcdy - plane->dcdx - plane->eo;
380 }
381
382
383 /*
384 * When rasterizing scissored tris, use the intersection of the
385 * triangle bounding box and the scissor rect to generate the
386 * scissor planes.
387 *
388 * This permits us to cut off the triangle "tails" that are present
389 * in the intermediate recursive levels caused when two of the
390 * triangles edges don't diverge quickly enough to trivially reject
391 * exterior blocks from the triangle.
392 *
393 * It's not really clear if it's worth worrying about these tails,
394 * but since we generate the planes for each scissored tri, it's
395 * free to trim them in this case.
396 *
397 * Note that otherwise, the scissor planes only vary in 'C' value,
398 * and even then only on state-changes. Could alternatively store
399 * these planes elsewhere.
400 */
401 if (nr_planes == 7) {
402 tri->plane[3].dcdx = -1;
403 tri->plane[3].dcdy = 0;
404 tri->plane[3].c = 1-bbox.x0;
405 tri->plane[3].ei = 0;
406 tri->plane[3].eo = 1;
407
408 tri->plane[4].dcdx = 1;
409 tri->plane[4].dcdy = 0;
410 tri->plane[4].c = bbox.x1+1;
411 tri->plane[4].ei = -1;
412 tri->plane[4].eo = 0;
413
414 tri->plane[5].dcdx = 0;
415 tri->plane[5].dcdy = 1;
416 tri->plane[5].c = 1-bbox.y0;
417 tri->plane[5].ei = 0;
418 tri->plane[5].eo = 1;
419
420 tri->plane[6].dcdx = 0;
421 tri->plane[6].dcdy = -1;
422 tri->plane[6].c = bbox.y1+1;
423 tri->plane[6].ei = -1;
424 tri->plane[6].eo = 0;
425 }
426
427 return lp_setup_bin_triangle( setup, tri, &bbox, nr_planes );
428 }
429
430 /*
431 * Round to nearest less or equal power of two of the input.
432 *
433 * Undefined if no bit set exists, so code should check against 0 first.
434 */
435 static INLINE uint32_t
436 floor_pot(uint32_t n)
437 {
438 #if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86)
439 if (n == 0)
440 return 0;
441
442 __asm__("bsr %1,%0"
443 : "=r" (n)
444 : "rm" (n));
445 return 1 << n;
446 #else
447 n |= (n >> 1);
448 n |= (n >> 2);
449 n |= (n >> 4);
450 n |= (n >> 8);
451 n |= (n >> 16);
452 return n - (n >> 1);
453 #endif
454 }
455
456
457 boolean
458 lp_setup_bin_triangle( struct lp_setup_context *setup,
459 struct lp_rast_triangle *tri,
460 const struct u_rect *bbox,
461 int nr_planes )
462 {
463 struct lp_scene *scene = setup->scene;
464 int i;
465
466 /* What is the largest power-of-two boundary this triangle crosses:
467 */
468 int dx = floor_pot((bbox->x0 ^ bbox->x1) |
469 (bbox->y0 ^ bbox->y1));
470
471 /* The largest dimension of the rasterized area of the triangle
472 * (aligned to a 4x4 grid), rounded down to the nearest power of two:
473 */
474 int sz = floor_pot((bbox->x1 - (bbox->x0 & ~3)) |
475 (bbox->y1 - (bbox->y0 & ~3)));
476
477 /* Determine which tile(s) intersect the triangle's bounding box
478 */
479 if (dx < TILE_SIZE)
480 {
481 int ix0 = bbox->x0 / TILE_SIZE;
482 int iy0 = bbox->y0 / TILE_SIZE;
483 int px = bbox->x0 & 63 & ~3;
484 int py = bbox->y0 & 63 & ~3;
485 int mask = px | (py << 8);
486
487 assert(iy0 == bbox->y1 / TILE_SIZE &&
488 ix0 == bbox->x1 / TILE_SIZE);
489
490 if (nr_planes == 3) {
491 if (sz < 4)
492 {
493 /* Triangle is contained in a single 4x4 stamp:
494 */
495 return lp_scene_bin_cmd_with_state( scene, ix0, iy0,
496 setup->fs.stored,
497 LP_RAST_OP_TRIANGLE_3_4,
498 lp_rast_arg_triangle(tri, mask) );
499 }
500
501 if (sz < 16)
502 {
503 /* Triangle is contained in a single 16x16 block:
504 */
505 return lp_scene_bin_cmd_with_state( scene, ix0, iy0,
506 setup->fs.stored,
507 LP_RAST_OP_TRIANGLE_3_16,
508 lp_rast_arg_triangle(tri, mask) );
509 }
510 }
511 else if (nr_planes == 4 && sz < 16)
512 {
513 return lp_scene_bin_cmd_with_state(scene, ix0, iy0,
514 setup->fs.stored,
515 LP_RAST_OP_TRIANGLE_4_16,
516 lp_rast_arg_triangle(tri, mask) );
517 }
518
519
520 /* Triangle is contained in a single tile:
521 */
522 return lp_scene_bin_cmd_with_state( scene, ix0, iy0, setup->fs.stored,
523 lp_rast_tri_tab[nr_planes],
524 lp_rast_arg_triangle(tri, (1<<nr_planes)-1) );
525 }
526 else
527 {
528 int c[MAX_PLANES];
529 int ei[MAX_PLANES];
530 int eo[MAX_PLANES];
531 int xstep[MAX_PLANES];
532 int ystep[MAX_PLANES];
533 int x, y;
534
535 int ix0 = bbox->x0 / TILE_SIZE;
536 int iy0 = bbox->y0 / TILE_SIZE;
537 int ix1 = bbox->x1 / TILE_SIZE;
538 int iy1 = bbox->y1 / TILE_SIZE;
539
540 for (i = 0; i < nr_planes; i++) {
541 c[i] = (tri->plane[i].c +
542 tri->plane[i].dcdy * iy0 * TILE_SIZE -
543 tri->plane[i].dcdx * ix0 * TILE_SIZE);
544
545 ei[i] = tri->plane[i].ei << TILE_ORDER;
546 eo[i] = tri->plane[i].eo << TILE_ORDER;
547 xstep[i] = -(tri->plane[i].dcdx << TILE_ORDER);
548 ystep[i] = tri->plane[i].dcdy << TILE_ORDER;
549 }
550
551
552
553 /* Test tile-sized blocks against the triangle.
554 * Discard blocks fully outside the tri. If the block is fully
555 * contained inside the tri, bin an lp_rast_shade_tile command.
556 * Else, bin a lp_rast_triangle command.
557 */
558 for (y = iy0; y <= iy1; y++)
559 {
560 boolean in = FALSE; /* are we inside the triangle? */
561 int cx[MAX_PLANES];
562
563 for (i = 0; i < nr_planes; i++)
564 cx[i] = c[i];
565
566 for (x = ix0; x <= ix1; x++)
567 {
568 int out = 0;
569 int partial = 0;
570
571 for (i = 0; i < nr_planes; i++) {
572 int planeout = cx[i] + eo[i];
573 int planepartial = cx[i] + ei[i] - 1;
574 out |= (planeout >> 31);
575 partial |= (planepartial >> 31) & (1<<i);
576 }
577
578 if (out) {
579 /* do nothing */
580 if (in)
581 break; /* exiting triangle, all done with this row */
582 LP_COUNT(nr_empty_64);
583 }
584 else if (partial) {
585 /* Not trivially accepted by at least one plane -
586 * rasterize/shade partial tile
587 */
588 int count = util_bitcount(partial);
589 in = TRUE;
590
591 if (!lp_scene_bin_cmd_with_state( scene, x, y,
592 setup->fs.stored,
593 lp_rast_tri_tab[count],
594 lp_rast_arg_triangle(tri, partial) ))
595 goto fail;
596
597 LP_COUNT(nr_partially_covered_64);
598 }
599 else {
600 /* triangle covers the whole tile- shade whole tile */
601 LP_COUNT(nr_fully_covered_64);
602 in = TRUE;
603 if (!lp_setup_whole_tile(setup, &tri->inputs, x, y))
604 goto fail;
605 }
606
607 /* Iterate cx values across the region:
608 */
609 for (i = 0; i < nr_planes; i++)
610 cx[i] += xstep[i];
611 }
612
613 /* Iterate c values down the region:
614 */
615 for (i = 0; i < nr_planes; i++)
616 c[i] += ystep[i];
617 }
618 }
619
620 return TRUE;
621
622 fail:
623 /* Need to disable any partially binned triangle. This is easier
624 * than trying to locate all the triangle, shade-tile, etc,
625 * commands which may have been binned.
626 */
627 tri->inputs.disable = TRUE;
628 return FALSE;
629 }
630
631
632 /**
633 * Try to draw the triangle, restart the scene on failure.
634 */
635 static void retry_triangle_ccw( struct lp_setup_context *setup,
636 const float (*v0)[4],
637 const float (*v1)[4],
638 const float (*v2)[4],
639 boolean front)
640 {
641 if (!do_triangle_ccw( setup, v0, v1, v2, front ))
642 {
643 if (!lp_setup_flush_and_restart(setup))
644 return;
645
646 if (!do_triangle_ccw( setup, v0, v1, v2, front ))
647 return;
648 }
649 }
650
651 static INLINE float
652 calc_area(const float (*v0)[4],
653 const float (*v1)[4],
654 const float (*v2)[4])
655 {
656 float dx01 = v0[0][0] - v1[0][0];
657 float dy01 = v0[0][1] - v1[0][1];
658 float dx20 = v2[0][0] - v0[0][0];
659 float dy20 = v2[0][1] - v0[0][1];
660 return dx01 * dy20 - dx20 * dy01;
661 }
662
663
664 /**
665 * Draw triangle if it's CW, cull otherwise.
666 */
667 static void triangle_cw( struct lp_setup_context *setup,
668 const float (*v0)[4],
669 const float (*v1)[4],
670 const float (*v2)[4] )
671 {
672 float area = calc_area(v0, v1, v2);
673
674 if (area < 0.0f)
675 retry_triangle_ccw(setup, v0, v2, v1, !setup->ccw_is_frontface);
676 }
677
678
679 static void triangle_ccw( struct lp_setup_context *setup,
680 const float (*v0)[4],
681 const float (*v1)[4],
682 const float (*v2)[4])
683 {
684 float area = calc_area(v0, v1, v2);
685
686 if (area > 0.0f)
687 retry_triangle_ccw(setup, v0, v1, v2, setup->ccw_is_frontface);
688 }
689
690 /**
691 * Draw triangle whether it's CW or CCW.
692 */
693 static void triangle_both( struct lp_setup_context *setup,
694 const float (*v0)[4],
695 const float (*v1)[4],
696 const float (*v2)[4] )
697 {
698 float area = calc_area(v0, v1, v2);
699
700 if (area > 0.0f)
701 retry_triangle_ccw( setup, v0, v1, v2, setup->ccw_is_frontface );
702 else if (area < 0.0f)
703 retry_triangle_ccw( setup, v0, v2, v1, !setup->ccw_is_frontface );
704 }
705
706
707 static void triangle_nop( struct lp_setup_context *setup,
708 const float (*v0)[4],
709 const float (*v1)[4],
710 const float (*v2)[4] )
711 {
712 }
713
714
715 void
716 lp_setup_choose_triangle( struct lp_setup_context *setup )
717 {
718 switch (setup->cullmode) {
719 case PIPE_FACE_NONE:
720 setup->triangle = triangle_both;
721 break;
722 case PIPE_FACE_BACK:
723 setup->triangle = setup->ccw_is_frontface ? triangle_ccw : triangle_cw;
724 break;
725 case PIPE_FACE_FRONT:
726 setup->triangle = setup->ccw_is_frontface ? triangle_cw : triangle_ccw;
727 break;
728 default:
729 setup->triangle = triangle_nop;
730 break;
731 }
732 }