llvmpipe: version of block4 which doesn't need the full step array
[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 <limits.h>
33 #include "util/u_math.h"
34 #include "lp_debug.h"
35 #include "lp_perf.h"
36 #include "lp_rast_priv.h"
37 #include "lp_tile_soa.h"
38
39
40 /**
41 * Map an index in [0,15] to an x,y position, multiplied by 4.
42 * This is used to get the position of each subtile in a 4x4
43 * grid of edge step values.
44 * Note: we can use some bit twiddling to compute these values instead
45 * of using a look-up table, but there's no measurable performance
46 * difference.
47 */
48 static const int pos_table4[16][2] = {
49 { 0, 0 },
50 { 4, 0 },
51 { 0, 4 },
52 { 4, 4 },
53 { 8, 0 },
54 { 12, 0 },
55 { 8, 4 },
56 { 12, 4 },
57 { 0, 8 },
58 { 4, 8 },
59 { 0, 12 },
60 { 4, 12 },
61 { 8, 8 },
62 { 12, 8 },
63 { 8, 12 },
64 { 12, 12 }
65 };
66
67
68 static const int pos_table16[16][2] = {
69 { 0, 0 },
70 { 16, 0 },
71 { 0, 16 },
72 { 16, 16 },
73 { 32, 0 },
74 { 48, 0 },
75 { 32, 16 },
76 { 48, 16 },
77 { 0, 32 },
78 { 16, 32 },
79 { 0, 48 },
80 { 16, 48 },
81 { 32, 32 },
82 { 48, 32 },
83 { 32, 48 },
84 { 48, 48 }
85 };
86
87
88 /**
89 * Shade all pixels in a 4x4 block.
90 */
91 static void
92 block_full_4(struct lp_rasterizer_task *task,
93 const struct lp_rast_triangle *tri,
94 int x, int y)
95 {
96 lp_rast_shade_quads_all(task, &tri->inputs, x, y);
97 }
98
99
100 /**
101 * Shade all pixels in a 16x16 block.
102 */
103 static void
104 block_full_16(struct lp_rasterizer_task *task,
105 const struct lp_rast_triangle *tri,
106 int x, int y)
107 {
108 unsigned ix, iy;
109 assert(x % 16 == 0);
110 assert(y % 16 == 0);
111 for (iy = 0; iy < 16; iy += 4)
112 for (ix = 0; ix < 16; ix += 4)
113 block_full_4(task, tri, x + ix, y + iy);
114 }
115
116
117 static INLINE unsigned
118 build_mask(int c, int dcdx, int dcdy)
119 {
120 int mask = 0;
121
122 int c0 = c;
123 int c1 = c0 + dcdx;
124 int c2 = c1 + dcdx;
125 int c3 = c2 + dcdx;
126
127 mask |= ((c0 + 0 * dcdy) >> 31) & (1 << 0);
128 mask |= ((c0 + 1 * dcdy) >> 31) & (1 << 2);
129 mask |= ((c0 + 2 * dcdy) >> 31) & (1 << 8);
130 mask |= ((c0 + 3 * dcdy) >> 31) & (1 << 10);
131 mask |= ((c1 + 0 * dcdy) >> 31) & (1 << 1);
132 mask |= ((c1 + 1 * dcdy) >> 31) & (1 << 3);
133 mask |= ((c1 + 2 * dcdy) >> 31) & (1 << 9);
134 mask |= ((c1 + 3 * dcdy) >> 31) & (1 << 11);
135 mask |= ((c2 + 0 * dcdy) >> 31) & (1 << 4);
136 mask |= ((c2 + 1 * dcdy) >> 31) & (1 << 6);
137 mask |= ((c2 + 2 * dcdy) >> 31) & (1 << 12);
138 mask |= ((c2 + 3 * dcdy) >> 31) & (1 << 14);
139 mask |= ((c3 + 0 * dcdy) >> 31) & (1 << 5);
140 mask |= ((c3 + 1 * dcdy) >> 31) & (1 << 7);
141 mask |= ((c3 + 2 * dcdy) >> 31) & (1 << 13);
142 mask |= ((c3 + 3 * dcdy) >> 31) & (1 << 15);
143
144 return mask;
145 }
146
147
148
149 #define TAG(x) x##_1
150 #define NR_PLANES 1
151 #include "lp_rast_tri_tmp.h"
152
153 #define TAG(x) x##_2
154 #define NR_PLANES 2
155 #include "lp_rast_tri_tmp.h"
156
157 #define TAG(x) x##_3
158 #define NR_PLANES 3
159 #include "lp_rast_tri_tmp.h"
160
161 #define TAG(x) x##_4
162 #define NR_PLANES 4
163 #include "lp_rast_tri_tmp.h"
164
165 #define TAG(x) x##_5
166 #define NR_PLANES 5
167 #include "lp_rast_tri_tmp.h"
168
169 #define TAG(x) x##_6
170 #define NR_PLANES 6
171 #include "lp_rast_tri_tmp.h"
172
173 #define TAG(x) x##_7
174 #define NR_PLANES 7
175 #include "lp_rast_tri_tmp.h"
176