~ubuntu-branches/ubuntu/natty/mesa/natty-proposed

« back to all changes in this revision

Viewing changes to src/gallium/drivers/llvmpipe/lp_rast_tri.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Hooker, Robert Hooker, Christopher James Halse Rogers
  • Date: 2010-09-14 08:55:40 UTC
  • mfrom: (1.2.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100914085540-m4fpl0hdjlfd4jgz
Tags: 7.9~git20100909-0ubuntu1
[ Robert Hooker ]
* New upstream git snapshot up to commit 94118fe2d4b1e5 (LP: #631413)
* New features include ATI HD5xxx series support in r600, and a vastly
  improved glsl compiler.
* Remove pre-generated .pc's, use the ones generated at build time
  instead.
* Remove all references to mesa-utils now that its no longer shipped
  with the mesa source.
* Disable the experimental ARB_fragment_shader option by default on
  i915, it exposes incomplete functionality that breaks KDE compositing
  among other things. It can be enabled via driconf still. (LP: #628930).

[ Christopher James Halse Rogers ]
* debian/patches/04_osmesa_version.diff:
  - Refresh for new upstream
* Bugs fixed in this release:
  - Fixes severe rendering corruption in Unity on radeon (LP: #628727,
    LP: #596292, LP: #599741, LP: #630315, LP: #613694, LP: #599741).
  - Also fixes rendering in gnome-shell (LP: #578619).
  - Flickering in OpenGL apps on radeon (LP: #626943, LP: #610541).
  - Provides preliminary support for new intel chips (LP: #601052).
* debian/rules:
  - Update configure flags to match upstream reshuffling.
  - Explicitly remove gallium DRI drivers that we don't want to ship.
* Update debian/gbp.conf for this Maverick-specific packaging
* libegl1-mesa-dri-x11,kms: There are no longer separate kms or x11 drivers
  for EGL, libegl1-mesa-drivers now contains a single driver that provides
  both backends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include "lp_tile_soa.h"
38
38
 
39
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
40
 
87
41
 
88
42
/**
113
67
         block_full_4(task, tri, x + ix, y + iy);
114
68
}
115
69
 
116
 
 
117
 
/**
118
 
 * Pass the 4x4 pixel block to the shader function.
119
 
 * Determination of which of the 16 pixels lies inside the triangle
120
 
 * will be done as part of the fragment shader.
121
 
 */
122
 
static void
123
 
do_block_4(struct lp_rasterizer_task *task,
124
 
           const struct lp_rast_triangle *tri,
125
 
           int x, int y,
126
 
           int c1, int c2, int c3)
127
 
{
128
 
   assert(x >= 0);
129
 
   assert(y >= 0);
130
 
 
131
 
   lp_rast_shade_quads(task, &tri->inputs, x, y, -c1, -c2, -c3);
132
 
}
133
 
 
134
 
 
135
 
/**
136
 
 * Evaluate a 16x16 block of pixels to determine which 4x4 subblocks are in/out
137
 
 * of the triangle's bounds.
138
 
 */
139
 
static void
140
 
do_block_16(struct lp_rasterizer_task *task,
141
 
            const struct lp_rast_triangle *tri,
142
 
            int x, int y,
143
 
            int c0, int c1, int c2)
144
 
{
145
 
   unsigned mask = 0;
146
 
   int eo[3];
 
70
#if !defined(PIPE_ARCH_SSE)
 
71
static INLINE unsigned
 
72
build_mask(int c, int dcdx, int dcdy)
 
73
{
 
74
   int mask = 0;
 
75
 
 
76
   int c0 = c;
 
77
   int c1 = c0 + dcdx;
 
78
   int c2 = c1 + dcdx;
 
79
   int c3 = c2 + dcdx;
 
80
 
 
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);
 
97
  
 
98
   return mask;
 
99
}
 
100
 
 
101
 
 
102
static INLINE unsigned
 
103
build_mask_linear(int c, int dcdx, int dcdy)
 
104
{
 
105
   int mask = 0;
 
106
 
 
107
   int c0 = c;
 
108
   int c1 = c0 + dcdy;
 
109
   int c2 = c1 + dcdy;
 
110
   int c3 = c2 + dcdy;
 
111
 
 
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);
 
128
  
 
129
   return mask;
 
130
}
 
131
 
 
132
 
 
133
static INLINE void
 
134
build_masks(int c, 
 
135
            int cdiff,
 
136
            int dcdx,
 
137
            int dcdy,
 
138
            unsigned *outmask,
 
139
            unsigned *partmask)
 
140
{
 
141
   *outmask |= build_mask_linear(c, dcdx, dcdy);
 
142
   *partmask |= build_mask_linear(c + cdiff, dcdx, dcdy);
 
143
}
 
144
 
 
145
#else
 
146
#include <emmintrin.h>
 
147
#include "util/u_sse.h"
 
148
 
 
149
 
 
150
static INLINE void
 
151
build_masks(int c, 
 
152
            int cdiff,
 
153
            int dcdx,
 
154
            int dcdy,
 
155
            unsigned *outmask,
 
156
            unsigned *partmask)
 
157
{
 
158
   __m128i cstep0 = _mm_setr_epi32(c, c+dcdx, c+dcdx*2, c+dcdx*3);
 
159
   __m128i xdcdy = _mm_set1_epi32(dcdy);
 
160
 
 
161
   /* Get values across the quad
 
162
    */
 
163
   __m128i cstep1 = _mm_add_epi32(cstep0, xdcdy);
 
164
   __m128i cstep2 = _mm_add_epi32(cstep1, xdcdy);
 
165
   __m128i cstep3 = _mm_add_epi32(cstep2, xdcdy);
 
166
 
 
167
   {
 
168
      __m128i cstep01, cstep23, result;
 
169
 
 
170
      cstep01 = _mm_packs_epi32(cstep0, cstep1);
 
171
      cstep23 = _mm_packs_epi32(cstep2, cstep3);
 
172
      result = _mm_packs_epi16(cstep01, cstep23);
 
173
 
 
174
      *outmask |= _mm_movemask_epi8(result);
 
175
   }
 
176
 
 
177
 
 
178
   {
 
179
      __m128i cio4 = _mm_set1_epi32(cdiff);
 
180
      __m128i cstep01, cstep23, result;
 
181
 
 
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);
 
186
 
 
187
      cstep01 = _mm_packs_epi32(cstep0, cstep1);
 
188
      cstep23 = _mm_packs_epi32(cstep2, cstep3);
 
189
      result = _mm_packs_epi16(cstep01, cstep23);
 
190
 
 
191
      *partmask |= _mm_movemask_epi8(result);
 
192
   }
 
193
}
 
194
 
 
195
 
 
196
static INLINE unsigned
 
197
build_mask_linear(int c, int dcdx, int dcdy)
 
198
{
 
199
   __m128i cstep0 = _mm_setr_epi32(c, c+dcdx, c+dcdx*2, c+dcdx*3);
 
200
   __m128i xdcdy = _mm_set1_epi32(dcdy);
 
201
 
 
202
   /* Get values across the quad
 
203
    */
 
204
   __m128i cstep1 = _mm_add_epi32(cstep0, xdcdy);
 
205
   __m128i cstep2 = _mm_add_epi32(cstep1, xdcdy);
 
206
   __m128i cstep3 = _mm_add_epi32(cstep2, xdcdy);
 
207
 
 
208
   /* pack pairs of results into epi16
 
209
    */
 
210
   __m128i cstep01 = _mm_packs_epi32(cstep0, cstep1);
 
211
   __m128i cstep23 = _mm_packs_epi32(cstep2, cstep3);
 
212
 
 
213
   /* pack into epi8, preserving sign bits
 
214
    */
 
215
   __m128i result = _mm_packs_epi16(cstep01, cstep23);
 
216
 
 
217
   /* extract sign bits to create mask
 
218
    */
 
219
   return _mm_movemask_epi8(result);
 
220
}
 
221
 
 
222
static INLINE unsigned
 
223
build_mask(int c, int dcdx, int dcdy)
 
224
{
 
225
   __m128i step = _mm_setr_epi32(0, dcdx, dcdy, dcdx + dcdy);
 
226
   __m128i c0 = _mm_set1_epi32(c);
 
227
 
 
228
   /* Get values across the quad
 
229
    */
 
230
   __m128i cstep0 = _mm_add_epi32(c0, step);
 
231
 
 
232
   /* Scale up step for moving between quads.
 
233
    */
 
234
   __m128i step4 = _mm_add_epi32(step, step);
 
235
 
 
236
   /* Get values for the remaining quads:
 
237
    */
 
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)));
 
244
 
 
245
   /* pack pairs of results into epi16
 
246
    */
 
247
   __m128i cstep01 = _mm_packs_epi32(cstep0, cstep1);
 
248
   __m128i cstep23 = _mm_packs_epi32(cstep2, cstep3);
 
249
 
 
250
   /* pack into epi8, preserving sign bits
 
251
    */
 
252
   __m128i result = _mm_packs_epi16(cstep01, cstep23);
 
253
 
 
254
   /* extract sign bits to create mask
 
255
    */
 
256
   return _mm_movemask_epi8(result);
 
257
}
 
258
 
 
259
#endif
 
260
 
 
261
 
 
262
 
 
263
 
 
264
#define TAG(x) x##_1
 
265
#define NR_PLANES 1
 
266
#include "lp_rast_tri_tmp.h"
 
267
 
 
268
#define TAG(x) x##_2
 
269
#define NR_PLANES 2
 
270
#include "lp_rast_tri_tmp.h"
 
271
 
 
272
#define TAG(x) x##_3
 
273
#define NR_PLANES 3
 
274
#include "lp_rast_tri_tmp.h"
 
275
 
 
276
#define TAG(x) x##_4
 
277
#define NR_PLANES 4
 
278
#include "lp_rast_tri_tmp.h"
 
279
 
 
280
#define TAG(x) x##_5
 
281
#define NR_PLANES 5
 
282
#include "lp_rast_tri_tmp.h"
 
283
 
 
284
#define TAG(x) x##_6
 
285
#define NR_PLANES 6
 
286
#include "lp_rast_tri_tmp.h"
 
287
 
 
288
#define TAG(x) x##_7
 
289
#define NR_PLANES 7
 
290
#include "lp_rast_tri_tmp.h"
 
291
 
 
292
#define TAG(x) x##_8
 
293
#define NR_PLANES 8
 
294
#include "lp_rast_tri_tmp.h"
 
295
 
 
296
 
 
297
/* Special case for 3 plane triangle which is contained entirely
 
298
 * within a 16x16 block.
 
299
 */
 
300
void
 
301
lp_rast_triangle_3_16(struct lp_rasterizer_task *task,
 
302
                      const union lp_rast_cmd_arg arg)
 
303
{
 
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;
 
310
   unsigned j;
147
311
   int c[3];
148
 
   int i, j;
149
 
 
150
 
   assert(x >= 0);
151
 
   assert(y >= 0);
152
 
   assert(x % 16 == 0);
153
 
   assert(y % 16 == 0);
154
 
 
155
 
   eo[0] = tri->eo1 * 4;
156
 
   eo[1] = tri->eo2 * 4;
157
 
   eo[2] = tri->eo3 * 4;
158
 
 
159
 
   c[0] = c0;
160
 
   c[1] = c1;
161
 
   c[2] = c2;
162
 
 
163
 
   for (j = 0; j < 3; j++) {
164
 
      const int *step = tri->inputs.step[j];
165
 
      const int cx = c[j] + eo[j];
166
 
 
167
 
      /* Mask has bits set whenever we are outside any of the edges.
168
 
       */
169
 
      for (i = 0; i < 16; i++) {
170
 
         int out = cx + step[i] * 4;
171
 
         mask |= (out >> 31) & (1 << i);
172
 
      }
173
 
   }
174
 
 
175
 
   mask = ~mask & 0xffff;
176
 
   while (mask) {
177
 
      int i = ffs(mask) - 1;
178
 
      int px = x + pos_table4[i][0];
179
 
      int py = y + pos_table4[i][1];
180
 
      int cx1 = c0 + tri->inputs.step[0][i] * 4;
181
 
      int cx2 = c1 + tri->inputs.step[1][i] * 4;
182
 
      int cx3 = c2 + tri->inputs.step[2][i] * 4;
183
 
 
184
 
      mask &= ~(1 << i);
185
 
 
186
 
      /* Don't bother testing if the 4x4 block is entirely in/out of
187
 
       * the triangle.  It's a little faster to do it in the jit code.
188
 
       */
189
 
      LP_COUNT(nr_non_empty_4);
190
 
      do_block_4(task, tri, px, py, cx1, cx2, cx3);
191
 
   }
192
 
}
193
 
 
194
 
 
195
 
/**
196
 
 * Scan the tile in chunks and figure out which pixels to rasterize
197
 
 * for this triangle.
198
 
 */
199
 
void
200
 
lp_rast_triangle(struct lp_rasterizer_task *task,
201
 
                 const union lp_rast_cmd_arg arg)
202
 
{
203
 
   const struct lp_rast_triangle *tri = arg.triangle;
204
 
   const int x = task->x, y = task->y;
205
 
   int ei[3], eo[3], c[3];
206
 
   unsigned outmask, inmask, partial_mask;
207
 
   unsigned i, j;
208
 
 
209
 
   c[0] = tri->c1 + tri->dx12 * y - tri->dy12 * x;
210
 
   c[1] = tri->c2 + tri->dx23 * y - tri->dy23 * x;
211
 
   c[2] = tri->c3 + tri->dx31 * y - tri->dy31 * x;
212
 
 
213
 
   eo[0] = tri->eo1 * 16;
214
 
   eo[1] = tri->eo2 * 16;
215
 
   eo[2] = tri->eo3 * 16;
216
 
 
217
 
   ei[0] = tri->ei1 * 16;
218
 
   ei[1] = tri->ei2 * 16;
219
 
   ei[2] = tri->ei3 * 16;
220
 
 
221
 
   outmask = 0;
222
 
   inmask = 0xffff;
223
 
 
224
 
   for (j = 0; j < 3; j++) {
225
 
      const int *step = tri->inputs.step[j];
226
 
      const int cox = c[j] + eo[j];
227
 
      const int cio = ei[j]- eo[j];
228
 
 
229
 
      /* Outmask has bits set whenever we are outside any of the
230
 
       * edges.
231
 
       */
232
 
      /* Inmask has bits set whenever we are inside all of the edges.
233
 
       */
234
 
      for (i = 0; i < 16; i++) {
235
 
         int out = cox + step[i] * 16;
236
 
         int in = out + cio;
237
 
         outmask |= (out >> 31) & (1 << i);
238
 
         inmask &= ~((in >> 31) & (1 << i));
239
 
      }
240
 
   }
241
 
 
242
 
   assert((outmask & inmask) == 0);
 
312
 
 
313
   outmask = 0;                 /* outside one or more trivial reject planes */
 
314
   partmask = 0;                /* outside one or more trivial accept planes */
 
315
 
 
316
   for (j = 0; j < 3; j++) {
 
317
      c[j] = plane[j].c + plane[j].dcdy * y - plane[j].dcdx * x;
 
318
 
 
319
      {
 
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;
 
324
 
 
325
         build_masks(c[j] + cox,
 
326
                     cio - cox,
 
327
                     dcdx, dcdy, 
 
328
                     &outmask,   /* sign bits from c[i][0..15] + cox */
 
329
                     &partmask); /* sign bits from c[i][0..15] + cio */
 
330
      }
 
331
   }
243
332
 
244
333
   if (outmask == 0xffff)
245
334
      return;
246
335
 
247
 
   /* Invert mask, so that bits are set whenever we are at least
248
 
    * partially inside all of the edges:
249
 
    */
250
 
   partial_mask = ~inmask & ~outmask & 0xffff;
 
336
   /* Mask of sub-blocks which are inside all trivial accept planes:
 
337
    */
 
338
   inmask = ~partmask & 0xffff;
 
339
 
 
340
   /* Mask of sub-blocks which are inside all trivial reject planes,
 
341
    * but outside at least one trivial accept plane:
 
342
    */
 
343
   partial_mask = partmask & ~outmask;
 
344
 
 
345
   assert((partial_mask & inmask) == 0);
251
346
 
252
347
   /* Iterate over partials:
253
348
    */
254
349
   while (partial_mask) {
255
350
      int i = ffs(partial_mask) - 1;
256
 
      int px = x + pos_table16[i][0];
257
 
      int py = y + pos_table16[i][1];
258
 
      int cx1 = c[0] + tri->inputs.step[0][i] * 16;
259
 
      int cx2 = c[1] + tri->inputs.step[1][i] * 16;
260
 
      int cx3 = c[2] + tri->inputs.step[2][i] * 16;
 
351
      int ix = (i & 3) * 4;
 
352
      int iy = (i >> 2) * 4;
 
353
      int px = x + ix;
 
354
      int py = y + iy; 
 
355
      int cx[3];
261
356
 
262
357
      partial_mask &= ~(1 << i);
263
358
 
264
 
      LP_COUNT(nr_partially_covered_16);
265
 
      do_block_16(task, tri, px, py, cx1, cx2, cx3);
 
359
      for (j = 0; j < 3; j++)
 
360
         cx[j] = (c[j] 
 
361
                  - plane[j].dcdx * ix
 
362
                  + plane[j].dcdy * iy);
 
363
 
 
364
      do_block_4_3(task, tri, plane, px, py, cx);
266
365
   }
267
366
 
268
367
   /* Iterate over fulls: 
269
368
    */
270
369
   while (inmask) {
271
370
      int i = ffs(inmask) - 1;
272
 
      int px = x + pos_table16[i][0];
273
 
      int py = y + pos_table16[i][1];
 
371
      int ix = (i & 3) * 4;
 
372
      int iy = (i >> 2) * 4;
 
373
      int px = x + ix;
 
374
      int py = y + iy; 
274
375
 
275
376
      inmask &= ~(1 << i);
276
377
 
277
 
      LP_COUNT(nr_fully_covered_16);
278
 
      block_full_16(task, tri, px, py);
 
378
      block_full_4(task, tri, px, py);
279
379
   }
280
380
}