6b5bee4af3c96322f687eef3049472ddee659ec0
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 float c1
, float c2
, float c3
)
71 float xstep1
= -tri
->dy12
;
72 float xstep2
= -tri
->dy23
;
73 float xstep3
= -tri
->dy31
;
75 float ystep1
= tri
->dx12
;
76 float ystep2
= tri
->dx23
;
77 float ystep3
= tri
->dx31
;
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
,
117 float xstep1
= -step
* tri
->dy12
;
118 float xstep2
= -step
* tri
->dy23
;
119 float xstep3
= -step
* tri
->dy31
;
121 float ystep1
= step
* tri
->dx12
;
122 float ystep2
= step
* tri
->dx23
;
123 float 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 lp_rast_shade_quads(rast
, &tri
->inputs
, x
, y
+ iy
, masks
);
154 /* Scan the tile in chunks and figure out which pixels to rasterize
157 void lp_rast_triangle( struct lp_rasterizer
*rast
,
158 const union lp_rast_cmd_arg arg
)
160 const struct lp_rast_triangle
*tri
= arg
.triangle
;
162 const int step
= BLOCKSIZE
;
164 float ei1
= tri
->ei1
* step
;
165 float ei2
= tri
->ei2
* step
;
166 float ei3
= tri
->ei3
* step
;
168 float eo1
= tri
->eo1
* step
;
169 float eo2
= tri
->eo2
* step
;
170 float eo3
= tri
->eo3
* step
;
172 float xstep1
= -step
* tri
->dy12
;
173 float xstep2
= -step
* tri
->dy23
;
174 float xstep3
= -step
* tri
->dy31
;
176 float ystep1
= step
* tri
->dx12
;
177 float ystep2
= step
* tri
->dx23
;
178 float ystep3
= step
* tri
->dx31
;
180 /* Clamp to tile dimensions:
182 int minx
= MAX2(tri
->minx
, rast
->x
);
183 int miny
= MAX2(tri
->miny
, rast
->y
);
184 int maxx
= MIN2(tri
->maxx
, rast
->x
+ TILE_SIZE
);
185 int maxy
= MIN2(tri
->maxy
, rast
->y
+ TILE_SIZE
);
191 debug_printf("%s\n", __FUNCTION__
);
193 if (miny
== maxy
|| minx
== maxx
) {
194 debug_printf("%s: non-intersecting triangle in bin\n", __FUNCTION__
);
204 c1
= tri
->c1
+ tri
->dx12
* y0
- tri
->dy12
* x0
;
205 c2
= tri
->c2
+ tri
->dx23
* y0
- tri
->dy23
* x0
;
206 c3
= tri
->c3
+ tri
->dx31
* y0
- tri
->dy31
* x0
;
208 for (y
= miny
; y
< maxy
; y
+= step
)
214 for (x
= minx
; x
< maxx
; x
+= step
)
221 else if (cx1
+ ei1
> 0 &&
225 block_full(rast
, tri
, x
, y
); /* trivial accept */
229 do_block(rast
, tri
, x
, y
, cx1
, cx2
, cx3
);
232 /* Iterate cx values across the region:
239 /* Iterate c values down the region: