From c49aca943c032049e25408986fef00ef63fa3b54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Monteiro?= Date: Thu, 3 Nov 2022 18:22:05 +0000 Subject: [PATCH] math: remove vector class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: António Monteiro Reviewed-by: Marek Olšák Part-of: --- src/mesa/main/tests/disable_windows_include.c | 3 - src/mesa/math/m_matrix.c | 2 - src/mesa/math/m_matrix.h | 6 + src/mesa/math/m_vector.c | 194 ------------------ src/mesa/math/m_vector.h | 85 -------- src/mesa/math/m_vector_asm.h | 57 ----- src/mesa/math/m_xform.h | 160 --------------- src/mesa/meson.build | 2 - 8 files changed, 6 insertions(+), 503 deletions(-) delete mode 100644 src/mesa/math/m_vector.c delete mode 100644 src/mesa/math/m_vector.h delete mode 100644 src/mesa/math/m_vector_asm.h delete mode 100644 src/mesa/math/m_xform.h diff --git a/src/mesa/main/tests/disable_windows_include.c b/src/mesa/main/tests/disable_windows_include.c index 69861d00422..0e5d3bd248d 100644 --- a/src/mesa/main/tests/disable_windows_include.c +++ b/src/mesa/main/tests/disable_windows_include.c @@ -137,9 +137,6 @@ #include #include #include -#include -#include -#include #include #include #include diff --git a/src/mesa/math/m_matrix.c b/src/mesa/math/m_matrix.c index 6fb5230ad31..fadea0fe225 100644 --- a/src/mesa/math/m_matrix.c +++ b/src/mesa/math/m_matrix.c @@ -39,8 +39,6 @@ #include "main/errors.h" #include "util/glheader.h" #include "main/macros.h" -#define MATH_ASM_PTR_SIZE sizeof(void *) -#include "math/m_vector_asm.h" #include "m_matrix.h" diff --git a/src/mesa/math/m_matrix.h b/src/mesa/math/m_matrix.h index 499e982b1b2..195558bbf32 100644 --- a/src/mesa/math/m_matrix.h +++ b/src/mesa/math/m_matrix.h @@ -54,6 +54,12 @@ extern "C" { #define MAT_TZ 14 /*@}*/ +/** + * If you add a new field, please add it to the STATIC_ASSERTs in + * _math_matrix_set_identity(). + */ +#define MATRIX_M 0 +#define MATRIX_INV (MATRIX_M + 16 * 4) /** * Different kinds of 4x4 transformation matrices. diff --git a/src/mesa/math/m_vector.c b/src/mesa/math/m_vector.c deleted file mode 100644 index 360488523e3..00000000000 --- a/src/mesa/math/m_vector.c +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -/* - * New (3.1) transformation code written by Keith Whitwell. - */ - -#include -#include - -#include "util/glheader.h" -#include "main/macros.h" - -#include "m_vector.h" - -#include "util/u_memory.h" - - - -/** - * Given a vector [count][4] of floats, set all the [][elt] values - * to 0 (if elt = 0, 1, 2) or 1.0 (if elt = 3). - */ -void -_mesa_vector4f_clean_elem( GLvector4f *vec, GLuint count, GLuint elt ) -{ - static const GLubyte elem_bits[4] = { - VEC_DIRTY_0, - VEC_DIRTY_1, - VEC_DIRTY_2, - VEC_DIRTY_3 - }; - static const GLfloat clean[4] = { 0, 0, 0, 1 }; - const GLfloat v = clean[elt]; - GLfloat (*data)[4] = (GLfloat (*)[4])vec->start; - GLuint i; - - for (i = 0; i < count; i++) - data[i][elt] = v; - - vec->flags &= ~elem_bits[elt]; -} - - -static const GLubyte size_bits[5] = { - 0, - VEC_SIZE_1, - VEC_SIZE_2, - VEC_SIZE_3, - VEC_SIZE_4, -}; - - -/** - * Initialize GLvector objects. - * \param v the vector object to initialize. - * \param flags bitwise-OR of VEC_* flags - * \param storage pointer to storage for the vector's data - */ -void -_mesa_vector4f_init( GLvector4f *v, GLbitfield flags, GLfloat (*storage)[4] ) -{ - STATIC_ASSERT(V4F_DATA == offsetof(GLvector4f, data)); - STATIC_ASSERT(V4F_START == offsetof(GLvector4f, start)); - STATIC_ASSERT(V4F_COUNT == offsetof(GLvector4f, count)); - STATIC_ASSERT(V4F_STRIDE == offsetof(GLvector4f, stride)); - STATIC_ASSERT(V4F_SIZE == offsetof(GLvector4f, size)); - STATIC_ASSERT(V4F_FLAGS == offsetof(GLvector4f, flags)); - - v->stride = 4 * sizeof(GLfloat); - v->size = 2; /* may change: 2-4 for vertices and 1-4 for texcoords */ - v->data = storage; - v->start = (GLfloat *) storage; - v->count = 0; - v->flags = size_bits[4] | flags; -} - - -/** - * Initialize GLvector objects and allocate storage. - * \param v the vector object - * \param flags bitwise-OR of VEC_* flags - * \param count number of elements to allocate in vector - * \param alignment desired memory alignment for the data (in bytes) - */ -void -_mesa_vector4f_alloc( GLvector4f *v, GLbitfield flags, GLuint count, - GLuint alignment ) -{ - v->stride = 4 * sizeof(GLfloat); - v->size = 2; - v->storage = align_malloc( count * 4 * sizeof(GLfloat), alignment ); - v->storage_count = count; - v->start = (GLfloat *) v->storage; - v->data = (GLfloat (*)[4]) v->storage; - v->count = 0; - v->flags = size_bits[4] | flags | VEC_MALLOC; -} - - -/** - * Vector deallocation. Free whatever memory is pointed to by the - * vector's storage field if the VEC_MALLOC flag is set. - * DO NOT free the GLvector object itself, though. - */ -void -_mesa_vector4f_free( GLvector4f *v ) -{ - if (v->flags & VEC_MALLOC) { - align_free( v->storage ); - v->data = NULL; - v->start = NULL; - v->storage = NULL; - v->flags &= ~VEC_MALLOC; - } -} - - -/** - * For debugging - */ -void -_mesa_vector4f_print( const GLvector4f *v, const GLubyte *cullmask, - GLboolean culling ) -{ - static const GLfloat c[4] = { 0, 0, 0, 1 }; - static const char *templates[5] = { - "%d:\t0, 0, 0, 1\n", - "%d:\t%f, 0, 0, 1\n", - "%d:\t%f, %f, 0, 1\n", - "%d:\t%f, %f, %f, 1\n", - "%d:\t%f, %f, %f, %f\n" - }; - - const char *t = templates[v->size]; - GLfloat *d = (GLfloat *)v->data; - GLuint j, i = 0, count; - - printf("data-start\n"); - for (; d != v->start; STRIDE_F(d, v->stride), i++) - printf(t, i, d[0], d[1], d[2], d[3]); - - printf("start-count(%u)\n", v->count); - count = i + v->count; - - if (culling) { - for (; i < count; STRIDE_F(d, v->stride), i++) - if (cullmask[i]) - printf(t, i, d[0], d[1], d[2], d[3]); - } - else { - for (; i < count; STRIDE_F(d, v->stride), i++) - printf(t, i, d[0], d[1], d[2], d[3]); - } - - for (j = v->size; j < 4; j++) { - if ((v->flags & (1<data; - i < count && d[j] == c[j]; - i++, STRIDE_F(d, v->stride)) { - /* no-op */ - } - - if (i == count) - printf(" --> ok\n"); - else - printf(" --> Failed at %u ******\n", i); - } - } -} diff --git a/src/mesa/math/m_vector.h b/src/mesa/math/m_vector.h deleted file mode 100644 index 8a3f5044401..00000000000 --- a/src/mesa/math/m_vector.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -/* - * New (3.1) transformation code written by Keith Whitwell. - */ - - -#ifndef _M_VECTOR_H_ -#define _M_VECTOR_H_ - -#include "util/glheader.h" -#define MATH_ASM_PTR_SIZE sizeof(void *) -#include "math/m_vector_asm.h" - -#define VEC_MALLOC 0x10 /* storage field points to self-allocated mem*/ -#define VEC_NOT_WRITEABLE 0x40 /* writable elements to hold clipped data */ -#define VEC_BAD_STRIDE 0x100 /* matches tnl's prefered stride */ - - - - - -/** - * Wrap all the information about vectors up in a struct. Has - * additional fields compared to the other vectors to help us track - * different vertex sizes, and whether we need to clean columns out - * because they contain non-(0,0,0,1) values. - * - * The start field is used to reserve data for copied vertices at the - * end of _mesa_transform_vb, and avoids the need for a multiplication in - * the transformation routines. - */ -typedef struct { - GLfloat (*data)[4]; /**< may be malloc'd or point to client data */ - GLfloat *start; /**< points somewhere inside of GLvector4f::data */ - GLuint count; /**< size of the vector (in elements) */ - GLuint stride; /**< stride from one element to the next (in bytes) */ - GLuint size; /**< 2-4 for vertices and 1-4 for texcoords */ - GLbitfield flags; /**< bitmask of VEC_x flags */ - void *storage; /**< self-allocated storage */ - GLuint storage_count; /**< storage size in elements */ -} GLvector4f; - - -extern void _mesa_vector4f_init( GLvector4f *v, GLbitfield flags, - GLfloat (*storage)[4] ); -extern void _mesa_vector4f_alloc( GLvector4f *v, GLbitfield flags, - GLuint count, GLuint alignment ); -extern void _mesa_vector4f_free( GLvector4f *v ); -extern void _mesa_vector4f_print( const GLvector4f *v, const GLubyte *, GLboolean ); -extern void _mesa_vector4f_clean_elem( GLvector4f *vec, GLuint nr, GLuint elt ); - - -/** - * Given vector , return a pointer (cast to to the -th element. - * - * End up doing a lot of slow imuls if not careful. - */ -#define VEC_ELT( v, type, i ) \ - ( (type *) ( ((GLbyte *) ((v)->data)) + (i) * (v)->stride) ) - - -#endif diff --git a/src/mesa/math/m_vector_asm.h b/src/mesa/math/m_vector_asm.h deleted file mode 100644 index 90de44b0a50..00000000000 --- a/src/mesa/math/m_vector_asm.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright © 2019 Google LLC - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -#ifndef _M_VECTOR_ASM_H_ -#define _M_VECTOR_ASM_H_ - -/* This file is a set of defines usable by the old FF TNL assembly code for - * referencing GLvector4f and GLmatrix structs. - */ - -#define VEC_DIRTY_0 0x1 -#define VEC_DIRTY_1 0x2 -#define VEC_DIRTY_2 0x4 -#define VEC_DIRTY_3 0x8 - -#define VEC_SIZE_1 VEC_DIRTY_0 -#define VEC_SIZE_2 (VEC_DIRTY_0|VEC_DIRTY_1) -#define VEC_SIZE_3 (VEC_DIRTY_0|VEC_DIRTY_1|VEC_DIRTY_2) -#define VEC_SIZE_4 (VEC_DIRTY_0|VEC_DIRTY_1|VEC_DIRTY_2|VEC_DIRTY_3) - -/* If you add a new field, please add it to the STATIC_ASSERTs in - * _mesa_vector4f_init(). - */ -#define V4F_DATA 0 -#define V4F_START (V4F_DATA + MATH_ASM_PTR_SIZE) -#define V4F_COUNT (V4F_START + MATH_ASM_PTR_SIZE) -#define V4F_STRIDE (V4F_COUNT + 4) -#define V4F_SIZE (V4F_STRIDE + 4) -#define V4F_FLAGS (V4F_SIZE + 4) - -/* If you add a new field, please add it to the STATIC_ASSERTs in - * _math_matrix_set_identity(). - */ -#define MATRIX_M 0 -#define MATRIX_INV (MATRIX_M + 16 * 4) - -#endif /* _M_VECTOR_ASM_H */ diff --git a/src/mesa/math/m_xform.h b/src/mesa/math/m_xform.h deleted file mode 100644 index 7ed24f15880..00000000000 --- a/src/mesa/math/m_xform.h +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - - -#ifndef _M_XFORM_H -#define _M_XFORM_H - - -#include "util/compiler.h" -#include "util/glheader.h" -#include "math/m_matrix.h" -#include "math/m_vector.h" - - -extern void -_math_init_transformation(void); -extern void -init_c_cliptest(void); - -/* KW: Clip functions now do projective divide as well. The projected - * coordinates are very useful to us because they let us cull - * backfaces and eliminate vertices from lighting, fogging, etc - * calculations. Despite the fact that this divide could be done one - * day in hardware, we would still have a reason to want to do it here - * as long as those other calculations remain in software. - * - * Clipping is a convenient place to do the divide on x86 as it should be - * possible to overlap with integer outcode calculations. - * - * There are two cases where we wouldn't want to do the divide in cliptest: - * - When we aren't clipping. We still might want to cull backfaces - * so the divide should be done elsewhere. This currently never - * happens. - * - * - When culling isn't likely to help us, such as when the GL culling - * is disabled and we not lighting or are only lighting - * one-sided. In this situation, backface determination provides - * us with no useful information. A tricky case to detect is when - * all input data is already culled, although hopefully the - * application wouldn't turn on culling in such cases. - * - * We supply a buffer to hold the [x/w,y/w,z/w,1/w] values which - * are the result of the projection. This is only used in the - * 4-vector case - in other cases, we just use the clip coordinates - * as the projected coordinates - they are identical. - * - * This is doubly convenient because it means the Win[] array is now - * of the same stride as all the others, so I can now turn map_vertices - * into a straight-forward matrix transformation, with asm acceleration - * automatically available. - */ - -/* Vertex buffer clipping flags - */ -#define CLIP_RIGHT_SHIFT 0 -#define CLIP_LEFT_SHIFT 1 -#define CLIP_TOP_SHIFT 2 -#define CLIP_BOTTOM_SHIFT 3 -#define CLIP_NEAR_SHIFT 4 -#define CLIP_FAR_SHIFT 5 - -#define CLIP_RIGHT_BIT 0x01 -#define CLIP_LEFT_BIT 0x02 -#define CLIP_TOP_BIT 0x04 -#define CLIP_BOTTOM_BIT 0x08 -#define CLIP_NEAR_BIT 0x10 -#define CLIP_FAR_BIT 0x20 -#define CLIP_USER_BIT 0x40 -#define CLIP_CULL_BIT 0x80 -#define CLIP_FRUSTUM_BITS 0x3f - - -typedef GLvector4f * (*clip_func)(GLvector4f *vClip, - GLvector4f *vProj, - GLubyte clipMask[], - GLubyte *orMask, - GLubyte *andMask, - GLboolean viewport_z_clip); - -typedef void (*dotprod_func)( GLfloat *out, - GLuint out_stride, - const GLvector4f *coord_vec, - const GLfloat plane[4] ); - -typedef void (*vec_copy_func)( GLvector4f *to, - const GLvector4f *from ); - - - -/* - * Functions for transformation of normals in the VB. - */ -typedef void (*normal_func)(const GLmatrix *mat, - GLfloat scale, - const GLvector4f *in, - const GLfloat lengths[], - GLvector4f *dest); - - -/* Flags for selecting a normal transformation function. - */ -#define NORM_RESCALE 0x1 /* apply the scale factor */ -#define NORM_NORMALIZE 0x2 /* normalize */ -#define NORM_TRANSFORM 0x4 /* apply the transformation matrix */ -#define NORM_TRANSFORM_NO_ROT 0x8 /* apply the transformation matrix */ - - - - -/* KW: New versions of the transform function allow a mask array - * specifying that individual vector transform should be skipped - * when the mask byte is zero. This is always present as a - * parameter, to allow a unified interface. - */ -typedef void (*transform_func)(GLvector4f *to_vec, - const GLfloat m[16], - const GLvector4f *from_vec); - - -extern dotprod_func _mesa_dotprod_tab[5]; -extern vec_copy_func _mesa_copy_tab[0x10]; -extern vec_copy_func _mesa_copy_clean_tab[5]; -extern clip_func _mesa_clip_tab[5]; -extern clip_func _mesa_clip_np_tab[5]; -extern normal_func _mesa_normal_tab[0xf]; - -/* Use of 2 layers of linked 1-dimensional arrays to reduce - * cost of lookup. - */ -extern transform_func *_mesa_transform_tab[5]; - - - -#define TransformRaw( to, mat, from ) \ - ( _mesa_transform_tab[(from)->size][(mat)->type]( to, (mat)->m, from ), \ - (to) ) - - -#endif diff --git a/src/mesa/meson.build b/src/mesa/meson.build index 057a709846c..6bb41f47f90 100644 --- a/src/mesa/meson.build +++ b/src/mesa/meson.build @@ -258,8 +258,6 @@ files_libmesa = files( 'math/m_eval.h', 'math/m_matrix.c', 'math/m_matrix.h', - 'math/m_vector.c', - 'math/m_vector.h', 'program/arbprogparse.c', 'program/arbprogparse.h', 'program/link_program.cpp',