dbaa8e023a4a70702147bb189706404397cb7400
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)
71 static INLINE
unsigned
72 build_mask(int c
, int dcdx
, int dcdy
)
81 mask
|= ((c0
+ 0 * dcdy
) >> 31) & (1 << 0);
82 mask
|= ((c0
+ 1 * dcdy
) >> 31) & (1 << 2);
83 mask
|= ((c0
+ 2 * dcdy
) >> 31) & (1 << 8);
84 mask
|= ((c0
+ 3 * dcdy
) >> 31) & (1 << 10);
85 mask
|= ((c1
+ 0 * dcdy
) >> 31) & (1 << 1);
86 mask
|= ((c1
+ 1 * dcdy
) >> 31) & (1 << 3);
87 mask
|= ((c1
+ 2 * dcdy
) >> 31) & (1 << 9);
88 mask
|= ((c1
+ 3 * dcdy
) >> 31) & (1 << 11);
89 mask
|= ((c2
+ 0 * dcdy
) >> 31) & (1 << 4);
90 mask
|= ((c2
+ 1 * dcdy
) >> 31) & (1 << 6);
91 mask
|= ((c2
+ 2 * dcdy
) >> 31) & (1 << 12);
92 mask
|= ((c2
+ 3 * dcdy
) >> 31) & (1 << 14);
93 mask
|= ((c3
+ 0 * dcdy
) >> 31) & (1 << 5);
94 mask
|= ((c3
+ 1 * dcdy
) >> 31) & (1 << 7);
95 mask
|= ((c3
+ 2 * dcdy
) >> 31) & (1 << 13);
96 mask
|= ((c3
+ 3 * dcdy
) >> 31) & (1 << 15);
102 static INLINE
unsigned
103 build_mask_linear(int c
, int dcdx
, int dcdy
)
112 mask
|= ((c0
+ 0 * dcdx
) >> 31) & (1 << 0);
113 mask
|= ((c0
+ 1 * dcdx
) >> 31) & (1 << 1);
114 mask
|= ((c0
+ 2 * dcdx
) >> 31) & (1 << 2);
115 mask
|= ((c0
+ 3 * dcdx
) >> 31) & (1 << 3);
116 mask
|= ((c1
+ 0 * dcdx
) >> 31) & (1 << 4);
117 mask
|= ((c1
+ 1 * dcdx
) >> 31) & (1 << 5);
118 mask
|= ((c1
+ 2 * dcdx
) >> 31) & (1 << 6);
119 mask
|= ((c1
+ 3 * dcdx
) >> 31) & (1 << 7);
120 mask
|= ((c2
+ 0 * dcdx
) >> 31) & (1 << 8);
121 mask
|= ((c2
+ 1 * dcdx
) >> 31) & (1 << 9);
122 mask
|= ((c2
+ 2 * dcdx
) >> 31) & (1 << 10);
123 mask
|= ((c2
+ 3 * dcdx
) >> 31) & (1 << 11);
124 mask
|= ((c3
+ 0 * dcdx
) >> 31) & (1 << 12);
125 mask
|= ((c3
+ 1 * dcdx
) >> 31) & (1 << 13);
126 mask
|= ((c3
+ 2 * dcdx
) >> 31) & (1 << 14);
127 mask
|= ((c3
+ 3 * dcdx
) >> 31) & (1 << 15);
141 *outmask
|= build_mask_linear(c
, dcdx
, dcdy
);
142 *partmask
|= build_mask_linear(c
+ cdiff
, dcdx
, dcdy
);
146 #include <emmintrin.h>
147 #include "util/u_sse.h"
158 __m128i cstep0
= _mm_setr_epi32(c
, c
+dcdx
, c
+dcdx
*2, c
+dcdx
*3);
159 __m128i xdcdy
= _mm_set1_epi32(dcdy
);
161 /* Get values across the quad
163 __m128i cstep1
= _mm_add_epi32(cstep0
, xdcdy
);
164 __m128i cstep2
= _mm_add_epi32(cstep1
, xdcdy
);
165 __m128i cstep3
= _mm_add_epi32(cstep2
, xdcdy
);
168 __m128i cstep01
, cstep23
, result
;
170 cstep01
= _mm_packs_epi32(cstep0
, cstep1
);
171 cstep23
= _mm_packs_epi32(cstep2
, cstep3
);
172 result
= _mm_packs_epi16(cstep01
, cstep23
);
174 *outmask
|= _mm_movemask_epi8(result
);
179 __m128i cio4
= _mm_set1_epi32(cdiff
);
180 __m128i cstep01
, cstep23
, result
;
182 cstep0
= _mm_add_epi32(cstep0
, cio4
);
183 cstep1
= _mm_add_epi32(cstep1
, cio4
);
184 cstep2
= _mm_add_epi32(cstep2
, cio4
);
185 cstep3
= _mm_add_epi32(cstep3
, cio4
);
187 cstep01
= _mm_packs_epi32(cstep0
, cstep1
);
188 cstep23
= _mm_packs_epi32(cstep2
, cstep3
);
189 result
= _mm_packs_epi16(cstep01
, cstep23
);
191 *partmask
|= _mm_movemask_epi8(result
);
196 static INLINE
unsigned
197 build_mask_linear(int c
, int dcdx
, int dcdy
)
199 __m128i cstep0
= _mm_setr_epi32(c
, c
+dcdx
, c
+dcdx
*2, c
+dcdx
*3);
200 __m128i xdcdy
= _mm_set1_epi32(dcdy
);
202 /* Get values across the quad
204 __m128i cstep1
= _mm_add_epi32(cstep0
, xdcdy
);
205 __m128i cstep2
= _mm_add_epi32(cstep1
, xdcdy
);
206 __m128i cstep3
= _mm_add_epi32(cstep2
, xdcdy
);
208 /* pack pairs of results into epi16
210 __m128i cstep01
= _mm_packs_epi32(cstep0
, cstep1
);
211 __m128i cstep23
= _mm_packs_epi32(cstep2
, cstep3
);
213 /* pack into epi8, preserving sign bits
215 __m128i result
= _mm_packs_epi16(cstep01
, cstep23
);
217 /* extract sign bits to create mask
219 return _mm_movemask_epi8(result
);
222 static INLINE
unsigned
223 build_mask(int c
, int dcdx
, int dcdy
)
225 __m128i step
= _mm_setr_epi32(0, dcdx
, dcdy
, dcdx
+ dcdy
);
226 __m128i c0
= _mm_set1_epi32(c
);
228 /* Get values across the quad
230 __m128i cstep0
= _mm_add_epi32(c0
, step
);
232 /* Scale up step for moving between quads.
234 __m128i step4
= _mm_add_epi32(step
, step
);
236 /* Get values for the remaining quads:
238 __m128i cstep1
= _mm_add_epi32(cstep0
,
239 _mm_shuffle_epi32(step4
, _MM_SHUFFLE(1,1,1,1)));
240 __m128i cstep2
= _mm_add_epi32(cstep0
,
241 _mm_shuffle_epi32(step4
, _MM_SHUFFLE(2,2,2,2)));
242 __m128i cstep3
= _mm_add_epi32(cstep2
,
243 _mm_shuffle_epi32(step4
, _MM_SHUFFLE(1,1,1,1)));
245 /* pack pairs of results into epi16
247 __m128i cstep01
= _mm_packs_epi32(cstep0
, cstep1
);
248 __m128i cstep23
= _mm_packs_epi32(cstep2
, cstep3
);
250 /* pack into epi8, preserving sign bits
252 __m128i result
= _mm_packs_epi16(cstep01
, cstep23
);
254 /* extract sign bits to create mask
256 return _mm_movemask_epi8(result
);
266 #include "lp_rast_tri_tmp.h"
270 #include "lp_rast_tri_tmp.h"
274 #include "lp_rast_tri_tmp.h"
278 #include "lp_rast_tri_tmp.h"
282 #include "lp_rast_tri_tmp.h"
286 #include "lp_rast_tri_tmp.h"
290 #include "lp_rast_tri_tmp.h"
294 #include "lp_rast_tri_tmp.h"
297 /* Special case for 3 plane triangle which is contained entirely
298 * within a 16x16 block.
301 lp_rast_triangle_3_16(struct lp_rasterizer_task
*task
,
302 const union lp_rast_cmd_arg arg
)
304 const struct lp_rast_triangle
*tri
= arg
.triangle
.tri
;
305 const struct lp_rast_plane
*plane
= tri
->plane
;
306 unsigned mask
= arg
.triangle
.plane_mask
;
307 const int x
= task
->x
+ (mask
& 0xf) * 16;
308 const int y
= task
->y
+ (mask
>> 4) * 16;
309 unsigned outmask
, inmask
, partmask
, partial_mask
;
313 outmask
= 0; /* outside one or more trivial reject planes */
314 partmask
= 0; /* outside one or more trivial accept planes */
316 for (j
= 0; j
< 3; j
++) {
317 c
[j
] = plane
[j
].c
+ plane
[j
].dcdy
* y
- plane
[j
].dcdx
* x
;
320 const int dcdx
= -plane
[j
].dcdx
* 4;
321 const int dcdy
= plane
[j
].dcdy
* 4;
322 const int cox
= plane
[j
].eo
* 4;
323 const int cio
= plane
[j
].ei
* 4 - 1;
325 build_masks(c
[j
] + cox
,
328 &outmask
, /* sign bits from c[i][0..15] + cox */
329 &partmask
); /* sign bits from c[i][0..15] + cio */
333 if (outmask
== 0xffff)
336 /* Mask of sub-blocks which are inside all trivial accept planes:
338 inmask
= ~partmask
& 0xffff;
340 /* Mask of sub-blocks which are inside all trivial reject planes,
341 * but outside at least one trivial accept plane:
343 partial_mask
= partmask
& ~outmask
;
345 assert((partial_mask
& inmask
) == 0);
347 /* Iterate over partials:
349 while (partial_mask
) {
350 int i
= ffs(partial_mask
) - 1;
351 int ix
= (i
& 3) * 4;
352 int iy
= (i
>> 2) * 4;
357 partial_mask
&= ~(1 << i
);
359 for (j
= 0; j
< 3; j
++)
362 + plane
[j
].dcdy
* iy
);
364 do_block_4_3(task
, tri
, plane
, px
, py
, cx
);
367 /* Iterate over fulls:
370 int i
= ffs(inmask
) - 1;
371 int ix
= (i
& 3) * 4;
372 int iy
= (i
>> 2) * 4;
378 block_full_4(task
, tri
, px
, py
);