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_clip.c
Go to the documentation of this file.
00001 /*
00002  * Mesa 3-D graphics library
00003  * Version:  6.1
00004  *
00005  * Copyright (C) 1999-2005  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  * Authors:
00025  *    Gareth Hughes
00026  */
00027 
00028 #include "main/glheader.h"
00029 #include "main/context.h"
00030 #include "main/macros.h"
00031 #include "main/imports.h"
00032 
00033 #include "m_matrix.h"
00034 #include "m_xform.h"
00035 
00036 #include "m_debug.h"
00037 #include "m_debug_util.h"
00038 
00039 #ifdef __UNIXOS2__
00040 /* The linker doesn't like empty files */
00041 static char dummy;
00042 #endif
00043 
00044 #ifdef DEBUG_MATH  /* This code only used for debugging */
00045 
00046 static clip_func *clip_tab[2] = {
00047    _mesa_clip_tab,
00048    _mesa_clip_np_tab
00049 };
00050 static char *cnames[2] = {
00051    "_mesa_clip_tab",
00052    "_mesa_clip_np_tab"
00053 };
00054 #ifdef RUN_DEBUG_BENCHMARK
00055 static char *cstrings[2] = {
00056    "clip, perspective divide",
00057    "clip, no divide"
00058 };
00059 #endif
00060 
00061 
00062 /* =============================================================
00063  * Reference cliptests
00064  */
00065 
00066 static GLvector4f *ref_cliptest_points4( GLvector4f *clip_vec,
00067                      GLvector4f *proj_vec,
00068                      GLubyte clipMask[],
00069                      GLubyte *orMask,
00070                      GLubyte *andMask )
00071 {
00072    const GLuint stride = clip_vec->stride;
00073    const GLuint count = clip_vec->count;
00074    const GLfloat *from = (GLfloat *)clip_vec->start;
00075    GLuint c = 0;
00076    GLfloat (*vProj)[4] = (GLfloat (*)[4])proj_vec->start;
00077    GLubyte tmpAndMask = *andMask;
00078    GLubyte tmpOrMask = *orMask;
00079    GLuint i;
00080    for ( i = 0 ; i < count ; i++, STRIDE_F(from, stride) ) {
00081       const GLfloat cx = from[0];
00082       const GLfloat cy = from[1];
00083       const GLfloat cz = from[2];
00084       const GLfloat cw = from[3];
00085       GLubyte mask = 0;
00086       if ( -cx + cw < 0 ) mask |= CLIP_RIGHT_BIT;
00087       if (  cx + cw < 0 ) mask |= CLIP_LEFT_BIT;
00088       if ( -cy + cw < 0 ) mask |= CLIP_TOP_BIT;
00089       if (  cy + cw < 0 ) mask |= CLIP_BOTTOM_BIT;
00090       if ( -cz + cw < 0 ) mask |= CLIP_FAR_BIT;
00091       if (  cz + cw < 0 ) mask |= CLIP_NEAR_BIT;
00092       clipMask[i] = mask;
00093       if ( mask ) {
00094      c++;
00095      tmpAndMask &= mask;
00096      tmpOrMask |= mask;
00097      vProj[i][0] = 0;
00098      vProj[i][1] = 0;
00099      vProj[i][2] = 0;
00100      vProj[i][3] = 1;
00101       } else {
00102      GLfloat oow = 1.0F / cw;
00103      vProj[i][0] = cx * oow;
00104      vProj[i][1] = cy * oow;
00105      vProj[i][2] = cz * oow;
00106      vProj[i][3] = oow;
00107       }
00108    }
00109 
00110    *orMask = tmpOrMask;
00111    *andMask = (GLubyte) (c < count ? 0 : tmpAndMask);
00112 
00113    proj_vec->flags |= VEC_SIZE_4;
00114    proj_vec->size = 4;
00115    proj_vec->count = clip_vec->count;
00116    return proj_vec;
00117 }
00118 
00119 /* Keep these here for now, even though we don't use them...
00120  */
00121 static GLvector4f *ref_cliptest_points3( GLvector4f *clip_vec,
00122                      GLvector4f *proj_vec,
00123                      GLubyte clipMask[],
00124                      GLubyte *orMask,
00125                      GLubyte *andMask )
00126 {
00127    const GLuint stride = clip_vec->stride;
00128    const GLuint count = clip_vec->count;
00129    const GLfloat *from = (GLfloat *)clip_vec->start;
00130 
00131    GLubyte tmpOrMask = *orMask;
00132    GLubyte tmpAndMask = *andMask;
00133    GLuint i;
00134    for ( i = 0 ; i < count ; i++, STRIDE_F(from, stride) ) {
00135       const GLfloat cx = from[0], cy = from[1], cz = from[2];
00136       GLubyte mask = 0;
00137       if ( cx >  1.0 )      mask |= CLIP_RIGHT_BIT;
00138       else if ( cx < -1.0 ) mask |= CLIP_LEFT_BIT;
00139       if ( cy >  1.0 )      mask |= CLIP_TOP_BIT;
00140       else if ( cy < -1.0 ) mask |= CLIP_BOTTOM_BIT;
00141       if ( cz >  1.0 )      mask |= CLIP_FAR_BIT;
00142       else if ( cz < -1.0 ) mask |= CLIP_NEAR_BIT;
00143       clipMask[i] = mask;
00144       tmpOrMask |= mask;
00145       tmpAndMask &= mask;
00146    }
00147 
00148    *orMask = tmpOrMask;
00149    *andMask = tmpAndMask;
00150    return clip_vec;
00151 }
00152 
00153 static GLvector4f * ref_cliptest_points2( GLvector4f *clip_vec,
00154                       GLvector4f *proj_vec,
00155                       GLubyte clipMask[],
00156                       GLubyte *orMask,
00157                       GLubyte *andMask )
00158 {
00159    const GLuint stride = clip_vec->stride;
00160    const GLuint count = clip_vec->count;
00161    const GLfloat *from = (GLfloat *)clip_vec->start;
00162 
00163    GLubyte tmpOrMask = *orMask;
00164    GLubyte tmpAndMask = *andMask;
00165    GLuint i;
00166    for ( i = 0 ; i < count ; i++, STRIDE_F(from, stride) ) {
00167       const GLfloat cx = from[0], cy = from[1];
00168       GLubyte mask = 0;
00169       if ( cx >  1.0 )      mask |= CLIP_RIGHT_BIT;
00170       else if ( cx < -1.0 ) mask |= CLIP_LEFT_BIT;
00171       if ( cy >  1.0 )      mask |= CLIP_TOP_BIT;
00172       else if ( cy < -1.0 ) mask |= CLIP_BOTTOM_BIT;
00173       clipMask[i] = mask;
00174       tmpOrMask |= mask;
00175       tmpAndMask &= mask;
00176    }
00177 
00178    *orMask = tmpOrMask;
00179    *andMask = tmpAndMask;
00180    return clip_vec;
00181 }
00182 
00183 static clip_func ref_cliptest[5] = {
00184    0,
00185    0,
00186    ref_cliptest_points2,
00187    ref_cliptest_points3,
00188    ref_cliptest_points4
00189 };
00190 
00191 
00192 /* =============================================================
00193  * Cliptest tests
00194  */
00195 
00196 ALIGN16(static GLfloat, s[TEST_COUNT][4]);
00197 ALIGN16(static GLfloat, d[TEST_COUNT][4]);
00198 ALIGN16(static GLfloat, r[TEST_COUNT][4]);
00199 
00200 
00201 static int test_cliptest_function( clip_func func, int np,
00202                    int psize, long *cycles )
00203 {
00204    GLvector4f source[1], dest[1], ref[1];
00205    GLubyte dm[TEST_COUNT], dco, dca;
00206    GLubyte rm[TEST_COUNT], rco, rca;
00207    int i, j;
00208 #ifdef  RUN_DEBUG_BENCHMARK
00209    int cycle_i;                /* the counter for the benchmarks we run */
00210 #endif
00211 
00212    (void) cycles;
00213 
00214    if ( psize > 4 ) {
00215       _mesa_problem( NULL, "test_cliptest_function called with psize > 4\n" );
00216       return 0;
00217    }
00218 
00219    for ( i = 0 ; i < TEST_COUNT ; i++) {
00220       ASSIGN_4V( d[i], 0.0, 0.0, 0.0, 1.0 );
00221       ASSIGN_4V( s[i], 0.0, 0.0, 0.0, 1.0 );
00222       for ( j = 0 ; j < psize ; j++ )
00223          s[i][j] = rnd();
00224    }
00225 
00226    source->data = (GLfloat(*)[4])s;
00227    source->start = (GLfloat *)s;
00228    source->count = TEST_COUNT;
00229    source->stride = sizeof(s[0]);
00230    source->size = 4;
00231    source->flags = 0;
00232 
00233    dest->data = (GLfloat(*)[4])d;
00234    dest->start = (GLfloat *)d;
00235    dest->count = TEST_COUNT;
00236    dest->stride = sizeof(float[4]);
00237    dest->size = 0;
00238    dest->flags = 0;
00239 
00240    ref->data = (GLfloat(*)[4])r;
00241    ref->start = (GLfloat *)r;
00242    ref->count = TEST_COUNT;
00243    ref->stride = sizeof(float[4]);
00244    ref->size = 0;
00245    ref->flags = 0;
00246 
00247    dco = rco = 0;
00248    dca = rca = CLIP_FRUSTUM_BITS;
00249 
00250    ref_cliptest[psize]( source, ref, rm, &rco, &rca );
00251 
00252    if ( mesa_profile ) {
00253       BEGIN_RACE( *cycles );
00254       func( source, dest, dm, &dco, &dca );
00255       END_RACE( *cycles );
00256    }
00257    else {
00258       func( source, dest, dm, &dco, &dca );
00259    }
00260 
00261    if ( dco != rco ) {
00262       _mesa_printf( "\n-----------------------------\n" );
00263       _mesa_printf( "dco = 0x%02x   rco = 0x%02x\n", dco, rco );
00264       return 0;
00265    }
00266    if ( dca != rca ) {
00267       _mesa_printf( "\n-----------------------------\n" );
00268       _mesa_printf( "dca = 0x%02x   rca = 0x%02x\n", dca, rca );
00269       return 0;
00270    }
00271    for ( i = 0 ; i < TEST_COUNT ; i++ ) {
00272       if ( dm[i] != rm[i] ) {
00273      _mesa_printf( "\n-----------------------------\n" );
00274      _mesa_printf( "(i = %i)\n", i );
00275      _mesa_printf( "dm = 0x%02x   rm = 0x%02x\n", dm[i], rm[i] );
00276      return 0;
00277       }
00278    }
00279 
00280    /* Only verify output on projected points4 case.  FIXME: Do we need
00281     * to test other cases?
00282     */
00283    if ( np || psize < 4 )
00284       return 1;
00285 
00286    for ( i = 0 ; i < TEST_COUNT ; i++ ) {
00287       for ( j = 0 ; j < 4 ; j++ ) {
00288          if ( significand_match( d[i][j], r[i][j] ) < REQUIRED_PRECISION ) {
00289             _mesa_printf( "\n-----------------------------\n" );
00290             _mesa_printf( "(i = %i, j = %i)  dm = 0x%02x   rm = 0x%02x\n",
00291             i, j, dm[i], rm[i] );
00292             _mesa_printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
00293             d[i][0], r[i][0], r[i][0]-d[i][0],
00294             MAX_PRECISION - significand_match( d[i][0], r[i][0] ) );
00295             _mesa_printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
00296             d[i][1], r[i][1], r[i][1]-d[i][1],
00297             MAX_PRECISION - significand_match( d[i][1], r[i][1] ) );
00298             _mesa_printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
00299             d[i][2], r[i][2], r[i][2]-d[i][2],
00300             MAX_PRECISION - significand_match( d[i][2], r[i][2] ) );
00301             _mesa_printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
00302             d[i][3], r[i][3], r[i][3]-d[i][3],
00303             MAX_PRECISION - significand_match( d[i][3], r[i][3] ) );
00304             return 0;
00305          }
00306       }
00307    }
00308 
00309    return 1;
00310 }
00311 
00312 void _math_test_all_cliptest_functions( char *description )
00313 {
00314    int np, psize;
00315    long benchmark_tab[2][4];
00316    static int first_time = 1;
00317 
00318    if ( first_time ) {
00319       first_time = 0;
00320       mesa_profile = _mesa_getenv( "MESA_PROFILE" );
00321    }
00322 
00323 #ifdef RUN_DEBUG_BENCHMARK
00324    if ( mesa_profile ) {
00325       if ( !counter_overhead ) {
00326      INIT_COUNTER();
00327      _mesa_printf( "counter overhead: %ld cycles\n\n", counter_overhead );
00328       }
00329       _mesa_printf( "cliptest results after hooking in %s functions:\n", description );
00330    }
00331 #endif
00332 
00333 #ifdef RUN_DEBUG_BENCHMARK
00334    if ( mesa_profile ) {
00335       _mesa_printf( "\n\t" );
00336       for ( psize = 2 ; psize <= 4 ; psize++ ) {
00337      _mesa_printf( " p%d\t", psize );
00338       }
00339       _mesa_printf( "\n--------------------------------------------------------\n\t" );
00340    }
00341 #endif
00342 
00343    for ( np = 0 ; np < 2 ; np++ ) {
00344       for ( psize = 2 ; psize <= 4 ; psize++ ) {
00345      clip_func func = clip_tab[np][psize];
00346      long *cycles = &(benchmark_tab[np][psize-1]);
00347 
00348      if ( test_cliptest_function( func, np, psize, cycles ) == 0 ) {
00349         char buf[100];
00350         _mesa_sprintf( buf, "%s[%d] failed test (%s)",
00351              cnames[np], psize, description );
00352         _mesa_problem( NULL, buf );
00353      }
00354 #ifdef RUN_DEBUG_BENCHMARK
00355      if ( mesa_profile )
00356         _mesa_printf( " %li\t", benchmark_tab[np][psize-1] );
00357 #endif
00358       }
00359 #ifdef RUN_DEBUG_BENCHMARK
00360       if ( mesa_profile )
00361      _mesa_printf( " | [%s]\n\t", cstrings[np] );
00362 #endif
00363    }
00364 #ifdef RUN_DEBUG_BENCHMARK
00365    if ( mesa_profile )
00366       _mesa_printf( "\n" );
00367 #endif
00368 }
00369 
00370 
00371 #endif /* DEBUG_MATH */

Generated on Sat May 26 2012 04:19:17 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.