llvmpipe: Remove quad headers.
[mesa.git] / src / gallium / drivers / llvmpipe / lp_rast_tri.c
1 /**************************************************************************
2 *
3 * Copyright 2007-2009 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 #include "util/u_math.h"
33 #include "lp_rast_priv.h"
34 #include "lp_tile_soa.h"
35
36
37 #define BLOCKSIZE 8
38
39
40 /* Convert 8x8 block into four runs of quads and render each in turn.
41 */
42 #if (BLOCKSIZE == 8)
43 static void block_full( struct lp_rasterizer *rast,
44 const struct lp_rast_triangle *tri,
45 int x, int y )
46 {
47 const unsigned masks[4] = {~0, ~0, ~0, ~0};
48 int iy;
49
50 for (iy = 0; iy < 8; iy += 2)
51 lp_rast_shade_quads(rast, tri->inputs, x, y + iy, masks);
52 }
53 #else
54 static void block_full( struct lp_rasterizer *rast,
55 const struct lp_rast_triangle *tri,
56 int x, int y )
57 {
58 const unsigned masks[4] = {~0, ~0, 0, 0}; /* FIXME: Wasting quads!!! */
59 int iy;
60
61 for (iy = 0; iy < 4; iy += 2)
62 lp_rast_shade_quads(rast, tri->inputs, x, y + iy, masks);
63 }
64 #endif
65
66 static INLINE unsigned
67 do_quad( const struct lp_rast_triangle *tri,
68 int x, int y,
69 float c1, float c2, float c3 )
70 {
71 float xstep1 = -tri->dy12;
72 float xstep2 = -tri->dy23;
73 float xstep3 = -tri->dy31;
74
75 float ystep1 = tri->dx12;
76 float ystep2 = tri->dx23;
77 float ystep3 = tri->dx31;
78
79 unsigned mask = 0;
80
81 if (c1 > 0 &&
82 c2 > 0 &&
83 c3 > 0)
84 mask |= 1;
85
86 if (c1 + xstep1 > 0 &&
87 c2 + xstep2 > 0 &&
88 c3 + xstep3 > 0)
89 mask |= 2;
90
91 if (c1 + ystep1 > 0 &&
92 c2 + ystep2 > 0 &&
93 c3 + ystep3 > 0)
94 mask |= 4;
95
96 if (c1 + ystep1 + xstep1 > 0 &&
97 c2 + ystep2 + xstep2 > 0 &&
98 c3 + ystep3 + xstep3 > 0)
99 mask |= 8;
100
101 return mask;
102 }
103
104 /* Evaluate each pixel in a block, generate a mask and possibly render
105 * the quad:
106 */
107 static void
108 do_block( struct lp_rasterizer *rast,
109 const struct lp_rast_triangle *tri,
110 int x, int y,
111 float c1,
112 float c2,
113 float c3 )
114 {
115 const int step = 2;
116
117 float xstep1 = -step * tri->dy12;
118 float xstep2 = -step * tri->dy23;
119 float xstep3 = -step * tri->dy31;
120
121 float ystep1 = step * tri->dx12;
122 float ystep2 = step * tri->dx23;
123 float ystep3 = step * tri->dx31;
124
125 int ix, iy;
126
127 for (iy = 0; iy < BLOCKSIZE; iy += 2) {
128 float cx1 = c1;
129 float cx2 = c2;
130 float cx3 = c3;
131
132 unsigned masks[4] = {0, 0, 0, 0};
133
134 for (ix = 0; ix < BLOCKSIZE; ix += 2) {
135
136 masks[ix >> 1] = do_quad(tri, x + ix, y + iy, cx1, cx2, cx3);
137
138 cx1 += xstep1;
139 cx2 += xstep2;
140 cx3 += xstep3;
141 }
142
143 lp_rast_shade_quads(rast, tri->inputs, x, y + iy, masks);
144
145 c1 += ystep1;
146 c2 += ystep2;
147 c3 += ystep3;
148 }
149
150 }
151
152
153
154 /* Scan the tile in chunks and figure out which pixels to rasterize
155 * for this triangle:
156 */
157 void lp_rast_triangle( struct lp_rasterizer *rast,
158 const union lp_rast_cmd_arg *arg )
159 {
160 const struct lp_rast_triangle *tri = arg->triangle;
161 int minx, maxx, miny, maxy;
162
163 /* Clamp to tile dimensions:
164 */
165 minx = MAX2(tri->maxx, rast->x);
166 miny = MAX2(tri->miny, rast->y);
167 maxx = MIN2(tri->maxx, rast->x + TILE_SIZE);
168 maxy = MIN2(tri->maxy, rast->y + TILE_SIZE);
169
170 if (miny == maxy ||
171 minx == maxx) {
172 debug_printf("%s: non-intersecting triangle in bin\n", __FUNCTION__);
173 //assert(0);
174 return;
175 }
176
177 const int step = BLOCKSIZE;
178
179 float ei1 = tri->ei1 * step;
180 float ei2 = tri->ei2 * step;
181 float ei3 = tri->ei3 * step;
182
183 float eo1 = tri->eo1 * step;
184 float eo2 = tri->eo2 * step;
185 float eo3 = tri->eo3 * step;
186
187 float xstep1 = -step * tri->dy12;
188 float xstep2 = -step * tri->dy23;
189 float xstep3 = -step * tri->dy31;
190
191 float ystep1 = step * tri->dx12;
192 float ystep2 = step * tri->dx23;
193 float ystep3 = step * tri->dx31;
194 int x, y;
195
196 minx &= ~(step-1);
197 miny &= ~(step-1);
198
199 for (y = miny; y < maxy; y += step)
200 {
201 float cx1 = c1;
202 float cx2 = c2;
203 float cx3 = c3;
204
205 for (x = minx; x < maxx; x += step)
206 {
207 if (cx1 + eo1 < 0 ||
208 cx2 + eo2 < 0 ||
209 cx3 + eo3 < 0)
210 {
211 }
212 else if (cx1 + ei1 > 0 &&
213 cx2 + ei2 > 0 &&
214 cx3 + ei3 > 0)
215 {
216 block_full(rast, tri, x, y); /* trivial accept */
217 }
218 else
219 {
220 do_block(rast, tri, x, y, cx1, cx2, cx3);
221 }
222
223 /* Iterate cx values across the region:
224 */
225 cx1 += xstep1;
226 cx2 += xstep2;
227 cx3 += xstep3;
228 }
229
230 /* Iterate c values down the region:
231 */
232 c1 += ystep1;
233 c2 += ystep2;
234 c3 += ystep3;
235 }
236 }
237