lp_rast_tri_tmp.h revision 510b03539413552a543e25de6b896eb10baf60ae
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 */ 42static void 43TAG(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, plane[j].step); 54 } 55 56 /* Now pass to the shader: 57 */ 58 if (mask) 59 lp_rast_shade_quads_mask(task, &tri->inputs, x, y, mask); 60} 61 62/** 63 * Evaluate a 16x16 block of pixels to determine which 4x4 subblocks are in/out 64 * of the triangle's bounds. 65 */ 66static void 67TAG(do_block_16)(struct lp_rasterizer_task *task, 68 const struct lp_rast_triangle *tri, 69 const struct lp_rast_plane *plane, 70 int x, int y, 71 const int *c) 72{ 73 unsigned outmask, inmask, partmask, partial_mask; 74 unsigned i, j; 75 76 outmask = 0; /* outside one or more trivial reject planes */ 77 partmask = 0; /* outside one or more trivial accept planes */ 78 79 for (j = 0; j < NR_PLANES; j++) { 80 const int *step = plane[j].step; 81 const int eo = plane[j].eo * 4; 82 const int ei = plane[j].ei * 4; 83 const int cox = c[j] + eo; 84 const int cio = ei - 1 - eo; 85 86 for (i = 0; i < 16; i++) { 87 int out = cox + step[i] * 4; 88 int part = out + cio; 89 outmask |= (out >> 31) & (1 << i); 90 partmask |= (part >> 31) & (1 << i); 91 } 92 } 93 94 if (outmask == 0xffff) 95 return; 96 97 /* Mask of sub-blocks which are inside all trivial accept planes: 98 */ 99 inmask = ~partmask & 0xffff; 100 101 /* Mask of sub-blocks which are inside all trivial reject planes, 102 * but outside at least one trivial accept plane: 103 */ 104 partial_mask = partmask & ~outmask; 105 106 assert((partial_mask & inmask) == 0); 107 108 /* Iterate over partials: 109 */ 110 while (partial_mask) { 111 int i = ffs(partial_mask) - 1; 112 int px = x + pos_table4[i][0]; 113 int py = y + pos_table4[i][1]; 114 int cx[NR_PLANES]; 115 116 for (j = 0; j < NR_PLANES; j++) 117 cx[j] = c[j] + plane[j].step[i] * 4; 118 119 partial_mask &= ~(1 << i); 120 121 TAG(do_block_4)(task, tri, plane, px, py, cx); 122 } 123 124 /* Iterate over fulls: 125 */ 126 while (inmask) { 127 int i = ffs(inmask) - 1; 128 int px = x + pos_table4[i][0]; 129 int py = y + pos_table4[i][1]; 130 131 inmask &= ~(1 << i); 132 133 block_full_4(task, tri, px, py); 134 } 135} 136 137 138/** 139 * Scan the tile in chunks and figure out which pixels to rasterize 140 * for this triangle. 141 */ 142void 143TAG(lp_rast_triangle)(struct lp_rasterizer_task *task, 144 const union lp_rast_cmd_arg arg) 145{ 146 const struct lp_rast_triangle *tri = arg.triangle.tri; 147 unsigned plane_mask = arg.triangle.plane_mask; 148 const int x = task->x, y = task->y; 149 struct lp_rast_plane plane[NR_PLANES]; 150 int c[NR_PLANES]; 151 unsigned outmask, inmask, partmask, partial_mask; 152 unsigned i, j, nr_planes = 0; 153 154 while (plane_mask) { 155 int i = ffs(plane_mask) - 1; 156 plane[nr_planes] = tri->plane[i]; 157 plane_mask &= ~(1 << i); 158 nr_planes++; 159 }; 160 161 assert(nr_planes == NR_PLANES); 162 outmask = 0; /* outside one or more trivial reject planes */ 163 partmask = 0; /* outside one or more trivial accept planes */ 164 165 for (j = 0; j < NR_PLANES; j++) { 166 const int *step = plane[j].step; 167 const int eo = plane[j].eo * 16; 168 const int ei = plane[j].ei * 16; 169 int cox, cio; 170 171 c[j] = plane[j].c + plane[j].dcdy * y - plane[j].dcdx * x; 172 cox = c[j] + eo; 173 cio = ei - 1 - eo; 174 175 for (i = 0; i < 16; i++) { 176 int out = cox + step[i] * 16; 177 int part = out + cio; 178 outmask |= (out >> 31) & (1 << i); 179 partmask |= (part >> 31) & (1 << i); 180 } 181 } 182 183 if (outmask == 0xffff) 184 return; 185 186 /* Mask of sub-blocks which are inside all trivial accept planes: 187 */ 188 inmask = ~partmask & 0xffff; 189 190 /* Mask of sub-blocks which are inside all trivial reject planes, 191 * but outside at least one trivial accept plane: 192 */ 193 partial_mask = partmask & ~outmask; 194 195 assert((partial_mask & inmask) == 0); 196 197 /* Iterate over partials: 198 */ 199 while (partial_mask) { 200 int i = ffs(partial_mask) - 1; 201 int px = x + pos_table16[i][0]; 202 int py = y + pos_table16[i][1]; 203 int cx[NR_PLANES]; 204 205 for (j = 0; j < NR_PLANES; j++) 206 cx[j] = c[j] + plane[j].step[i] * 16; 207 208 partial_mask &= ~(1 << i); 209 210 LP_COUNT(nr_partially_covered_16); 211 TAG(do_block_16)(task, tri, plane, px, py, cx); 212 } 213 214 /* Iterate over fulls: 215 */ 216 while (inmask) { 217 int i = ffs(inmask) - 1; 218 int px = x + pos_table16[i][0]; 219 int py = y + pos_table16[i][1]; 220 221 inmask &= ~(1 << i); 222 223 LP_COUNT(nr_fully_covered_16); 224 block_full_16(task, tri, px, py); 225 } 226} 227 228#undef TAG 229#undef NR_PLANES 230 231