Rev 134 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
134 | giacomo | 1 | /* $Id: m_xform_debug.c,v 1.1 2003-04-24 13:37:47 giacomo Exp $ */ |
2 | |||
3 | /* |
||
4 | * Mesa 3-D graphics library |
||
5 | * Version: 3.5 |
||
6 | * |
||
7 | * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. |
||
8 | * |
||
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: |
||
15 | * |
||
16 | * The above copyright notice and this permission notice shall be included |
||
17 | * in all copies or substantial portions of the Software. |
||
18 | * |
||
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. |
||
25 | */ |
||
26 | |||
27 | /* |
||
28 | * Updated for P6 architecture by Gareth Hughes. |
||
29 | */ |
||
30 | |||
31 | #include "glheader.h" |
||
32 | #include "context.h" |
||
33 | #include "macros.h" |
||
34 | #include "imports.h" |
||
35 | |||
36 | #include "m_matrix.h" |
||
37 | #include "m_xform.h" |
||
38 | |||
39 | #include "m_debug.h" |
||
40 | #include "m_debug_util.h" |
||
41 | |||
42 | #ifdef DEBUG /* This code only used for debugging */ |
||
43 | |||
44 | |||
45 | /* Overhead of profiling counter in cycles. Automatically adjusted to |
||
46 | * your machine at run time - counter initialization should give very |
||
47 | * consistent results. |
||
48 | */ |
||
49 | long counter_overhead = 0; |
||
50 | |||
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. |
||
54 | */ |
||
55 | char *mesa_profile = NULL; |
||
56 | |||
57 | |||
58 | static int m_general[16] = { |
||
59 | VAR, VAR, VAR, VAR, |
||
60 | VAR, VAR, VAR, VAR, |
||
61 | VAR, VAR, VAR, VAR, |
||
62 | VAR, VAR, VAR, VAR |
||
63 | }; |
||
64 | static int m_identity[16] = { |
||
65 | ONE, NIL, NIL, NIL, |
||
66 | NIL, ONE, NIL, NIL, |
||
67 | NIL, NIL, ONE, NIL, |
||
68 | NIL, NIL, NIL, ONE |
||
69 | }; |
||
70 | static int m_2d[16] = { |
||
71 | VAR, VAR, NIL, VAR, |
||
72 | VAR, VAR, NIL, VAR, |
||
73 | NIL, NIL, ONE, NIL, |
||
74 | NIL, NIL, NIL, ONE |
||
75 | }; |
||
76 | static int m_2d_no_rot[16] = { |
||
77 | VAR, NIL, NIL, VAR, |
||
78 | NIL, VAR, NIL, VAR, |
||
79 | NIL, NIL, ONE, NIL, |
||
80 | NIL, NIL, NIL, ONE |
||
81 | }; |
||
82 | static int m_3d[16] = { |
||
83 | VAR, VAR, VAR, VAR, |
||
84 | VAR, VAR, VAR, VAR, |
||
85 | VAR, VAR, VAR, VAR, |
||
86 | NIL, NIL, NIL, ONE |
||
87 | }; |
||
88 | static int m_3d_no_rot[16] = { |
||
89 | VAR, NIL, NIL, VAR, |
||
90 | NIL, VAR, NIL, VAR, |
||
91 | NIL, NIL, VAR, VAR, |
||
92 | NIL, NIL, NIL, ONE |
||
93 | }; |
||
94 | static int m_perspective[16] = { |
||
95 | VAR, NIL, VAR, NIL, |
||
96 | NIL, VAR, VAR, NIL, |
||
97 | NIL, NIL, VAR, VAR, |
||
98 | NIL, NIL, NEG, NIL |
||
99 | }; |
||
100 | static int *templates[7] = { |
||
101 | m_general, |
||
102 | m_identity, |
||
103 | m_3d_no_rot, |
||
104 | m_perspective, |
||
105 | m_2d, |
||
106 | m_2d_no_rot, |
||
107 | m_3d |
||
108 | }; |
||
109 | static int mtypes[7] = { |
||
110 | MATRIX_GENERAL, |
||
111 | MATRIX_IDENTITY, |
||
112 | MATRIX_3D_NO_ROT, |
||
113 | MATRIX_PERSPECTIVE, |
||
114 | MATRIX_2D, |
||
115 | MATRIX_2D_NO_ROT, |
||
116 | MATRIX_3D |
||
117 | }; |
||
118 | static char *mstrings[7] = { |
||
119 | "MATRIX_GENERAL", |
||
120 | "MATRIX_IDENTITY", |
||
121 | "MATRIX_3D_NO_ROT", |
||
122 | "MATRIX_PERSPECTIVE", |
||
123 | "MATRIX_2D", |
||
124 | "MATRIX_2D_NO_ROT", |
||
125 | "MATRIX_3D" |
||
126 | }; |
||
127 | |||
128 | |||
129 | /* ============================================================= |
||
130 | * Reference transformations |
||
131 | */ |
||
132 | |||
133 | static void ref_transform( GLvector4f *dst, |
||
134 | const GLmatrix *mat, |
||
135 | const GLvector4f *src ) |
||
136 | { |
||
137 | GLuint i; |
||
138 | GLfloat *s = (GLfloat *)src->start; |
||
139 | GLfloat (*d)[4] = (GLfloat (*)[4])dst->start; |
||
140 | const GLfloat *m = mat->m; |
||
141 | |||
142 | for ( i = 0 ; i < src->count ; i++ ) { |
||
143 | TRANSFORM_POINT( d[i], m, s ); |
||
144 | s = (GLfloat *)((char *)s + src->stride); |
||
145 | } |
||
146 | } |
||
147 | |||
148 | |||
149 | /* ============================================================= |
||
150 | * Vertex transformation tests |
||
151 | */ |
||
152 | |||
153 | static void init_matrix( GLfloat *m ) |
||
154 | { |
||
155 | m[0] = 63.0; m[4] = 43.0; m[ 8] = 29.0; m[12] = 43.0; |
||
156 | m[1] = 55.0; m[5] = 17.0; m[ 9] = 31.0; m[13] = 7.0; |
||
157 | m[2] = 44.0; m[6] = 9.0; m[10] = 7.0; m[14] = 3.0; |
||
158 | m[3] = 11.0; m[7] = 23.0; m[11] = 91.0; m[15] = 9.0; |
||
159 | } |
||
160 | |||
161 | static GLfloat s[TEST_COUNT][4] ALIGN16; |
||
162 | static GLfloat d[TEST_COUNT][4] ALIGN16; |
||
163 | static GLfloat r[TEST_COUNT][4] ALIGN16; |
||
164 | |||
165 | static int test_transform_function( transform_func func, int psize, |
||
166 | int mtype, long *cycles ) |
||
167 | { |
||
168 | GLvector4f source[1], dest[1], ref[1]; |
||
169 | GLmatrix mat[1]; |
||
170 | GLfloat *m; |
||
171 | int i, j; |
||
172 | #ifdef RUN_DEBUG_BENCHMARK |
||
173 | int cycle_i; /* the counter for the benchmarks we run */ |
||
174 | #endif |
||
175 | |||
176 | (void) cycles; |
||
177 | |||
178 | if ( psize > 4 ) { |
||
179 | _mesa_problem( NULL, "test_transform_function called with psize > 4\n" ); |
||
180 | return 0; |
||
181 | } |
||
182 | |||
183 | mat->m = (GLfloat *) ALIGN_MALLOC( 16 * sizeof(GLfloat), 16 ); |
||
184 | mat->type = mtypes[mtype]; |
||
185 | |||
186 | m = mat->m; |
||
187 | ASSERT( ((GLuint)m & 15) == 0 ); |
||
188 | |||
189 | init_matrix( m ); |
||
190 | |||
191 | for ( i = 0 ; i < 4 ; i++ ) { |
||
192 | for ( j = 0 ; j < 4 ; j++ ) { |
||
193 | switch ( templates[mtype][i * 4 + j] ) { |
||
194 | case NIL: |
||
195 | m[j * 4 + i] = 0.0; |
||
196 | break; |
||
197 | case ONE: |
||
198 | m[j * 4 + i] = 1.0; |
||
199 | break; |
||
200 | case NEG: |
||
201 | m[j * 4 + i] = -1.0; |
||
202 | break; |
||
203 | case VAR: |
||
204 | break; |
||
205 | default: |
||
206 | abort(); |
||
207 | } |
||
208 | } |
||
209 | } |
||
210 | |||
211 | for ( i = 0 ; i < TEST_COUNT ; i++) { |
||
212 | ASSIGN_4V( d[i], 0.0, 0.0, 0.0, 1.0 ); |
||
213 | ASSIGN_4V( s[i], 0.0, 0.0, 0.0, 1.0 ); |
||
214 | for ( j = 0 ; j < psize ; j++ ) |
||
215 | s[i][j] = rnd(); |
||
216 | } |
||
217 | |||
218 | source->data = (GLfloat(*)[4])s; |
||
219 | source->start = (GLfloat *)s; |
||
220 | source->count = TEST_COUNT; |
||
221 | source->stride = sizeof(s[0]); |
||
222 | source->size = 4; |
||
223 | source->flags = 0; |
||
224 | |||
225 | dest->data = (GLfloat(*)[4])d; |
||
226 | dest->start = (GLfloat *)d; |
||
227 | dest->count = TEST_COUNT; |
||
228 | dest->stride = sizeof(float[4]); |
||
229 | dest->size = 0; |
||
230 | dest->flags = 0; |
||
231 | |||
232 | ref->data = (GLfloat(*)[4])r; |
||
233 | ref->start = (GLfloat *)r; |
||
234 | ref->count = TEST_COUNT; |
||
235 | ref->stride = sizeof(float[4]); |
||
236 | ref->size = 0; |
||
237 | ref->flags = 0; |
||
238 | |||
239 | ref_transform( ref, mat, source ); |
||
240 | |||
241 | if ( mesa_profile ) { |
||
242 | BEGIN_RACE( *cycles ); |
||
243 | func( dest, mat->m, source ); |
||
244 | END_RACE( *cycles ); |
||
245 | } |
||
246 | else { |
||
247 | func( dest, mat->m, source ); |
||
248 | } |
||
249 | |||
250 | for ( i = 0 ; i < TEST_COUNT ; i++ ) { |
||
251 | for ( j = 0 ; j < 4 ; j++ ) { |
||
252 | if ( significand_match( d[i][j], r[i][j] ) < REQUIRED_PRECISION ) { |
||
253 | _mesa_printf(NULL, "-----------------------------\n" ); |
||
254 | _mesa_printf(NULL, "(i = %i, j = %i)\n", i, j ); |
||
255 | _mesa_printf(NULL, "%f \t %f \t [diff = %e - %i bit missed]\n", |
||
256 | d[i][0], r[i][0], r[i][0]-d[i][0], |
||
257 | MAX_PRECISION - significand_match( d[i][0], r[i][0] ) ); |
||
258 | _mesa_printf(NULL, "%f \t %f \t [diff = %e - %i bit missed]\n", |
||
259 | d[i][1], r[i][1], r[i][1]-d[i][1], |
||
260 | MAX_PRECISION - significand_match( d[i][1], r[i][1] ) ); |
||
261 | _mesa_printf(NULL, "%f \t %f \t [diff = %e - %i bit missed]\n", |
||
262 | d[i][2], r[i][2], r[i][2]-d[i][2], |
||
263 | MAX_PRECISION - significand_match( d[i][2], r[i][2] ) ); |
||
264 | _mesa_printf(NULL, "%f \t %f \t [diff = %e - %i bit missed]\n", |
||
265 | d[i][3], r[i][3], r[i][3]-d[i][3], |
||
266 | MAX_PRECISION - significand_match( d[i][3], r[i][3] ) ); |
||
267 | return 0; |
||
268 | } |
||
269 | } |
||
270 | } |
||
271 | |||
272 | ALIGN_FREE( mat->m ); |
||
273 | return 1; |
||
274 | } |
||
275 | |||
276 | void _math_test_all_transform_functions( char *description ) |
||
277 | { |
||
278 | int psize, mtype; |
||
279 | long benchmark_tab[4][7]; |
||
280 | static int first_time = 1; |
||
281 | |||
282 | if ( first_time ) { |
||
283 | first_time = 0; |
||
284 | mesa_profile = getenv( "MESA_PROFILE" ); |
||
285 | } |
||
286 | |||
287 | #ifdef RUN_DEBUG_BENCHMARK |
||
288 | if ( mesa_profile ) { |
||
289 | if ( !counter_overhead ) { |
||
290 | INIT_COUNTER(); |
||
291 | _mesa_printf(NULL, "counter overhead: %ld cycles\n\n", counter_overhead ); |
||
292 | } |
||
293 | _mesa_printf(NULL, "transform results after hooking in %s functions:\n", description ); |
||
294 | } |
||
295 | #endif |
||
296 | |||
297 | #ifdef RUN_DEBUG_BENCHMARK |
||
298 | if ( mesa_profile ) { |
||
299 | _mesa_printf(NULL, "\n" ); |
||
300 | for ( psize = 1 ; psize <= 4 ; psize++ ) { |
||
301 | _mesa_printf(NULL, " p%d\t", psize ); |
||
302 | } |
||
303 | _mesa_printf(NULL, "\n--------------------------------------------------------\n" ); |
||
304 | } |
||
305 | #endif |
||
306 | |||
307 | for ( mtype = 0 ; mtype < 7 ; mtype++ ) { |
||
308 | for ( psize = 1 ; psize <= 4 ; psize++ ) { |
||
309 | transform_func func = _mesa_transform_tab[psize][mtypes[mtype]]; |
||
310 | long *cycles = &(benchmark_tab[psize-1][mtype]); |
||
311 | |||
312 | if ( test_transform_function( func, psize, mtype, cycles ) == 0 ) { |
||
313 | char buf[100]; |
||
314 | _mesa_sprintf(NULL, buf, "_mesa_transform_tab[0][%d][%s] failed test (%s)", |
||
315 | psize, mstrings[mtype], description ); |
||
316 | _mesa_problem( NULL, buf ); |
||
317 | } |
||
318 | #ifdef RUN_DEBUG_BENCHMARK |
||
319 | if ( mesa_profile ) |
||
320 | _mesa_printf(NULL, " %li\t", benchmark_tab[psize-1][mtype] ); |
||
321 | #endif |
||
322 | } |
||
323 | #ifdef RUN_DEBUG_BENCHMARK |
||
324 | if ( mesa_profile ) |
||
325 | _mesa_printf(NULL, " | [%s]\n", mstrings[mtype] ); |
||
326 | #endif |
||
327 | } |
||
328 | #ifdef RUN_DEBUG_BENCHMARK |
||
329 | if ( mesa_profile ) |
||
330 | _mesa_printf(NULL, "\n" ); |
||
331 | #endif |
||
332 | } |
||
333 | |||
334 | |||
335 | #endif /* DEBUG */ |