llvmpipe: add missing fallthrough comments
[mesa.git] / src / gallium / drivers / llvmpipe / lp_setup_tri.c
1 /**************************************************************************
2 *
3 * Copyright 2007 VMware, Inc.
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 VMWARE 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 "util/u_sse.h"
36 #include "lp_perf.h"
37 #include "lp_setup_context.h"
38 #include "lp_rast.h"
39 #include "lp_state_fs.h"
40 #include "lp_state_setup.h"
41 #include "lp_context.h"
42
43 #include <inttypes.h>
44
45 #define NUM_CHANNELS 4
46
47 #if defined(PIPE_ARCH_SSE)
48 #include <emmintrin.h>
49 #elif defined(_ARCH_PWR8) && UTIL_ARCH_LITTLE_ENDIAN
50 #include <altivec.h>
51 #include "util/u_pwr8.h"
52 #endif
53
54 #if !defined(PIPE_ARCH_SSE)
55
56 static inline int
57 subpixel_snap(float a)
58 {
59 return util_iround(FIXED_ONE * a);
60 }
61
62 #endif
63
64 /* Position and area in fixed point coordinates */
65 struct fixed_position {
66 int32_t x[4];
67 int32_t y[4];
68 int32_t dx01;
69 int32_t dy01;
70 int32_t dx20;
71 int32_t dy20;
72 int64_t area;
73 };
74
75
76 /**
77 * Alloc space for a new triangle plus the input.a0/dadx/dady arrays
78 * immediately after it.
79 * The memory is allocated from the per-scene pool, not per-tile.
80 * \param tri_size returns number of bytes allocated
81 * \param num_inputs number of fragment shader inputs
82 * \return pointer to triangle space
83 */
84 struct lp_rast_triangle *
85 lp_setup_alloc_triangle(struct lp_scene *scene,
86 unsigned nr_inputs,
87 unsigned nr_planes,
88 unsigned *tri_size)
89 {
90 unsigned input_array_sz = NUM_CHANNELS * (nr_inputs + 1) * sizeof(float);
91 unsigned plane_sz = nr_planes * sizeof(struct lp_rast_plane);
92 struct lp_rast_triangle *tri;
93
94 STATIC_ASSERT(sizeof(struct lp_rast_plane) % 8 == 0);
95
96 *tri_size = (sizeof(struct lp_rast_triangle) +
97 3 * input_array_sz +
98 plane_sz);
99
100 tri = lp_scene_alloc_aligned( scene, *tri_size, 16 );
101 if (!tri)
102 return NULL;
103
104 tri->inputs.stride = input_array_sz;
105
106 {
107 char *a = (char *)tri;
108 char *b = (char *)&GET_PLANES(tri)[nr_planes];
109 assert(b - a == *tri_size);
110 }
111
112 return tri;
113 }
114
115 void
116 lp_setup_print_vertex(struct lp_setup_context *setup,
117 const char *name,
118 const float (*v)[4])
119 {
120 const struct lp_setup_variant_key *key = &setup->setup.variant->key;
121 int i, j;
122
123 debug_printf(" wpos (%s[0]) xyzw %f %f %f %f\n",
124 name,
125 v[0][0], v[0][1], v[0][2], v[0][3]);
126
127 for (i = 0; i < key->num_inputs; i++) {
128 const float *in = v[key->inputs[i].src_index];
129
130 debug_printf(" in[%d] (%s[%d]) %s%s%s%s ",
131 i,
132 name, key->inputs[i].src_index,
133 (key->inputs[i].usage_mask & 0x1) ? "x" : " ",
134 (key->inputs[i].usage_mask & 0x2) ? "y" : " ",
135 (key->inputs[i].usage_mask & 0x4) ? "z" : " ",
136 (key->inputs[i].usage_mask & 0x8) ? "w" : " ");
137
138 for (j = 0; j < 4; j++)
139 if (key->inputs[i].usage_mask & (1<<j))
140 debug_printf("%.5f ", in[j]);
141
142 debug_printf("\n");
143 }
144 }
145
146
147 /**
148 * Print triangle vertex attribs (for debug).
149 */
150 void
151 lp_setup_print_triangle(struct lp_setup_context *setup,
152 const float (*v0)[4],
153 const float (*v1)[4],
154 const float (*v2)[4])
155 {
156 debug_printf("triangle\n");
157
158 {
159 const float ex = v0[0][0] - v2[0][0];
160 const float ey = v0[0][1] - v2[0][1];
161 const float fx = v1[0][0] - v2[0][0];
162 const float fy = v1[0][1] - v2[0][1];
163
164 /* det = cross(e,f).z */
165 const float det = ex * fy - ey * fx;
166 if (det < 0.0f)
167 debug_printf(" - ccw\n");
168 else if (det > 0.0f)
169 debug_printf(" - cw\n");
170 else
171 debug_printf(" - zero area\n");
172 }
173
174 lp_setup_print_vertex(setup, "v0", v0);
175 lp_setup_print_vertex(setup, "v1", v1);
176 lp_setup_print_vertex(setup, "v2", v2);
177 }
178
179
180 #define MAX_PLANES 8
181 static unsigned
182 lp_rast_tri_tab[MAX_PLANES+1] = {
183 0, /* should be impossible */
184 LP_RAST_OP_TRIANGLE_1,
185 LP_RAST_OP_TRIANGLE_2,
186 LP_RAST_OP_TRIANGLE_3,
187 LP_RAST_OP_TRIANGLE_4,
188 LP_RAST_OP_TRIANGLE_5,
189 LP_RAST_OP_TRIANGLE_6,
190 LP_RAST_OP_TRIANGLE_7,
191 LP_RAST_OP_TRIANGLE_8
192 };
193
194 static unsigned
195 lp_rast_32_tri_tab[MAX_PLANES+1] = {
196 0, /* should be impossible */
197 LP_RAST_OP_TRIANGLE_32_1,
198 LP_RAST_OP_TRIANGLE_32_2,
199 LP_RAST_OP_TRIANGLE_32_3,
200 LP_RAST_OP_TRIANGLE_32_4,
201 LP_RAST_OP_TRIANGLE_32_5,
202 LP_RAST_OP_TRIANGLE_32_6,
203 LP_RAST_OP_TRIANGLE_32_7,
204 LP_RAST_OP_TRIANGLE_32_8
205 };
206
207 static unsigned
208 lp_rast_ms_tri_tab[MAX_PLANES+1] = {
209 0, /* should be impossible */
210 LP_RAST_OP_MS_TRIANGLE_1,
211 LP_RAST_OP_MS_TRIANGLE_2,
212 LP_RAST_OP_MS_TRIANGLE_3,
213 LP_RAST_OP_MS_TRIANGLE_4,
214 LP_RAST_OP_MS_TRIANGLE_5,
215 LP_RAST_OP_MS_TRIANGLE_6,
216 LP_RAST_OP_MS_TRIANGLE_7,
217 LP_RAST_OP_MS_TRIANGLE_8
218 };
219
220 /**
221 * The primitive covers the whole tile- shade whole tile.
222 *
223 * \param tx, ty the tile position in tiles, not pixels
224 */
225 static boolean
226 lp_setup_whole_tile(struct lp_setup_context *setup,
227 const struct lp_rast_shader_inputs *inputs,
228 int tx, int ty)
229 {
230 struct lp_scene *scene = setup->scene;
231
232 LP_COUNT(nr_fully_covered_64);
233
234 /* if variant is opaque and scissor doesn't effect the tile */
235 if (inputs->opaque) {
236 /* Several things prevent this optimization from working:
237 * - For layered rendering we can't determine if this covers the same layer
238 * as previous rendering (or in case of clears those actually always cover
239 * all layers so optimization is impossible). Need to use fb_max_layer and
240 * not setup->layer_slot to determine this since even if there's currently
241 * no slot assigned previous rendering could have used one.
242 * - If there were any Begin/End query commands in the scene then those
243 * would get removed which would be very wrong. Furthermore, if queries
244 * were just active we also can't do the optimization since to get
245 * accurate query results we unfortunately need to execute the rendering
246 * commands.
247 */
248 if (!scene->fb.zsbuf && scene->fb_max_layer == 0 && !scene->had_queries) {
249 /*
250 * All previous rendering will be overwritten so reset the bin.
251 */
252 lp_scene_bin_reset( scene, tx, ty );
253 }
254
255 LP_COUNT(nr_shade_opaque_64);
256 return lp_scene_bin_cmd_with_state( scene, tx, ty,
257 setup->fs.stored,
258 LP_RAST_OP_SHADE_TILE_OPAQUE,
259 lp_rast_arg_inputs(inputs) );
260 } else {
261 LP_COUNT(nr_shade_64);
262 return lp_scene_bin_cmd_with_state( scene, tx, ty,
263 setup->fs.stored,
264 LP_RAST_OP_SHADE_TILE,
265 lp_rast_arg_inputs(inputs) );
266 }
267 }
268
269
270 /**
271 * Do basic setup for triangle rasterization and determine which
272 * framebuffer tiles are touched. Put the triangle in the scene's
273 * bins for the tiles which we overlap.
274 */
275 static boolean
276 do_triangle_ccw(struct lp_setup_context *setup,
277 struct fixed_position* position,
278 const float (*v0)[4],
279 const float (*v1)[4],
280 const float (*v2)[4],
281 boolean frontfacing )
282 {
283 struct lp_scene *scene = setup->scene;
284 const struct lp_setup_variant_key *key = &setup->setup.variant->key;
285 struct lp_rast_triangle *tri;
286 struct lp_rast_plane *plane;
287 const struct u_rect *scissor = NULL;
288 struct u_rect bbox, bboxpos;
289 boolean s_planes[4];
290 unsigned tri_bytes;
291 int nr_planes = 3;
292 unsigned viewport_index = 0;
293 unsigned layer = 0;
294 const float (*pv)[4];
295
296 /* Area should always be positive here */
297 assert(position->area > 0);
298
299 if (0)
300 lp_setup_print_triangle(setup, v0, v1, v2);
301
302 if (setup->flatshade_first) {
303 pv = v0;
304 }
305 else {
306 pv = v2;
307 }
308 if (setup->viewport_index_slot > 0) {
309 unsigned *udata = (unsigned*)pv[setup->viewport_index_slot];
310 viewport_index = lp_clamp_viewport_idx(*udata);
311 }
312 if (setup->layer_slot > 0) {
313 layer = *(unsigned*)pv[setup->layer_slot];
314 layer = MIN2(layer, scene->fb_max_layer);
315 }
316
317 /* Bounding rectangle (in pixels) */
318 {
319 /* Yes this is necessary to accurately calculate bounding boxes
320 * with the two fill-conventions we support. GL (normally) ends
321 * up needing a bottom-left fill convention, which requires
322 * slightly different rounding.
323 */
324 int adj = (setup->bottom_edge_rule != 0) ? 1 : 0;
325
326 /* Inclusive x0, exclusive x1 */
327 bbox.x0 = MIN3(position->x[0], position->x[1], position->x[2]) >> FIXED_ORDER;
328 bbox.x1 = (MAX3(position->x[0], position->x[1], position->x[2]) - 1) >> FIXED_ORDER;
329
330 /* Inclusive / exclusive depending upon adj (bottom-left or top-right) */
331 bbox.y0 = (MIN3(position->y[0], position->y[1], position->y[2]) + adj) >> FIXED_ORDER;
332 bbox.y1 = (MAX3(position->y[0], position->y[1], position->y[2]) - 1 + adj) >> FIXED_ORDER;
333 }
334
335 if (bbox.x1 < bbox.x0 ||
336 bbox.y1 < bbox.y0) {
337 if (0) debug_printf("empty bounding box\n");
338 LP_COUNT(nr_culled_tris);
339 return TRUE;
340 }
341
342 if (!u_rect_test_intersection(&setup->draw_regions[viewport_index], &bbox)) {
343 if (0) debug_printf("offscreen\n");
344 LP_COUNT(nr_culled_tris);
345 return TRUE;
346 }
347
348 bboxpos = bbox;
349
350 /* Can safely discard negative regions, but need to keep hold of
351 * information about when the triangle extends past screen
352 * boundaries. See trimmed_box in lp_setup_bin_triangle().
353 */
354 bboxpos.x0 = MAX2(bboxpos.x0, 0);
355 bboxpos.y0 = MAX2(bboxpos.y0, 0);
356
357 nr_planes = 3;
358 /*
359 * Determine how many scissor planes we need, that is drop scissor
360 * edges if the bounding box of the tri is fully inside that edge.
361 */
362 if (setup->scissor_test) {
363 /* why not just use draw_regions */
364 scissor = &setup->scissors[viewport_index];
365 scissor_planes_needed(s_planes, &bboxpos, scissor);
366 nr_planes += s_planes[0] + s_planes[1] + s_planes[2] + s_planes[3];
367 } else {
368 scissor = &setup->draw_regions[viewport_index];
369 scissor_planes_needed(s_planes, &bboxpos, scissor);
370 nr_planes += s_planes[0] + s_planes[1] + s_planes[2] + s_planes[3];
371 }
372
373 tri = lp_setup_alloc_triangle(scene,
374 key->num_inputs,
375 nr_planes,
376 &tri_bytes);
377 if (!tri)
378 return FALSE;
379
380 #ifdef DEBUG
381 tri->v[0][0] = v0[0][0];
382 tri->v[1][0] = v1[0][0];
383 tri->v[2][0] = v2[0][0];
384 tri->v[0][1] = v0[0][1];
385 tri->v[1][1] = v1[0][1];
386 tri->v[2][1] = v2[0][1];
387 #endif
388
389 LP_COUNT(nr_tris);
390
391 /* Setup parameter interpolants:
392 */
393 setup->setup.variant->jit_function(v0, v1, v2,
394 frontfacing,
395 GET_A0(&tri->inputs),
396 GET_DADX(&tri->inputs),
397 GET_DADY(&tri->inputs));
398
399 tri->inputs.frontfacing = frontfacing;
400 tri->inputs.disable = FALSE;
401 tri->inputs.opaque = setup->fs.current.variant->opaque;
402 tri->inputs.layer = layer;
403 tri->inputs.viewport_index = viewport_index;
404
405 if (0)
406 lp_dump_setup_coef(&setup->setup.variant->key,
407 (const float (*)[4])GET_A0(&tri->inputs),
408 (const float (*)[4])GET_DADX(&tri->inputs),
409 (const float (*)[4])GET_DADY(&tri->inputs));
410
411 plane = GET_PLANES(tri);
412
413 #if defined(PIPE_ARCH_SSE)
414 if (1) {
415 __m128i vertx, verty;
416 __m128i shufx, shufy;
417 __m128i dcdx, dcdy;
418 __m128i cdx02, cdx13, cdy02, cdy13, c02, c13;
419 __m128i c01, c23, unused;
420 __m128i dcdx_neg_mask;
421 __m128i dcdy_neg_mask;
422 __m128i dcdx_zero_mask;
423 __m128i top_left_flag, c_dec;
424 __m128i eo, p0, p1, p2;
425 __m128i zero = _mm_setzero_si128();
426
427 vertx = _mm_load_si128((__m128i *)position->x); /* vertex x coords */
428 verty = _mm_load_si128((__m128i *)position->y); /* vertex y coords */
429
430 shufx = _mm_shuffle_epi32(vertx, _MM_SHUFFLE(3,0,2,1));
431 shufy = _mm_shuffle_epi32(verty, _MM_SHUFFLE(3,0,2,1));
432
433 dcdx = _mm_sub_epi32(verty, shufy);
434 dcdy = _mm_sub_epi32(vertx, shufx);
435
436 dcdx_neg_mask = _mm_srai_epi32(dcdx, 31);
437 dcdx_zero_mask = _mm_cmpeq_epi32(dcdx, zero);
438 dcdy_neg_mask = _mm_srai_epi32(dcdy, 31);
439
440 top_left_flag = _mm_set1_epi32((setup->bottom_edge_rule == 0) ? ~0 : 0);
441
442 c_dec = _mm_or_si128(dcdx_neg_mask,
443 _mm_and_si128(dcdx_zero_mask,
444 _mm_xor_si128(dcdy_neg_mask,
445 top_left_flag)));
446
447 /*
448 * 64 bit arithmetic.
449 * Note we need _signed_ mul (_mm_mul_epi32) which we emulate.
450 */
451 cdx02 = mm_mullohi_epi32(dcdx, vertx, &cdx13);
452 cdy02 = mm_mullohi_epi32(dcdy, verty, &cdy13);
453 c02 = _mm_sub_epi64(cdx02, cdy02);
454 c13 = _mm_sub_epi64(cdx13, cdy13);
455 c02 = _mm_sub_epi64(c02, _mm_shuffle_epi32(c_dec,
456 _MM_SHUFFLE(2,2,0,0)));
457 c13 = _mm_sub_epi64(c13, _mm_shuffle_epi32(c_dec,
458 _MM_SHUFFLE(3,3,1,1)));
459
460 /*
461 * Useful for very small fbs/tris (or fewer subpixel bits) only:
462 * c = _mm_sub_epi32(mm_mullo_epi32(dcdx, vertx),
463 * mm_mullo_epi32(dcdy, verty));
464 *
465 * c = _mm_sub_epi32(c, c_dec);
466 */
467
468 /* Scale up to match c:
469 */
470 dcdx = _mm_slli_epi32(dcdx, FIXED_ORDER);
471 dcdy = _mm_slli_epi32(dcdy, FIXED_ORDER);
472
473 /*
474 * Calculate trivial reject values:
475 * Note eo cannot overflow even if dcdx/dcdy would already have
476 * 31 bits (which they shouldn't have). This is because eo
477 * is never negative (albeit if we rely on that need to be careful...)
478 */
479 eo = _mm_sub_epi32(_mm_andnot_si128(dcdy_neg_mask, dcdy),
480 _mm_and_si128(dcdx_neg_mask, dcdx));
481
482 /* ei = _mm_sub_epi32(_mm_sub_epi32(dcdy, dcdx), eo); */
483
484 /*
485 * Pointless transpose which gets undone immediately in
486 * rasterization.
487 * It is actually difficult to do away with it - would essentially
488 * need GET_PLANES_DX, GET_PLANES_DY etc., but the calculations
489 * for this then would need to depend on the number of planes.
490 * The transpose is quite special here due to c being 64bit...
491 * The store has to be unaligned (unless we'd make the plane size
492 * a multiple of 128), and of course storing eo separately...
493 */
494 c01 = _mm_unpacklo_epi64(c02, c13);
495 c23 = _mm_unpackhi_epi64(c02, c13);
496 transpose2_64_2_32(&c01, &c23, &dcdx, &dcdy,
497 &p0, &p1, &p2, &unused);
498 _mm_storeu_si128((__m128i *)&plane[0], p0);
499 plane[0].eo = (uint32_t)_mm_cvtsi128_si32(eo);
500 _mm_storeu_si128((__m128i *)&plane[1], p1);
501 eo = _mm_shuffle_epi32(eo, _MM_SHUFFLE(3,2,0,1));
502 plane[1].eo = (uint32_t)_mm_cvtsi128_si32(eo);
503 _mm_storeu_si128((__m128i *)&plane[2], p2);
504 eo = _mm_shuffle_epi32(eo, _MM_SHUFFLE(0,0,0,2));
505 plane[2].eo = (uint32_t)_mm_cvtsi128_si32(eo);
506 } else
507 #elif defined(_ARCH_PWR8) && UTIL_ARCH_LITTLE_ENDIAN
508 /*
509 * XXX this code is effectively disabled for all practical purposes,
510 * as the allowed fb size is tiny if FIXED_ORDER is 8.
511 */
512 if (setup->fb.width <= MAX_FIXED_LENGTH32 &&
513 setup->fb.height <= MAX_FIXED_LENGTH32 &&
514 (bbox.x1 - bbox.x0) <= MAX_FIXED_LENGTH32 &&
515 (bbox.y1 - bbox.y0) <= MAX_FIXED_LENGTH32) {
516 unsigned int bottom_edge;
517 __m128i vertx, verty;
518 __m128i shufx, shufy;
519 __m128i dcdx, dcdy, c;
520 __m128i unused;
521 __m128i dcdx_neg_mask;
522 __m128i dcdy_neg_mask;
523 __m128i dcdx_zero_mask;
524 __m128i top_left_flag;
525 __m128i c_inc_mask, c_inc;
526 __m128i eo, p0, p1, p2;
527 __m128i_union vshuf_mask;
528 __m128i zero = vec_splats((unsigned char) 0);
529 PIPE_ALIGN_VAR(16) int32_t temp_vec[4];
530
531 #if UTIL_ARCH_LITTLE_ENDIAN
532 vshuf_mask.i[0] = 0x07060504;
533 vshuf_mask.i[1] = 0x0B0A0908;
534 vshuf_mask.i[2] = 0x03020100;
535 vshuf_mask.i[3] = 0x0F0E0D0C;
536 #else
537 vshuf_mask.i[0] = 0x00010203;
538 vshuf_mask.i[1] = 0x0C0D0E0F;
539 vshuf_mask.i[2] = 0x04050607;
540 vshuf_mask.i[3] = 0x08090A0B;
541 #endif
542
543 /* vertex x coords */
544 vertx = vec_load_si128((const uint32_t *) position->x);
545 /* vertex y coords */
546 verty = vec_load_si128((const uint32_t *) position->y);
547
548 shufx = vec_perm (vertx, vertx, vshuf_mask.m128i);
549 shufy = vec_perm (verty, verty, vshuf_mask.m128i);
550
551 dcdx = vec_sub_epi32(verty, shufy);
552 dcdy = vec_sub_epi32(vertx, shufx);
553
554 dcdx_neg_mask = vec_srai_epi32(dcdx, 31);
555 dcdx_zero_mask = vec_cmpeq_epi32(dcdx, zero);
556 dcdy_neg_mask = vec_srai_epi32(dcdy, 31);
557
558 bottom_edge = (setup->bottom_edge_rule == 0) ? ~0 : 0;
559 top_left_flag = (__m128i) vec_splats(bottom_edge);
560
561 c_inc_mask = vec_or(dcdx_neg_mask,
562 vec_and(dcdx_zero_mask,
563 vec_xor(dcdy_neg_mask,
564 top_left_flag)));
565
566 c_inc = vec_srli_epi32(c_inc_mask, 31);
567
568 c = vec_sub_epi32(vec_mullo_epi32(dcdx, vertx),
569 vec_mullo_epi32(dcdy, verty));
570
571 c = vec_add_epi32(c, c_inc);
572
573 /* Scale up to match c:
574 */
575 dcdx = vec_slli_epi32(dcdx, FIXED_ORDER);
576 dcdy = vec_slli_epi32(dcdy, FIXED_ORDER);
577
578 /* Calculate trivial reject values:
579 */
580 eo = vec_sub_epi32(vec_andnot_si128(dcdy_neg_mask, dcdy),
581 vec_and(dcdx_neg_mask, dcdx));
582
583 /* ei = _mm_sub_epi32(_mm_sub_epi32(dcdy, dcdx), eo); */
584
585 /* Pointless transpose which gets undone immediately in
586 * rasterization:
587 */
588 transpose4_epi32(&c, &dcdx, &dcdy, &eo,
589 &p0, &p1, &p2, &unused);
590
591 #define STORE_PLANE(plane, vec) do { \
592 vec_store_si128((uint32_t *)&temp_vec, vec); \
593 plane.c = (int64_t)temp_vec[0]; \
594 plane.dcdx = temp_vec[1]; \
595 plane.dcdy = temp_vec[2]; \
596 plane.eo = temp_vec[3]; \
597 } while(0)
598
599 STORE_PLANE(plane[0], p0);
600 STORE_PLANE(plane[1], p1);
601 STORE_PLANE(plane[2], p2);
602 #undef STORE_PLANE
603 } else
604 #endif
605 {
606 int i;
607 plane[0].dcdy = position->dx01;
608 plane[1].dcdy = position->x[1] - position->x[2];
609 plane[2].dcdy = position->dx20;
610 plane[0].dcdx = position->dy01;
611 plane[1].dcdx = position->y[1] - position->y[2];
612 plane[2].dcdx = position->dy20;
613
614 for (i = 0; i < 3; i++) {
615 /* half-edge constants, will be iterated over the whole render
616 * target.
617 */
618 plane[i].c = IMUL64(plane[i].dcdx, position->x[i]) -
619 IMUL64(plane[i].dcdy, position->y[i]);
620
621 /* correct for top-left vs. bottom-left fill convention.
622 */
623 if (plane[i].dcdx < 0) {
624 /* both fill conventions want this - adjust for left edges */
625 plane[i].c++;
626 }
627 else if (plane[i].dcdx == 0) {
628 if (setup->bottom_edge_rule == 0){
629 /* correct for top-left fill convention:
630 */
631 if (plane[i].dcdy > 0) plane[i].c++;
632 }
633 else {
634 /* correct for bottom-left fill convention:
635 */
636 if (plane[i].dcdy < 0) plane[i].c++;
637 }
638 }
639
640 /* Scale up to match c:
641 */
642 assert((plane[i].dcdx << FIXED_ORDER) >> FIXED_ORDER == plane[i].dcdx);
643 assert((plane[i].dcdy << FIXED_ORDER) >> FIXED_ORDER == plane[i].dcdy);
644 plane[i].dcdx <<= FIXED_ORDER;
645 plane[i].dcdy <<= FIXED_ORDER;
646
647 /* find trivial reject offsets for each edge for a single-pixel
648 * sized block. These will be scaled up at each recursive level to
649 * match the active blocksize. Scaling in this way works best if
650 * the blocks are square.
651 */
652 plane[i].eo = 0;
653 if (plane[i].dcdx < 0) plane[i].eo -= plane[i].dcdx;
654 if (plane[i].dcdy > 0) plane[i].eo += plane[i].dcdy;
655 }
656 }
657
658 if (0) {
659 debug_printf("p0: %"PRIx64"/%08x/%08x/%08x\n",
660 plane[0].c,
661 plane[0].dcdx,
662 plane[0].dcdy,
663 plane[0].eo);
664
665 debug_printf("p1: %"PRIx64"/%08x/%08x/%08x\n",
666 plane[1].c,
667 plane[1].dcdx,
668 plane[1].dcdy,
669 plane[1].eo);
670
671 debug_printf("p2: %"PRIx64"/%08x/%08x/%08x\n",
672 plane[2].c,
673 plane[2].dcdx,
674 plane[2].dcdy,
675 plane[2].eo);
676 }
677
678
679 /*
680 * When rasterizing scissored tris, use the intersection of the
681 * triangle bounding box and the scissor rect to generate the
682 * scissor planes.
683 *
684 * This permits us to cut off the triangle "tails" that are present
685 * in the intermediate recursive levels caused when two of the
686 * triangles edges don't diverge quickly enough to trivially reject
687 * exterior blocks from the triangle.
688 *
689 * It's not really clear if it's worth worrying about these tails,
690 * but since we generate the planes for each scissored tri, it's
691 * free to trim them in this case.
692 *
693 * Note that otherwise, the scissor planes only vary in 'C' value,
694 * and even then only on state-changes. Could alternatively store
695 * these planes elsewhere.
696 * (Or only store the c value together with a bit indicating which
697 * scissor edge this is, so rasterization would treat them differently
698 * (easier to evaluate) to ordinary planes.)
699 */
700 if (nr_planes > 3) {
701 /* why not just use draw_regions */
702 struct lp_rast_plane *plane_s = &plane[3];
703
704 if (s_planes[0]) {
705 plane_s->dcdx = ~0U << 8;
706 plane_s->dcdy = 0;
707 plane_s->c = (1-scissor->x0) << 8;
708 plane_s->eo = 1 << 8;
709 plane_s++;
710 }
711 if (s_planes[1]) {
712 plane_s->dcdx = 1 << 8;
713 plane_s->dcdy = 0;
714 plane_s->c = (scissor->x1+1) << 8;
715 plane_s->eo = 0 << 8;
716 plane_s++;
717 }
718 if (s_planes[2]) {
719 plane_s->dcdx = 0;
720 plane_s->dcdy = 1 << 8;
721 plane_s->c = (1-scissor->y0) << 8;
722 plane_s->eo = 1 << 8;
723 plane_s++;
724 }
725 if (s_planes[3]) {
726 plane_s->dcdx = 0;
727 plane_s->dcdy = ~0U << 8;
728 plane_s->c = (scissor->y1+1) << 8;
729 plane_s->eo = 0;
730 plane_s++;
731 }
732 assert(plane_s == &plane[nr_planes]);
733 }
734
735 return lp_setup_bin_triangle(setup, tri, &bbox, &bboxpos, nr_planes, viewport_index);
736 }
737
738 /*
739 * Round to nearest less or equal power of two of the input.
740 *
741 * Undefined if no bit set exists, so code should check against 0 first.
742 */
743 static inline uint32_t
744 floor_pot(uint32_t n)
745 {
746 #if defined(PIPE_CC_GCC) && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64))
747 if (n == 0)
748 return 0;
749
750 __asm__("bsr %1,%0"
751 : "=r" (n)
752 : "rm" (n)
753 : "cc");
754 return 1 << n;
755 #else
756 n |= (n >> 1);
757 n |= (n >> 2);
758 n |= (n >> 4);
759 n |= (n >> 8);
760 n |= (n >> 16);
761 return n - (n >> 1);
762 #endif
763 }
764
765
766 boolean
767 lp_setup_bin_triangle(struct lp_setup_context *setup,
768 struct lp_rast_triangle *tri,
769 const struct u_rect *bboxorig,
770 const struct u_rect *bbox,
771 int nr_planes,
772 unsigned viewport_index)
773 {
774 struct lp_scene *scene = setup->scene;
775 struct u_rect trimmed_box = *bbox;
776 int i;
777 unsigned cmd;
778
779 /* What is the largest power-of-two boundary this triangle crosses:
780 */
781 int dx = floor_pot((bbox->x0 ^ bbox->x1) |
782 (bbox->y0 ^ bbox->y1));
783
784 /* The largest dimension of the rasterized area of the triangle
785 * (aligned to a 4x4 grid), rounded down to the nearest power of two:
786 */
787 int max_sz = ((bbox->x1 - (bbox->x0 & ~3)) |
788 (bbox->y1 - (bbox->y0 & ~3)));
789 int sz = floor_pot(max_sz);
790
791 /*
792 * NOTE: It is important to use the original bounding box
793 * which might contain negative values here, because if the
794 * plane math may overflow or not with the 32bit rasterization
795 * functions depends on the original extent of the triangle.
796 */
797 int max_szorig = ((bboxorig->x1 - (bboxorig->x0 & ~3)) |
798 (bboxorig->y1 - (bboxorig->y0 & ~3)));
799 boolean use_32bits = max_szorig <= MAX_FIXED_LENGTH32;
800
801 /* Now apply scissor, etc to the bounding box. Could do this
802 * earlier, but it confuses the logic for tri-16 and would force
803 * the rasterizer to also respect scissor, etc, just for the rare
804 * cases where a small triangle extends beyond the scissor.
805 */
806 u_rect_find_intersection(&setup->draw_regions[viewport_index],
807 &trimmed_box);
808
809 /* Determine which tile(s) intersect the triangle's bounding box
810 */
811 if (dx < TILE_SIZE)
812 {
813 int ix0 = bbox->x0 / TILE_SIZE;
814 int iy0 = bbox->y0 / TILE_SIZE;
815 unsigned px = bbox->x0 & 63 & ~3;
816 unsigned py = bbox->y0 & 63 & ~3;
817
818 assert(iy0 == bbox->y1 / TILE_SIZE &&
819 ix0 == bbox->x1 / TILE_SIZE);
820
821 if (nr_planes == 3) {
822 if (sz < 4)
823 {
824 /* Triangle is contained in a single 4x4 stamp:
825 */
826 assert(px + 4 <= TILE_SIZE);
827 assert(py + 4 <= TILE_SIZE);
828 if (setup->multisample)
829 cmd = LP_RAST_OP_MS_TRIANGLE_3_4;
830 else
831 cmd = use_32bits ? LP_RAST_OP_TRIANGLE_32_3_4 : LP_RAST_OP_TRIANGLE_3_4;
832 return lp_scene_bin_cmd_with_state( scene, ix0, iy0,
833 setup->fs.stored, cmd,
834 lp_rast_arg_triangle_contained(tri, px, py) );
835 }
836
837 if (sz < 16)
838 {
839 /* Triangle is contained in a single 16x16 block:
840 */
841
842 /*
843 * The 16x16 block is only 4x4 aligned, and can exceed the tile
844 * dimensions if the triangle is 16 pixels in one dimension but 4
845 * in the other. So budge the 16x16 back inside the tile.
846 */
847 px = MIN2(px, TILE_SIZE - 16);
848 py = MIN2(py, TILE_SIZE - 16);
849
850 assert(px + 16 <= TILE_SIZE);
851 assert(py + 16 <= TILE_SIZE);
852
853 if (setup->multisample)
854 cmd = LP_RAST_OP_MS_TRIANGLE_3_16;
855 else
856 cmd = use_32bits ? LP_RAST_OP_TRIANGLE_32_3_16 : LP_RAST_OP_TRIANGLE_3_16;
857 return lp_scene_bin_cmd_with_state( scene, ix0, iy0,
858 setup->fs.stored, cmd,
859 lp_rast_arg_triangle_contained(tri, px, py) );
860 }
861 }
862 else if (nr_planes == 4 && sz < 16)
863 {
864 px = MIN2(px, TILE_SIZE - 16);
865 py = MIN2(py, TILE_SIZE - 16);
866
867 assert(px + 16 <= TILE_SIZE);
868 assert(py + 16 <= TILE_SIZE);
869
870 if (setup->multisample)
871 cmd = LP_RAST_OP_MS_TRIANGLE_4_16;
872 else
873 cmd = use_32bits ? LP_RAST_OP_TRIANGLE_32_4_16 : LP_RAST_OP_TRIANGLE_4_16;
874 return lp_scene_bin_cmd_with_state(scene, ix0, iy0,
875 setup->fs.stored, cmd,
876 lp_rast_arg_triangle_contained(tri, px, py));
877 }
878
879
880 /* Triangle is contained in a single tile:
881 */
882 if (setup->multisample)
883 cmd = lp_rast_ms_tri_tab[nr_planes];
884 else
885 cmd = use_32bits ? lp_rast_32_tri_tab[nr_planes] : lp_rast_tri_tab[nr_planes];
886 return lp_scene_bin_cmd_with_state(
887 scene, ix0, iy0, setup->fs.stored, cmd,
888 lp_rast_arg_triangle(tri, (1<<nr_planes)-1));
889 }
890 else
891 {
892 struct lp_rast_plane *plane = GET_PLANES(tri);
893 int64_t c[MAX_PLANES];
894 int64_t ei[MAX_PLANES];
895
896 int64_t eo[MAX_PLANES];
897 int64_t xstep[MAX_PLANES];
898 int64_t ystep[MAX_PLANES];
899 int x, y;
900
901 int ix0 = trimmed_box.x0 / TILE_SIZE;
902 int iy0 = trimmed_box.y0 / TILE_SIZE;
903 int ix1 = trimmed_box.x1 / TILE_SIZE;
904 int iy1 = trimmed_box.y1 / TILE_SIZE;
905
906 for (i = 0; i < nr_planes; i++) {
907 c[i] = (plane[i].c +
908 IMUL64(plane[i].dcdy, iy0) * TILE_SIZE -
909 IMUL64(plane[i].dcdx, ix0) * TILE_SIZE);
910
911 ei[i] = (plane[i].dcdy -
912 plane[i].dcdx -
913 (int64_t)plane[i].eo) << TILE_ORDER;
914
915 eo[i] = (int64_t)plane[i].eo << TILE_ORDER;
916 xstep[i] = -(((int64_t)plane[i].dcdx) << TILE_ORDER);
917 ystep[i] = ((int64_t)plane[i].dcdy) << TILE_ORDER;
918 }
919
920
921
922 /* Test tile-sized blocks against the triangle.
923 * Discard blocks fully outside the tri. If the block is fully
924 * contained inside the tri, bin an lp_rast_shade_tile command.
925 * Else, bin a lp_rast_triangle command.
926 */
927 for (y = iy0; y <= iy1; y++)
928 {
929 boolean in = FALSE; /* are we inside the triangle? */
930 int64_t cx[MAX_PLANES];
931
932 for (i = 0; i < nr_planes; i++)
933 cx[i] = c[i];
934
935 for (x = ix0; x <= ix1; x++)
936 {
937 int out = 0;
938 int partial = 0;
939
940 for (i = 0; i < nr_planes; i++) {
941 int64_t planeout = cx[i] + eo[i];
942 int64_t planepartial = cx[i] + ei[i] - 1;
943 out |= (int) (planeout >> 63);
944 partial |= ((int) (planepartial >> 63)) & (1<<i);
945 }
946
947 if (out) {
948 /* do nothing */
949 if (in)
950 break; /* exiting triangle, all done with this row */
951 LP_COUNT(nr_empty_64);
952 }
953 else if (partial) {
954 /* Not trivially accepted by at least one plane -
955 * rasterize/shade partial tile
956 */
957 int count = util_bitcount(partial);
958 in = TRUE;
959
960 if (setup->multisample)
961 cmd = lp_rast_ms_tri_tab[count];
962 else
963 cmd = use_32bits ? lp_rast_32_tri_tab[count] : lp_rast_tri_tab[count];
964 if (!lp_scene_bin_cmd_with_state( scene, x, y,
965 setup->fs.stored, cmd,
966 lp_rast_arg_triangle(tri, partial) ))
967 goto fail;
968
969 LP_COUNT(nr_partially_covered_64);
970 }
971 else {
972 /* triangle covers the whole tile- shade whole tile */
973 LP_COUNT(nr_fully_covered_64);
974 in = TRUE;
975 if (!lp_setup_whole_tile(setup, &tri->inputs, x, y))
976 goto fail;
977 }
978
979 /* Iterate cx values across the region: */
980 for (i = 0; i < nr_planes; i++)
981 cx[i] += xstep[i];
982 }
983
984 /* Iterate c values down the region: */
985 for (i = 0; i < nr_planes; i++)
986 c[i] += ystep[i];
987 }
988 }
989
990 return TRUE;
991
992 fail:
993 /* Need to disable any partially binned triangle. This is easier
994 * than trying to locate all the triangle, shade-tile, etc,
995 * commands which may have been binned.
996 */
997 tri->inputs.disable = TRUE;
998 return FALSE;
999 }
1000
1001
1002 /**
1003 * Try to draw the triangle, restart the scene on failure.
1004 */
1005 static void retry_triangle_ccw( struct lp_setup_context *setup,
1006 struct fixed_position* position,
1007 const float (*v0)[4],
1008 const float (*v1)[4],
1009 const float (*v2)[4],
1010 boolean front)
1011 {
1012 if (!do_triangle_ccw( setup, position, v0, v1, v2, front ))
1013 {
1014 if (!lp_setup_flush_and_restart(setup))
1015 return;
1016
1017 if (!do_triangle_ccw( setup, position, v0, v1, v2, front ))
1018 return;
1019 }
1020 }
1021
1022 /**
1023 * Calculate fixed position data for a triangle
1024 * It is unfortunate we need to do that here (as we need area
1025 * calculated in fixed point), as there's quite some code duplication
1026 * to what is done in the jit setup prog.
1027 */
1028 static inline void
1029 calc_fixed_position(struct lp_setup_context *setup,
1030 struct fixed_position* position,
1031 const float (*v0)[4],
1032 const float (*v1)[4],
1033 const float (*v2)[4])
1034 {
1035 float pixel_offset = setup->multisample ? 0.0 : setup->pixel_offset;
1036 /*
1037 * The rounding may not be quite the same with PIPE_ARCH_SSE
1038 * (util_iround right now only does nearest/even on x87,
1039 * otherwise nearest/away-from-zero).
1040 * Both should be acceptable, I think.
1041 */
1042 #if defined(PIPE_ARCH_SSE)
1043 __m128 v0r, v1r;
1044 __m128 vxy0xy2, vxy1xy0;
1045 __m128i vxy0xy2i, vxy1xy0i;
1046 __m128i dxdy0120, x0x2y0y2, x1x0y1y0, x0120, y0120;
1047 __m128 pix_offset = _mm_set1_ps(pixel_offset);
1048 __m128 fixed_one = _mm_set1_ps((float)FIXED_ONE);
1049 v0r = _mm_castpd_ps(_mm_load_sd((double *)v0[0]));
1050 vxy0xy2 = _mm_loadh_pi(v0r, (__m64 *)v2[0]);
1051 v1r = _mm_castpd_ps(_mm_load_sd((double *)v1[0]));
1052 vxy1xy0 = _mm_movelh_ps(v1r, vxy0xy2);
1053 vxy0xy2 = _mm_sub_ps(vxy0xy2, pix_offset);
1054 vxy1xy0 = _mm_sub_ps(vxy1xy0, pix_offset);
1055 vxy0xy2 = _mm_mul_ps(vxy0xy2, fixed_one);
1056 vxy1xy0 = _mm_mul_ps(vxy1xy0, fixed_one);
1057 vxy0xy2i = _mm_cvtps_epi32(vxy0xy2);
1058 vxy1xy0i = _mm_cvtps_epi32(vxy1xy0);
1059 dxdy0120 = _mm_sub_epi32(vxy0xy2i, vxy1xy0i);
1060 _mm_store_si128((__m128i *)&position->dx01, dxdy0120);
1061 /*
1062 * For the mul, would need some more shuffles, plus emulation
1063 * for the signed mul (without sse41), so don't bother.
1064 */
1065 x0x2y0y2 = _mm_shuffle_epi32(vxy0xy2i, _MM_SHUFFLE(3,1,2,0));
1066 x1x0y1y0 = _mm_shuffle_epi32(vxy1xy0i, _MM_SHUFFLE(3,1,2,0));
1067 x0120 = _mm_unpacklo_epi32(x0x2y0y2, x1x0y1y0);
1068 y0120 = _mm_unpackhi_epi32(x0x2y0y2, x1x0y1y0);
1069 _mm_store_si128((__m128i *)&position->x[0], x0120);
1070 _mm_store_si128((__m128i *)&position->y[0], y0120);
1071
1072 #else
1073 position->x[0] = subpixel_snap(v0[0][0] - pixel_offset);
1074 position->x[1] = subpixel_snap(v1[0][0] - pixel_offset);
1075 position->x[2] = subpixel_snap(v2[0][0] - pixel_offset);
1076 position->x[3] = 0; // should be unused
1077
1078 position->y[0] = subpixel_snap(v0[0][1] - pixel_offset);
1079 position->y[1] = subpixel_snap(v1[0][1] - pixel_offset);
1080 position->y[2] = subpixel_snap(v2[0][1] - pixel_offset);
1081 position->y[3] = 0; // should be unused
1082
1083 position->dx01 = position->x[0] - position->x[1];
1084 position->dy01 = position->y[0] - position->y[1];
1085
1086 position->dx20 = position->x[2] - position->x[0];
1087 position->dy20 = position->y[2] - position->y[0];
1088 #endif
1089
1090 position->area = IMUL64(position->dx01, position->dy20) -
1091 IMUL64(position->dx20, position->dy01);
1092 }
1093
1094
1095 /**
1096 * Rotate a triangle, flipping its clockwise direction,
1097 * Swaps values for xy[0] and xy[1]
1098 */
1099 static inline void
1100 rotate_fixed_position_01( struct fixed_position* position )
1101 {
1102 int x, y;
1103
1104 x = position->x[1];
1105 y = position->y[1];
1106 position->x[1] = position->x[0];
1107 position->y[1] = position->y[0];
1108 position->x[0] = x;
1109 position->y[0] = y;
1110
1111 position->dx01 = -position->dx01;
1112 position->dy01 = -position->dy01;
1113 position->dx20 = position->x[2] - position->x[0];
1114 position->dy20 = position->y[2] - position->y[0];
1115
1116 position->area = -position->area;
1117 }
1118
1119
1120 /**
1121 * Rotate a triangle, flipping its clockwise direction,
1122 * Swaps values for xy[1] and xy[2]
1123 */
1124 static inline void
1125 rotate_fixed_position_12( struct fixed_position* position )
1126 {
1127 int x, y;
1128
1129 x = position->x[2];
1130 y = position->y[2];
1131 position->x[2] = position->x[1];
1132 position->y[2] = position->y[1];
1133 position->x[1] = x;
1134 position->y[1] = y;
1135
1136 x = position->dx01;
1137 y = position->dy01;
1138 position->dx01 = -position->dx20;
1139 position->dy01 = -position->dy20;
1140 position->dx20 = -x;
1141 position->dy20 = -y;
1142
1143 position->area = -position->area;
1144 }
1145
1146
1147 /**
1148 * Draw triangle if it's CW, cull otherwise.
1149 */
1150 static void triangle_cw(struct lp_setup_context *setup,
1151 const float (*v0)[4],
1152 const float (*v1)[4],
1153 const float (*v2)[4])
1154 {
1155 PIPE_ALIGN_VAR(16) struct fixed_position position;
1156 struct llvmpipe_context *lp_context = (struct llvmpipe_context *)setup->pipe;
1157
1158 if (lp_context->active_statistics_queries) {
1159 lp_context->pipeline_statistics.c_primitives++;
1160 }
1161
1162 calc_fixed_position(setup, &position, v0, v1, v2);
1163
1164 if (position.area < 0) {
1165 if (setup->flatshade_first) {
1166 rotate_fixed_position_12(&position);
1167 retry_triangle_ccw(setup, &position, v0, v2, v1, !setup->ccw_is_frontface);
1168 } else {
1169 rotate_fixed_position_01(&position);
1170 retry_triangle_ccw(setup, &position, v1, v0, v2, !setup->ccw_is_frontface);
1171 }
1172 }
1173 }
1174
1175
1176 static void triangle_ccw(struct lp_setup_context *setup,
1177 const float (*v0)[4],
1178 const float (*v1)[4],
1179 const float (*v2)[4])
1180 {
1181 PIPE_ALIGN_VAR(16) struct fixed_position position;
1182 struct llvmpipe_context *lp_context = (struct llvmpipe_context *)setup->pipe;
1183
1184 if (lp_context->active_statistics_queries) {
1185 lp_context->pipeline_statistics.c_primitives++;
1186 }
1187
1188 calc_fixed_position(setup, &position, v0, v1, v2);
1189
1190 if (position.area > 0)
1191 retry_triangle_ccw(setup, &position, v0, v1, v2, setup->ccw_is_frontface);
1192 }
1193
1194 /**
1195 * Draw triangle whether it's CW or CCW.
1196 */
1197 static void triangle_both(struct lp_setup_context *setup,
1198 const float (*v0)[4],
1199 const float (*v1)[4],
1200 const float (*v2)[4])
1201 {
1202 PIPE_ALIGN_VAR(16) struct fixed_position position;
1203 struct llvmpipe_context *lp_context = (struct llvmpipe_context *)setup->pipe;
1204
1205 if (lp_context->active_statistics_queries) {
1206 lp_context->pipeline_statistics.c_primitives++;
1207 }
1208
1209 calc_fixed_position(setup, &position, v0, v1, v2);
1210
1211 if (0) {
1212 assert(!util_is_inf_or_nan(v0[0][0]));
1213 assert(!util_is_inf_or_nan(v0[0][1]));
1214 assert(!util_is_inf_or_nan(v1[0][0]));
1215 assert(!util_is_inf_or_nan(v1[0][1]));
1216 assert(!util_is_inf_or_nan(v2[0][0]));
1217 assert(!util_is_inf_or_nan(v2[0][1]));
1218 }
1219
1220 if (position.area > 0)
1221 retry_triangle_ccw( setup, &position, v0, v1, v2, setup->ccw_is_frontface );
1222 else if (position.area < 0) {
1223 if (setup->flatshade_first) {
1224 rotate_fixed_position_12( &position );
1225 retry_triangle_ccw( setup, &position, v0, v2, v1, !setup->ccw_is_frontface );
1226 } else {
1227 rotate_fixed_position_01( &position );
1228 retry_triangle_ccw( setup, &position, v1, v0, v2, !setup->ccw_is_frontface );
1229 }
1230 }
1231 }
1232
1233
1234 static void triangle_noop(struct lp_setup_context *setup,
1235 const float (*v0)[4],
1236 const float (*v1)[4],
1237 const float (*v2)[4])
1238 {
1239 }
1240
1241
1242 void
1243 lp_setup_choose_triangle(struct lp_setup_context *setup)
1244 {
1245 if (setup->rasterizer_discard) {
1246 setup->triangle = triangle_noop;
1247 return;
1248 }
1249 switch (setup->cullmode) {
1250 case PIPE_FACE_NONE:
1251 setup->triangle = triangle_both;
1252 break;
1253 case PIPE_FACE_BACK:
1254 setup->triangle = setup->ccw_is_frontface ? triangle_ccw : triangle_cw;
1255 break;
1256 case PIPE_FACE_FRONT:
1257 setup->triangle = setup->ccw_is_frontface ? triangle_cw : triangle_ccw;
1258 break;
1259 default:
1260 setup->triangle = triangle_noop;
1261 break;
1262 }
1263 }