9976996719aebb5cb941411d367e9122fe8d746b
1 /**************************************************************************
3 * Copyright 2007-2010 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
35 * Prototype for a 8 plane rasterizer function. Will codegenerate
38 * XXX: Varients for more/fewer planes.
39 * XXX: Need ways of dropping planes as we descend.
43 TAG(do_block_4
)(struct lp_rasterizer_task
*task
,
44 const struct lp_rast_triangle
*tri
,
45 const struct lp_rast_plane
*plane
,
49 unsigned mask
= 0xffff;
52 for (j
= 0; j
< NR_PLANES
; j
++) {
53 mask
&= ~build_mask_linear(c
[j
] - 1,
58 /* Now pass to the shader:
61 lp_rast_shade_quads_mask(task
, &tri
->inputs
, x
, y
, mask
);
65 * Evaluate a 16x16 block of pixels to determine which 4x4 subblocks are in/out
66 * of the triangle's bounds.
69 TAG(do_block_16
)(struct lp_rasterizer_task
*task
,
70 const struct lp_rast_triangle
*tri
,
71 const struct lp_rast_plane
*plane
,
75 unsigned outmask
, inmask
, partmask
, partial_mask
;
78 outmask
= 0; /* outside one or more trivial reject planes */
79 partmask
= 0; /* outside one or more trivial accept planes */
81 for (j
= 0; j
< NR_PLANES
; j
++) {
82 const int dcdx
= -plane
[j
].dcdx
* 4;
83 const int dcdy
= plane
[j
].dcdy
* 4;
84 const int cox
= plane
[j
].eo
* 4;
85 const int cio
= plane
[j
].ei
* 4 - 1;
87 build_masks(c
[j
] + cox
,
90 &outmask
, /* sign bits from c[i][0..15] + cox */
91 &partmask
); /* sign bits from c[i][0..15] + cio */
94 if (outmask
== 0xffff)
97 /* Mask of sub-blocks which are inside all trivial accept planes:
99 inmask
= ~partmask
& 0xffff;
101 /* Mask of sub-blocks which are inside all trivial reject planes,
102 * but outside at least one trivial accept plane:
104 partial_mask
= partmask
& ~outmask
;
106 assert((partial_mask
& inmask
) == 0);
108 LP_COUNT_ADD(nr_empty_4
, util_bitcount(0xffff & ~(partial_mask
| inmask
)));
110 /* Iterate over partials:
112 while (partial_mask
) {
113 int i
= ffs(partial_mask
) - 1;
114 int ix
= (i
& 3) * 4;
115 int iy
= (i
>> 2) * 4;
120 partial_mask
&= ~(1 << i
);
122 LP_COUNT(nr_partially_covered_4
);
124 for (j
= 0; j
< NR_PLANES
; j
++)
127 + plane
[j
].dcdy
* iy
);
129 TAG(do_block_4
)(task
, tri
, plane
, px
, py
, cx
);
132 /* Iterate over fulls:
135 int i
= ffs(inmask
) - 1;
136 int ix
= (i
& 3) * 4;
137 int iy
= (i
>> 2) * 4;
143 LP_COUNT(nr_fully_covered_4
);
144 block_full_4(task
, tri
, px
, py
);
150 * Scan the tile in chunks and figure out which pixels to rasterize
154 TAG(lp_rast_triangle
)(struct lp_rasterizer_task
*task
,
155 const union lp_rast_cmd_arg arg
)
157 const struct lp_rast_triangle
*tri
= arg
.triangle
.tri
;
158 unsigned plane_mask
= arg
.triangle
.plane_mask
;
159 const struct lp_rast_plane
*tri_plane
= GET_PLANES(tri
);
160 const int x
= task
->x
, y
= task
->y
;
161 struct lp_rast_plane plane
[NR_PLANES
];
163 unsigned outmask
, inmask
, partmask
, partial_mask
;
166 if (tri
->inputs
.disable
) {
167 /* This triangle was partially binned and has been disabled */
171 outmask
= 0; /* outside one or more trivial reject planes */
172 partmask
= 0; /* outside one or more trivial accept planes */
175 int i
= ffs(plane_mask
) - 1;
176 plane
[j
] = tri_plane
[i
];
177 plane_mask
&= ~(1 << i
);
178 c
[j
] = plane
[j
].c
+ plane
[j
].dcdy
* y
- plane
[j
].dcdx
* x
;
181 const int dcdx
= -plane
[j
].dcdx
* 16;
182 const int dcdy
= plane
[j
].dcdy
* 16;
183 const int cox
= plane
[j
].eo
* 16;
184 const int cio
= plane
[j
].ei
* 16 - 1;
186 build_masks(c
[j
] + cox
,
189 &outmask
, /* sign bits from c[i][0..15] + cox */
190 &partmask
); /* sign bits from c[i][0..15] + cio */
196 if (outmask
== 0xffff)
199 /* Mask of sub-blocks which are inside all trivial accept planes:
201 inmask
= ~partmask
& 0xffff;
203 /* Mask of sub-blocks which are inside all trivial reject planes,
204 * but outside at least one trivial accept plane:
206 partial_mask
= partmask
& ~outmask
;
208 assert((partial_mask
& inmask
) == 0);
210 LP_COUNT_ADD(nr_empty_16
, util_bitcount(0xffff & ~(partial_mask
| inmask
)));
212 /* Iterate over partials:
214 while (partial_mask
) {
215 int i
= ffs(partial_mask
) - 1;
216 int ix
= (i
& 3) * 16;
217 int iy
= (i
>> 2) * 16;
222 for (j
= 0; j
< NR_PLANES
; j
++)
225 + plane
[j
].dcdy
* iy
);
227 partial_mask
&= ~(1 << i
);
229 LP_COUNT(nr_partially_covered_16
);
230 TAG(do_block_16
)(task
, tri
, plane
, px
, py
, cx
);
233 /* Iterate over fulls:
236 int i
= ffs(inmask
) - 1;
237 int ix
= (i
& 3) * 16;
238 int iy
= (i
>> 2) * 16;
244 LP_COUNT(nr_fully_covered_16
);
245 block_full_16(task
, tri
, px
, py
);
249 #if defined(PIPE_ARCH_SSE) && defined(TRI_16)
250 /* XXX: special case this when intersection is not required.
251 * - tile completely within bbox,
252 * - bbox completely within tile.
255 TRI_16(struct lp_rasterizer_task
*task
,
256 const union lp_rast_cmd_arg arg
)
258 const struct lp_rast_triangle
*tri
= arg
.triangle
.tri
;
259 const struct lp_rast_plane
*plane
= GET_PLANES(tri
);
260 unsigned mask
= arg
.triangle
.plane_mask
;
261 unsigned outmask
, partial_mask
;
263 __m128i cstep4
[NR_PLANES
][4];
265 int x
= (mask
& 0xff);
268 outmask
= 0; /* outside one or more trivial reject planes */
273 for (j
= 0; j
< NR_PLANES
; j
++) {
274 const int dcdx
= -plane
[j
].dcdx
* 4;
275 const int dcdy
= plane
[j
].dcdy
* 4;
276 __m128i xdcdy
= _mm_set1_epi32(dcdy
);
278 cstep4
[j
][0] = _mm_setr_epi32(0, dcdx
, dcdx
*2, dcdx
*3);
279 cstep4
[j
][1] = _mm_add_epi32(cstep4
[j
][0], xdcdy
);
280 cstep4
[j
][2] = _mm_add_epi32(cstep4
[j
][1], xdcdy
);
281 cstep4
[j
][3] = _mm_add_epi32(cstep4
[j
][2], xdcdy
);
284 const int c
= plane
[j
].c
+ plane
[j
].dcdy
* y
- plane
[j
].dcdx
* x
;
285 const int cox
= plane
[j
].eo
* 4;
287 outmask
|= sign_bits4(cstep4
[j
], c
+ cox
);
291 if (outmask
== 0xffff)
295 /* Mask of sub-blocks which are inside all trivial reject planes,
296 * but outside at least one trivial accept plane:
298 partial_mask
= 0xffff & ~outmask
;
300 /* Iterate over partials:
302 while (partial_mask
) {
303 int i
= ffs(partial_mask
) - 1;
304 int ix
= (i
& 3) * 4;
305 int iy
= (i
>> 2) * 4;
308 unsigned mask
= 0xffff;
310 partial_mask
&= ~(1 << i
);
312 for (j
= 0; j
< NR_PLANES
; j
++) {
313 const int cx
= (plane
[j
].c
- 1
315 + plane
[j
].dcdy
* py
) * 4;
317 mask
&= ~sign_bits4(cstep4
[j
], cx
);
321 lp_rast_shade_quads_mask(task
, &tri
->inputs
, px
, py
, mask
);
326 #if defined(PIPE_ARCH_SSE) && defined(TRI_4)
328 TRI_4(struct lp_rasterizer_task
*task
,
329 const union lp_rast_cmd_arg arg
)
331 const struct lp_rast_triangle
*tri
= arg
.triangle
.tri
;
332 const struct lp_rast_plane
*plane
= GET_PLANES(tri
);
333 unsigned mask
= arg
.triangle
.plane_mask
;
334 const int x
= task
->x
+ (mask
& 0xff);
335 const int y
= task
->y
+ (mask
>> 8);
338 /* Iterate over partials:
341 unsigned mask
= 0xffff;
343 for (j
= 0; j
< NR_PLANES
; j
++) {
344 const int cx
= (plane
[j
].c
346 + plane
[j
].dcdy
* y
);
348 const int dcdx
= -plane
[j
].dcdx
;
349 const int dcdy
= plane
[j
].dcdy
;
350 __m128i xdcdy
= _mm_set1_epi32(dcdy
);
352 __m128i cstep0
= _mm_setr_epi32(cx
, cx
+ dcdx
, cx
+ dcdx
*2, cx
+ dcdx
*3);
353 __m128i cstep1
= _mm_add_epi32(cstep0
, xdcdy
);
354 __m128i cstep2
= _mm_add_epi32(cstep1
, xdcdy
);
355 __m128i cstep3
= _mm_add_epi32(cstep2
, xdcdy
);
357 __m128i cstep01
= _mm_packs_epi32(cstep0
, cstep1
);
358 __m128i cstep23
= _mm_packs_epi32(cstep2
, cstep3
);
359 __m128i result
= _mm_packs_epi16(cstep01
, cstep23
);
361 /* Extract the sign bits
363 mask
&= ~_mm_movemask_epi8(result
);
367 lp_rast_shade_quads_mask(task
, &tri
->inputs
, x
, y
, mask
);