5f22aca668a32f2c3cae74ee4b4ecbb2c1761ed9
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 /* Render a 4x4 unmasked block:
42 static void block_full( struct lp_rasterizer
*rast
,
43 const struct lp_rast_triangle
*tri
,
46 static const uint32_t ALIGN16_ATTRIB masks
[4][4] =
52 lp_rast_shade_quads(rast
, &tri
->inputs
, x
, y
, &masks
[0][0]);
57 do_quad( const struct lp_rast_triangle
*tri
,
58 int c1
, int c2
, int c3
,
61 const int xstep1
= -tri
->dy12
;
62 const int xstep2
= -tri
->dy23
;
63 const int xstep3
= -tri
->dy31
;
65 const int ystep1
= tri
->dx12
;
66 const int ystep2
= tri
->dx23
;
67 const int ystep3
= tri
->dx31
;
73 mask
[1] = ~(((c1
+ xstep1
) |
75 (c3
+ xstep3
)) >> 31);
77 mask
[2] = ~(((c1
+ ystep1
) |
79 (c3
+ ystep3
)) >> 31);
81 mask
[3] = ~(((c1
+ ystep1
+ xstep1
) |
82 (c2
+ ystep2
+ xstep2
) |
83 (c3
+ ystep3
+ xstep3
)) >> 31);
86 /* Evaluate each pixel in a block, generate a mask and possibly render
90 do_block( struct lp_rasterizer
*rast
,
91 const struct lp_rast_triangle
*tri
,
99 const int xstep1
= -step
* tri
->dy12
;
100 const int xstep2
= -step
* tri
->dy23
;
101 const int xstep3
= -step
* tri
->dy31
;
103 const int ystep1
= step
* tri
->dx12
;
104 const int ystep2
= step
* tri
->dx23
;
105 const int ystep3
= step
* tri
->dx31
;
108 uint32_t ALIGN16_ATTRIB mask
[4][4];
111 for (iy
= 0; iy
< 4; iy
+= 2) {
116 for (ix
= 0; ix
< 2; ix
++) {
118 do_quad(tri
, cx1
, cx2
, cx3
, (int32_t *)mask
[iy
+ix
]);
130 /* As we do trivial reject already, masks should rarely be all
133 lp_rast_shade_quads(rast
, &tri
->inputs
, x
, y
, &mask
[0][0] );
138 /* Scan the tile in chunks and figure out which pixels to rasterize
141 void lp_rast_triangle( struct lp_rasterizer
*rast
,
142 const union lp_rast_cmd_arg arg
)
144 const struct lp_rast_triangle
*tri
= arg
.triangle
;
146 const int step
= BLOCKSIZE
;
148 int ei1
= tri
->ei1
* step
;
149 int ei2
= tri
->ei2
* step
;
150 int ei3
= tri
->ei3
* step
;
152 int eo1
= tri
->eo1
* step
;
153 int eo2
= tri
->eo2
* step
;
154 int eo3
= tri
->eo3
* step
;
156 int xstep1
= -step
* tri
->dy12
;
157 int xstep2
= -step
* tri
->dy23
;
158 int xstep3
= -step
* tri
->dy31
;
160 int ystep1
= step
* tri
->dx12
;
161 int ystep2
= step
* tri
->dx23
;
162 int ystep3
= step
* tri
->dx31
;
164 /* Clamp to tile dimensions:
166 int minx
= MAX2(tri
->minx
, rast
->x
);
167 int miny
= MAX2(tri
->miny
, rast
->y
);
168 int maxx
= MIN2(tri
->maxx
, rast
->x
+ TILE_SIZE
);
169 int maxy
= MIN2(tri
->maxy
, rast
->y
+ TILE_SIZE
);
174 debug_printf("%s\n", __FUNCTION__
);
176 if (miny
== maxy
|| minx
== maxx
) {
177 debug_printf("%s: non-intersecting triangle in bin\n", __FUNCTION__
);
181 minx
&= ~(BLOCKSIZE
-1);
182 miny
&= ~(BLOCKSIZE
-1);
184 c1
= tri
->c1
+ tri
->dx12
* miny
- tri
->dy12
* minx
;
185 c2
= tri
->c2
+ tri
->dx23
* miny
- tri
->dy23
* minx
;
186 c3
= tri
->c3
+ tri
->dx31
* miny
- tri
->dy31
* minx
;
188 for (y
= miny
; y
< maxy
; y
+= BLOCKSIZE
)
194 for (x
= minx
; x
< maxx
; x
+= BLOCKSIZE
)
201 else if (cx1
+ ei1
> 0 &&
205 block_full(rast
, tri
, x
, y
); /* trivial accept */
209 do_block(rast
, tri
, x
, y
, cx1
, cx2
, cx3
);
212 /* Iterate cx values across the region:
219 /* Iterate c values down the region: