llvmpipe: version of block4 which doesn't need the full step array
[mesa.git] / src / gallium / drivers / llvmpipe / lp_rast_tri_tmp.h
1 /**************************************************************************
2 *
3 * Copyright 2007-2010 VMware, Inc.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 /*
29 * Rasterization for binned triangles within a tile
30 */
31
32
33
34 /**
35 * Prototype for a 7 plane rasterizer function. Will codegenerate
36 * several of these.
37 *
38 * XXX: Varients for more/fewer planes.
39 * XXX: Need ways of dropping planes as we descend.
40 * XXX: SIMD
41 */
42 static void
43 TAG(do_block_4)(struct lp_rasterizer_task *task,
44 const struct lp_rast_triangle *tri,
45 const struct lp_rast_plane *plane,
46 int x, int y,
47 const int *c)
48 {
49 unsigned mask = 0xffff;
50 int j;
51
52 for (j = 0; j < NR_PLANES; j++) {
53 mask &= ~build_mask(c[j] - 1,
54 plane[j].step[1],
55 plane[j].step[2]);
56 }
57
58 /* Now pass to the shader:
59 */
60 if (mask)
61 lp_rast_shade_quads_mask(task, &tri->inputs, x, y, mask);
62 }
63
64 /**
65 * Evaluate a 16x16 block of pixels to determine which 4x4 subblocks are in/out
66 * of the triangle's bounds.
67 */
68 static void
69 TAG(do_block_16)(struct lp_rasterizer_task *task,
70 const struct lp_rast_triangle *tri,
71 const struct lp_rast_plane *plane,
72 int x, int y,
73 const int *c)
74 {
75 unsigned outmask, inmask, partmask, partial_mask;
76 unsigned i, j;
77
78 outmask = 0; /* outside one or more trivial reject planes */
79 partmask = 0; /* outside one or more trivial accept planes */
80
81 for (j = 0; j < NR_PLANES; j++) {
82 const int *step = plane[j].step;
83 const int eo = plane[j].eo * 4;
84 const int ei = plane[j].ei * 4;
85 const int cox = c[j] + eo;
86 const int cio = ei - 1 - eo;
87
88 for (i = 0; i < 16; i++) {
89 int out = cox + step[i] * 4;
90 int part = out + cio;
91 outmask |= (out >> 31) & (1 << i);
92 partmask |= (part >> 31) & (1 << i);
93 }
94 }
95
96 if (outmask == 0xffff)
97 return;
98
99 /* Mask of sub-blocks which are inside all trivial accept planes:
100 */
101 inmask = ~partmask & 0xffff;
102
103 /* Mask of sub-blocks which are inside all trivial reject planes,
104 * but outside at least one trivial accept plane:
105 */
106 partial_mask = partmask & ~outmask;
107
108 assert((partial_mask & inmask) == 0);
109
110 /* Iterate over partials:
111 */
112 while (partial_mask) {
113 int i = ffs(partial_mask) - 1;
114 int px = x + pos_table4[i][0];
115 int py = y + pos_table4[i][1];
116 int cx[NR_PLANES];
117
118 for (j = 0; j < NR_PLANES; j++)
119 cx[j] = c[j] + plane[j].step[i] * 4;
120
121 partial_mask &= ~(1 << i);
122
123 TAG(do_block_4)(task, tri, plane, px, py, cx);
124 }
125
126 /* Iterate over fulls:
127 */
128 while (inmask) {
129 int i = ffs(inmask) - 1;
130 int px = x + pos_table4[i][0];
131 int py = y + pos_table4[i][1];
132
133 inmask &= ~(1 << i);
134
135 block_full_4(task, tri, px, py);
136 }
137 }
138
139
140 /**
141 * Scan the tile in chunks and figure out which pixels to rasterize
142 * for this triangle.
143 */
144 void
145 TAG(lp_rast_triangle)(struct lp_rasterizer_task *task,
146 const union lp_rast_cmd_arg arg)
147 {
148 const struct lp_rast_triangle *tri = arg.triangle.tri;
149 unsigned plane_mask = arg.triangle.plane_mask;
150 const int x = task->x, y = task->y;
151 struct lp_rast_plane plane[NR_PLANES];
152 int c[NR_PLANES];
153 unsigned outmask, inmask, partmask, partial_mask;
154 unsigned i, j, nr_planes = 0;
155
156 while (plane_mask) {
157 int i = ffs(plane_mask) - 1;
158 plane[nr_planes] = tri->plane[i];
159 plane_mask &= ~(1 << i);
160 nr_planes++;
161 };
162
163 assert(nr_planes == NR_PLANES);
164 outmask = 0; /* outside one or more trivial reject planes */
165 partmask = 0; /* outside one or more trivial accept planes */
166
167 for (j = 0; j < NR_PLANES; j++) {
168 const int *step = plane[j].step;
169 const int eo = plane[j].eo * 16;
170 const int ei = plane[j].ei * 16;
171 int cox, cio;
172
173 c[j] = plane[j].c + plane[j].dcdy * y - plane[j].dcdx * x;
174 cox = c[j] + eo;
175 cio = ei - 1 - eo;
176
177 for (i = 0; i < 16; i++) {
178 int out = cox + step[i] * 16;
179 int part = out + cio;
180 outmask |= (out >> 31) & (1 << i);
181 partmask |= (part >> 31) & (1 << i);
182 }
183 }
184
185 if (outmask == 0xffff)
186 return;
187
188 /* Mask of sub-blocks which are inside all trivial accept planes:
189 */
190 inmask = ~partmask & 0xffff;
191
192 /* Mask of sub-blocks which are inside all trivial reject planes,
193 * but outside at least one trivial accept plane:
194 */
195 partial_mask = partmask & ~outmask;
196
197 assert((partial_mask & inmask) == 0);
198
199 /* Iterate over partials:
200 */
201 while (partial_mask) {
202 int i = ffs(partial_mask) - 1;
203 int px = x + pos_table16[i][0];
204 int py = y + pos_table16[i][1];
205 int cx[NR_PLANES];
206
207 for (j = 0; j < NR_PLANES; j++)
208 cx[j] = c[j] + plane[j].step[i] * 16;
209
210 partial_mask &= ~(1 << i);
211
212 LP_COUNT(nr_partially_covered_16);
213 TAG(do_block_16)(task, tri, plane, px, py, cx);
214 }
215
216 /* Iterate over fulls:
217 */
218 while (inmask) {
219 int i = ffs(inmask) - 1;
220 int px = x + pos_table16[i][0];
221 int py = y + pos_table16[i][1];
222
223 inmask &= ~(1 << i);
224
225 LP_COUNT(nr_fully_covered_16);
226 block_full_16(task, tri, px, py);
227 }
228 }
229
230 #undef TAG
231 #undef NR_PLANES
232