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 * Add a 4x4 block of pixels to the block list.
42 * All pixels are known to be inside the triangle's bounds.
45 block_full_4( struct lp_rasterizer
*rast
, int x
, int y
)
47 const unsigned i
= rast
->nr_blocks
;
50 rast
->blocks
[i
].x
= x
;
51 rast
->blocks
[i
].y
= y
;
52 rast
->blocks
[i
].mask
= ~0;
58 * Add a 16x16 block of pixels to the block list.
59 * All pixels are known to be inside the triangle's bounds.
62 block_full_16( struct lp_rasterizer
*rast
, int x
, int y
)
67 for (iy
= 0; iy
< 16; iy
+= 4)
68 for (ix
= 0; ix
< 16; ix
+= 4)
69 block_full_4(rast
, x
+ ix
, y
+ iy
);
74 * Evaluate each pixel in a 4x4 block to determine if it lies within
75 * the triangle's bounds.
76 * Generate a mask of in/out flags and add the block to the blocks list.
79 do_block_4( struct lp_rasterizer
*rast
,
80 const struct lp_rast_triangle
*tri
,
92 for (i
= 0; i
< 16; i
++)
93 mask
|= (~(((c1
+ tri
->step
[0][i
]) |
94 (c2
+ tri
->step
[1][i
]) |
95 (c3
+ tri
->step
[2][i
])) >> 31)) & (1 << i
);
97 /* As we do trivial reject already, masks should rarely be all zero:
100 const unsigned i
= rast
->nr_blocks
;
101 rast
->blocks
[i
].x
= x
;
102 rast
->blocks
[i
].y
= y
;
103 rast
->blocks
[i
].mask
= mask
;
110 * Evaluate a 16x16 block of pixels to determine which 4x4 subblocks are in/out
111 * of the triangle's bounds.
114 do_block_16( struct lp_rasterizer
*rast
,
115 const struct lp_rast_triangle
*tri
,
123 int ei1
= tri
->ei1
<< 2;
124 int ei2
= tri
->ei2
<< 2;
125 int ei3
= tri
->ei3
<< 2;
127 int eo1
= tri
->eo1
<< 2;
128 int eo2
= tri
->eo2
<< 2;
129 int eo3
= tri
->eo3
<< 2;
134 for (iy
= 0; iy
< 16; iy
+=4) {
135 for (ix
= 0; ix
< 16; ix
+=4, i
++) {
136 int cx1
= c1
+ (tri
->step
[0][i
] << 2);
137 int cx2
= c2
+ (tri
->step
[1][i
] << 2);
138 int cx3
= c3
+ (tri
->step
[2][i
] << 2);
143 /* the block is completely outside the triangle - nop */
145 else if (cx1
+ ei1
> 0 &&
148 /* the block is completely inside the triangle */
149 block_full_4(rast
, x
+ix
, y
+iy
);
152 /* the block is partially in/out of the triangle */
153 do_block_4(rast
, tri
, x
+ix
, y
+iy
, cx1
, cx2
, cx3
);
161 * Scan the tile in chunks and figure out which pixels to rasterize
165 lp_rast_triangle( struct lp_rasterizer
*rast
,
166 const union lp_rast_cmd_arg arg
)
168 const struct lp_rast_triangle
*tri
= arg
.triangle
;
175 int c1
= tri
->c1
+ tri
->dx12
* y
- tri
->dy12
* x
;
176 int c2
= tri
->c2
+ tri
->dx23
* y
- tri
->dy23
* x
;
177 int c3
= tri
->c3
+ tri
->dx31
* y
- tri
->dy31
* x
;
179 int ei1
= tri
->ei1
<< 4;
180 int ei2
= tri
->ei2
<< 4;
181 int ei3
= tri
->ei3
<< 4;
183 int eo1
= tri
->eo1
<< 4;
184 int eo2
= tri
->eo2
<< 4;
185 int eo3
= tri
->eo3
<< 4;
187 debug_printf("%s\n", __FUNCTION__
);
191 /* Walk over the tile to build a list of 4x4 pixel blocks which will
192 * be filled/shaded. We do this at two granularities: 16x16 blocks
193 * and then 4x4 blocks.
195 for (iy
= 0; iy
< TILE_SIZE
; iy
+= 16) {
196 for (ix
= 0; ix
< TILE_SIZE
; ix
+= 16, i
++) {
197 int cx1
= c1
+ (tri
->step
[0][i
] << 4);
198 int cx2
= c2
+ (tri
->step
[1][i
] << 4);
199 int cx3
= c3
+ (tri
->step
[2][i
] << 4);
204 /* the block is completely outside the triangle - nop */
206 else if (cx1
+ ei1
> 0 &&
209 /* the block is completely inside the triangle */
210 block_full_16(rast
, x
+ix
, y
+iy
);
213 /* the block is partially in/out of the triangle */
214 do_block_16(rast
, tri
, x
+ix
, y
+iy
, cx1
, cx2
, cx3
);
219 /* Shade the 4x4 pixel blocks */
220 for (i
= 0; i
< rast
->nr_blocks
; i
++)
221 lp_rast_shade_quads(rast
, &tri
->inputs
,
224 rast
->blocks
[i
].mask
);