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"
40 /* Convert 8x8 block into four runs of quads and render each in turn.
43 static void block_full( struct lp_rasterizer
*rast
,
44 const struct lp_rast_triangle
*tri
,
47 const unsigned masks
[4] = {~0, ~0, ~0, ~0};
50 for (iy
= 0; iy
< 8; iy
+= 2)
51 lp_rast_shade_quads(rast
, &tri
->inputs
, x
, y
+ iy
, masks
);
54 static void block_full( struct lp_rasterizer
*rast
,
55 const struct lp_rast_triangle
*tri
,
58 const unsigned masks
[4] = {~0, ~0, 0, 0}; /* FIXME: Wasting quads!!! */
61 for (iy
= 0; iy
< 4; iy
+= 2)
62 lp_rast_shade_quads(rast
, &tri
->inputs
, x
, y
+ iy
, masks
);
66 static INLINE
unsigned
67 do_quad( const struct lp_rast_triangle
*tri
,
69 int c1
, int c2
, int c3
)
71 const int xstep1
= -tri
->dy12
* FIXED_ONE
;
72 const int xstep2
= -tri
->dy23
* FIXED_ONE
;
73 const int xstep3
= -tri
->dy31
* FIXED_ONE
;
75 const int ystep1
= tri
->dx12
* FIXED_ONE
;
76 const int ystep2
= tri
->dx23
* FIXED_ONE
;
77 const int ystep3
= tri
->dx31
* FIXED_ONE
;
86 if (c1
+ xstep1
> 0 &&
91 if (c1
+ ystep1
> 0 &&
96 if (c1
+ ystep1
+ xstep1
> 0 &&
97 c2
+ ystep2
+ xstep2
> 0 &&
98 c3
+ ystep3
+ xstep3
> 0)
104 /* Evaluate each pixel in a block, generate a mask and possibly render
108 do_block( struct lp_rasterizer
*rast
,
109 const struct lp_rast_triangle
*tri
,
115 const int step
= 2 * FIXED_ONE
;
117 const int xstep1
= -step
* tri
->dy12
;
118 const int xstep2
= -step
* tri
->dy23
;
119 const int xstep3
= -step
* tri
->dy31
;
121 const int ystep1
= step
* tri
->dx12
;
122 const int ystep2
= step
* tri
->dx23
;
123 const int ystep3
= step
* tri
->dx31
;
127 for (iy
= 0; iy
< BLOCKSIZE
; iy
+= 2) {
132 unsigned masks
[4] = {0, 0, 0, 0};
134 for (ix
= 0; ix
< BLOCKSIZE
; ix
+= 2) {
136 masks
[ix
>> 1] = do_quad(tri
, x
+ ix
, y
+ iy
, cx1
, cx2
, cx3
);
143 if(masks
[0] || masks
[1] || masks
[2] || masks
[3])
144 lp_rast_shade_quads(rast
, &tri
->inputs
, x
, y
+ iy
, masks
);
155 /* Scan the tile in chunks and figure out which pixels to rasterize
158 void lp_rast_triangle( struct lp_rasterizer
*rast
,
159 const union lp_rast_cmd_arg arg
)
161 const struct lp_rast_triangle
*tri
= arg
.triangle
;
163 const int step
= BLOCKSIZE
* FIXED_ONE
;
165 int ei1
= tri
->ei1
* step
;
166 int ei2
= tri
->ei2
* step
;
167 int ei3
= tri
->ei3
* step
;
169 int eo1
= tri
->eo1
* step
;
170 int eo2
= tri
->eo2
* step
;
171 int eo3
= tri
->eo3
* step
;
173 int xstep1
= -step
* tri
->dy12
;
174 int xstep2
= -step
* tri
->dy23
;
175 int xstep3
= -step
* tri
->dy31
;
177 int ystep1
= step
* tri
->dx12
;
178 int ystep2
= step
* tri
->dx23
;
179 int ystep3
= step
* tri
->dx31
;
181 /* Clamp to tile dimensions:
183 int minx
= MAX2(tri
->minx
, rast
->x
);
184 int miny
= MAX2(tri
->miny
, rast
->y
);
185 int maxx
= MIN2(tri
->maxx
, rast
->x
+ TILE_SIZE
);
186 int maxy
= MIN2(tri
->maxy
, rast
->y
+ TILE_SIZE
);
192 debug_printf("%s\n", __FUNCTION__
);
194 if (miny
== maxy
|| minx
== maxx
) {
195 debug_printf("%s: non-intersecting triangle in bin\n", __FUNCTION__
);
199 minx
&= ~(BLOCKSIZE
-1);
200 miny
&= ~(BLOCKSIZE
-1);
202 x0
= minx
<< FIXED_ORDER
;
203 y0
= miny
<< FIXED_ORDER
;
205 c1
= tri
->c1
+ tri
->dx12
* y0
- tri
->dy12
* x0
;
206 c2
= tri
->c2
+ tri
->dx23
* y0
- tri
->dy23
* x0
;
207 c3
= tri
->c3
+ tri
->dx31
* y0
- tri
->dy31
* x0
;
209 for (y
= miny
; y
< maxy
; y
+= BLOCKSIZE
)
215 for (x
= minx
; x
< maxx
; x
+= BLOCKSIZE
)
222 else if (cx1
+ ei1
> 0 &&
226 block_full(rast
, tri
, x
, y
); /* trivial accept */
230 do_block(rast
, tri
, x
, y
, cx1
, cx2
, cx3
);
233 /* Iterate cx values across the region:
240 /* Iterate c values down the region: