1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
29 * Binning code for triangles
32 #include "util/u_math.h"
33 #include "util/u_memory.h"
35 #include "lp_setup_context.h"
37 #include "lp_state_fs.h"
39 #define NUM_CHANNELS 4
45 /* fixed point vertex coordinates */
49 /* float x,y deltas - all from the original coordinates
64 static const int step_scissor_minx
[16] = {
71 static const int step_scissor_maxx
[16] = {
78 static const int step_scissor_miny
[16] = {
85 static const int step_scissor_maxy
[16] = {
96 subpixel_snap(float a
)
98 return util_iround(FIXED_ONE
* a
);
102 fixed_to_float(int a
)
104 return a
* (1.0 / FIXED_ONE
);
110 * Compute a0 for a constant-valued coefficient (GL_FLAT shading).
112 static void constant_coef( struct lp_rast_triangle
*tri
,
117 tri
->inputs
.a0
[slot
][i
] = value
;
118 tri
->inputs
.dadx
[slot
][i
] = 0.0f
;
119 tri
->inputs
.dady
[slot
][i
] = 0.0f
;
124 static void linear_coef( struct lp_rast_triangle
*tri
,
125 const struct tri_info
*info
,
130 float a0
= info
->v0
[vert_attr
][i
];
131 float a1
= info
->v1
[vert_attr
][i
];
132 float a2
= info
->v2
[vert_attr
][i
];
134 float da01
= a0
- a1
;
135 float da20
= a2
- a0
;
136 float dadx
= (da01
* info
->dy20
- info
->dy01
* da20
) * info
->oneoverarea
;
137 float dady
= (da20
* info
->dx01
- info
->dx20
* da01
) * info
->oneoverarea
;
139 tri
->inputs
.dadx
[slot
][i
] = dadx
;
140 tri
->inputs
.dady
[slot
][i
] = dady
;
142 /* calculate a0 as the value which would be sampled for the
143 * fragment at (0,0), taking into account that we want to sample at
144 * pixel centers, in other words (0.5, 0.5).
146 * this is neat but unfortunately not a good way to do things for
147 * triangles with very large values of dadx or dady as it will
148 * result in the subtraction and re-addition from a0 of a very
149 * large number, which means we'll end up loosing a lot of the
150 * fractional bits and precision from a0. the way to fix this is
151 * to define a0 as the sample at a pixel center somewhere near vmin
152 * instead - i'll switch to this later.
154 tri
->inputs
.a0
[slot
][i
] = (a0
-
155 (dadx
* (info
->v0
[0][0] - info
->pixel_offset
) +
156 dady
* (info
->v0
[0][1] - info
->pixel_offset
)));
161 * Compute a0, dadx and dady for a perspective-corrected interpolant,
163 * We basically multiply the vertex value by 1/w before computing
164 * the plane coefficients (a0, dadx, dady).
165 * Later, when we compute the value at a particular fragment position we'll
166 * divide the interpolated value by the interpolated W at that fragment.
168 static void perspective_coef( struct lp_rast_triangle
*tri
,
169 const struct tri_info
*info
,
174 /* premultiply by 1/w (v[0][3] is always 1/w):
176 float a0
= info
->v0
[vert_attr
][i
] * info
->v0
[0][3];
177 float a1
= info
->v1
[vert_attr
][i
] * info
->v1
[0][3];
178 float a2
= info
->v2
[vert_attr
][i
] * info
->v2
[0][3];
179 float da01
= a0
- a1
;
180 float da20
= a2
- a0
;
181 float dadx
= (da01
* info
->dy20
- info
->dy01
* da20
) * info
->oneoverarea
;
182 float dady
= (da20
* info
->dx01
- info
->dx20
* da01
) * info
->oneoverarea
;
184 tri
->inputs
.dadx
[slot
][i
] = dadx
;
185 tri
->inputs
.dady
[slot
][i
] = dady
;
186 tri
->inputs
.a0
[slot
][i
] = (a0
-
187 (dadx
* (info
->v0
[0][0] - info
->pixel_offset
) +
188 dady
* (info
->v0
[0][1] - info
->pixel_offset
)));
193 * Special coefficient setup for gl_FragCoord.
194 * X and Y are trivial
195 * Z and W are copied from position_coef which should have already been computed.
196 * We could do a bit less work if we'd examine gl_FragCoord's swizzle mask.
199 setup_fragcoord_coef(struct lp_rast_triangle
*tri
,
200 const struct tri_info
*info
,
205 if (usage_mask
& TGSI_WRITEMASK_X
) {
206 tri
->inputs
.a0
[slot
][0] = 0.0;
207 tri
->inputs
.dadx
[slot
][0] = 1.0;
208 tri
->inputs
.dady
[slot
][0] = 0.0;
212 if (usage_mask
& TGSI_WRITEMASK_Y
) {
213 tri
->inputs
.a0
[slot
][1] = 0.0;
214 tri
->inputs
.dadx
[slot
][1] = 0.0;
215 tri
->inputs
.dady
[slot
][1] = 1.0;
219 if (usage_mask
& TGSI_WRITEMASK_Z
) {
220 linear_coef(tri
, info
, slot
, 0, 2);
224 if (usage_mask
& TGSI_WRITEMASK_W
) {
225 linear_coef(tri
, info
, slot
, 0, 3);
231 * Setup the fragment input attribute with the front-facing value.
232 * \param frontface is the triangle front facing?
234 static void setup_facing_coef( struct lp_rast_triangle
*tri
,
239 /* convert TRUE to 1.0 and FALSE to -1.0 */
240 if (usage_mask
& TGSI_WRITEMASK_X
)
241 constant_coef( tri
, slot
, 2.0f
* frontface
- 1.0f
, 0 );
243 if (usage_mask
& TGSI_WRITEMASK_Y
)
244 constant_coef( tri
, slot
, 0.0f
, 1 ); /* wasted */
246 if (usage_mask
& TGSI_WRITEMASK_Z
)
247 constant_coef( tri
, slot
, 0.0f
, 2 ); /* wasted */
249 if (usage_mask
& TGSI_WRITEMASK_W
)
250 constant_coef( tri
, slot
, 0.0f
, 3 ); /* wasted */
255 * Compute the tri->coef[] array dadx, dady, a0 values.
257 static void setup_tri_coefficients( struct lp_setup_context
*setup
,
258 struct lp_rast_triangle
*tri
,
259 const struct tri_info
*info
)
261 unsigned fragcoord_usage_mask
= TGSI_WRITEMASK_XYZ
;
264 /* setup interpolation for all the remaining attributes:
266 for (slot
= 0; slot
< setup
->fs
.nr_inputs
; slot
++) {
267 unsigned vert_attr
= setup
->fs
.input
[slot
].src_index
;
268 unsigned usage_mask
= setup
->fs
.input
[slot
].usage_mask
;
271 switch (setup
->fs
.input
[slot
].interp
) {
272 case LP_INTERP_CONSTANT
:
273 if (setup
->flatshade_first
) {
274 for (i
= 0; i
< NUM_CHANNELS
; i
++)
275 if (usage_mask
& (1 << i
))
276 constant_coef(tri
, slot
+1, info
->v0
[vert_attr
][i
], i
);
279 for (i
= 0; i
< NUM_CHANNELS
; i
++)
280 if (usage_mask
& (1 << i
))
281 constant_coef(tri
, slot
+1, info
->v2
[vert_attr
][i
], i
);
285 case LP_INTERP_LINEAR
:
286 for (i
= 0; i
< NUM_CHANNELS
; i
++)
287 if (usage_mask
& (1 << i
))
288 linear_coef(tri
, info
, slot
+1, vert_attr
, i
);
291 case LP_INTERP_PERSPECTIVE
:
292 for (i
= 0; i
< NUM_CHANNELS
; i
++)
293 if (usage_mask
& (1 << i
))
294 perspective_coef(tri
, info
, slot
+1, vert_attr
, i
);
295 fragcoord_usage_mask
|= TGSI_WRITEMASK_W
;
298 case LP_INTERP_POSITION
:
300 * The generated pixel interpolators will pick up the coeffs from
301 * slot 0, so all need to ensure that the usage mask is covers all
304 fragcoord_usage_mask
|= usage_mask
;
307 case LP_INTERP_FACING
:
308 setup_facing_coef(tri
, slot
+1, info
->frontfacing
, usage_mask
);
316 /* The internal position input is in slot zero:
318 setup_fragcoord_coef(tri
, info
, 0, fragcoord_usage_mask
);
327 * Alloc space for a new triangle plus the input.a0/dadx/dady arrays
328 * immediately after it.
329 * The memory is allocated from the per-scene pool, not per-tile.
330 * \param tri_size returns number of bytes allocated
331 * \param nr_inputs number of fragment shader inputs
332 * \return pointer to triangle space
334 static INLINE
struct lp_rast_triangle
*
335 alloc_triangle(struct lp_scene
*scene
,
340 unsigned input_array_sz
= NUM_CHANNELS
* (nr_inputs
+ 1) * sizeof(float);
341 struct lp_rast_triangle
*tri
;
342 unsigned tri_bytes
, bytes
;
345 assert(sizeof(*tri
) % 16 == 0);
347 tri_bytes
= align(Offset(struct lp_rast_triangle
, plane
[nr_planes
]), 16);
348 bytes
= tri_bytes
+ (3 * input_array_sz
);
350 tri
= lp_scene_alloc_aligned( scene
, bytes
, 16 );
353 inputs
= ((char *)tri
) + tri_bytes
;
354 tri
->inputs
.a0
= (float (*)[4]) inputs
;
355 tri
->inputs
.dadx
= (float (*)[4]) (inputs
+ input_array_sz
);
356 tri
->inputs
.dady
= (float (*)[4]) (inputs
+ 2 * input_array_sz
);
366 * Print triangle vertex attribs (for debug).
369 print_triangle(struct lp_setup_context
*setup
,
370 const float (*v1
)[4],
371 const float (*v2
)[4],
372 const float (*v3
)[4])
376 debug_printf("llvmpipe triangle\n");
377 for (i
= 0; i
< 1 + setup
->fs
.nr_inputs
; i
++) {
378 debug_printf(" v1[%d]: %f %f %f %f\n", i
,
379 v1
[i
][0], v1
[i
][1], v1
[i
][2], v1
[i
][3]);
381 for (i
= 0; i
< 1 + setup
->fs
.nr_inputs
; i
++) {
382 debug_printf(" v2[%d]: %f %f %f %f\n", i
,
383 v2
[i
][0], v2
[i
][1], v2
[i
][2], v2
[i
][3]);
385 for (i
= 0; i
< 1 + setup
->fs
.nr_inputs
; i
++) {
386 debug_printf(" v3[%d]: %f %f %f %f\n", i
,
387 v3
[i
][0], v3
[i
][1], v3
[i
][2], v3
[i
][3]);
392 lp_rast_cmd lp_rast_tri_tab
[8] = {
393 NULL
, /* should be impossible */
404 * Do basic setup for triangle rasterization and determine which
405 * framebuffer tiles are touched. Put the triangle in the scene's
406 * bins for the tiles which we overlap.
409 do_triangle_ccw(struct lp_setup_context
*setup
,
410 const float (*v1
)[4],
411 const float (*v2
)[4],
412 const float (*v3
)[4],
413 boolean frontfacing
)
416 struct lp_scene
*scene
= lp_setup_get_current_scene(setup
);
417 struct lp_fragment_shader_variant
*variant
= setup
->fs
.current
.variant
;
418 struct lp_rast_triangle
*tri
;
419 struct tri_info info
;
421 int minx
, maxx
, miny
, maxy
;
422 int ix0
, ix1
, iy0
, iy1
;
428 print_triangle(setup
, v1
, v2
, v3
);
430 if (setup
->scissor_test
) {
438 tri
= alloc_triangle(scene
,
446 tri
->v
[0][0] = v1
[0][0];
447 tri
->v
[1][0] = v2
[0][0];
448 tri
->v
[2][0] = v3
[0][0];
449 tri
->v
[0][1] = v1
[0][1];
450 tri
->v
[1][1] = v2
[0][1];
451 tri
->v
[2][1] = v3
[0][1];
454 /* x/y positions in fixed point */
455 info
.x
[0] = subpixel_snap(v1
[0][0] - setup
->pixel_offset
);
456 info
.x
[1] = subpixel_snap(v2
[0][0] - setup
->pixel_offset
);
457 info
.x
[2] = subpixel_snap(v3
[0][0] - setup
->pixel_offset
);
458 info
.y
[0] = subpixel_snap(v1
[0][1] - setup
->pixel_offset
);
459 info
.y
[1] = subpixel_snap(v2
[0][1] - setup
->pixel_offset
);
460 info
.y
[2] = subpixel_snap(v3
[0][1] - setup
->pixel_offset
);
462 tri
->plane
[0].dcdy
= info
.x
[0] - info
.x
[1];
463 tri
->plane
[1].dcdy
= info
.x
[1] - info
.x
[2];
464 tri
->plane
[2].dcdy
= info
.x
[2] - info
.x
[0];
466 tri
->plane
[0].dcdx
= info
.y
[0] - info
.y
[1];
467 tri
->plane
[1].dcdx
= info
.y
[1] - info
.y
[2];
468 tri
->plane
[2].dcdx
= info
.y
[2] - info
.y
[0];
470 area
= (tri
->plane
[0].dcdy
* tri
->plane
[2].dcdx
-
471 tri
->plane
[2].dcdy
* tri
->plane
[0].dcdx
);
475 /* Cull non-ccw and zero-sized triangles.
477 * XXX: subject to overflow??
480 lp_scene_putback_data( scene
, tri_bytes
);
481 LP_COUNT(nr_culled_tris
);
485 /* Bounding rectangle (in pixels) */
487 /* Yes this is necessary to accurately calculate bounding boxes
488 * with the two fill-conventions we support. GL (normally) ends
489 * up needing a bottom-left fill convention, which requires
490 * slightly different rounding.
492 int adj
= (setup
->pixel_offset
!= 0) ? 1 : 0;
494 minx
= (MIN3(info
.x
[0], info
.x
[1], info
.x
[2]) + (FIXED_ONE
-1)) >> FIXED_ORDER
;
495 maxx
= (MAX3(info
.x
[0], info
.x
[1], info
.x
[2]) + (FIXED_ONE
-1)) >> FIXED_ORDER
;
496 miny
= (MIN3(info
.y
[0], info
.y
[1], info
.y
[2]) + (FIXED_ONE
-1) + adj
) >> FIXED_ORDER
;
497 maxy
= (MAX3(info
.y
[0], info
.y
[1], info
.y
[2]) + (FIXED_ONE
-1) + adj
) >> FIXED_ORDER
;
500 if (setup
->scissor_test
) {
501 minx
= MAX2(minx
, setup
->scissor
.current
.minx
);
502 maxx
= MIN2(maxx
, setup
->scissor
.current
.maxx
);
503 miny
= MAX2(miny
, setup
->scissor
.current
.miny
);
504 maxy
= MIN2(maxy
, setup
->scissor
.current
.maxy
);
507 minx
= MAX2(minx
, 0);
508 miny
= MAX2(miny
, 0);
509 maxx
= MIN2(maxx
, scene
->fb
.width
);
510 maxy
= MIN2(maxy
, scene
->fb
.height
);
514 if (miny
>= maxy
|| minx
>= maxx
) {
515 lp_scene_putback_data( scene
, tri_bytes
);
516 LP_COUNT(nr_culled_tris
);
522 info
.pixel_offset
= setup
->pixel_offset
;
526 info
.dx01
= info
.v0
[0][0] - info
.v1
[0][0];
527 info
.dx20
= info
.v2
[0][0] - info
.v0
[0][0];
528 info
.dy01
= info
.v0
[0][1] - info
.v1
[0][1];
529 info
.dy20
= info
.v2
[0][1] - info
.v0
[0][1];
530 info
.oneoverarea
= 1.0 / (info
.dx01
* info
.dy20
- info
.dx20
* info
.dy01
);
531 info
.frontfacing
= frontfacing
;
533 /* Setup parameter interpolants:
535 setup_tri_coefficients( setup
, tri
, &info
);
537 tri
->inputs
.facing
= frontfacing
? 1.0F
: -1.0F
;
541 for (i
= 0; i
< 3; i
++) {
542 struct lp_rast_plane
*plane
= &tri
->plane
[i
];
544 /* half-edge constants, will be interated over the whole render
547 plane
->c
= plane
->dcdx
* info
.x
[i
] - plane
->dcdy
* info
.y
[i
];
549 /* correct for top-left vs. bottom-left fill convention.
551 * note that we're overloading gl_rasterization_rules to mean
552 * both (0.5,0.5) pixel centers *and* bottom-left filling
555 * GL actually has a top-left filling convention, but GL's
556 * notion of "top" differs from gallium's...
558 * Also, sometimes (in FBO cases) GL will render upside down
559 * to its usual method, in which case it will probably want
560 * to use the opposite, top-left convention.
562 if (plane
->dcdx
< 0) {
563 /* both fill conventions want this - adjust for left edges */
566 else if (plane
->dcdx
== 0) {
567 if (setup
->pixel_offset
== 0) {
568 /* correct for top-left fill convention:
570 if (plane
->dcdy
> 0) plane
->c
++;
573 /* correct for bottom-left fill convention:
575 if (plane
->dcdy
< 0) plane
->c
++;
579 plane
->dcdx
*= FIXED_ONE
;
580 plane
->dcdy
*= FIXED_ONE
;
582 /* find trivial reject offsets for each edge for a single-pixel
583 * sized block. These will be scaled up at each recursive level to
584 * match the active blocksize. Scaling in this way works best if
585 * the blocks are square.
588 if (plane
->dcdx
< 0) plane
->eo
-= plane
->dcdx
;
589 if (plane
->dcdy
> 0) plane
->eo
+= plane
->dcdy
;
591 /* Calculate trivial accept offsets from the above.
593 plane
->ei
= plane
->dcdy
- plane
->dcdx
- plane
->eo
;
595 plane
->step
= tri
->step
[i
];
597 /* Fill in the inputs.step[][] arrays.
598 * We've manually unrolled some loops here.
600 #define SETUP_STEP(j, x, y) \
601 tri->step[i][j] = y * plane->dcdy - x * plane->dcdx
615 SETUP_STEP(10, 0, 3);
616 SETUP_STEP(11, 1, 3);
618 SETUP_STEP(12, 2, 2);
619 SETUP_STEP(13, 3, 2);
620 SETUP_STEP(14, 2, 3);
621 SETUP_STEP(15, 3, 3);
627 * When rasterizing scissored tris, use the intersection of the
628 * triangle bounding box and the scissor rect to generate the
631 * This permits us to cut off the triangle "tails" that are present
632 * in the intermediate recursive levels caused when two of the
633 * triangles edges don't diverge quickly enough to trivially reject
634 * exterior blocks from the triangle.
636 * It's not really clear if it's worth worrying about these tails,
637 * but since we generate the planes for each scissored tri, it's
638 * free to trim them in this case.
640 * Note that otherwise, the scissor planes only vary in 'C' value,
641 * and even then only on state-changes. Could alternatively store
642 * these planes elsewhere.
644 if (nr_planes
== 7) {
645 tri
->plane
[3].step
= step_scissor_minx
;
646 tri
->plane
[3].dcdx
= -1;
647 tri
->plane
[3].dcdy
= 0;
648 tri
->plane
[3].c
= 1-minx
;
649 tri
->plane
[3].ei
= 0;
650 tri
->plane
[3].eo
= 1;
652 tri
->plane
[4].step
= step_scissor_maxx
;
653 tri
->plane
[4].dcdx
= 1;
654 tri
->plane
[4].dcdy
= 0;
655 tri
->plane
[4].c
= maxx
;
656 tri
->plane
[4].ei
= -1;
657 tri
->plane
[4].eo
= 0;
659 tri
->plane
[5].step
= step_scissor_miny
;
660 tri
->plane
[5].dcdx
= 0;
661 tri
->plane
[5].dcdy
= 1;
662 tri
->plane
[5].c
= 1-miny
;
663 tri
->plane
[5].ei
= 0;
664 tri
->plane
[5].eo
= 1;
666 tri
->plane
[6].step
= step_scissor_maxy
;
667 tri
->plane
[6].dcdx
= 0;
668 tri
->plane
[6].dcdy
= -1;
669 tri
->plane
[6].c
= maxy
;
670 tri
->plane
[6].ei
= -1;
671 tri
->plane
[6].eo
= 0;
676 * All fields of 'tri' are now set. The remaining code here is
677 * concerned with binning.
680 /* Convert to tile coordinates, and inclusive ranges:
682 ix0
= minx
/ TILE_SIZE
;
683 iy0
= miny
/ TILE_SIZE
;
684 ix1
= (maxx
-1) / TILE_SIZE
;
685 iy1
= (maxy
-1) / TILE_SIZE
;
688 * Clamp to framebuffer size
690 assert(ix0
== MAX2(ix0
, 0));
691 assert(iy0
== MAX2(iy0
, 0));
692 assert(ix1
== MIN2(ix1
, scene
->tiles_x
- 1));
693 assert(iy1
== MIN2(iy1
, scene
->tiles_y
- 1));
695 /* Determine which tile(s) intersect the triangle's bounding box
697 if (iy0
== iy1
&& ix0
== ix1
)
699 /* Triangle is contained in a single tile:
701 lp_scene_bin_command( scene
, ix0
, iy0
,
702 lp_rast_tri_tab
[nr_planes
],
703 lp_rast_arg_triangle(tri
, (1<<nr_planes
)-1) );
714 for (i
= 0; i
< nr_planes
; i
++) {
715 c
[i
] = (tri
->plane
[i
].c
+
716 tri
->plane
[i
].dcdy
* iy0
* TILE_SIZE
-
717 tri
->plane
[i
].dcdx
* ix0
* TILE_SIZE
);
719 ei
[i
] = tri
->plane
[i
].ei
<< TILE_ORDER
;
720 eo
[i
] = tri
->plane
[i
].eo
<< TILE_ORDER
;
721 xstep
[i
] = -(tri
->plane
[i
].dcdx
<< TILE_ORDER
);
722 ystep
[i
] = tri
->plane
[i
].dcdy
<< TILE_ORDER
;
727 /* Test tile-sized blocks against the triangle.
728 * Discard blocks fully outside the tri. If the block is fully
729 * contained inside the tri, bin an lp_rast_shade_tile command.
730 * Else, bin a lp_rast_triangle command.
732 for (y
= iy0
; y
<= iy1
; y
++)
734 boolean in
= FALSE
; /* are we inside the triangle? */
737 for (i
= 0; i
< nr_planes
; i
++)
740 for (x
= ix0
; x
<= ix1
; x
++)
745 for (i
= 0; i
< nr_planes
; i
++) {
746 int planeout
= cx
[i
] + eo
[i
];
747 int planepartial
= cx
[i
] + ei
[i
] - 1;
748 out
|= (planeout
>> 31);
749 partial
|= (planepartial
>> 31) & (1<<i
);
755 break; /* exiting triangle, all done with this row */
756 LP_COUNT(nr_empty_64
);
759 /* Not trivially accepted by at least one plane -
760 * rasterize/shade partial tile
762 int count
= util_bitcount(partial
);
764 lp_scene_bin_command( scene
, x
, y
,
765 lp_rast_tri_tab
[count
],
766 lp_rast_arg_triangle(tri
, partial
) );
768 LP_COUNT(nr_partially_covered_64
);
771 /* triangle covers the whole tile- shade whole tile */
772 LP_COUNT(nr_fully_covered_64
);
774 if (variant
->opaque
&&
776 lp_scene_bin_reset( scene
, x
, y
);
777 lp_scene_bin_command( scene
, x
, y
,
779 lp_rast_arg_state(setup
->fs
.stored
) );
781 lp_scene_bin_command( scene
, x
, y
,
783 lp_rast_arg_inputs(&tri
->inputs
) );
786 /* Iterate cx values across the region:
788 for (i
= 0; i
< nr_planes
; i
++)
792 /* Iterate c values down the region:
794 for (i
= 0; i
< nr_planes
; i
++)
802 * Draw triangle if it's CW, cull otherwise.
804 static void triangle_cw( struct lp_setup_context
*setup
,
805 const float (*v0
)[4],
806 const float (*v1
)[4],
807 const float (*v2
)[4] )
809 do_triangle_ccw( setup
, v1
, v0
, v2
, !setup
->ccw_is_frontface
);
814 * Draw triangle if it's CCW, cull otherwise.
816 static void triangle_ccw( struct lp_setup_context
*setup
,
817 const float (*v0
)[4],
818 const float (*v1
)[4],
819 const float (*v2
)[4] )
821 do_triangle_ccw( setup
, v0
, v1
, v2
, setup
->ccw_is_frontface
);
827 * Draw triangle whether it's CW or CCW.
829 static void triangle_both( struct lp_setup_context
*setup
,
830 const float (*v0
)[4],
831 const float (*v1
)[4],
832 const float (*v2
)[4] )
834 /* edge vectors e = v0 - v2, f = v1 - v2 */
835 const float ex
= v0
[0][0] - v2
[0][0];
836 const float ey
= v0
[0][1] - v2
[0][1];
837 const float fx
= v1
[0][0] - v2
[0][0];
838 const float fy
= v1
[0][1] - v2
[0][1];
840 /* det = cross(e,f).z */
841 if (ex
* fy
- ey
* fx
< 0.0f
)
842 triangle_ccw( setup
, v0
, v1
, v2
);
844 triangle_cw( setup
, v0
, v1
, v2
);
848 static void triangle_nop( struct lp_setup_context
*setup
,
849 const float (*v0
)[4],
850 const float (*v1
)[4],
851 const float (*v2
)[4] )
857 lp_setup_choose_triangle( struct lp_setup_context
*setup
)
859 switch (setup
->cullmode
) {
861 setup
->triangle
= triangle_both
;
864 setup
->triangle
= setup
->ccw_is_frontface
? triangle_ccw
: triangle_cw
;
866 case PIPE_FACE_FRONT
:
867 setup
->triangle
= setup
->ccw_is_frontface
? triangle_cw
: triangle_ccw
;
870 setup
->triangle
= triangle_nop
;