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.
26
* Gareth Hughes <gareth@valinux.com>
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
static char *cstrings[2] = {
51
"clip, perspective divide",
56
/* =============================================================
60
static GLvector4f *ref_cliptest_points4( GLvector4f *clip_vec,
66
const GLuint stride = clip_vec->stride;
67
const GLuint count = clip_vec->count;
68
const GLfloat *from = (GLfloat *)clip_vec->start;
70
GLfloat (*vProj)[4] = (GLfloat (*)[4])proj_vec->start;
71
GLubyte tmpAndMask = *andMask;
72
GLubyte tmpOrMask = *orMask;
74
for ( i = 0 ; i < count ; i++, STRIDE_F(from, stride) ) {
75
const GLfloat cx = from[0];
76
const GLfloat cy = from[1];
77
const GLfloat cz = from[2];
78
const GLfloat cw = from[3];
80
if ( -cx + cw < 0 ) mask |= CLIP_RIGHT_BIT;
81
if ( cx + cw < 0 ) mask |= CLIP_LEFT_BIT;
82
if ( -cy + cw < 0 ) mask |= CLIP_TOP_BIT;
83
if ( cy + cw < 0 ) mask |= CLIP_BOTTOM_BIT;
84
if ( -cz + cw < 0 ) mask |= CLIP_FAR_BIT;
85
if ( cz + cw < 0 ) mask |= CLIP_NEAR_BIT;
96
GLfloat oow = 1.0F / cw;
97
vProj[i][0] = cx * oow;
98
vProj[i][1] = cy * oow;
99
vProj[i][2] = cz * oow;
105
*andMask = (GLubyte) (c < count ? 0 : tmpAndMask);
107
proj_vec->flags |= VEC_SIZE_4;
109
proj_vec->count = clip_vec->count;
113
/* Keep these here for now, even though we don't use them...
115
static GLvector4f *ref_cliptest_points3( GLvector4f *clip_vec,
116
GLvector4f *proj_vec,
121
const GLuint stride = clip_vec->stride;
122
const GLuint count = clip_vec->count;
123
const GLfloat *from = (GLfloat *)clip_vec->start;
125
GLubyte tmpOrMask = *orMask;
126
GLubyte tmpAndMask = *andMask;
128
for ( i = 0 ; i < count ; i++, STRIDE_F(from, stride) ) {
129
const GLfloat cx = from[0], cy = from[1], cz = from[2];
131
if ( cx > 1.0 ) mask |= CLIP_RIGHT_BIT;
132
else if ( cx < -1.0 ) mask |= CLIP_LEFT_BIT;
133
if ( cy > 1.0 ) mask |= CLIP_TOP_BIT;
134
else if ( cy < -1.0 ) mask |= CLIP_BOTTOM_BIT;
135
if ( cz > 1.0 ) mask |= CLIP_FAR_BIT;
136
else if ( cz < -1.0 ) mask |= CLIP_NEAR_BIT;
143
*andMask = tmpAndMask;
147
static GLvector4f * ref_cliptest_points2( GLvector4f *clip_vec,
148
GLvector4f *proj_vec,
153
const GLuint stride = clip_vec->stride;
154
const GLuint count = clip_vec->count;
155
const GLfloat *from = (GLfloat *)clip_vec->start;
157
GLubyte tmpOrMask = *orMask;
158
GLubyte tmpAndMask = *andMask;
160
for ( i = 0 ; i < count ; i++, STRIDE_F(from, stride) ) {
161
const GLfloat cx = from[0], cy = from[1];
163
if ( cx > 1.0 ) mask |= CLIP_RIGHT_BIT;
164
else if ( cx < -1.0 ) mask |= CLIP_LEFT_BIT;
165
if ( cy > 1.0 ) mask |= CLIP_TOP_BIT;
166
else if ( cy < -1.0 ) mask |= CLIP_BOTTOM_BIT;
173
*andMask = tmpAndMask;
177
static clip_func ref_cliptest[5] = {
180
ref_cliptest_points2,
181
ref_cliptest_points3,
186
/* =============================================================
190
static GLfloat s[TEST_COUNT][4] ALIGN16;
191
static GLfloat d[TEST_COUNT][4] ALIGN16;
192
static GLfloat r[TEST_COUNT][4] ALIGN16;
194
static int test_cliptest_function( clip_func func, int np,
195
int psize, long *cycles )
197
GLvector4f source[1], dest[1], ref[1];
198
GLubyte dm[TEST_COUNT], dco, dca;
199
GLubyte rm[TEST_COUNT], rco, rca;
201
#ifdef RUN_DEBUG_BENCHMARK
202
int cycle_i; /* the counter for the benchmarks we run */
208
_mesa_problem( NULL, "test_cliptest_function called with psize > 4\n" );
212
for ( i = 0 ; i < TEST_COUNT ; i++) {
213
ASSIGN_4V( d[i], 0.0, 0.0, 0.0, 1.0 );
214
ASSIGN_4V( s[i], 0.0, 0.0, 0.0, 1.0 );
215
for ( j = 0 ; j < psize ; j++ )
219
source->data = (GLfloat(*)[4])s;
220
source->start = (GLfloat *)s;
221
source->count = TEST_COUNT;
222
source->stride = sizeof(s[0]);
226
dest->data = (GLfloat(*)[4])d;
227
dest->start = (GLfloat *)d;
228
dest->count = TEST_COUNT;
229
dest->stride = sizeof(float[4]);
233
ref->data = (GLfloat(*)[4])r;
234
ref->start = (GLfloat *)r;
235
ref->count = TEST_COUNT;
236
ref->stride = sizeof(float[4]);
241
dca = rca = CLIP_ALL_BITS;
243
ref_cliptest[psize]( source, ref, rm, &rco, &rca );
245
if ( mesa_profile ) {
246
BEGIN_RACE( *cycles );
247
func( source, dest, dm, &dco, &dca );
251
func( source, dest, dm, &dco, &dca );
255
printf( "\n-----------------------------\n" );
256
printf( "dco = 0x%02x rco = 0x%02x\n", dco, rco );
260
printf( "\n-----------------------------\n" );
261
printf( "dca = 0x%02x rca = 0x%02x\n", dca, rca );
264
for ( i = 0 ; i < TEST_COUNT ; i++ ) {
265
if ( dm[i] != rm[i] ) {
266
printf( "\n-----------------------------\n" );
267
printf( "(i = %i)\n", i );
268
printf( "dm = 0x%02x rm = 0x%02x\n", dm[i], rm[i] );
273
/* Only verify output on projected points4 case. FIXME: Do we need
274
* to test other cases?
276
if ( np || psize < 4 )
279
for ( i = 0 ; i < TEST_COUNT ; i++ ) {
280
for ( j = 0 ; j < 4 ; j++ ) {
281
if ( significand_match( d[i][j], r[i][j] ) < REQUIRED_PRECISION ) {
282
printf( "\n-----------------------------\n" );
283
printf( "(i = %i, j = %i) dm = 0x%02x rm = 0x%02x\n",
284
i, j, dm[i], rm[i] );
285
printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
286
d[i][0], r[i][0], r[i][0]-d[i][0],
287
MAX_PRECISION - significand_match( d[i][0], r[i][0] ) );
288
printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
289
d[i][1], r[i][1], r[i][1]-d[i][1],
290
MAX_PRECISION - significand_match( d[i][1], r[i][1] ) );
291
printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
292
d[i][2], r[i][2], r[i][2]-d[i][2],
293
MAX_PRECISION - significand_match( d[i][2], r[i][2] ) );
294
printf( "%f \t %f \t [diff = %e - %i bit missed]\n",
295
d[i][3], r[i][3], r[i][3]-d[i][3],
296
MAX_PRECISION - significand_match( d[i][3], r[i][3] ) );
305
void _math_test_all_cliptest_functions( char *description )
308
long benchmark_tab[2][4];
309
static int first_time = 1;
313
mesa_profile = getenv( "MESA_PROFILE" );
316
#ifdef RUN_DEBUG_BENCHMARK
317
if ( mesa_profile ) {
318
if ( !counter_overhead ) {
320
printf( "counter overhead: %ld cycles\n\n", counter_overhead );
322
printf( "cliptest results after hooking in %s functions:\n", description );
326
#ifdef RUN_DEBUG_BENCHMARK
327
if ( mesa_profile ) {
329
for ( psize = 2 ; psize <= 4 ; psize++ ) {
330
printf( " p%d\t", psize );
332
printf( "\n--------------------------------------------------------\n\t" );
336
for ( np = 0 ; np < 2 ; np++ ) {
337
for ( psize = 2 ; psize <= 4 ; psize++ ) {
338
clip_func func = clip_tab[np][psize];
339
long *cycles = &(benchmark_tab[np][psize-1]);
341
if ( test_cliptest_function( func, np, psize, cycles ) == 0 ) {
343
sprintf( buf, "%s[%d] failed test (%s)",
344
cnames[np], psize, description );
345
_mesa_problem( NULL, buf );
347
#ifdef RUN_DEBUG_BENCHMARK
349
printf( " %li\t", benchmark_tab[np][psize-1] );
352
#ifdef RUN_DEBUG_BENCHMARK
354
printf( " | [%s]\n\t", cstrings[np] );
357
#ifdef RUN_DEBUG_BENCHMARK