Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4358 Serge 1
 
2
 * Mesa 3-D graphics library
3
 *
4
 * Copyright (C) 1999-2003  Brian Paul   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 "Software"),
8
 * to deal in the Software without restriction, including without limitation
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
 * and/or sell copies of the Software, and to permit persons to whom the
11
 * Software is furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included
14
 * in all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
 * OTHER DEALINGS IN THE SOFTWARE.
23
 *
24
 * Authors:
25
 *    Gareth Hughes
26
 */
27
28
 
29
#include "main/context.h"
30
#include "main/macros.h"
31
#include "main/imports.h"
32
33
 
34
#include "m_xform.h"
35
36
 
37
#include "m_debug_util.h"
38
39
 
40
 
41
/* The linker doesn't like empty files */
42
static char dummy;
43
#endif
44
45
 
46
47
 
48
 
49
   ONE, NIL, NIL, NIL,
50
   NIL, ONE, NIL, NIL,
51
   NIL, NIL, ONE, NIL,
52
   NIL, NIL, NIL, NIL
53
};
54
static int m_norm_general[16] = {
55
   VAR, VAR, VAR, NIL,
56
   VAR, VAR, VAR, NIL,
57
   VAR, VAR, VAR, NIL,
58
   NIL, NIL, NIL, NIL
59
};
60
static int m_norm_no_rot[16] = {
61
   VAR, NIL, NIL, NIL,
62
   NIL, VAR, NIL, NIL,
63
   NIL, NIL, VAR, NIL,
64
   NIL, NIL, NIL, NIL
65
};
66
static int *norm_templates[8] = {
67
   m_norm_no_rot,
68
   m_norm_no_rot,
69
   m_norm_no_rot,
70
   m_norm_general,
71
   m_norm_general,
72
   m_norm_general,
73
   m_norm_identity,
74
   m_norm_identity
75
};
76
static int norm_types[8] = {
77
   NORM_TRANSFORM_NO_ROT,
78
   NORM_TRANSFORM_NO_ROT | NORM_RESCALE,
79
   NORM_TRANSFORM_NO_ROT | NORM_NORMALIZE,
80
   NORM_TRANSFORM,
81
   NORM_TRANSFORM | NORM_RESCALE,
82
   NORM_TRANSFORM | NORM_NORMALIZE,
83
   NORM_RESCALE,
84
   NORM_NORMALIZE
85
};
86
static int norm_scale_types[8] = {               /*  rescale factor          */
87
   NIL,                                          /*  NIL disables rescaling  */
88
   VAR,
89
   NIL,
90
   NIL,
91
   VAR,
92
   NIL,
93
   VAR,
94
   NIL
95
};
96
static int norm_normalize_types[8] = {           /*  normalizing ?? (no = 0) */
97
   0,
98
   0,
99
   1,
100
   0,
101
   0,
102
   1,
103
   0,
104
   1
105
};
106
static char *norm_strings[8] = {
107
   "NORM_TRANSFORM_NO_ROT",
108
   "NORM_TRANSFORM_NO_ROT | NORM_RESCALE",
109
   "NORM_TRANSFORM_NO_ROT | NORM_NORMALIZE",
110
   "NORM_TRANSFORM",
111
   "NORM_TRANSFORM | NORM_RESCALE",
112
   "NORM_TRANSFORM | NORM_NORMALIZE",
113
   "NORM_RESCALE",
114
   "NORM_NORMALIZE"
115
};
116
117
 
118
 
119
 * Reference transformations
120
 */
121
122
 
123
					GLfloat scale,
124
					const GLvector4f *in,
125
					const GLfloat *lengths,
126
					GLvector4f *dest )
127
{
128
   GLuint i;
129
   const GLfloat *s = in->start;
130
   const GLfloat *m = mat->inv;
131
   GLfloat (*out)[4] = (GLfloat (*)[4]) dest->start;
132
133
 
134
135
 
136
      GLfloat t[3];
137
138
 
139
      SCALE_SCALAR_3V( out[i], scale, t );
140
141
 
142
   }
143
}
144
145
 
146
					  GLfloat scale,
147
					  const GLvector4f *in,
148
					  const GLfloat *lengths,
149
					  GLvector4f *dest )
150
{
151
   GLuint i;
152
   const GLfloat *s = in->start;
153
   const GLfloat *m = mat->inv;
154
   GLfloat (*out)[4] = (GLfloat (*)[4]) dest->start;
155
156
 
157
      GLfloat t[3];
158
159
 
160
161
 
162
         GLfloat len = LEN_SQUARED_3FV( t );
163
         if ( len > 1e-20 ) {
164
	    /* Hmmm, don't know how we could test the precalculated
165
	     * length case...
166
	     */
167
            scale = INV_SQRTF( len );
168
	    SCALE_SCALAR_3V( out[i], scale, t );
169
         } else {
170
            out[i][0] = out[i][1] = out[i][2] = 0;
171
         }
172
      } else {
173
         scale = lengths[i];;
174
	 SCALE_SCALAR_3V( out[i], scale, t );
175
      }
176
177
 
178
   }
179
}
180
181
 
182
 
183
 * Normal transformation tests
184
 */
185
186
 
187
{
188
   m[0] = 63.0; m[4] = 43.0; m[ 8] = 29.0; m[12] = 43.0;
189
   m[1] = 55.0; m[5] = 17.0; m[ 9] = 31.0; m[13] =  7.0;
190
   m[2] = 44.0; m[6] =  9.0; m[10] =  7.0; m[14] =  3.0;
191
   m[3] = 11.0; m[7] = 23.0; m[11] = 91.0; m[15] =  9.0;
192
}
193
194
 
195
 
196
{
197
   GLvector4f source[1], dest[1], dest2[1], ref[1], ref2[1];
198
   GLmatrix mat[1];
199
   GLfloat s[TEST_COUNT][5], d[TEST_COUNT][4], r[TEST_COUNT][4];
200
   GLfloat d2[TEST_COUNT][4], r2[TEST_COUNT][4], length[TEST_COUNT];
201
   GLfloat scale;
202
   GLfloat *m;
203
   int i, j;
204
#ifdef  RUN_DEBUG_BENCHMARK
205
   int cycle_i;		/* the counter for the benchmarks we run */
206
#endif
207
208
 
209
210
 
211
   mat->inv = m = mat->m;
212
213
 
214
215
 
216
217
 
218
      for ( j = 0 ; j < 4 ; j++ ) {
219
         switch ( norm_templates[mtype][i * 4 + j] ) {
220
         case NIL:
221
            m[j * 4 + i] = 0.0;
222
            break;
223
         case ONE:
224
            m[j * 4 + i] = 1.0;
225
            break;
226
         case NEG:
227
            m[j * 4 + i] = -1.0;
228
            break;
229
         case VAR:
230
            break;
231
         default:
232
            exit(1);
233
         }
234
      }
235
   }
236
237
 
238
      ASSIGN_3V( d[i],  0.0, 0.0, 0.0 );
239
      ASSIGN_3V( s[i],  0.0, 0.0, 0.0 );
240
      ASSIGN_3V( d2[i], 0.0, 0.0, 0.0 );
241
      for ( j = 0 ; j < 3 ; j++ )
242
         s[i][j] = rnd();
243
      length[i] = INV_SQRTF( LEN_SQUARED_3FV( s[i] ) );
244
   }
245
246
 
247
   source->start = (GLfloat *) s;
248
   source->count = TEST_COUNT;
249
   source->stride = sizeof(s[0]);
250
   source->flags = 0;
251
252
 
253
   dest->start = (GLfloat *) d;
254
   dest->count = TEST_COUNT;
255
   dest->stride = sizeof(float[4]);
256
   dest->flags = 0;
257
258
 
259
   dest2->start = (GLfloat *) d2;
260
   dest2->count = TEST_COUNT;
261
   dest2->stride = sizeof(float[4]);
262
   dest2->flags = 0;
263
264
 
265
   ref->start = (GLfloat *) r;
266
   ref->count = TEST_COUNT;
267
   ref->stride = sizeof(float[4]);
268
   ref->flags = 0;
269
270
 
271
   ref2->start = (GLfloat *) r2;
272
   ref2->count = TEST_COUNT;
273
   ref2->stride = sizeof(float[4]);
274
   ref2->flags = 0;
275
276
 
277
      ref_norm_transform_rescale( mat, scale, source, NULL, ref );
278
   } else {
279
      ref_norm_transform_normalize( mat, scale, source, NULL, ref );
280
      ref_norm_transform_normalize( mat, scale, source, length, ref2 );
281
   }
282
283
 
284
      BEGIN_RACE( *cycles );
285
      func( mat, scale, source, NULL, dest );
286
      END_RACE( *cycles );
287
      func( mat, scale, source, length, dest2 );
288
   } else {
289
      func( mat, scale, source, NULL, dest );
290
      func( mat, scale, source, length, dest2 );
291
   }
292
293
 
294
      for ( j = 0 ; j < 3 ; j++ ) {
295
         if ( significand_match( d[i][j], r[i][j] ) < REQUIRED_PRECISION ) {
296
            printf( "-----------------------------\n" );
297
            printf( "(i = %i, j = %i)\n", i, j );
298
            printf( "%f \t %f \t [ratio = %e - %i bit missed]\n",
299
		    d[i][0], r[i][0], r[i][0]/d[i][0],
300
		    MAX_PRECISION - significand_match( d[i][0], r[i][0] ) );
301
            printf( "%f \t %f \t [ratio = %e - %i bit missed]\n",
302
		    d[i][1], r[i][1], r[i][1]/d[i][1],
303
		    MAX_PRECISION - significand_match( d[i][1], r[i][1] ) );
304
            printf( "%f \t %f \t [ratio = %e - %i bit missed]\n",
305
		    d[i][2], r[i][2], r[i][2]/d[i][2],
306
		    MAX_PRECISION - significand_match( d[i][2], r[i][2] ) );
307
            return 0;
308
         }
309
310
 
311
            if ( significand_match( d2[i][j], r2[i][j] ) < REQUIRED_PRECISION ) {
312
               printf( "------------------- precalculated length case ------\n" );
313
               printf( "(i = %i, j = %i)\n", i, j );
314
               printf( "%f \t %f \t [ratio = %e - %i bit missed]\n",
315
		       d2[i][0], r2[i][0], r2[i][0]/d2[i][0],
316
		       MAX_PRECISION - significand_match( d2[i][0], r2[i][0] ) );
317
               printf( "%f \t %f \t [ratio = %e - %i bit missed]\n",
318
		       d2[i][1], r2[i][1], r2[i][1]/d2[i][1],
319
		       MAX_PRECISION - significand_match( d2[i][1], r2[i][1] ) );
320
               printf( "%f \t %f \t [ratio = %e - %i bit missed]\n",
321
		       d2[i][2], r2[i][2], r2[i][2]/d2[i][2],
322
		       MAX_PRECISION - significand_match( d2[i][2], r2[i][2] ) );
323
               return 0;
324
            }
325
         }
326
      }
327
   }
328
329
 
330
   return 1;
331
}
332
333
 
334
{
335
   int mtype;
336
   long benchmark_tab[0xf];
337
   static int first_time = 1;
338
339
 
340
      first_time = 0;
341
      mesa_profile = _mesa_getenv( "MESA_PROFILE" );
342
   }
343
344
 
345
   if ( mesa_profile ) {
346
      if ( !counter_overhead ) {
347
	 INIT_COUNTER();
348
	 printf( "counter overhead: %ld cycles\n\n", counter_overhead );
349
      }
350
      printf( "normal transform results after hooking in %s functions:\n",
351
	      description );
352
      printf( "\n-------------------------------------------------------\n" );
353
   }
354
#endif
355
356
 
357
      normal_func func = _mesa_normal_tab[norm_types[mtype]];
358
      long *cycles = &benchmark_tab[mtype];
359
360
 
361
	 char buf[100];
362
	 sprintf( buf, "_mesa_normal_tab[0][%s] failed test (%s)",
363
		  norm_strings[mtype], description );
364
	 _mesa_problem( NULL, "%s", buf );
365
      }
366
367
 
368
      if ( mesa_profile ) {
369
	 printf( " %li\t", benchmark_tab[mtype] );
370
	 printf( " | [%s]\n", norm_strings[mtype] );
371
      }
372
#endif
373
   }
374
#ifdef RUN_DEBUG_BENCHMARK
375
   if ( mesa_profile ) {
376
      printf( "\n" );
377
   }
378
#endif
379
}
380
381
 
382
 
383