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_xform.c
Go to the documentation of this file.
00001 /*
00002  * Mesa 3-D graphics library
00003  * Version:  6.1
00004  *
00005  * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a
00008  * copy of this software and associated documentation files (the "Software"),
00009  * to deal in the Software without restriction, including without limitation
00010  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00011  * and/or sell copies of the Software, and to permit persons to whom the
00012  * Software is furnished to do so, subject to the following conditions:
00013  *
00014  * The above copyright notice and this permission notice shall be included
00015  * in all copies or substantial portions of the Software.
00016  *
00017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00018  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00020  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023  */
00024 
00025 /*
00026  * Updated for P6 architecture by 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 #ifdef __UNIXOS2__
00041 /* The linker doesn't like empty files */
00042 static char dummy;
00043 #endif
00044 
00045 #ifdef DEBUG_MATH  /* This code only used for debugging */
00046 
00047 
00048 /* Overhead of profiling counter in cycles.  Automatically adjusted to
00049  * your machine at run time - counter initialization should give very
00050  * consistent results.
00051  */
00052 long counter_overhead = 0;
00053 
00054 /* This is the value of the environment variable MESA_PROFILE, and is
00055  * used to determine if we should benchmark the functions as well as
00056  * verify their correctness.
00057  */
00058 char *mesa_profile = NULL;
00059 
00060 
00061 static int m_general[16] = {
00062    VAR, VAR, VAR, VAR,
00063    VAR, VAR, VAR, VAR,
00064    VAR, VAR, VAR, VAR,
00065    VAR, VAR, VAR, VAR
00066 };
00067 static int m_identity[16] = {
00068    ONE, NIL, NIL, NIL,
00069    NIL, ONE, NIL, NIL,
00070    NIL, NIL, ONE, NIL,
00071    NIL, NIL, NIL, ONE
00072 };
00073 static int  m_2d[16]  = {
00074    VAR, VAR, NIL, VAR,
00075    VAR, VAR, NIL, VAR,
00076    NIL, NIL, ONE, NIL,
00077    NIL, NIL, NIL, ONE
00078 };
00079 static int m_2d_no_rot[16] = {
00080    VAR, NIL, NIL, VAR,
00081    NIL, VAR, NIL, VAR,
00082    NIL, NIL, ONE, NIL,
00083    NIL, NIL, NIL, ONE
00084 };
00085 static int m_3d[16] = {
00086    VAR, VAR, VAR, VAR,
00087    VAR, VAR, VAR, VAR,
00088    VAR, VAR, VAR, VAR,
00089    NIL, NIL, NIL, ONE
00090 };
00091 static int m_3d_no_rot[16] = {
00092    VAR, NIL, NIL, VAR,
00093    NIL, VAR, NIL, VAR,
00094    NIL, NIL, VAR, VAR,
00095    NIL, NIL, NIL, ONE
00096 };
00097 static int m_perspective[16] = {
00098    VAR, NIL, VAR, NIL,
00099    NIL, VAR, VAR, NIL,
00100    NIL, NIL, VAR, VAR,
00101    NIL, NIL, NEG, NIL
00102 };
00103 static int *templates[7] = {
00104    m_general,
00105    m_identity,
00106    m_3d_no_rot,
00107    m_perspective,
00108    m_2d,
00109    m_2d_no_rot,
00110    m_3d
00111 };
00112 static enum GLmatrixtype mtypes[7] = {
00113    MATRIX_GENERAL,
00114    MATRIX_IDENTITY,
00115    MATRIX_3D_NO_ROT,
00116    MATRIX_PERSPECTIVE,
00117    MATRIX_2D,
00118    MATRIX_2D_NO_ROT,
00119    MATRIX_3D
00120 };
00121 static char *mstrings[7] = {
00122    "MATRIX_GENERAL",
00123    "MATRIX_IDENTITY",
00124    "MATRIX_3D_NO_ROT",
00125    "MATRIX_PERSPECTIVE",
00126    "MATRIX_2D",
00127    "MATRIX_2D_NO_ROT",
00128    "MATRIX_3D"
00129 };
00130 
00131 
00132 /* =============================================================
00133  * Reference transformations
00134  */
00135 
00136 static void ref_transform( GLvector4f *dst,
00137                            const GLmatrix *mat,
00138                            const GLvector4f *src )
00139 {
00140    GLuint i;
00141    GLfloat *s = (GLfloat *)src->start;
00142    GLfloat (*d)[4] = (GLfloat (*)[4])dst->start;
00143    const GLfloat *m = mat->m;
00144 
00145    for ( i = 0 ; i < src->count ; i++ ) {
00146       TRANSFORM_POINT( d[i], m, s );
00147       s = (GLfloat *)((char *)s + src->stride);
00148    }
00149 }
00150 
00151 
00152 /* =============================================================
00153  * Vertex transformation tests
00154  */
00155 
00156 static void init_matrix( GLfloat *m )
00157 {
00158    m[0] = 63.0; m[4] = 43.0; m[ 8] = 29.0; m[12] = 43.0;
00159    m[1] = 55.0; m[5] = 17.0; m[ 9] = 31.0; m[13] =  7.0;
00160    m[2] = 44.0; m[6] =  9.0; m[10] =  7.0; m[14] =  3.0;
00161    m[3] = 11.0; m[7] = 23.0; m[11] = 91.0; m[15] =  9.0;
00162 }
00163 
00164 ALIGN16(static GLfloat, s[TEST_COUNT][4]);
00165 ALIGN16(static GLfloat, d[TEST_COUNT][4]);
00166 ALIGN16(static GLfloat, r[TEST_COUNT][4]);
00167 
00168 static int test_transform_function( transform_func func, int psize,
00169                     int mtype, unsigned long *cycles )
00170 {
00171    GLvector4f source[1], dest[1], ref[1];
00172    GLmatrix mat[1];
00173    GLfloat *m;
00174    int i, j;
00175 #ifdef  RUN_DEBUG_BENCHMARK
00176    int cycle_i;                /* the counter for the benchmarks we run */
00177 #endif
00178 
00179    (void) cycles;
00180 
00181    if ( psize > 4 ) {
00182       _mesa_problem( NULL, "test_transform_function called with psize > 4\n" );
00183       return 0;
00184    }
00185 
00186    mat->m = (GLfloat *) ALIGN_MALLOC( 16 * sizeof(GLfloat), 16 );
00187    mat->type = mtypes[mtype];
00188 
00189    m = mat->m;
00190    ASSERT( ((long)m & 15) == 0 );
00191 
00192    init_matrix( m );
00193 
00194    for ( i = 0 ; i < 4 ; i++ ) {
00195       for ( j = 0 ; j < 4 ; j++ ) {
00196          switch ( templates[mtype][i * 4 + j] ) {
00197          case NIL:
00198             m[j * 4 + i] = 0.0;
00199             break;
00200          case ONE:
00201             m[j * 4 + i] = 1.0;
00202             break;
00203          case NEG:
00204             m[j * 4 + i] = -1.0;
00205             break;
00206          case VAR:
00207             break;
00208          default:
00209             abort();
00210          }
00211       }
00212    }
00213 
00214    for ( i = 0 ; i < TEST_COUNT ; i++) {
00215       ASSIGN_4V( d[i], 0.0, 0.0, 0.0, 1.0 );
00216       ASSIGN_4V( s[i], 0.0, 0.0, 0.0, 1.0 );
00217       for ( j = 0 ; j < psize ; j++ )
00218          s[i][j] = rnd();
00219    }
00220 
00221    source->data = (GLfloat(*)[4])s;
00222    source->start = (GLfloat *)s;
00223    source->count = TEST_COUNT;
00224    source->stride = sizeof(s[0]);
00225    source->size = 4;
00226    source->flags = 0;
00227 
00228    dest->data = (GLfloat(*)[4])d;
00229    dest->start = (GLfloat *)d;
00230    dest->count = TEST_COUNT;
00231    dest->stride = sizeof(float[4]);
00232    dest->size = 0;
00233    dest->flags = 0;
00234 
00235    ref->data = (GLfloat(*)[4])r;
00236    ref->start = (GLfloat *)r;
00237    ref->count = TEST_COUNT;
00238    ref->stride = sizeof(float[4]);
00239    ref->size = 0;
00240    ref->flags = 0;
00241 
00242    ref_transform( ref, mat, source );
00243 
00244    if ( mesa_profile ) {
00245       BEGIN_RACE( *cycles );
00246       func( dest, mat->m, source );
00247       END_RACE( *cycles );
00248    }
00249    else {
00250       func( dest, mat->m, source );
00251    }
00252 
00253    for ( i = 0 ; i < TEST_COUNT ; i++ ) {
00254       for ( j = 0 ; j < 4 ; j++ ) {
00255          if ( significand_match( d[i][j], r[i][j] ) < REQUIRED_PRECISION ) {
00256             _mesa_printf("-----------------------------\n" );
00257             _mesa_printf("(i = %i, j = %i)\n", i, j );
00258             _mesa_printf("%f \t %f \t [diff = %e - %i bit missed]\n",
00259             d[i][0], r[i][0], r[i][0]-d[i][0],
00260             MAX_PRECISION - significand_match( d[i][0], r[i][0] ) );
00261             _mesa_printf("%f \t %f \t [diff = %e - %i bit missed]\n",
00262             d[i][1], r[i][1], r[i][1]-d[i][1],
00263             MAX_PRECISION - significand_match( d[i][1], r[i][1] ) );
00264             _mesa_printf("%f \t %f \t [diff = %e - %i bit missed]\n",
00265             d[i][2], r[i][2], r[i][2]-d[i][2],
00266             MAX_PRECISION - significand_match( d[i][2], r[i][2] ) );
00267             _mesa_printf("%f \t %f \t [diff = %e - %i bit missed]\n",
00268             d[i][3], r[i][3], r[i][3]-d[i][3],
00269             MAX_PRECISION - significand_match( d[i][3], r[i][3] ) );
00270             return 0;
00271          }
00272       }
00273    }
00274 
00275    ALIGN_FREE( mat->m );
00276    return 1;
00277 }
00278 
00279 void _math_test_all_transform_functions( char *description )
00280 {
00281    int psize, mtype;
00282    unsigned long benchmark_tab[4][7];
00283    static int first_time = 1;
00284 
00285    if ( first_time ) {
00286       first_time = 0;
00287       mesa_profile = _mesa_getenv( "MESA_PROFILE" );
00288    }
00289 
00290 #ifdef RUN_DEBUG_BENCHMARK
00291    if ( mesa_profile ) {
00292       if ( !counter_overhead ) {
00293      INIT_COUNTER();
00294      _mesa_printf("counter overhead: %lu cycles\n\n", counter_overhead );
00295       }
00296       _mesa_printf("transform results after hooking in %s functions:\n", description );
00297    }
00298 #endif
00299 
00300 #ifdef RUN_DEBUG_BENCHMARK
00301    if ( mesa_profile ) {
00302       _mesa_printf("\n" );
00303       for ( psize = 1 ; psize <= 4 ; psize++ ) {
00304      _mesa_printf(" p%d\t", psize );
00305       }
00306       _mesa_printf("\n--------------------------------------------------------\n" );
00307    }
00308 #endif
00309 
00310    for ( mtype = 0 ; mtype < 7 ; mtype++ ) {
00311       for ( psize = 1 ; psize <= 4 ; psize++ ) {
00312      transform_func func = _mesa_transform_tab[psize][mtypes[mtype]];
00313      unsigned long *cycles = &(benchmark_tab[psize-1][mtype]);
00314 
00315      if ( test_transform_function( func, psize, mtype, cycles ) == 0 ) {
00316         char buf[100];
00317         _mesa_sprintf(buf, "_mesa_transform_tab[0][%d][%s] failed test (%s)",
00318              psize, mstrings[mtype], description );
00319         _mesa_problem( NULL, buf );
00320      }
00321 #ifdef RUN_DEBUG_BENCHMARK
00322      if ( mesa_profile )
00323         _mesa_printf(" %li\t", benchmark_tab[psize-1][mtype] );
00324 #endif
00325       }
00326 #ifdef RUN_DEBUG_BENCHMARK
00327       if ( mesa_profile )
00328      _mesa_printf(" | [%s]\n", mstrings[mtype] );
00329 #endif
00330    }
00331 #ifdef RUN_DEBUG_BENCHMARK
00332    if ( mesa_profile )
00333       _mesa_printf( "\n" );
00334 #endif
00335 }
00336 
00337 
00338 #endif /* DEBUG_MATH */

Generated on Sun May 27 2012 04:20:32 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.