mesa: Replace gen_matypes with a simple header for V4F/mat layout.

We can greatly simplify our builds by just hardcoding GLvector4f and
GLmatrix's layouts.

Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
This commit is contained in:
Eric Anholt
2019-06-20 10:18:41 -07:00
parent 1738b38ce8
commit 52a39a332f
26 changed files with 101 additions and 270 deletions

View File

@@ -47,13 +47,6 @@ LOCAL_SRC_FILES := $(filter-out $(sources), $(LOCAL_SRC_FILES))
LOCAL_C_INCLUDES += $(intermediates)/main LOCAL_C_INCLUDES += $(intermediates)/main
ifeq ($(strip $(MESA_ENABLE_ASM)),true)
ifeq ($(TARGET_ARCH),x86)
sources += x86/matypes.h
LOCAL_C_INCLUDES += $(intermediates)/x86
endif
endif
sources := $(addprefix $(intermediates)/, $(sources)) sources := $(addprefix $(intermediates)/, $(sources))
LOCAL_GENERATED_SOURCES += $(sources) LOCAL_GENERATED_SOURCES += $(sources)
@@ -70,16 +63,6 @@ define es-gen
$(hide) $(PRIVATE_SCRIPT) $(1) $(PRIVATE_XML) > $@ $(hide) $(PRIVATE_SCRIPT) $(1) $(PRIVATE_XML) > $@
endef endef
matypes_deps := \
$(BUILD_OUT_EXECUTABLES)/mesa_gen_matypes$(BUILD_EXECUTABLE_SUFFIX) \
$(LOCAL_PATH)/main/mtypes.h \
$(LOCAL_PATH)/tnl/t_context.h
$(intermediates)/x86/matypes.h: $(matypes_deps)
@mkdir -p $(dir $@)
@echo "MATYPES: $(PRIVATE_MODULE) <= $(notdir $@)"
$(hide) $< > $@
$(intermediates)/main/dispatch.h: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(glapi)/gl_table.py $(intermediates)/main/dispatch.h: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(glapi)/gl_table.py
$(intermediates)/main/dispatch.h: PRIVATE_XML := -f $(glapi)/gl_and_es_API.xml $(intermediates)/main/dispatch.h: PRIVATE_XML := -f $(glapi)/gl_and_es_API.xml

View File

@@ -1,47 +0,0 @@
# Copyright 2012 Intel Corporation
# Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com>
# Copyright (C) 2010-2011 LunarG Inc.
#
# 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.
# ---------------------------------------------------------------------
# host executable: mesa_gen_matypes
# ---------------------------------------------------------------------
ifeq ($(strip $(MESA_ENABLE_ASM)),true)
ifeq ($(TARGET_ARCH),x86)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := mesa_gen_matypes
LOCAL_IS_HOST_MODULE := true
LOCAL_C_INCLUDES := \
$(MESA_TOP)/src/mapi
LOCAL_SRC_FILES := \
x86/gen_matypes.c
include $(MESA_COMMON_MK)
include $(BUILD_HOST_EXECUTABLE)
endif # x86
endif # MESA_ENABLE_ASM

View File

@@ -20,7 +20,6 @@
LOCAL_PATH := $(call my-dir) LOCAL_PATH := $(call my-dir)
include $(LOCAL_PATH)/Android.mesa_gen_matypes.mk
include $(LOCAL_PATH)/Android.libmesa_glsl_utils.mk include $(LOCAL_PATH)/Android.libmesa_glsl_utils.mk
include $(LOCAL_PATH)/Android.libmesa_dricore.mk include $(LOCAL_PATH)/Android.libmesa_dricore.mk
include $(LOCAL_PATH)/Android.libmesa_st_mesa.mk include $(LOCAL_PATH)/Android.libmesa_st_mesa.mk

View File

@@ -103,23 +103,6 @@ if env['platform'] not in ('cygwin', 'darwin', 'windows', 'haiku'):
else: else:
pass pass
# Generate matypes.h
if env['machine'] in ('x86', 'x86_64'):
# See http://www.scons.org/wiki/UsingCodeGenerators
gen_matypes = env.Program(
target = 'gen_matypes',
source = 'x86/gen_matypes.c',
)
matypes = env.Command(
'matypes.h',
gen_matypes,
gen_matypes[0].abspath + ' > $TARGET',
)
# Add the dir containing the generated header (somewhere inside the
# build dir) to the include path
env.Prepend(CPPPATH = [matypes[0].dir])
# The marshal_generated.c file is generated from the GL/ES API.xml file # The marshal_generated.c file is generated from the GL/ES API.xml file
env.CodeGenerate( env.CodeGenerate(
target = 'main/marshal_generated.c', target = 'main/marshal_generated.c',

View File

@@ -39,6 +39,8 @@
#include "main/glheader.h" #include "main/glheader.h"
#include "main/imports.h" #include "main/imports.h"
#include "main/macros.h" #include "main/macros.h"
#define MATH_ASM_PTR_SIZE sizeof(void *)
#include "math/m_vector_asm.h"
#include "m_matrix.h" #include "m_matrix.h"
@@ -1137,6 +1139,9 @@ _math_matrix_viewport(GLmatrix *m, const float scale[3],
void void
_math_matrix_set_identity( GLmatrix *mat ) _math_matrix_set_identity( GLmatrix *mat )
{ {
STATIC_ASSERT(MATRIX_M == offsetof(GLmatrix, m));
STATIC_ASSERT(MATRIX_INV == offsetof(GLmatrix, inv));
memcpy( mat->m, Identity, sizeof(Identity) ); memcpy( mat->m, Identity, sizeof(Identity) );
memcpy( mat->inv, Identity, sizeof(Identity) ); memcpy( mat->inv, Identity, sizeof(Identity) );

View File

@@ -79,6 +79,13 @@ static const GLubyte size_bits[5] = {
void void
_mesa_vector4f_init( GLvector4f *v, GLbitfield flags, GLfloat (*storage)[4] ) _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->stride = 4 * sizeof(GLfloat);
v->size = 2; /* may change: 2-4 for vertices and 1-4 for texcoords */ v->size = 2; /* may change: 2-4 for vertices and 1-4 for texcoords */
v->data = storage; v->data = storage;

View File

@@ -31,21 +31,14 @@
#define _M_VECTOR_H_ #define _M_VECTOR_H_
#include "main/glheader.h" #include "main/glheader.h"
#define MATH_ASM_PTR_SIZE sizeof(void *)
#include "math/m_vector_asm.h"
#define VEC_DIRTY_0 0x1
#define VEC_DIRTY_1 0x2
#define VEC_DIRTY_2 0x4
#define VEC_DIRTY_3 0x8
#define VEC_MALLOC 0x10 /* storage field points to self-allocated mem*/ #define VEC_MALLOC 0x10 /* storage field points to self-allocated mem*/
#define VEC_NOT_WRITEABLE 0x40 /* writable elements to hold clipped data */ #define VEC_NOT_WRITEABLE 0x40 /* writable elements to hold clipped data */
#define VEC_BAD_STRIDE 0x100 /* matches tnl's prefered stride */ #define VEC_BAD_STRIDE 0x100 /* matches tnl's prefered stride */
#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)

View File

@@ -0,0 +1,57 @@
/*
* 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 + MATH_ASM_PTR_SIZE)
#endif /* _M_VECTOR_ASM_H */

View File

@@ -605,22 +605,6 @@ files_libmesa_gallium = files(
'state_tracker/st_vdpau.h', 'state_tracker/st_vdpau.h',
) )
matypes_h = []
if with_asm_arch == 'x86' or with_asm_arch == 'x86_64'
gen_matypes = executable(
'gen_matypes',
'x86/gen_matypes.c',
c_args : [c_vis_args, c_msvc_compat_args],
include_directories : inc_common,
)
matypes_h = custom_target(
'matypes.h',
output : 'matypes.h',
command : [gen_matypes],
capture : true,
)
endif
inc_libmesa_asm = [] inc_libmesa_asm = []
if with_asm_arch == 'x86' if with_asm_arch == 'x86'
files_libmesa_common += files( files_libmesa_common += files(
@@ -707,7 +691,6 @@ files_libmesa_common += [
main_dispatch_h, main_dispatch_h,
ir_expression_operation_h, ir_expression_operation_h,
main_remap_helper_h, main_remap_helper_h,
matypes_h,
sha1_h, sha1_h,
] ]

View File

@@ -24,7 +24,8 @@
#ifdef USE_X86_64_ASM #ifdef USE_X86_64_ASM
#include "matypes.h" #define MATH_ASM_PTR_SIZE 8
#include "math/m_vector_asm.h"
.text .text

View File

@@ -25,7 +25,8 @@
#ifdef USE_3DNOW_ASM #ifdef USE_3DNOW_ASM
#include "assyntax.h" #include "assyntax.h"
#include "matypes.h" #define MATH_ASM_PTR_SIZE 4
#include "math/m_vector_asm.h"
#include "xform_args.h" #include "xform_args.h"
SEG_TEXT SEG_TEXT

View File

@@ -25,7 +25,8 @@
#ifdef USE_3DNOW_ASM #ifdef USE_3DNOW_ASM
#include "assyntax.h" #include "assyntax.h"
#include "matypes.h" #define MATH_ASM_PTR_SIZE 4
#include "math/m_vector_asm.h"
#include "xform_args.h" #include "xform_args.h"
SEG_TEXT SEG_TEXT

View File

@@ -25,7 +25,8 @@
#ifdef USE_3DNOW_ASM #ifdef USE_3DNOW_ASM
#include "assyntax.h" #include "assyntax.h"
#include "matypes.h" #define MATH_ASM_PTR_SIZE 4
#include "math/m_vector_asm.h"
#include "xform_args.h" #include "xform_args.h"
SEG_TEXT SEG_TEXT

View File

@@ -25,7 +25,8 @@
#ifdef USE_3DNOW_ASM #ifdef USE_3DNOW_ASM
#include "assyntax.h" #include "assyntax.h"
#include "matypes.h" #define MATH_ASM_PTR_SIZE 4
#include "math/m_vector_asm.h"
#include "xform_args.h" #include "xform_args.h"
SEG_TEXT SEG_TEXT

View File

@@ -39,7 +39,6 @@
* in there will break the build on some platforms. * in there will break the build on some platforms.
*/ */
#include "matypes.h"
#include "assyntax.h" #include "assyntax.h"
#include "common_x86_features.h" #include "common_x86_features.h"

View File

@@ -1,146 +0,0 @@
/*
* Mesa 3-D graphics library
*
* Copyright (C) 1999-2006 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.
*
* Authors:
* Gareth Hughes
*/
/*
* This generates an asm version of mtypes.h (called matypes.h), so that
* Mesa's x86 assembly code can access the internal structures easily.
* This will be particularly useful when developing new x86 asm code for
* Mesa, including lighting, clipping, texture image conversion etc.
*/
#include <stdio.h>
#include <inttypes.h>
#include "main/glheader.h"
#include "main/mtypes.h"
#include "tnl/t_context.h"
#undef offsetof
#define offsetof( type, member ) ((size_t) &((type *)0)->member)
#define OFFSET_HEADER( x ) \
do { \
printf( "\n" ); \
printf( "\n" ); \
printf( "/* =====================================================" \
"========\n" ); \
printf( " * Offsets for " x "\n" ); \
printf( " */\n" ); \
printf( "\n" ); \
} while (0)
#define DEFINE_HEADER( x ) \
do { \
printf( "\n" ); \
printf( "/*\n" ); \
printf( " * Flags for " x "\n" ); \
printf( " */\n" ); \
printf( "\n" ); \
} while (0)
#ifdef ASM_OFFSETS
/*
* Format the asm output in a special way that we can manipulate
* after the fact and turn into the final header for the target.
*/
#define DEFINE_UL( s, ul ) \
__asm__ __volatile__ ( "\n->" s " %0" : : "i" (ul) )
#define DEFINE( s, d ) \
DEFINE_UL( s, d )
#define printf( x ) \
__asm__ __volatile__ ( "\n->" x )
#else
#define DEFINE_UL( s, ul ) \
printf( "#define %s\t%lu\n", s, (unsigned long) (ul) );
#define DEFINE( s, d ) \
printf( "#define %s\t0x%" PRIx64 "\n", s, (uint64_t) d );
#endif
#define OFFSET( s, t, m ) \
DEFINE_UL( s, offsetof( t, m ) )
#define SIZEOF( s, t ) \
DEFINE_UL( s, sizeof(t) )
int main( int argc, char **argv )
{
printf( "/*\n" );
printf( " * This file is automatically generated from the Mesa internal type\n" );
printf( " * definitions. Do not edit directly.\n" );
printf( " */\n" );
printf( "\n" );
printf( "#ifndef __ASM_TYPES_H__\n" );
printf( "#define __ASM_TYPES_H__\n" );
printf( "\n" );
/* GLvector4f offsets:
*/
OFFSET_HEADER( "GLvector4f" );
OFFSET( "V4F_DATA ", GLvector4f, data );
OFFSET( "V4F_START ", GLvector4f, start );
OFFSET( "V4F_COUNT ", GLvector4f, count );
OFFSET( "V4F_STRIDE ", GLvector4f, stride );
OFFSET( "V4F_SIZE ", GLvector4f, size );
OFFSET( "V4F_FLAGS ", GLvector4f, flags );
DEFINE_HEADER( "GLvector4f" );
DEFINE( "VEC_SIZE_1 ", VEC_SIZE_1 );
DEFINE( "VEC_SIZE_2 ", VEC_SIZE_2 );
DEFINE( "VEC_SIZE_3 ", VEC_SIZE_3 );
DEFINE( "VEC_SIZE_4 ", VEC_SIZE_4 );
/* GLmatrix offsets:
*/
OFFSET_HEADER( "GLmatrix" );
OFFSET( "MATRIX_DATA ", GLmatrix, m );
OFFSET( "MATRIX_INV ", GLmatrix, inv );
OFFSET( "MATRIX_FLAGS ", GLmatrix, flags );
OFFSET( "MATRIX_TYPE ", GLmatrix, type );
printf( "\n" );
printf( "\n" );
printf( "#endif /* __ASM_TYPES_H__ */\n" );
return 0;
}

View File

@@ -6,7 +6,8 @@
#ifdef USE_MMX_ASM #ifdef USE_MMX_ASM
#include "assyntax.h" #include "assyntax.h"
#include "matypes.h" #define MATH_ASM_PTR_SIZE 4
#include "math/m_vector_asm.h"
/* integer multiplication - alpha plus one /* integer multiplication - alpha plus one
* *

View File

@@ -32,7 +32,8 @@
#ifdef USE_SSE_ASM #ifdef USE_SSE_ASM
#include "assyntax.h" #include "assyntax.h"
#include "matypes.h" #define MATH_ASM_PTR_SIZE 4
#include "math/m_vector_asm.h"
#include "norm_args.h" #include "norm_args.h"
SEG_TEXT SEG_TEXT

View File

@@ -32,7 +32,8 @@
#ifdef USE_SSE_ASM #ifdef USE_SSE_ASM
#include "assyntax.h" #include "assyntax.h"
#include "matypes.h" #define MATH_ASM_PTR_SIZE 4
#include "math/m_vector_asm.h"
#include "xform_args.h" #include "xform_args.h"
SEG_TEXT SEG_TEXT

View File

@@ -32,7 +32,8 @@
#ifdef USE_SSE_ASM #ifdef USE_SSE_ASM
#include "assyntax.h" #include "assyntax.h"
#include "matypes.h" #define MATH_ASM_PTR_SIZE 4
#include "math/m_vector_asm.h"
#include "xform_args.h" #include "xform_args.h"
SEG_TEXT SEG_TEXT

View File

@@ -32,7 +32,8 @@
#ifdef USE_SSE_ASM #ifdef USE_SSE_ASM
#include "assyntax.h" #include "assyntax.h"
#include "matypes.h" #define MATH_ASM_PTR_SIZE 4
#include "math/m_vector_asm.h"
#include "xform_args.h" #include "xform_args.h"
SEG_TEXT SEG_TEXT

View File

@@ -25,7 +25,8 @@
#ifdef USE_SSE_ASM #ifdef USE_SSE_ASM
#include "assyntax.h" #include "assyntax.h"
#include "matypes.h" #define MATH_ASM_PTR_SIZE 4
#include "math/m_vector_asm.h"
#include "xform_args.h" #include "xform_args.h"
SEG_TEXT SEG_TEXT

View File

@@ -30,7 +30,8 @@
*/ */
#include "assyntax.h" #include "assyntax.h"
#include "matypes.h" #define MATH_ASM_PTR_SIZE 4
#include "math/m_vector_asm.h"
#include "clip_args.h" #include "clip_args.h"
#define SRC0 REGOFF(0, ESI) #define SRC0 REGOFF(0, ESI)

View File

@@ -30,7 +30,8 @@
*/ */
#include "assyntax.h" #include "assyntax.h"
#include "matypes.h" #define MATH_ASM_PTR_SIZE 4
#include "math/m_vector_asm.h"
#include "xform_args.h" #include "xform_args.h"
SEG_TEXT SEG_TEXT

View File

@@ -30,7 +30,8 @@
*/ */
#include "assyntax.h" #include "assyntax.h"
#include "matypes.h" #define MATH_ASM_PTR_SIZE 4
#include "math/m_vector_asm.h"
#include "xform_args.h" #include "xform_args.h"
SEG_TEXT SEG_TEXT

View File

@@ -30,7 +30,8 @@
*/ */
#include "assyntax.h" #include "assyntax.h"
#include "matypes.h" #define MATH_ASM_PTR_SIZE 4
#include "math/m_vector_asm.h"
#include "xform_args.h" #include "xform_args.h"
SEG_TEXT SEG_TEXT