ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

m_debug_norm.c
Go to the documentation of this file.
00001 
00002 /*
00003  * Mesa 3-D graphics library
00004  * Version:  5.1
00005  *
00006  * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining a
00009  * copy of this software and associated documentation files (the "Software"),
00010  * to deal in the Software without restriction, including without limitation
00011  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00012  * and/or sell copies of the Software, and to permit persons to whom the
00013  * Software is furnished to do so, subject to the following conditions:
00014  *
00015  * The above copyright notice and this permission notice shall be included
00016  * in all copies or substantial portions of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00021  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00022  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00023  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00024  *
00025  * Authors:
00026  *    Gareth Hughes
00027  */
00028 
00029 #include "main/glheader.h"
00030 #include "main/context.h"
00031 #include "main/macros.h"
00032 #include "main/imports.h"
00033 
00034 #include "m_matrix.h"
00035 #include "m_xform.h"
00036 
00037 #include "m_debug.h"
00038 #include "m_debug_util.h"
00039 
00040 
00041 #ifdef __UNIXOS2__
00042 /* The linker doesn't like empty files */
00043 static char dummy;
00044 #endif
00045 
00046 #ifdef DEBUG_MATH  /* This code only used for debugging */
00047 
00048 
00049 static int m_norm_identity[16] = {
00050    ONE, NIL, NIL, NIL,
00051    NIL, ONE, NIL, NIL,
00052    NIL, NIL, ONE, NIL,
00053    NIL, NIL, NIL, NIL
00054 };
00055 static int m_norm_general[16] = {
00056    VAR, VAR, VAR, NIL,
00057    VAR, VAR, VAR, NIL,
00058    VAR, VAR, VAR, NIL,
00059    NIL, NIL, NIL, NIL
00060 };
00061 static int m_norm_no_rot[16] = {
00062    VAR, NIL, NIL, NIL,
00063    NIL, VAR, NIL, NIL,
00064    NIL, NIL, VAR, NIL,
00065    NIL, NIL, NIL, NIL
00066 };
00067 static int *norm_templates[8] = {
00068    m_norm_no_rot,
00069    m_norm_no_rot,
00070    m_norm_no_rot,
00071    m_norm_general,
00072    m_norm_general,
00073    m_norm_general,
00074    m_norm_identity,
00075    m_norm_identity
00076 };
00077 static int norm_types[8] = {
00078    NORM_TRANSFORM_NO_ROT,
00079    NORM_TRANSFORM_NO_ROT | NORM_RESCALE,
00080    NORM_TRANSFORM_NO_ROT | NORM_NORMALIZE,
00081    NORM_TRANSFORM,
00082    NORM_TRANSFORM | NORM_RESCALE,
00083    NORM_TRANSFORM | NORM_NORMALIZE,
00084    NORM_RESCALE,
00085    NORM_NORMALIZE
00086 };
00087 static int norm_scale_types[8] = {               /*  rescale factor          */
00088    NIL,                                          /*  NIL disables rescaling  */
00089    VAR,
00090    NIL,
00091    NIL,
00092    VAR,
00093    NIL,
00094    VAR,
00095    NIL
00096 };
00097 static int norm_normalize_types[8] = {           /*  normalizing ?? (no = 0) */
00098    0,
00099    0,
00100    1,
00101    0,
00102    0,
00103    1,
00104    0,
00105    1
00106 };
00107 static char *norm_strings[8] = {
00108    "NORM_TRANSFORM_NO_ROT",
00109    "NORM_TRANSFORM_NO_ROT | NORM_RESCALE",
00110    "NORM_TRANSFORM_NO_ROT | NORM_NORMALIZE",
00111    "NORM_TRANSFORM",
00112    "NORM_TRANSFORM | NORM_RESCALE",
00113    "NORM_TRANSFORM | NORM_NORMALIZE",
00114    "NORM_RESCALE",
00115    "NORM_NORMALIZE"
00116 };
00117 
00118 
00119 /* =============================================================
00120  * Reference transformations
00121  */
00122 
00123 static void ref_norm_transform_rescale( const GLmatrix *mat,
00124                     GLfloat scale,
00125                     const GLvector4f *in,
00126                     const GLfloat *lengths,
00127                     GLvector4f *dest )
00128 {
00129    GLuint i;
00130    const GLfloat *s = in->start;
00131    const GLfloat *m = mat->inv;
00132    GLfloat (*out)[4] = (GLfloat (*)[4]) dest->start;
00133 
00134    (void) lengths;
00135 
00136    for ( i = 0 ; i < in->count ; i++ ) {
00137       GLfloat t[3];
00138 
00139       TRANSFORM_NORMAL( t, s, m );
00140       SCALE_SCALAR_3V( out[i], scale, t );
00141 
00142       s = (GLfloat *)((char *)s + in->stride);
00143    }
00144 }
00145 
00146 static void ref_norm_transform_normalize( const GLmatrix *mat,
00147                       GLfloat scale,
00148                       const GLvector4f *in,
00149                       const GLfloat *lengths,
00150                       GLvector4f *dest )
00151 {
00152    GLuint i;
00153    const GLfloat *s = in->start;
00154    const GLfloat *m = mat->inv;
00155    GLfloat (*out)[4] = (GLfloat (*)[4]) dest->start;
00156 
00157    for ( i = 0 ; i < in->count ; i++ ) {
00158       GLfloat t[3];
00159 
00160       TRANSFORM_NORMAL( t, s, m );
00161 
00162       if ( !lengths ) {
00163          GLfloat len = LEN_SQUARED_3FV( t );
00164          if ( len > 1e-20 ) {
00165         /* Hmmm, don't know how we could test the precalculated
00166          * length case...
00167          */
00168             scale = 1.0 / SQRTF( len );
00169         SCALE_SCALAR_3V( out[i], scale, t );
00170          } else {
00171             out[i][0] = out[i][1] = out[i][2] = 0;
00172          }
00173       } else {
00174          scale = lengths[i];;
00175      SCALE_SCALAR_3V( out[i], scale, t );
00176       }
00177 
00178       s = (GLfloat *)((char *)s + in->stride);
00179    }
00180 }
00181 
00182 
00183 /* =============================================================
00184  * Normal transformation tests
00185  */
00186 
00187 static void init_matrix( GLfloat *m )
00188 {
00189    m[0] = 63.0; m[4] = 43.0; m[ 8] = 29.0; m[12] = 43.0;
00190    m[1] = 55.0; m[5] = 17.0; m[ 9] = 31.0; m[13] =  7.0;
00191    m[2] = 44.0; m[6] =  9.0; m[10] =  7.0; m[14] =  3.0;
00192    m[3] = 11.0; m[7] = 23.0; m[11] = 91.0; m[15] =  9.0;
00193 }
00194 
00195 
00196 static int test_norm_function( normal_func func, int mtype, long *cycles )
00197 {
00198    GLvector4f source[1], dest[1], dest2[1], ref[1], ref2[1];
00199    GLmatrix mat[1];
00200    GLfloat s[TEST_COUNT][5], d[TEST_COUNT][4], r[TEST_COUNT][4];
00201    GLfloat d2[TEST_COUNT][4], r2[TEST_COUNT][4], length[TEST_COUNT];
00202    GLfloat scale;
00203    GLfloat *m;
00204    int i, j;
00205 #ifdef  RUN_DEBUG_BENCHMARK
00206    int cycle_i;     /* the counter for the benchmarks we run */
00207 #endif
00208 
00209    (void) cycles;
00210 
00211    mat->m = (GLfloat *) ALIGN_MALLOC( 16 * sizeof(GLfloat), 16 );
00212    mat->inv = m = mat->m;
00213 
00214    init_matrix( m );
00215 
00216    scale = 1.0F + rnd () * norm_scale_types[mtype];
00217 
00218    for ( i = 0 ; i < 4 ; i++ ) {
00219       for ( j = 0 ; j < 4 ; j++ ) {
00220          switch ( norm_templates[mtype][i * 4 + j] ) {
00221          case NIL:
00222             m[j * 4 + i] = 0.0;
00223             break;
00224          case ONE:
00225             m[j * 4 + i] = 1.0;
00226             break;
00227          case NEG:
00228             m[j * 4 + i] = -1.0;
00229             break;
00230          case VAR:
00231             break;
00232          default:
00233             _mesa_exit(1);
00234          }
00235       }
00236    }
00237 
00238    for ( i = 0 ; i < TEST_COUNT ; i++ ) {
00239       ASSIGN_3V( d[i],  0.0, 0.0, 0.0 );
00240       ASSIGN_3V( s[i],  0.0, 0.0, 0.0 );
00241       ASSIGN_3V( d2[i], 0.0, 0.0, 0.0 );
00242       for ( j = 0 ; j < 3 ; j++ )
00243          s[i][j] = rnd();
00244       length[i] = 1 / SQRTF( LEN_SQUARED_3FV( s[i] ) );
00245    }
00246 
00247    source->data = (GLfloat(*)[4]) s;
00248    source->start = (GLfloat *) s;
00249    source->count = TEST_COUNT;
00250    source->stride = sizeof(s[0]);
00251    source->flags = 0;
00252 
00253    dest->data = d;
00254    dest->start = (GLfloat *) d;
00255    dest->count = TEST_COUNT;
00256    dest->stride = sizeof(float[4]);
00257    dest->flags = 0;
00258 
00259    dest2->data = d2;
00260    dest2->start = (GLfloat *) d2;
00261    dest2->count = TEST_COUNT;
00262    dest2->stride = sizeof(float[4]);
00263    dest2->flags = 0;
00264 
00265    ref->data = r;
00266    ref->start = (GLfloat *) r;
00267    ref->count = TEST_COUNT;
00268    ref->stride = sizeof(float[4]);
00269    ref->flags = 0;
00270 
00271    ref2->data = r2;
00272    ref2->start = (GLfloat *) r2;
00273    ref2->count = TEST_COUNT;
00274    ref2->stride = sizeof(float[4]);
00275    ref2->flags = 0;
00276 
00277    if ( norm_normalize_types[mtype] == 0 ) {
00278       ref_norm_transform_rescale( mat, scale, source, NULL, ref );
00279    } else {
00280       ref_norm_transform_normalize( mat, scale, source, NULL, ref );
00281       ref_norm_transform_normalize( mat, scale, source, length, ref2 );
00282    }
00283 
00284    if ( mesa_profile ) {
00285       BEGIN_RACE( *cycles );
00286       func( mat, scale, source, NULL, dest );
00287       END_RACE( *cycles );
00288       func( mat, scale, source, length, dest2 );
00289    } else {
00290       func( mat, scale, source, NULL, dest );
00291       func( mat, scale, source, length, dest2 );
00292    }
00293 
00294    for ( i = 0 ; i < TEST_COUNT ; i++ ) {
00295       for ( j = 0 ; j < 3 ; j++ ) {
00296          if ( significand_match( d[i][j], r[i][j] ) < REQUIRED_PRECISION ) {
00297             _mesa_printf( "-----------------------------\n" );
00298             _mesa_printf( "(i = %i, j = %i)\n", i, j );
00299             _mesa_printf( "%f \t %f \t [ratio = %e - %i bit missed]\n",
00300             d[i][0], r[i][0], r[i][0]/d[i][0],
00301             MAX_PRECISION - significand_match( d[i][0], r[i][0] ) );
00302             _mesa_printf( "%f \t %f \t [ratio = %e - %i bit missed]\n",
00303             d[i][1], r[i][1], r[i][1]/d[i][1],
00304             MAX_PRECISION - significand_match( d[i][1], r[i][1] ) );
00305             _mesa_printf( "%f \t %f \t [ratio = %e - %i bit missed]\n",
00306             d[i][2], r[i][2], r[i][2]/d[i][2],
00307             MAX_PRECISION - significand_match( d[i][2], r[i][2] ) );
00308             return 0;
00309          }
00310 
00311          if ( norm_normalize_types[mtype] != 0 ) {
00312             if ( significand_match( d2[i][j], r2[i][j] ) < REQUIRED_PRECISION ) {
00313                _mesa_printf( "------------------- precalculated length case ------\n" );
00314                _mesa_printf( "(i = %i, j = %i)\n", i, j );
00315                _mesa_printf( "%f \t %f \t [ratio = %e - %i bit missed]\n",
00316                d2[i][0], r2[i][0], r2[i][0]/d2[i][0],
00317                MAX_PRECISION - significand_match( d2[i][0], r2[i][0] ) );
00318                _mesa_printf( "%f \t %f \t [ratio = %e - %i bit missed]\n",
00319                d2[i][1], r2[i][1], r2[i][1]/d2[i][1],
00320                MAX_PRECISION - significand_match( d2[i][1], r2[i][1] ) );
00321                _mesa_printf( "%f \t %f \t [ratio = %e - %i bit missed]\n",
00322                d2[i][2], r2[i][2], r2[i][2]/d2[i][2],
00323                MAX_PRECISION - significand_match( d2[i][2], r2[i][2] ) );
00324                return 0;
00325             }
00326          }
00327       }
00328    }
00329 
00330    ALIGN_FREE( mat->m );
00331    return 1;
00332 }
00333 
00334 void _math_test_all_normal_transform_functions( char *description )
00335 {
00336    int mtype;
00337    long benchmark_tab[0xf];
00338    static int first_time = 1;
00339 
00340    if ( first_time ) {
00341       first_time = 0;
00342       mesa_profile = _mesa_getenv( "MESA_PROFILE" );
00343    }
00344 
00345 #ifdef RUN_DEBUG_BENCHMARK
00346    if ( mesa_profile ) {
00347       if ( !counter_overhead ) {
00348      INIT_COUNTER();
00349      _mesa_printf( "counter overhead: %ld cycles\n\n", counter_overhead );
00350       }
00351       _mesa_printf( "normal transform results after hooking in %s functions:\n",
00352           description );
00353       _mesa_printf( "\n-------------------------------------------------------\n" );
00354    }
00355 #endif
00356 
00357    for ( mtype = 0 ; mtype < 8 ; mtype++ ) {
00358       normal_func func = _mesa_normal_tab[norm_types[mtype]];
00359       long *cycles = &benchmark_tab[mtype];
00360 
00361       if ( test_norm_function( func, mtype, cycles ) == 0 ) {
00362      char buf[100];
00363      _mesa_sprintf( buf, "_mesa_normal_tab[0][%s] failed test (%s)",
00364           norm_strings[mtype], description );
00365      _mesa_problem( NULL, buf );
00366       }
00367 
00368 #ifdef RUN_DEBUG_BENCHMARK
00369       if ( mesa_profile ) {
00370      _mesa_printf( " %li\t", benchmark_tab[mtype] );
00371      _mesa_printf( " | [%s]\n", norm_strings[mtype] );
00372       }
00373 #endif
00374    }
00375 #ifdef RUN_DEBUG_BENCHMARK
00376    if ( mesa_profile ) {
00377       _mesa_printf( "\n" );
00378    }
00379 #endif
00380 }
00381 
00382 
00383 #endif /* DEBUG_MATH */

Generated on Sat May 26 2012 04:19:18 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.