mesa/main: Add support for remap table.

This commit only adds the source files.  It is supposed to replace the
remap table in DRI drivers.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
This commit is contained in:
Chia-I Wu 2009-10-08 10:33:32 +08:00 committed by Brian Paul
parent bec5230a1f
commit d7d3fb925b
6 changed files with 6416 additions and 0 deletions

View file

@ -9,6 +9,7 @@ include $(TOP)/configs/current
OUTPUTS = glprocs.h glapitemp.h glapioffsets.h glapitable.h dispatch.h \
../main/enums.c \
../main/remap_helper.h \
../x86/glapi_x86.S \
../x86-64/glapi_x86-64.S \
../sparc/glapi_sparc.S \
@ -92,6 +93,9 @@ dispatch.h $(GLX_DIR)/dispatch.h: gl_table.py $(COMMON)
../main/enums.c: gl_enums.py $(COMMON)
$(PYTHON2) $(PYTHON_FLAGS) $< > $@
../main/remap_helper.h: remap_helper.py $(COMMON)
$(PYTHON2) $(PYTHON_FLAGS) $< > $@
../x86/glapi_x86.S: gl_x86_asm.py $(COMMON)
$(PYTHON2) $(PYTHON_FLAGS) $< > $@

View file

@ -0,0 +1,219 @@
#!/usr/bin/env python
# Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>
# All Rights Reserved.
#
# This is based on extension_helper.py by Ian Romanick.
#
# 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
# on the rights to use, copy, modify, merge, publish, distribute, sub
# license, 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 NON-INFRINGEMENT. IN NO EVENT SHALL
# IBM AND/OR ITS SUPPLIERS 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.
import gl_XML
import license
import sys, getopt, string
def get_function_spec(func):
sig = ""
# derive parameter signature
for p in func.parameterIterator():
if p.is_padding:
continue
# FIXME: This is a *really* ugly hack. :(
tn = p.type_expr.get_base_type_node()
if p.is_pointer():
sig += 'p'
elif tn.integer:
sig += 'i'
elif tn.size == 4:
sig += 'f'
else:
sig += 'd'
spec = [sig]
for ent in func.entry_points:
spec.append("gl" + ent)
# spec is terminated by an empty string
spec.append('')
return spec
class PrintGlRemap(gl_XML.gl_print_base):
def __init__(self):
gl_XML.gl_print_base.__init__(self)
self.name = "remap_helper.py (from Mesa)"
self.license = license.bsd_license_template % ("Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>", "Chia-I Wu")
return
def printRealHeader(self):
print '#include "glapi/dispatch.h"'
print '#include "glapi/glapioffsets.h"'
print ''
return
def printBody(self, api):
print 'struct gl_function_remap {'
print ' GLint func_index;'
print ' GLint dispatch_offset; /* for sanity check */'
print '};'
print ''
pool_indices = {}
print '/* this is internal to remap.c */'
print '#ifdef need_MESA_remap_table'
print ''
print 'static const char _mesa_function_pool[] ='
# output string pool
index = 0;
for f in api.functionIterateAll():
pool_indices[f] = index
spec = get_function_spec(f)
# a function has either assigned offset, fixed offset,
# or no offset
if f.assign_offset:
comments = "will be remapped"
elif f.offset > 0:
comments = "offset %d" % f.offset
else:
comments = "dynamic"
print ' /* _mesa_function_pool[%d]: %s (%s) */' \
% (index, f.name, comments)
for line in spec:
print ' "%s\\0"' % line
index += len(line) + 1
print ' ;'
print ''
print '/* these functions need to be remapped */'
print 'static const struct {'
print ' GLint pool_index;'
print ' GLint remap_index;'
print '} MESA_remap_table_functions[] = {'
# output all functions that need to be remapped
# iterate by offsets so that they are sorted by remap indices
for f in api.functionIterateByOffset():
if not f.assign_offset:
continue
print ' { %5d, %s_remap_index },' \
% (pool_indices[f], f.name)
print ' { -1, -1 }'
print '};'
print ''
abi = [ "1.0", "1.1", "1.2", "GL_ARB_multitexture" ]
extension_functions = {}
# collect non-ABI functions
for f in api.functionIterateAll():
for n in f.entry_points:
category, num = api.get_category_for_name(n)
if category not in abi:
c = gl_XML.real_category_name(category)
if not extension_functions.has_key(c):
extension_functions[c] = []
extension_functions[c].append(f)
extensions = extension_functions.keys()
extensions.sort()
# output ABI functions that have alternative names (with ext suffix)
print '/* these functions are in the ABI, but have alternative names */'
print 'static const struct gl_function_remap MESA_alt_functions[] = {'
for ext in extensions:
funcs = []
for f in extension_functions[ext]:
# test if the function is in the ABI
if not f.assign_offset and f.offset >= 0:
funcs.append(f)
if not funcs:
continue
print ' /* from %s */' % ext
for f in funcs:
print ' { %5d, _gloffset_%s },' \
% (pool_indices[f], f.name)
print ' { -1, -1 }'
print '};'
print ''
print '#endif /* need_MESA_remap_table */'
print ''
# output remap helpers for DRI drivers
for ext in extensions:
funcs = []
remapped = []
for f in extension_functions[ext]:
if f.assign_offset:
# these are handled above
remapped.append(f)
else:
# these functions are either in the
# abi, or have offset -1
funcs.append(f)
print '#if defined(need_%s)' % (ext)
if remapped:
print '/* functions defined in MESA_remap_table_functions are excluded */'
# output extension functions that need to be mapped
print 'static const struct gl_function_remap %s_functions[] = {' % (ext)
for f in funcs:
if f.offset >= 0:
print ' { %5d, _gloffset_%s },' \
% (pool_indices[f], f.name)
else:
print ' { %5d, -1 }, /* %s */' % \
(pool_indices[f], f.name)
print ' { -1, -1 }'
print '};'
print '#endif'
print ''
return
def show_usage():
print "Usage: %s [-f input_file_name]" % sys.argv[0]
sys.exit(1)
if __name__ == '__main__':
file_name = "gl_API.xml"
try:
(args, trail) = getopt.getopt(sys.argv[1:], "f:")
except Exception,e:
show_usage()
for (arg,val) in args:
if arg == "-f":
file_name = val
api = gl_XML.parse_GL_API( file_name )
printer = PrintGlRemap()
printer.Print( api )

View file

@ -68,6 +68,12 @@
* enabled or not.
*/
#ifdef IN_DRI_DRIVER
#define FEATURE_remap_table 1
#else
#define FEATURE_remap_table 0
#endif
#define FEATURE_accum _HAVE_FULL_GL
#define FEATURE_arrayelt _HAVE_FULL_GL
#define FEATURE_attrib_stack _HAVE_FULL_GL

216
src/mesa/main/remap.c Normal file
View file

@ -0,0 +1,216 @@
/*
* Mesa 3-D graphics library
* Version: 7.7
*
* Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>
*
* 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
* BRIAN PAUL 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.
*/
/**
* \file remap.c
* Remap table management.
*
* Entries in the dispatch table are either static or dynamic. The
* dispatch table is shared by mesa core and glapi. When they are
* built separately, it is possible that a static entry in mesa core
* is dynamic, or assigned a different static offset, in glapi. The
* remap table is in charge of mapping a static entry in mesa core to
* a dynamic entry, or the corresponding static entry, in glapi.
*/
#include "remap.h"
#include "imports.h"
#include "glapi/dispatch.h"
#if FEATURE_remap_table
#define need_MESA_remap_table
#include "remap_helper.h"
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
#define MAX_ENTRY_POINTS 16
/* this is global for quick access */
int driDispatchRemapTable[driDispatchRemapTable_size];
/**
* Return the spec string associated with the given function index.
* The index is available from including remap_helper.h.
*
* \param func_index an opaque function index.
*
* \return the spec string associated with the function index, or NULL.
*/
const char *
_mesa_get_function_spec(GLint func_index)
{
if (func_index < ARRAY_SIZE(_mesa_function_pool))
return _mesa_function_pool + func_index;
else
return NULL;
}
/**
* Map a function by its spec. The function will be added to glapi,
* and the dispatch offset will be returned.
*
* \param spec a '\0'-separated string array specifying a function.
* It begins with the parameter signature of the function,
* followed by the names of the entry points. An empty entry
* point name terminates the array.
*
* \return the offset of the (re-)mapped function in the dispatch
* table, or -1.
*/
GLint
_mesa_map_function_spec(const char *spec)
{
const char *signature;
const char *names[MAX_ENTRY_POINTS + 1];
GLint num_names = 0;
if (!spec)
return -1;
signature = spec;
spec += strlen(spec) + 1;
/* spec is terminated by an empty string */
while (*spec) {
names[num_names] = spec;
num_names++;
if (num_names >= MAX_ENTRY_POINTS)
break;
spec += strlen(spec) + 1;
}
if (!num_names)
return -1;
names[num_names] = NULL;
/* add the entry points to the dispatch table */
return _glapi_add_dispatch(names, signature);
}
/**
* Map an array of functions. This is a convenient function for
* use with arrays available from including remap_helper.h.
*
* Note that the dispatch offsets of the functions are not returned.
* If they are needed, _mesa_map_function_spec() should be used.
*
* \param func_array an array of function remaps.
*/
void
_mesa_map_function_array(const struct gl_function_remap *func_array)
{
GLint i;
if (!func_array)
return;
for (i = 0; func_array[i].func_index != -1; i++) {
const char *spec;
GLint offset;
spec = _mesa_get_function_spec(func_array[i].func_index);
if (!spec) {
_mesa_problem(NULL, "invalid function index %d",
func_array[i].func_index);
continue;
}
offset = _mesa_map_function_spec(spec);
/* error checks */
if (offset < 0) {
const char *name = spec + strlen(spec) + 1;
_mesa_warning(NULL, "failed to remap %s", name);
}
else if (func_array[i].dispatch_offset >= 0 &&
offset != func_array[i].dispatch_offset) {
const char *name = spec + strlen(spec) + 1;
_mesa_problem(NULL, "%s should be mapped to %d, not %d",
name, func_array[i].dispatch_offset, offset);
}
}
}
/**
* Map the functions which are already static.
*
* When a extension function are incorporated into the ABI, the
* extension suffix is usually stripped. Mapping such functions
* makes sure the alternative names are available.
*
* Note that functions mapped by _mesa_init_remap_table() are
* excluded.
*/
void
_mesa_map_static_functions(void)
{
/* Remap static functions which have alternative names and are in the ABI.
* This is to be on the safe side. glapi should have defined those names.
*/
_mesa_map_function_array(MESA_alt_functions);
}
/**
* Initialize the remap table. This is called in one_time_init().
* The remap table needs to be initialized before calling the
* CALL/GET/SET macros defined in glapi/dispatch.h.
*/
void
_mesa_init_remap_table(void)
{
static GLboolean initialized = GL_FALSE;
GLint i;
if (initialized)
return;
initialized = GL_TRUE;
/* initialize the remap table */
for (i = 0; i < ARRAY_SIZE(driDispatchRemapTable); i++) {
GLint offset;
const char *spec;
/* sanity check */
ASSERT(i == MESA_remap_table_functions[i].remap_index);
spec = _mesa_function_pool + MESA_remap_table_functions[i].pool_index;
offset = _mesa_map_function_spec(spec);
/* store the dispatch offset in the remap table */
driDispatchRemapTable[i] = offset;
if (offset < 0)
_mesa_warning(NULL, "failed to remap index %d", i);
}
}
#endif /* FEATURE_remap_table */

87
src/mesa/main/remap.h Normal file
View file

@ -0,0 +1,87 @@
/*
* Mesa 3-D graphics library
* Version: 7.7
*
* Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>
*
* 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
* BRIAN PAUL 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 REMAP_H
#define REMAP_H
#include "main/mtypes.h"
struct gl_function_remap;
#if FEATURE_remap_table
extern int
driDispatchRemapTable[];
extern const char *
_mesa_get_function_spec(GLint func_index);
extern GLint
_mesa_map_function_spec(const char *spec);
extern void
_mesa_map_function_array(const struct gl_function_remap *func_array);
extern void
_mesa_map_static_functions(void);
extern void
_mesa_init_remap_table(void);
#else /* FEATURE_remap_table */
static INLINE const char *
_mesa_get_function_spec(GLint func_index)
{
return NULL;
}
static INLINE GLint
_mesa_map_function_spec(const char *spec)
{
return -1;
}
static INLINE void
_mesa_map_function_array(const struct gl_function_remap *func_array)
{
}
static INLINE void
_mesa_map_static_functions(void)
{
}
static INLINE void
_mesa_init_remap_table(void)
{
}
#endif /* FEATURE_remap_table */
#endif /* REMAP_H */

5884
src/mesa/main/remap_helper.h Normal file

File diff suppressed because it is too large Load diff