8b26a233b43d099cfab6517420d220bb7ee86f13
1 /* $Id: m_debug_xform.c,v 1.3 2001/03/03 20:33:30 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Updated for P6 architecture by Gareth Hughes.
40 #include "m_debug_util.h"
42 #ifdef DEBUG /* This code only used for debugging */
45 /* Overhead of profiling counter in cycles. Automatically adjusted to
46 * your machine at run time - counter initialization should give very
49 long counter_overhead
= 0;
51 /* This is the value of the environment variable MESA_PROFILE, and is
52 * used to determine if we should benchmark the functions as well as
53 * verify their correctness.
55 char *mesa_profile
= NULL
;
58 static int m_general
[16] = {
64 static int m_identity
[16] = {
70 static int m_2d
[16] = {
76 static int m_2d_no_rot
[16] = {
82 static int m_3d
[16] = {
88 static int m_3d_no_rot
[16] = {
94 static int m_perspective
[16] = {
100 static int *templates
[7] = {
109 static int mtypes
[7] = {
118 static char *mstrings
[7] = {
122 "MATRIX_PERSPECTIVE",
129 /* ================================================================
130 * Reference transformations
133 static void ref_transform( GLvector4f
*dst
,
135 const GLvector4f
*src
,
136 const GLubyte
*clipmask
,
140 GLfloat
*s
= (GLfloat
*)src
->start
;
141 GLfloat (*d
)[4] = (GLfloat (*)[4])dst
->start
;
142 const GLfloat
*m
= mat
->m
;
147 for ( i
= 0 ; i
< src
->count
; i
++ ) {
148 TRANSFORM_POINT( d
[i
], m
, s
);
149 s
= (GLfloat
*)((char *)s
+ src
->stride
);
154 /* ================================================================
155 * Vertex transformation tests
158 static GLfloat s
[TEST_COUNT
][5] ALIGN16
;
159 static GLfloat d
[TEST_COUNT
][4] ALIGN16
;
160 static GLfloat r
[TEST_COUNT
][4] ALIGN16
;
162 static int test_transform_function( transform_func func
, int psize
, int mtype
,
163 int masked
, long *cycles
)
165 GLvector4f source
[1], dest
[1], ref
[1];
168 GLubyte mask
[TEST_COUNT
];
170 #ifdef RUN_DEBUG_BENCHMARK
171 int cycle_i
; /* the counter for the benchmarks we run */
177 _mesa_problem( NULL
, "test_transform_function called with psize > 4\n" );
181 mat
->m
= (GLfloat
*) ALIGN_MALLOC( 16 * sizeof(GLfloat
), 16 );
182 mat
->type
= mtypes
[mtype
];
188 for ( i
= 0 ; i
< 4 ; i
++ ) {
189 for ( j
= 0 ; j
< 4 ; j
++ ) {
190 switch ( templates
[mtype
][i
* 4 + j
] ) {
208 for ( i
= 0 ; i
< TEST_COUNT
; i
++) {
209 mask
[i
] = i
% 2; /* mask every 2nd element */
210 ASSIGN_4V( d
[i
], 0.0, 0.0, 0.0, 1.0 );
211 ASSIGN_4V( s
[i
], 0.0, 0.0, 0.0, 1.0 );
212 for ( j
= 0 ; j
< psize
; j
++ )
216 source
->data
= (GLfloat(*)[4])s
;
217 source
->start
= (GLfloat
*)s
;
218 source
->count
= TEST_COUNT
;
219 source
->stride
= sizeof(s
[0]);
223 dest
->data
= (GLfloat(*)[4])d
;
224 dest
->start
= (GLfloat
*)d
;
225 dest
->count
= TEST_COUNT
;
226 dest
->stride
= sizeof(float[4]);
230 ref
->data
= (GLfloat(*)[4])r
;
231 ref
->start
= (GLfloat
*)r
;
232 ref
->count
= TEST_COUNT
;
233 ref
->stride
= sizeof(float[4]);
237 ref_transform( ref
, mat
, source
, NULL
, 0 );
239 if ( mesa_profile
) {
241 BEGIN_RACE( *cycles
);
242 func( dest
, mat
->m
, source
, mask
, 1 );
245 BEGIN_RACE( *cycles
);
246 func( dest
, mat
->m
, source
, NULL
, 0 );
252 func( dest
, mat
->m
, source
, mask
, 1 );
254 func( dest
, mat
->m
, source
, NULL
, 0 );
258 for ( i
= 0 ; i
< TEST_COUNT
; i
++ ) {
259 if ( masked
&& (mask
[i
] & 1) )
262 for ( j
= 0 ; j
< 4 ; j
++ ) {
263 if ( significand_match( d
[i
][j
], r
[i
][j
] ) < REQUIRED_PRECISION
) {
264 printf( "-----------------------------\n" );
265 printf( "(i = %i, j = %i)\n", i
, j
);
266 printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
267 d
[i
][0], r
[i
][0], r
[i
][0]-d
[i
][0],
268 MAX_PRECISION
- significand_match( d
[i
][0], r
[i
][0] ) );
269 printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
270 d
[i
][1], r
[i
][1], r
[i
][1]-d
[i
][1],
271 MAX_PRECISION
- significand_match( d
[i
][1], r
[i
][1] ) );
272 printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
273 d
[i
][2], r
[i
][2], r
[i
][2]-d
[i
][2],
274 MAX_PRECISION
- significand_match( d
[i
][2], r
[i
][2] ) );
275 printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
276 d
[i
][3], r
[i
][3], r
[i
][3]-d
[i
][3],
277 MAX_PRECISION
- significand_match( d
[i
][3], r
[i
][3] ) );
283 ALIGN_FREE( mat
->m
);
287 void _math_test_all_transform_functions( char *description
)
289 int masked
, psize
, mtype
;
290 long benchmark_tab
[2][4][7];
291 static int first_time
= 1;
295 mesa_profile
= getenv( "MESA_PROFILE" );
298 #ifdef RUN_DEBUG_BENCHMARK
299 if ( mesa_profile
) {
300 if ( !counter_overhead
) {
302 printf( "counter overhead: %ld cycles\n\n", counter_overhead
);
304 printf( "transform results after hooking in %s functions:\n", description
);
308 for ( masked
= 0 ; masked
<= 1 ; masked
++ ) {
309 int cma
= masked
? 1 : 0;
310 char *cmastring
= masked
? "CULL_MASK_ACTIVE" : "0";
312 #ifdef RUN_DEBUG_BENCHMARK
313 if ( mesa_profile
) {
314 printf( "\n culling: %s \n", masked
? "CULL_MASK_ACTIVE" : "0" );
315 for ( psize
= 1 ; psize
<= 4 ; psize
++ ) {
316 printf( " p%d\t", psize
);
318 printf( "\n--------------------------------------------------------\n" );
322 for ( mtype
= 0 ; mtype
< 7 ; mtype
++ ) {
323 for ( psize
= 1 ; psize
<= 4 ; psize
++ ) {
324 transform_func func
= _mesa_transform_tab
[cma
][psize
][mtypes
[mtype
]];
325 long *cycles
= &(benchmark_tab
[cma
][psize
-1][mtype
]);
327 if ( test_transform_function( func
, psize
, mtype
,
328 masked
, cycles
) == 0 ) {
330 sprintf( buf
, "_mesa_transform_tab[%s][%d][%s] failed test (%s)",
331 cmastring
, psize
, mstrings
[mtype
], description
);
332 _mesa_problem( NULL
, buf
);
334 #ifdef RUN_DEBUG_BENCHMARK
336 printf( " %li\t", benchmark_tab
[cma
][psize
-1][mtype
] );
339 #ifdef RUN_DEBUG_BENCHMARK
341 printf( " | [%s]\n", mstrings
[mtype
] );
344 #ifdef RUN_DEBUG_BENCHMARK