b6d4a0cd4a6cb4ecfd00d1a57b506550d2155c62
1 /* $Id: m_debug_clip.c,v 1.3 2002/10/24 23:57:24 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 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.
27 * Gareth Hughes <gareth@valinux.com>
39 #include "m_debug_util.h"
41 #ifdef DEBUG /* This code only used for debugging */
43 static clip_func
*clip_tab
[2] = {
47 static char *cnames
[2] = {
51 #ifdef RUN_DEBUG_BENCHMARK
52 static char *cstrings
[2] = {
53 "clip, perspective divide",
59 /* =============================================================
63 static GLvector4f
*ref_cliptest_points4( GLvector4f
*clip_vec
,
69 const GLuint stride
= clip_vec
->stride
;
70 const GLuint count
= clip_vec
->count
;
71 const GLfloat
*from
= (GLfloat
*)clip_vec
->start
;
73 GLfloat (*vProj
)[4] = (GLfloat (*)[4])proj_vec
->start
;
74 GLubyte tmpAndMask
= *andMask
;
75 GLubyte tmpOrMask
= *orMask
;
77 for ( i
= 0 ; i
< count
; i
++, STRIDE_F(from
, stride
) ) {
78 const GLfloat cx
= from
[0];
79 const GLfloat cy
= from
[1];
80 const GLfloat cz
= from
[2];
81 const GLfloat cw
= from
[3];
83 if ( -cx
+ cw
< 0 ) mask
|= CLIP_RIGHT_BIT
;
84 if ( cx
+ cw
< 0 ) mask
|= CLIP_LEFT_BIT
;
85 if ( -cy
+ cw
< 0 ) mask
|= CLIP_TOP_BIT
;
86 if ( cy
+ cw
< 0 ) mask
|= CLIP_BOTTOM_BIT
;
87 if ( -cz
+ cw
< 0 ) mask
|= CLIP_FAR_BIT
;
88 if ( cz
+ cw
< 0 ) mask
|= CLIP_NEAR_BIT
;
99 GLfloat oow
= 1.0F
/ cw
;
100 vProj
[i
][0] = cx
* oow
;
101 vProj
[i
][1] = cy
* oow
;
102 vProj
[i
][2] = cz
* oow
;
108 *andMask
= (GLubyte
) (c
< count
? 0 : tmpAndMask
);
110 proj_vec
->flags
|= VEC_SIZE_4
;
112 proj_vec
->count
= clip_vec
->count
;
116 /* Keep these here for now, even though we don't use them...
118 static GLvector4f
*ref_cliptest_points3( GLvector4f
*clip_vec
,
119 GLvector4f
*proj_vec
,
124 const GLuint stride
= clip_vec
->stride
;
125 const GLuint count
= clip_vec
->count
;
126 const GLfloat
*from
= (GLfloat
*)clip_vec
->start
;
128 GLubyte tmpOrMask
= *orMask
;
129 GLubyte tmpAndMask
= *andMask
;
131 for ( i
= 0 ; i
< count
; i
++, STRIDE_F(from
, stride
) ) {
132 const GLfloat cx
= from
[0], cy
= from
[1], cz
= from
[2];
134 if ( cx
> 1.0 ) mask
|= CLIP_RIGHT_BIT
;
135 else if ( cx
< -1.0 ) mask
|= CLIP_LEFT_BIT
;
136 if ( cy
> 1.0 ) mask
|= CLIP_TOP_BIT
;
137 else if ( cy
< -1.0 ) mask
|= CLIP_BOTTOM_BIT
;
138 if ( cz
> 1.0 ) mask
|= CLIP_FAR_BIT
;
139 else if ( cz
< -1.0 ) mask
|= CLIP_NEAR_BIT
;
146 *andMask
= tmpAndMask
;
150 static GLvector4f
* ref_cliptest_points2( GLvector4f
*clip_vec
,
151 GLvector4f
*proj_vec
,
156 const GLuint stride
= clip_vec
->stride
;
157 const GLuint count
= clip_vec
->count
;
158 const GLfloat
*from
= (GLfloat
*)clip_vec
->start
;
160 GLubyte tmpOrMask
= *orMask
;
161 GLubyte tmpAndMask
= *andMask
;
163 for ( i
= 0 ; i
< count
; i
++, STRIDE_F(from
, stride
) ) {
164 const GLfloat cx
= from
[0], cy
= from
[1];
166 if ( cx
> 1.0 ) mask
|= CLIP_RIGHT_BIT
;
167 else if ( cx
< -1.0 ) mask
|= CLIP_LEFT_BIT
;
168 if ( cy
> 1.0 ) mask
|= CLIP_TOP_BIT
;
169 else if ( cy
< -1.0 ) mask
|= CLIP_BOTTOM_BIT
;
176 *andMask
= tmpAndMask
;
180 static clip_func ref_cliptest
[5] = {
183 ref_cliptest_points2
,
184 ref_cliptest_points3
,
189 /* =============================================================
193 static GLfloat s
[TEST_COUNT
][4] ALIGN16
;
194 static GLfloat d
[TEST_COUNT
][4] ALIGN16
;
195 static GLfloat r
[TEST_COUNT
][4] ALIGN16
;
197 static int test_cliptest_function( clip_func func
, int np
,
198 int psize
, long *cycles
)
200 GLvector4f source
[1], dest
[1], ref
[1];
201 GLubyte dm
[TEST_COUNT
], dco
, dca
;
202 GLubyte rm
[TEST_COUNT
], rco
, rca
;
204 #ifdef RUN_DEBUG_BENCHMARK
205 int cycle_i
; /* the counter for the benchmarks we run */
211 _mesa_problem( NULL
, "test_cliptest_function called with psize > 4\n" );
215 for ( i
= 0 ; i
< TEST_COUNT
; i
++) {
216 ASSIGN_4V( d
[i
], 0.0, 0.0, 0.0, 1.0 );
217 ASSIGN_4V( s
[i
], 0.0, 0.0, 0.0, 1.0 );
218 for ( j
= 0 ; j
< psize
; j
++ )
222 source
->data
= (GLfloat(*)[4])s
;
223 source
->start
= (GLfloat
*)s
;
224 source
->count
= TEST_COUNT
;
225 source
->stride
= sizeof(s
[0]);
229 dest
->data
= (GLfloat(*)[4])d
;
230 dest
->start
= (GLfloat
*)d
;
231 dest
->count
= TEST_COUNT
;
232 dest
->stride
= sizeof(float[4]);
236 ref
->data
= (GLfloat(*)[4])r
;
237 ref
->start
= (GLfloat
*)r
;
238 ref
->count
= TEST_COUNT
;
239 ref
->stride
= sizeof(float[4]);
244 dca
= rca
= CLIP_ALL_BITS
;
246 ref_cliptest
[psize
]( source
, ref
, rm
, &rco
, &rca
);
248 if ( mesa_profile
) {
249 BEGIN_RACE( *cycles
);
250 func( source
, dest
, dm
, &dco
, &dca
);
254 func( source
, dest
, dm
, &dco
, &dca
);
258 _mesa_printf(NULL
, "\n-----------------------------\n" );
259 _mesa_printf(NULL
, "dco = 0x%02x rco = 0x%02x\n", dco
, rco
);
263 _mesa_printf(NULL
, "\n-----------------------------\n" );
264 _mesa_printf(NULL
, "dca = 0x%02x rca = 0x%02x\n", dca
, rca
);
267 for ( i
= 0 ; i
< TEST_COUNT
; i
++ ) {
268 if ( dm
[i
] != rm
[i
] ) {
269 _mesa_printf(NULL
, "\n-----------------------------\n" );
270 _mesa_printf(NULL
, "(i = %i)\n", i
);
271 _mesa_printf(NULL
, "dm = 0x%02x rm = 0x%02x\n", dm
[i
], rm
[i
] );
276 /* Only verify output on projected points4 case. FIXME: Do we need
277 * to test other cases?
279 if ( np
|| psize
< 4 )
282 for ( i
= 0 ; i
< TEST_COUNT
; i
++ ) {
283 for ( j
= 0 ; j
< 4 ; j
++ ) {
284 if ( significand_match( d
[i
][j
], r
[i
][j
] ) < REQUIRED_PRECISION
) {
285 _mesa_printf(NULL
, "\n-----------------------------\n" );
286 _mesa_printf(NULL
, "(i = %i, j = %i) dm = 0x%02x rm = 0x%02x\n",
287 i
, j
, dm
[i
], rm
[i
] );
288 _mesa_printf(NULL
, "%f \t %f \t [diff = %e - %i bit missed]\n",
289 d
[i
][0], r
[i
][0], r
[i
][0]-d
[i
][0],
290 MAX_PRECISION
- significand_match( d
[i
][0], r
[i
][0] ) );
291 _mesa_printf(NULL
, "%f \t %f \t [diff = %e - %i bit missed]\n",
292 d
[i
][1], r
[i
][1], r
[i
][1]-d
[i
][1],
293 MAX_PRECISION
- significand_match( d
[i
][1], r
[i
][1] ) );
294 _mesa_printf(NULL
, "%f \t %f \t [diff = %e - %i bit missed]\n",
295 d
[i
][2], r
[i
][2], r
[i
][2]-d
[i
][2],
296 MAX_PRECISION
- significand_match( d
[i
][2], r
[i
][2] ) );
297 _mesa_printf(NULL
, "%f \t %f \t [diff = %e - %i bit missed]\n",
298 d
[i
][3], r
[i
][3], r
[i
][3]-d
[i
][3],
299 MAX_PRECISION
- significand_match( d
[i
][3], r
[i
][3] ) );
308 void _math_test_all_cliptest_functions( char *description
)
311 long benchmark_tab
[2][4];
312 static int first_time
= 1;
316 mesa_profile
= getenv( "MESA_PROFILE" );
319 #ifdef RUN_DEBUG_BENCHMARK
320 if ( mesa_profile
) {
321 if ( !counter_overhead
) {
323 _mesa_printf(NULL
, "counter overhead: %ld cycles\n\n", counter_overhead
);
325 _mesa_printf(NULL
, "cliptest results after hooking in %s functions:\n", description
);
329 #ifdef RUN_DEBUG_BENCHMARK
330 if ( mesa_profile
) {
331 _mesa_printf(NULL
, "\n\t" );
332 for ( psize
= 2 ; psize
<= 4 ; psize
++ ) {
333 _mesa_printf(NULL
, " p%d\t", psize
);
335 _mesa_printf(NULL
, "\n--------------------------------------------------------\n\t" );
339 for ( np
= 0 ; np
< 2 ; np
++ ) {
340 for ( psize
= 2 ; psize
<= 4 ; psize
++ ) {
341 clip_func func
= clip_tab
[np
][psize
];
342 long *cycles
= &(benchmark_tab
[np
][psize
-1]);
344 if ( test_cliptest_function( func
, np
, psize
, cycles
) == 0 ) {
346 _mesa_sprintf(NULL
, buf
, "%s[%d] failed test (%s)",
347 cnames
[np
], psize
, description
);
348 _mesa_problem( NULL
, buf
);
350 #ifdef RUN_DEBUG_BENCHMARK
352 _mesa_printf(NULL
, " %li\t", benchmark_tab
[np
][psize
-1] );
355 #ifdef RUN_DEBUG_BENCHMARK
357 _mesa_printf(NULL
, " | [%s]\n\t", cstrings
[np
] );
360 #ifdef RUN_DEBUG_BENCHMARK
362 _mesa_printf(NULL
, "\n" );