~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/extras/Mesa/src/math/m_debug_clip.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * Mesa 3-D graphics library
 
4
 * Version:  3.5
 
5
 *
 
6
 * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
 
7
 *
 
8
 * Permission is hereby granted, free of charge, to any person obtaining a
 
9
 * copy of this software and associated documentation files (the "Software"),
 
10
 * to deal in the Software without restriction, including without limitation
 
11
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
12
 * and/or sell copies of the Software, and to permit persons to whom the
 
13
 * Software is furnished to do so, subject to the following conditions:
 
14
 *
 
15
 * The above copyright notice and this permission notice shall be included
 
16
 * in all copies or substantial portions 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 MERCHANTABILITY,
 
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
21
 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
22
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
23
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
24
 *
 
25
 * Authors:
 
26
 *    Gareth Hughes <gareth@valinux.com>
 
27
 */
 
28
 
 
29
#include "glheader.h"
 
30
#include "context.h"
 
31
#include "macros.h"
 
32
#include "mem.h"
 
33
 
 
34
#include "m_matrix.h"
 
35
#include "m_xform.h"
 
36
 
 
37
#include "m_debug.h"
 
38
#include "m_debug_util.h"
 
39
 
 
40
#ifdef DEBUG  /* This code only used for debugging */
 
41
 
 
42
static clip_func *clip_tab[2] = {
 
43
   _mesa_clip_tab,
 
44
   _mesa_clip_np_tab
 
45
};
 
46
static char *cnames[2] = {
 
47
   "_mesa_clip_tab",
 
48
   "_mesa_clip_np_tab"
 
49
};
 
50
static char *cstrings[2] = {
 
51
   "clip, perspective divide",
 
52
   "clip, no divide"
 
53
};
 
54
 
 
55
 
 
56
/* =============================================================
 
57
 * Reference cliptests
 
58
 */
 
59
 
 
60
static GLvector4f *ref_cliptest_points4( GLvector4f *clip_vec,
 
61
                                         GLvector4f *proj_vec,
 
62
                                         GLubyte clipMask[],
 
63
                                         GLubyte *orMask,
 
64
                                         GLubyte *andMask )
 
65
{
 
66
   const GLuint stride = clip_vec->stride;
 
67
   const GLuint count = clip_vec->count;
 
68
   const GLfloat *from = (GLfloat *)clip_vec->start;
 
69
   GLuint c = 0;
 
70
   GLfloat (*vProj)[4] = (GLfloat (*)[4])proj_vec->start;
 
71
   GLubyte tmpAndMask = *andMask;
 
72
   GLubyte tmpOrMask = *orMask;
 
73
   GLuint i;
 
74
   for ( i = 0 ; i < count ; i++, STRIDE_F(from, stride) ) {
 
75
      const GLfloat cx = from[0];
 
76
      const GLfloat cy = from[1];
 
77
      const GLfloat cz = from[2];
 
78
      const GLfloat cw = from[3];
 
79
      GLubyte mask = 0;
 
80
      if ( -cx + cw < 0 ) mask |= CLIP_RIGHT_BIT;
 
81
      if (  cx + cw < 0 ) mask |= CLIP_LEFT_BIT;
 
82
      if ( -cy + cw < 0 ) mask |= CLIP_TOP_BIT;
 
83
      if (  cy + cw < 0 ) mask |= CLIP_BOTTOM_BIT;
 
84
      if ( -cz + cw < 0 ) mask |= CLIP_FAR_BIT;
 
85
      if (  cz + cw < 0 ) mask |= CLIP_NEAR_BIT;
 
86
      clipMask[i] = mask;
 
87
      if ( mask ) {
 
88
         c++;
 
89
         tmpAndMask &= mask;
 
90
         tmpOrMask |= mask;
 
91
         vProj[i][0] = 0;
 
92
         vProj[i][1] = 0;
 
93
         vProj[i][2] = 0;
 
94
         vProj[i][3] = 1;
 
95
      } else {
 
96
         GLfloat oow = 1.0F / cw;
 
97
         vProj[i][0] = cx * oow;
 
98
         vProj[i][1] = cy * oow;
 
99
         vProj[i][2] = cz * oow;
 
100
         vProj[i][3] = oow;
 
101
      }
 
102
   }
 
103
 
 
104
   *orMask = tmpOrMask;
 
105
   *andMask = (GLubyte) (c < count ? 0 : tmpAndMask);
 
106
 
 
107
   proj_vec->flags |= VEC_SIZE_4;
 
108
   proj_vec->size = 4;
 
109
   proj_vec->count = clip_vec->count;
 
110
   return proj_vec;
 
111
}
 
112
 
 
113
/* Keep these here for now, even though we don't use them...
 
114
 */
 
115
static GLvector4f *ref_cliptest_points3( GLvector4f *clip_vec,
 
116
                                         GLvector4f *proj_vec,
 
117
                                         GLubyte clipMask[],
 
118
                                         GLubyte *orMask,
 
119
                                         GLubyte *andMask )
 
120
{
 
121
   const GLuint stride = clip_vec->stride;
 
122
   const GLuint count = clip_vec->count;
 
123
   const GLfloat *from = (GLfloat *)clip_vec->start;
 
124
 
 
125
   GLubyte tmpOrMask = *orMask;
 
126
   GLubyte tmpAndMask = *andMask;
 
127
   GLuint i;
 
128
   for ( i = 0 ; i < count ; i++, STRIDE_F(from, stride) ) {
 
129
      const GLfloat cx = from[0], cy = from[1], cz = from[2];
 
130
      GLubyte mask = 0;
 
131
      if ( cx >  1.0 )          mask |= CLIP_RIGHT_BIT;
 
132
      else if ( cx < -1.0 )     mask |= CLIP_LEFT_BIT;
 
133
      if ( cy >  1.0 )          mask |= CLIP_TOP_BIT;
 
134
      else if ( cy < -1.0 )     mask |= CLIP_BOTTOM_BIT;
 
135
      if ( cz >  1.0 )          mask |= CLIP_FAR_BIT;
 
136
      else if ( cz < -1.0 )     mask |= CLIP_NEAR_BIT;
 
137
      clipMask[i] = mask;
 
138
      tmpOrMask |= mask;
 
139
      tmpAndMask &= mask;
 
140
   }
 
141
 
 
142
   *orMask = tmpOrMask;
 
143
   *andMask = tmpAndMask;
 
144
   return clip_vec;
 
145
}
 
146
 
 
147
static GLvector4f * ref_cliptest_points2( GLvector4f *clip_vec,
 
148
                                          GLvector4f *proj_vec,
 
149
                                          GLubyte clipMask[],
 
150
                                          GLubyte *orMask,
 
151
                                          GLubyte *andMask )
 
152
{
 
153
   const GLuint stride = clip_vec->stride;
 
154
   const GLuint count = clip_vec->count;
 
155
   const GLfloat *from = (GLfloat *)clip_vec->start;
 
156
 
 
157
   GLubyte tmpOrMask = *orMask;
 
158
   GLubyte tmpAndMask = *andMask;
 
159
   GLuint i;
 
160
   for ( i = 0 ; i < count ; i++, STRIDE_F(from, stride) ) {
 
161
      const GLfloat cx = from[0], cy = from[1];
 
162
      GLubyte mask = 0;
 
163
      if ( cx >  1.0 )          mask |= CLIP_RIGHT_BIT;
 
164
      else if ( cx < -1.0 )     mask |= CLIP_LEFT_BIT;
 
165
      if ( cy >  1.0 )          mask |= CLIP_TOP_BIT;
 
166
      else if ( cy < -1.0 )     mask |= CLIP_BOTTOM_BIT;
 
167
      clipMask[i] = mask;
 
168
      tmpOrMask |= mask;
 
169
      tmpAndMask &= mask;
 
170
   }
 
171
 
 
172
   *orMask = tmpOrMask;
 
173
   *andMask = tmpAndMask;
 
174
   return clip_vec;
 
175
}
 
176
 
 
177
static clip_func ref_cliptest[5] = {
 
178
   0,
 
179
   0,
 
180
   ref_cliptest_points2,
 
181
   ref_cliptest_points3,
 
182
   ref_cliptest_points4
 
183
};
 
184
 
 
185
 
 
186
/* =============================================================
 
187
 * Cliptest tests
 
188
 */
 
189
 
 
190
static GLfloat s[TEST_COUNT][4] ALIGN16;
 
191
static GLfloat d[TEST_COUNT][4] ALIGN16;
 
192
static GLfloat r[TEST_COUNT][4] ALIGN16;
 
193
 
 
194
static int test_cliptest_function( clip_func func, int np,
 
195
                                   int psize, long *cycles )
 
196
{
 
197
   GLvector4f source[1], dest[1], ref[1];
 
198
   GLubyte dm[TEST_COUNT], dco, dca;
 
199
   GLubyte rm[TEST_COUNT], rco, rca;
 
200
   int i, j;
 
201
#ifdef  RUN_DEBUG_BENCHMARK
 
202
   int cycle_i;                /* the counter for the benchmarks we run */
 
203
#endif
 
204
 
 
205
   (void) cycles;
 
206
 
 
207
   if ( psize > 4 ) {
 
208
      _mesa_problem( NULL, "test_cliptest_function called with psize > 4\n" );
 
209
      return 0;
 
210
   }
 
211
 
 
212
   for ( i = 0 ; i < TEST_COUNT ; i++) {
 
213
      ASSIGN_4V( d[i], 0.0, 0.0, 0.0, 1.0 );
 
214
      ASSIGN_4V( s[i], 0.0, 0.0, 0.0, 1.0 );
 
215
      for ( j = 0 ; j < psize ; j++ )
 
216
         s[i][j] = rnd();
 
217
   }
 
218
 
 
219
   source->data = (GLfloat(*)[4])s;
 
220
   source->start = (GLfloat *)s;
 
221
   source->count = TEST_COUNT;
 
222
   source->stride = sizeof(s[0]);
 
223
   source->size = 4;
 
224
   source->flags = 0;
 
225
 
 
226
   dest->data = (GLfloat(*)[4])d;
 
227
   dest->start = (GLfloat *)d;
 
228
   dest->count = TEST_COUNT;
 
229
   dest->stride = sizeof(float[4]);
 
230
   dest->size = 0;
 
231
   dest->flags = 0;
 
232
 
 
233
   ref->data = (GLfloat(*)[4])r;
 
234
   ref->start = (GLfloat *)r;
 
235
   ref->count = TEST_COUNT;
 
236
   ref->stride = sizeof(float[4]);
 
237
   ref->size = 0;
 
238
   ref->flags = 0;
 
239
 
 
240
   dco = rco = 0;
 
241
   dca = rca = CLIP_ALL_BITS;
 
242
 
 
243
   ref_cliptest[psize]( source, ref, rm, &rco, &rca );
 
244
 
 
245
   if ( mesa_profile ) {
 
246
      BEGIN_RACE( *cycles );
 
247
      func( source, dest, dm, &dco, &dca );
 
248
      END_RACE( *cycles );
 
249
   }
 
250
   else {
 
251
      func( source, dest, dm, &dco, &dca );
 
252
   }
 
253
 
 
254
   if ( dco != rco ) {
 
255
      printf( "\n-----------------------------\n" );
 
256
      printf( "dco = 0x%02x   rco = 0x%02x\n", dco, rco );
 
257
      return 0;
 
258
   }
 
259
   if ( dca != rca ) {
 
260
      printf( "\n-----------------------------\n" );
 
261
      printf( "dca = 0x%02x   rca = 0x%02x\n", dca, rca );
 
262
      return 0;
 
263
   }
 
264
   for ( i = 0 ; i < TEST_COUNT ; i++ ) {
 
265
      if ( dm[i] != rm[i] ) {
 
266
         printf( "\n-----------------------------\n" );
 
267
         printf( "(i = %i)\n", i );
 
268
         printf( "dm = 0x%02x   rm = 0x%02x\n", dm[i], rm[i] );
 
269
         return 0;
 
270
      }
 
271
   }
 
272
 
 
273
   /* Only verify output on projected points4 case.  FIXME: Do we need
 
274
    * to test other cases?
 
275
    */
 
276
   if ( np || psize < 4 )
 
277
      return 1;
 
278
 
 
279
   for ( i = 0 ; i < TEST_COUNT ; i++ ) {
 
280
      for ( j = 0 ; j < 4 ; j++ ) {
 
281
         if ( significand_match( d[i][j], r[i][j] ) < REQUIRED_PRECISION ) {
 
282
            printf( "\n-----------------------------\n" );
 
283
            printf( "(i = %i, j = %i)  dm = 0x%02x   rm = 0x%02x\n",
 
284
                    i, j, dm[i], rm[i] );
 
285
            printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
 
286
                    d[i][0], r[i][0], r[i][0]-d[i][0],
 
287
                    MAX_PRECISION - significand_match( d[i][0], r[i][0] ) );
 
288
            printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
 
289
                    d[i][1], r[i][1], r[i][1]-d[i][1],
 
290
                    MAX_PRECISION - significand_match( d[i][1], r[i][1] ) );
 
291
            printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
 
292
                    d[i][2], r[i][2], r[i][2]-d[i][2],
 
293
                    MAX_PRECISION - significand_match( d[i][2], r[i][2] ) );
 
294
            printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
 
295
                    d[i][3], r[i][3], r[i][3]-d[i][3],
 
296
                    MAX_PRECISION - significand_match( d[i][3], r[i][3] ) );
 
297
            return 0;
 
298
         }
 
299
      }
 
300
   }
 
301
 
 
302
   return 1;
 
303
}
 
304
 
 
305
void _math_test_all_cliptest_functions( char *description )
 
306
{
 
307
   int np, psize;
 
308
   long benchmark_tab[2][4];
 
309
   static int first_time = 1;
 
310
 
 
311
   if ( first_time ) {
 
312
      first_time = 0;
 
313
      mesa_profile = getenv( "MESA_PROFILE" );
 
314
   }
 
315
 
 
316
#ifdef RUN_DEBUG_BENCHMARK
 
317
   if ( mesa_profile ) {
 
318
      if ( !counter_overhead ) {
 
319
         INIT_COUNTER();
 
320
         printf( "counter overhead: %ld cycles\n\n", counter_overhead );
 
321
      }
 
322
      printf( "cliptest results after hooking in %s functions:\n", description );
 
323
   }
 
324
#endif
 
325
 
 
326
#ifdef RUN_DEBUG_BENCHMARK
 
327
   if ( mesa_profile ) {
 
328
      printf( "\n\t" );
 
329
      for ( psize = 2 ; psize <= 4 ; psize++ ) {
 
330
         printf( " p%d\t", psize );
 
331
      }
 
332
      printf( "\n--------------------------------------------------------\n\t" );
 
333
   }
 
334
#endif
 
335
 
 
336
   for ( np = 0 ; np < 2 ; np++ ) {
 
337
      for ( psize = 2 ; psize <= 4 ; psize++ ) {
 
338
         clip_func func = clip_tab[np][psize];
 
339
         long *cycles = &(benchmark_tab[np][psize-1]);
 
340
 
 
341
         if ( test_cliptest_function( func, np, psize, cycles ) == 0 ) {
 
342
            char buf[100];
 
343
            sprintf( buf, "%s[%d] failed test (%s)",
 
344
                     cnames[np], psize, description );
 
345
            _mesa_problem( NULL, buf );
 
346
         }
 
347
#ifdef RUN_DEBUG_BENCHMARK
 
348
         if ( mesa_profile )
 
349
            printf( " %li\t", benchmark_tab[np][psize-1] );
 
350
#endif
 
351
      }
 
352
#ifdef RUN_DEBUG_BENCHMARK
 
353
      if ( mesa_profile )
 
354
         printf( " | [%s]\n\t", cstrings[np] );
 
355
#endif
 
356
   }
 
357
#ifdef RUN_DEBUG_BENCHMARK
 
358
   if ( mesa_profile )
 
359
      printf( "\n" );
 
360
#endif
 
361
}
 
362
 
 
363
 
 
364
#endif /* DEBUG */