1 /**************************************************************************
3 * Copyright 2007-2009 VMware, Inc.
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 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.
26 **************************************************************************/
29 * Rasterization for binned triangles within a tile
32 #include "util/u_math.h"
33 #include "lp_rast_priv.h"
34 #include "lp_tile_soa.h"
41 /* Render a 4x4 unmasked block:
43 static void block_full( struct lp_rasterizer
*rast
,
44 const struct lp_rast_triangle
*tri
,
49 lp_rast_shade_quads(rast
, &tri
->inputs
, x
, y
, mask
);
54 /* Evaluate each pixel in a block, generate a mask and possibly render
58 do_block( struct lp_rasterizer
*rast
,
59 const struct lp_rast_triangle
*tri
,
68 for (i
= 0; i
< 16; i
++)
69 mask
|= (~(((c1
+ tri
->step
[0][i
]) |
70 (c2
+ tri
->step
[1][i
]) |
71 (c3
+ tri
->step
[2][i
])) >> 31)) & (1 << i
);
74 /* As we do trivial reject already, masks should rarely be all
77 lp_rast_shade_quads(rast
, &tri
->inputs
, x
, y
, mask
);
82 /* Scan the tile in chunks and figure out which pixels to rasterize
85 void lp_rast_triangle( struct lp_rasterizer
*rast
,
86 const union lp_rast_cmd_arg arg
)
88 const struct lp_rast_triangle
*tri
= arg
.triangle
;
90 const int step
= BLOCKSIZE
;
92 int ei1
= tri
->ei1
* step
;
93 int ei2
= tri
->ei2
* step
;
94 int ei3
= tri
->ei3
* step
;
96 int eo1
= tri
->eo1
* step
;
97 int eo2
= tri
->eo2
* step
;
98 int eo3
= tri
->eo3
* step
;
100 int xstep1
= -step
* tri
->dy12
;
101 int xstep2
= -step
* tri
->dy23
;
102 int xstep3
= -step
* tri
->dy31
;
104 int ystep1
= step
* tri
->dx12
;
105 int ystep2
= step
* tri
->dx23
;
106 int ystep3
= step
* tri
->dx31
;
108 /* Clamp to tile dimensions:
110 int minx
= MAX2(tri
->minx
, rast
->x
);
111 int miny
= MAX2(tri
->miny
, rast
->y
);
112 int maxx
= MIN2(tri
->maxx
, rast
->x
+ TILE_SIZE
);
113 int maxy
= MIN2(tri
->maxy
, rast
->y
+ TILE_SIZE
);
118 debug_printf("%s\n", __FUNCTION__
);
120 if (miny
== maxy
|| minx
== maxx
) {
121 debug_printf("%s: non-intersecting triangle in bin\n", __FUNCTION__
);
125 minx
&= ~(BLOCKSIZE
-1);
126 miny
&= ~(BLOCKSIZE
-1);
128 c1
= tri
->c1
+ tri
->dx12
* miny
- tri
->dy12
* minx
;
129 c2
= tri
->c2
+ tri
->dx23
* miny
- tri
->dy23
* minx
;
130 c3
= tri
->c3
+ tri
->dx31
* miny
- tri
->dy31
* minx
;
132 for (y
= miny
; y
< maxy
; y
+= BLOCKSIZE
)
138 for (x
= minx
; x
< maxx
; x
+= BLOCKSIZE
)
145 else if (cx1
+ ei1
> 0 &&
149 block_full(rast
, tri
, x
, y
); /* trivial accept */
153 do_block(rast
, tri
, x
, y
, cx1
, cx2
, cx3
);
156 /* Iterate cx values across the region:
163 /* Iterate c values down the region: