3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 #include "m_debug_util.h"
40 #ifdef DEBUG /* This code only used for debugging */
42 static clip_func
*clip_tab
[2] = {
46 static char *cnames
[2] = {
50 #ifdef RUN_DEBUG_BENCHMARK
51 static char *cstrings
[2] = {
52 "clip, perspective divide",
58 /* =============================================================
62 static GLvector4f
*ref_cliptest_points4( GLvector4f
*clip_vec
,
68 const GLuint stride
= clip_vec
->stride
;
69 const GLuint count
= clip_vec
->count
;
70 const GLfloat
*from
= (GLfloat
*)clip_vec
->start
;
72 GLfloat (*vProj
)[4] = (GLfloat (*)[4])proj_vec
->start
;
73 GLubyte tmpAndMask
= *andMask
;
74 GLubyte tmpOrMask
= *orMask
;
76 for ( i
= 0 ; i
< count
; i
++, STRIDE_F(from
, stride
) ) {
77 const GLfloat cx
= from
[0];
78 const GLfloat cy
= from
[1];
79 const GLfloat cz
= from
[2];
80 const GLfloat cw
= from
[3];
82 if ( -cx
+ cw
< 0 ) mask
|= CLIP_RIGHT_BIT
;
83 if ( cx
+ cw
< 0 ) mask
|= CLIP_LEFT_BIT
;
84 if ( -cy
+ cw
< 0 ) mask
|= CLIP_TOP_BIT
;
85 if ( cy
+ cw
< 0 ) mask
|= CLIP_BOTTOM_BIT
;
86 if ( -cz
+ cw
< 0 ) mask
|= CLIP_FAR_BIT
;
87 if ( cz
+ cw
< 0 ) mask
|= CLIP_NEAR_BIT
;
98 GLfloat oow
= 1.0F
/ cw
;
99 vProj
[i
][0] = cx
* oow
;
100 vProj
[i
][1] = cy
* oow
;
101 vProj
[i
][2] = cz
* oow
;
107 *andMask
= (GLubyte
) (c
< count
? 0 : tmpAndMask
);
109 proj_vec
->flags
|= VEC_SIZE_4
;
111 proj_vec
->count
= clip_vec
->count
;
115 /* Keep these here for now, even though we don't use them...
117 static GLvector4f
*ref_cliptest_points3( GLvector4f
*clip_vec
,
118 GLvector4f
*proj_vec
,
123 const GLuint stride
= clip_vec
->stride
;
124 const GLuint count
= clip_vec
->count
;
125 const GLfloat
*from
= (GLfloat
*)clip_vec
->start
;
127 GLubyte tmpOrMask
= *orMask
;
128 GLubyte tmpAndMask
= *andMask
;
130 for ( i
= 0 ; i
< count
; i
++, STRIDE_F(from
, stride
) ) {
131 const GLfloat cx
= from
[0], cy
= from
[1], cz
= from
[2];
133 if ( cx
> 1.0 ) mask
|= CLIP_RIGHT_BIT
;
134 else if ( cx
< -1.0 ) mask
|= CLIP_LEFT_BIT
;
135 if ( cy
> 1.0 ) mask
|= CLIP_TOP_BIT
;
136 else if ( cy
< -1.0 ) mask
|= CLIP_BOTTOM_BIT
;
137 if ( cz
> 1.0 ) mask
|= CLIP_FAR_BIT
;
138 else if ( cz
< -1.0 ) mask
|= CLIP_NEAR_BIT
;
145 *andMask
= tmpAndMask
;
149 static GLvector4f
* ref_cliptest_points2( GLvector4f
*clip_vec
,
150 GLvector4f
*proj_vec
,
155 const GLuint stride
= clip_vec
->stride
;
156 const GLuint count
= clip_vec
->count
;
157 const GLfloat
*from
= (GLfloat
*)clip_vec
->start
;
159 GLubyte tmpOrMask
= *orMask
;
160 GLubyte tmpAndMask
= *andMask
;
162 for ( i
= 0 ; i
< count
; i
++, STRIDE_F(from
, stride
) ) {
163 const GLfloat cx
= from
[0], cy
= from
[1];
165 if ( cx
> 1.0 ) mask
|= CLIP_RIGHT_BIT
;
166 else if ( cx
< -1.0 ) mask
|= CLIP_LEFT_BIT
;
167 if ( cy
> 1.0 ) mask
|= CLIP_TOP_BIT
;
168 else if ( cy
< -1.0 ) mask
|= CLIP_BOTTOM_BIT
;
175 *andMask
= tmpAndMask
;
179 static clip_func ref_cliptest
[5] = {
182 ref_cliptest_points2
,
183 ref_cliptest_points3
,
188 /* =============================================================
192 static GLfloat s
[TEST_COUNT
][4] ALIGN16
;
193 static GLfloat d
[TEST_COUNT
][4] ALIGN16
;
194 static GLfloat r
[TEST_COUNT
][4] ALIGN16
;
196 static int test_cliptest_function( clip_func func
, int np
,
197 int psize
, long *cycles
)
199 GLvector4f source
[1], dest
[1], ref
[1];
200 GLubyte dm
[TEST_COUNT
], dco
, dca
;
201 GLubyte rm
[TEST_COUNT
], rco
, rca
;
203 #ifdef RUN_DEBUG_BENCHMARK
204 int cycle_i
; /* the counter for the benchmarks we run */
210 _mesa_problem( NULL
, "test_cliptest_function called with psize > 4\n" );
214 for ( i
= 0 ; i
< TEST_COUNT
; i
++) {
215 ASSIGN_4V( d
[i
], 0.0, 0.0, 0.0, 1.0 );
216 ASSIGN_4V( s
[i
], 0.0, 0.0, 0.0, 1.0 );
217 for ( j
= 0 ; j
< psize
; j
++ )
221 source
->data
= (GLfloat(*)[4])s
;
222 source
->start
= (GLfloat
*)s
;
223 source
->count
= TEST_COUNT
;
224 source
->stride
= sizeof(s
[0]);
228 dest
->data
= (GLfloat(*)[4])d
;
229 dest
->start
= (GLfloat
*)d
;
230 dest
->count
= TEST_COUNT
;
231 dest
->stride
= sizeof(float[4]);
235 ref
->data
= (GLfloat(*)[4])r
;
236 ref
->start
= (GLfloat
*)r
;
237 ref
->count
= TEST_COUNT
;
238 ref
->stride
= sizeof(float[4]);
243 dca
= rca
= CLIP_ALL_BITS
;
245 ref_cliptest
[psize
]( source
, ref
, rm
, &rco
, &rca
);
247 if ( mesa_profile
) {
248 BEGIN_RACE( *cycles
);
249 func( source
, dest
, dm
, &dco
, &dca
);
253 func( source
, dest
, dm
, &dco
, &dca
);
257 _mesa_printf( "\n-----------------------------\n" );
258 _mesa_printf( "dco = 0x%02x rco = 0x%02x\n", dco
, rco
);
262 _mesa_printf( "\n-----------------------------\n" );
263 _mesa_printf( "dca = 0x%02x rca = 0x%02x\n", dca
, rca
);
266 for ( i
= 0 ; i
< TEST_COUNT
; i
++ ) {
267 if ( dm
[i
] != rm
[i
] ) {
268 _mesa_printf( "\n-----------------------------\n" );
269 _mesa_printf( "(i = %i)\n", i
);
270 _mesa_printf( "dm = 0x%02x rm = 0x%02x\n", dm
[i
], rm
[i
] );
275 /* Only verify output on projected points4 case. FIXME: Do we need
276 * to test other cases?
278 if ( np
|| psize
< 4 )
281 for ( i
= 0 ; i
< TEST_COUNT
; i
++ ) {
282 for ( j
= 0 ; j
< 4 ; j
++ ) {
283 if ( significand_match( d
[i
][j
], r
[i
][j
] ) < REQUIRED_PRECISION
) {
284 _mesa_printf( "\n-----------------------------\n" );
285 _mesa_printf( "(i = %i, j = %i) dm = 0x%02x rm = 0x%02x\n",
286 i
, j
, dm
[i
], rm
[i
] );
287 _mesa_printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
288 d
[i
][0], r
[i
][0], r
[i
][0]-d
[i
][0],
289 MAX_PRECISION
- significand_match( d
[i
][0], r
[i
][0] ) );
290 _mesa_printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
291 d
[i
][1], r
[i
][1], r
[i
][1]-d
[i
][1],
292 MAX_PRECISION
- significand_match( d
[i
][1], r
[i
][1] ) );
293 _mesa_printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
294 d
[i
][2], r
[i
][2], r
[i
][2]-d
[i
][2],
295 MAX_PRECISION
- significand_match( d
[i
][2], r
[i
][2] ) );
296 _mesa_printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
297 d
[i
][3], r
[i
][3], r
[i
][3]-d
[i
][3],
298 MAX_PRECISION
- significand_match( d
[i
][3], r
[i
][3] ) );
307 void _math_test_all_cliptest_functions( char *description
)
310 long benchmark_tab
[2][4];
311 static int first_time
= 1;
315 mesa_profile
= _mesa_getenv( "MESA_PROFILE" );
318 #ifdef RUN_DEBUG_BENCHMARK
319 if ( mesa_profile
) {
320 if ( !counter_overhead
) {
322 _mesa_printf( "counter overhead: %ld cycles\n\n", counter_overhead
);
324 _mesa_printf( "cliptest results after hooking in %s functions:\n", description
);
328 #ifdef RUN_DEBUG_BENCHMARK
329 if ( mesa_profile
) {
330 _mesa_printf( "\n\t" );
331 for ( psize
= 2 ; psize
<= 4 ; psize
++ ) {
332 _mesa_printf( " p%d\t", psize
);
334 _mesa_printf( "\n--------------------------------------------------------\n\t" );
338 for ( np
= 0 ; np
< 2 ; np
++ ) {
339 for ( psize
= 2 ; psize
<= 4 ; psize
++ ) {
340 clip_func func
= clip_tab
[np
][psize
];
341 long *cycles
= &(benchmark_tab
[np
][psize
-1]);
343 if ( test_cliptest_function( func
, np
, psize
, cycles
) == 0 ) {
345 _mesa_sprintf( buf
, "%s[%d] failed test (%s)",
346 cnames
[np
], psize
, description
);
347 _mesa_problem( NULL
, buf
);
349 #ifdef RUN_DEBUG_BENCHMARK
351 _mesa_printf( " %li\t", benchmark_tab
[np
][psize
-1] );
354 #ifdef RUN_DEBUG_BENCHMARK
356 _mesa_printf( " | [%s]\n\t", cstrings
[np
] );
359 #ifdef RUN_DEBUG_BENCHMARK
361 _mesa_printf( "\n" );