ee5cd71b74aa640f8c4a1c59d93345658634b0f6
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
33 #include "util/u_math.h"
36 #include "lp_rast_priv.h"
37 #include "lp_tile_soa.h"
43 * Shade all pixels in a 4x4 block.
46 block_full_4(struct lp_rasterizer_task
*task
,
47 const struct lp_rast_triangle
*tri
,
50 lp_rast_shade_quads_all(task
, &tri
->inputs
, x
, y
);
55 * Shade all pixels in a 16x16 block.
58 block_full_16(struct lp_rasterizer_task
*task
,
59 const struct lp_rast_triangle
*tri
,
65 for (iy
= 0; iy
< 16; iy
+= 4)
66 for (ix
= 0; ix
< 16; ix
+= 4)
67 block_full_4(task
, tri
, x
+ ix
, y
+ iy
);
70 #if !defined(PIPE_ARCH_SSE)
72 static INLINE
unsigned
73 build_mask_linear(int c
, int dcdx
, int dcdy
)
82 mask
|= ((c0
+ 0 * dcdx
) >> 31) & (1 << 0);
83 mask
|= ((c0
+ 1 * dcdx
) >> 31) & (1 << 1);
84 mask
|= ((c0
+ 2 * dcdx
) >> 31) & (1 << 2);
85 mask
|= ((c0
+ 3 * dcdx
) >> 31) & (1 << 3);
86 mask
|= ((c1
+ 0 * dcdx
) >> 31) & (1 << 4);
87 mask
|= ((c1
+ 1 * dcdx
) >> 31) & (1 << 5);
88 mask
|= ((c1
+ 2 * dcdx
) >> 31) & (1 << 6);
89 mask
|= ((c1
+ 3 * dcdx
) >> 31) & (1 << 7);
90 mask
|= ((c2
+ 0 * dcdx
) >> 31) & (1 << 8);
91 mask
|= ((c2
+ 1 * dcdx
) >> 31) & (1 << 9);
92 mask
|= ((c2
+ 2 * dcdx
) >> 31) & (1 << 10);
93 mask
|= ((c2
+ 3 * dcdx
) >> 31) & (1 << 11);
94 mask
|= ((c3
+ 0 * dcdx
) >> 31) & (1 << 12);
95 mask
|= ((c3
+ 1 * dcdx
) >> 31) & (1 << 13);
96 mask
|= ((c3
+ 2 * dcdx
) >> 31) & (1 << 14);
97 mask
|= ((c3
+ 3 * dcdx
) >> 31) & (1 << 15);
111 *outmask
|= build_mask_linear(c
, dcdx
, dcdy
);
112 *partmask
|= build_mask_linear(c
+ cdiff
, dcdx
, dcdy
);
116 lp_rast_triangle_3_16(struct lp_rasterizer_task
*task
,
117 const union lp_rast_cmd_arg arg
)
119 union lp_rast_cmd_arg arg2
;
121 arg2
.mask
= (1<<3)-1;
122 lp_rast_triangle_3(task
, arg2
);
126 lp_rast_triangle_3_4(struct lp_rasterizer_task
*task
,
127 const union lp_rast_cmd_arg arg
)
129 lp_rast_triangle_3_16(task
, arg
);
133 #include <emmintrin.h>
134 #include "util/u_sse.h"
145 __m128i cstep0
= _mm_setr_epi32(c
, c
+dcdx
, c
+dcdx
*2, c
+dcdx
*3);
146 __m128i xdcdy
= _mm_set1_epi32(dcdy
);
148 /* Get values across the quad
150 __m128i cstep1
= _mm_add_epi32(cstep0
, xdcdy
);
151 __m128i cstep2
= _mm_add_epi32(cstep1
, xdcdy
);
152 __m128i cstep3
= _mm_add_epi32(cstep2
, xdcdy
);
155 __m128i cstep01
, cstep23
, result
;
157 cstep01
= _mm_packs_epi32(cstep0
, cstep1
);
158 cstep23
= _mm_packs_epi32(cstep2
, cstep3
);
159 result
= _mm_packs_epi16(cstep01
, cstep23
);
161 *outmask
|= _mm_movemask_epi8(result
);
166 __m128i cio4
= _mm_set1_epi32(cdiff
);
167 __m128i cstep01
, cstep23
, result
;
169 cstep0
= _mm_add_epi32(cstep0
, cio4
);
170 cstep1
= _mm_add_epi32(cstep1
, cio4
);
171 cstep2
= _mm_add_epi32(cstep2
, cio4
);
172 cstep3
= _mm_add_epi32(cstep3
, cio4
);
174 cstep01
= _mm_packs_epi32(cstep0
, cstep1
);
175 cstep23
= _mm_packs_epi32(cstep2
, cstep3
);
176 result
= _mm_packs_epi16(cstep01
, cstep23
);
178 *partmask
|= _mm_movemask_epi8(result
);
183 static INLINE
unsigned
184 build_mask_linear(int c
, int dcdx
, int dcdy
)
186 __m128i cstep0
= _mm_setr_epi32(c
, c
+dcdx
, c
+dcdx
*2, c
+dcdx
*3);
187 __m128i xdcdy
= _mm_set1_epi32(dcdy
);
189 /* Get values across the quad
191 __m128i cstep1
= _mm_add_epi32(cstep0
, xdcdy
);
192 __m128i cstep2
= _mm_add_epi32(cstep1
, xdcdy
);
193 __m128i cstep3
= _mm_add_epi32(cstep2
, xdcdy
);
195 /* pack pairs of results into epi16
197 __m128i cstep01
= _mm_packs_epi32(cstep0
, cstep1
);
198 __m128i cstep23
= _mm_packs_epi32(cstep2
, cstep3
);
200 /* pack into epi8, preserving sign bits
202 __m128i result
= _mm_packs_epi16(cstep01
, cstep23
);
204 /* extract sign bits to create mask
206 return _mm_movemask_epi8(result
);
209 static INLINE
unsigned
210 sign_bits4(const __m128i
*cstep
, int cdiff
)
213 /* Adjust the step values
215 __m128i cio4
= _mm_set1_epi32(cdiff
);
216 __m128i cstep0
= _mm_add_epi32(cstep
[0], cio4
);
217 __m128i cstep1
= _mm_add_epi32(cstep
[1], cio4
);
218 __m128i cstep2
= _mm_add_epi32(cstep
[2], cio4
);
219 __m128i cstep3
= _mm_add_epi32(cstep
[3], cio4
);
223 __m128i cstep01
= _mm_packs_epi32(cstep0
, cstep1
);
224 __m128i cstep23
= _mm_packs_epi32(cstep2
, cstep3
);
225 __m128i result
= _mm_packs_epi16(cstep01
, cstep23
);
227 /* Extract the sign bits
229 return _mm_movemask_epi8(result
);
233 /* Special case for 3 plane triangle which is contained entirely
234 * within a 16x16 block.
237 lp_rast_triangle_3_16(struct lp_rasterizer_task
*task
,
238 const union lp_rast_cmd_arg arg
)
240 const struct lp_rast_triangle
*tri
= arg
.triangle
.tri
;
241 const struct lp_rast_plane
*plane
= tri
->plane
;
242 unsigned mask
= arg
.triangle
.plane_mask
;
243 const int x
= task
->x
+ (mask
& 0xff);
244 const int y
= task
->y
+ (mask
>> 8);
245 unsigned outmask
, inmask
, partmask
, partial_mask
;
247 __m128i cstep4
[3][4];
249 outmask
= 0; /* outside one or more trivial reject planes */
250 partmask
= 0; /* outside one or more trivial accept planes */
252 for (j
= 0; j
< 3; j
++) {
253 const int dcdx
= -plane
[j
].dcdx
* 4;
254 const int dcdy
= plane
[j
].dcdy
* 4;
255 __m128i xdcdy
= _mm_set1_epi32(dcdy
);
257 cstep4
[j
][0] = _mm_setr_epi32(0, dcdx
, dcdx
*2, dcdx
*3);
258 cstep4
[j
][1] = _mm_add_epi32(cstep4
[j
][0], xdcdy
);
259 cstep4
[j
][2] = _mm_add_epi32(cstep4
[j
][1], xdcdy
);
260 cstep4
[j
][3] = _mm_add_epi32(cstep4
[j
][2], xdcdy
);
263 const int c
= plane
[j
].c
+ plane
[j
].dcdy
* y
- plane
[j
].dcdx
* x
;
264 const int cox
= plane
[j
].eo
* 4;
265 const int cio
= plane
[j
].ei
* 4 - 1;
267 outmask
|= sign_bits4(cstep4
[j
], c
+ cox
);
268 partmask
|= sign_bits4(cstep4
[j
], c
+ cio
);
272 if (outmask
== 0xffff)
275 /* Mask of sub-blocks which are inside all trivial accept planes:
277 inmask
= ~partmask
& 0xffff;
279 /* Mask of sub-blocks which are inside all trivial reject planes,
280 * but outside at least one trivial accept plane:
282 partial_mask
= partmask
& ~outmask
;
284 assert((partial_mask
& inmask
) == 0);
286 /* Iterate over partials:
288 while (partial_mask
) {
289 int i
= ffs(partial_mask
) - 1;
290 int ix
= (i
& 3) * 4;
291 int iy
= (i
>> 2) * 4;
294 unsigned mask
= 0xffff;
296 partial_mask
&= ~(1 << i
);
298 for (j
= 0; j
< 3; j
++) {
299 const int cx
= (plane
[j
].c
301 + plane
[j
].dcdy
* py
) * 4;
303 mask
&= ~sign_bits4(cstep4
[j
], cx
);
307 lp_rast_shade_quads_mask(task
, &tri
->inputs
, px
, py
, mask
);
310 /* Iterate over fulls:
313 int i
= ffs(inmask
) - 1;
314 int ix
= (i
& 3) * 4;
315 int iy
= (i
>> 2) * 4;
321 block_full_4(task
, tri
, px
, py
);
327 lp_rast_triangle_3_4(struct lp_rasterizer_task
*task
,
328 const union lp_rast_cmd_arg arg
)
330 const struct lp_rast_triangle
*tri
= arg
.triangle
.tri
;
331 const struct lp_rast_plane
*plane
= tri
->plane
;
332 unsigned mask
= arg
.triangle
.plane_mask
;
333 const int x
= task
->x
+ (mask
& 0xff);
334 const int y
= task
->y
+ (mask
>> 8);
337 /* Iterate over partials:
340 unsigned mask
= 0xffff;
342 for (j
= 0; j
< 3; j
++) {
343 const int cx
= (plane
[j
].c
345 + plane
[j
].dcdy
* y
);
347 const int dcdx
= -plane
[j
].dcdx
;
348 const int dcdy
= plane
[j
].dcdy
;
349 __m128i xdcdy
= _mm_set1_epi32(dcdy
);
351 __m128i cstep0
= _mm_setr_epi32(cx
, cx
+ dcdx
, cx
+ dcdx
*2, cx
+ dcdx
*3);
352 __m128i cstep1
= _mm_add_epi32(cstep0
, xdcdy
);
353 __m128i cstep2
= _mm_add_epi32(cstep1
, xdcdy
);
354 __m128i cstep3
= _mm_add_epi32(cstep2
, xdcdy
);
356 __m128i cstep01
= _mm_packs_epi32(cstep0
, cstep1
);
357 __m128i cstep23
= _mm_packs_epi32(cstep2
, cstep3
);
358 __m128i result
= _mm_packs_epi16(cstep01
, cstep23
);
360 /* Extract the sign bits
362 mask
&= ~_mm_movemask_epi8(result
);
366 lp_rast_shade_quads_mask(task
, &tri
->inputs
, x
, y
, mask
);
378 #include "lp_rast_tri_tmp.h"
382 #include "lp_rast_tri_tmp.h"
386 #include "lp_rast_tri_tmp.h"
390 #include "lp_rast_tri_tmp.h"
394 #include "lp_rast_tri_tmp.h"
398 #include "lp_rast_tri_tmp.h"
402 #include "lp_rast_tri_tmp.h"
406 #include "lp_rast_tri_tmp.h"