X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmath%2Fm_debug_clip.c;h=044768dbdd2d071feb112eea0140d7f24270cb4d;hb=b5f6b9b0eb65a9e095618d00724b74f4f9f1dc62;hp=aad7b6627788b133463b2a5ad857bb1155643f73;hpb=91e98cd153da9e17fa1abda2acf9c4bd5ee0976a;p=mesa.git diff --git a/src/mesa/math/m_debug_clip.c b/src/mesa/math/m_debug_clip.c index aad7b662778..044768dbdd2 100644 --- a/src/mesa/math/m_debug_clip.c +++ b/src/mesa/math/m_debug_clip.c @@ -1,10 +1,7 @@ -/* $Id: m_debug_clip.c,v 1.6 2002/12/04 14:24:44 brianp Exp $ */ - /* * Mesa 3-D graphics library - * Version: 5.0 * - * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -19,18 +16,19 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. * * Authors: * Gareth Hughes */ -#include "glheader.h" -#include "context.h" -#include "macros.h" -#include "imports.h" +#include "main/glheader.h" +#include "main/context.h" +#include "main/macros.h" +#include "main/imports.h" #include "m_matrix.h" #include "m_xform.h" @@ -38,7 +36,12 @@ #include "m_debug.h" #include "m_debug_util.h" -#ifdef DEBUG /* This code only used for debugging */ +#ifdef __UNIXOS2__ +/* The linker doesn't like empty files */ +static char dummy; +#endif + +#ifdef DEBUG_MATH /* This code only used for debugging */ static clip_func *clip_tab[2] = { _mesa_clip_tab, @@ -64,7 +67,8 @@ static GLvector4f *ref_cliptest_points4( GLvector4f *clip_vec, GLvector4f *proj_vec, GLubyte clipMask[], GLubyte *orMask, - GLubyte *andMask ) + GLubyte *andMask, + GLboolean viewport_z_clip ) { const GLuint stride = clip_vec->stride; const GLuint count = clip_vec->count; @@ -84,8 +88,10 @@ static GLvector4f *ref_cliptest_points4( GLvector4f *clip_vec, if ( cx + cw < 0 ) mask |= CLIP_LEFT_BIT; if ( -cy + cw < 0 ) mask |= CLIP_TOP_BIT; if ( cy + cw < 0 ) mask |= CLIP_BOTTOM_BIT; - if ( -cz + cw < 0 ) mask |= CLIP_FAR_BIT; - if ( cz + cw < 0 ) mask |= CLIP_NEAR_BIT; + if (viewport_z_clip) { + if ( -cz + cw < 0 ) mask |= CLIP_FAR_BIT; + if ( cz + cw < 0 ) mask |= CLIP_NEAR_BIT; + } clipMask[i] = mask; if ( mask ) { c++; @@ -119,7 +125,8 @@ static GLvector4f *ref_cliptest_points3( GLvector4f *clip_vec, GLvector4f *proj_vec, GLubyte clipMask[], GLubyte *orMask, - GLubyte *andMask ) + GLubyte *andMask, + GLboolean viewport_z_clip ) { const GLuint stride = clip_vec->stride; const GLuint count = clip_vec->count; @@ -135,8 +142,10 @@ static GLvector4f *ref_cliptest_points3( GLvector4f *clip_vec, else if ( cx < -1.0 ) mask |= CLIP_LEFT_BIT; if ( cy > 1.0 ) mask |= CLIP_TOP_BIT; else if ( cy < -1.0 ) mask |= CLIP_BOTTOM_BIT; - if ( cz > 1.0 ) mask |= CLIP_FAR_BIT; - else if ( cz < -1.0 ) mask |= CLIP_NEAR_BIT; + if (viewport_z_clip) { + if ( cz > 1.0 ) mask |= CLIP_FAR_BIT; + else if ( cz < -1.0 ) mask |= CLIP_NEAR_BIT; + } clipMask[i] = mask; tmpOrMask |= mask; tmpAndMask &= mask; @@ -151,7 +160,8 @@ static GLvector4f * ref_cliptest_points2( GLvector4f *clip_vec, GLvector4f *proj_vec, GLubyte clipMask[], GLubyte *orMask, - GLubyte *andMask ) + GLubyte *andMask, + GLboolean viewport_z_clip ) { const GLuint stride = clip_vec->stride; const GLuint count = clip_vec->count; @@ -160,6 +170,9 @@ static GLvector4f * ref_cliptest_points2( GLvector4f *clip_vec, GLubyte tmpOrMask = *orMask; GLubyte tmpAndMask = *andMask; GLuint i; + + (void) viewport_z_clip; + for ( i = 0 ; i < count ; i++, STRIDE_F(from, stride) ) { const GLfloat cx = from[0], cy = from[1]; GLubyte mask = 0; @@ -190,9 +203,28 @@ static clip_func ref_cliptest[5] = { * Cliptest tests */ -static GLfloat s[TEST_COUNT][4] ALIGN16; -static GLfloat d[TEST_COUNT][4] ALIGN16; -static GLfloat r[TEST_COUNT][4] ALIGN16; +ALIGN16(static GLfloat, s[TEST_COUNT][4]); +ALIGN16(static GLfloat, d[TEST_COUNT][4]); +ALIGN16(static GLfloat, r[TEST_COUNT][4]); + + +/** + * Check if X, Y or Z component of the coordinate is close to W, in terms + * of the clip test. + */ +static GLboolean +xyz_close_to_w(const GLfloat c[4]) +{ + float k = 0.0001; + return (fabs(c[0] - c[3]) < k || + fabs(c[1] - c[3]) < k || + fabs(c[2] - c[3]) < k || + fabs(-c[0] - c[3]) < k || + fabs(-c[1] - c[3]) < k || + fabs(-c[2] - c[3]) < k); +} + + static int test_cliptest_function( clip_func func, int np, int psize, long *cycles ) @@ -204,6 +236,7 @@ static int test_cliptest_function( clip_func func, int np, #ifdef RUN_DEBUG_BENCHMARK int cycle_i; /* the counter for the benchmarks we run */ #endif + GLboolean viewport_z_clip = GL_TRUE; (void) cycles; @@ -241,34 +274,43 @@ static int test_cliptest_function( clip_func func, int np, ref->flags = 0; dco = rco = 0; - dca = rca = CLIP_ALL_BITS; + dca = rca = CLIP_FRUSTUM_BITS; - ref_cliptest[psize]( source, ref, rm, &rco, &rca ); + ref_cliptest[psize]( source, ref, rm, &rco, &rca, viewport_z_clip ); if ( mesa_profile ) { BEGIN_RACE( *cycles ); - func( source, dest, dm, &dco, &dca ); + func( source, dest, dm, &dco, &dca, viewport_z_clip ); END_RACE( *cycles ); } else { - func( source, dest, dm, &dco, &dca ); + func( source, dest, dm, &dco, &dca, viewport_z_clip ); } if ( dco != rco ) { - _mesa_printf( "\n-----------------------------\n" ); - _mesa_printf( "dco = 0x%02x rco = 0x%02x\n", dco, rco ); + printf( "\n-----------------------------\n" ); + printf( "dco = 0x%02x rco = 0x%02x\n", dco, rco ); return 0; } if ( dca != rca ) { - _mesa_printf( "\n-----------------------------\n" ); - _mesa_printf( "dca = 0x%02x rca = 0x%02x\n", dca, rca ); + printf( "\n-----------------------------\n" ); + printf( "dca = 0x%02x rca = 0x%02x\n", dca, rca ); return 0; } for ( i = 0 ; i < TEST_COUNT ; i++ ) { if ( dm[i] != rm[i] ) { - _mesa_printf( "\n-----------------------------\n" ); - _mesa_printf( "(i = %i)\n", i ); - _mesa_printf( "dm = 0x%02x rm = 0x%02x\n", dm[i], rm[i] ); + GLfloat *c = source->start; + STRIDE_F(c, source->stride * i); + if (psize == 4 && xyz_close_to_w(c)) { + /* The coordinate is very close to the clip plane. The clipmask + * may vary depending on code path, but that's OK. + */ + continue; + } + printf( "\n-----------------------------\n" ); + printf( "mask[%d] = 0x%02x ref mask[%d] = 0x%02x\n", i, dm[i], i,rm[i] ); + printf(" coord = %f, %f, %f, %f\n", + c[0], c[1], c[2], c[3]); return 0; } } @@ -282,19 +324,19 @@ static int test_cliptest_function( clip_func func, int np, for ( i = 0 ; i < TEST_COUNT ; i++ ) { for ( j = 0 ; j < 4 ; j++ ) { if ( significand_match( d[i][j], r[i][j] ) < REQUIRED_PRECISION ) { - _mesa_printf( "\n-----------------------------\n" ); - _mesa_printf( "(i = %i, j = %i) dm = 0x%02x rm = 0x%02x\n", + printf( "\n-----------------------------\n" ); + printf( "(i = %i, j = %i) dm = 0x%02x rm = 0x%02x\n", i, j, dm[i], rm[i] ); - _mesa_printf( "%f \t %f \t [diff = %e - %i bit missed]\n", + printf( "%f \t %f \t [diff = %e - %i bit missed]\n", d[i][0], r[i][0], r[i][0]-d[i][0], MAX_PRECISION - significand_match( d[i][0], r[i][0] ) ); - _mesa_printf( "%f \t %f \t [diff = %e - %i bit missed]\n", + printf( "%f \t %f \t [diff = %e - %i bit missed]\n", d[i][1], r[i][1], r[i][1]-d[i][1], MAX_PRECISION - significand_match( d[i][1], r[i][1] ) ); - _mesa_printf( "%f \t %f \t [diff = %e - %i bit missed]\n", + printf( "%f \t %f \t [diff = %e - %i bit missed]\n", d[i][2], r[i][2], r[i][2]-d[i][2], MAX_PRECISION - significand_match( d[i][2], r[i][2] ) ); - _mesa_printf( "%f \t %f \t [diff = %e - %i bit missed]\n", + printf( "%f \t %f \t [diff = %e - %i bit missed]\n", d[i][3], r[i][3], r[i][3]-d[i][3], MAX_PRECISION - significand_match( d[i][3], r[i][3] ) ); return 0; @@ -313,26 +355,26 @@ void _math_test_all_cliptest_functions( char *description ) if ( first_time ) { first_time = 0; - mesa_profile = _mesa_getenv( "MESA_PROFILE" ); + mesa_profile = getenv( "MESA_PROFILE" ); } #ifdef RUN_DEBUG_BENCHMARK if ( mesa_profile ) { if ( !counter_overhead ) { INIT_COUNTER(); - _mesa_printf( "counter overhead: %ld cycles\n\n", counter_overhead ); + printf( "counter overhead: %ld cycles\n\n", counter_overhead ); } - _mesa_printf( "cliptest results after hooking in %s functions:\n", description ); + printf( "cliptest results after hooking in %s functions:\n", description ); } #endif #ifdef RUN_DEBUG_BENCHMARK if ( mesa_profile ) { - _mesa_printf( "\n\t" ); + printf( "\n\t" ); for ( psize = 2 ; psize <= 4 ; psize++ ) { - _mesa_printf( " p%d\t", psize ); + printf( " p%d\t", psize ); } - _mesa_printf( "\n--------------------------------------------------------\n\t" ); + printf( "\n--------------------------------------------------------\n\t" ); } #endif @@ -343,25 +385,25 @@ void _math_test_all_cliptest_functions( char *description ) if ( test_cliptest_function( func, np, psize, cycles ) == 0 ) { char buf[100]; - _mesa_sprintf( buf, "%s[%d] failed test (%s)", + sprintf( buf, "%s[%d] failed test (%s)", cnames[np], psize, description ); - _mesa_problem( NULL, buf ); + _mesa_problem( NULL, "%s", buf ); } #ifdef RUN_DEBUG_BENCHMARK if ( mesa_profile ) - _mesa_printf( " %li\t", benchmark_tab[np][psize-1] ); + printf( " %li\t", benchmark_tab[np][psize-1] ); #endif } #ifdef RUN_DEBUG_BENCHMARK if ( mesa_profile ) - _mesa_printf( " | [%s]\n\t", cstrings[np] ); + printf( " | [%s]\n\t", cstrings[np] ); #endif } #ifdef RUN_DEBUG_BENCHMARK if ( mesa_profile ) - _mesa_printf( "\n" ); + printf( "\n" ); #endif } -#endif /* DEBUG */ +#endif /* DEBUG_MATH */