llvmpipe: choose correct position for multisample
[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 }
368
369 tri = lp_setup_alloc_triangle(scene,
370 key->num_inputs,
371 nr_planes,
372 &tri_bytes);
373 if (!tri)
374 return FALSE;
375
376 #ifdef DEBUG
377 tri->v[0][0] = v0[0][0];
378 tri->v[1][0] = v1[0][0];
379 tri->v[2][0] = v2[0][0];
380 tri->v[0][1] = v0[0][1];
381 tri->v[1][1] = v1[0][1];
382 tri->v[2][1] = v2[0][1];
383 #endif
384
385 LP_COUNT(nr_tris);
386
387 /* Setup parameter interpolants:
388 */
389 setup->setup.variant->jit_function(v0, v1, v2,
390 frontfacing,
391 GET_A0(&tri->inputs),
392 GET_DADX(&tri->inputs),
393 GET_DADY(&tri->inputs));
394
395 tri->inputs.frontfacing = frontfacing;
396 tri->inputs.disable = FALSE;
397 tri->inputs.opaque = setup->fs.current.variant->opaque;
398 tri->inputs.layer = layer;
399 tri->inputs.viewport_index = viewport_index;
400
401 if (0)
402 lp_dump_setup_coef(&setup->setup.variant->key,
403 (const float (*)[4])GET_A0(&tri->inputs),
404 (const float (*)[4])GET_DADX(&tri->inputs),
405 (const float (*)[4])GET_DADY(&tri->inputs));
406
407 plane = GET_PLANES(tri);
408
409 #if defined(PIPE_ARCH_SSE)
410 if (1) {
411 __m128i vertx, verty;
412 __m128i shufx, shufy;
413 __m128i dcdx, dcdy;
414 __m128i cdx02, cdx13, cdy02, cdy13, c02, c13;
415 __m128i c01, c23, unused;
416 __m128i dcdx_neg_mask;
417 __m128i dcdy_neg_mask;
418 __m128i dcdx_zero_mask;
419 __m128i top_left_flag, c_dec;
420 __m128i eo, p0, p1, p2;
421 __m128i zero = _mm_setzero_si128();
422
423 vertx = _mm_load_si128((__m128i *)position->x); /* vertex x coords */
424 verty = _mm_load_si128((__m128i *)position->y); /* vertex y coords */
425
426 shufx = _mm_shuffle_epi32(vertx, _MM_SHUFFLE(3,0,2,1));
427 shufy = _mm_shuffle_epi32(verty, _MM_SHUFFLE(3,0,2,1));
428
429 dcdx = _mm_sub_epi32(verty, shufy);
430 dcdy = _mm_sub_epi32(vertx, shufx);
431
432 dcdx_neg_mask = _mm_srai_epi32(dcdx, 31);
433 dcdx_zero_mask = _mm_cmpeq_epi32(dcdx, zero);
434 dcdy_neg_mask = _mm_srai_epi32(dcdy, 31);
435
436 top_left_flag = _mm_set1_epi32((setup->bottom_edge_rule == 0) ? ~0 : 0);
437
438 c_dec = _mm_or_si128(dcdx_neg_mask,
439 _mm_and_si128(dcdx_zero_mask,
440 _mm_xor_si128(dcdy_neg_mask,
441 top_left_flag)));
442
443 /*
444 * 64 bit arithmetic.
445 * Note we need _signed_ mul (_mm_mul_epi32) which we emulate.
446 */
447 cdx02 = mm_mullohi_epi32(dcdx, vertx, &cdx13);
448 cdy02 = mm_mullohi_epi32(dcdy, verty, &cdy13);
449 c02 = _mm_sub_epi64(cdx02, cdy02);
450 c13 = _mm_sub_epi64(cdx13, cdy13);
451 c02 = _mm_sub_epi64(c02, _mm_shuffle_epi32(c_dec,
452 _MM_SHUFFLE(2,2,0,0)));
453 c13 = _mm_sub_epi64(c13, _mm_shuffle_epi32(c_dec,
454 _MM_SHUFFLE(3,3,1,1)));
455
456 /*
457 * Useful for very small fbs/tris (or fewer subpixel bits) only:
458 * c = _mm_sub_epi32(mm_mullo_epi32(dcdx, vertx),
459 * mm_mullo_epi32(dcdy, verty));
460 *
461 * c = _mm_sub_epi32(c, c_dec);
462 */
463
464 /* Scale up to match c:
465 */
466 dcdx = _mm_slli_epi32(dcdx, FIXED_ORDER);
467 dcdy = _mm_slli_epi32(dcdy, FIXED_ORDER);
468
469 /*
470 * Calculate trivial reject values:
471 * Note eo cannot overflow even if dcdx/dcdy would already have
472 * 31 bits (which they shouldn't have). This is because eo
473 * is never negative (albeit if we rely on that need to be careful...)
474 */
475 eo = _mm_sub_epi32(_mm_andnot_si128(dcdy_neg_mask, dcdy),
476 _mm_and_si128(dcdx_neg_mask, dcdx));
477
478 /* ei = _mm_sub_epi32(_mm_sub_epi32(dcdy, dcdx), eo); */
479
480 /*
481 * Pointless transpose which gets undone immediately in
482 * rasterization.
483 * It is actually difficult to do away with it - would essentially
484 * need GET_PLANES_DX, GET_PLANES_DY etc., but the calculations
485 * for this then would need to depend on the number of planes.
486 * The transpose is quite special here due to c being 64bit...
487 * The store has to be unaligned (unless we'd make the plane size
488 * a multiple of 128), and of course storing eo separately...
489 */
490 c01 = _mm_unpacklo_epi64(c02, c13);
491 c23 = _mm_unpackhi_epi64(c02, c13);
492 transpose2_64_2_32(&c01, &c23, &dcdx, &dcdy,
493 &p0, &p1, &p2, &unused);
494 _mm_storeu_si128((__m128i *)&plane[0], p0);
495 plane[0].eo = (uint32_t)_mm_cvtsi128_si32(eo);
496 _mm_storeu_si128((__m128i *)&plane[1], p1);
497 eo = _mm_shuffle_epi32(eo, _MM_SHUFFLE(3,2,0,1));
498 plane[1].eo = (uint32_t)_mm_cvtsi128_si32(eo);
499 _mm_storeu_si128((__m128i *)&plane[2], p2);
500 eo = _mm_shuffle_epi32(eo, _MM_SHUFFLE(0,0,0,2));
501 plane[2].eo = (uint32_t)_mm_cvtsi128_si32(eo);
502 } else
503 #elif defined(_ARCH_PWR8) && UTIL_ARCH_LITTLE_ENDIAN
504 /*
505 * XXX this code is effectively disabled for all practical purposes,
506 * as the allowed fb size is tiny if FIXED_ORDER is 8.
507 */
508 if (setup->fb.width <= MAX_FIXED_LENGTH32 &&
509 setup->fb.height <= MAX_FIXED_LENGTH32 &&
510 (bbox.x1 - bbox.x0) <= MAX_FIXED_LENGTH32 &&
511 (bbox.y1 - bbox.y0) <= MAX_FIXED_LENGTH32) {
512 unsigned int bottom_edge;
513 __m128i vertx, verty;
514 __m128i shufx, shufy;
515 __m128i dcdx, dcdy, c;
516 __m128i unused;
517 __m128i dcdx_neg_mask;
518 __m128i dcdy_neg_mask;
519 __m128i dcdx_zero_mask;
520 __m128i top_left_flag;
521 __m128i c_inc_mask, c_inc;
522 __m128i eo, p0, p1, p2;
523 __m128i_union vshuf_mask;
524 __m128i zero = vec_splats((unsigned char) 0);
525 PIPE_ALIGN_VAR(16) int32_t temp_vec[4];
526
527 #if UTIL_ARCH_LITTLE_ENDIAN
528 vshuf_mask.i[0] = 0x07060504;
529 vshuf_mask.i[1] = 0x0B0A0908;
530 vshuf_mask.i[2] = 0x03020100;
531 vshuf_mask.i[3] = 0x0F0E0D0C;
532 #else
533 vshuf_mask.i[0] = 0x00010203;
534 vshuf_mask.i[1] = 0x0C0D0E0F;
535 vshuf_mask.i[2] = 0x04050607;
536 vshuf_mask.i[3] = 0x08090A0B;
537 #endif
538
539 /* vertex x coords */
540 vertx = vec_load_si128((const uint32_t *) position->x);
541 /* vertex y coords */
542 verty = vec_load_si128((const uint32_t *) position->y);
543
544 shufx = vec_perm (vertx, vertx, vshuf_mask.m128i);
545 shufy = vec_perm (verty, verty, vshuf_mask.m128i);
546
547 dcdx = vec_sub_epi32(verty, shufy);
548 dcdy = vec_sub_epi32(vertx, shufx);
549
550 dcdx_neg_mask = vec_srai_epi32(dcdx, 31);
551 dcdx_zero_mask = vec_cmpeq_epi32(dcdx, zero);
552 dcdy_neg_mask = vec_srai_epi32(dcdy, 31);
553
554 bottom_edge = (setup->bottom_edge_rule == 0) ? ~0 : 0;
555 top_left_flag = (__m128i) vec_splats(bottom_edge);
556
557 c_inc_mask = vec_or(dcdx_neg_mask,
558 vec_and(dcdx_zero_mask,
559 vec_xor(dcdy_neg_mask,
560 top_left_flag)));
561
562 c_inc = vec_srli_epi32(c_inc_mask, 31);
563
564 c = vec_sub_epi32(vec_mullo_epi32(dcdx, vertx),
565 vec_mullo_epi32(dcdy, verty));
566
567 c = vec_add_epi32(c, c_inc);
568
569 /* Scale up to match c:
570 */
571 dcdx = vec_slli_epi32(dcdx, FIXED_ORDER);
572 dcdy = vec_slli_epi32(dcdy, FIXED_ORDER);
573
574 /* Calculate trivial reject values:
575 */
576 eo = vec_sub_epi32(vec_andnot_si128(dcdy_neg_mask, dcdy),
577 vec_and(dcdx_neg_mask, dcdx));
578
579 /* ei = _mm_sub_epi32(_mm_sub_epi32(dcdy, dcdx), eo); */
580
581 /* Pointless transpose which gets undone immediately in
582 * rasterization:
583 */
584 transpose4_epi32(&c, &dcdx, &dcdy, &eo,
585 &p0, &p1, &p2, &unused);
586
587 #define STORE_PLANE(plane, vec) do { \
588 vec_store_si128((uint32_t *)&temp_vec, vec); \
589 plane.c = (int64_t)temp_vec[0]; \
590 plane.dcdx = temp_vec[1]; \
591 plane.dcdy = temp_vec[2]; \
592 plane.eo = temp_vec[3]; \
593 } while(0)
594
595 STORE_PLANE(plane[0], p0);
596 STORE_PLANE(plane[1], p1);
597 STORE_PLANE(plane[2], p2);
598 #undef STORE_PLANE
599 } else
600 #endif
601 {
602 int i;
603 plane[0].dcdy = position->dx01;
604 plane[1].dcdy = position->x[1] - position->x[2];
605 plane[2].dcdy = position->dx20;
606 plane[0].dcdx = position->dy01;
607 plane[1].dcdx = position->y[1] - position->y[2];
608 plane[2].dcdx = position->dy20;
609
610 for (i = 0; i < 3; i++) {
611 /* half-edge constants, will be iterated over the whole render
612 * target.
613 */
614 plane[i].c = IMUL64(plane[i].dcdx, position->x[i]) -
615 IMUL64(plane[i].dcdy, position->y[i]);
616
617 /* correct for top-left vs. bottom-left fill convention.
618 */
619 if (plane[i].dcdx < 0) {
620 /* both fill conventions want this - adjust for left edges */
621 plane[i].c++;
622 }
623 else if (plane[i].dcdx == 0) {
624 if (setup->bottom_edge_rule == 0){
625 /* correct for top-left fill convention:
626 */
627 if (plane[i].dcdy > 0) plane[i].c++;
628 }
629 else {
630 /* correct for bottom-left fill convention:
631 */
632 if (plane[i].dcdy < 0) plane[i].c++;
633 }
634 }
635
636 /* Scale up to match c:
637 */
638 assert((plane[i].dcdx << FIXED_ORDER) >> FIXED_ORDER == plane[i].dcdx);
639 assert((plane[i].dcdy << FIXED_ORDER) >> FIXED_ORDER == plane[i].dcdy);
640 plane[i].dcdx <<= FIXED_ORDER;
641 plane[i].dcdy <<= FIXED_ORDER;
642
643 /* find trivial reject offsets for each edge for a single-pixel
644 * sized block. These will be scaled up at each recursive level to
645 * match the active blocksize. Scaling in this way works best if
646 * the blocks are square.
647 */
648 plane[i].eo = 0;
649 if (plane[i].dcdx < 0) plane[i].eo -= plane[i].dcdx;
650 if (plane[i].dcdy > 0) plane[i].eo += plane[i].dcdy;
651 }
652 }
653
654 if (0) {
655 debug_printf("p0: %"PRIx64"/%08x/%08x/%08x\n",
656 plane[0].c,
657 plane[0].dcdx,
658 plane[0].dcdy,
659 plane[0].eo);
660
661 debug_printf("p1: %"PRIx64"/%08x/%08x/%08x\n",
662 plane[1].c,
663 plane[1].dcdx,
664 plane[1].dcdy,
665 plane[1].eo);
666
667 debug_printf("p2: %"PRIx64"/%08x/%08x/%08x\n",
668 plane[2].c,
669 plane[2].dcdx,
670 plane[2].dcdy,
671 plane[2].eo);
672 }
673
674
675 /*
676 * When rasterizing scissored tris, use the intersection of the
677 * triangle bounding box and the scissor rect to generate the
678 * scissor planes.
679 *
680 * This permits us to cut off the triangle "tails" that are present
681 * in the intermediate recursive levels caused when two of the
682 * triangles edges don't diverge quickly enough to trivially reject
683 * exterior blocks from the triangle.
684 *
685 * It's not really clear if it's worth worrying about these tails,
686 * but since we generate the planes for each scissored tri, it's
687 * free to trim them in this case.
688 *
689 * Note that otherwise, the scissor planes only vary in 'C' value,
690 * and even then only on state-changes. Could alternatively store
691 * these planes elsewhere.
692 * (Or only store the c value together with a bit indicating which
693 * scissor edge this is, so rasterization would treat them differently
694 * (easier to evaluate) to ordinary planes.)
695 */
696 if (nr_planes > 3) {
697 /* why not just use draw_regions */
698 struct lp_rast_plane *plane_s = &plane[3];
699
700 if (s_planes[0]) {
701 plane_s->dcdx = ~0U << 8;
702 plane_s->dcdy = 0;
703 plane_s->c = (1-scissor->x0) << 8;
704 plane_s->eo = 1 << 8;
705 plane_s++;
706 }
707 if (s_planes[1]) {
708 plane_s->dcdx = 1 << 8;
709 plane_s->dcdy = 0;
710 plane_s->c = (scissor->x1+1) << 8;
711 plane_s->eo = 0 << 8;
712 plane_s++;
713 }
714 if (s_planes[2]) {
715 plane_s->dcdx = 0;
716 plane_s->dcdy = 1 << 8;
717 plane_s->c = (1-scissor->y0) << 8;
718 plane_s->eo = 1 << 8;
719 plane_s++;
720 }
721 if (s_planes[3]) {
722 plane_s->dcdx = 0;
723 plane_s->dcdy = ~0U << 8;
724 plane_s->c = (scissor->y1+1) << 8;
725 plane_s->eo = 0;
726 plane_s++;
727 }
728 assert(plane_s == &plane[nr_planes]);
729 }
730
731 return lp_setup_bin_triangle(setup, tri, &bbox, &bboxpos, nr_planes, viewport_index);
732 }
733
734 /*
735 * Round to nearest less or equal power of two of the input.
736 *
737 * Undefined if no bit set exists, so code should check against 0 first.
738 */
739 static inline uint32_t
740 floor_pot(uint32_t n)
741 {
742 #if defined(PIPE_CC_GCC) && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64))
743 if (n == 0)
744 return 0;
745
746 __asm__("bsr %1,%0"
747 : "=r" (n)
748 : "rm" (n)
749 : "cc");
750 return 1 << n;
751 #else
752 n |= (n >> 1);
753 n |= (n >> 2);
754 n |= (n >> 4);
755 n |= (n >> 8);
756 n |= (n >> 16);
757 return n - (n >> 1);
758 #endif
759 }
760
761
762 boolean
763 lp_setup_bin_triangle(struct lp_setup_context *setup,
764 struct lp_rast_triangle *tri,
765 const struct u_rect *bboxorig,
766 const struct u_rect *bbox,
767 int nr_planes,
768 unsigned viewport_index)
769 {
770 struct lp_scene *scene = setup->scene;
771 struct u_rect trimmed_box = *bbox;
772 int i;
773 unsigned cmd;
774
775 /* What is the largest power-of-two boundary this triangle crosses:
776 */
777 int dx = floor_pot((bbox->x0 ^ bbox->x1) |
778 (bbox->y0 ^ bbox->y1));
779
780 /* The largest dimension of the rasterized area of the triangle
781 * (aligned to a 4x4 grid), rounded down to the nearest power of two:
782 */
783 int max_sz = ((bbox->x1 - (bbox->x0 & ~3)) |
784 (bbox->y1 - (bbox->y0 & ~3)));
785 int sz = floor_pot(max_sz);
786
787 /*
788 * NOTE: It is important to use the original bounding box
789 * which might contain negative values here, because if the
790 * plane math may overflow or not with the 32bit rasterization
791 * functions depends on the original extent of the triangle.
792 */
793 int max_szorig = ((bboxorig->x1 - (bboxorig->x0 & ~3)) |
794 (bboxorig->y1 - (bboxorig->y0 & ~3)));
795 boolean use_32bits = max_szorig <= MAX_FIXED_LENGTH32;
796
797 /* Now apply scissor, etc to the bounding box. Could do this
798 * earlier, but it confuses the logic for tri-16 and would force
799 * the rasterizer to also respect scissor, etc, just for the rare
800 * cases where a small triangle extends beyond the scissor.
801 */
802 u_rect_find_intersection(&setup->draw_regions[viewport_index],
803 &trimmed_box);
804
805 /* Determine which tile(s) intersect the triangle's bounding box
806 */
807 if (dx < TILE_SIZE)
808 {
809 int ix0 = bbox->x0 / TILE_SIZE;
810 int iy0 = bbox->y0 / TILE_SIZE;
811 unsigned px = bbox->x0 & 63 & ~3;
812 unsigned py = bbox->y0 & 63 & ~3;
813
814 assert(iy0 == bbox->y1 / TILE_SIZE &&
815 ix0 == bbox->x1 / TILE_SIZE);
816
817 if (nr_planes == 3) {
818 if (sz < 4)
819 {
820 /* Triangle is contained in a single 4x4 stamp:
821 */
822 assert(px + 4 <= TILE_SIZE);
823 assert(py + 4 <= TILE_SIZE);
824 if (setup->multisample)
825 cmd = LP_RAST_OP_MS_TRIANGLE_3_4;
826 else
827 cmd = use_32bits ? LP_RAST_OP_TRIANGLE_32_3_4 : LP_RAST_OP_TRIANGLE_3_4;
828 return lp_scene_bin_cmd_with_state( scene, ix0, iy0,
829 setup->fs.stored, cmd,
830 lp_rast_arg_triangle_contained(tri, px, py) );
831 }
832
833 if (sz < 16)
834 {
835 /* Triangle is contained in a single 16x16 block:
836 */
837
838 /*
839 * The 16x16 block is only 4x4 aligned, and can exceed the tile
840 * dimensions if the triangle is 16 pixels in one dimension but 4
841 * in the other. So budge the 16x16 back inside the tile.
842 */
843 px = MIN2(px, TILE_SIZE - 16);
844 py = MIN2(py, TILE_SIZE - 16);
845
846 assert(px + 16 <= TILE_SIZE);
847 assert(py + 16 <= TILE_SIZE);
848
849 if (setup->multisample)
850 cmd = LP_RAST_OP_MS_TRIANGLE_3_16;
851 else
852 cmd = use_32bits ? LP_RAST_OP_TRIANGLE_32_3_16 : LP_RAST_OP_TRIANGLE_3_16;
853 return lp_scene_bin_cmd_with_state( scene, ix0, iy0,
854 setup->fs.stored, cmd,
855 lp_rast_arg_triangle_contained(tri, px, py) );
856 }
857 }
858 else if (nr_planes == 4 && sz < 16)
859 {
860 px = MIN2(px, TILE_SIZE - 16);
861 py = MIN2(py, TILE_SIZE - 16);
862
863 assert(px + 16 <= TILE_SIZE);
864 assert(py + 16 <= TILE_SIZE);
865
866 if (setup->multisample)
867 cmd = LP_RAST_OP_MS_TRIANGLE_4_16;
868 else
869 cmd = use_32bits ? LP_RAST_OP_TRIANGLE_32_4_16 : LP_RAST_OP_TRIANGLE_4_16;
870 return lp_scene_bin_cmd_with_state(scene, ix0, iy0,
871 setup->fs.stored, cmd,
872 lp_rast_arg_triangle_contained(tri, px, py));
873 }
874
875
876 /* Triangle is contained in a single tile:
877 */
878 if (setup->multisample)
879 cmd = lp_rast_ms_tri_tab[nr_planes];
880 else
881 cmd = use_32bits ? lp_rast_32_tri_tab[nr_planes] : lp_rast_tri_tab[nr_planes];
882 return lp_scene_bin_cmd_with_state(
883 scene, ix0, iy0, setup->fs.stored, cmd,
884 lp_rast_arg_triangle(tri, (1<<nr_planes)-1));
885 }
886 else
887 {
888 struct lp_rast_plane *plane = GET_PLANES(tri);
889 int64_t c[MAX_PLANES];
890 int64_t ei[MAX_PLANES];
891
892 int64_t eo[MAX_PLANES];
893 int64_t xstep[MAX_PLANES];
894 int64_t ystep[MAX_PLANES];
895 int x, y;
896
897 int ix0 = trimmed_box.x0 / TILE_SIZE;
898 int iy0 = trimmed_box.y0 / TILE_SIZE;
899 int ix1 = trimmed_box.x1 / TILE_SIZE;
900 int iy1 = trimmed_box.y1 / TILE_SIZE;
901
902 for (i = 0; i < nr_planes; i++) {
903 c[i] = (plane[i].c +
904 IMUL64(plane[i].dcdy, iy0) * TILE_SIZE -
905 IMUL64(plane[i].dcdx, ix0) * TILE_SIZE);
906
907 ei[i] = (plane[i].dcdy -
908 plane[i].dcdx -
909 (int64_t)plane[i].eo) << TILE_ORDER;
910
911 eo[i] = (int64_t)plane[i].eo << TILE_ORDER;
912 xstep[i] = -(((int64_t)plane[i].dcdx) << TILE_ORDER);
913 ystep[i] = ((int64_t)plane[i].dcdy) << TILE_ORDER;
914 }
915
916
917
918 /* Test tile-sized blocks against the triangle.
919 * Discard blocks fully outside the tri. If the block is fully
920 * contained inside the tri, bin an lp_rast_shade_tile command.
921 * Else, bin a lp_rast_triangle command.
922 */
923 for (y = iy0; y <= iy1; y++)
924 {
925 boolean in = FALSE; /* are we inside the triangle? */
926 int64_t cx[MAX_PLANES];
927
928 for (i = 0; i < nr_planes; i++)
929 cx[i] = c[i];
930
931 for (x = ix0; x <= ix1; x++)
932 {
933 int out = 0;
934 int partial = 0;
935
936 for (i = 0; i < nr_planes; i++) {
937 int64_t planeout = cx[i] + eo[i];
938 int64_t planepartial = cx[i] + ei[i] - 1;
939 out |= (int) (planeout >> 63);
940 partial |= ((int) (planepartial >> 63)) & (1<<i);
941 }
942
943 if (out) {
944 /* do nothing */
945 if (in)
946 break; /* exiting triangle, all done with this row */
947 LP_COUNT(nr_empty_64);
948 }
949 else if (partial) {
950 /* Not trivially accepted by at least one plane -
951 * rasterize/shade partial tile
952 */
953 int count = util_bitcount(partial);
954 in = TRUE;
955
956 if (setup->multisample)
957 cmd = lp_rast_ms_tri_tab[count];
958 else
959 cmd = use_32bits ? lp_rast_32_tri_tab[count] : lp_rast_tri_tab[count];
960 if (!lp_scene_bin_cmd_with_state( scene, x, y,
961 setup->fs.stored, cmd,
962 lp_rast_arg_triangle(tri, partial) ))
963 goto fail;
964
965 LP_COUNT(nr_partially_covered_64);
966 }
967 else {
968 /* triangle covers the whole tile- shade whole tile */
969 LP_COUNT(nr_fully_covered_64);
970 in = TRUE;
971 if (!lp_setup_whole_tile(setup, &tri->inputs, x, y))
972 goto fail;
973 }
974
975 /* Iterate cx values across the region: */
976 for (i = 0; i < nr_planes; i++)
977 cx[i] += xstep[i];
978 }
979
980 /* Iterate c values down the region: */
981 for (i = 0; i < nr_planes; i++)
982 c[i] += ystep[i];
983 }
984 }
985
986 return TRUE;
987
988 fail:
989 /* Need to disable any partially binned triangle. This is easier
990 * than trying to locate all the triangle, shade-tile, etc,
991 * commands which may have been binned.
992 */
993 tri->inputs.disable = TRUE;
994 return FALSE;
995 }
996
997
998 /**
999 * Try to draw the triangle, restart the scene on failure.
1000 */
1001 static void retry_triangle_ccw( struct lp_setup_context *setup,
1002 struct fixed_position* position,
1003 const float (*v0)[4],
1004 const float (*v1)[4],
1005 const float (*v2)[4],
1006 boolean front)
1007 {
1008 if (!do_triangle_ccw( setup, position, v0, v1, v2, front ))
1009 {
1010 if (!lp_setup_flush_and_restart(setup))
1011 return;
1012
1013 if (!do_triangle_ccw( setup, position, v0, v1, v2, front ))
1014 return;
1015 }
1016 }
1017
1018 /**
1019 * Calculate fixed position data for a triangle
1020 * It is unfortunate we need to do that here (as we need area
1021 * calculated in fixed point), as there's quite some code duplication
1022 * to what is done in the jit setup prog.
1023 */
1024 static inline void
1025 calc_fixed_position(struct lp_setup_context *setup,
1026 struct fixed_position* position,
1027 const float (*v0)[4],
1028 const float (*v1)[4],
1029 const float (*v2)[4])
1030 {
1031 float pixel_offset = setup->multisample ? 0.0 : setup->pixel_offset;
1032 /*
1033 * The rounding may not be quite the same with PIPE_ARCH_SSE
1034 * (util_iround right now only does nearest/even on x87,
1035 * otherwise nearest/away-from-zero).
1036 * Both should be acceptable, I think.
1037 */
1038 #if defined(PIPE_ARCH_SSE)
1039 __m128 v0r, v1r;
1040 __m128 vxy0xy2, vxy1xy0;
1041 __m128i vxy0xy2i, vxy1xy0i;
1042 __m128i dxdy0120, x0x2y0y2, x1x0y1y0, x0120, y0120;
1043 __m128 pix_offset = _mm_set1_ps(pixel_offset);
1044 __m128 fixed_one = _mm_set1_ps((float)FIXED_ONE);
1045 v0r = _mm_castpd_ps(_mm_load_sd((double *)v0[0]));
1046 vxy0xy2 = _mm_loadh_pi(v0r, (__m64 *)v2[0]);
1047 v1r = _mm_castpd_ps(_mm_load_sd((double *)v1[0]));
1048 vxy1xy0 = _mm_movelh_ps(v1r, vxy0xy2);
1049 vxy0xy2 = _mm_sub_ps(vxy0xy2, pix_offset);
1050 vxy1xy0 = _mm_sub_ps(vxy1xy0, pix_offset);
1051 vxy0xy2 = _mm_mul_ps(vxy0xy2, fixed_one);
1052 vxy1xy0 = _mm_mul_ps(vxy1xy0, fixed_one);
1053 vxy0xy2i = _mm_cvtps_epi32(vxy0xy2);
1054 vxy1xy0i = _mm_cvtps_epi32(vxy1xy0);
1055 dxdy0120 = _mm_sub_epi32(vxy0xy2i, vxy1xy0i);
1056 _mm_store_si128((__m128i *)&position->dx01, dxdy0120);
1057 /*
1058 * For the mul, would need some more shuffles, plus emulation
1059 * for the signed mul (without sse41), so don't bother.
1060 */
1061 x0x2y0y2 = _mm_shuffle_epi32(vxy0xy2i, _MM_SHUFFLE(3,1,2,0));
1062 x1x0y1y0 = _mm_shuffle_epi32(vxy1xy0i, _MM_SHUFFLE(3,1,2,0));
1063 x0120 = _mm_unpacklo_epi32(x0x2y0y2, x1x0y1y0);
1064 y0120 = _mm_unpackhi_epi32(x0x2y0y2, x1x0y1y0);
1065 _mm_store_si128((__m128i *)&position->x[0], x0120);
1066 _mm_store_si128((__m128i *)&position->y[0], y0120);
1067
1068 #else
1069 position->x[0] = subpixel_snap(v0[0][0] - pixel_offset);
1070 position->x[1] = subpixel_snap(v1[0][0] - pixel_offset);
1071 position->x[2] = subpixel_snap(v2[0][0] - pixel_offset);
1072 position->x[3] = 0; // should be unused
1073
1074 position->y[0] = subpixel_snap(v0[0][1] - pixel_offset);
1075 position->y[1] = subpixel_snap(v1[0][1] - pixel_offset);
1076 position->y[2] = subpixel_snap(v2[0][1] - pixel_offset);
1077 position->y[3] = 0; // should be unused
1078
1079 position->dx01 = position->x[0] - position->x[1];
1080 position->dy01 = position->y[0] - position->y[1];
1081
1082 position->dx20 = position->x[2] - position->x[0];
1083 position->dy20 = position->y[2] - position->y[0];
1084 #endif
1085
1086 position->area = IMUL64(position->dx01, position->dy20) -
1087 IMUL64(position->dx20, position->dy01);
1088 }
1089
1090
1091 /**
1092 * Rotate a triangle, flipping its clockwise direction,
1093 * Swaps values for xy[0] and xy[1]
1094 */
1095 static inline void
1096 rotate_fixed_position_01( struct fixed_position* position )
1097 {
1098 int x, y;
1099
1100 x = position->x[1];
1101 y = position->y[1];
1102 position->x[1] = position->x[0];
1103 position->y[1] = position->y[0];
1104 position->x[0] = x;
1105 position->y[0] = y;
1106
1107 position->dx01 = -position->dx01;
1108 position->dy01 = -position->dy01;
1109 position->dx20 = position->x[2] - position->x[0];
1110 position->dy20 = position->y[2] - position->y[0];
1111
1112 position->area = -position->area;
1113 }
1114
1115
1116 /**
1117 * Rotate a triangle, flipping its clockwise direction,
1118 * Swaps values for xy[1] and xy[2]
1119 */
1120 static inline void
1121 rotate_fixed_position_12( struct fixed_position* position )
1122 {
1123 int x, y;
1124
1125 x = position->x[2];
1126 y = position->y[2];
1127 position->x[2] = position->x[1];
1128 position->y[2] = position->y[1];
1129 position->x[1] = x;
1130 position->y[1] = y;
1131
1132 x = position->dx01;
1133 y = position->dy01;
1134 position->dx01 = -position->dx20;
1135 position->dy01 = -position->dy20;
1136 position->dx20 = -x;
1137 position->dy20 = -y;
1138
1139 position->area = -position->area;
1140 }
1141
1142
1143 /**
1144 * Draw triangle if it's CW, cull otherwise.
1145 */
1146 static void triangle_cw(struct lp_setup_context *setup,
1147 const float (*v0)[4],
1148 const float (*v1)[4],
1149 const float (*v2)[4])
1150 {
1151 PIPE_ALIGN_VAR(16) struct fixed_position position;
1152 struct llvmpipe_context *lp_context = (struct llvmpipe_context *)setup->pipe;
1153
1154 if (lp_context->active_statistics_queries) {
1155 lp_context->pipeline_statistics.c_primitives++;
1156 }
1157
1158 calc_fixed_position(setup, &position, v0, v1, v2);
1159
1160 if (position.area < 0) {
1161 if (setup->flatshade_first) {
1162 rotate_fixed_position_12(&position);
1163 retry_triangle_ccw(setup, &position, v0, v2, v1, !setup->ccw_is_frontface);
1164 } else {
1165 rotate_fixed_position_01(&position);
1166 retry_triangle_ccw(setup, &position, v1, v0, v2, !setup->ccw_is_frontface);
1167 }
1168 }
1169 }
1170
1171
1172 static void triangle_ccw(struct lp_setup_context *setup,
1173 const float (*v0)[4],
1174 const float (*v1)[4],
1175 const float (*v2)[4])
1176 {
1177 PIPE_ALIGN_VAR(16) struct fixed_position position;
1178 struct llvmpipe_context *lp_context = (struct llvmpipe_context *)setup->pipe;
1179
1180 if (lp_context->active_statistics_queries) {
1181 lp_context->pipeline_statistics.c_primitives++;
1182 }
1183
1184 calc_fixed_position(setup, &position, v0, v1, v2);
1185
1186 if (position.area > 0)
1187 retry_triangle_ccw(setup, &position, v0, v1, v2, setup->ccw_is_frontface);
1188 }
1189
1190 /**
1191 * Draw triangle whether it's CW or CCW.
1192 */
1193 static void triangle_both(struct lp_setup_context *setup,
1194 const float (*v0)[4],
1195 const float (*v1)[4],
1196 const float (*v2)[4])
1197 {
1198 PIPE_ALIGN_VAR(16) struct fixed_position position;
1199 struct llvmpipe_context *lp_context = (struct llvmpipe_context *)setup->pipe;
1200
1201 if (lp_context->active_statistics_queries) {
1202 lp_context->pipeline_statistics.c_primitives++;
1203 }
1204
1205 calc_fixed_position(setup, &position, v0, v1, v2);
1206
1207 if (0) {
1208 assert(!util_is_inf_or_nan(v0[0][0]));
1209 assert(!util_is_inf_or_nan(v0[0][1]));
1210 assert(!util_is_inf_or_nan(v1[0][0]));
1211 assert(!util_is_inf_or_nan(v1[0][1]));
1212 assert(!util_is_inf_or_nan(v2[0][0]));
1213 assert(!util_is_inf_or_nan(v2[0][1]));
1214 }
1215
1216 if (position.area > 0)
1217 retry_triangle_ccw( setup, &position, v0, v1, v2, setup->ccw_is_frontface );
1218 else if (position.area < 0) {
1219 if (setup->flatshade_first) {
1220 rotate_fixed_position_12( &position );
1221 retry_triangle_ccw( setup, &position, v0, v2, v1, !setup->ccw_is_frontface );
1222 } else {
1223 rotate_fixed_position_01( &position );
1224 retry_triangle_ccw( setup, &position, v1, v0, v2, !setup->ccw_is_frontface );
1225 }
1226 }
1227 }
1228
1229
1230 static void triangle_noop(struct lp_setup_context *setup,
1231 const float (*v0)[4],
1232 const float (*v1)[4],
1233 const float (*v2)[4])
1234 {
1235 }
1236
1237
1238 void
1239 lp_setup_choose_triangle(struct lp_setup_context *setup)
1240 {
1241 if (setup->rasterizer_discard) {
1242 setup->triangle = triangle_noop;
1243 return;
1244 }
1245 switch (setup->cullmode) {
1246 case PIPE_FACE_NONE:
1247 setup->triangle = triangle_both;
1248 break;
1249 case PIPE_FACE_BACK:
1250 setup->triangle = setup->ccw_is_frontface ? triangle_ccw : triangle_cw;
1251 break;
1252 case PIPE_FACE_FRONT:
1253 setup->triangle = setup->ccw_is_frontface ? triangle_cw : triangle_ccw;
1254 break;
1255 default:
1256 setup->triangle = triangle_noop;
1257 break;
1258 }
1259 }