m_debug_clip.c revision e7e38a47a8dd567fd5a848cbef09b14018fb2fe0
1e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/* $Id: m_debug_clip.c,v 1.1 2001/05/21 16:33:41 gareth Exp $ */ 2e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 3e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/* 4e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * Mesa 3-D graphics library 5e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * Version: 3.5 6e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * 7e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. 8e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * 9e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * Permission is hereby granted, free of charge, to any person obtaining a 10e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * copy of this software and associated documentation files (the "Software"), 11e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * to deal in the Software without restriction, including without limitation 12e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * the rights to use, copy, modify, merge, publish, distribute, sublicense, 13e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * and/or sell copies of the Software, and to permit persons to whom the 14e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * Software is furnished to do so, subject to the following conditions: 15e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * 16e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * The above copyright notice and this permission notice shall be included 17e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * in all copies or substantial portions of the Software. 18e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * 19e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 22e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 23e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 24e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * 26e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * Authors: 27e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * Gareth Hughes <gareth@valinux.com> 28e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes */ 29e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 30e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#include "glheader.h" 31e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#include "context.h" 32e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#include "macros.h" 33e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#include "mem.h" 34e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 35e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#include "m_matrix.h" 36e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#include "m_xform.h" 37e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 38e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#include "m_debug.h" 39e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#include "m_debug_util.h" 40e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 41e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#ifdef DEBUG /* This code only used for debugging */ 42e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 43e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughesstatic clip_func *clip_tab[2] = { 44e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes _mesa_clip_tab, 45e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes _mesa_clip_np_tab 46e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes}; 47e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughesstatic char *cnames[2] = { 48e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes "_mesa_clip_tab", 49e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes "_mesa_clip_np_tab" 50e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes}; 51e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughesstatic char *cstrings[2] = { 52e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes "clip, perspective divide", 53e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes "clip, no divide" 54e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes}; 55e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 56e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 57e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/* ============================================================= 58e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * Reference cliptests 59e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes */ 60e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 61e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughesstatic GLvector4f *ref_cliptest_points4( GLvector4f *clip_vec, 62e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLvector4f *proj_vec, 63e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLubyte clipMask[], 64e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLubyte *orMask, 65e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLubyte *andMask ) 66e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes{ 67e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const GLuint stride = clip_vec->stride; 68e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const GLuint count = clip_vec->count; 69e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const GLfloat *from = (GLfloat *)clip_vec->start; 70e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLuint c = 0; 71e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLfloat (*vProj)[4] = (GLfloat (*)[4])proj_vec->start; 72e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLubyte tmpAndMask = *andMask; 73e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLubyte tmpOrMask = *orMask; 74e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLuint i; 75e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes for ( i = 0 ; i < count ; i++, STRIDE_F(from, stride) ) { 76e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const GLfloat cx = from[0]; 77e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const GLfloat cy = from[1]; 78e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const GLfloat cz = from[2]; 79e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const GLfloat cw = from[3]; 80e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLubyte mask = 0; 81e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( -cx + cw < 0 ) mask |= CLIP_RIGHT_BIT; 82e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( cx + cw < 0 ) mask |= CLIP_LEFT_BIT; 83e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( -cy + cw < 0 ) mask |= CLIP_TOP_BIT; 84e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( cy + cw < 0 ) mask |= CLIP_BOTTOM_BIT; 85e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( -cz + cw < 0 ) mask |= CLIP_FAR_BIT; 86e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( cz + cw < 0 ) mask |= CLIP_NEAR_BIT; 87e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes clipMask[i] = mask; 88e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( mask ) { 89e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes c++; 90e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes tmpAndMask &= mask; 91e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes tmpOrMask |= mask; 92e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes vProj[i][0] = 0; 93e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes vProj[i][1] = 0; 94e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes vProj[i][2] = 0; 95e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes vProj[i][3] = 1; 96e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } else { 97e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLfloat oow = 1.0F / cw; 98e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes vProj[i][0] = cx * oow; 99e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes vProj[i][1] = cy * oow; 100e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes vProj[i][2] = cz * oow; 101e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes vProj[i][3] = oow; 102e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 103e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 104e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 105e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes *orMask = tmpOrMask; 106e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes *andMask = (GLubyte) (c < count ? 0 : tmpAndMask); 107e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 108e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes proj_vec->flags |= VEC_SIZE_4; 109e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes proj_vec->size = 4; 110e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes proj_vec->count = clip_vec->count; 111e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return proj_vec; 112e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes} 113e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 114e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/* Keep these here for now, even though we don't use them... 115e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes */ 116e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughesstatic GLvector4f *ref_cliptest_points3( GLvector4f *clip_vec, 117e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLvector4f *proj_vec, 118e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLubyte clipMask[], 119e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLubyte *orMask, 120e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLubyte *andMask ) 121e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes{ 122e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const GLuint stride = clip_vec->stride; 123e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const GLuint count = clip_vec->count; 124e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const GLfloat *from = (GLfloat *)clip_vec->start; 125e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 126e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLubyte tmpOrMask = *orMask; 127e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLubyte tmpAndMask = *andMask; 128e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLuint i; 129e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes for ( i = 0 ; i < count ; i++, STRIDE_F(from, stride) ) { 130e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const GLfloat cx = from[0], cy = from[1], cz = from[2]; 131e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLubyte mask = 0; 132e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( cx > 1.0 ) mask |= CLIP_RIGHT_BIT; 133e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes else if ( cx < -1.0 ) mask |= CLIP_LEFT_BIT; 134e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( cy > 1.0 ) mask |= CLIP_TOP_BIT; 135e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes else if ( cy < -1.0 ) mask |= CLIP_BOTTOM_BIT; 136e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( cz > 1.0 ) mask |= CLIP_FAR_BIT; 137e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes else if ( cz < -1.0 ) mask |= CLIP_NEAR_BIT; 138e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes clipMask[i] = mask; 139e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes tmpOrMask |= mask; 140e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes tmpAndMask &= mask; 141e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 142e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 143e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes *orMask = tmpOrMask; 144e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes *andMask = tmpAndMask; 145e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return clip_vec; 146e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes} 147e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 148e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughesstatic GLvector4f * ref_cliptest_points2( GLvector4f *clip_vec, 149e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLvector4f *proj_vec, 150e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLubyte clipMask[], 151e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLubyte *orMask, 152e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLubyte *andMask ) 153e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes{ 154e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const GLuint stride = clip_vec->stride; 155e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const GLuint count = clip_vec->count; 156e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const GLfloat *from = (GLfloat *)clip_vec->start; 157e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 158e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLubyte tmpOrMask = *orMask; 159e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLubyte tmpAndMask = *andMask; 160e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLuint i; 161e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes for ( i = 0 ; i < count ; i++, STRIDE_F(from, stride) ) { 162e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const GLfloat cx = from[0], cy = from[1]; 163e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLubyte mask = 0; 164e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( cx > 1.0 ) mask |= CLIP_RIGHT_BIT; 165e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes else if ( cx < -1.0 ) mask |= CLIP_LEFT_BIT; 166e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( cy > 1.0 ) mask |= CLIP_TOP_BIT; 167e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes else if ( cy < -1.0 ) mask |= CLIP_BOTTOM_BIT; 168e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes clipMask[i] = mask; 169e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes tmpOrMask |= mask; 170e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes tmpAndMask &= mask; 171e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 172e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 173e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes *orMask = tmpOrMask; 174e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes *andMask = tmpAndMask; 175e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return clip_vec; 176e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes} 177e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 178e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughesstatic clip_func ref_cliptest[5] = { 179e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 0, 180e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 0, 181e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes ref_cliptest_points2, 182e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes ref_cliptest_points3, 183e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes ref_cliptest_points4 184e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes}; 185e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 186e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 187e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/* ============================================================= 188e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * Cliptest tests 189e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes */ 190e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 191e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughesstatic GLfloat s[TEST_COUNT][4] ALIGN16; 192e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughesstatic GLfloat d[TEST_COUNT][4] ALIGN16; 193e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughesstatic GLfloat r[TEST_COUNT][4] ALIGN16; 194e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 195e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughesstatic int test_cliptest_function( clip_func func, int np, 196e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes int psize, long *cycles ) 197e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes{ 198e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLvector4f source[1], dest[1], ref[1]; 199e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLubyte dm[TEST_COUNT], dco, dca; 200e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes GLubyte rm[TEST_COUNT], rco, rca; 201e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes int i, j; 202e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#ifdef RUN_DEBUG_BENCHMARK 203e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes int cycle_i; /* the counter for the benchmarks we run */ 204e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#endif 205e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 206e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes (void) cycles; 207e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 208e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( psize > 4 ) { 209e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes _mesa_problem( NULL, "test_cliptest_function called with psize > 4\n" ); 210e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return 0; 211e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 212e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 213e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes for ( i = 0 ; i < TEST_COUNT ; i++) { 214e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes ASSIGN_4V( d[i], 0.0, 0.0, 0.0, 1.0 ); 215e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes ASSIGN_4V( s[i], 0.0, 0.0, 0.0, 1.0 ); 216e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes for ( j = 0 ; j < psize ; j++ ) 217e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes s[i][j] = rnd(); 218e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 219e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 220e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes source->data = (GLfloat(*)[4])s; 221e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes source->start = (GLfloat *)s; 222e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes source->count = TEST_COUNT; 223e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes source->stride = sizeof(s[0]); 224e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes source->size = 4; 225e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes source->flags = 0; 226e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 227e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes dest->data = (GLfloat(*)[4])d; 228e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes dest->start = (GLfloat *)d; 229e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes dest->count = TEST_COUNT; 230e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes dest->stride = sizeof(float[4]); 231e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes dest->size = 0; 232e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes dest->flags = 0; 233e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 234e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes ref->data = (GLfloat(*)[4])r; 235e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes ref->start = (GLfloat *)r; 236e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes ref->count = TEST_COUNT; 237e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes ref->stride = sizeof(float[4]); 238e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes ref->size = 0; 239e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes ref->flags = 0; 240e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 241e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes dco = rco = 0; 242e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes dca = rca = CLIP_ALL_BITS; 243e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 244e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes ref_cliptest[psize]( source, ref, rm, &rco, &rca ); 245e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 246e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( mesa_profile ) { 247e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes BEGIN_RACE( *cycles ); 248e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes func( source, dest, dm, &dco, &dca ); 249e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes END_RACE( *cycles ); 250e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 251e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes else { 252e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes func( source, dest, dm, &dco, &dca ); 253e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 254e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 255e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( dco != rco ) { 256e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( "\n-----------------------------\n" ); 257e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( "dco = 0x%02x rco = 0x%02x\n", dco, rco ); 258e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return 0; 259e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 260e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( dca != rca ) { 261e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( "\n-----------------------------\n" ); 262e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( "dca = 0x%02x rca = 0x%02x\n", dca, rca ); 263e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return 0; 264e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 265e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes for ( i = 0 ; i < TEST_COUNT ; i++ ) { 266e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( dm[i] != rm[i] ) { 267e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( "\n-----------------------------\n" ); 268e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( "(i = %i)\n", i ); 269e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( "dm = 0x%02x rm = 0x%02x\n", dm[i], rm[i] ); 270e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return 0; 271e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 272e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 273e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 274e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /* Only verify output on projected points4 case. FIXME: Do we need 275e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes * to test other cases? 276e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes */ 277e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( np || psize < 4 ) 278e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return 1; 279e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 280e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes for ( i = 0 ; i < TEST_COUNT ; i++ ) { 281e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes for ( j = 0 ; j < 4 ; j++ ) { 282e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( significand_match( d[i][j], r[i][j] ) < REQUIRED_PRECISION ) { 283e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( "\n-----------------------------\n" ); 284e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( "(i = %i, j = %i) dm = 0x%02x rm = 0x%02x\n", 285e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes i, j, dm[i], rm[i] ); 286e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( "%f \t %f \t [diff = %e - %i bit missed]\n", 287e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes d[i][0], r[i][0], r[i][0]-d[i][0], 288e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes MAX_PRECISION - significand_match( d[i][0], r[i][0] ) ); 289e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( "%f \t %f \t [diff = %e - %i bit missed]\n", 290e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes d[i][1], r[i][1], r[i][1]-d[i][1], 291e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes MAX_PRECISION - significand_match( d[i][1], r[i][1] ) ); 292e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( "%f \t %f \t [diff = %e - %i bit missed]\n", 293e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes d[i][2], r[i][2], r[i][2]-d[i][2], 294e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes MAX_PRECISION - significand_match( d[i][2], r[i][2] ) ); 295e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( "%f \t %f \t [diff = %e - %i bit missed]\n", 296e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes d[i][3], r[i][3], r[i][3]-d[i][3], 297e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes MAX_PRECISION - significand_match( d[i][3], r[i][3] ) ); 298e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return 0; 299e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 300e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 301e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 302e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 303e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return 1; 304e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes} 305e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 306e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughesvoid _math_test_all_cliptest_functions( char *description ) 307e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes{ 308e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes int np, psize; 309e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes long benchmark_tab[2][4]; 310e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static int first_time = 1; 311e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 312e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( first_time ) { 313e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes first_time = 0; 314e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes mesa_profile = getenv( "MESA_PROFILE" ); 315e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 316e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 317e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#ifdef RUN_DEBUG_BENCHMARK 318e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( mesa_profile ) { 319e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( !counter_overhead ) { 320e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes INIT_COUNTER(); 321e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( "counter overhead: %ld cycles\n\n", counter_overhead ); 322e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 323e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( "cliptest results after hooking in %s functions:\n", description ); 324e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 325e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#endif 326e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 327e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#ifdef RUN_DEBUG_BENCHMARK 328e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( mesa_profile ) { 329e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( "\n\t" ); 330e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes for ( psize = 2 ; psize <= 4 ; psize++ ) { 331e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( " p%d\t", psize ); 332e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 333e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( "\n--------------------------------------------------------\n\t" ); 334e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 335e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#endif 336e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 337e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes for ( np = 0 ; np < 2 ; np++ ) { 338e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes for ( psize = 2 ; psize <= 4 ; psize++ ) { 339e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes clip_func func = clip_tab[np][psize]; 340e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes long *cycles = &(benchmark_tab[np][psize-1]); 341e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 342e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( test_cliptest_function( func, np, psize, cycles ) == 0 ) { 343e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes char buf[100]; 344e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes sprintf( buf, "%s[%d] failed test (%s)", 345e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes cnames[np], psize, description ); 346e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes _mesa_problem( NULL, buf ); 347e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 348e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#ifdef RUN_DEBUG_BENCHMARK 349e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( mesa_profile ) 350e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( " %li\t", benchmark_tab[np][psize-1] ); 351e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#endif 352e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 353e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#ifdef RUN_DEBUG_BENCHMARK 354e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( mesa_profile ) 355e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( " | [%s]\n\t", cstrings[np] ); 356e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#endif 357e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 358e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#ifdef RUN_DEBUG_BENCHMARK 359e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes if ( mesa_profile ) 360e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes printf( "\n" ); 361e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#endif 362e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes} 363e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 364e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 365e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#endif /* DEBUG */ 366