From: George Sapountzis Date: Mon, 22 Feb 2010 20:27:48 +0000 (+0200) Subject: glapi: mv code generation to subdir X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f437a673777ca613ef4c1464fb9083e269f3928c;p=mesa.git glapi: mv code generation to subdir This just moves files, code generation Makefile will be fixed in next commit for easier review. --- diff --git a/src/mesa/glapi/APPLE_vertex_array_object.xml b/src/mesa/glapi/APPLE_vertex_array_object.xml deleted file mode 100644 index bd8427eaf62..00000000000 --- a/src/mesa/glapi/APPLE_vertex_array_object.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/mesa/glapi/ARB_copy_buffer.xml b/src/mesa/glapi/ARB_copy_buffer.xml deleted file mode 100644 index 719816d817e..00000000000 --- a/src/mesa/glapi/ARB_copy_buffer.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/mesa/glapi/ARB_depth_clamp.xml b/src/mesa/glapi/ARB_depth_clamp.xml deleted file mode 100644 index 157c9a86b12..00000000000 --- a/src/mesa/glapi/ARB_depth_clamp.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/src/mesa/glapi/ARB_draw_elements_base_vertex.xml b/src/mesa/glapi/ARB_draw_elements_base_vertex.xml deleted file mode 100644 index f4067f4c8dd..00000000000 --- a/src/mesa/glapi/ARB_draw_elements_base_vertex.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/mesa/glapi/ARB_framebuffer_object.xml b/src/mesa/glapi/ARB_framebuffer_object.xml deleted file mode 100644 index e6bdcd6e509..00000000000 --- a/src/mesa/glapi/ARB_framebuffer_object.xml +++ /dev/null @@ -1,275 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/mesa/glapi/ARB_map_buffer_range.xml b/src/mesa/glapi/ARB_map_buffer_range.xml deleted file mode 100644 index afcb9b6ba6d..00000000000 --- a/src/mesa/glapi/ARB_map_buffer_range.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/mesa/glapi/ARB_seamless_cube_map.xml b/src/mesa/glapi/ARB_seamless_cube_map.xml deleted file mode 100644 index 3cdc84d2b98..00000000000 --- a/src/mesa/glapi/ARB_seamless_cube_map.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/src/mesa/glapi/ARB_sync.xml b/src/mesa/glapi/ARB_sync.xml deleted file mode 100644 index 4e4eebac32a..00000000000 --- a/src/mesa/glapi/ARB_sync.xml +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/mesa/glapi/ARB_vertex_array_object.xml b/src/mesa/glapi/ARB_vertex_array_object.xml deleted file mode 100644 index 3b4ab64f557..00000000000 --- a/src/mesa/glapi/ARB_vertex_array_object.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/mesa/glapi/EXT_draw_buffers2.xml b/src/mesa/glapi/EXT_draw_buffers2.xml deleted file mode 100644 index efbe61f74ed..00000000000 --- a/src/mesa/glapi/EXT_draw_buffers2.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/mesa/glapi/EXT_framebuffer_object.xml b/src/mesa/glapi/EXT_framebuffer_object.xml deleted file mode 100644 index 4f418f7b64c..00000000000 --- a/src/mesa/glapi/EXT_framebuffer_object.xml +++ /dev/null @@ -1,235 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/mesa/glapi/EXT_packed_depth_stencil.xml b/src/mesa/glapi/EXT_packed_depth_stencil.xml deleted file mode 100644 index 5be810302f3..00000000000 --- a/src/mesa/glapi/EXT_packed_depth_stencil.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/src/mesa/glapi/EXT_provoking_vertex.xml b/src/mesa/glapi/EXT_provoking_vertex.xml deleted file mode 100644 index 71d2c729091..00000000000 --- a/src/mesa/glapi/EXT_provoking_vertex.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/mesa/glapi/EXT_texture_array.xml b/src/mesa/glapi/EXT_texture_array.xml deleted file mode 100644 index b5b8bd406f7..00000000000 --- a/src/mesa/glapi/EXT_texture_array.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/mesa/glapi/Makefile b/src/mesa/glapi/Makefile deleted file mode 100644 index da679607d7b..00000000000 --- a/src/mesa/glapi/Makefile +++ /dev/null @@ -1,158 +0,0 @@ -# This file isn't used during a normal compilation since we don't want to -# require Python in order to compile Mesa. -# Instead, when the Mesa developers update/change the API interface it's -# up to him/her to re-run this makefile and check in the newly generated files. - - -TOP = ../../.. -include $(TOP)/configs/current - -OUTPUTS = glprocs.h glapitemp.h glapioffsets.h glapitable.h glapidispatch.h \ - ../main/enums.c \ - ../main/remap_helper.h \ - ../x86/glapi_x86.S \ - ../x86-64/glapi_x86-64.S \ - ../sparc/glapi_sparc.S \ - ../../glx/indirect.c \ - ../../glx/indirect.h \ - ../../glx/indirect_init.c \ - ../../glx/indirect_size.h \ - ../../glx/indirect_size.c - - -GLX_DIR = $(XORG_BASE)/glx - -SERVER_GLAPI_FILES = \ - $(GLX_DIR)/glapi.h \ - $(GLX_DIR)/glapi.c \ - $(GLX_DIR)/glapi_nop.c \ - $(GLX_DIR)/glthread.c \ - $(GLX_DIR)/glthread.h - -SERVER_OUTPUTS = \ - $(GLX_DIR)/indirect_dispatch.c \ - $(GLX_DIR)/indirect_dispatch_swap.c \ - $(GLX_DIR)/indirect_dispatch.h \ - $(GLX_DIR)/indirect_reqsize.c \ - $(GLX_DIR)/indirect_reqsize.h \ - $(GLX_DIR)/indirect_size.h \ - $(GLX_DIR)/indirect_size_get.c \ - $(GLX_DIR)/indirect_size_get.h \ - $(GLX_DIR)/indirect_table.c \ - $(GLX_DIR)/glapitemp.h \ - $(GLX_DIR)/glapitable.h \ - $(GLX_DIR)/glapioffsets.h \ - $(GLX_DIR)/glapidispatch.h \ - $(GLX_DIR)/glprocs.h \ - $(SERVER_GLAPI_FILES) - -API_XML = gl_API.xml \ - ARB_copy_buffer.xml \ - ARB_depth_clamp.xml \ - ARB_draw_elements_base_vertex.xml \ - ARB_framebuffer_object.xml \ - ARB_map_buffer_range.xml \ - ARB_seamless_cube_map.xml \ - ARB_sync.xml \ - ARB_vertex_array_object.xml \ - APPLE_vertex_array_object.xml \ - EXT_draw_buffers2.xml \ - EXT_framebuffer_object.xml \ - EXT_packed_depth_stencil.xml \ - EXT_provoking_vertex.xml \ - EXT_texture_array.xml \ - NV_conditional_render.xml - -COMMON = gl_XML.py glX_XML.py license.py $(API_XML) typeexpr.py -COMMON_GLX = $(COMMON) glX_API.xml glX_XML.py glX_proto_common.py - -all: check-xorg-source $(OUTPUTS) $(SERVER_OUTPUTS) - -check-xorg-source: - @if ! test -d $(GLX_DIR); then \ - echo "ERROR: Must specify path to xserver checkout; set XORG_BASE."; \ - exit 1; \ - fi - -$(GLX_DIR)/%.c: %.c - cp $< $@ - -$(GLX_DIR)/%.h: %.h - cp $< $@ - -glprocs.h $(GLX_DIR)/glprocs.h: gl_procs.py $(COMMON) - $(PYTHON2) $(PYTHON_FLAGS) $< > $@ - -glapitemp.h $(GLX_DIR)/glapitemp.h: gl_apitemp.py $(COMMON) - $(PYTHON2) $(PYTHON_FLAGS) $< > $@ - -glapioffsets.h $(GLX_DIR)/glapioffsets.h: gl_offsets.py $(COMMON) - $(PYTHON2) $(PYTHON_FLAGS) $< > $@ - -glapitable.h $(GLX_DIR)/glapitable.h: gl_table.py $(COMMON) - $(PYTHON2) $(PYTHON_FLAGS) $< > $@ - -glapidispatch.h $(GLX_DIR)/glapidispatch.h: gl_table.py $(COMMON) - $(PYTHON2) $(PYTHON_FLAGS) $< -m remap_table > $@ - -../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) $< > $@ - -../x86-64/glapi_x86-64.S: gl_x86-64_asm.py $(COMMON) - $(PYTHON2) $(PYTHON_FLAGS) $< > $@ - -../sparc/glapi_sparc.S: gl_SPARC_asm.py $(COMMON) - $(PYTHON2) $(PYTHON_FLAGS) $< > $@ - -../../glx/indirect.c: glX_proto_send.py $(COMMON_GLX) - $(PYTHON2) $(PYTHON_FLAGS) $< -m proto | $(INDENT) $(INDENT_FLAGS) > $@ - -../../glx/indirect.h: glX_proto_send.py $(COMMON_GLX) - $(PYTHON2) $(PYTHON_FLAGS) $< -m init_h > $@ - -../../glx/indirect_init.c: glX_proto_send.py $(COMMON_GLX) - $(PYTHON2) $(PYTHON_FLAGS) $< -m init_c > $@ - -../../glx/indirect_size.h $(GLX_DIR)/indirect_size.h: glX_proto_size.py $(COMMON_GLX) - $(PYTHON2) $(PYTHON_FLAGS) $< -m size_h --only-set -h _INDIRECT_SIZE_H_ \ - | $(INDENT) $(INDENT_FLAGS) > $@ - -../../glx/indirect_size.c: glX_proto_size.py $(COMMON_GLX) - $(PYTHON2) $(PYTHON_FLAGS) $< -m size_c --only-set \ - | $(INDENT) $(INDENT_FLAGS) > $@ - -$(GLX_DIR)/indirect_dispatch.c: glX_proto_recv.py $(COMMON_GLX) - $(PYTHON2) $(PYTHON_FLAGS) $< -m dispatch_c > $@ - -$(GLX_DIR)/indirect_dispatch_swap.c: glX_proto_recv.py $(COMMON_GLX) - $(PYTHON2) $(PYTHON_FLAGS) $< -m dispatch_c -s > $@ - -$(GLX_DIR)/indirect_dispatch.h: glX_proto_recv.py gl_and_glX_API.xml $(COMMON_GLX) - $(PYTHON2) $(PYTHON_FLAGS) $< -m dispatch_h -f gl_and_glX_API.xml -s > $@ - -$(GLX_DIR)/indirect_size_get.h: glX_proto_size.py $(COMMON_GLX) - $(PYTHON2) $(PYTHON_FLAGS) $< -m size_h --only-get -h '_INDIRECT_SIZE_GET_H_' \ - | $(INDENT) $(INDENT_FLAGS) > $@ - -$(GLX_DIR)/indirect_size_get.c: glX_proto_size.py $(COMMON_GLX) - $(PYTHON2) $(PYTHON_FLAGS) $< -m size_c | $(INDENT) $(INDENT_FLAGS) > $@ - -$(GLX_DIR)/indirect_reqsize.h: glX_proto_size.py $(COMMON_GLX) - $(PYTHON2) $(PYTHON_FLAGS) $< -m reqsize_h --only-get -h '_INDIRECT_SIZE_GET_H_' \ - | $(INDENT) $(INDENT_FLAGS) -l200 > $@ - -$(GLX_DIR)/indirect_reqsize.c: glX_proto_size.py $(COMMON_GLX) - $(PYTHON2) $(PYTHON_FLAGS) $< -m reqsize_c | $(INDENT) $(INDENT_FLAGS) > $@ - -$(GLX_DIR)/indirect_table.c: glX_server_table.py gl_and_glX_API.xml $(COMMON_GLX) - $(PYTHON2) $(PYTHON_FLAGS) $< -f gl_and_glX_API.xml > $@ - -clean: - -rm -f *~ *.pyo - -rm -f $(OUTPUTS) diff --git a/src/mesa/glapi/NV_conditional_render.xml b/src/mesa/glapi/NV_conditional_render.xml deleted file mode 100644 index 8bb31dd1fc9..00000000000 --- a/src/mesa/glapi/NV_conditional_render.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/mesa/glapi/extension_helper.py b/src/mesa/glapi/extension_helper.py deleted file mode 100644 index 83471d89f50..00000000000 --- a/src/mesa/glapi/extension_helper.py +++ /dev/null @@ -1,324 +0,0 @@ -#!/usr/bin/env python - -# (C) Copyright IBM Corporation 2005 -# 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 -# 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. -# -# Authors: -# Ian Romanick - -import gl_XML -import license -import sys, getopt, string - -vtxfmt = [ - "ArrayElement", \ - "Color3f", \ - "Color3fv", \ - "Color4f", \ - "Color4fv", \ - "EdgeFlag", \ - "EdgeFlagv", \ - "EvalCoord1f", \ - "EvalCoord1fv", \ - "EvalCoord2f", \ - "EvalCoord2fv", \ - "EvalPoint1", \ - "EvalPoint2", \ - "FogCoordfEXT", \ - "FogCoordfvEXT", \ - "Indexf", \ - "Indexfv", \ - "Materialfv", \ - "MultiTexCoord1fARB", \ - "MultiTexCoord1fvARB", \ - "MultiTexCoord2fARB", \ - "MultiTexCoord2fvARB", \ - "MultiTexCoord3fARB", \ - "MultiTexCoord3fvARB", \ - "MultiTexCoord4fARB", \ - "MultiTexCoord4fvARB", \ - "Normal3f", \ - "Normal3fv", \ - "SecondaryColor3fEXT", \ - "SecondaryColor3fvEXT", \ - "TexCoord1f", \ - "TexCoord1fv", \ - "TexCoord2f", \ - "TexCoord2fv", \ - "TexCoord3f", \ - "TexCoord3fv", \ - "TexCoord4f", \ - "TexCoord4fv", \ - "Vertex2f", \ - "Vertex2fv", \ - "Vertex3f", \ - "Vertex3fv", \ - "Vertex4f", \ - "Vertex4fv", \ - "CallList", \ - "CallLists", \ - "Begin", \ - "End", \ - "VertexAttrib1fNV", \ - "VertexAttrib1fvNV", \ - "VertexAttrib2fNV", \ - "VertexAttrib2fvNV", \ - "VertexAttrib3fNV", \ - "VertexAttrib3fvNV", \ - "VertexAttrib4fNV", \ - "VertexAttrib4fvNV", \ - "VertexAttrib1fARB", \ - "VertexAttrib1fvARB", \ - "VertexAttrib2fARB", \ - "VertexAttrib2fvARB", \ - "VertexAttrib3fARB", \ - "VertexAttrib3fvARB", \ - "VertexAttrib4fARB", \ - "VertexAttrib4fvARB", \ - "Rectf", \ - "DrawArrays", \ - "DrawElements", \ - "DrawRangeElements", \ - "EvalMesh1", \ - "EvalMesh2", \ -] - -def all_entrypoints_in_abi(f, abi, api): - for n in f.entry_points: - [category, num] = api.get_category_for_name( n ) - if category not in abi: - return 0 - - return 1 - - -def any_entrypoints_in_abi(f, abi, api): - for n in f.entry_points: - [category, num] = api.get_category_for_name( n ) - if category in abi: - return 1 - - return 0 - - -def condition_for_function(f, abi, all_not_in_ABI): - """Create a C-preprocessor condition for the function. - - There are two modes of operation. If all_not_in_ABI is set, a - condition is only created is all of the entry-point names for f are - not in the selected ABI. If all_not_in_ABI is not set, a condition - is created if any entryp-point name is not in the selected ABI. - """ - - condition = [] - for n in f.entry_points: - [category, num] = api.get_category_for_name( n ) - if category not in abi: - condition.append( 'defined(need_%s)' % (gl_XML.real_category_name( category )) ) - elif all_not_in_ABI: - return [] - - return condition - - -class PrintGlExtensionGlue(gl_XML.gl_print_base): - def __init__(self): - gl_XML.gl_print_base.__init__(self) - - self.name = "extension_helper.py (from Mesa)" - self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM") - return - - - def printRealHeader(self): - print '#include "utils.h"' - print '#include "glapi/dispatch.h"' - print '' - return - - - def printBody(self, api): - abi = [ "1.0", "1.1", "1.2", "GL_ARB_multitexture" ] - - category_list = {} - - print '#ifndef NULL' - print '# define NULL 0' - print '#endif' - print '' - - for f in api.functionIterateAll(): - condition = condition_for_function(f, abi, 0) - if len(condition): - print '#if %s' % (string.join(condition, " || ")) - print 'static const char %s_names[] =' % (f.name) - - parameter_signature = '' - for p in f.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(): - parameter_signature += 'p' - elif tn.integer: - parameter_signature += 'i' - elif tn.size == 4: - parameter_signature += 'f' - else: - parameter_signature += 'd' - - print ' "%s\\0" /* Parameter signature */' % (parameter_signature) - - for n in f.entry_points: - print ' "gl%s\\0"' % (n) - - [category, num] = api.get_category_for_name( n ) - if category not in abi: - c = gl_XML.real_category_name(category) - if not category_list.has_key(c): - category_list[ c ] = [] - - category_list[ c ].append( f ) - - print ' "";' - print '#endif' - print '' - - keys = category_list.keys() - keys.sort() - - for category in keys: - print '#if defined(need_%s)' % (category) - print 'static const struct dri_extension_function %s_functions[] = {' % (category) - - for f in category_list[ category ]: - # A function either has an offset that is - # assigned by the ABI, or it has a remap - # index. - if any_entrypoints_in_abi(f, abi, api): - index_name = "-1" - offset = f.offset - else: - index_name = "%s_remap_index" % (f.name) - offset = -1 - - print ' { %s_names, %s, %d },' % (f.name, index_name, offset) - - - print ' { NULL, 0, 0 }' - print '};' - print '#endif' - print '' - - return - - -class PrintInitDispatch(gl_XML.gl_print_base): - def __init__(self): - gl_XML.gl_print_base.__init__(self) - - self.name = "extension_helper.py (from Mesa)" - self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM") - return - - - def do_function_body(self, api, abi, vtxfmt_only): - last_condition_string = None - for f in api.functionIterateByOffset(): - if (f.name in vtxfmt) and not vtxfmt_only: - continue - - if (f.name not in vtxfmt) and vtxfmt_only: - continue - - condition = condition_for_function(f, abi, 1) - condition_string = string.join(condition, " || ") - - if condition_string != last_condition_string: - if last_condition_string: - print '#endif /* %s */' % (last_condition_string) - - if condition_string: - print '#if %s' % (condition_string) - - if vtxfmt_only: - print ' disp->%s = vfmt->%s;' % (f.name, f.name) - else: - print ' disp->%s = _mesa_%s;' % (f.name, f.name) - - last_condition_string = condition_string - - if last_condition_string: - print '#endif /* %s */' % (last_condition_string) - - - - def printBody(self, api): - abi = [ "1.0", "1.1", "1.2", "GL_ARB_multitexture" ] - - print 'void driver_init_exec_table(struct _glapi_table *disp)' - print '{' - self.do_function_body(api, abi, 0) - print '}' - print '' - print 'void driver_install_vtxfmt(struct _glapi_table *disp, const GLvertexformat *vfmt)' - print '{' - self.do_function_body(api, abi, 1) - print '}' - - return - - -def show_usage(): - print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0] - print " -m output_mode Output mode can be one of 'extensions' or 'exec_init'." - sys.exit(1) - -if __name__ == '__main__': - file_name = "gl_API.xml" - - try: - (args, trail) = getopt.getopt(sys.argv[1:], "f:m:") - except Exception,e: - show_usage() - - mode = "extensions" - for (arg,val) in args: - if arg == "-f": - file_name = val - if arg == '-m': - mode = val - - - api = gl_XML.parse_GL_API( file_name ) - - if mode == "extensions": - printer = PrintGlExtensionGlue() - elif mode == "exec_init": - printer = PrintInitDispatch() - else: - show_usage() - - printer.Print( api ) diff --git a/src/mesa/glapi/gen/APPLE_vertex_array_object.xml b/src/mesa/glapi/gen/APPLE_vertex_array_object.xml new file mode 100644 index 00000000000..bd8427eaf62 --- /dev/null +++ b/src/mesa/glapi/gen/APPLE_vertex_array_object.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mesa/glapi/gen/ARB_copy_buffer.xml b/src/mesa/glapi/gen/ARB_copy_buffer.xml new file mode 100644 index 00000000000..719816d817e --- /dev/null +++ b/src/mesa/glapi/gen/ARB_copy_buffer.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mesa/glapi/gen/ARB_depth_clamp.xml b/src/mesa/glapi/gen/ARB_depth_clamp.xml new file mode 100644 index 00000000000..157c9a86b12 --- /dev/null +++ b/src/mesa/glapi/gen/ARB_depth_clamp.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/mesa/glapi/gen/ARB_draw_elements_base_vertex.xml b/src/mesa/glapi/gen/ARB_draw_elements_base_vertex.xml new file mode 100644 index 00000000000..f4067f4c8dd --- /dev/null +++ b/src/mesa/glapi/gen/ARB_draw_elements_base_vertex.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mesa/glapi/gen/ARB_framebuffer_object.xml b/src/mesa/glapi/gen/ARB_framebuffer_object.xml new file mode 100644 index 00000000000..e6bdcd6e509 --- /dev/null +++ b/src/mesa/glapi/gen/ARB_framebuffer_object.xml @@ -0,0 +1,275 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mesa/glapi/gen/ARB_map_buffer_range.xml b/src/mesa/glapi/gen/ARB_map_buffer_range.xml new file mode 100644 index 00000000000..afcb9b6ba6d --- /dev/null +++ b/src/mesa/glapi/gen/ARB_map_buffer_range.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mesa/glapi/gen/ARB_seamless_cube_map.xml b/src/mesa/glapi/gen/ARB_seamless_cube_map.xml new file mode 100644 index 00000000000..3cdc84d2b98 --- /dev/null +++ b/src/mesa/glapi/gen/ARB_seamless_cube_map.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/mesa/glapi/gen/ARB_sync.xml b/src/mesa/glapi/gen/ARB_sync.xml new file mode 100644 index 00000000000..4e4eebac32a --- /dev/null +++ b/src/mesa/glapi/gen/ARB_sync.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mesa/glapi/gen/ARB_vertex_array_object.xml b/src/mesa/glapi/gen/ARB_vertex_array_object.xml new file mode 100644 index 00000000000..3b4ab64f557 --- /dev/null +++ b/src/mesa/glapi/gen/ARB_vertex_array_object.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mesa/glapi/gen/EXT_draw_buffers2.xml b/src/mesa/glapi/gen/EXT_draw_buffers2.xml new file mode 100644 index 00000000000..efbe61f74ed --- /dev/null +++ b/src/mesa/glapi/gen/EXT_draw_buffers2.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mesa/glapi/gen/EXT_framebuffer_object.xml b/src/mesa/glapi/gen/EXT_framebuffer_object.xml new file mode 100644 index 00000000000..4f418f7b64c --- /dev/null +++ b/src/mesa/glapi/gen/EXT_framebuffer_object.xml @@ -0,0 +1,235 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mesa/glapi/gen/EXT_packed_depth_stencil.xml b/src/mesa/glapi/gen/EXT_packed_depth_stencil.xml new file mode 100644 index 00000000000..5be810302f3 --- /dev/null +++ b/src/mesa/glapi/gen/EXT_packed_depth_stencil.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/mesa/glapi/gen/EXT_provoking_vertex.xml b/src/mesa/glapi/gen/EXT_provoking_vertex.xml new file mode 100644 index 00000000000..71d2c729091 --- /dev/null +++ b/src/mesa/glapi/gen/EXT_provoking_vertex.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mesa/glapi/gen/EXT_texture_array.xml b/src/mesa/glapi/gen/EXT_texture_array.xml new file mode 100644 index 00000000000..b5b8bd406f7 --- /dev/null +++ b/src/mesa/glapi/gen/EXT_texture_array.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mesa/glapi/gen/Makefile b/src/mesa/glapi/gen/Makefile new file mode 100644 index 00000000000..da679607d7b --- /dev/null +++ b/src/mesa/glapi/gen/Makefile @@ -0,0 +1,158 @@ +# This file isn't used during a normal compilation since we don't want to +# require Python in order to compile Mesa. +# Instead, when the Mesa developers update/change the API interface it's +# up to him/her to re-run this makefile and check in the newly generated files. + + +TOP = ../../.. +include $(TOP)/configs/current + +OUTPUTS = glprocs.h glapitemp.h glapioffsets.h glapitable.h glapidispatch.h \ + ../main/enums.c \ + ../main/remap_helper.h \ + ../x86/glapi_x86.S \ + ../x86-64/glapi_x86-64.S \ + ../sparc/glapi_sparc.S \ + ../../glx/indirect.c \ + ../../glx/indirect.h \ + ../../glx/indirect_init.c \ + ../../glx/indirect_size.h \ + ../../glx/indirect_size.c + + +GLX_DIR = $(XORG_BASE)/glx + +SERVER_GLAPI_FILES = \ + $(GLX_DIR)/glapi.h \ + $(GLX_DIR)/glapi.c \ + $(GLX_DIR)/glapi_nop.c \ + $(GLX_DIR)/glthread.c \ + $(GLX_DIR)/glthread.h + +SERVER_OUTPUTS = \ + $(GLX_DIR)/indirect_dispatch.c \ + $(GLX_DIR)/indirect_dispatch_swap.c \ + $(GLX_DIR)/indirect_dispatch.h \ + $(GLX_DIR)/indirect_reqsize.c \ + $(GLX_DIR)/indirect_reqsize.h \ + $(GLX_DIR)/indirect_size.h \ + $(GLX_DIR)/indirect_size_get.c \ + $(GLX_DIR)/indirect_size_get.h \ + $(GLX_DIR)/indirect_table.c \ + $(GLX_DIR)/glapitemp.h \ + $(GLX_DIR)/glapitable.h \ + $(GLX_DIR)/glapioffsets.h \ + $(GLX_DIR)/glapidispatch.h \ + $(GLX_DIR)/glprocs.h \ + $(SERVER_GLAPI_FILES) + +API_XML = gl_API.xml \ + ARB_copy_buffer.xml \ + ARB_depth_clamp.xml \ + ARB_draw_elements_base_vertex.xml \ + ARB_framebuffer_object.xml \ + ARB_map_buffer_range.xml \ + ARB_seamless_cube_map.xml \ + ARB_sync.xml \ + ARB_vertex_array_object.xml \ + APPLE_vertex_array_object.xml \ + EXT_draw_buffers2.xml \ + EXT_framebuffer_object.xml \ + EXT_packed_depth_stencil.xml \ + EXT_provoking_vertex.xml \ + EXT_texture_array.xml \ + NV_conditional_render.xml + +COMMON = gl_XML.py glX_XML.py license.py $(API_XML) typeexpr.py +COMMON_GLX = $(COMMON) glX_API.xml glX_XML.py glX_proto_common.py + +all: check-xorg-source $(OUTPUTS) $(SERVER_OUTPUTS) + +check-xorg-source: + @if ! test -d $(GLX_DIR); then \ + echo "ERROR: Must specify path to xserver checkout; set XORG_BASE."; \ + exit 1; \ + fi + +$(GLX_DIR)/%.c: %.c + cp $< $@ + +$(GLX_DIR)/%.h: %.h + cp $< $@ + +glprocs.h $(GLX_DIR)/glprocs.h: gl_procs.py $(COMMON) + $(PYTHON2) $(PYTHON_FLAGS) $< > $@ + +glapitemp.h $(GLX_DIR)/glapitemp.h: gl_apitemp.py $(COMMON) + $(PYTHON2) $(PYTHON_FLAGS) $< > $@ + +glapioffsets.h $(GLX_DIR)/glapioffsets.h: gl_offsets.py $(COMMON) + $(PYTHON2) $(PYTHON_FLAGS) $< > $@ + +glapitable.h $(GLX_DIR)/glapitable.h: gl_table.py $(COMMON) + $(PYTHON2) $(PYTHON_FLAGS) $< > $@ + +glapidispatch.h $(GLX_DIR)/glapidispatch.h: gl_table.py $(COMMON) + $(PYTHON2) $(PYTHON_FLAGS) $< -m remap_table > $@ + +../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) $< > $@ + +../x86-64/glapi_x86-64.S: gl_x86-64_asm.py $(COMMON) + $(PYTHON2) $(PYTHON_FLAGS) $< > $@ + +../sparc/glapi_sparc.S: gl_SPARC_asm.py $(COMMON) + $(PYTHON2) $(PYTHON_FLAGS) $< > $@ + +../../glx/indirect.c: glX_proto_send.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m proto | $(INDENT) $(INDENT_FLAGS) > $@ + +../../glx/indirect.h: glX_proto_send.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m init_h > $@ + +../../glx/indirect_init.c: glX_proto_send.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m init_c > $@ + +../../glx/indirect_size.h $(GLX_DIR)/indirect_size.h: glX_proto_size.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m size_h --only-set -h _INDIRECT_SIZE_H_ \ + | $(INDENT) $(INDENT_FLAGS) > $@ + +../../glx/indirect_size.c: glX_proto_size.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m size_c --only-set \ + | $(INDENT) $(INDENT_FLAGS) > $@ + +$(GLX_DIR)/indirect_dispatch.c: glX_proto_recv.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m dispatch_c > $@ + +$(GLX_DIR)/indirect_dispatch_swap.c: glX_proto_recv.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m dispatch_c -s > $@ + +$(GLX_DIR)/indirect_dispatch.h: glX_proto_recv.py gl_and_glX_API.xml $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m dispatch_h -f gl_and_glX_API.xml -s > $@ + +$(GLX_DIR)/indirect_size_get.h: glX_proto_size.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m size_h --only-get -h '_INDIRECT_SIZE_GET_H_' \ + | $(INDENT) $(INDENT_FLAGS) > $@ + +$(GLX_DIR)/indirect_size_get.c: glX_proto_size.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m size_c | $(INDENT) $(INDENT_FLAGS) > $@ + +$(GLX_DIR)/indirect_reqsize.h: glX_proto_size.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m reqsize_h --only-get -h '_INDIRECT_SIZE_GET_H_' \ + | $(INDENT) $(INDENT_FLAGS) -l200 > $@ + +$(GLX_DIR)/indirect_reqsize.c: glX_proto_size.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m reqsize_c | $(INDENT) $(INDENT_FLAGS) > $@ + +$(GLX_DIR)/indirect_table.c: glX_server_table.py gl_and_glX_API.xml $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -f gl_and_glX_API.xml > $@ + +clean: + -rm -f *~ *.pyo + -rm -f $(OUTPUTS) diff --git a/src/mesa/glapi/gen/NV_conditional_render.xml b/src/mesa/glapi/gen/NV_conditional_render.xml new file mode 100644 index 00000000000..8bb31dd1fc9 --- /dev/null +++ b/src/mesa/glapi/gen/NV_conditional_render.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mesa/glapi/gen/extension_helper.py b/src/mesa/glapi/gen/extension_helper.py new file mode 100644 index 00000000000..83471d89f50 --- /dev/null +++ b/src/mesa/glapi/gen/extension_helper.py @@ -0,0 +1,324 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2005 +# 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 +# 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. +# +# Authors: +# Ian Romanick + +import gl_XML +import license +import sys, getopt, string + +vtxfmt = [ + "ArrayElement", \ + "Color3f", \ + "Color3fv", \ + "Color4f", \ + "Color4fv", \ + "EdgeFlag", \ + "EdgeFlagv", \ + "EvalCoord1f", \ + "EvalCoord1fv", \ + "EvalCoord2f", \ + "EvalCoord2fv", \ + "EvalPoint1", \ + "EvalPoint2", \ + "FogCoordfEXT", \ + "FogCoordfvEXT", \ + "Indexf", \ + "Indexfv", \ + "Materialfv", \ + "MultiTexCoord1fARB", \ + "MultiTexCoord1fvARB", \ + "MultiTexCoord2fARB", \ + "MultiTexCoord2fvARB", \ + "MultiTexCoord3fARB", \ + "MultiTexCoord3fvARB", \ + "MultiTexCoord4fARB", \ + "MultiTexCoord4fvARB", \ + "Normal3f", \ + "Normal3fv", \ + "SecondaryColor3fEXT", \ + "SecondaryColor3fvEXT", \ + "TexCoord1f", \ + "TexCoord1fv", \ + "TexCoord2f", \ + "TexCoord2fv", \ + "TexCoord3f", \ + "TexCoord3fv", \ + "TexCoord4f", \ + "TexCoord4fv", \ + "Vertex2f", \ + "Vertex2fv", \ + "Vertex3f", \ + "Vertex3fv", \ + "Vertex4f", \ + "Vertex4fv", \ + "CallList", \ + "CallLists", \ + "Begin", \ + "End", \ + "VertexAttrib1fNV", \ + "VertexAttrib1fvNV", \ + "VertexAttrib2fNV", \ + "VertexAttrib2fvNV", \ + "VertexAttrib3fNV", \ + "VertexAttrib3fvNV", \ + "VertexAttrib4fNV", \ + "VertexAttrib4fvNV", \ + "VertexAttrib1fARB", \ + "VertexAttrib1fvARB", \ + "VertexAttrib2fARB", \ + "VertexAttrib2fvARB", \ + "VertexAttrib3fARB", \ + "VertexAttrib3fvARB", \ + "VertexAttrib4fARB", \ + "VertexAttrib4fvARB", \ + "Rectf", \ + "DrawArrays", \ + "DrawElements", \ + "DrawRangeElements", \ + "EvalMesh1", \ + "EvalMesh2", \ +] + +def all_entrypoints_in_abi(f, abi, api): + for n in f.entry_points: + [category, num] = api.get_category_for_name( n ) + if category not in abi: + return 0 + + return 1 + + +def any_entrypoints_in_abi(f, abi, api): + for n in f.entry_points: + [category, num] = api.get_category_for_name( n ) + if category in abi: + return 1 + + return 0 + + +def condition_for_function(f, abi, all_not_in_ABI): + """Create a C-preprocessor condition for the function. + + There are two modes of operation. If all_not_in_ABI is set, a + condition is only created is all of the entry-point names for f are + not in the selected ABI. If all_not_in_ABI is not set, a condition + is created if any entryp-point name is not in the selected ABI. + """ + + condition = [] + for n in f.entry_points: + [category, num] = api.get_category_for_name( n ) + if category not in abi: + condition.append( 'defined(need_%s)' % (gl_XML.real_category_name( category )) ) + elif all_not_in_ABI: + return [] + + return condition + + +class PrintGlExtensionGlue(gl_XML.gl_print_base): + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + self.name = "extension_helper.py (from Mesa)" + self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM") + return + + + def printRealHeader(self): + print '#include "utils.h"' + print '#include "glapi/dispatch.h"' + print '' + return + + + def printBody(self, api): + abi = [ "1.0", "1.1", "1.2", "GL_ARB_multitexture" ] + + category_list = {} + + print '#ifndef NULL' + print '# define NULL 0' + print '#endif' + print '' + + for f in api.functionIterateAll(): + condition = condition_for_function(f, abi, 0) + if len(condition): + print '#if %s' % (string.join(condition, " || ")) + print 'static const char %s_names[] =' % (f.name) + + parameter_signature = '' + for p in f.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(): + parameter_signature += 'p' + elif tn.integer: + parameter_signature += 'i' + elif tn.size == 4: + parameter_signature += 'f' + else: + parameter_signature += 'd' + + print ' "%s\\0" /* Parameter signature */' % (parameter_signature) + + for n in f.entry_points: + print ' "gl%s\\0"' % (n) + + [category, num] = api.get_category_for_name( n ) + if category not in abi: + c = gl_XML.real_category_name(category) + if not category_list.has_key(c): + category_list[ c ] = [] + + category_list[ c ].append( f ) + + print ' "";' + print '#endif' + print '' + + keys = category_list.keys() + keys.sort() + + for category in keys: + print '#if defined(need_%s)' % (category) + print 'static const struct dri_extension_function %s_functions[] = {' % (category) + + for f in category_list[ category ]: + # A function either has an offset that is + # assigned by the ABI, or it has a remap + # index. + if any_entrypoints_in_abi(f, abi, api): + index_name = "-1" + offset = f.offset + else: + index_name = "%s_remap_index" % (f.name) + offset = -1 + + print ' { %s_names, %s, %d },' % (f.name, index_name, offset) + + + print ' { NULL, 0, 0 }' + print '};' + print '#endif' + print '' + + return + + +class PrintInitDispatch(gl_XML.gl_print_base): + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + self.name = "extension_helper.py (from Mesa)" + self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM") + return + + + def do_function_body(self, api, abi, vtxfmt_only): + last_condition_string = None + for f in api.functionIterateByOffset(): + if (f.name in vtxfmt) and not vtxfmt_only: + continue + + if (f.name not in vtxfmt) and vtxfmt_only: + continue + + condition = condition_for_function(f, abi, 1) + condition_string = string.join(condition, " || ") + + if condition_string != last_condition_string: + if last_condition_string: + print '#endif /* %s */' % (last_condition_string) + + if condition_string: + print '#if %s' % (condition_string) + + if vtxfmt_only: + print ' disp->%s = vfmt->%s;' % (f.name, f.name) + else: + print ' disp->%s = _mesa_%s;' % (f.name, f.name) + + last_condition_string = condition_string + + if last_condition_string: + print '#endif /* %s */' % (last_condition_string) + + + + def printBody(self, api): + abi = [ "1.0", "1.1", "1.2", "GL_ARB_multitexture" ] + + print 'void driver_init_exec_table(struct _glapi_table *disp)' + print '{' + self.do_function_body(api, abi, 0) + print '}' + print '' + print 'void driver_install_vtxfmt(struct _glapi_table *disp, const GLvertexformat *vfmt)' + print '{' + self.do_function_body(api, abi, 1) + print '}' + + return + + +def show_usage(): + print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0] + print " -m output_mode Output mode can be one of 'extensions' or 'exec_init'." + sys.exit(1) + +if __name__ == '__main__': + file_name = "gl_API.xml" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:m:") + except Exception,e: + show_usage() + + mode = "extensions" + for (arg,val) in args: + if arg == "-f": + file_name = val + if arg == '-m': + mode = val + + + api = gl_XML.parse_GL_API( file_name ) + + if mode == "extensions": + printer = PrintGlExtensionGlue() + elif mode == "exec_init": + printer = PrintInitDispatch() + else: + show_usage() + + printer.Print( api ) diff --git a/src/mesa/glapi/gen/glX_API.xml b/src/mesa/glapi/gen/glX_API.xml new file mode 100644 index 00000000000..9e02aa498ee --- /dev/null +++ b/src/mesa/glapi/gen/glX_API.xml @@ -0,0 +1,220 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mesa/glapi/gen/glX_XML.py b/src/mesa/glapi/gen/glX_XML.py new file mode 100644 index 00000000000..4c2e0f95bf4 --- /dev/null +++ b/src/mesa/glapi/gen/glX_XML.py @@ -0,0 +1,570 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004, 2005 +# 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 +# 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. +# +# Authors: +# Ian Romanick + +import gl_XML +import license +import sys, getopt, string + + +class glx_item_factory(gl_XML.gl_item_factory): + """Factory to create GLX protocol oriented objects derived from gl_item.""" + + def create_item(self, name, element, context): + if name == "function": + return glx_function(element, context) + elif name == "enum": + return glx_enum(element, context) + elif name == "api": + return glx_api(self) + else: + return gl_XML.gl_item_factory.create_item(self, name, element, context) + + +class glx_enum(gl_XML.gl_enum): + def __init__(self, element, context): + gl_XML.gl_enum.__init__(self, element, context) + + self.functions = {} + + child = element.children + while child: + if child.type == "element" and child.name == "size": + n = child.nsProp( "name", None ) + c = child.nsProp( "count", None ) + m = child.nsProp( "mode", None ) + + if not c: + c = self.default_count + else: + c = int(c) + + if m == "get": + mode = 0 + else: + mode = 1 + + if not self.functions.has_key(n): + self.functions[ n ] = [c, mode] + + child = child.next + + return + + +class glx_function(gl_XML.gl_function): + def __init__(self, element, context): + self.glx_rop = 0 + self.glx_sop = 0 + self.glx_vendorpriv = 0 + + self.glx_vendorpriv_names = [] + + # If this is set to true, it means that GLdouble parameters should be + # written to the GLX protocol packet in the order they appear in the + # prototype. This is different from the "classic" ordering. In the + # classic ordering GLdoubles are written to the protocol packet first, + # followed by non-doubles. NV_vertex_program was the first extension + # to break with this tradition. + + self.glx_doubles_in_order = 0 + + self.vectorequiv = None + self.output = None + self.can_be_large = 0 + self.reply_always_array = 0 + self.dimensions_in_reply = 0 + self.img_reset = None + + self.server_handcode = 0 + self.client_handcode = 0 + self.ignore = 0 + + self.count_parameter_list = [] + self.counter_list = [] + self.parameters_by_name = {} + self.offsets_calculated = 0 + + gl_XML.gl_function.__init__(self, element, context) + return + + + def process_element(self, element): + gl_XML.gl_function.process_element(self, element) + + # If the function already has a vector equivalent set, don't + # set it again. This can happen if an alias to a function + # appears after the function that it aliases. + + if not self.vectorequiv: + self.vectorequiv = element.nsProp("vectorequiv", None) + + + name = element.nsProp("name", None) + if name == self.name: + for param in self.parameters: + self.parameters_by_name[ param.name ] = param + + if len(param.count_parameter_list): + self.count_parameter_list.extend( param.count_parameter_list ) + + if param.counter and param.counter not in self.counter_list: + self.counter_list.append(param.counter) + + + child = element.children + while child: + if child.type == "element" and child.name == "glx": + rop = child.nsProp( 'rop', None ) + sop = child.nsProp( 'sop', None ) + vop = child.nsProp( 'vendorpriv', None ) + + if rop: + self.glx_rop = int(rop) + + if sop: + self.glx_sop = int(sop) + + if vop: + self.glx_vendorpriv = int(vop) + self.glx_vendorpriv_names.append(name) + + self.img_reset = child.nsProp( 'img_reset', None ) + + # The 'handcode' attribute can be one of 'true', + # 'false', 'client', or 'server'. + + handcode = child.nsProp( 'handcode', None ) + if handcode == "false": + self.server_handcode = 0 + self.client_handcode = 0 + elif handcode == "true": + self.server_handcode = 1 + self.client_handcode = 1 + elif handcode == "client": + self.server_handcode = 0 + self.client_handcode = 1 + elif handcode == "server": + self.server_handcode = 1 + self.client_handcode = 0 + else: + raise RuntimeError('Invalid handcode mode "%s" in function "%s".' % (handcode, self.name)) + + self.ignore = gl_XML.is_attr_true( child, 'ignore' ) + self.can_be_large = gl_XML.is_attr_true( child, 'large' ) + self.glx_doubles_in_order = gl_XML.is_attr_true( child, 'doubles_in_order' ) + self.reply_always_array = gl_XML.is_attr_true( child, 'always_array' ) + self.dimensions_in_reply = gl_XML.is_attr_true( child, 'dimensions_in_reply' ) + + child = child.next + + + # Do some validation of the GLX protocol information. As + # new tests are discovered, they should be added here. + + for param in self.parameters: + if param.is_output and self.glx_rop != 0: + raise RuntimeError("Render / RenderLarge commands cannot have outputs (%s)." % (self.name)) + + return + + + def has_variable_size_request(self): + """Determine if the GLX request packet is variable sized. + + The GLX request packet is variable sized in several common + situations. + + 1. The function has a non-output parameter that is counted + by another parameter (e.g., the 'textures' parameter of + glDeleteTextures). + + 2. The function has a non-output parameter whose count is + determined by another parameter that is an enum (e.g., the + 'params' parameter of glLightfv). + + 3. The function has a non-output parameter that is an + image. + + 4. The function must be hand-coded on the server. + """ + + if self.glx_rop == 0: + return 0 + + if self.server_handcode or self.images: + return 1 + + for param in self.parameters: + if not param.is_output: + if param.counter or len(param.count_parameter_list): + return 1 + + return 0 + + + def variable_length_parameter(self): + for param in self.parameters: + if not param.is_output: + if param.counter or len(param.count_parameter_list): + return param + + return None + + + def calculate_offsets(self): + if not self.offsets_calculated: + # Calculate the offset of the first function parameter + # in the GLX command packet. This byte offset is + # measured from the end of the Render / RenderLarge + # header. The offset for all non-pixel commends is + # zero. The offset for pixel commands depends on the + # number of dimensions of the pixel data. + + if len(self.images) and not self.images[0].is_output: + [dim, junk, junk, junk, junk] = self.images[0].get_dimensions() + + # The base size is the size of the pixel pack info + # header used by images with the specified number + # of dimensions. + + if dim <= 2: + offset = 20 + elif dim <= 4: + offset = 36 + else: + raise RuntimeError('Invalid number of dimensions %u for parameter "%s" in function "%s".' % (dim, self.image.name, self.name)) + else: + offset = 0 + + for param in self.parameterIterateGlxSend(): + if param.img_null_flag: + offset += 4 + + if param.name != self.img_reset: + param.offset = offset + if not param.is_variable_length() and not param.is_client_only: + offset += param.size() + + if self.pad_after( param ): + offset += 4 + + + self.offsets_calculated = 1 + return + + + def offset_of(self, param_name): + self.calculate_offsets() + return self.parameters_by_name[ param_name ].offset + + + def parameterIterateGlxSend(self, include_variable_parameters = 1): + """Create an iterator for parameters in GLX request order.""" + + # The parameter lists are usually quite short, so it's easier + # (i.e., less code) to just generate a new list with the + # required elements than it is to create a new iterator class. + + temp = [ [], [], [] ] + for param in self.parameters: + if param.is_output: continue + + if param.is_variable_length(): + temp[2].append( param ) + elif not self.glx_doubles_in_order and param.is_64_bit(): + temp[0].append( param ) + else: + temp[1].append( param ) + + parameters = temp[0] + parameters.extend( temp[1] ) + if include_variable_parameters: + parameters.extend( temp[2] ) + return parameters.__iter__() + + + def parameterIterateCounters(self): + temp = [] + for name in self.counter_list: + temp.append( self.parameters_by_name[ name ] ) + + return temp.__iter__() + + + def parameterIterateOutputs(self): + temp = [] + for p in self.parameters: + if p.is_output: + temp.append( p ) + + return temp + + + def command_fixed_length(self): + """Return the length, in bytes as an integer, of the + fixed-size portion of the command.""" + + if len(self.parameters) == 0: + return 0 + + self.calculate_offsets() + + size = 0 + for param in self.parameterIterateGlxSend(0): + if param.name != self.img_reset and not param.is_client_only: + if size == 0: + size = param.offset + param.size() + else: + size += param.size() + + if self.pad_after( param ): + size += 4 + + for param in self.images: + if param.img_null_flag or param.is_output: + size += 4 + + return size + + + def command_variable_length(self): + """Return the length, as a string, of the variable-sized + portion of the command.""" + + size_string = "" + for p in self.parameterIterateGlxSend(): + if (not p.is_output) and (p.is_variable_length() or p.is_image()): + # FIXME Replace the 1 in the size_string call + # FIXME w/0 to eliminate some un-needed parnes + # FIXME This would already be done, but it + # FIXME adds some extra diffs to the generated + # FIXME code. + + size_string = size_string + " + __GLX_PAD(%s)" % (p.size_string(1)) + + return size_string + + + def command_length(self): + size = self.command_fixed_length() + + if self.glx_rop != 0: + size += 4 + + size = ((size + 3) & ~3) + return "%u%s" % (size, self.command_variable_length()) + + + def opcode_real_value(self): + """Get the true numeric value of the GLX opcode + + Behaves similarly to opcode_value, except for + X_GLXVendorPrivate and X_GLXVendorPrivateWithReply commands. + In these cases the value for the GLX opcode field (i.e., + 16 for X_GLXVendorPrivate or 17 for + X_GLXVendorPrivateWithReply) is returned. For other 'single' + commands, the opcode for the command (e.g., 101 for + X_GLsop_NewList) is returned.""" + + if self.glx_vendorpriv != 0: + if self.needs_reply(): + return 17 + else: + return 16 + else: + return self.opcode_value() + + + def opcode_value(self): + """Get the unique protocol opcode for the glXFunction""" + + if (self.glx_rop == 0) and self.vectorequiv: + equiv = self.context.functions_by_name[ self.vectorequiv ] + self.glx_rop = equiv.glx_rop + + + if self.glx_rop != 0: + return self.glx_rop + elif self.glx_sop != 0: + return self.glx_sop + elif self.glx_vendorpriv != 0: + return self.glx_vendorpriv + else: + return -1 + + + def opcode_rop_basename(self): + """Return either the name to be used for GLX protocol enum. + + Returns either the name of the function or the name of the + name of the equivalent vector (e.g., glVertex3fv for + glVertex3f) function.""" + + if self.vectorequiv == None: + return self.name + else: + return self.vectorequiv + + + def opcode_name(self): + """Get the unique protocol enum name for the glXFunction""" + + if (self.glx_rop == 0) and self.vectorequiv: + equiv = self.context.functions_by_name[ self.vectorequiv ] + self.glx_rop = equiv.glx_rop + self.glx_doubles_in_order = equiv.glx_doubles_in_order + + + if self.glx_rop != 0: + return "X_GLrop_%s" % (self.opcode_rop_basename()) + elif self.glx_sop != 0: + return "X_GLsop_%s" % (self.name) + elif self.glx_vendorpriv != 0: + return "X_GLvop_%s" % (self.name) + else: + raise RuntimeError('Function "%s" has no opcode.' % (self.name)) + + + def opcode_vendor_name(self, name): + if name in self.glx_vendorpriv_names: + return "X_GLvop_%s" % (name) + else: + raise RuntimeError('Function "%s" has no VendorPrivate opcode.' % (name)) + + + def opcode_real_name(self): + """Get the true protocol enum name for the GLX opcode + + Behaves similarly to opcode_name, except for + X_GLXVendorPrivate and X_GLXVendorPrivateWithReply commands. + In these cases the string 'X_GLXVendorPrivate' or + 'X_GLXVendorPrivateWithReply' is returned. For other + single or render commands 'X_GLsop' or 'X_GLrop' plus the + name of the function returned.""" + + if self.glx_vendorpriv != 0: + if self.needs_reply(): + return "X_GLXVendorPrivateWithReply" + else: + return "X_GLXVendorPrivate" + else: + return self.opcode_name() + + + def needs_reply(self): + try: + x = self._needs_reply + except Exception, e: + x = 0 + if self.return_type != 'void': + x = 1 + + for param in self.parameters: + if param.is_output: + x = 1 + break + + self._needs_reply = x + + return x + + + def pad_after(self, p): + """Returns the name of the field inserted after the + specified field to pad out the command header.""" + + for image in self.images: + if image.img_pad_dimensions: + if not image.height: + if p.name == image.width: + return "height" + elif p.name == image.img_xoff: + return "yoffset" + elif not image.extent: + if p.name == image.depth: + # Should this be "size4d"? + return "extent" + elif p.name == image.img_zoff: + return "woffset" + + return None + + + def has_different_protocol(self, name): + """Returns true if the named version of the function uses different protocol from the other versions. + + Some functions, such as glDeleteTextures and + glDeleteTexturesEXT are functionally identical, but have + different protocol. This function returns true if the + named function is an alias name and that named version uses + different protocol from the function that is aliased. + """ + + return (name in self.glx_vendorpriv_names) and self.glx_sop + + + def static_glx_name(self, name): + if self.has_different_protocol(name): + for n in self.glx_vendorpriv_names: + if n in self.static_entry_points: + return n + + return self.static_name(name) + + + def client_supported_for_indirect(self): + """Returns true if the function is supported on the client + side for indirect rendering.""" + + return not self.ignore and (self.offset != -1) and (self.glx_rop or self.glx_sop or self.glx_vendorpriv or self.vectorequiv or self.client_handcode) + + +class glx_function_iterator: + """Class to iterate over a list of glXFunctions""" + + def __init__(self, context): + self.iterator = context.functionIterateByOffset() + return + + + def __iter__(self): + return self + + + def next(self): + f = self.iterator.next() + + if f.client_supported_for_indirect(): + return f + else: + return self.next() + + +class glx_api(gl_XML.gl_api): + def functionIterateGlx(self): + return glx_function_iterator(self) + diff --git a/src/mesa/glapi/gen/glX_doc.py b/src/mesa/glapi/gen/glX_doc.py new file mode 100644 index 00000000000..e9fbbe6f169 --- /dev/null +++ b/src/mesa/glapi/gen/glX_doc.py @@ -0,0 +1,280 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004, 2005 +# 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 +# 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. +# +# Authors: +# Ian Romanick + +import gl_XML, glX_XML, glX_proto_common, license +import sys, getopt + + +class glx_doc_item_factory(glX_proto_common.glx_proto_item_factory): + """Factory to create GLX protocol documentation oriented objects derived from glItem.""" + + def create_item(self, name, element, context): + if name == "parameter": + return glx_doc_parameter(element, context) + else: + return glX_proto_common.glx_proto_item_factory.create_item(self, name, element, context) + + +class glx_doc_parameter(gl_XML.gl_parameter): + def packet_type(self, type_dict): + """Get the type string for the packet header + + GLX protocol documentation uses type names like CARD32, + FLOAT64, LISTofCARD8, and ENUM. This function converts the + type of the parameter to one of these names.""" + + list_of = "" + if self.is_array(): + list_of = "LISTof" + + t_name = self.get_base_type_string() + if not type_dict.has_key( t_name ): + type_name = "CARD8" + else: + type_name = type_dict[ t_name ] + + return "%s%s" % (list_of, type_name) + + + def packet_size(self): + p = None + s = self.size() + if s == 0: + a_prod = "n" + b_prod = self.p_type.size + + if not self.count_parameter_list and self.counter: + a_prod = self.counter + elif self.count_parameter_list and not self.counter or self.is_output: + pass + elif self.count_parameter_list and self.counter: + b_prod = self.counter + else: + raise RuntimeError("Parameter '%s' to function '%s' has size 0." % (self.name, self.context.name)) + + ss = "%s*%s" % (a_prod, b_prod) + + return [ss, p] + else: + if s % 4 != 0: + p = "p" + + return [str(s), p] + +class PrintGlxProtoText(gl_XML.gl_print_base): + def __init__(self): + gl_XML.gl_print_base.__init__(self) + self.license = "" + + + def printHeader(self): + return + + + def body_size(self, f): + # At some point, refactor this function and + # glXFunction::command_payload_length. + + size = 0; + size_str = "" + pad_str = "" + plus = "" + for p in f.parameterIterateGlxSend(): + [s, pad] = p.packet_size() + try: + size += int(s) + except Exception,e: + size_str += "%s%s" % (plus, s) + plus = "+" + + if pad != None: + pad_str = pad + + return [size, size_str, pad_str] + + + def print_render_header(self, f): + [size, size_str, pad_str] = self.body_size(f) + size += 4; + + if size_str == "": + s = "%u" % ((size + 3) & ~3) + elif pad_str != "": + s = "%u+%s+%s" % (size, size_str, pad_str) + else: + s = "%u+%s" % (size, size_str) + + print ' 2 %-15s rendering command length' % (s) + print ' 2 %-4u rendering command opcode' % (f.glx_rop) + return + + + def print_single_header(self, f): + [size, size_str, pad_str] = self.body_size(f) + size = ((size + 3) / 4) + 2; + + if f.glx_vendorpriv != 0: + size += 1 + + print ' 1 CARD8 opcode (X assigned)' + print ' 1 %-4u GLX opcode (%s)' % (f.opcode_real_value(), f.opcode_real_name()) + + if size_str == "": + s = "%u" % (size) + elif pad_str != "": + s = "%u+((%s+%s)/4)" % (size, size_str, pad_str) + else: + s = "%u+((%s)/4)" % (size, size_str) + + print ' 2 %-15s request length' % (s) + + if f.glx_vendorpriv != 0: + print ' 4 %-4u vendor specific opcode' % (f.opcode_value()) + + print ' 4 GLX_CONTEXT_TAG context tag' + + return + + + def print_reply(self, f): + print ' =>' + print ' 1 1 reply' + print ' 1 unused' + print ' 2 CARD16 sequence number' + + if f.output == None: + print ' 4 0 reply length' + elif f.reply_always_array: + print ' 4 m reply length' + else: + print ' 4 m reply length, m = (n == 1 ? 0 : n)' + + + output = None + for x in f.parameterIterateOutputs(): + output = x + break + + + unused = 24 + if f.return_type != 'void': + print ' 4 %-15s return value' % (f.return_type) + unused -= 4 + elif output != None: + print ' 4 unused' + unused -= 4 + + if output != None: + print ' 4 CARD32 n' + unused -= 4 + + if output != None: + if not f.reply_always_array: + print '' + print ' if (n = 1) this follows:' + print '' + print ' 4 CARD32 %s' % (output.name) + print ' %-2u unused' % (unused - 4) + print '' + print ' otherwise this follows:' + print '' + + print ' %-2u unused' % (unused) + + [s, pad] = output.packet_size() + print ' %-8s %-15s %s' % (s, output.packet_type( self.type_map ), output.name) + if pad != None: + try: + bytes = int(s) + bytes = 4 - (bytes & 3) + print ' %-8u %-15s unused' % (bytes, "") + except Exception,e: + print ' %-8s %-15s unused, %s=pad(%s)' % (pad, "", pad, s) + else: + print ' %-2u unused' % (unused) + + + def print_body(self, f): + for p in f.parameterIterateGlxSend(): + [s, pad] = p.packet_size() + print ' %-8s %-15s %s' % (s, p.packet_type( self.type_map ), p.name) + if pad != None: + try: + bytes = int(s) + bytes = 4 - (bytes & 3) + print ' %-8u %-15s unused' % (bytes, "") + except Exception,e: + print ' %-8s %-15s unused, %s=pad(%s)' % (pad, "", pad, s) + + def printBody(self, api): + self.type_map = {} + for t in api.typeIterate(): + self.type_map[ "GL" + t.name ] = t.glx_name + + + # At some point this should be expanded to support pixel + # functions, but I'm not going to lose any sleep over it now. + + for f in api.functionIterateByOffset(): + if f.client_handcode or f.server_handcode or f.vectorequiv or len(f.get_images()): + continue + + + if f.glx_rop: + print ' %s' % (f.name) + self.print_render_header(f) + elif f.glx_sop or f.glx_vendorpriv: + print ' %s' % (f.name) + self.print_single_header(f) + else: + continue + + self.print_body(f) + + if f.needs_reply(): + self.print_reply(f) + + print '' + return + + +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, glx_doc_item_factory() ) + + printer = PrintGlxProtoText() + printer.Print( api ) diff --git a/src/mesa/glapi/gen/glX_proto_common.py b/src/mesa/glapi/gen/glX_proto_common.py new file mode 100644 index 00000000000..6f094e22b31 --- /dev/null +++ b/src/mesa/glapi/gen/glX_proto_common.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004, 2005 +# 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 +# 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. +# +# Authors: +# Ian Romanick + +import gl_XML, glX_XML +import string + + +class glx_proto_item_factory(glX_XML.glx_item_factory): + """Factory to create GLX protocol oriented objects derived from gl_item.""" + + def create_item(self, name, element, context): + if name == "type": + return glx_proto_type(element, context) + else: + return glX_XML.glx_item_factory.create_item(self, name, element, context) + + +class glx_proto_type(gl_XML.gl_type): + def __init__(self, element, context): + gl_XML.gl_type.__init__(self, element, context) + + self.glx_name = element.nsProp( "glx_name", None ) + return + + +class glx_print_proto(gl_XML.gl_print_base): + def size_call(self, func, outputs_also = 0): + """Create C code to calculate 'compsize'. + + Creates code to calculate 'compsize'. If the function does + not need 'compsize' to be calculated, None will be + returned.""" + + compsize = None + + for param in func.parameterIterator(): + if outputs_also or not param.is_output: + if param.is_image(): + [dim, w, h, d, junk] = param.get_dimensions() + + compsize = '__glImageSize(%s, %s, %s, %s, %s, %s)' % (w, h, d, param.img_format, param.img_type, param.img_target) + if not param.img_send_null: + compsize = '(%s != NULL) ? %s : 0' % (param.name, compsize) + + return compsize + + elif len(param.count_parameter_list): + parameters = string.join( param.count_parameter_list, "," ) + compsize = "__gl%s_size(%s)" % (func.name, parameters) + + return compsize + + return None + + + def emit_packet_size_calculation(self, f, bias): + # compsize is only used in the command size calculation if + # the function has a non-output parameter that has a non-empty + # counter_parameter_list. + + compsize = self.size_call(f) + if compsize: + print ' const GLuint compsize = %s;' % (compsize) + + if bias: + print ' const GLuint cmdlen = %s - %u;' % (f.command_length(), bias) + else: + print ' const GLuint cmdlen = %s;' % (f.command_length()) + + #print '' + return compsize diff --git a/src/mesa/glapi/gen/glX_proto_recv.py b/src/mesa/glapi/gen/glX_proto_recv.py new file mode 100644 index 00000000000..f423c6db084 --- /dev/null +++ b/src/mesa/glapi/gen/glX_proto_recv.py @@ -0,0 +1,554 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2005 +# 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 +# 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. +# +# Authors: +# Ian Romanick + +import gl_XML, glX_XML, glX_proto_common, license +import sys, getopt, string + + +class PrintGlxDispatch_h(gl_XML.gl_print_base): + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + self.name = "glX_proto_recv.py (from Mesa)" + self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005", "IBM") + + self.header_tag = "_INDIRECT_DISPATCH_H_" + return + + + def printRealHeader(self): + self.printVisibility( "HIDDEN", "hidden" ) + print 'struct __GLXclientStateRec;' + print '' + return + + + def printBody(self, api): + for func in api.functionIterateAll(): + if not func.ignore and not func.vectorequiv: + if func.glx_rop: + print 'extern HIDDEN void __glXDisp_%s(GLbyte * pc);' % (func.name) + print 'extern HIDDEN void __glXDispSwap_%s(GLbyte * pc);' % (func.name) + elif func.glx_sop or func.glx_vendorpriv: + print 'extern HIDDEN int __glXDisp_%s(struct __GLXclientStateRec *, GLbyte *);' % (func.name) + print 'extern HIDDEN int __glXDispSwap_%s(struct __GLXclientStateRec *, GLbyte *);' % (func.name) + + if func.glx_sop and func.glx_vendorpriv: + n = func.glx_vendorpriv_names[0] + print 'extern HIDDEN int __glXDisp_%s(struct __GLXclientStateRec *, GLbyte *);' % (n) + print 'extern HIDDEN int __glXDispSwap_%s(struct __GLXclientStateRec *, GLbyte *);' % (n) + + return + + +class PrintGlxDispatchFunctions(glX_proto_common.glx_print_proto): + def __init__(self, do_swap): + gl_XML.gl_print_base.__init__(self) + self.name = "glX_proto_recv.py (from Mesa)" + self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005", "IBM") + + self.real_types = [ '', '', 'uint16_t', '', 'uint32_t', '', '', '', 'uint64_t' ] + self.do_swap = do_swap + return + + + def printRealHeader(self): + print '#include ' + print '#include ' + print '#include ' + + print '#include ' + print '#include "indirect_size.h"' + print '#include "indirect_size_get.h"' + print '#include "indirect_dispatch.h"' + print '#include "glxserver.h"' + print '#include "glxbyteorder.h"' + print '#include "indirect_util.h"' + print '#include "singlesize.h"' + print '#include "glapi.h"' + print '#include "glapitable.h"' + print '#include "glthread.h"' + print '#include "dispatch.h"' + print '' + print '#define __GLX_PAD(x) (((x) + 3) & ~3)' + print '' + print 'typedef struct {' + print ' __GLX_PIXEL_3D_HDR;' + print '} __GLXpixel3DHeader;' + print '' + print 'extern GLboolean __glXErrorOccured( void );' + print 'extern void __glXClearErrorOccured( void );' + print '' + print 'static const unsigned dummy_answer[2] = {0, 0};' + print '' + return + + + def printBody(self, api): + if self.do_swap: + self.emit_swap_wrappers(api) + + + for func in api.functionIterateByOffset(): + if not func.ignore and not func.server_handcode and not func.vectorequiv and (func.glx_rop or func.glx_sop or func.glx_vendorpriv): + self.printFunction(func, func.name) + if func.glx_sop and func.glx_vendorpriv: + self.printFunction(func, func.glx_vendorpriv_names[0]) + + + return + + + def printFunction(self, f, name): + if (f.glx_sop or f.glx_vendorpriv) and (len(f.get_images()) != 0): + return + + if not self.do_swap: + base = '__glXDisp' + else: + base = '__glXDispSwap' + + if f.glx_rop: + print 'void %s_%s(GLbyte * pc)' % (base, name) + else: + print 'int %s_%s(__GLXclientState *cl, GLbyte *pc)' % (base, name) + + print '{' + + if f.glx_rop or f.vectorequiv: + self.printRenderFunction(f) + elif f.glx_sop or f.glx_vendorpriv: + if len(f.get_images()) == 0: + self.printSingleFunction(f, name) + else: + print "/* Missing GLX protocol for %s. */" % (name) + + print '}' + print '' + return + + + def swap_name(self, bytes): + return 'bswap_%u_array' % (8 * bytes) + + + def emit_swap_wrappers(self, api): + self.type_map = {} + already_done = [ ] + + for t in api.typeIterate(): + te = t.get_type_expression() + t_size = te.get_element_size() + + if t_size > 1 and t.glx_name: + + t_name = "GL" + t.name + self.type_map[ t_name ] = t.glx_name + + if t.glx_name not in already_done: + real_name = self.real_types[t_size] + + print 'static %s' % (t_name) + print 'bswap_%s( const void * src )' % (t.glx_name) + print '{' + print ' union { %s dst; %s ret; } x;' % (real_name, t_name) + print ' x.dst = bswap_%u( *(%s *) src );' % (t_size * 8, real_name) + print ' return x.ret;' + print '}' + print '' + already_done.append( t.glx_name ) + + for bits in [16, 32, 64]: + print 'static void *' + print 'bswap_%u_array( uint%u_t * src, unsigned count )' % (bits, bits) + print '{' + print ' unsigned i;' + print '' + print ' for ( i = 0 ; i < count ; i++ ) {' + print ' uint%u_t temp = bswap_%u( src[i] );' % (bits, bits) + print ' src[i] = temp;' + print ' }' + print '' + print ' return src;' + print '}' + print '' + + + def fetch_param(self, param): + t = param.type_string() + o = param.offset + element_size = param.size() / param.get_element_count() + + if self.do_swap and (element_size != 1): + if param.is_array(): + real_name = self.real_types[ element_size ] + + swap_func = self.swap_name( element_size ) + return ' (%-8s)%s( (%s *) (pc + %2s), %s )' % (t, swap_func, real_name, o, param.count) + else: + t_name = param.get_base_type_string() + return ' (%-8s)bswap_%-7s( pc + %2s )' % (t, self.type_map[ t_name ], o) + else: + if param.is_array(): + return ' (%-8s)(pc + %2u)' % (t, o) + else: + return '*(%-8s *)(pc + %2u)' % (t, o) + + return None + + + def emit_function_call(self, f, retval_assign, indent): + list = [] + + for param in f.parameterIterator(): + if param.is_padding: + continue + + if param.is_counter or param.is_image() or param.is_output or param.name in f.count_parameter_list or len(param.count_parameter_list): + location = param.name + else: + location = self.fetch_param(param) + + list.append( '%s %s' % (indent, location) ) + + + if len( list ): + print '%s %sCALL_%s( GET_DISPATCH(), (' % (indent, retval_assign, f.name) + print string.join( list, ",\n" ) + print '%s ) );' % (indent) + else: + print '%s %sCALL_%s( GET_DISPATCH(), () );' % (indent, retval_assign, f.name) + return + + + def common_func_print_just_start(self, f, indent): + align64 = 0 + need_blank = 0 + + + f.calculate_offsets() + for param in f.parameterIterateGlxSend(): + # If any parameter has a 64-bit base type, then we + # have to do alignment magic for the while thing. + + if param.is_64_bit(): + align64 = 1 + + + # FIXME img_null_flag is over-loaded. In addition to + # FIXME being used for images, it is used to signify + # FIXME NULL data pointers for vertex buffer object + # FIXME related functions. Re-name it to null_data + # FIXME or something similar. + + if param.img_null_flag: + print '%s const CARD32 ptr_is_null = *(CARD32 *)(pc + %s);' % (indent, param.offset - 4) + cond = '(ptr_is_null != 0) ? NULL : ' + else: + cond = "" + + + type_string = param.type_string() + + if param.is_image(): + offset = f.offset_of( param.name ) + + print '%s %s const %s = (%s) (%s(pc + %s));' % (indent, type_string, param.name, type_string, cond, offset) + + if param.depth: + print '%s __GLXpixel3DHeader * const hdr = (__GLXpixel3DHeader *)(pc);' % (indent) + else: + print '%s __GLXpixelHeader * const hdr = (__GLXpixelHeader *)(pc);' % (indent) + + need_blank = 1 + elif param.is_counter or param.name in f.count_parameter_list: + location = self.fetch_param(param) + print '%s const %s %s = %s;' % (indent, type_string, param.name, location) + need_blank = 1 + elif len(param.count_parameter_list): + if param.size() == 1 and not self.do_swap: + location = self.fetch_param(param) + print '%s %s %s = %s%s;' % (indent, type_string, param.name, cond, location) + else: + print '%s %s %s;' % (indent, type_string, param.name) + need_blank = 1 + + + + if need_blank: + print '' + + if align64: + print '#ifdef __GLX_ALIGN64' + + if f.has_variable_size_request(): + self.emit_packet_size_calculation(f, 4) + s = "cmdlen" + else: + s = str((f.command_fixed_length() + 3) & ~3) + + print ' if ((unsigned long)(pc) & 7) {' + print ' (void) memmove(pc-4, pc, %s);' % (s) + print ' pc -= 4;' + print ' }' + print '#endif' + print '' + + + need_blank = 0 + if self.do_swap: + for param in f.parameterIterateGlxSend(): + if param.count_parameter_list: + o = param.offset + count = param.get_element_count() + type_size = param.size() / count + + if param.counter: + count_name = param.counter + else: + count_name = str(count) + + # This is basically an ugly special- + # case for glCallLists. + + if type_size == 1: + x = [] + x.append( [1, ['BYTE', 'UNSIGNED_BYTE', '2_BYTES', '3_BYTES', '4_BYTES']] ) + x.append( [2, ['SHORT', 'UNSIGNED_SHORT']] ) + x.append( [4, ['INT', 'UNSIGNED_INT', 'FLOAT']] ) + + print ' switch(%s) {' % (param.count_parameter_list[0]) + for sub in x: + for t_name in sub[1]: + print ' case GL_%s:' % (t_name) + + if sub[0] == 1: + print ' %s = (%s) (pc + %s); break;' % (param.name, param.type_string(), o) + else: + swap_func = self.swap_name(sub[0]) + print ' %s = (%s) %s( (%s *) (pc + %s), %s ); break;' % (param.name, param.type_string(), swap_func, self.real_types[sub[0]], o, count_name) + print ' default:' + print ' return;' + print ' }' + else: + swap_func = self.swap_name(type_size) + compsize = self.size_call(f, 1) + print ' %s = (%s) %s( (%s *) (pc + %s), %s );' % (param.name, param.type_string(), swap_func, self.real_types[type_size], o, compsize) + + need_blank = 1 + + else: + for param in f.parameterIterateGlxSend(): + if param.count_parameter_list: + print '%s %s = (%s) (pc + %s);' % (indent, param.name, param.type_string(), param.offset) + need_blank = 1 + + + if need_blank: + print '' + + + return + + + def printSingleFunction(self, f, name): + if name not in f.glx_vendorpriv_names: + print ' xGLXSingleReq * const req = (xGLXSingleReq *) pc;' + else: + print ' xGLXVendorPrivateReq * const req = (xGLXVendorPrivateReq *) pc;' + + print ' int error;' + + if self.do_swap: + print ' __GLXcontext * const cx = __glXForceCurrent(cl, bswap_CARD32( &req->contextTag ), &error);' + else: + print ' __GLXcontext * const cx = __glXForceCurrent(cl, req->contextTag, &error);' + + print '' + if name not in f.glx_vendorpriv_names: + print ' pc += __GLX_SINGLE_HDR_SIZE;' + else: + print ' pc += __GLX_VENDPRIV_HDR_SIZE;' + + print ' if ( cx != NULL ) {' + self.common_func_print_just_start(f, " ") + + + if f.return_type != 'void': + print ' %s retval;' % (f.return_type) + retval_string = "retval" + retval_assign = "retval = " + else: + retval_string = "0" + retval_assign = "" + + + type_size = 0 + answer_string = "dummy_answer" + answer_count = "0" + is_array_string = "GL_FALSE" + + for param in f.parameterIterateOutputs(): + answer_type = param.get_base_type_string() + if answer_type == "GLvoid": + answer_type = "GLubyte" + + + c = param.get_element_count() + type_size = (param.size() / c) + if type_size == 1: + size_scale = "" + else: + size_scale = " * %u" % (type_size) + + + if param.count_parameter_list: + print ' const GLuint compsize = %s;' % (self.size_call(f, 1)) + print ' %s answerBuffer[200];' % (answer_type) + print ' %s %s = __glXGetAnswerBuffer(cl, compsize%s, answerBuffer, sizeof(answerBuffer), %u);' % (param.type_string(), param.name, size_scale, type_size ) + answer_string = param.name + answer_count = "compsize" + + print '' + print ' if (%s == NULL) return BadAlloc;' % (param.name) + print ' __glXClearErrorOccured();' + print '' + elif param.counter: + print ' %s answerBuffer[200];' % (answer_type) + print ' %s %s = __glXGetAnswerBuffer(cl, %s%s, answerBuffer, sizeof(answerBuffer), %u);' % (param.type_string(), param.name, param.counter, size_scale, type_size) + answer_string = param.name + answer_count = param.counter + elif c >= 1: + print ' %s %s[%u];' % (answer_type, param.name, c) + answer_string = param.name + answer_count = "%u" % (c) + + if f.reply_always_array: + is_array_string = "GL_TRUE" + + + self.emit_function_call(f, retval_assign, " ") + + + if f.needs_reply(): + if self.do_swap: + for param in f.parameterIterateOutputs(): + c = param.get_element_count() + type_size = (param.size() / c) + + if type_size > 1: + swap_name = self.swap_name( type_size ) + print ' (void) %s( (uint%u_t *) %s, %s );' % (swap_name, 8 * type_size, param.name, answer_count) + + + reply_func = '__glXSendReplySwap' + else: + reply_func = '__glXSendReply' + + print ' %s(cl->client, %s, %s, %u, %s, %s);' % (reply_func, answer_string, answer_count, type_size, is_array_string, retval_string) + #elif f.note_unflushed: + # print ' cx->hasUnflushedCommands = GL_TRUE;' + + print ' error = Success;' + print ' }' + print '' + print ' return error;' + return + + + def printRenderFunction(self, f): + # There are 4 distinct phases in a rendering dispatch function. + # In the first phase we compute the sizes and offsets of each + # element in the command. In the second phase we (optionally) + # re-align 64-bit data elements. In the third phase we + # (optionally) byte-swap array data. Finally, in the fourth + # phase we actually dispatch the function. + + self.common_func_print_just_start(f, "") + + images = f.get_images() + if len(images): + if self.do_swap: + pre = "bswap_CARD32( & " + post = " )" + else: + pre = "" + post = "" + + img = images[0] + + # swapBytes and lsbFirst are single byte fields, so + # the must NEVER be byte-swapped. + + if not (img.img_type == "GL_BITMAP" and img.img_format == "GL_COLOR_INDEX"): + print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SWAP_BYTES, hdr->swapBytes) );' + + print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_LSB_FIRST, hdr->lsbFirst) );' + + print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_ROW_LENGTH, (GLint) %shdr->rowLength%s) );' % (pre, post) + if img.depth: + print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_IMAGE_HEIGHT, (GLint) %shdr->imageHeight%s) );' % (pre, post) + print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_ROWS, (GLint) %shdr->skipRows%s) );' % (pre, post) + if img.depth: + print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_IMAGES, (GLint) %shdr->skipImages%s) );' % (pre, post) + print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_PIXELS, (GLint) %shdr->skipPixels%s) );' % (pre, post) + print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_ALIGNMENT, (GLint) %shdr->alignment%s) );' % (pre, post) + print '' + + + self.emit_function_call(f, "", "") + return + + +if __name__ == '__main__': + file_name = "gl_API.xml" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:m:s") + except Exception,e: + show_usage() + + mode = "dispatch_c" + do_swap = 0 + for (arg,val) in args: + if arg == "-f": + file_name = val + elif arg == "-m": + mode = val + elif arg == "-s": + do_swap = 1 + + if mode == "dispatch_c": + printer = PrintGlxDispatchFunctions(do_swap) + elif mode == "dispatch_h": + printer = PrintGlxDispatch_h() + else: + show_usage() + + api = gl_XML.parse_GL_API( file_name, glX_proto_common.glx_proto_item_factory() ) + + printer.Print( api ) diff --git a/src/mesa/glapi/gen/glX_proto_send.py b/src/mesa/glapi/gen/glX_proto_send.py new file mode 100644 index 00000000000..daca1b767a3 --- /dev/null +++ b/src/mesa/glapi/gen/glX_proto_send.py @@ -0,0 +1,1042 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004, 2005 +# 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 +# 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. +# +# Authors: +# Ian Romanick +# Jeremy Kolb + +import gl_XML, glX_XML, glX_proto_common, license +import sys, getopt, copy, string + +def convertStringForXCB(str): + tmp = "" + special = [ "ARB" ] + i = 0 + while i < len(str): + if str[i:i+3] in special: + tmp = '%s_%s' % (tmp, string.lower(str[i:i+3])) + i = i + 2; + elif str[i].isupper(): + tmp = '%s_%s' % (tmp, string.lower(str[i])) + else: + tmp = '%s%s' % (tmp, str[i]) + i += 1 + return tmp + +def hash_pixel_function(func): + """Generate a 'unique' key for a pixel function. The key is based on + the parameters written in the command packet. This includes any + padding that might be added for the original function and the 'NULL + image' flag.""" + + + h = "" + hash_pre = "" + hash_suf = "" + for param in func.parameterIterateGlxSend(): + if param.is_image(): + [dim, junk, junk, junk, junk] = param.get_dimensions() + + d = (dim + 1) & ~1 + hash_pre = "%uD%uD_" % (d - 1, d) + + if param.img_null_flag: + hash_suf = "_NF" + + h += "%u" % (param.size()) + + if func.pad_after(param): + h += "4" + + + n = func.name.replace("%uD" % (dim), "") + n = "__glx_%s_%uD%uD" % (n, d - 1, d) + + h = hash_pre + h + hash_suf + return [h, n] + + +class glx_pixel_function_stub(glX_XML.glx_function): + """Dummy class used to generate pixel "utility" functions that are + shared by multiple dimension image functions. For example, these + objects are used to generate shared functions used to send GLX + protocol for TexImage1D and TexImage2D, TexSubImage1D and + TexSubImage2D, etc.""" + + def __init__(self, func, name): + # The parameters to the utility function are the same as the + # parameters to the real function except for the added "pad" + # parameters. + + self.name = name + self.images = [] + self.parameters = [] + self.parameters_by_name = {} + for _p in func.parameterIterator(): + p = copy.copy(_p) + self.parameters.append(p) + self.parameters_by_name[ p.name ] = p + + + if p.is_image(): + self.images.append(p) + p.height = "height" + + if p.img_yoff == None: + p.img_yoff = "yoffset" + + if p.depth: + if p.extent == None: + p.extent = "extent" + + if p.img_woff == None: + p.img_woff = "woffset" + + + pad_name = func.pad_after(p) + if pad_name: + pad = copy.copy(p) + pad.name = pad_name + self.parameters.append(pad) + self.parameters_by_name[ pad.name ] = pad + + + self.return_type = func.return_type + + self.glx_rop = ~0 + self.glx_sop = 0 + self.glx_vendorpriv = 0 + + self.glx_doubles_in_order = func.glx_doubles_in_order + + self.vectorequiv = None + self.output = None + self.can_be_large = func.can_be_large + self.reply_always_array = func.reply_always_array + self.dimensions_in_reply = func.dimensions_in_reply + self.img_reset = None + + self.server_handcode = 0 + self.client_handcode = 0 + self.ignore = 0 + + self.count_parameter_list = func.count_parameter_list + self.counter_list = func.counter_list + self.offsets_calculated = 0 + return + + +class PrintGlxProtoStubs(glX_proto_common.glx_print_proto): + def __init__(self): + glX_proto_common.glx_print_proto.__init__(self) + self.name = "glX_proto_send.py (from Mesa)" + self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2004, 2005", "IBM") + + + self.last_category = "" + self.generic_sizes = [3, 4, 6, 8, 12, 16, 24, 32] + self.pixel_stubs = {} + self.debug = 0 + return + + def printRealHeader(self): + print '' + print '#include ' + print '#include "indirect.h"' + print '#include "glxclient.h"' + print '#include "indirect_size.h"' + print '#include "dispatch.h"' + print '#include "glapi.h"' + print '#include "glthread.h"' + print '#include ' + print '#ifdef USE_XCB' + print '#include ' + print '#include ' + print '#include ' + print '#endif /* USE_XCB */' + + print '' + print '#define __GLX_PAD(n) (((n) + 3) & ~3)' + print '' + self.printFastcall() + self.printNoinline() + print '' + print '#if !defined __GNUC__ || __GNUC__ < 3' + print '# define __builtin_expect(x, y) x' + print '#endif' + print '' + print '/* If the size and opcode values are known at compile-time, this will, on' + print ' * x86 at least, emit them with a single instruction.' + print ' */' + print '#define emit_header(dest, op, size) \\' + print ' do { union { short s[2]; int i; } temp; \\' + print ' temp.s[0] = (size); temp.s[1] = (op); \\' + print ' *((int *)(dest)) = temp.i; } while(0)' + print '' + print """NOINLINE CARD32 +__glXReadReply( Display *dpy, size_t size, void * dest, GLboolean reply_is_always_array ) +{ + xGLXSingleReply reply; + + (void) _XReply(dpy, (xReply *) & reply, 0, False); + if (size != 0) { + if ((reply.length > 0) || reply_is_always_array) { + const GLint bytes = (reply_is_always_array) + ? (4 * reply.length) : (reply.size * size); + const GLint extra = 4 - (bytes & 3); + + _XRead(dpy, dest, bytes); + if ( extra < 4 ) { + _XEatData(dpy, extra); + } + } + else { + (void) memcpy( dest, &(reply.pad3), size); + } + } + + return reply.retval; +} + +NOINLINE void +__glXReadPixelReply( Display *dpy, __GLXcontext * gc, unsigned max_dim, + GLint width, GLint height, GLint depth, GLenum format, GLenum type, + void * dest, GLboolean dimensions_in_reply ) +{ + xGLXSingleReply reply; + GLint size; + + (void) _XReply(dpy, (xReply *) & reply, 0, False); + + if ( dimensions_in_reply ) { + width = reply.pad3; + height = reply.pad4; + depth = reply.pad5; + + if ((height == 0) || (max_dim < 2)) { height = 1; } + if ((depth == 0) || (max_dim < 3)) { depth = 1; } + } + + size = reply.length * 4; + if (size != 0) { + void * buf = Xmalloc( size ); + + if ( buf == NULL ) { + _XEatData(dpy, size); + __glXSetError(gc, GL_OUT_OF_MEMORY); + } + else { + const GLint extra = 4 - (size & 3); + + _XRead(dpy, buf, size); + if ( extra < 4 ) { + _XEatData(dpy, extra); + } + + __glEmptyImage(gc, 3, width, height, depth, format, type, + buf, dest); + Xfree(buf); + } + } +} + +#define X_GLXSingle 0 + +NOINLINE FASTCALL GLubyte * +__glXSetupSingleRequest( __GLXcontext * gc, GLint sop, GLint cmdlen ) +{ + xGLXSingleReq * req; + Display * const dpy = gc->currentDpy; + + (void) __glXFlushRenderBuffer(gc, gc->pc); + LockDisplay(dpy); + GetReqExtra(GLXSingle, cmdlen, req); + req->reqType = gc->majorOpcode; + req->contextTag = gc->currentContextTag; + req->glxCode = sop; + return (GLubyte *)(req) + sz_xGLXSingleReq; +} + +NOINLINE FASTCALL GLubyte * +__glXSetupVendorRequest( __GLXcontext * gc, GLint code, GLint vop, GLint cmdlen ) +{ + xGLXVendorPrivateReq * req; + Display * const dpy = gc->currentDpy; + + (void) __glXFlushRenderBuffer(gc, gc->pc); + LockDisplay(dpy); + GetReqExtra(GLXVendorPrivate, cmdlen, req); + req->reqType = gc->majorOpcode; + req->glxCode = code; + req->vendorCode = vop; + req->contextTag = gc->currentContextTag; + return (GLubyte *)(req) + sz_xGLXVendorPrivateReq; +} + +const GLuint __glXDefaultPixelStore[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + +#define zero (__glXDefaultPixelStore+0) +#define one (__glXDefaultPixelStore+8) +#define default_pixel_store_1D (__glXDefaultPixelStore+4) +#define default_pixel_store_1D_size 20 +#define default_pixel_store_2D (__glXDefaultPixelStore+4) +#define default_pixel_store_2D_size 20 +#define default_pixel_store_3D (__glXDefaultPixelStore+0) +#define default_pixel_store_3D_size 36 +#define default_pixel_store_4D (__glXDefaultPixelStore+0) +#define default_pixel_store_4D_size 36 +""" + + for size in self.generic_sizes: + self.print_generic_function(size) + return + + + def printBody(self, api): + + self.pixel_stubs = {} + generated_stubs = [] + + for func in api.functionIterateGlx(): + if func.client_handcode: continue + + # If the function is a pixel function with a certain + # GLX protocol signature, create a fake stub function + # for it. For example, create a single stub function + # that is used to implement both glTexImage1D and + # glTexImage2D. + + if func.glx_rop != 0: + do_it = 0 + for image in func.get_images(): + if image.img_pad_dimensions: + do_it = 1 + break + + + if do_it: + [h, n] = hash_pixel_function(func) + + + self.pixel_stubs[ func.name ] = n + if h not in generated_stubs: + generated_stubs.append(h) + + fake_func = glx_pixel_function_stub( func, n ) + self.printFunction(fake_func, fake_func.name) + + + self.printFunction(func, func.name) + if func.glx_sop and func.glx_vendorpriv: + self.printFunction(func, func.glx_vendorpriv_names[0]) + + return + + + def printFunction(self, func, name): + footer = '}\n' + if func.glx_rop == ~0: + print 'static %s' % (func.return_type) + print '%s( unsigned opcode, unsigned dim, %s )' % (func.name, func.get_parameter_string()) + print '{' + else: + if func.has_different_protocol(name): + if func.return_type == "void": + ret_string = '' + else: + ret_string = "return " + + func_name = func.static_glx_name(name) + print '#define %s %d' % (func.opcode_vendor_name(name), func.glx_vendorpriv) + print '%s gl%s(%s)' % (func.return_type, func_name, func.get_parameter_string()) + print '{' + print ' __GLXcontext * const gc = __glXGetCurrentContext();' + print '' + print '#ifdef GLX_DIRECT_RENDERING' + print ' if (gc->driContext) {' + print ' %sCALL_%s(GET_DISPATCH(), (%s));' % (ret_string, func.name, func.get_called_parameter_string()) + print ' } else' + print '#endif' + print ' {' + + footer = '}\n}\n' + else: + print '#define %s %d' % (func.opcode_name(), func.opcode_value()) + + print '%s __indirect_gl%s(%s)' % (func.return_type, name, func.get_parameter_string()) + print '{' + + + if func.glx_rop != 0 or func.vectorequiv != None: + if len(func.images): + self.printPixelFunction(func) + else: + self.printRenderFunction(func) + elif func.glx_sop != 0 or func.glx_vendorpriv != 0: + self.printSingleFunction(func, name) + pass + else: + print "/* Missing GLX protocol for %s. */" % (name) + + print footer + return + + + def print_generic_function(self, n): + size = (n + 3) & ~3 + print """static FASTCALL NOINLINE void +generic_%u_byte( GLint rop, const void * ptr ) +{ + __GLXcontext * const gc = __glXGetCurrentContext(); + const GLuint cmdlen = %u; + + emit_header(gc->pc, rop, cmdlen); + (void) memcpy((void *)(gc->pc + 4), ptr, %u); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { (void) __glXFlushRenderBuffer(gc, gc->pc); } +} +""" % (n, size + 4, size) + return + + + def common_emit_one_arg(self, p, pc, adjust, extra_offset): + if p.is_array(): + src_ptr = p.name + else: + src_ptr = "&" + p.name + + if p.is_padding: + print '(void) memset((void *)(%s + %u), 0, %s);' \ + % (pc, p.offset + adjust, p.size_string() ) + elif not extra_offset: + print '(void) memcpy((void *)(%s + %u), (void *)(%s), %s);' \ + % (pc, p.offset + adjust, src_ptr, p.size_string() ) + else: + print '(void) memcpy((void *)(%s + %u + %s), (void *)(%s), %s);' \ + % (pc, p.offset + adjust, extra_offset, src_ptr, p.size_string() ) + + def common_emit_args(self, f, pc, adjust, skip_vla): + extra_offset = None + + for p in f.parameterIterateGlxSend( not skip_vla ): + if p.name != f.img_reset: + self.common_emit_one_arg(p, pc, adjust, extra_offset) + + if p.is_variable_length(): + temp = p.size_string() + if extra_offset: + extra_offset += " + %s" % (temp) + else: + extra_offset = temp + + return + + + def pixel_emit_args(self, f, pc, large): + """Emit the arguments for a pixel function. This differs from + common_emit_args in that pixel functions may require padding + be inserted (i.e., for the missing width field for + TexImage1D), and they may also require a 'NULL image' flag + be inserted before the image data.""" + + if large: + adjust = 8 + else: + adjust = 4 + + for param in f.parameterIterateGlxSend(): + if not param.is_image(): + self.common_emit_one_arg(param, pc, adjust, None) + + if f.pad_after(param): + print '(void) memcpy((void *)(%s + %u), zero, 4);' % (pc, (param.offset + param.size()) + adjust) + + else: + [dim, width, height, depth, extent] = param.get_dimensions() + if f.glx_rop == ~0: + dim_str = "dim" + else: + dim_str = str(dim) + + if param.is_padding: + print '(void) memset((void *)(%s + %u), 0, %s);' \ + % (pc, (param.offset - 4) + adjust, param.size_string() ) + + if param.img_null_flag: + if large: + print '(void) memcpy((void *)(%s + %u), zero, 4);' % (pc, (param.offset - 4) + adjust) + else: + print '(void) memcpy((void *)(%s + %u), (void *)((%s == NULL) ? one : zero), 4);' % (pc, (param.offset - 4) + adjust, param.name) + + + pixHeaderPtr = "%s + %u" % (pc, adjust) + pcPtr = "%s + %u" % (pc, param.offset + adjust) + + if not large: + if param.img_send_null: + condition = '(compsize > 0) && (%s != NULL)' % (param.name) + else: + condition = 'compsize > 0' + + print 'if (%s) {' % (condition) + print ' (*gc->fillImage)(gc, %s, %s, %s, %s, %s, %s, %s, %s, %s);' % (dim_str, width, height, depth, param.img_format, param.img_type, param.name, pcPtr, pixHeaderPtr) + print '} else {' + print ' (void) memcpy( %s, default_pixel_store_%uD, default_pixel_store_%uD_size );' % (pixHeaderPtr, dim, dim) + print '}' + else: + print '__glXSendLargeImage(gc, compsize, %s, %s, %s, %s, %s, %s, %s, %s, %s);' % (dim_str, width, height, depth, param.img_format, param.img_type, param.name, pcPtr, pixHeaderPtr) + + return + + + def large_emit_begin(self, f, op_name = None): + if not op_name: + op_name = f.opcode_real_name() + + print 'const GLint op = %s;' % (op_name) + print 'const GLuint cmdlenLarge = cmdlen + 4;' + print 'GLubyte * const pc = __glXFlushRenderBuffer(gc, gc->pc);' + print '(void) memcpy((void *)(pc + 0), (void *)(&cmdlenLarge), 4);' + print '(void) memcpy((void *)(pc + 4), (void *)(&op), 4);' + return + + + def common_func_print_just_start(self, f, name): + print ' __GLXcontext * const gc = __glXGetCurrentContext();' + + # The only reason that single and vendor private commands need + # a variable called 'dpy' is becuase they use the SyncHandle + # macro. For whatever brain-dead reason, that macro is hard- + # coded to use a variable called 'dpy' instead of taking a + # parameter. + + # FIXME Simplify the logic related to skip_condition and + # FIXME condition_list in this function. Basically, remove + # FIXME skip_condition, and just append the "dpy != NULL" type + # FIXME condition to condition_list from the start. The only + # FIXME reason it's done in this confusing way now is to + # FIXME minimize the diffs in the generated code. + + if not f.glx_rop: + for p in f.parameterIterateOutputs(): + if p.is_image() and (p.img_format != "GL_COLOR_INDEX" or p.img_type != "GL_BITMAP"): + print ' const __GLXattribute * const state = gc->client_state_private;' + break + + print ' Display * const dpy = gc->currentDpy;' + skip_condition = "dpy != NULL" + elif f.can_be_large: + skip_condition = "gc->currentDpy != NULL" + else: + skip_condition = None + + + if f.return_type != 'void': + print ' %s retval = (%s) 0;' % (f.return_type, f.return_type) + + + if name != None and name not in f.glx_vendorpriv_names: + print '#ifndef USE_XCB' + self.emit_packet_size_calculation(f, 0) + if name != None and name not in f.glx_vendorpriv_names: + print '#endif' + + condition_list = [] + for p in f.parameterIterateCounters(): + condition_list.append( "%s >= 0" % (p.name) ) + # 'counter' parameters cannot be negative + print " if (%s < 0) {" % p.name + print " __glXSetError(gc, GL_INVALID_VALUE);" + if f.return_type != 'void': + print " return 0;" + else: + print " return;" + print " }" + + if skip_condition: + condition_list.append( skip_condition ) + + if len( condition_list ) > 0: + if len( condition_list ) > 1: + skip_condition = "(%s)" % (string.join( condition_list, ") && (" )) + else: + skip_condition = "%s" % (condition_list.pop(0)) + + print ' if (__builtin_expect(%s, 1)) {' % (skip_condition) + return 1 + else: + return 0 + + + def printSingleFunction(self, f, name): + self.common_func_print_just_start(f, name) + + if self.debug: + print ' printf( "Enter %%s...\\n", "gl%s" );' % (f.name) + + if name not in f.glx_vendorpriv_names: + + # XCB specific: + print '#ifdef USE_XCB' + if self.debug: + print ' printf("\\tUsing XCB.\\n");' + print ' xcb_connection_t *c = XGetXCBConnection(dpy);' + print ' (void) __glXFlushRenderBuffer(gc, gc->pc);' + xcb_name = 'xcb_glx%s' % convertStringForXCB(name) + + iparams=[] + extra_iparams = [] + output = None + for p in f.parameterIterator(): + if p.is_output: + output = p + + if p.is_image(): + if p.img_format != "GL_COLOR_INDEX" or p.img_type != "GL_BITMAP": + extra_iparams.append("state->storePack.swapEndian") + else: + extra_iparams.append("0") + + # Hardcode this in. lsb_first param (apparently always GL_FALSE) + # also present in GetPolygonStipple, but taken care of above. + if xcb_name == "xcb_glx_read_pixels": + extra_iparams.append("0") + else: + iparams.append(p.name) + + + xcb_request = '%s(%s)' % (xcb_name, ", ".join(["c", "gc->currentContextTag"] + iparams + extra_iparams)) + + if f.needs_reply(): + print ' %s_reply_t *reply = %s_reply(c, %s, NULL);' % (xcb_name, xcb_name, xcb_request) + if output and f.reply_always_array: + print ' (void)memcpy(%s, %s_data(reply), %s_data_length(reply) * sizeof(%s));' % (output.name, xcb_name, xcb_name, output.get_base_type_string()) + + elif output and not f.reply_always_array: + if not output.is_image(): + print ' if (%s_data_length(reply) == 0)' % (xcb_name) + print ' (void)memcpy(%s, &reply->datum, sizeof(reply->datum));' % (output.name) + print ' else' + print ' (void)memcpy(%s, %s_data(reply), %s_data_length(reply) * sizeof(%s));' % (output.name, xcb_name, xcb_name, output.get_base_type_string()) + + + if f.return_type != 'void': + print ' retval = reply->ret_val;' + print ' free(reply);' + else: + print ' ' + xcb_request + ';' + print '#else' + # End of XCB specific. + + + if f.parameters != []: + pc_decl = "GLubyte const * pc =" + else: + pc_decl = "(void)" + + if name in f.glx_vendorpriv_names: + print ' %s __glXSetupVendorRequest(gc, %s, %s, cmdlen);' % (pc_decl, f.opcode_real_name(), f.opcode_vendor_name(name)) + else: + print ' %s __glXSetupSingleRequest(gc, %s, cmdlen);' % (pc_decl, f.opcode_name()) + + self.common_emit_args(f, "pc", 0, 0) + + images = f.get_images() + + for img in images: + if img.is_output: + o = f.command_fixed_length() - 4 + print ' *(int32_t *)(pc + %u) = 0;' % (o) + if img.img_format != "GL_COLOR_INDEX" or img.img_type != "GL_BITMAP": + print ' * (int8_t *)(pc + %u) = state->storePack.swapEndian;' % (o) + + if f.img_reset: + print ' * (int8_t *)(pc + %u) = %s;' % (o + 1, f.img_reset) + + + return_name = '' + if f.needs_reply(): + if f.return_type != 'void': + return_name = " retval" + return_str = " retval = (%s)" % (f.return_type) + else: + return_str = " (void)" + + got_reply = 0 + + for p in f.parameterIterateOutputs(): + if p.is_image(): + [dim, w, h, d, junk] = p.get_dimensions() + if f.dimensions_in_reply: + print " __glXReadPixelReply(dpy, gc, %u, 0, 0, 0, %s, %s, %s, GL_TRUE);" % (dim, p.img_format, p.img_type, p.name) + else: + print " __glXReadPixelReply(dpy, gc, %u, %s, %s, %s, %s, %s, %s, GL_FALSE);" % (dim, w, h, d, p.img_format, p.img_type, p.name) + + got_reply = 1 + else: + if f.reply_always_array: + aa = "GL_TRUE" + else: + aa = "GL_FALSE" + + # gl_parameter.size() returns the size + # of the entire data item. If the + # item is a fixed-size array, this is + # the size of the whole array. This + # is not what __glXReadReply wants. It + # wants the size of a single data + # element in the reply packet. + # Dividing by the array size (1 for + # non-arrays) gives us this. + + s = p.size() / p.get_element_count() + print " %s __glXReadReply(dpy, %s, %s, %s);" % (return_str, s, p.name, aa) + got_reply = 1 + + + # If a reply wasn't read to fill an output parameter, + # read a NULL reply to get the return value. + + if not got_reply: + print " %s __glXReadReply(dpy, 0, NULL, GL_FALSE);" % (return_str) + + + elif self.debug: + # Only emit the extra glFinish call for functions + # that don't already require a reply from the server. + print ' __indirect_glFinish();' + + if self.debug: + print ' printf( "Exit %%s.\\n", "gl%s" );' % (name) + + + print ' UnlockDisplay(dpy); SyncHandle();' + + if name not in f.glx_vendorpriv_names: + print '#endif /* USE_XCB */' + + print ' }' + print ' return%s;' % (return_name) + return + + + def printPixelFunction(self, f): + if self.pixel_stubs.has_key( f.name ): + # Normally gl_function::get_parameter_string could be + # used. However, this call needs to have the missing + # dimensions (e.g., a fake height value for + # glTexImage1D) added in. + + p_string = "" + for param in f.parameterIterateGlxSend(): + if param.is_padding: + continue + + p_string += ", " + param.name + + if param.is_image(): + [dim, junk, junk, junk, junk] = param.get_dimensions() + + if f.pad_after(param): + p_string += ", 1" + + print ' %s(%s, %u%s );' % (self.pixel_stubs[f.name] , f.opcode_name(), dim, p_string) + return + + + if self.common_func_print_just_start(f, None): + trailer = " }" + else: + trailer = None + + + if f.can_be_large: + print 'if (cmdlen <= gc->maxSmallRenderCommandSize) {' + print ' if ( (gc->pc + cmdlen) > gc->bufEnd ) {' + print ' (void) __glXFlushRenderBuffer(gc, gc->pc);' + print ' }' + + if f.glx_rop == ~0: + opcode = "opcode" + else: + opcode = f.opcode_real_name() + + print 'emit_header(gc->pc, %s, cmdlen);' % (opcode) + + self.pixel_emit_args( f, "gc->pc", 0 ) + print 'gc->pc += cmdlen;' + print 'if (gc->pc > gc->limit) { (void) __glXFlushRenderBuffer(gc, gc->pc); }' + + if f.can_be_large: + print '}' + print 'else {' + + self.large_emit_begin(f, opcode) + self.pixel_emit_args(f, "pc", 1) + + print '}' + + if trailer: print trailer + return + + + def printRenderFunction(self, f): + # There is a class of GL functions that take a single pointer + # as a parameter. This pointer points to a fixed-size chunk + # of data, and the protocol for this functions is very + # regular. Since they are so regular and there are so many + # of them, special case them with generic functions. On + # x86, this saves about 26KB in the libGL.so binary. + + if f.variable_length_parameter() == None and len(f.parameters) == 1: + p = f.parameters[0] + if p.is_pointer(): + cmdlen = f.command_fixed_length() + if cmdlen in self.generic_sizes: + print ' generic_%u_byte( %s, %s );' % (cmdlen, f.opcode_real_name(), p.name) + return + + if self.common_func_print_just_start(f, None): + trailer = " }" + else: + trailer = None + + if self.debug: + print 'printf( "Enter %%s...\\n", "gl%s" );' % (f.name) + + if f.can_be_large: + print 'if (cmdlen <= gc->maxSmallRenderCommandSize) {' + print ' if ( (gc->pc + cmdlen) > gc->bufEnd ) {' + print ' (void) __glXFlushRenderBuffer(gc, gc->pc);' + print ' }' + + print 'emit_header(gc->pc, %s, cmdlen);' % (f.opcode_real_name()) + + self.common_emit_args(f, "gc->pc", 4, 0) + print 'gc->pc += cmdlen;' + print 'if (__builtin_expect(gc->pc > gc->limit, 0)) { (void) __glXFlushRenderBuffer(gc, gc->pc); }' + + if f.can_be_large: + print '}' + print 'else {' + + self.large_emit_begin(f) + self.common_emit_args(f, "pc", 8, 1) + + p = f.variable_length_parameter() + print ' __glXSendLargeCommand(gc, pc, %u, %s, %s);' % (p.offset + 8, p.name, p.size_string()) + print '}' + + if self.debug: + print '__indirect_glFinish();' + print 'printf( "Exit %%s.\\n", "gl%s" );' % (f.name) + + if trailer: print trailer + return + + +class PrintGlxProtoInit_c(gl_XML.gl_print_base): + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + self.name = "glX_proto_send.py (from Mesa)" + self.license = license.bsd_license_template % ( \ +"""Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. +(C) Copyright IBM Corporation 2004""", "PRECISION INSIGHT, IBM") + return + + + def printRealHeader(self): + print """/** + * \\file indirect_init.c + * Initialize indirect rendering dispatch table. + * + * \\author Kevin E. Martin + * \\author Brian Paul + * \\author Ian Romanick + */ + +#include "indirect_init.h" +#include "indirect.h" +#include "glapi.h" + + +/** + * No-op function used to initialize functions that have no GLX protocol + * support. + */ +static int NoOp(void) +{ + return 0; +} + +/** + * Create and initialize a new GL dispatch table. The table is initialized + * with GLX indirect rendering protocol functions. + */ +__GLapi * __glXNewIndirectAPI( void ) +{ + __GLapi *glAPI; + GLuint entries; + + entries = _glapi_get_dispatch_table_size(); + glAPI = (__GLapi *) Xmalloc(entries * sizeof(void *)); + + /* first, set all entries to point to no-op functions */ + { + int i; + void **dispatch = (void **) glAPI; + for (i = 0; i < entries; i++) { + dispatch[i] = (void *) NoOp; + } + } + + /* now, initialize the entries we understand */""" + + def printRealFooter(self): + print """ + return glAPI; +} +""" + return + + + def printBody(self, api): + for [name, number] in api.categoryIterate(): + if number != None: + preamble = '\n /* %3u. %s */\n\n' % (int(number), name) + else: + preamble = '\n /* %s */\n\n' % (name) + + for func in api.functionIterateByCategory(name): + if func.client_supported_for_indirect(): + print '%s glAPI->%s = __indirect_gl%s;' % (preamble, func.name, func.name) + preamble = '' + + return + + +class PrintGlxProtoInit_h(gl_XML.gl_print_base): + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + self.name = "glX_proto_send.py (from Mesa)" + self.license = license.bsd_license_template % ( \ +"""Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. +(C) Copyright IBM Corporation 2004""", "PRECISION INSIGHT, IBM") + self.header_tag = "_INDIRECT_H_" + + self.last_category = "" + return + + + def printRealHeader(self): + print """/** + * \\file + * Prototypes for indirect rendering functions. + * + * \\author Kevin E. Martin + * \\author Ian Romanick + */ +""" + self.printVisibility( "HIDDEN", "hidden" ) + self.printFastcall() + self.printNoinline() + + print """ +#include "glxclient.h" + +extern HIDDEN NOINLINE CARD32 __glXReadReply( Display *dpy, size_t size, + void * dest, GLboolean reply_is_always_array ); + +extern HIDDEN NOINLINE void __glXReadPixelReply( Display *dpy, + __GLXcontext * gc, unsigned max_dim, GLint width, GLint height, + GLint depth, GLenum format, GLenum type, void * dest, + GLboolean dimensions_in_reply ); + +extern HIDDEN NOINLINE FASTCALL GLubyte * __glXSetupSingleRequest( + __GLXcontext * gc, GLint sop, GLint cmdlen ); + +extern HIDDEN NOINLINE FASTCALL GLubyte * __glXSetupVendorRequest( + __GLXcontext * gc, GLint code, GLint vop, GLint cmdlen ); +""" + + + def printBody(self, api): + for func in api.functionIterateGlx(): + params = func.get_parameter_string() + + print 'extern HIDDEN %s __indirect_gl%s(%s);' % (func.return_type, func.name, params) + + for n in func.entry_points: + if func.has_different_protocol(n): + asdf = func.static_glx_name(n) + if asdf not in func.static_entry_points: + print 'extern HIDDEN %s gl%s(%s);' % (func.return_type, asdf, params) + else: + print 'GLAPI %s GLAPIENTRY gl%s(%s);' % (func.return_type, asdf, params) + + break + + + +def show_usage(): + print "Usage: %s [-f input_file_name] [-m output_mode] [-d]" % sys.argv[0] + print " -m output_mode Output mode can be one of 'proto', 'init_c' or 'init_h'." + print " -d Enable extra debug information in the generated code." + sys.exit(1) + + +if __name__ == '__main__': + file_name = "gl_API.xml" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:m:d") + except Exception,e: + show_usage() + + debug = 0 + mode = "proto" + for (arg,val) in args: + if arg == "-f": + file_name = val + elif arg == "-m": + mode = val + elif arg == "-d": + debug = 1 + + if mode == "proto": + printer = PrintGlxProtoStubs() + elif mode == "init_c": + printer = PrintGlxProtoInit_c() + elif mode == "init_h": + printer = PrintGlxProtoInit_h() + else: + show_usage() + + + printer.debug = debug + api = gl_XML.parse_GL_API( file_name, glX_XML.glx_item_factory() ) + + printer.Print( api ) diff --git a/src/mesa/glapi/gen/glX_proto_size.py b/src/mesa/glapi/gen/glX_proto_size.py new file mode 100644 index 00000000000..95cb5110cc3 --- /dev/null +++ b/src/mesa/glapi/gen/glX_proto_size.py @@ -0,0 +1,704 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004, 2005 +# 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 +# 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. +# +# Authors: +# Ian Romanick + +import gl_XML, glX_XML +import license +import sys, getopt, copy, string + + +class glx_enum_function: + def __init__(self, func_name, enum_dict): + self.name = func_name + self.mode = 1 + self.sig = None + + # "enums" is a set of lists. The element in the set is the + # value of the enum. The list is the list of names for that + # value. For example, [0x8126] = {"POINT_SIZE_MIN", + # "POINT_SIZE_MIN_ARB", "POINT_SIZE_MIN_EXT", + # "POINT_SIZE_MIN_SGIS"}. + + self.enums = {} + + # "count" is indexed by count values. Each element of count + # is a list of index to "enums" that have that number of + # associated data elements. For example, [4] = + # {GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION, + # GL_AMBIENT_AND_DIFFUSE} (the enum names are used here, + # but the actual hexadecimal values would be in the array). + + self.count = {} + + + # Fill self.count and self.enums using the dictionary of enums + # that was passed in. The generic Get functions (e.g., + # GetBooleanv and friends) are handled specially here. In + # the data the generic Get functions are refered to as "Get". + + if func_name in ["GetIntegerv", "GetBooleanv", "GetFloatv", "GetDoublev"]: + match_name = "Get" + else: + match_name = func_name + + mode_set = 0 + for enum_name in enum_dict: + e = enum_dict[ enum_name ] + + if e.functions.has_key( match_name ): + [count, mode] = e.functions[ match_name ] + + if mode_set and mode != self.mode: + raise RuntimeError("Not all enums for %s have the same mode." % (func_name)) + + self.mode = mode + + if self.enums.has_key( e.value ): + if e.name not in self.enums[ e.value ]: + self.enums[ e.value ].append( e ) + else: + if not self.count.has_key( count ): + self.count[ count ] = [] + + self.enums[ e.value ] = [ e ] + self.count[ count ].append( e.value ) + + + return + + + def signature( self ): + if self.sig == None: + self.sig = "" + for i in self.count: + if i == None: + raise RuntimeError("i is None. WTF?") + + self.count[i].sort() + for e in self.count[i]: + self.sig += "%04x,%d," % (e, i) + + return self.sig + + + def is_set( self ): + return self.mode + + + def PrintUsingTable(self): + """Emit the body of the __gl*_size function using a pair + of look-up tables and a mask. The mask is calculated such + that (e & mask) is unique for all the valid values of e for + this function. The result of (e & mask) is used as an index + into the first look-up table. If it matches e, then the + same entry of the second table is returned. Otherwise zero + is returned. + + It seems like this should cause better code to be generated. + However, on x86 at least, the resulting .o file is about 20% + larger then the switch-statment version. I am leaving this + code in because the results may be different on other + platforms (e.g., PowerPC or x86-64).""" + + return 0 + count = 0 + for a in self.enums: + count += 1 + + if self.count.has_key(-1): + return 0 + + # Determine if there is some mask M, such that M = (2^N) - 1, + # that will generate unique values for all of the enums. + + mask = 0 + for i in [1, 2, 3, 4, 5, 6, 7, 8]: + mask = (1 << i) - 1 + + fail = 0; + for a in self.enums: + for b in self.enums: + if a != b: + if (a & mask) == (b & mask): + fail = 1; + + if not fail: + break; + else: + mask = 0 + + if (mask != 0) and (mask < (2 * count)): + masked_enums = {} + masked_count = {} + + for i in range(0, mask + 1): + masked_enums[i] = "0"; + masked_count[i] = 0; + + for c in self.count: + for e in self.count[c]: + i = e & mask + enum_obj = self.enums[e][0] + masked_enums[i] = '0x%04x /* %s */' % (e, enum_obj.name ) + masked_count[i] = c + + + print ' static const GLushort a[%u] = {' % (mask + 1) + for e in masked_enums: + print ' %s, ' % (masked_enums[e]) + print ' };' + + print ' static const GLubyte b[%u] = {' % (mask + 1) + for c in masked_count: + print ' %u, ' % (masked_count[c]) + print ' };' + + print ' const unsigned idx = (e & 0x%02xU);' % (mask) + print '' + print ' return (e == a[idx]) ? (GLint) b[idx] : 0;' + return 1; + else: + return 0; + + + def PrintUsingSwitch(self, name): + """Emit the body of the __gl*_size function using a + switch-statement.""" + + print ' switch( e ) {' + + for c in self.count: + for e in self.count[c]: + first = 1 + + # There may be multiple enums with the same + # value. This happens has extensions are + # promoted from vendor-specific or EXT to + # ARB and to the core. Emit the first one as + # a case label, and emit the others as + # commented-out case labels. + + list = {} + for enum_obj in self.enums[e]: + list[ enum_obj.priority() ] = enum_obj.name + + keys = list.keys() + keys.sort() + for k in keys: + j = list[k] + if first: + print ' case GL_%s:' % (j) + first = 0 + else: + print '/* case GL_%s:*/' % (j) + + if c == -1: + print ' return __gl%s_variable_size( e );' % (name) + else: + print ' return %u;' % (c) + + print ' default: return 0;' + print ' }' + + + def Print(self, name): + print 'INTERNAL PURE FASTCALL GLint' + print '__gl%s_size( GLenum e )' % (name) + print '{' + + if not self.PrintUsingTable(): + self.PrintUsingSwitch(name) + + print '}' + print '' + + +class glx_server_enum_function(glx_enum_function): + def __init__(self, func, enum_dict): + glx_enum_function.__init__(self, func.name, enum_dict) + + self.function = func + return + + + def signature( self ): + if self.sig == None: + sig = glx_enum_function.signature(self) + + p = self.function.variable_length_parameter() + if p: + sig += "%u" % (p.size()) + + self.sig = sig + + return self.sig; + + + def Print(self, name, printer): + f = self.function + printer.common_func_print_just_header( f ) + + fixup = [] + + foo = {} + for param_name in f.count_parameter_list: + o = f.offset_of( param_name ) + foo[o] = param_name + + for param_name in f.counter_list: + o = f.offset_of( param_name ) + foo[o] = param_name + + keys = foo.keys() + keys.sort() + for o in keys: + p = f.parameters_by_name[ foo[o] ] + + printer.common_emit_one_arg(p, "pc", 0) + fixup.append( p.name ) + + + print ' GLsizei compsize;' + print '' + + printer.common_emit_fixups(fixup) + + print '' + print ' compsize = __gl%s_size(%s);' % (f.name, string.join(f.count_parameter_list, ",")) + p = f.variable_length_parameter() + print ' return __GLX_PAD(%s);' % (p.size_string()) + + print '}' + print '' + + +class PrintGlxSizeStubs_common(gl_XML.gl_print_base): + do_get = (1 << 0) + do_set = (1 << 1) + + def __init__(self, which_functions): + gl_XML.gl_print_base.__init__(self) + + self.name = "glX_proto_size.py (from Mesa)" + self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2004", "IBM") + + self.emit_set = ((which_functions & PrintGlxSizeStubs_common.do_set) != 0) + self.emit_get = ((which_functions & PrintGlxSizeStubs_common.do_get) != 0) + return + + +class PrintGlxSizeStubs_c(PrintGlxSizeStubs_common): + def printRealHeader(self): + print '' + print '#include ' + if self.emit_get: + print '#include "indirect_size_get.h"' + print '#include "glxserver.h"' + print '#include "indirect_util.h"' + + print '#include "indirect_size.h"' + + print '' + self.printPure() + print '' + self.printFastcall() + print '' + self.printVisibility( "INTERNAL", "internal" ) + print '' + print '' + print '#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__APPLE__)' + print '# undef HAVE_ALIAS' + print '#endif' + print '#ifdef HAVE_ALIAS' + print '# define ALIAS2(from,to) \\' + print ' INTERNAL PURE FASTCALL GLint __gl ## from ## _size( GLenum e ) \\' + print ' __attribute__ ((alias( # to )));' + print '# define ALIAS(from,to) ALIAS2( from, __gl ## to ## _size )' + print '#else' + print '# define ALIAS(from,to) \\' + print ' INTERNAL PURE FASTCALL GLint __gl ## from ## _size( GLenum e ) \\' + print ' { return __gl ## to ## _size( e ); }' + print '#endif' + print '' + print '' + + + def printBody(self, api): + enum_sigs = {} + aliases = [] + + for func in api.functionIterateGlx(): + ef = glx_enum_function( func.name, api.enums_by_name ) + if len(ef.enums) == 0: + continue + + if (ef.is_set() and self.emit_set) or (not ef.is_set() and self.emit_get): + sig = ef.signature() + if enum_sigs.has_key( sig ): + aliases.append( [func.name, enum_sigs[ sig ]] ) + else: + enum_sigs[ sig ] = func.name + ef.Print( func.name ) + + + for [alias_name, real_name] in aliases: + print 'ALIAS( %s, %s )' % (alias_name, real_name) + + + +class PrintGlxSizeStubs_h(PrintGlxSizeStubs_common): + def printRealHeader(self): + print """/** + * \\file + * Prototypes for functions used to determine the number of data elements in + * various GLX protocol messages. + * + * \\author Ian Romanick + */ +""" + self.printPure(); + print '' + self.printFastcall(); + print '' + self.printVisibility( "INTERNAL", "internal" ); + print '' + + + def printBody(self, api): + for func in api.functionIterateGlx(): + ef = glx_enum_function( func.name, api.enums_by_name ) + if len(ef.enums) == 0: + continue + + if (ef.is_set() and self.emit_set) or (not ef.is_set() and self.emit_get): + print 'extern INTERNAL PURE FASTCALL GLint __gl%s_size(GLenum);' % (func.name) + + +class PrintGlxReqSize_common(gl_XML.gl_print_base): + """Common base class for PrintGlxSizeReq_h and PrintGlxSizeReq_h. + + The main purpose of this common base class is to provide the infrastructure + for the derrived classes to iterate over the same set of functions. + """ + + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + self.name = "glX_proto_size.py (from Mesa)" + self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005", "IBM") + + +class PrintGlxReqSize_h(PrintGlxReqSize_common): + def __init__(self): + PrintGlxReqSize_common.__init__(self) + self.header_tag = "_INDIRECT_REQSIZE_H_" + + + def printRealHeader(self): + self.printVisibility("HIDDEN", "hidden") + print '' + self.printPure() + print '' + + + def printBody(self, api): + for func in api.functionIterateGlx(): + if not func.ignore and func.has_variable_size_request(): + print 'extern PURE HIDDEN int __glX%sReqSize(const GLbyte *pc, Bool swap);' % (func.name) + + +class PrintGlxReqSize_c(PrintGlxReqSize_common): + """Create the server-side 'request size' functions. + + Create the server-side functions that are used to determine what the + size of a varible length command should be. The server then uses + this value to determine if the incoming command packed it malformed. + """ + + def __init__(self): + PrintGlxReqSize_common.__init__(self) + self.counter_sigs = {} + + + def printRealHeader(self): + print '' + print '#include ' + print '#include "glxserver.h"' + print '#include "glxbyteorder.h"' + print '#include "indirect_size.h"' + print '#include "indirect_reqsize.h"' + print '' + print '#define __GLX_PAD(x) (((x) + 3) & ~3)' + print '' + print '#if defined(__CYGWIN__) || defined(__MINGW32__)' + print '# undef HAVE_ALIAS' + print '#endif' + print '#ifdef HAVE_ALIAS' + print '# define ALIAS2(from,to) \\' + print ' GLint __glX ## from ## ReqSize( const GLbyte * pc, Bool swap ) \\' + print ' __attribute__ ((alias( # to )));' + print '# define ALIAS(from,to) ALIAS2( from, __glX ## to ## ReqSize )' + print '#else' + print '# define ALIAS(from,to) \\' + print ' GLint __glX ## from ## ReqSize( const GLbyte * pc, Bool swap ) \\' + print ' { return __glX ## to ## ReqSize( pc, swap ); }' + print '#endif' + print '' + print '' + + + def printBody(self, api): + aliases = [] + enum_functions = {} + enum_sigs = {} + + for func in api.functionIterateGlx(): + if not func.has_variable_size_request(): continue + + ef = glx_server_enum_function( func, api.enums_by_name ) + if len(ef.enums) == 0: continue + + sig = ef.signature() + + if not enum_functions.has_key(func.name): + enum_functions[ func.name ] = sig + + if not enum_sigs.has_key( sig ): + enum_sigs[ sig ] = ef + + + + for func in api.functionIterateGlx(): + # Even though server-handcode fuctions are on "the + # list", and prototypes are generated for them, there + # isn't enough information to generate a size + # function. If there was enough information, they + # probably wouldn't need to be handcoded in the first + # place! + + if func.server_handcode: continue + if not func.has_variable_size_request(): continue + + if enum_functions.has_key(func.name): + sig = enum_functions[func.name] + ef = enum_sigs[ sig ] + + if ef.name != func.name: + aliases.append( [func.name, ef.name] ) + else: + ef.Print( func.name, self ) + + elif func.images: + self.printPixelFunction(func) + elif func.has_variable_size_request(): + a = self.printCountedFunction(func) + if a: aliases.append(a) + + + for [alias_name, real_name] in aliases: + print 'ALIAS( %s, %s )' % (alias_name, real_name) + + return + + + def common_emit_fixups(self, fixup): + """Utility function to emit conditional byte-swaps.""" + + if fixup: + print ' if (swap) {' + for name in fixup: + print ' %s = bswap_32(%s);' % (name, name) + print ' }' + + return + + + def common_emit_one_arg(self, p, pc, adjust): + offset = p.offset + dst = p.string() + src = '(%s *)' % (p.type_string()) + print '%-18s = *%11s(%s + %u);' % (dst, src, pc, offset + adjust); + return + + + def common_func_print_just_header(self, f): + print 'int' + print '__glX%sReqSize( const GLbyte * pc, Bool swap )' % (f.name) + print '{' + + + def printPixelFunction(self, f): + self.common_func_print_just_header(f) + + f.offset_of( f.parameters[0].name ) + [dim, w, h, d, junk] = f.get_images()[0].get_dimensions() + + print ' GLint row_length = * (GLint *)(pc + 4);' + + if dim < 3: + fixup = ['row_length', 'skip_rows', 'alignment'] + print ' GLint image_height = 0;' + print ' GLint skip_images = 0;' + print ' GLint skip_rows = * (GLint *)(pc + 8);' + print ' GLint alignment = * (GLint *)(pc + 16);' + else: + fixup = ['row_length', 'image_height', 'skip_rows', 'skip_images', 'alignment'] + print ' GLint image_height = * (GLint *)(pc + 8);' + print ' GLint skip_rows = * (GLint *)(pc + 16);' + print ' GLint skip_images = * (GLint *)(pc + 20);' + print ' GLint alignment = * (GLint *)(pc + 32);' + + img = f.images[0] + for p in f.parameterIterateGlxSend(): + if p.name in [w, h, d, img.img_format, img.img_type, img.img_target]: + self.common_emit_one_arg(p, "pc", 0) + fixup.append( p.name ) + + print '' + + self.common_emit_fixups(fixup) + + if img.img_null_flag: + print '' + print ' if (*(CARD32 *) (pc + %s))' % (img.offset - 4) + print ' return 0;' + + print '' + print ' return __glXImageSize(%s, %s, %s, %s, %s, %s,' % (img.img_format, img.img_type, img.img_target, w, h, d ) + print ' image_height, row_length, skip_images,' + print ' skip_rows, alignment);' + print '}' + print '' + return + + + def printCountedFunction(self, f): + + sig = "" + offset = 0 + fixup = [] + params = [] + plus = '' + size = '' + param_offsets = {} + + # Calculate the offset of each counter parameter and the + # size string for the variable length parameter(s). While + # that is being done, calculate a unique signature for this + # function. + + for p in f.parameterIterateGlxSend(): + if p.is_counter: + fixup.append( p.name ) + params.append( p ) + elif p.counter: + s = p.size() + if s == 0: s = 1 + + sig += "(%u,%u)" % (f.offset_of(p.counter), s) + size += '%s%s' % (plus, p.size_string()) + plus = ' + ' + + + # If the calculated signature matches a function that has + # already be emitted, don't emit this function. Instead, add + # it to the list of function aliases. + + if self.counter_sigs.has_key(sig): + n = self.counter_sigs[sig]; + alias = [f.name, n] + else: + alias = None + self.counter_sigs[sig] = f.name + + self.common_func_print_just_header(f) + + for p in params: + self.common_emit_one_arg(p, "pc", 0) + + + print '' + self.common_emit_fixups(fixup) + print '' + + print ' return __GLX_PAD(%s);' % (size) + print '}' + print '' + + return alias + + +def show_usage(): + print "Usage: %s [-f input_file_name] -m output_mode [--only-get | --only-set] [--get-alias-set]" % sys.argv[0] + print " -m output_mode Output mode can be one of 'size_c' or 'size_h'." + print " --only-get Only emit 'get'-type functions." + print " --only-set Only emit 'set'-type functions." + print "" + print "By default, both 'get' and 'set'-type functions are emitted." + sys.exit(1) + + +if __name__ == '__main__': + file_name = "gl_API.xml" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:m:h:", ["only-get", "only-set", "header-tag"]) + except Exception,e: + show_usage() + + mode = None + header_tag = None + which_functions = PrintGlxSizeStubs_common.do_get | PrintGlxSizeStubs_common.do_set + + for (arg,val) in args: + if arg == "-f": + file_name = val + elif arg == "-m": + mode = val + elif arg == "--only-get": + which_functions = PrintGlxSizeStubs_common.do_get + elif arg == "--only-set": + which_functions = PrintGlxSizeStubs_common.do_set + elif (arg == '-h') or (arg == "--header-tag"): + header_tag = val + + if mode == "size_c": + printer = PrintGlxSizeStubs_c( which_functions ) + elif mode == "size_h": + printer = PrintGlxSizeStubs_h( which_functions ) + if header_tag: + printer.header_tag = header_tag + elif mode == "reqsize_c": + printer = PrintGlxReqSize_c() + elif mode == "reqsize_h": + printer = PrintGlxReqSize_h() + else: + show_usage() + + api = gl_XML.parse_GL_API( file_name, glX_XML.glx_item_factory() ) + + + printer.Print( api ) diff --git a/src/mesa/glapi/gen/glX_server_table.py b/src/mesa/glapi/gen/glX_server_table.py new file mode 100644 index 00000000000..f3962f875b0 --- /dev/null +++ b/src/mesa/glapi/gen/glX_server_table.py @@ -0,0 +1,411 @@ +#!/bin/env python + +# (C) Copyright IBM Corporation 2005, 2006 +# 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 +# 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. +# +# Authors: +# Ian Romanick + +import gl_XML, glX_XML, glX_proto_common, license +import sys, getopt + + +def log2(value): + for i in range(0, 30): + p = 1 << i + if p >= value: + return i + + return -1 + + +def round_down_to_power_of_two(n): + """Returns the nearest power-of-two less than or equal to n.""" + + for i in range(30, 0, -1): + p = 1 << i + if p <= n: + return p + + return -1 + + +class function_table: + def __init__(self, name, do_size_check): + self.name_base = name + self.do_size_check = do_size_check + + + self.max_bits = 1 + self.next_opcode_threshold = (1 << self.max_bits) + self.max_opcode = 0 + + self.functions = {} + self.lookup_table = [] + + # Minimum number of opcodes in a leaf node. + self.min_op_bits = 3 + self.min_op_count = (1 << self.min_op_bits) + return + + + def append(self, opcode, func): + self.functions[opcode] = func + + if opcode > self.max_opcode: + self.max_opcode = opcode + + if opcode > self.next_opcode_threshold: + bits = log2(opcode) + if (1 << bits) <= opcode: + bits += 1 + + self.max_bits = bits + self.next_opcode_threshold = 1 << bits + return + + + def divide_group(self, min_opcode, total): + """Divide the group starting min_opcode into subgroups. + Returns a tuple containing the number of bits consumed by + the node, the list of the children's tuple, and the number + of entries in the final array used by this node and its + children, and the depth of the subtree rooted at the node.""" + + remaining_bits = self.max_bits - total + next_opcode = min_opcode + (1 << remaining_bits) + empty_children = 0 + + for M in range(0, remaining_bits): + op_count = 1 << (remaining_bits - M); + child_count = 1 << M; + + empty_children = 0 + full_children = 0 + for i in range(min_opcode, next_opcode, op_count): + used = 0 + empty = 0 + + for j in range(i, i + op_count): + if self.functions.has_key(j): + used += 1; + else: + empty += 1; + + + if empty == op_count: + empty_children += 1 + + if used == op_count: + full_children += 1 + + if (empty_children > 0) or (full_children == child_count) or (op_count <= self.min_op_count): + break + + + # If all the remaining bits are used by this node, as is the + # case when M is 0 or remaining_bits, the node is a leaf. + + if (M == 0) or (M == remaining_bits): + return [remaining_bits, [], 0, 0] + else: + children = [] + count = 1 + depth = 1 + all_children_are_nonempty_leaf_nodes = 1 + for i in range(min_opcode, next_opcode, op_count): + n = self.divide_group(i, total + M) + + if not (n[1] == [] and not self.is_empty_leaf(i, n[0])): + all_children_are_nonempty_leaf_nodes = 0 + + children.append(n) + count += n[2] + 1 + + if n[3] >= depth: + depth = n[3] + 1 + + # If all of the child nodes are non-empty leaf nodes, pull + # them up and make this node a leaf. + + if all_children_are_nonempty_leaf_nodes: + return [remaining_bits, [], 0, 0] + else: + return [M, children, count, depth] + + + def is_empty_leaf(self, base_opcode, M): + for op in range(base_opcode, base_opcode + (1 << M)): + if self.functions.has_key(op): + return 0 + break + + return 1 + + + def dump_tree(self, node, base_opcode, remaining_bits, base_entry, depth): + M = node[0] + children = node[1] + child_M = remaining_bits - M + + + # This actually an error condition. + if children == []: + return + + print ' /* [%u] -> opcode range [%u, %u], node depth %u */' % (base_entry, base_opcode, base_opcode + (1 << remaining_bits), depth) + print ' %u,' % (M) + + base_entry += (1 << M) + 1 + + child_index = base_entry + child_base_opcode = base_opcode + for child in children: + if child[1] == []: + if self.is_empty_leaf(child_base_opcode, child_M): + print ' EMPTY_LEAF,' + else: + # Emit the index of the next dispatch + # function. Then add all the + # dispatch functions for this leaf + # node to the dispatch function + # lookup table. + + print ' LEAF(%u),' % (len(self.lookup_table)) + + for op in range(child_base_opcode, child_base_opcode + (1 << child_M)): + if self.functions.has_key(op): + func = self.functions[op] + size = func.command_fixed_length() + + if func.glx_rop != 0: + size += 4 + + size = ((size + 3) & ~3) + + if func.has_variable_size_request(): + size_name = "__glX%sReqSize" % (func.name) + else: + size_name = "" + + if func.glx_vendorpriv == op: + func_name = func.glx_vendorpriv_names[0] + else: + func_name = func.name + + temp = [op, "__glXDisp_%s" % (func_name), "__glXDispSwap_%s" % (func_name), size, size_name] + else: + temp = [op, "NULL", "NULL", 0, ""] + + self.lookup_table.append(temp) + else: + print ' %u,' % (child_index) + child_index += child[2] + + child_base_opcode += 1 << child_M + + print '' + + child_index = base_entry + for child in children: + if child[1] != []: + self.dump_tree(child, base_opcode, remaining_bits - M, child_index, depth + 1) + child_index += child[2] + + base_opcode += 1 << (remaining_bits - M) + + + def Print(self): + # Each dispatch table consists of two data structures. + # + # The first structure is an N-way tree where the opcode for + # the function is the key. Each node switches on a range of + # bits from the opcode. M bits are extracted from the opcde + # and are used as an index to select one of the N, where + # N = 2^M, children. + # + # The tree is stored as a flat array. The first value is the + # number of bits, M, used by the node. For inner nodes, the + # following 2^M values are indexes into the array for the + # child nodes. For leaf nodes, the followign 2^M values are + # indexes into the second data structure. + # + # If an inner node's child index is 0, the child is an empty + # leaf node. That is, none of the opcodes selectable from + # that child exist. Since most of the possible opcode space + # is unused, this allows compact data storage. + # + # The second data structure is an array of pairs of function + # pointers. Each function contains a pointer to a protocol + # decode function and a pointer to a byte-swapped protocol + # decode function. Elements in this array are selected by the + # leaf nodes of the first data structure. + # + # As the tree is traversed, an accumulator is kept. This + # accumulator counts the bits of the opcode consumed by the + # traversal. When accumulator + M = B, where B is the + # maximum number of bits in an opcode, the traversal has + # reached a leaf node. The traversal starts with the most + # significant bits and works down to the least significant + # bits. + # + # Creation of the tree is the most complicated part. At + # each node the elements are divided into groups of 2^M + # elements. The value of M selected is the smallest possible + # value where all of the groups are either empty or full, or + # the groups are a preset minimum size. If all the children + # of a node are non-empty leaf nodes, the children are merged + # to create a single leaf node that replaces the parent. + + tree = self.divide_group(0, 0) + + print '/*****************************************************************/' + print '/* tree depth = %u */' % (tree[3]) + print 'static const int_fast16_t %s_dispatch_tree[%u] = {' % (self.name_base, tree[2]) + self.dump_tree(tree, 0, self.max_bits, 0, 1) + print '};\n' + + # After dumping the tree, dump the function lookup table. + + print 'static const void *%s_function_table[%u][2] = {' % (self.name_base, len(self.lookup_table)) + index = 0 + for func in self.lookup_table: + opcode = func[0] + name = func[1] + name_swap = func[2] + + print ' /* [% 3u] = %5u */ {%s, %s},' % (index, opcode, name, name_swap) + + index += 1 + + print '};\n' + + if self.do_size_check: + var_table = [] + + print 'static const int_fast16_t %s_size_table[%u][2] = {' % (self.name_base, len(self.lookup_table)) + index = 0 + var_table = [] + for func in self.lookup_table: + opcode = func[0] + fixed = func[3] + var = func[4] + + if var != "": + var_offset = "%2u" % (len(var_table)) + var_table.append(var) + else: + var_offset = "~0" + + print ' /* [%3u] = %5u */ {%3u, %s},' % (index, opcode, fixed, var_offset) + index += 1 + + + print '};\n' + + + print 'static const gl_proto_size_func %s_size_func_table[%u] = {' % (self.name_base, len(var_table)) + for func in var_table: + print ' %s,' % (func) + + print '};\n' + + + print 'const struct __glXDispatchInfo %s_dispatch_info = {' % (self.name_base) + print ' %u,' % (self.max_bits) + print ' %s_dispatch_tree,' % (self.name_base) + print ' %s_function_table,' % (self.name_base) + if self.do_size_check: + print ' %s_size_table,' % (self.name_base) + print ' %s_size_func_table' % (self.name_base) + else: + print ' NULL,' + print ' NULL' + print '};\n' + return + + +class PrintGlxDispatchTables(glX_proto_common.glx_print_proto): + def __init__(self): + gl_XML.gl_print_base.__init__(self) + self.name = "glX_server_table.py (from Mesa)" + self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005, 2006", "IBM") + + self.rop_functions = function_table("Render", 1) + self.sop_functions = function_table("Single", 0) + self.vop_functions = function_table("VendorPriv", 0) + return + + + def printRealHeader(self): + print '#include ' + print '#include "glxserver.h"' + print '#include "glxext.h"' + print '#include "indirect_dispatch.h"' + print '#include "indirect_reqsize.h"' + print '#include "g_disptab.h"' + print '#include "indirect_table.h"' + print '' + return + + + def printBody(self, api): + for f in api.functionIterateAll(): + if not f.ignore and f.vectorequiv == None: + if f.glx_rop != 0: + self.rop_functions.append(f.glx_rop, f) + if f.glx_sop != 0: + self.sop_functions.append(f.glx_sop, f) + if f.glx_vendorpriv != 0: + self.vop_functions.append(f.glx_vendorpriv, f) + + self.sop_functions.Print() + self.rop_functions.Print() + self.vop_functions.Print() + return + + +if __name__ == '__main__': + file_name = "gl_API.xml" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:m") + except Exception,e: + show_usage() + + mode = "table_c" + for (arg,val) in args: + if arg == "-f": + file_name = val + elif arg == "-m": + mode = val + + if mode == "table_c": + printer = PrintGlxDispatchTables() + else: + show_usage() + + + api = gl_XML.parse_GL_API( file_name, glX_XML.glx_item_factory() ) + + + printer.Print( api ) diff --git a/src/mesa/glapi/gen/gl_API.dtd b/src/mesa/glapi/gen/gl_API.dtd new file mode 100644 index 00000000000..30c646c9244 --- /dev/null +++ b/src/mesa/glapi/gen/gl_API.dtd @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mesa/glapi/gen/gl_API.xml b/src/mesa/glapi/gen/gl_API.xml new file mode 100644 index 00000000000..fbf8b0c3e4a --- /dev/null +++ b/src/mesa/glapi/gen/gl_API.xml @@ -0,0 +1,12505 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mesa/glapi/gen/gl_SPARC_asm.py b/src/mesa/glapi/gen/gl_SPARC_asm.py new file mode 100644 index 00000000000..33e752df38c --- /dev/null +++ b/src/mesa/glapi/gen/gl_SPARC_asm.py @@ -0,0 +1,275 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004 +# 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 +# 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. +# +# Authors: +# Ian Romanick + +import license +import gl_XML, glX_XML +import sys, getopt + +class PrintGenericStubs(gl_XML.gl_print_base): + def __init__(self): + gl_XML.gl_print_base.__init__(self) + self.name = "gl_SPARC_asm.py (from Mesa)" + self.license = license.bsd_license_template % ( \ +"""Copyright (C) 1999-2003 Brian Paul All Rights Reserved. +(C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM") + + + def printRealHeader(self): + print '#include "glapi/glapioffsets.h"' + print '' + print '#ifdef __arch64__' + print '#define GL_OFF(N)\t((N) * 8)' + print '#define GL_LL\t\tldx' + print '#define GL_TIE_LD(SYM)\t%tie_ldx(SYM)' + print '#define GL_STACK_SIZE\t128' + print '#else' + print '#define GL_OFF(N)\t((N) * 4)' + print '#define GL_LL\t\tld' + print '#define GL_TIE_LD(SYM)\t%tie_ld(SYM)' + print '#define GL_STACK_SIZE\t64' + print '#endif' + print '' + print '#define GLOBL_FN(x) .globl x ; .type x, @function' + print '#define HIDDEN(x) .hidden x' + print '' + print '\t.register %g2, #scratch' + print '\t.register %g3, #scratch' + print '' + print '\t.text' + print '' + print '\tGLOBL_FN(__glapi_sparc_icache_flush)' + print '\tHIDDEN(__glapi_sparc_icache_flush)' + print '\t.type\t__glapi_sparc_icache_flush, @function' + print '__glapi_sparc_icache_flush: /* %o0 = insn_addr */' + print '\tflush\t%o0' + print '\tretl' + print '\t nop' + print '' + print '\t.align\t32' + print '' + print '\t.type\t__glapi_sparc_get_pc, @function' + print '__glapi_sparc_get_pc:' + print '\tretl' + print '\t add\t%o7, %g2, %g2' + print '\t.size\t__glapi_sparc_get_pc, .-__glapi_sparc_get_pc' + print '' + print '#ifdef GLX_USE_TLS' + print '' + print '\tGLOBL_FN(__glapi_sparc_get_dispatch)' + print '\tHIDDEN(__glapi_sparc_get_dispatch)' + print '__glapi_sparc_get_dispatch:' + print '\tmov\t%o7, %g1' + print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2' + print '\tcall\t__glapi_sparc_get_pc' + print '\tadd\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2' + print '\tmov\t%g1, %o7' + print '\tsethi\t%tie_hi22(_glapi_tls_Dispatch), %g1' + print '\tadd\t%g1, %tie_lo10(_glapi_tls_Dispatch), %g1' + print '\tGL_LL\t[%g2 + %g1], %g2, GL_TIE_LD(_glapi_tls_Dispatch)' + print '\tretl' + print '\t mov\t%g2, %o0' + print '' + print '\t.data' + print '\t.align\t32' + print '' + print '\t/* --> sethi %hi(_glapi_tls_Dispatch), %g1 */' + print '\t/* --> or %g1, %lo(_glapi_tls_Dispatch), %g1 */' + print '\tGLOBL_FN(__glapi_sparc_tls_stub)' + print '\tHIDDEN(__glapi_sparc_tls_stub)' + print '__glapi_sparc_tls_stub: /* Call offset in %g3 */' + print '\tmov\t%o7, %g1' + print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2' + print '\tcall\t__glapi_sparc_get_pc' + print '\tadd\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2' + print '\tmov\t%g1, %o7' + print '\tsrl\t%g3, 10, %g3' + print '\tsethi\t%tie_hi22(_glapi_tls_Dispatch), %g1' + print '\tadd\t%g1, %tie_lo10(_glapi_tls_Dispatch), %g1' + print '\tGL_LL\t[%g2 + %g1], %g2, GL_TIE_LD(_glapi_tls_Dispatch)' + print '\tGL_LL\t[%g7+%g2], %g1' + print '\tGL_LL\t[%g1 + %g3], %g1' + print '\tjmp\t%g1' + print '\t nop' + print '\t.size\t__glapi_sparc_tls_stub, .-__glapi_sparc_tls_stub' + print '' + print '#define GL_STUB(fn, off)\t\t\t\t\\' + print '\tGLOBL_FN(fn);\t\t\t\t\t\\' + print 'fn:\tba\t__glapi_sparc_tls_stub;\t\t\t\\' + print '\t sethi\tGL_OFF(off), %g3;\t\t\t\\' + print '\t.size\tfn,.-fn;' + print '' + print '#elif defined(PTHREADS)' + print '' + print '\t/* 64-bit 0x00 --> sethi %hh(_glapi_Dispatch), %g1 */' + print '\t/* 64-bit 0x04 --> sethi %lm(_glapi_Dispatch), %g2 */' + print '\t/* 64-bit 0x08 --> or %g1, %hm(_glapi_Dispatch), %g1 */' + print '\t/* 64-bit 0x0c --> sllx %g1, 32, %g1 */' + print '\t/* 64-bit 0x10 --> add %g1, %g2, %g1 */' + print '\t/* 64-bit 0x14 --> ldx [%g1 + %lo(_glapi_Dispatch)], %g1 */' + print '' + print '\t/* 32-bit 0x00 --> sethi %hi(_glapi_Dispatch), %g1 */' + print '\t/* 32-bit 0x04 --> ld [%g1 + %lo(_glapi_Dispatch)], %g1 */' + print '' + print '\t.data' + print '\t.align\t32' + print '' + print '\tGLOBL_FN(__glapi_sparc_pthread_stub)' + print '\tHIDDEN(__glapi_sparc_pthread_stub)' + print '__glapi_sparc_pthread_stub: /* Call offset in %g3 */' + print '\tmov\t%o7, %g1' + print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2' + print '\tcall\t__glapi_sparc_get_pc' + print '\t add\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2' + print '\tmov\t%g1, %o7' + print '\tsethi\t%hi(_glapi_Dispatch), %g1' + print '\tor\t%g1, %lo(_glapi_Dispatch), %g1' + print '\tsrl\t%g3, 10, %g3' + print '\tGL_LL\t[%g2+%g1], %g2' + print '\tGL_LL\t[%g2], %g1' + print '\tcmp\t%g1, 0' + print '\tbe\t2f' + print '\t nop' + print '1:\tGL_LL\t[%g1 + %g3], %g1' + print '\tjmp\t%g1' + print '\t nop' + print '2:\tsave\t%sp, GL_STACK_SIZE, %sp' + print '\tmov\t%g3, %l0' + print '\tcall\t_glapi_get_dispatch' + print '\t nop' + print '\tmov\t%o0, %g1' + print '\tmov\t%l0, %g3' + print '\tba\t1b' + print '\t restore %g0, %g0, %g0' + print '\t.size\t__glapi_sparc_pthread_stub, .-__glapi_sparc_pthread_stub' + print '' + print '#define GL_STUB(fn, off)\t\t\t\\' + print '\tGLOBL_FN(fn);\t\t\t\t\\' + print 'fn:\tba\t__glapi_sparc_pthread_stub;\t\\' + print '\t sethi\tGL_OFF(off), %g3;\t\t\\' + print '\t.size\tfn,.-fn;' + print '' + print '#else /* Non-threaded version. */' + print '' + print '\t.type __glapi_sparc_nothread_stub, @function' + print '__glapi_sparc_nothread_stub: /* Call offset in %g3 */' + print '\tmov\t%o7, %g1' + print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2' + print '\tcall\t__glapi_sparc_get_pc' + print '\t add\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2' + print '\tmov\t%g1, %o7' + print '\tsrl\t%g3, 10, %g3' + print '\tsethi\t%hi(_glapi_Dispatch), %g1' + print '\tor\t%g1, %lo(_glapi_Dispatch), %g1' + print '\tGL_LL\t[%g2+%g1], %g2' + print '\tGL_LL\t[%g2], %g1' + print '\tGL_LL\t[%g1 + %g3], %g1' + print '\tjmp\t%g1' + print '\t nop' + print '\t.size\t__glapi_sparc_nothread_stub, .-__glapi_sparc_nothread_stub' + print '' + print '#define GL_STUB(fn, off)\t\t\t\\' + print '\tGLOBL_FN(fn);\t\t\t\t\\' + print 'fn:\tba\t__glapi_sparc_nothread_stub;\t\\' + print '\t sethi\tGL_OFF(off), %g3;\t\t\\' + print '\t.size\tfn,.-fn;' + print '' + print '#endif' + print '' + print '#define GL_STUB_ALIAS(fn, alias) \\' + print ' .globl fn; \\' + print ' .set fn, alias' + print '' + print '\t.text' + print '\t.align\t32' + print '' + print '\t.globl\tgl_dispatch_functions_start' + print '\tHIDDEN(gl_dispatch_functions_start)' + print 'gl_dispatch_functions_start:' + print '' + return + + def printRealFooter(self): + print '' + print '\t.globl\tgl_dispatch_functions_end' + print '\tHIDDEN(gl_dispatch_functions_end)' + print 'gl_dispatch_functions_end:' + return + + def printBody(self, api): + for f in api.functionIterateByOffset(): + name = f.dispatch_name() + + print '\tGL_STUB(gl%s, _gloffset_%s)' % (name, f.name) + + if not f.is_static_entry_point(f.name): + print '\tHIDDEN(gl%s)' % (name) + + for f in api.functionIterateByOffset(): + name = f.dispatch_name() + + if f.is_static_entry_point(f.name): + for n in f.entry_points: + if n != f.name: + text = '\tGL_STUB_ALIAS(gl%s, gl%s)' % (n, f.name) + + if f.has_different_protocol(n): + print '#ifndef GLX_INDIRECT_RENDERING' + print text + print '#endif' + else: + print text + + return + + +def show_usage(): + print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0] + sys.exit(1) + +if __name__ == '__main__': + file_name = "gl_API.xml" + mode = "generic" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "m:f:") + except Exception,e: + show_usage() + + for (arg,val) in args: + if arg == '-m': + mode = val + elif arg == "-f": + file_name = val + + if mode == "generic": + printer = PrintGenericStubs() + else: + print "ERROR: Invalid mode \"%s\" specified." % mode + show_usage() + + api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory()) + printer.Print(api) diff --git a/src/mesa/glapi/gen/gl_XML.py b/src/mesa/glapi/gen/gl_XML.py new file mode 100644 index 00000000000..a10a35e513c --- /dev/null +++ b/src/mesa/glapi/gen/gl_XML.py @@ -0,0 +1,967 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004, 2005 +# 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 +# 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. +# +# Authors: +# Ian Romanick + +import libxml2 +import re, sys, string +import typeexpr + + +def parse_GL_API( file_name, factory = None ): + doc = libxml2.readFile( file_name, None, libxml2.XML_PARSE_XINCLUDE + libxml2.XML_PARSE_NOBLANKS + libxml2.XML_PARSE_DTDVALID + libxml2.XML_PARSE_DTDATTR + libxml2.XML_PARSE_DTDLOAD + libxml2.XML_PARSE_NOENT ) + ret = doc.xincludeProcess() + + if not factory: + factory = gl_item_factory() + + api = factory.create_item( "api", None, None ) + api.process_element( doc ) + + # After the XML has been processed, we need to go back and assign + # dispatch offsets to the functions that request that their offsets + # be assigned by the scripts. Typically this means all functions + # that are not part of the ABI. + + for func in api.functionIterateByCategory(): + if func.assign_offset: + func.offset = api.next_offset; + api.next_offset += 1 + + doc.freeDoc() + + return api + + +def is_attr_true( element, name ): + """Read a name value from an element's attributes. + + The value read from the attribute list must be either 'true' or + 'false'. If the value is 'false', zero will be returned. If the + value is 'true', non-zero will be returned. An exception will be + raised for any other value.""" + + value = element.nsProp( name, None ) + if value == "true": + return 1 + elif value == "false": + return 0 + else: + raise RuntimeError('Invalid value "%s" for boolean "%s".' % (value, name)) + + +class gl_print_base: + """Base class of all API pretty-printers. + + In the model-view-controller pattern, this is the view. Any derived + class will want to over-ride the printBody, printRealHader, and + printRealFooter methods. Some derived classes may want to over-ride + printHeader and printFooter, or even Print (though this is unlikely). + """ + + def __init__(self): + # Name of the script that is generating the output file. + # Every derived class should set this to the name of its + # source file. + + self.name = "a" + + + # License on the *generated* source file. This may differ + # from the license on the script that is generating the file. + # Every derived class should set this to some reasonable + # value. + # + # See license.py for an example of a reasonable value. + + self.license = "The license for this file is unspecified." + + + # The header_tag is the name of the C preprocessor define + # used to prevent multiple inclusion. Typically only + # generated C header files need this to be set. Setting it + # causes code to be generated automatically in printHeader + # and printFooter. + + self.header_tag = None + + + # List of file-private defines that must be undefined at the + # end of the file. This can be used in header files to define + # names for use in the file, then undefine them at the end of + # the header file. + + self.undef_list = [] + return + + + def Print(self, api): + self.printHeader() + self.printBody(api) + self.printFooter() + return + + + def printHeader(self): + """Print the header associated with all files and call the printRealHeader method.""" + + print '/* DO NOT EDIT - This file generated automatically by %s script */' \ + % (self.name) + print '' + print '/*' + print ' * ' + self.license.replace('\n', '\n * ') + print ' */' + print '' + if self.header_tag: + print '#if !defined( %s )' % (self.header_tag) + print '# define %s' % (self.header_tag) + print '' + self.printRealHeader(); + return + + + def printFooter(self): + """Print the header associated with all files and call the printRealFooter method.""" + + self.printRealFooter() + + if self.undef_list: + print '' + for u in self.undef_list: + print "# undef %s" % (u) + + if self.header_tag: + print '' + print '#endif /* !defined( %s ) */' % (self.header_tag) + + + def printRealHeader(self): + """Print the "real" header for the created file. + + In the base class, this function is empty. All derived + classes should over-ride this function.""" + return + + + def printRealFooter(self): + """Print the "real" footer for the created file. + + In the base class, this function is empty. All derived + classes should over-ride this function.""" + return + + + def printPure(self): + """Conditionally define `PURE' function attribute. + + Conditionally defines a preprocessor macro `PURE' that wraps + GCC's `pure' function attribute. The conditional code can be + easilly adapted to other compilers that support a similar + feature. + + The name is also added to the file's undef_list. + """ + self.undef_list.append("PURE") + print """# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) +# define PURE __attribute__((pure)) +# else +# define PURE +# endif""" + return + + + def printFastcall(self): + """Conditionally define `FASTCALL' function attribute. + + Conditionally defines a preprocessor macro `FASTCALL' that + wraps GCC's `fastcall' function attribute. The conditional + code can be easilly adapted to other compilers that support a + similar feature. + + The name is also added to the file's undef_list. + """ + + self.undef_list.append("FASTCALL") + print """# if defined(__i386__) && defined(__GNUC__) && !defined(__CYGWIN__) && !defined(__MINGW32__) +# define FASTCALL __attribute__((fastcall)) +# else +# define FASTCALL +# endif""" + return + + + def printVisibility(self, S, s): + """Conditionally define visibility function attribute. + + Conditionally defines a preprocessor macro name S that wraps + GCC's visibility function attribute. The visibility used is + the parameter s. The conditional code can be easilly adapted + to other compilers that support a similar feature. + + The name is also added to the file's undef_list. + """ + + self.undef_list.append(S) + print """# if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))) && defined(__ELF__) +# define %s __attribute__((visibility("%s"))) +# else +# define %s +# endif""" % (S, s, S) + return + + + def printNoinline(self): + """Conditionally define `NOINLINE' function attribute. + + Conditionally defines a preprocessor macro `NOINLINE' that + wraps GCC's `noinline' function attribute. The conditional + code can be easilly adapted to other compilers that support a + similar feature. + + The name is also added to the file's undef_list. + """ + + self.undef_list.append("NOINLINE") + print """# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) +# define NOINLINE __attribute__((noinline)) +# else +# define NOINLINE +# endif""" + return + + +def real_function_name(element): + name = element.nsProp( "name", None ) + alias = element.nsProp( "alias", None ) + + if alias: + return alias + else: + return name + + +def real_category_name(c): + if re.compile("[1-9][0-9]*[.][0-9]+").match(c): + return "GL_VERSION_" + c.replace(".", "_") + else: + return c + + +def classify_category(name, number): + """Based on the category name and number, select a numerical class for it. + + Categories are divided into four classes numbered 0 through 3. The + classes are: + + 0. Core GL versions, sorted by version number. + 1. ARB extensions, sorted by extension number. + 2. Non-ARB extensions, sorted by extension number. + 3. Un-numbered extensions, sorted by extension name. + """ + + try: + core_version = float(name) + except Exception,e: + core_version = 0.0 + + if core_version > 0.0: + cat_type = 0 + key = name + elif name.startswith("GL_ARB_") or name.startswith("GLX_ARB_") or name.startswith("WGL_ARB_"): + cat_type = 1 + key = int(number) + else: + if number != None: + cat_type = 2 + key = int(number) + else: + cat_type = 3 + key = name + + + return [cat_type, key] + + +def create_parameter_string(parameters, include_names): + """Create a parameter string from a list of gl_parameters.""" + + list = [] + for p in parameters: + if p.is_padding: + continue + + if include_names: + list.append( p.string() ) + else: + list.append( p.type_string() ) + + if len(list) == 0: list = ["void"] + + return string.join(list, ", ") + + +class gl_item: + def __init__(self, element, context): + self.context = context + self.name = element.nsProp( "name", None ) + self.category = real_category_name( element.parent.nsProp( "name", None ) ) + return + + +class gl_type( gl_item ): + def __init__(self, element, context): + gl_item.__init__(self, element, context) + self.size = int( element.nsProp( "size", None ), 0 ) + + te = typeexpr.type_expression( None ) + tn = typeexpr.type_node() + tn.size = int( element.nsProp( "size", None ), 0 ) + tn.integer = not is_attr_true( element, "float" ) + tn.unsigned = is_attr_true( element, "unsigned" ) + tn.name = "GL" + self.name + te.set_base_type_node( tn ) + + self.type_expr = te + return + + + def get_type_expression(self): + return self.type_expr + + +class gl_enum( gl_item ): + def __init__(self, element, context): + gl_item.__init__(self, element, context) + self.value = int( element.nsProp( "value", None ), 0 ) + + temp = element.nsProp( "count", None ) + if not temp or temp == "?": + self.default_count = -1 + else: + try: + c = int(temp) + except Exception,e: + raise RuntimeError('Invalid count value "%s" for enum "%s" in function "%s" when an integer was expected.' % (temp, self.name, n)) + + self.default_count = c + + return + + + def priority(self): + """Calculate a 'priority' for this enum name. + + When an enum is looked up by number, there may be many + possible names, but only one is the 'prefered' name. The + priority is used to select which name is the 'best'. + + Highest precedence is given to core GL name. ARB extension + names have the next highest, followed by EXT extension names. + Vendor extension names are the lowest. + """ + + if self.name.endswith( "_BIT" ): + bias = 1 + else: + bias = 0 + + if self.category.startswith( "GL_VERSION_" ): + priority = 0 + elif self.category.startswith( "GL_ARB_" ): + priority = 2 + elif self.category.startswith( "GL_EXT_" ): + priority = 4 + else: + priority = 6 + + return priority + bias + + + +class gl_parameter: + def __init__(self, element, context): + self.name = element.nsProp( "name", None ) + + ts = element.nsProp( "type", None ) + self.type_expr = typeexpr.type_expression( ts, context ) + + temp = element.nsProp( "variable_param", None ) + if temp: + self.count_parameter_list = temp.split( ' ' ) + else: + self.count_parameter_list = [] + + # The count tag can be either a numeric string or the name of + # a variable. If it is the name of a variable, the int(c) + # statement will throw an exception, and the except block will + # take over. + + c = element.nsProp( "count", None ) + try: + count = int(c) + self.count = count + self.counter = None + except Exception,e: + count = 1 + self.count = 0 + self.counter = c + + self.count_scale = int(element.nsProp( "count_scale", None )) + + elements = (count * self.count_scale) + if elements == 1: + elements = 0 + + #if ts == "GLdouble": + # print '/* stack size -> %s = %u (before)*/' % (self.name, self.type_expr.get_stack_size()) + # print '/* # elements = %u */' % (elements) + self.type_expr.set_elements( elements ) + #if ts == "GLdouble": + # print '/* stack size -> %s = %u (after) */' % (self.name, self.type_expr.get_stack_size()) + + self.is_client_only = is_attr_true( element, 'client_only' ) + self.is_counter = is_attr_true( element, 'counter' ) + self.is_output = is_attr_true( element, 'output' ) + + + # Pixel data has special parameters. + + self.width = element.nsProp('img_width', None) + self.height = element.nsProp('img_height', None) + self.depth = element.nsProp('img_depth', None) + self.extent = element.nsProp('img_extent', None) + + self.img_xoff = element.nsProp('img_xoff', None) + self.img_yoff = element.nsProp('img_yoff', None) + self.img_zoff = element.nsProp('img_zoff', None) + self.img_woff = element.nsProp('img_woff', None) + + self.img_format = element.nsProp('img_format', None) + self.img_type = element.nsProp('img_type', None) + self.img_target = element.nsProp('img_target', None) + + self.img_pad_dimensions = is_attr_true( element, 'img_pad_dimensions' ) + self.img_null_flag = is_attr_true( element, 'img_null_flag' ) + self.img_send_null = is_attr_true( element, 'img_send_null' ) + + self.is_padding = is_attr_true( element, 'padding' ) + return + + + def compatible(self, other): + return 1 + + + def is_array(self): + return self.is_pointer() + + + def is_pointer(self): + return self.type_expr.is_pointer() + + + def is_image(self): + if self.width: + return 1 + else: + return 0 + + + def is_variable_length(self): + return len(self.count_parameter_list) or self.counter + + + def is_64_bit(self): + count = self.type_expr.get_element_count() + if count: + if (self.size() / count) == 8: + return 1 + else: + if self.size() == 8: + return 1 + + return 0 + + + def string(self): + return self.type_expr.original_string + " " + self.name + + + def type_string(self): + return self.type_expr.original_string + + + def get_base_type_string(self): + return self.type_expr.get_base_name() + + + def get_dimensions(self): + if not self.width: + return [ 0, "0", "0", "0", "0" ] + + dim = 1 + w = self.width + h = "1" + d = "1" + e = "1" + + if self.height: + dim = 2 + h = self.height + + if self.depth: + dim = 3 + d = self.depth + + if self.extent: + dim = 4 + e = self.extent + + return [ dim, w, h, d, e ] + + + def get_stack_size(self): + return self.type_expr.get_stack_size() + + + def size(self): + if self.is_image(): + return 0 + else: + return self.type_expr.get_element_size() + + + def get_element_count(self): + c = self.type_expr.get_element_count() + if c == 0: + return 1 + + return c + + + def size_string(self, use_parens = 1): + s = self.size() + if self.counter or self.count_parameter_list: + list = [ "compsize" ] + + if self.counter and self.count_parameter_list: + list.append( self.counter ) + elif self.counter: + list = [ self.counter ] + + if s > 1: + list.append( str(s) ) + + if len(list) > 1 and use_parens : + return "(%s)" % (string.join(list, " * ")) + else: + return string.join(list, " * ") + + elif self.is_image(): + return "compsize" + else: + return str(s) + + + def format_string(self): + if self.type_expr.original_string == "GLenum": + return "0x%x" + else: + return self.type_expr.format_string() + + + +class gl_function( gl_item ): + def __init__(self, element, context): + self.context = context + self.name = None + + self.entry_points = [] + self.return_type = "void" + self.parameters = [] + self.offset = -1 + self.initialized = 0 + self.images = [] + + self.assign_offset = 0 + + self.static_entry_points = [] + + # Track the parameter string (for the function prototype) + # for each entry-point. This is done because some functions + # change their prototype slightly when promoted from extension + # to ARB extension to core. glTexImage3DEXT and glTexImage3D + # are good examples of this. Scripts that need to generate + # code for these differing aliases need to real prototype + # for each entry-point. Otherwise, they may generate code + # that won't compile. + + self.parameter_strings = {} + + self.process_element( element ) + + return + + + def process_element(self, element): + name = element.nsProp( "name", None ) + alias = element.nsProp( "alias", None ) + + if is_attr_true(element, "static_dispatch"): + self.static_entry_points.append(name) + + self.entry_points.append( name ) + if alias: + true_name = alias + else: + true_name = name + + # Only try to set the offset when a non-alias + # entry-point is being processes. + + offset = element.nsProp( "offset", None ) + if offset: + try: + o = int( offset ) + self.offset = o + except Exception, e: + self.offset = -1 + if offset == "assign": + self.assign_offset = 1 + + + if not self.name: + self.name = true_name + elif self.name != true_name: + raise RuntimeError("Function true name redefined. Was %s, now %s." % (self.name, true_name)) + + + # There are two possible cases. The first time an entry-point + # with data is seen, self.initialized will be 0. On that + # pass, we just fill in the data. The next time an + # entry-point with data is seen, self.initialized will be 1. + # On that pass we have to make that the new values match the + # valuse from the previous entry-point. + + parameters = [] + return_type = "void" + child = element.children + while child: + if child.type == "element": + if child.name == "return": + return_type = child.nsProp( "type", None ) + elif child.name == "param": + param = self.context.factory.create_item( "parameter", child, self.context) + parameters.append( param ) + + child = child.next + + + if self.initialized: + if self.return_type != return_type: + raise RuntimeError( "Return type changed in %s. Was %s, now %s." % (name, self.return_type, return_type)) + + if len(parameters) != len(self.parameters): + raise RuntimeError( "Parameter count mismatch in %s. Was %d, now %d." % (name, len(self.parameters), len(parameters))) + + for j in range(0, len(parameters)): + p1 = parameters[j] + p2 = self.parameters[j] + if not p1.compatible( p2 ): + raise RuntimeError( 'Parameter type mismatch in %s. "%s" was "%s", now "%s".' % (name, p2.name, p2.type_expr.original_string, p1.type_expr.original_string)) + + + if true_name == name or not self.initialized: + self.return_type = return_type + self.parameters = parameters + + for param in self.parameters: + if param.is_image(): + self.images.append( param ) + + if element.children: + self.initialized = 1 + self.parameter_strings[name] = create_parameter_string(parameters, 1) + else: + self.parameter_strings[name] = None + + return + + + def get_images(self): + """Return potentially empty list of input images.""" + return self.images + + + def parameterIterator(self): + return self.parameters.__iter__(); + + + def get_parameter_string(self, entrypoint = None): + if entrypoint: + s = self.parameter_strings[ entrypoint ] + if s: + return s + + return create_parameter_string( self.parameters, 1 ) + + def get_called_parameter_string(self): + p_string = "" + comma = "" + + for p in self.parameterIterator(): + p_string = p_string + comma + p.name + comma = ", " + + return p_string + + + def is_abi(self): + return (self.offset >= 0 and not self.assign_offset) + + def is_static_entry_point(self, name): + return name in self.static_entry_points + + def dispatch_name(self): + if self.name in self.static_entry_points: + return self.name + else: + return "_dispatch_stub_%u" % (self.offset) + + def static_name(self, name): + if name in self.static_entry_points: + return name + else: + return "_dispatch_stub_%u" % (self.offset) + + +class gl_item_factory: + """Factory to create objects derived from gl_item.""" + + def create_item(self, item_name, element, context): + if item_name == "function": + return gl_function(element, context) + if item_name == "type": + return gl_type(element, context) + elif item_name == "enum": + return gl_enum(element, context) + elif item_name == "parameter": + return gl_parameter(element, context) + elif item_name == "api": + return gl_api(self) + else: + return None + + +class gl_api: + def __init__(self, factory): + self.functions_by_name = {} + self.enums_by_name = {} + self.types_by_name = {} + + self.category_dict = {} + self.categories = [{}, {}, {}, {}] + + self.factory = factory + + self.next_offset = 0 + + typeexpr.create_initial_types() + return + + + def process_element(self, doc): + element = doc.children + while element.type != "element" or element.name != "OpenGLAPI": + element = element.next + + if element: + self.process_OpenGLAPI(element) + return + + + def process_OpenGLAPI(self, element): + child = element.children + while child: + if child.type == "element": + if child.name == "category": + self.process_category( child ) + elif child.name == "OpenGLAPI": + self.process_OpenGLAPI( child ) + + child = child.next + + return + + + def process_category(self, cat): + cat_name = cat.nsProp( "name", None ) + cat_number = cat.nsProp( "number", None ) + + [cat_type, key] = classify_category(cat_name, cat_number) + self.categories[cat_type][key] = [cat_name, cat_number] + + child = cat.children + while child: + if child.type == "element": + if child.name == "function": + func_name = real_function_name( child ) + + temp_name = child.nsProp( "name", None ) + self.category_dict[ temp_name ] = [cat_name, cat_number] + + if self.functions_by_name.has_key( func_name ): + func = self.functions_by_name[ func_name ] + func.process_element( child ) + else: + func = self.factory.create_item( "function", child, self ) + self.functions_by_name[ func_name ] = func + + if func.offset >= self.next_offset: + self.next_offset = func.offset + 1 + + + elif child.name == "enum": + enum = self.factory.create_item( "enum", child, self ) + self.enums_by_name[ enum.name ] = enum + elif child.name == "type": + t = self.factory.create_item( "type", child, self ) + self.types_by_name[ "GL" + t.name ] = t + + + child = child.next + + return + + + def functionIterateByCategory(self, cat = None): + """Iterate over functions by category. + + If cat is None, all known functions are iterated in category + order. See classify_category for details of the ordering. + Within a category, functions are sorted by name. If cat is + not None, then only functions in that category are iterated. + """ + lists = [{}, {}, {}, {}] + + for func in self.functionIterateAll(): + [cat_name, cat_number] = self.category_dict[func.name] + + if (cat == None) or (cat == cat_name): + [func_cat_type, key] = classify_category(cat_name, cat_number) + + if not lists[func_cat_type].has_key(key): + lists[func_cat_type][key] = {} + + lists[func_cat_type][key][func.name] = func + + + functions = [] + for func_cat_type in range(0,4): + keys = lists[func_cat_type].keys() + keys.sort() + + for key in keys: + names = lists[func_cat_type][key].keys() + names.sort() + + for name in names: + functions.append(lists[func_cat_type][key][name]) + + return functions.__iter__() + + + def functionIterateByOffset(self): + max_offset = -1 + for func in self.functions_by_name.itervalues(): + if func.offset > max_offset: + max_offset = func.offset + + + temp = [None for i in range(0, max_offset + 1)] + for func in self.functions_by_name.itervalues(): + if func.offset != -1: + temp[ func.offset ] = func + + + list = [] + for i in range(0, max_offset + 1): + if temp[i]: + list.append(temp[i]) + + return list.__iter__(); + + + def functionIterateAll(self): + return self.functions_by_name.itervalues() + + + def enumIterateByName(self): + keys = self.enums_by_name.keys() + keys.sort() + + list = [] + for enum in keys: + list.append( self.enums_by_name[ enum ] ) + + return list.__iter__() + + + def categoryIterate(self): + """Iterate over categories. + + Iterate over all known categories in the order specified by + classify_category. Each iterated value is a tuple of the + name and number (which may be None) of the category. + """ + + list = [] + for cat_type in range(0,4): + keys = self.categories[cat_type].keys() + keys.sort() + + for key in keys: + list.append(self.categories[cat_type][key]) + + return list.__iter__() + + + def get_category_for_name( self, name ): + if self.category_dict.has_key(name): + return self.category_dict[name] + else: + return ["", None] + + + def typeIterate(self): + return self.types_by_name.itervalues() + + + def find_type( self, type_name ): + if type_name in self.types_by_name: + return self.types_by_name[ type_name ].type_expr + else: + print "Unable to find base type matching \"%s\"." % (type_name) + return None diff --git a/src/mesa/glapi/gen/gl_and_glX_API.xml b/src/mesa/glapi/gen/gl_and_glX_API.xml new file mode 100644 index 00000000000..34c977e9c0c --- /dev/null +++ b/src/mesa/glapi/gen/gl_and_glX_API.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/mesa/glapi/gen/gl_apitemp.py b/src/mesa/glapi/gen/gl_apitemp.py new file mode 100644 index 00000000000..41a40fbeb68 --- /dev/null +++ b/src/mesa/glapi/gen/gl_apitemp.py @@ -0,0 +1,320 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004, 2005 +# 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 +# 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. +# +# Authors: +# Ian Romanick + +import gl_XML, glX_XML +import license +import sys, getopt + +class PrintGlOffsets(gl_XML.gl_print_base): + def __init__(self, es=False): + gl_XML.gl_print_base.__init__(self) + + self.name = "gl_apitemp.py (from Mesa)" + self.license = license.bsd_license_template % ( \ +"""Copyright (C) 1999-2001 Brian Paul All Rights Reserved. +(C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM") + + self.es = es + + self.undef_list.append( "KEYWORD1" ) + self.undef_list.append( "KEYWORD1_ALT" ) + self.undef_list.append( "KEYWORD2" ) + self.undef_list.append( "NAME" ) + self.undef_list.append( "DISPATCH" ) + self.undef_list.append( "RETURN_DISPATCH" ) + self.undef_list.append( "DISPATCH_TABLE_NAME" ) + self.undef_list.append( "UNUSED_TABLE_NAME" ) + self.undef_list.append( "TABLE_ENTRY" ) + + + def printFunction(self, f, name): + p_string = "" + o_string = "" + t_string = "" + comma = "" + + if f.is_static_entry_point(name): + keyword = "KEYWORD1" + else: + keyword = "KEYWORD1_ALT" + + n = f.static_name(name) + + for p in f.parameterIterator(): + if p.is_padding: + continue + + if p.is_pointer(): + cast = "(const void *) " + else: + cast = "" + + t_string = t_string + comma + p.format_string() + p_string = p_string + comma + p.name + o_string = o_string + comma + cast + p.name + comma = ", " + + + if f.return_type != 'void': + dispatch = "RETURN_DISPATCH" + else: + dispatch = "DISPATCH" + + need_proto = False + if not f.is_static_entry_point(name): + need_proto = True + elif self.es: + cat, num = api.get_category_for_name(name) + if (cat.startswith("es") or cat.startswith("GL_OES")): + need_proto = True + if need_proto: + print '%s %s KEYWORD2 NAME(%s)(%s);' % (keyword, f.return_type, n, f.get_parameter_string(name)) + print '' + + print '%s %s KEYWORD2 NAME(%s)(%s)' % (keyword, f.return_type, n, f.get_parameter_string(name)) + print '{' + if p_string == "": + print ' %s(%s, (), (F, "gl%s();\\n"));' \ + % (dispatch, f.name, name) + else: + print ' %s(%s, (%s), (F, "gl%s(%s);\\n", %s));' \ + % (dispatch, f.name, p_string, name, t_string, o_string) + print '}' + print '' + return + + def printRealHeader(self): + print '' + self.printVisibility( "HIDDEN", "hidden" ) + print """ +/* + * This file is a template which generates the OpenGL API entry point + * functions. It should be included by a .c file which first defines + * the following macros: + * KEYWORD1 - usually nothing, but might be __declspec(dllexport) on Win32 + * KEYWORD2 - usually nothing, but might be __stdcall on Win32 + * NAME(n) - builds the final function name (usually add "gl" prefix) + * DISPATCH(func, args, msg) - code to do dispatch of named function. + * msg is a printf-style debug message. + * RETURN_DISPATCH(func, args, msg) - code to do dispatch with a return value + * + * Here is an example which generates the usual OpenGL functions: + * #define KEYWORD1 + * #define KEYWORD2 + * #define NAME(func) gl##func + * #define DISPATCH(func, args, msg) \\ + * struct _glapi_table *dispatch = CurrentDispatch; \\ + * (*dispatch->func) args + * #define RETURN DISPATCH(func, args, msg) \\ + * struct _glapi_table *dispatch = CurrentDispatch; \\ + * return (*dispatch->func) args + * + */ + + +#if defined( NAME ) +#ifndef KEYWORD1 +#define KEYWORD1 +#endif + +#ifndef KEYWORD1_ALT +#define KEYWORD1_ALT HIDDEN +#endif + +#ifndef KEYWORD2 +#define KEYWORD2 +#endif + +#ifndef DISPATCH +#error DISPATCH must be defined +#endif + +#ifndef RETURN_DISPATCH +#error RETURN_DISPATCH must be defined +#endif + +""" + return + + + + def printInitDispatch(self, api): + print """ +#endif /* defined( NAME ) */ + +/* + * This is how a dispatch table can be initialized with all the functions + * we generated above. + */ +#ifdef DISPATCH_TABLE_NAME + +#ifndef TABLE_ENTRY +#error TABLE_ENTRY must be defined +#endif + +#ifdef _GLAPI_SKIP_NORMAL_ENTRY_POINTS +#error _GLAPI_SKIP_NORMAL_ENTRY_POINTS must not be defined +#endif + +_glapi_proc DISPATCH_TABLE_NAME[] = {""" + for f in api.functionIterateByOffset(): + print ' TABLE_ENTRY(%s),' % (f.dispatch_name()) + + print ' /* A whole bunch of no-op functions. These might be called' + print ' * when someone tries to call a dynamically-registered' + print ' * extension function without a current rendering context.' + print ' */' + for i in range(1, 100): + print ' TABLE_ENTRY(Unused),' + + print '};' + print '#endif /* DISPATCH_TABLE_NAME */' + print '' + return + + + def printAliasedTable(self, api): + print """ +/* + * This is just used to silence compiler warnings. + * We list the functions which are not otherwise used. + */ +#ifdef UNUSED_TABLE_NAME +_glapi_proc UNUSED_TABLE_NAME[] = {""" + + normal_entries = [] + proto_entries = [] + for f in api.functionIterateByOffset(): + normal_ents, proto_ents = self.classifyEntryPoints(f) + + # exclude f.name + if f.name in normal_ents: + normal_ents.remove(f.name) + elif f.name in proto_ents: + proto_ents.remove(f.name) + + normal_ents = [f.static_name(ent) for ent in normal_ents] + proto_ents = [f.static_name(ent) for ent in proto_ents] + + normal_entries.extend(normal_ents) + proto_entries.extend(proto_ents) + + print '#ifndef _GLAPI_SKIP_NORMAL_ENTRY_POINTS' + for ent in normal_entries: + print ' TABLE_ENTRY(%s),' % (ent) + print '#endif /* _GLAPI_SKIP_NORMAL_ENTRY_POINTS */' + print '#ifndef _GLAPI_SKIP_PROTO_ENTRY_POINTS' + for ent in proto_entries: + print ' TABLE_ENTRY(%s),' % (ent) + print '#endif /* _GLAPI_SKIP_PROTO_ENTRY_POINTS */' + + print '};' + print '#endif /*UNUSED_TABLE_NAME*/' + print '' + return + + + def classifyEntryPoints(self, func): + normal_names = [] + normal_stubs = [] + proto_names = [] + proto_stubs = [] + # classify the entry points + for name in func.entry_points: + if func.has_different_protocol(name): + if func.is_static_entry_point(name): + proto_names.append(name) + else: + proto_stubs.append(name) + else: + if func.is_static_entry_point(name): + normal_names.append(name) + else: + normal_stubs.append(name) + # there can be at most one stub for a function + if normal_stubs: + normal_names.append(normal_stubs[0]) + elif proto_stubs: + proto_names.append(proto_stubs[0]) + + return (normal_names, proto_names) + + def printBody(self, api): + normal_entry_points = [] + proto_entry_points = [] + for func in api.functionIterateByOffset(): + normal_ents, proto_ents = self.classifyEntryPoints(func) + normal_entry_points.append((func, normal_ents)) + proto_entry_points.append((func, proto_ents)) + + print '#ifndef _GLAPI_SKIP_NORMAL_ENTRY_POINTS' + print '' + for func, ents in normal_entry_points: + for ent in ents: + self.printFunction(func, ent) + print '' + print '#endif /* _GLAPI_SKIP_NORMAL_ENTRY_POINTS */' + print '' + print '/* these entry points might require different protocols */' + print '#ifndef _GLAPI_SKIP_PROTO_ENTRY_POINTS' + print '' + for func, ents in proto_entry_points: + for ent in ents: + self.printFunction(func, ent) + print '' + print '#endif /* _GLAPI_SKIP_PROTO_ENTRY_POINTS */' + print '' + + self.printInitDispatch(api) + self.printAliasedTable(api) + return + + +def show_usage(): + print "Usage: %s [-f input_file_name] [-c]" % sys.argv[0] + print "-c Enable compatibility with OpenGL ES." + sys.exit(1) + +if __name__ == '__main__': + file_name = "gl_API.xml" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:c") + except Exception,e: + show_usage() + + es = False + for (arg,val) in args: + if arg == "-f": + file_name = val + elif arg == "-c": + es = True + + api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory()) + + printer = PrintGlOffsets(es) + printer.Print(api) diff --git a/src/mesa/glapi/gen/gl_enums.py b/src/mesa/glapi/gen/gl_enums.py new file mode 100644 index 00000000000..3a9ea3c86c7 --- /dev/null +++ b/src/mesa/glapi/gen/gl_enums.py @@ -0,0 +1,243 @@ +#!/usr/bin/python2 +# -*- Mode: Python; py-indent-offset: 8 -*- + +# (C) Copyright Zack Rusin 2005 +# 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 +# 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. +# +# Authors: +# Zack Rusin + +import license +import gl_XML +import sys, getopt + +class PrintGlEnums(gl_XML.gl_print_base): + + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + self.name = "gl_enums.py (from Mesa)" + self.license = license.bsd_license_template % ( \ +"""Copyright (C) 1999-2005 Brian Paul All Rights Reserved.""", "BRIAN PAUL") + self.enum_table = {} + + + def printRealHeader(self): + print '#include "main/glheader.h"' + print '#include "main/mfeatures.h"' + print '#include "main/enums.h"' + print '#include "main/imports.h"' + print '' + print 'typedef struct {' + print ' size_t offset;' + print ' int n;' + print '} enum_elt;' + print '' + return + + def print_code(self): + print """ +typedef int (*cfunc)(const void *, const void *); + +/** + * Compare a key name to an element in the \c all_enums array. + * + * \c bsearch always passes the key as the first parameter and the pointer + * to the array element as the second parameter. We can elimiate some + * extra work by taking advantage of that fact. + * + * \param a Pointer to the desired enum name. + * \param b Pointer to an element of the \c all_enums array. + */ +static int compar_name( const char *a, const enum_elt *b ) +{ + return strcmp( a, & enum_string_table[ b->offset ] ); +} + +/** + * Compare a key enum value to an element in the \c all_enums array. + * + * \c bsearch always passes the key as the first parameter and the pointer + * to the array element as the second parameter. We can elimiate some + * extra work by taking advantage of that fact. + * + * \param a Pointer to the desired enum name. + * \param b Pointer to an index into the \c all_enums array. + */ +static int compar_nr( const int *a, const unsigned *b ) +{ + return a[0] - all_enums[*b].n; +} + + +static char token_tmp[20]; + +const char *_mesa_lookup_enum_by_nr( int nr ) +{ + unsigned * i; + + i = (unsigned *) _mesa_bsearch(& nr, reduced_enums, + Elements(reduced_enums), + sizeof(reduced_enums[0]), + (cfunc) compar_nr); + + if ( i != NULL ) { + return & enum_string_table[ all_enums[ *i ].offset ]; + } + else { + /* this is not re-entrant safe, no big deal here */ + sprintf(token_tmp, "0x%x", nr); + return token_tmp; + } +} + +/* Get the name of an enum given that it is a primitive type. Avoids + * GL_FALSE/GL_POINTS ambiguity and others. + */ +const char *_mesa_lookup_prim_by_nr( int nr ) +{ + switch (nr) { + case GL_POINTS: return "GL_POINTS"; + case GL_LINES: return "GL_LINES"; + case GL_LINE_STRIP: return "GL_LINE_STRIP"; + case GL_LINE_LOOP: return "GL_LINE_LOOP"; + case GL_TRIANGLES: return "GL_TRIANGLES"; + case GL_TRIANGLE_STRIP: return "GL_TRIANGLE_STRIP"; + case GL_TRIANGLE_FAN: return "GL_TRIANGLE_FAN"; + case GL_QUADS: return "GL_QUADS"; + case GL_QUAD_STRIP: return "GL_QUAD_STRIP"; + case GL_POLYGON: return "GL_POLYGON"; + case GL_POLYGON+1: return "OUTSIDE_BEGIN_END"; + default: return ""; + } +} + + + +int _mesa_lookup_enum_by_name( const char *symbol ) +{ + enum_elt * f = NULL; + + if ( symbol != NULL ) { + f = (enum_elt *) _mesa_bsearch(symbol, all_enums, + Elements(all_enums), + sizeof( enum_elt ), + (cfunc) compar_name); + } + + return (f != NULL) ? f->n : -1; +} + +""" + return + + + def printBody(self, api): + self.process_enums( api ) + + keys = self.enum_table.keys() + keys.sort() + + name_table = [] + enum_table = {} + + for enum in keys: + low_pri = 9 + for [name, pri] in self.enum_table[ enum ]: + name_table.append( [name, enum] ) + + if pri < low_pri: + low_pri = pri + enum_table[enum] = name + + + name_table.sort() + + string_offsets = {} + i = 0; + print 'LONGSTRING static const char enum_string_table[] = ' + for [name, enum] in name_table: + print ' "%s\\0"' % (name) + string_offsets[ name ] = i + i += len(name) + 1 + + print ' ;' + print '' + + + print 'static const enum_elt all_enums[%u] =' % (len(name_table)) + print '{' + for [name, enum] in name_table: + print ' { %5u, 0x%08X }, /* %s */' % (string_offsets[name], enum, name) + print '};' + print '' + + print 'static const unsigned reduced_enums[%u] =' % (len(keys)) + print '{' + for enum in keys: + name = enum_table[ enum ] + if [name, enum] not in name_table: + print ' /* Error! %s, 0x%04x */ 0,' % (name, enum) + else: + i = name_table.index( [name, enum] ) + + print ' %4u, /* %s */' % (i, name) + print '};' + + + self.print_code() + return + + + def process_enums(self, api): + self.enum_table = {} + + for obj in api.enumIterateByName(): + if obj.value not in self.enum_table: + self.enum_table[ obj.value ] = [] + + + name = "GL_" + obj.name + priority = obj.priority() + self.enum_table[ obj.value ].append( [name, priority] ) + + +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 = PrintGlEnums() + printer.Print( api ) diff --git a/src/mesa/glapi/gen/gl_offsets.py b/src/mesa/glapi/gen/gl_offsets.py new file mode 100644 index 00000000000..54867b34634 --- /dev/null +++ b/src/mesa/glapi/gen/gl_offsets.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004, 2005 +# 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 +# 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. +# +# Authors: +# Ian Romanick + +import gl_XML +import license +import sys, getopt + +class PrintGlOffsets(gl_XML.gl_print_base): + def __init__(self, es=False): + gl_XML.gl_print_base.__init__(self) + + self.es = es + self.name = "gl_offsets.py (from Mesa)" + self.header_tag = '_GLAPI_OFFSETS_H_' + self.license = license.bsd_license_template % ( \ +"""Copyright (C) 1999-2001 Brian Paul All Rights Reserved. +(C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM") + return + + def printBody(self, api): + print '/* this file should not be included directly in mesa */' + print '' + + functions = [] + abi_functions = [] + alias_functions = [] + count = 0 + for f in api.functionIterateByOffset(): + if not f.is_abi(): + functions.append( [f, count] ) + count += 1 + else: + abi_functions.append( f ) + + if self.es: + # remember functions with aliases + if len(f.entry_points) > 1: + alias_functions.append(f) + + for f in abi_functions: + print '#define _gloffset_%s %d' % (f.name, f.offset) + last_static = f.offset + + print '' + print '#if !defined(_GLAPI_USE_REMAP_TABLE)' + print '' + + for [f, index] in functions: + print '#define _gloffset_%s %d' % (f.name, f.offset) + + print '#define _gloffset_FIRST_DYNAMIC %d' % (api.next_offset) + + print '' + print '#else' + print '' + + for [f, index] in functions: + print '#define _gloffset_%s driDispatchRemapTable[%s_remap_index]' % (f.name, f.name) + + print '' + print '#endif /* !defined(_GLAPI_USE_REMAP_TABLE) */' + + if alias_functions: + print '' + print '/* define aliases for compatibility */' + for f in alias_functions: + for name in f.entry_points: + if name != f.name: + print '#define _gloffset_%s _gloffset_%s' % (name, f.name) + return + + +def show_usage(): + print "Usage: %s [-f input_file_name] [-c]" % sys.argv[0] + print " -c Enable compatibility with OpenGL ES." + sys.exit(1) + +if __name__ == '__main__': + file_name = "gl_API.xml" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:c") + except Exception,e: + show_usage() + + es = False + for (arg,val) in args: + if arg == "-f": + file_name = val + elif arg == "-c": + es = True + + api = gl_XML.parse_GL_API( file_name ) + + printer = PrintGlOffsets(es) + printer.Print( api ) diff --git a/src/mesa/glapi/gen/gl_procs.py b/src/mesa/glapi/gen/gl_procs.py new file mode 100644 index 00000000000..5de61fbdfe9 --- /dev/null +++ b/src/mesa/glapi/gen/gl_procs.py @@ -0,0 +1,215 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004, 2005 +# 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 +# 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. +# +# Authors: +# Ian Romanick + +import license +import gl_XML, glX_XML +import sys, getopt + +class PrintGlProcs(gl_XML.gl_print_base): + def __init__(self, long_strings, es=False): + gl_XML.gl_print_base.__init__(self) + + self.es = es + self.long_strings = long_strings + self.name = "gl_procs.py (from Mesa)" + self.license = license.bsd_license_template % ( \ +"""Copyright (C) 1999-2001 Brian Paul All Rights Reserved. +(C) Copyright IBM Corporation 2004, 2006""", "BRIAN PAUL, IBM") + + + def printRealHeader(self): + print """ +/* This file is only included by glapi.c and is used for + * the GetProcAddress() function + */ + +typedef struct { + GLint Name_offset; +#if defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING) + _glapi_proc Address; +#endif + GLuint Offset; +} glprocs_table_t; + +#if !defined(NEED_FUNCTION_POINTER) && !defined(GLX_INDIRECT_RENDERING) +# define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , o } +#elif defined(NEED_FUNCTION_POINTER) && !defined(GLX_INDIRECT_RENDERING) +# define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f1 , o } +#elif defined(NEED_FUNCTION_POINTER) && defined(GLX_INDIRECT_RENDERING) +# define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f2 , o } +#elif !defined(NEED_FUNCTION_POINTER) && defined(GLX_INDIRECT_RENDERING) +# define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f3 , o } +#endif + +""" + return + + def printRealFooter(self): + print '' + print '#undef NAME_FUNC_OFFSET' + return + + def printFunctionString(self, name): + if self.long_strings: + print ' "gl%s\\0"' % (name) + else: + print " 'g','l',", + for c in name: + print "'%s'," % (c), + + print "'\\0'," + + + def printBody(self, api): + print '' + if self.long_strings: + print 'static const char gl_string_table[] =' + else: + print 'static const char gl_string_table[] = {' + + base_offset = 0 + table = [] + for func in api.functionIterateByOffset(): + name = func.dispatch_name() + self.printFunctionString(func.name) + table.append((base_offset, "gl" + name, "gl" + name, "NULL", func.name)) + + # The length of the function's name, plus 2 for "gl", + # plus 1 for the NUL. + + base_offset += len(func.name) + 3 + + + for func in api.functionIterateByOffset(): + for n in func.entry_points: + if n != func.name: + name = func.dispatch_name() + self.printFunctionString( n ) + + if func.has_different_protocol(n): + alt_name = "gl" + func.static_glx_name(n) + table.append((base_offset, "gl" + name, alt_name, alt_name, func.name)) + else: + table.append((base_offset, "gl" + name, "gl" + name, "NULL", func.name)) + + base_offset += len(n) + 3 + + + if self.long_strings: + print ' ;' + else: + print '};' + + print '' + print '' + print "#ifdef USE_MGL_NAMESPACE" + for func in api.functionIterateByOffset(): + for n in func.entry_points: + if (not func.is_static_entry_point(func.name)) or (func.has_different_protocol(n) and not func.is_static_entry_point(n)): + print '#define gl_dispatch_stub_%u mgl_dispatch_stub_%u' % (func.offset, func.offset) + break + print "#endif /* USE_MGL_NAMESPACE */" + print '' + print '' + print '#if defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING)' + for func in api.functionIterateByOffset(): + for n in func.entry_points: + if (not func.is_static_entry_point(func.name)) or (func.has_different_protocol(n) and not func.is_static_entry_point(n)): + print '%s GLAPIENTRY gl_dispatch_stub_%u(%s);' % (func.return_type, func.offset, func.get_parameter_string()) + break + + if self.es: + categories = {} + for func in api.functionIterateByOffset(): + for n in func.entry_points: + cat, num = api.get_category_for_name(n) + if (cat.startswith("es") or cat.startswith("GL_OES")): + if not categories.has_key(cat): + categories[cat] = [] + proto = 'GLAPI %s GLAPIENTRY %s(%s);' \ + % (func.return_type, "gl" + n, func.get_parameter_string(n)) + categories[cat].append(proto) + if categories: + print '' + print '/* OpenGL ES specific prototypes */' + print '' + keys = categories.keys() + keys.sort() + for key in keys: + print '/* category %s */' % key + print "\n".join(categories[key]) + print '' + + print '#endif /* defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING) */' + + print '' + print 'static const glprocs_table_t static_functions[] = {' + + for info in table: + print ' NAME_FUNC_OFFSET(%5u, %s, %s, %s, _gloffset_%s),' % info + + print ' NAME_FUNC_OFFSET(-1, NULL, NULL, NULL, 0)' + print '};' + return + + +def show_usage(): + print "Usage: %s [-f input_file_name] [-m mode] [-c]" % sys.argv[0] + print "-c Enable compatibility with OpenGL ES." + print "-m mode mode can be one of:" + print " long - Create code for compilers that can handle very" + print " long string constants. (default)" + print " short - Create code for compilers that can only handle" + print " ANSI C89 string constants." + sys.exit(1) + +if __name__ == '__main__': + file_name = "gl_API.xml" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:m:c") + except Exception,e: + show_usage() + + long_string = 1 + es = False + for (arg,val) in args: + if arg == "-f": + file_name = val + elif arg == "-m": + if val == "short": + long_string = 0 + elif val == "long": + long_string = 1 + else: + show_usage() + elif arg == "-c": + es = True + + api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory()) + printer = PrintGlProcs(long_string, es) + printer.Print(api) diff --git a/src/mesa/glapi/gen/gl_table.py b/src/mesa/glapi/gen/gl_table.py new file mode 100644 index 00000000000..3bd7569e92a --- /dev/null +++ b/src/mesa/glapi/gen/gl_table.py @@ -0,0 +1,229 @@ +#!/usr/bin/python2 + +# (C) Copyright IBM Corporation 2004 +# 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 +# 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. +# +# Authors: +# Ian Romanick + +import gl_XML +import license +import sys, getopt + +class PrintGlTable(gl_XML.gl_print_base): + def __init__(self, es=False): + gl_XML.gl_print_base.__init__(self) + + self.es = es + self.header_tag = '_GLAPI_TABLE_H_' + self.name = "gl_table.py (from Mesa)" + self.license = license.bsd_license_template % ( \ +"""Copyright (C) 1999-2003 Brian Paul All Rights Reserved. +(C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM") + return + + + def printBody(self, api): + for f in api.functionIterateByOffset(): + arg_string = f.get_parameter_string() + print ' %s (GLAPIENTRYP %s)(%s); /* %d */' % (f.return_type, f.name, arg_string, f.offset) + + + def printRealHeader(self): + print '#ifndef GLAPIENTRYP' + print '# ifndef GLAPIENTRY' + print '# define GLAPIENTRY' + print '# endif' + print '' + print '# define GLAPIENTRYP GLAPIENTRY *' + print '#endif' + print '' + print '' + print 'struct _glapi_table' + print '{' + return + + + def printRealFooter(self): + print '};' + return + + +class PrintRemapTable(gl_XML.gl_print_base): + def __init__(self, es=False): + gl_XML.gl_print_base.__init__(self) + + self.es = es + self.header_tag = '_GLAPI_DISPATCH_H_' + self.name = "gl_table.py (from Mesa)" + self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM") + return + + + def printRealHeader(self): + print """ +/* this file should not be included directly in mesa */ + +/** + * \\file glapidispatch.h + * Macros for handling GL dispatch tables. + * + * For each known GL function, there are 3 macros in this file. The first + * macro is named CALL_FuncName and is used to call that GL function using + * the specified dispatch table. The other 2 macros, called GET_FuncName + * can SET_FuncName, are used to get and set the dispatch pointer for the + * named function in the specified dispatch table. + */ +""" + + return + + def printBody(self, api): + print '#define CALL_by_offset(disp, cast, offset, parameters) \\' + print ' (*(cast (GET_by_offset(disp, offset)))) parameters' + print '#define GET_by_offset(disp, offset) \\' + print ' (offset >= 0) ? (((_glapi_proc *)(disp))[offset]) : NULL' + print '#define SET_by_offset(disp, offset, fn) \\' + print ' do { \\' + print ' if ( (offset) < 0 ) { \\' + print ' /* fprintf( stderr, "[%s:%u] SET_by_offset(%p, %d, %s)!\\n", */ \\' + print ' /* __func__, __LINE__, disp, offset, # fn); */ \\' + print ' /* abort(); */ \\' + print ' } \\' + print ' else { \\' + print ' ( (_glapi_proc *) (disp) )[offset] = (_glapi_proc) fn; \\' + print ' } \\' + print ' } while(0)' + print '' + + functions = [] + abi_functions = [] + alias_functions = [] + count = 0 + for f in api.functionIterateByOffset(): + if not f.is_abi(): + functions.append( [f, count] ) + count += 1 + else: + abi_functions.append( f ) + + if self.es: + # remember functions with aliases + if len(f.entry_points) > 1: + alias_functions.append(f) + + + for f in abi_functions: + print '#define CALL_%s(disp, parameters) (*((disp)->%s)) parameters' % (f.name, f.name) + print '#define GET_%s(disp) ((disp)->%s)' % (f.name, f.name) + print '#define SET_%s(disp, fn) ((disp)->%s = fn)' % (f.name, f.name) + + + print '' + print '#if !defined(_GLAPI_USE_REMAP_TABLE)' + print '' + + for [f, index] in functions: + print '#define CALL_%s(disp, parameters) (*((disp)->%s)) parameters' % (f.name, f.name) + print '#define GET_%s(disp) ((disp)->%s)' % (f.name, f.name) + print '#define SET_%s(disp, fn) ((disp)->%s = fn)' % (f.name, f.name) + + print '' + print '#else' + print '' + print '#define driDispatchRemapTable_size %u' % (count) + print 'extern int driDispatchRemapTable[ driDispatchRemapTable_size ];' + print '' + + for [f, index] in functions: + print '#define %s_remap_index %u' % (f.name, index) + + print '' + + for [f, index] in functions: + arg_string = gl_XML.create_parameter_string( f.parameters, 0 ) + cast = '%s (GLAPIENTRYP)(%s)' % (f.return_type, arg_string) + + print '#define CALL_%s(disp, parameters) CALL_by_offset(disp, (%s), driDispatchRemapTable[%s_remap_index], parameters)' % (f.name, cast, f.name) + print '#define GET_%s(disp) GET_by_offset(disp, driDispatchRemapTable[%s_remap_index])' % (f.name, f.name) + print '#define SET_%s(disp, fn) SET_by_offset(disp, driDispatchRemapTable[%s_remap_index], fn)' % (f.name, f.name) + + + print '' + print '#endif /* !defined(_GLAPI_USE_REMAP_TABLE) */' + + if alias_functions: + print '' + print '/* define aliases for compatibility */' + for f in alias_functions: + for name in f.entry_points: + if name != f.name: + print '#define CALL_%s(disp, parameters) CALL_%s(disp, parameters)' % (name, f.name) + print '#define GET_%s(disp) GET_%s(disp)' % (name, f.name) + print '#define SET_%s(disp, fn) SET_%s(disp, fn)' % (name, f.name) + print '' + + print '#if defined(_GLAPI_USE_REMAP_TABLE)' + for f in alias_functions: + for name in f.entry_points: + if name != f.name: + print '#define %s_remap_index %s_remap_index' % (name, f.name) + print '#endif /* defined(_GLAPI_USE_REMAP_TABLE) */' + print '' + + return + + +def show_usage(): + print "Usage: %s [-f input_file_name] [-m mode] [-c]" % sys.argv[0] + print " -m mode Mode can be 'table' or 'remap_table'." + print " -c Enable compatibility with OpenGL ES." + sys.exit(1) + +if __name__ == '__main__': + file_name = "gl_API.xml" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:m:c") + except Exception,e: + show_usage() + + mode = "table" + es = False + for (arg,val) in args: + if arg == "-f": + file_name = val + elif arg == "-m": + mode = val + elif arg == "-c": + es = True + + if mode == "table": + printer = PrintGlTable(es) + elif mode == "remap_table": + printer = PrintRemapTable(es) + else: + show_usage() + + api = gl_XML.parse_GL_API( file_name ) + + printer.Print( api ) diff --git a/src/mesa/glapi/gen/gl_x86-64_asm.py b/src/mesa/glapi/gen/gl_x86-64_asm.py new file mode 100644 index 00000000000..31c1a2b93a8 --- /dev/null +++ b/src/mesa/glapi/gen/gl_x86-64_asm.py @@ -0,0 +1,334 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2005 +# 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 +# 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. +# +# Authors: +# Ian Romanick + +import license +import gl_XML, glX_XML +import sys, getopt, copy + +def should_use_push(registers): + for [reg, offset] in registers: + if reg[1:4] == "xmm": + return 0 + + N = len(registers) + return (N & 1) != 0 + + +def local_size(registers): + # The x86-64 ABI says "the value (%rsp - 8) is always a multiple of + # 16 when control is transfered to the function entry point." This + # means that the local stack usage must be (16*N)+8 for some value + # of N. (16*N)+8 = (8*(2N))+8 = 8*(2N+1). As long as N is odd, we + # meet this requirement. + + N = (len(registers) | 1) + return 8*N + + +def save_all_regs(registers): + adjust_stack = 0 + if not should_use_push(registers): + adjust_stack = local_size(registers) + print '\tsubq\t$%u, %%rsp' % (adjust_stack) + + for [reg, stack_offset] in registers: + save_reg( reg, stack_offset, adjust_stack ) + return + + +def restore_all_regs(registers): + adjust_stack = 0 + if not should_use_push(registers): + adjust_stack = local_size(registers) + + temp = copy.deepcopy(registers) + while len(temp): + [reg, stack_offset] = temp.pop() + restore_reg(reg, stack_offset, adjust_stack) + + if adjust_stack: + print '\taddq\t$%u, %%rsp' % (adjust_stack) + return + + +def save_reg(reg, offset, use_move): + if use_move: + if offset == 0: + print '\tmovq\t%s, (%%rsp)' % (reg) + else: + print '\tmovq\t%s, %u(%%rsp)' % (reg, offset) + else: + print '\tpushq\t%s' % (reg) + + return + + +def restore_reg(reg, offset, use_move): + if use_move: + if offset == 0: + print '\tmovq\t(%%rsp), %s' % (reg) + else: + print '\tmovq\t%u(%%rsp), %s' % (offset, reg) + else: + print '\tpopq\t%s' % (reg) + + return + + +class PrintGenericStubs(gl_XML.gl_print_base): + + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + self.name = "gl_x86-64_asm.py (from Mesa)" + self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM") + return + + + def get_stack_size(self, f): + size = 0 + for p in f.parameterIterator(): + size += p.get_stack_size() + + return size + + + def printRealHeader(self): + print "/* If we build with gcc's -fvisibility=hidden flag, we'll need to change" + print " * the symbol visibility mode to 'default'." + print ' */' + print '' + print '#include "x86/assyntax.h"' + print '' + print '#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303' + print '# pragma GCC visibility push(default)' + print '# define HIDDEN(x) .hidden x' + print '#else' + print '# define HIDDEN(x)' + print '#endif' + print '' + print '# if defined(USE_MGL_NAMESPACE)' + print '# define GL_PREFIX(n) GLNAME(CONCAT(mgl,n))' + print '# define _glapi_Dispatch _mglapi_Dispatch' + print '# else' + print '# define GL_PREFIX(n) GLNAME(CONCAT(gl,n))' + print '# endif' + print '' + print '#if defined(PTHREADS) || defined(SOLARIS_THREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)' + print '# define THREADS' + print '#endif' + print '' + print '\t.text' + print '' + print '#ifdef GLX_USE_TLS' + print '' + print '\t.globl _x86_64_get_get_dispatch; HIDDEN(_x86_64_get_get_dispatch)' + print '_x86_64_get_get_dispatch:' + print '\tlea\t_x86_64_get_dispatch(%rip), %rax' + print '\tret' + print '' + print '\t.p2align\t4,,15' + print '_x86_64_get_dispatch:' + print '\tmovq\t_glapi_tls_Dispatch@GOTTPOFF(%rip), %rax' + print '\tmovq\t%fs:(%rax), %rax' + print '\tret' + print '\t.size\t_x86_64_get_dispatch, .-_x86_64_get_dispatch' + print '' + print '#elif defined(PTHREADS)' + print '' + print '\t.extern\t_glapi_Dispatch' + print '\t.extern\t_gl_DispatchTSD' + print '\t.extern\tpthread_getspecific' + print '' + print '\t.p2align\t4,,15' + print '_x86_64_get_dispatch:' + print '\tmovq\t_gl_DispatchTSD(%rip), %rdi' + print '\tjmp\tpthread_getspecific@PLT' + print '' + print '#elif defined(THREADS)' + print '' + print '\t.extern\t_glapi_get_dispatch' + print '' + print '#endif' + print '' + return + + + def printRealFooter(self): + print '' + print '#if defined(GLX_USE_TLS) && defined(__linux__)' + print ' .section ".note.ABI-tag", "a"' + print ' .p2align 2' + print ' .long 1f - 0f /* name length */' + print ' .long 3f - 2f /* data length */' + print ' .long 1 /* note length */' + print '0: .asciz "GNU" /* vendor name */' + print '1: .p2align 2' + print '2: .long 0 /* note data: the ABI tag */' + print ' .long 2,4,20 /* Minimum kernel version w/TLS */' + print '3: .p2align 2 /* pad out section */' + print '#endif /* GLX_USE_TLS */' + print '' + print '#if defined (__ELF__) && defined (__linux__)' + print ' .section .note.GNU-stack,"",%progbits' + print '#endif' + return + + + def printFunction(self, f): + + # The x86-64 ABI divides function parameters into a couple + # classes. For the OpenGL interface, the only ones that are + # relevent are INTEGER and SSE. Basically, the first 8 + # GLfloat or GLdouble parameters are placed in %xmm0 - %xmm7, + # the first 6 non-GLfloat / non-GLdouble parameters are placed + # in registers listed in int_parameters. + # + # If more parameters than that are required, they are passed + # on the stack. Therefore, we just have to make sure that + # %esp hasn't changed when we jump to the actual function. + # Since we're jumping to the function (and not calling it), we + # have to make sure of that anyway! + + int_parameters = ["%rdi", "%rsi", "%rdx", "%rcx", "%r8", "%r9"] + + int_class = 0 + sse_class = 0 + stack_offset = 0 + registers = [] + for p in f.parameterIterator(): + type_name = p.get_base_type_string() + + if p.is_pointer() or (type_name != "GLfloat" and type_name != "GLdouble"): + if int_class < 6: + registers.append( [int_parameters[int_class], stack_offset] ) + int_class += 1 + stack_offset += 8 + else: + if sse_class < 8: + registers.append( ["%%xmm%u" % (sse_class), stack_offset] ) + sse_class += 1 + stack_offset += 8 + + if ((int_class & 1) == 0) and (sse_class == 0): + registers.append( ["%rbp", 0] ) + + + name = f.dispatch_name() + + print '\t.p2align\t4,,15' + print '\t.globl\tGL_PREFIX(%s)' % (name) + print '\t.type\tGL_PREFIX(%s), @function' % (name) + if not f.is_static_entry_point(f.name): + print '\tHIDDEN(GL_PREFIX(%s))' % (name) + print 'GL_PREFIX(%s):' % (name) + print '#if defined(GLX_USE_TLS)' + print '\tcall\t_x86_64_get_dispatch@PLT' + print '\tmovq\t%u(%%rax), %%r11' % (f.offset * 8) + print '\tjmp\t*%r11' + print '#elif defined(PTHREADS)' + + save_all_regs(registers) + print '\tcall\t_x86_64_get_dispatch@PLT' + restore_all_regs(registers) + + if f.offset == 0: + print '\tmovq\t(%rax), %r11' + else: + print '\tmovq\t%u(%%rax), %%r11' % (f.offset * 8) + + print '\tjmp\t*%r11' + + print '#else' + print '\tmovq\t_glapi_Dispatch(%rip), %rax' + print '\ttestq\t%rax, %rax' + print '\tje\t1f' + print '\tmovq\t%u(%%rax), %%r11' % (f.offset * 8) + print '\tjmp\t*%r11' + print '1:' + + save_all_regs(registers) + print '\tcall\t_glapi_get_dispatch' + restore_all_regs(registers) + + print '\tmovq\t%u(%%rax), %%r11' % (f.offset * 8) + print '\tjmp\t*%r11' + print '#endif /* defined(GLX_USE_TLS) */' + + print '\t.size\tGL_PREFIX(%s), .-GL_PREFIX(%s)' % (name, name) + print '' + return + + + def printBody(self, api): + for f in api.functionIterateByOffset(): + self.printFunction(f) + + + for f in api.functionIterateByOffset(): + dispatch = f.dispatch_name() + for n in f.entry_points: + if n != f.name: + if f.is_static_entry_point(n): + text = '\t.globl GL_PREFIX(%s) ; .set GL_PREFIX(%s), GL_PREFIX(%s)' % (n, n, dispatch) + + if f.has_different_protocol(n): + print '#ifndef GLX_INDIRECT_RENDERING' + print text + print '#endif' + else: + print text + + return + +def show_usage(): + print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0] + sys.exit(1) + +if __name__ == '__main__': + file_name = "gl_API.xml" + mode = "generic" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "m:f:") + except Exception,e: + show_usage() + + for (arg,val) in args: + if arg == '-m': + mode = val + elif arg == "-f": + file_name = val + + if mode == "generic": + printer = PrintGenericStubs() + else: + print "ERROR: Invalid mode \"%s\" specified." % mode + show_usage() + + api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory()) + printer.Print(api) diff --git a/src/mesa/glapi/gen/gl_x86_asm.py b/src/mesa/glapi/gen/gl_x86_asm.py new file mode 100644 index 00000000000..d210f3a2481 --- /dev/null +++ b/src/mesa/glapi/gen/gl_x86_asm.py @@ -0,0 +1,270 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004, 2005 +# 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 +# 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. +# +# Authors: +# Ian Romanick + +import license +import gl_XML, glX_XML +import sys, getopt + +class PrintGenericStubs(gl_XML.gl_print_base): + + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + self.name = "gl_x86_asm.py (from Mesa)" + self.license = license.bsd_license_template % ( \ +"""Copyright (C) 1999-2001 Brian Paul All Rights Reserved. +(C) Copyright IBM Corporation 2004, 2005""", "BRIAN PAUL, IBM") + return + + + def get_stack_size(self, f): + size = 0 + for p in f.parameterIterator(): + if p.is_padding: + continue + + size += p.get_stack_size() + + return size + + + def printRealHeader(self): + print '#include "x86/assyntax.h"' + print '#include "glapi/glapioffsets.h"' + print '' + print '#if defined(STDCALL_API)' + print '# if defined(USE_MGL_NAMESPACE)' + print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n2))' + print '# else' + print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n2))' + print '# endif' + print '#else' + print '# if defined(USE_MGL_NAMESPACE)' + print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n))' + print '# define _glapi_Dispatch _mglapi_Dispatch' + print '# else' + print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n))' + print '# endif' + print '#endif' + print '' + print '#define GL_OFFSET(x) CODEPTR(REGOFF(4 * x, EAX))' + print '' + print '#if defined(GNU_ASSEMBLER) && !defined(__DJGPP__) && !defined(__MINGW32__) && !defined(__APPLE__)' + print '#define GLOBL_FN(x) GLOBL x ; .type x, function' + print '#else' + print '#define GLOBL_FN(x) GLOBL x' + print '#endif' + print '' + print '#if defined(PTHREADS) || defined(SOLARIS_THREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)' + print '# define THREADS' + print '#endif' + print '' + print '#ifdef GLX_USE_TLS' + print '' + print '#ifdef GLX_X86_READONLY_TEXT' + print '# define CTX_INSNS MOV_L(GS:(EAX), EAX)' + print '#else' + print '# define CTX_INSNS NOP /* Pad for init_glapi_relocs() */' + print '#endif' + print '' + print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\' + print 'ALIGNTEXT16;\t\t\t\t\t\t\\' + print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\' + print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\' + print '\tCALL(_x86_get_dispatch) ;\t\t\t\\' + print '\tCTX_INSNS ; \\' + print '\tJMP(GL_OFFSET(off))' + print '' + print '#elif defined(PTHREADS)' + print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\' + print 'ALIGNTEXT16;\t\t\t\t\t\t\\' + print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\' + print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\' + print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\' + print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\' + print '\tJE(1f) ;\t\t\t\t\t\\' + print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\' + print '1:\tCALL(_x86_get_dispatch) ;\t\t\t\\' + print '\tJMP(GL_OFFSET(off))' + print '#elif defined(THREADS)' + print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\' + print 'ALIGNTEXT16;\t\t\t\t\t\t\\' + print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\' + print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\' + print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\' + print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\' + print '\tJE(1f) ;\t\t\t\t\t\\' + print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\' + print '1:\tCALL(_glapi_get_dispatch) ;\t\t\t\\' + print '\tJMP(GL_OFFSET(off))' + print '#else /* Non-threaded version. */' + print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\' + print 'ALIGNTEXT16;\t\t\t\t\t\t\\' + print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\' + print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\' + print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\' + print '\tJMP(GL_OFFSET(off))' + print '#endif' + print '' + print '#ifdef HAVE_ALIAS' + print '# define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt)\t\\' + print '\t.globl\tGL_PREFIX(fn, fn_alt) ;\t\t\t\\' + print '\t.set\tGL_PREFIX(fn, fn_alt), GL_PREFIX(alias, alias_alt)' + print '#else' + print '# define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt)\t\\' + print ' GL_STUB(fn, off, fn_alt)' + print '#endif' + print '' + print 'SEG_TEXT' + print '' + print '#ifdef GLX_USE_TLS' + print '' + print '\tGLOBL\tGLNAME(_x86_get_dispatch)' + print '\tHIDDEN(GLNAME(_x86_get_dispatch))' + print 'ALIGNTEXT16' + print 'GLNAME(_x86_get_dispatch):' + print '\tcall 1f' + print '1:\tpopl %eax' + print '\taddl $_GLOBAL_OFFSET_TABLE_+[.-1b], %eax' + print '\tmovl _glapi_tls_Dispatch@GOTNTPOFF(%eax), %eax' + print '\tret' + print '' + print '#elif defined(PTHREADS)' + print 'EXTERN GLNAME(_glapi_Dispatch)' + print 'EXTERN GLNAME(_gl_DispatchTSD)' + print 'EXTERN GLNAME(pthread_getspecific)' + print '' + print 'ALIGNTEXT16' + print 'GLNAME(_x86_get_dispatch):' + print '\tSUB_L(CONST(24), ESP)' + print '\tPUSH_L(GLNAME(_gl_DispatchTSD))' + print '\tCALL(GLNAME(pthread_getspecific))' + print '\tADD_L(CONST(28), ESP)' + print '\tRET' + print '#elif defined(THREADS)' + print 'EXTERN GLNAME(_glapi_get_dispatch)' + print '#endif' + print '' + + print '#if defined( GLX_USE_TLS ) && !defined( GLX_X86_READONLY_TEXT )' + print '\t\t.section\twtext, "awx", @progbits' + print '#endif /* defined( GLX_USE_TLS ) */' + + print '' + print '\t\tALIGNTEXT16' + print '\t\tGLOBL GLNAME(gl_dispatch_functions_start)' + print '\t\tHIDDEN(GLNAME(gl_dispatch_functions_start))' + print 'GLNAME(gl_dispatch_functions_start):' + print '' + return + + + def printRealFooter(self): + print '' + print '\t\tGLOBL\tGLNAME(gl_dispatch_functions_end)' + print '\t\tHIDDEN(GLNAME(gl_dispatch_functions_end))' + print '\t\tALIGNTEXT16' + print 'GLNAME(gl_dispatch_functions_end):' + print '' + print '#if defined(GLX_USE_TLS) && defined(__linux__)' + print ' .section ".note.ABI-tag", "a"' + print ' .p2align 2' + print ' .long 1f - 0f /* name length */' + print ' .long 3f - 2f /* data length */' + print ' .long 1 /* note length */' + print '0: .asciz "GNU" /* vendor name */' + print '1: .p2align 2' + print '2: .long 0 /* note data: the ABI tag */' + print ' .long 2,4,20 /* Minimum kernel version w/TLS */' + print '3: .p2align 2 /* pad out section */' + print '#endif /* GLX_USE_TLS */' + print '' + print '#if defined (__ELF__) && defined (__linux__)' + print ' .section .note.GNU-stack,"",%progbits' + print '#endif' + return + + + def printBody(self, api): + for f in api.functionIterateByOffset(): + name = f.dispatch_name() + stack = self.get_stack_size(f) + alt = "%s@%u" % (name, stack) + + print '\tGL_STUB(%s, _gloffset_%s, %s)' % (name, f.name, alt) + + if not f.is_static_entry_point(f.name): + print '\tHIDDEN(GL_PREFIX(%s, %s))' % (name, alt) + + + for f in api.functionIterateByOffset(): + name = f.dispatch_name() + stack = self.get_stack_size(f) + alt = "%s@%u" % (name, stack) + + if f.is_static_entry_point(f.name): + for n in f.entry_points: + if n != f.name: + alt2 = "%s@%u" % (n, stack) + text = '\tGL_STUB_ALIAS(%s, _gloffset_%s, %s, %s, %s)' % (n, f.name, alt2, f.name, alt) + + if f.has_different_protocol(n): + print '#ifndef GLX_INDIRECT_RENDERING' + print text + print '#endif' + else: + print text + + return + +def show_usage(): + print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0] + sys.exit(1) + +if __name__ == '__main__': + file_name = "gl_API.xml" + mode = "generic" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "m:f:") + except Exception,e: + show_usage() + + for (arg,val) in args: + if arg == '-m': + mode = val + elif arg == "-f": + file_name = val + + if mode == "generic": + printer = PrintGenericStubs() + else: + print "ERROR: Invalid mode \"%s\" specified." % mode + show_usage() + + api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory()) + printer.Print(api) diff --git a/src/mesa/glapi/gen/license.py b/src/mesa/glapi/gen/license.py new file mode 100644 index 00000000000..02181648e4b --- /dev/null +++ b/src/mesa/glapi/gen/license.py @@ -0,0 +1,47 @@ +# (C) Copyright IBM Corporation 2004 +# 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 +# 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. +# +# Authors: +# Ian Romanick + +bsd_license_template = """%s +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, 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 +%s, +AND/OR THEIR 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.""" diff --git a/src/mesa/glapi/gen/mesadef.py b/src/mesa/glapi/gen/mesadef.py new file mode 100644 index 00000000000..38b0246ba5b --- /dev/null +++ b/src/mesa/glapi/gen/mesadef.py @@ -0,0 +1,216 @@ +#!/usr/bin/env python + + +# Mesa 3-D graphics library +# Version: 4.1 +# +# 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 +# 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. + + +# Generate the mesa.def file for Windows. +# +# Usage: +# mesadef.py >mesa.def +# Then copy to src/mesa/drivers/windows/gdi +# +# Dependencies: +# The apispec file must be in the current directory. + + + +import apiparser +import string + + +def PrintHead(): + print '; DO NOT EDIT - This file generated automatically by mesadef.py script' + print 'DESCRIPTION \'Mesa (OpenGL work-alike) for Win32\'' + print 'VERSION 6.0' + print ';' + print '; Module definition file for Mesa (OPENGL32.DLL)' + print ';' + print '; Note: The OpenGL functions use the STDCALL' + print '; function calling convention. Microsoft\'s' + print '; OPENGL32 uses this convention and so must the' + print '; Mesa OPENGL32 so that the Mesa DLL can be used' + print '; as a drop-in replacement.' + print ';' + print '; The linker exports STDCALL entry points with' + print '; \'decorated\' names; e.g., _glBegin@0, where the' + print '; trailing number is the number of bytes of ' + print '; parameter data pushed onto the stack. The' + print '; callee is responsible for popping this data' + print '; off the stack, usually via a RETF n instruction.' + print ';' + print '; However, the Microsoft OPENGL32.DLL does not export' + print '; the decorated names, even though the calling convention' + print '; is STDCALL. So, this module definition file is' + print '; needed to force the Mesa OPENGL32.DLL to export the' + print '; symbols in the same manner as the Microsoft DLL.' + print '; Were it not for this problem, this file would not' + print '; be needed (for the gl* functions) since the entry' + print '; points are compiled with dllexport declspec.' + print ';' + print '; However, this file is still needed to export "internal"' + print '; Mesa symbols for the benefit of the OSMESA32.DLL.' + print ';' + print 'EXPORTS' + return +#enddef + + +def PrintTail(): + print ';' + print '; WGL API' + print '\twglChoosePixelFormat' + print '\twglCopyContext' + print '\twglCreateContext' + print '\twglCreateLayerContext' + print '\twglDeleteContext' + print '\twglDescribeLayerPlane' + print '\twglDescribePixelFormat' + print '\twglGetCurrentContext' + print '\twglGetCurrentDC' + print '\twglGetExtensionsStringARB' + print '\twglGetLayerPaletteEntries' + print '\twglGetPixelFormat' + print '\twglGetProcAddress' + print '\twglMakeCurrent' + print '\twglRealizeLayerPalette' + print '\twglSetLayerPaletteEntries' + print '\twglSetPixelFormat' + print '\twglShareLists' + print '\twglSwapBuffers' + print '\twglSwapLayerBuffers' + print '\twglUseFontBitmapsA' + print '\twglUseFontBitmapsW' + print '\twglUseFontOutlinesA' + print '\twglUseFontOutlinesW' + print ';' + print '; Mesa internals - mostly for OSMESA' + print '\t_ac_CreateContext' + print '\t_ac_DestroyContext' + print '\t_ac_InvalidateState' + print '\t_glapi_get_context' + print '\t_glapi_get_proc_address' + print '\t_mesa_buffer_data' + print '\t_mesa_buffer_map' + print '\t_mesa_buffer_subdata' + print '\t_mesa_choose_tex_format' + print '\t_mesa_compressed_texture_size' + print '\t_mesa_create_framebuffer' + print '\t_mesa_create_visual' + print '\t_mesa_delete_buffer_object' + print '\t_mesa_delete_texture_object' + print '\t_mesa_destroy_framebuffer' + print '\t_mesa_destroy_visual' + print '\t_mesa_enable_1_3_extensions' + print '\t_mesa_enable_1_4_extensions' + print '\t_mesa_enable_1_5_extensions' + print '\t_mesa_enable_sw_extensions' + print '\t_mesa_error' + print '\t_mesa_free_context_data' + print '\t_mesa_get_current_context' + print '\t_mesa_init_default_imports' + print '\t_mesa_initialize_context' + print '\t_mesa_make_current' + print '\t_mesa_new_buffer_object' + print '\t_mesa_new_texture_object' + print '\t_mesa_problem' + print '\t_mesa_ResizeBuffersMESA' + print '\t_mesa_store_compressed_teximage1d' + print '\t_mesa_store_compressed_teximage2d' + print '\t_mesa_store_compressed_teximage3d' + print '\t_mesa_store_compressed_texsubimage1d' + print '\t_mesa_store_compressed_texsubimage2d' + print '\t_mesa_store_compressed_texsubimage3d' + print '\t_mesa_store_teximage1d' + print '\t_mesa_store_teximage2d' + print '\t_mesa_store_teximage3d' + print '\t_mesa_store_texsubimage1d' + print '\t_mesa_store_texsubimage2d' + print '\t_mesa_store_texsubimage3d' + print '\t_mesa_test_proxy_teximage' + print '\t_mesa_Viewport' + print '\t_mesa_meta_CopyColorSubTable' + print '\t_mesa_meta_CopyColorTable' + print '\t_mesa_meta_CopyConvolutionFilter1D' + print '\t_mesa_meta_CopyConvolutionFilter2D' + print '\t_mesa_meta_CopyTexImage1D' + print '\t_mesa_meta_CopyTexImage2D' + print '\t_mesa_meta_CopyTexSubImage1D' + print '\t_mesa_meta_CopyTexSubImage2D' + print '\t_mesa_meta_CopyTexSubImage3D' + print '\t_swrast_Accum' + print '\t_swrast_alloc_buffers' + print '\t_swrast_Bitmap' + print '\t_swrast_CopyPixels' + print '\t_swrast_DrawPixels' + print '\t_swrast_GetDeviceDriverReference' + print '\t_swrast_Clear' + print '\t_swrast_choose_line' + print '\t_swrast_choose_triangle' + print '\t_swrast_CreateContext' + print '\t_swrast_DestroyContext' + print '\t_swrast_InvalidateState' + print '\t_swrast_ReadPixels' + print '\t_swrast_zbuffer_address' + print '\t_swsetup_Wakeup' + print '\t_swsetup_CreateContext' + print '\t_swsetup_DestroyContext' + print '\t_swsetup_InvalidateState' + print '\t_tnl_CreateContext' + print '\t_tnl_DestroyContext' + print '\t_tnl_InvalidateState' + print '\t_tnl_MakeCurrent' + print '\t_tnl_run_pipeline' +#enddef + + +records = [] + +def FindOffset(funcName): + for (name, alias, offset) in records: + if name == funcName: + return offset + #endif + #endfor + return -1 +#enddef + + +def EmitEntry(name, returnType, argTypeList, argNameList, alias, offset): + if alias == '': + dispatchName = name + else: + dispatchName = alias + if offset < 0: + offset = FindOffset(dispatchName) + if offset >= 0 and string.find(name, "unused") == -1: + print '\tgl%s' % (name) + # save this info in case we need to look up an alias later + records.append((name, dispatchName, offset)) + +#enddef + + +PrintHead() +apiparser.ProcessSpecFile("APIspec", EmitEntry) +PrintTail() diff --git a/src/mesa/glapi/gen/next_available_offset.sh b/src/mesa/glapi/gen/next_available_offset.sh new file mode 100755 index 00000000000..e7d6c2f4afa --- /dev/null +++ b/src/mesa/glapi/gen/next_available_offset.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# +# (C) Copyright IBM Corporation 2004 +# 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 +# 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. +# +# Authors: +# Ian Romanick + +# Trivial shell script to search the API definition file and print out the +# next numerically available API entry-point offset. This could probably +# be made smarter, but it would be better to use the existin Python +# framework to do that. This is just a quick-and-dirty hack. + +num=$(grep 'offset="' gl_API.xml |\ + sed 's/.\+ offset="//g;s/".*$//g' |\ + grep -v '?' |\ + sort -rn |\ + head -1) + +echo $((num + 1)) diff --git a/src/mesa/glapi/gen/remap_helper.py b/src/mesa/glapi/gen/remap_helper.py new file mode 100644 index 00000000000..d93c7a42855 --- /dev/null +++ b/src/mesa/glapi/gen/remap_helper.py @@ -0,0 +1,226 @@ +#!/usr/bin/env python + +# Copyright (C) 2009 Chia-I Wu +# 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 ", "Chia-I Wu") + return + + + def printRealHeader(self): + print '#include "glapi/dispatch.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 '' + + # collect functions by versions/extensions + extension_functions = {} + abi_extensions = [] + for f in api.functionIterateAll(): + for n in f.entry_points: + category, num = api.get_category_for_name(n) + # consider only GL_VERSION_X_Y or extensions + c = gl_XML.real_category_name(category) + if c.startswith("GL_"): + if not extension_functions.has_key(c): + extension_functions[c] = [] + extension_functions[c].append(f) + # remember the ext names of the ABI + if (f.is_abi() and n == f.name and + c not in abi_extensions): + abi_extensions.append(c) + # ignore the ABI itself + for ext in abi_extensions: + extension_functions.pop(ext) + + 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 and has alt names + if f.is_abi() and len(f.entry_points) > 1: + 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 ) diff --git a/src/mesa/glapi/gen/typeexpr.py b/src/mesa/glapi/gen/typeexpr.py new file mode 100644 index 00000000000..8ba7de48627 --- /dev/null +++ b/src/mesa/glapi/gen/typeexpr.py @@ -0,0 +1,292 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2005 +# 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 +# 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. +# +# Authors: +# Ian Romanick + +import string, copy + +class type_node: + def __init__(self): + self.pointer = 0 # bool + self.const = 0 # bool + self.signed = 1 # bool + self.integer = 1 # bool + + # If elements is set to non-zero, then field is an array. + self.elements = 0 + + self.name = None + self.size = 0 # type's size in bytes + return + + + def string(self): + """Return string representation of this type_node.""" + s = "" + + if self.pointer: + s = "* " + + if self.const: + s += "const " + + if not self.pointer: + if self.integer: + if self.signed: + s += "signed " + else: + s += "unsigned " + + if self.name: + s += "%s " % (self.name) + + return s + + +class type_table: + def __init__(self): + self.types_by_name = {} + return + + + def add_type(self, type_expr): + self.types_by_name[ type_expr.get_base_name() ] = type_expr + return + + + def find_type(self, name): + if name in self.types_by_name: + return self.types_by_name[ name ] + else: + return None + + +def create_initial_types(): + tt = type_table() + + basic_types = [ + ("char", 1, 1), + ("short", 2, 1), + ("int", 4, 1), + ("long", 4, 1), + ("float", 4, 0), + ("double", 8, 0), + ("enum", 4, 1) + ] + + for (type_name, type_size, integer) in basic_types: + te = type_expression(None) + tn = type_node() + tn.name = type_name + tn.size = type_size + tn.integer = integer + te.expr.append(tn) + tt.add_type( te ) + + type_expression.built_in_types = tt + return + + +class type_expression: + built_in_types = None + + def __init__(self, type_string, extra_types = None): + self.expr = [] + + if not type_string: + return + + self.original_string = type_string + + if not type_expression.built_in_types: + raise RuntimeError("create_initial_types must be called before creating type_expression objects.") + + # Replace '*' with ' * ' in type_string. Then, split the string + # into tokens, separated by spaces. + tokens = string.split( string.replace( type_string, "*", " * " ) ) + + const = 0 + t = None + signed = 0 + unsigned = 0 + + for i in tokens: + if i == "const": + if t and t.pointer: + t.const = 1 + else: + const = 1 + elif i == "signed": + signed = 1 + elif i == "unsigned": + unsigned = 1 + elif i == "*": + # This is a quirky special-case because of the + # way the C works for types. If 'unsigned' is + # specified all by itself, it is treated the + # same as "unsigned int". + + if unsigned: + self.set_base_type( "int", signed, unsigned, const, extra_types ) + const = 0 + signed = 0 + unsigned = 0 + + if not self.expr: + raise RuntimeError("Invalid type expression (dangling pointer)") + + if signed: + raise RuntimeError("Invalid type expression (signed / unsigned applied to pointer)") + + t = type_node() + t.pointer = 1 + self.expr.append( t ) + else: + if self.expr: + raise RuntimeError('Invalid type expression (garbage after pointer qualifier -> "%s")' % (self.original_string)) + + self.set_base_type( i, signed, unsigned, const, extra_types ) + const = 0 + signed = 0 + unsigned = 0 + + if signed and unsigned: + raise RuntimeError("Invalid type expression (both signed and unsigned specified)") + + + if const: + raise RuntimeError("Invalid type expression (dangling const)") + + if unsigned: + raise RuntimeError("Invalid type expression (dangling signed)") + + if signed: + raise RuntimeError("Invalid type expression (dangling unsigned)") + + return + + + def set_base_type(self, type_name, signed, unsigned, const, extra_types): + te = type_expression.built_in_types.find_type( type_name ) + if not te: + te = extra_types.find_type( type_name ) + + if not te: + raise RuntimeError('Unknown base type "%s".' % (type_name)) + + self.expr = copy.deepcopy(te.expr) + + t = self.expr[ len(self.expr) - 1 ] + t.const = const + if signed: + t.signed = 1 + elif unsigned: + t.signed = 0 + + + def set_base_type_node(self, tn): + self.expr = [tn] + return + + + def set_elements(self, count): + tn = self.expr[0] + + tn.elements = count + return + + + def string(self): + s = "" + for t in self.expr: + s += t.string() + + return s + + + def get_base_type_node(self): + return self.expr[0] + + + def get_base_name(self): + if len(self.expr): + return self.expr[0].name + else: + return None + + + def get_element_size(self): + tn = self.expr[0] + + if tn.elements: + return tn.elements * tn.size + else: + return tn.size + + + def get_element_count(self): + tn = self.expr[0] + return tn.elements + + + def get_stack_size(self): + tn = self.expr[ len(self.expr) - 1 ] + + if tn.elements or tn.pointer: + return 4 + elif not tn.integer: + return tn.size + else: + return 4 + + + def is_pointer(self): + tn = self.expr[ len(self.expr) - 1 ] + return tn.pointer + + + def format_string(self): + tn = self.expr[ len(self.expr) - 1 ] + if tn.pointer: + return "%p" + elif not tn.integer: + return "%f" + else: + return "%d" + + + +if __name__ == '__main__': + + types_to_try = [ "int", "int *", "const int *", "int * const", "const int * const", \ + "unsigned * const *", \ + "float", "const double", "double * const"] + + create_initial_types() + + for t in types_to_try: + print 'Trying "%s"...' % (t) + te = type_expression( t ) + print 'Got "%s" (%u, %u).' % (te.string(), te.get_stack_size(), te.get_element_size()) diff --git a/src/mesa/glapi/glX_API.xml b/src/mesa/glapi/glX_API.xml deleted file mode 100644 index 9e02aa498ee..00000000000 --- a/src/mesa/glapi/glX_API.xml +++ /dev/null @@ -1,220 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/mesa/glapi/glX_XML.py b/src/mesa/glapi/glX_XML.py deleted file mode 100644 index 4c2e0f95bf4..00000000000 --- a/src/mesa/glapi/glX_XML.py +++ /dev/null @@ -1,570 +0,0 @@ -#!/usr/bin/env python - -# (C) Copyright IBM Corporation 2004, 2005 -# 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 -# 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. -# -# Authors: -# Ian Romanick - -import gl_XML -import license -import sys, getopt, string - - -class glx_item_factory(gl_XML.gl_item_factory): - """Factory to create GLX protocol oriented objects derived from gl_item.""" - - def create_item(self, name, element, context): - if name == "function": - return glx_function(element, context) - elif name == "enum": - return glx_enum(element, context) - elif name == "api": - return glx_api(self) - else: - return gl_XML.gl_item_factory.create_item(self, name, element, context) - - -class glx_enum(gl_XML.gl_enum): - def __init__(self, element, context): - gl_XML.gl_enum.__init__(self, element, context) - - self.functions = {} - - child = element.children - while child: - if child.type == "element" and child.name == "size": - n = child.nsProp( "name", None ) - c = child.nsProp( "count", None ) - m = child.nsProp( "mode", None ) - - if not c: - c = self.default_count - else: - c = int(c) - - if m == "get": - mode = 0 - else: - mode = 1 - - if not self.functions.has_key(n): - self.functions[ n ] = [c, mode] - - child = child.next - - return - - -class glx_function(gl_XML.gl_function): - def __init__(self, element, context): - self.glx_rop = 0 - self.glx_sop = 0 - self.glx_vendorpriv = 0 - - self.glx_vendorpriv_names = [] - - # If this is set to true, it means that GLdouble parameters should be - # written to the GLX protocol packet in the order they appear in the - # prototype. This is different from the "classic" ordering. In the - # classic ordering GLdoubles are written to the protocol packet first, - # followed by non-doubles. NV_vertex_program was the first extension - # to break with this tradition. - - self.glx_doubles_in_order = 0 - - self.vectorequiv = None - self.output = None - self.can_be_large = 0 - self.reply_always_array = 0 - self.dimensions_in_reply = 0 - self.img_reset = None - - self.server_handcode = 0 - self.client_handcode = 0 - self.ignore = 0 - - self.count_parameter_list = [] - self.counter_list = [] - self.parameters_by_name = {} - self.offsets_calculated = 0 - - gl_XML.gl_function.__init__(self, element, context) - return - - - def process_element(self, element): - gl_XML.gl_function.process_element(self, element) - - # If the function already has a vector equivalent set, don't - # set it again. This can happen if an alias to a function - # appears after the function that it aliases. - - if not self.vectorequiv: - self.vectorequiv = element.nsProp("vectorequiv", None) - - - name = element.nsProp("name", None) - if name == self.name: - for param in self.parameters: - self.parameters_by_name[ param.name ] = param - - if len(param.count_parameter_list): - self.count_parameter_list.extend( param.count_parameter_list ) - - if param.counter and param.counter not in self.counter_list: - self.counter_list.append(param.counter) - - - child = element.children - while child: - if child.type == "element" and child.name == "glx": - rop = child.nsProp( 'rop', None ) - sop = child.nsProp( 'sop', None ) - vop = child.nsProp( 'vendorpriv', None ) - - if rop: - self.glx_rop = int(rop) - - if sop: - self.glx_sop = int(sop) - - if vop: - self.glx_vendorpriv = int(vop) - self.glx_vendorpriv_names.append(name) - - self.img_reset = child.nsProp( 'img_reset', None ) - - # The 'handcode' attribute can be one of 'true', - # 'false', 'client', or 'server'. - - handcode = child.nsProp( 'handcode', None ) - if handcode == "false": - self.server_handcode = 0 - self.client_handcode = 0 - elif handcode == "true": - self.server_handcode = 1 - self.client_handcode = 1 - elif handcode == "client": - self.server_handcode = 0 - self.client_handcode = 1 - elif handcode == "server": - self.server_handcode = 1 - self.client_handcode = 0 - else: - raise RuntimeError('Invalid handcode mode "%s" in function "%s".' % (handcode, self.name)) - - self.ignore = gl_XML.is_attr_true( child, 'ignore' ) - self.can_be_large = gl_XML.is_attr_true( child, 'large' ) - self.glx_doubles_in_order = gl_XML.is_attr_true( child, 'doubles_in_order' ) - self.reply_always_array = gl_XML.is_attr_true( child, 'always_array' ) - self.dimensions_in_reply = gl_XML.is_attr_true( child, 'dimensions_in_reply' ) - - child = child.next - - - # Do some validation of the GLX protocol information. As - # new tests are discovered, they should be added here. - - for param in self.parameters: - if param.is_output and self.glx_rop != 0: - raise RuntimeError("Render / RenderLarge commands cannot have outputs (%s)." % (self.name)) - - return - - - def has_variable_size_request(self): - """Determine if the GLX request packet is variable sized. - - The GLX request packet is variable sized in several common - situations. - - 1. The function has a non-output parameter that is counted - by another parameter (e.g., the 'textures' parameter of - glDeleteTextures). - - 2. The function has a non-output parameter whose count is - determined by another parameter that is an enum (e.g., the - 'params' parameter of glLightfv). - - 3. The function has a non-output parameter that is an - image. - - 4. The function must be hand-coded on the server. - """ - - if self.glx_rop == 0: - return 0 - - if self.server_handcode or self.images: - return 1 - - for param in self.parameters: - if not param.is_output: - if param.counter or len(param.count_parameter_list): - return 1 - - return 0 - - - def variable_length_parameter(self): - for param in self.parameters: - if not param.is_output: - if param.counter or len(param.count_parameter_list): - return param - - return None - - - def calculate_offsets(self): - if not self.offsets_calculated: - # Calculate the offset of the first function parameter - # in the GLX command packet. This byte offset is - # measured from the end of the Render / RenderLarge - # header. The offset for all non-pixel commends is - # zero. The offset for pixel commands depends on the - # number of dimensions of the pixel data. - - if len(self.images) and not self.images[0].is_output: - [dim, junk, junk, junk, junk] = self.images[0].get_dimensions() - - # The base size is the size of the pixel pack info - # header used by images with the specified number - # of dimensions. - - if dim <= 2: - offset = 20 - elif dim <= 4: - offset = 36 - else: - raise RuntimeError('Invalid number of dimensions %u for parameter "%s" in function "%s".' % (dim, self.image.name, self.name)) - else: - offset = 0 - - for param in self.parameterIterateGlxSend(): - if param.img_null_flag: - offset += 4 - - if param.name != self.img_reset: - param.offset = offset - if not param.is_variable_length() and not param.is_client_only: - offset += param.size() - - if self.pad_after( param ): - offset += 4 - - - self.offsets_calculated = 1 - return - - - def offset_of(self, param_name): - self.calculate_offsets() - return self.parameters_by_name[ param_name ].offset - - - def parameterIterateGlxSend(self, include_variable_parameters = 1): - """Create an iterator for parameters in GLX request order.""" - - # The parameter lists are usually quite short, so it's easier - # (i.e., less code) to just generate a new list with the - # required elements than it is to create a new iterator class. - - temp = [ [], [], [] ] - for param in self.parameters: - if param.is_output: continue - - if param.is_variable_length(): - temp[2].append( param ) - elif not self.glx_doubles_in_order and param.is_64_bit(): - temp[0].append( param ) - else: - temp[1].append( param ) - - parameters = temp[0] - parameters.extend( temp[1] ) - if include_variable_parameters: - parameters.extend( temp[2] ) - return parameters.__iter__() - - - def parameterIterateCounters(self): - temp = [] - for name in self.counter_list: - temp.append( self.parameters_by_name[ name ] ) - - return temp.__iter__() - - - def parameterIterateOutputs(self): - temp = [] - for p in self.parameters: - if p.is_output: - temp.append( p ) - - return temp - - - def command_fixed_length(self): - """Return the length, in bytes as an integer, of the - fixed-size portion of the command.""" - - if len(self.parameters) == 0: - return 0 - - self.calculate_offsets() - - size = 0 - for param in self.parameterIterateGlxSend(0): - if param.name != self.img_reset and not param.is_client_only: - if size == 0: - size = param.offset + param.size() - else: - size += param.size() - - if self.pad_after( param ): - size += 4 - - for param in self.images: - if param.img_null_flag or param.is_output: - size += 4 - - return size - - - def command_variable_length(self): - """Return the length, as a string, of the variable-sized - portion of the command.""" - - size_string = "" - for p in self.parameterIterateGlxSend(): - if (not p.is_output) and (p.is_variable_length() or p.is_image()): - # FIXME Replace the 1 in the size_string call - # FIXME w/0 to eliminate some un-needed parnes - # FIXME This would already be done, but it - # FIXME adds some extra diffs to the generated - # FIXME code. - - size_string = size_string + " + __GLX_PAD(%s)" % (p.size_string(1)) - - return size_string - - - def command_length(self): - size = self.command_fixed_length() - - if self.glx_rop != 0: - size += 4 - - size = ((size + 3) & ~3) - return "%u%s" % (size, self.command_variable_length()) - - - def opcode_real_value(self): - """Get the true numeric value of the GLX opcode - - Behaves similarly to opcode_value, except for - X_GLXVendorPrivate and X_GLXVendorPrivateWithReply commands. - In these cases the value for the GLX opcode field (i.e., - 16 for X_GLXVendorPrivate or 17 for - X_GLXVendorPrivateWithReply) is returned. For other 'single' - commands, the opcode for the command (e.g., 101 for - X_GLsop_NewList) is returned.""" - - if self.glx_vendorpriv != 0: - if self.needs_reply(): - return 17 - else: - return 16 - else: - return self.opcode_value() - - - def opcode_value(self): - """Get the unique protocol opcode for the glXFunction""" - - if (self.glx_rop == 0) and self.vectorequiv: - equiv = self.context.functions_by_name[ self.vectorequiv ] - self.glx_rop = equiv.glx_rop - - - if self.glx_rop != 0: - return self.glx_rop - elif self.glx_sop != 0: - return self.glx_sop - elif self.glx_vendorpriv != 0: - return self.glx_vendorpriv - else: - return -1 - - - def opcode_rop_basename(self): - """Return either the name to be used for GLX protocol enum. - - Returns either the name of the function or the name of the - name of the equivalent vector (e.g., glVertex3fv for - glVertex3f) function.""" - - if self.vectorequiv == None: - return self.name - else: - return self.vectorequiv - - - def opcode_name(self): - """Get the unique protocol enum name for the glXFunction""" - - if (self.glx_rop == 0) and self.vectorequiv: - equiv = self.context.functions_by_name[ self.vectorequiv ] - self.glx_rop = equiv.glx_rop - self.glx_doubles_in_order = equiv.glx_doubles_in_order - - - if self.glx_rop != 0: - return "X_GLrop_%s" % (self.opcode_rop_basename()) - elif self.glx_sop != 0: - return "X_GLsop_%s" % (self.name) - elif self.glx_vendorpriv != 0: - return "X_GLvop_%s" % (self.name) - else: - raise RuntimeError('Function "%s" has no opcode.' % (self.name)) - - - def opcode_vendor_name(self, name): - if name in self.glx_vendorpriv_names: - return "X_GLvop_%s" % (name) - else: - raise RuntimeError('Function "%s" has no VendorPrivate opcode.' % (name)) - - - def opcode_real_name(self): - """Get the true protocol enum name for the GLX opcode - - Behaves similarly to opcode_name, except for - X_GLXVendorPrivate and X_GLXVendorPrivateWithReply commands. - In these cases the string 'X_GLXVendorPrivate' or - 'X_GLXVendorPrivateWithReply' is returned. For other - single or render commands 'X_GLsop' or 'X_GLrop' plus the - name of the function returned.""" - - if self.glx_vendorpriv != 0: - if self.needs_reply(): - return "X_GLXVendorPrivateWithReply" - else: - return "X_GLXVendorPrivate" - else: - return self.opcode_name() - - - def needs_reply(self): - try: - x = self._needs_reply - except Exception, e: - x = 0 - if self.return_type != 'void': - x = 1 - - for param in self.parameters: - if param.is_output: - x = 1 - break - - self._needs_reply = x - - return x - - - def pad_after(self, p): - """Returns the name of the field inserted after the - specified field to pad out the command header.""" - - for image in self.images: - if image.img_pad_dimensions: - if not image.height: - if p.name == image.width: - return "height" - elif p.name == image.img_xoff: - return "yoffset" - elif not image.extent: - if p.name == image.depth: - # Should this be "size4d"? - return "extent" - elif p.name == image.img_zoff: - return "woffset" - - return None - - - def has_different_protocol(self, name): - """Returns true if the named version of the function uses different protocol from the other versions. - - Some functions, such as glDeleteTextures and - glDeleteTexturesEXT are functionally identical, but have - different protocol. This function returns true if the - named function is an alias name and that named version uses - different protocol from the function that is aliased. - """ - - return (name in self.glx_vendorpriv_names) and self.glx_sop - - - def static_glx_name(self, name): - if self.has_different_protocol(name): - for n in self.glx_vendorpriv_names: - if n in self.static_entry_points: - return n - - return self.static_name(name) - - - def client_supported_for_indirect(self): - """Returns true if the function is supported on the client - side for indirect rendering.""" - - return not self.ignore and (self.offset != -1) and (self.glx_rop or self.glx_sop or self.glx_vendorpriv or self.vectorequiv or self.client_handcode) - - -class glx_function_iterator: - """Class to iterate over a list of glXFunctions""" - - def __init__(self, context): - self.iterator = context.functionIterateByOffset() - return - - - def __iter__(self): - return self - - - def next(self): - f = self.iterator.next() - - if f.client_supported_for_indirect(): - return f - else: - return self.next() - - -class glx_api(gl_XML.gl_api): - def functionIterateGlx(self): - return glx_function_iterator(self) - diff --git a/src/mesa/glapi/glX_doc.py b/src/mesa/glapi/glX_doc.py deleted file mode 100644 index e9fbbe6f169..00000000000 --- a/src/mesa/glapi/glX_doc.py +++ /dev/null @@ -1,280 +0,0 @@ -#!/usr/bin/env python - -# (C) Copyright IBM Corporation 2004, 2005 -# 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 -# 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. -# -# Authors: -# Ian Romanick - -import gl_XML, glX_XML, glX_proto_common, license -import sys, getopt - - -class glx_doc_item_factory(glX_proto_common.glx_proto_item_factory): - """Factory to create GLX protocol documentation oriented objects derived from glItem.""" - - def create_item(self, name, element, context): - if name == "parameter": - return glx_doc_parameter(element, context) - else: - return glX_proto_common.glx_proto_item_factory.create_item(self, name, element, context) - - -class glx_doc_parameter(gl_XML.gl_parameter): - def packet_type(self, type_dict): - """Get the type string for the packet header - - GLX protocol documentation uses type names like CARD32, - FLOAT64, LISTofCARD8, and ENUM. This function converts the - type of the parameter to one of these names.""" - - list_of = "" - if self.is_array(): - list_of = "LISTof" - - t_name = self.get_base_type_string() - if not type_dict.has_key( t_name ): - type_name = "CARD8" - else: - type_name = type_dict[ t_name ] - - return "%s%s" % (list_of, type_name) - - - def packet_size(self): - p = None - s = self.size() - if s == 0: - a_prod = "n" - b_prod = self.p_type.size - - if not self.count_parameter_list and self.counter: - a_prod = self.counter - elif self.count_parameter_list and not self.counter or self.is_output: - pass - elif self.count_parameter_list and self.counter: - b_prod = self.counter - else: - raise RuntimeError("Parameter '%s' to function '%s' has size 0." % (self.name, self.context.name)) - - ss = "%s*%s" % (a_prod, b_prod) - - return [ss, p] - else: - if s % 4 != 0: - p = "p" - - return [str(s), p] - -class PrintGlxProtoText(gl_XML.gl_print_base): - def __init__(self): - gl_XML.gl_print_base.__init__(self) - self.license = "" - - - def printHeader(self): - return - - - def body_size(self, f): - # At some point, refactor this function and - # glXFunction::command_payload_length. - - size = 0; - size_str = "" - pad_str = "" - plus = "" - for p in f.parameterIterateGlxSend(): - [s, pad] = p.packet_size() - try: - size += int(s) - except Exception,e: - size_str += "%s%s" % (plus, s) - plus = "+" - - if pad != None: - pad_str = pad - - return [size, size_str, pad_str] - - - def print_render_header(self, f): - [size, size_str, pad_str] = self.body_size(f) - size += 4; - - if size_str == "": - s = "%u" % ((size + 3) & ~3) - elif pad_str != "": - s = "%u+%s+%s" % (size, size_str, pad_str) - else: - s = "%u+%s" % (size, size_str) - - print ' 2 %-15s rendering command length' % (s) - print ' 2 %-4u rendering command opcode' % (f.glx_rop) - return - - - def print_single_header(self, f): - [size, size_str, pad_str] = self.body_size(f) - size = ((size + 3) / 4) + 2; - - if f.glx_vendorpriv != 0: - size += 1 - - print ' 1 CARD8 opcode (X assigned)' - print ' 1 %-4u GLX opcode (%s)' % (f.opcode_real_value(), f.opcode_real_name()) - - if size_str == "": - s = "%u" % (size) - elif pad_str != "": - s = "%u+((%s+%s)/4)" % (size, size_str, pad_str) - else: - s = "%u+((%s)/4)" % (size, size_str) - - print ' 2 %-15s request length' % (s) - - if f.glx_vendorpriv != 0: - print ' 4 %-4u vendor specific opcode' % (f.opcode_value()) - - print ' 4 GLX_CONTEXT_TAG context tag' - - return - - - def print_reply(self, f): - print ' =>' - print ' 1 1 reply' - print ' 1 unused' - print ' 2 CARD16 sequence number' - - if f.output == None: - print ' 4 0 reply length' - elif f.reply_always_array: - print ' 4 m reply length' - else: - print ' 4 m reply length, m = (n == 1 ? 0 : n)' - - - output = None - for x in f.parameterIterateOutputs(): - output = x - break - - - unused = 24 - if f.return_type != 'void': - print ' 4 %-15s return value' % (f.return_type) - unused -= 4 - elif output != None: - print ' 4 unused' - unused -= 4 - - if output != None: - print ' 4 CARD32 n' - unused -= 4 - - if output != None: - if not f.reply_always_array: - print '' - print ' if (n = 1) this follows:' - print '' - print ' 4 CARD32 %s' % (output.name) - print ' %-2u unused' % (unused - 4) - print '' - print ' otherwise this follows:' - print '' - - print ' %-2u unused' % (unused) - - [s, pad] = output.packet_size() - print ' %-8s %-15s %s' % (s, output.packet_type( self.type_map ), output.name) - if pad != None: - try: - bytes = int(s) - bytes = 4 - (bytes & 3) - print ' %-8u %-15s unused' % (bytes, "") - except Exception,e: - print ' %-8s %-15s unused, %s=pad(%s)' % (pad, "", pad, s) - else: - print ' %-2u unused' % (unused) - - - def print_body(self, f): - for p in f.parameterIterateGlxSend(): - [s, pad] = p.packet_size() - print ' %-8s %-15s %s' % (s, p.packet_type( self.type_map ), p.name) - if pad != None: - try: - bytes = int(s) - bytes = 4 - (bytes & 3) - print ' %-8u %-15s unused' % (bytes, "") - except Exception,e: - print ' %-8s %-15s unused, %s=pad(%s)' % (pad, "", pad, s) - - def printBody(self, api): - self.type_map = {} - for t in api.typeIterate(): - self.type_map[ "GL" + t.name ] = t.glx_name - - - # At some point this should be expanded to support pixel - # functions, but I'm not going to lose any sleep over it now. - - for f in api.functionIterateByOffset(): - if f.client_handcode or f.server_handcode or f.vectorequiv or len(f.get_images()): - continue - - - if f.glx_rop: - print ' %s' % (f.name) - self.print_render_header(f) - elif f.glx_sop or f.glx_vendorpriv: - print ' %s' % (f.name) - self.print_single_header(f) - else: - continue - - self.print_body(f) - - if f.needs_reply(): - self.print_reply(f) - - print '' - return - - -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, glx_doc_item_factory() ) - - printer = PrintGlxProtoText() - printer.Print( api ) diff --git a/src/mesa/glapi/glX_proto_common.py b/src/mesa/glapi/glX_proto_common.py deleted file mode 100644 index 6f094e22b31..00000000000 --- a/src/mesa/glapi/glX_proto_common.py +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env python - -# (C) Copyright IBM Corporation 2004, 2005 -# 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 -# 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. -# -# Authors: -# Ian Romanick - -import gl_XML, glX_XML -import string - - -class glx_proto_item_factory(glX_XML.glx_item_factory): - """Factory to create GLX protocol oriented objects derived from gl_item.""" - - def create_item(self, name, element, context): - if name == "type": - return glx_proto_type(element, context) - else: - return glX_XML.glx_item_factory.create_item(self, name, element, context) - - -class glx_proto_type(gl_XML.gl_type): - def __init__(self, element, context): - gl_XML.gl_type.__init__(self, element, context) - - self.glx_name = element.nsProp( "glx_name", None ) - return - - -class glx_print_proto(gl_XML.gl_print_base): - def size_call(self, func, outputs_also = 0): - """Create C code to calculate 'compsize'. - - Creates code to calculate 'compsize'. If the function does - not need 'compsize' to be calculated, None will be - returned.""" - - compsize = None - - for param in func.parameterIterator(): - if outputs_also or not param.is_output: - if param.is_image(): - [dim, w, h, d, junk] = param.get_dimensions() - - compsize = '__glImageSize(%s, %s, %s, %s, %s, %s)' % (w, h, d, param.img_format, param.img_type, param.img_target) - if not param.img_send_null: - compsize = '(%s != NULL) ? %s : 0' % (param.name, compsize) - - return compsize - - elif len(param.count_parameter_list): - parameters = string.join( param.count_parameter_list, "," ) - compsize = "__gl%s_size(%s)" % (func.name, parameters) - - return compsize - - return None - - - def emit_packet_size_calculation(self, f, bias): - # compsize is only used in the command size calculation if - # the function has a non-output parameter that has a non-empty - # counter_parameter_list. - - compsize = self.size_call(f) - if compsize: - print ' const GLuint compsize = %s;' % (compsize) - - if bias: - print ' const GLuint cmdlen = %s - %u;' % (f.command_length(), bias) - else: - print ' const GLuint cmdlen = %s;' % (f.command_length()) - - #print '' - return compsize diff --git a/src/mesa/glapi/glX_proto_recv.py b/src/mesa/glapi/glX_proto_recv.py deleted file mode 100644 index f423c6db084..00000000000 --- a/src/mesa/glapi/glX_proto_recv.py +++ /dev/null @@ -1,554 +0,0 @@ -#!/usr/bin/env python - -# (C) Copyright IBM Corporation 2005 -# 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 -# 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. -# -# Authors: -# Ian Romanick - -import gl_XML, glX_XML, glX_proto_common, license -import sys, getopt, string - - -class PrintGlxDispatch_h(gl_XML.gl_print_base): - def __init__(self): - gl_XML.gl_print_base.__init__(self) - - self.name = "glX_proto_recv.py (from Mesa)" - self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005", "IBM") - - self.header_tag = "_INDIRECT_DISPATCH_H_" - return - - - def printRealHeader(self): - self.printVisibility( "HIDDEN", "hidden" ) - print 'struct __GLXclientStateRec;' - print '' - return - - - def printBody(self, api): - for func in api.functionIterateAll(): - if not func.ignore and not func.vectorequiv: - if func.glx_rop: - print 'extern HIDDEN void __glXDisp_%s(GLbyte * pc);' % (func.name) - print 'extern HIDDEN void __glXDispSwap_%s(GLbyte * pc);' % (func.name) - elif func.glx_sop or func.glx_vendorpriv: - print 'extern HIDDEN int __glXDisp_%s(struct __GLXclientStateRec *, GLbyte *);' % (func.name) - print 'extern HIDDEN int __glXDispSwap_%s(struct __GLXclientStateRec *, GLbyte *);' % (func.name) - - if func.glx_sop and func.glx_vendorpriv: - n = func.glx_vendorpriv_names[0] - print 'extern HIDDEN int __glXDisp_%s(struct __GLXclientStateRec *, GLbyte *);' % (n) - print 'extern HIDDEN int __glXDispSwap_%s(struct __GLXclientStateRec *, GLbyte *);' % (n) - - return - - -class PrintGlxDispatchFunctions(glX_proto_common.glx_print_proto): - def __init__(self, do_swap): - gl_XML.gl_print_base.__init__(self) - self.name = "glX_proto_recv.py (from Mesa)" - self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005", "IBM") - - self.real_types = [ '', '', 'uint16_t', '', 'uint32_t', '', '', '', 'uint64_t' ] - self.do_swap = do_swap - return - - - def printRealHeader(self): - print '#include ' - print '#include ' - print '#include ' - - print '#include ' - print '#include "indirect_size.h"' - print '#include "indirect_size_get.h"' - print '#include "indirect_dispatch.h"' - print '#include "glxserver.h"' - print '#include "glxbyteorder.h"' - print '#include "indirect_util.h"' - print '#include "singlesize.h"' - print '#include "glapi.h"' - print '#include "glapitable.h"' - print '#include "glthread.h"' - print '#include "dispatch.h"' - print '' - print '#define __GLX_PAD(x) (((x) + 3) & ~3)' - print '' - print 'typedef struct {' - print ' __GLX_PIXEL_3D_HDR;' - print '} __GLXpixel3DHeader;' - print '' - print 'extern GLboolean __glXErrorOccured( void );' - print 'extern void __glXClearErrorOccured( void );' - print '' - print 'static const unsigned dummy_answer[2] = {0, 0};' - print '' - return - - - def printBody(self, api): - if self.do_swap: - self.emit_swap_wrappers(api) - - - for func in api.functionIterateByOffset(): - if not func.ignore and not func.server_handcode and not func.vectorequiv and (func.glx_rop or func.glx_sop or func.glx_vendorpriv): - self.printFunction(func, func.name) - if func.glx_sop and func.glx_vendorpriv: - self.printFunction(func, func.glx_vendorpriv_names[0]) - - - return - - - def printFunction(self, f, name): - if (f.glx_sop or f.glx_vendorpriv) and (len(f.get_images()) != 0): - return - - if not self.do_swap: - base = '__glXDisp' - else: - base = '__glXDispSwap' - - if f.glx_rop: - print 'void %s_%s(GLbyte * pc)' % (base, name) - else: - print 'int %s_%s(__GLXclientState *cl, GLbyte *pc)' % (base, name) - - print '{' - - if f.glx_rop or f.vectorequiv: - self.printRenderFunction(f) - elif f.glx_sop or f.glx_vendorpriv: - if len(f.get_images()) == 0: - self.printSingleFunction(f, name) - else: - print "/* Missing GLX protocol for %s. */" % (name) - - print '}' - print '' - return - - - def swap_name(self, bytes): - return 'bswap_%u_array' % (8 * bytes) - - - def emit_swap_wrappers(self, api): - self.type_map = {} - already_done = [ ] - - for t in api.typeIterate(): - te = t.get_type_expression() - t_size = te.get_element_size() - - if t_size > 1 and t.glx_name: - - t_name = "GL" + t.name - self.type_map[ t_name ] = t.glx_name - - if t.glx_name not in already_done: - real_name = self.real_types[t_size] - - print 'static %s' % (t_name) - print 'bswap_%s( const void * src )' % (t.glx_name) - print '{' - print ' union { %s dst; %s ret; } x;' % (real_name, t_name) - print ' x.dst = bswap_%u( *(%s *) src );' % (t_size * 8, real_name) - print ' return x.ret;' - print '}' - print '' - already_done.append( t.glx_name ) - - for bits in [16, 32, 64]: - print 'static void *' - print 'bswap_%u_array( uint%u_t * src, unsigned count )' % (bits, bits) - print '{' - print ' unsigned i;' - print '' - print ' for ( i = 0 ; i < count ; i++ ) {' - print ' uint%u_t temp = bswap_%u( src[i] );' % (bits, bits) - print ' src[i] = temp;' - print ' }' - print '' - print ' return src;' - print '}' - print '' - - - def fetch_param(self, param): - t = param.type_string() - o = param.offset - element_size = param.size() / param.get_element_count() - - if self.do_swap and (element_size != 1): - if param.is_array(): - real_name = self.real_types[ element_size ] - - swap_func = self.swap_name( element_size ) - return ' (%-8s)%s( (%s *) (pc + %2s), %s )' % (t, swap_func, real_name, o, param.count) - else: - t_name = param.get_base_type_string() - return ' (%-8s)bswap_%-7s( pc + %2s )' % (t, self.type_map[ t_name ], o) - else: - if param.is_array(): - return ' (%-8s)(pc + %2u)' % (t, o) - else: - return '*(%-8s *)(pc + %2u)' % (t, o) - - return None - - - def emit_function_call(self, f, retval_assign, indent): - list = [] - - for param in f.parameterIterator(): - if param.is_padding: - continue - - if param.is_counter or param.is_image() or param.is_output or param.name in f.count_parameter_list or len(param.count_parameter_list): - location = param.name - else: - location = self.fetch_param(param) - - list.append( '%s %s' % (indent, location) ) - - - if len( list ): - print '%s %sCALL_%s( GET_DISPATCH(), (' % (indent, retval_assign, f.name) - print string.join( list, ",\n" ) - print '%s ) );' % (indent) - else: - print '%s %sCALL_%s( GET_DISPATCH(), () );' % (indent, retval_assign, f.name) - return - - - def common_func_print_just_start(self, f, indent): - align64 = 0 - need_blank = 0 - - - f.calculate_offsets() - for param in f.parameterIterateGlxSend(): - # If any parameter has a 64-bit base type, then we - # have to do alignment magic for the while thing. - - if param.is_64_bit(): - align64 = 1 - - - # FIXME img_null_flag is over-loaded. In addition to - # FIXME being used for images, it is used to signify - # FIXME NULL data pointers for vertex buffer object - # FIXME related functions. Re-name it to null_data - # FIXME or something similar. - - if param.img_null_flag: - print '%s const CARD32 ptr_is_null = *(CARD32 *)(pc + %s);' % (indent, param.offset - 4) - cond = '(ptr_is_null != 0) ? NULL : ' - else: - cond = "" - - - type_string = param.type_string() - - if param.is_image(): - offset = f.offset_of( param.name ) - - print '%s %s const %s = (%s) (%s(pc + %s));' % (indent, type_string, param.name, type_string, cond, offset) - - if param.depth: - print '%s __GLXpixel3DHeader * const hdr = (__GLXpixel3DHeader *)(pc);' % (indent) - else: - print '%s __GLXpixelHeader * const hdr = (__GLXpixelHeader *)(pc);' % (indent) - - need_blank = 1 - elif param.is_counter or param.name in f.count_parameter_list: - location = self.fetch_param(param) - print '%s const %s %s = %s;' % (indent, type_string, param.name, location) - need_blank = 1 - elif len(param.count_parameter_list): - if param.size() == 1 and not self.do_swap: - location = self.fetch_param(param) - print '%s %s %s = %s%s;' % (indent, type_string, param.name, cond, location) - else: - print '%s %s %s;' % (indent, type_string, param.name) - need_blank = 1 - - - - if need_blank: - print '' - - if align64: - print '#ifdef __GLX_ALIGN64' - - if f.has_variable_size_request(): - self.emit_packet_size_calculation(f, 4) - s = "cmdlen" - else: - s = str((f.command_fixed_length() + 3) & ~3) - - print ' if ((unsigned long)(pc) & 7) {' - print ' (void) memmove(pc-4, pc, %s);' % (s) - print ' pc -= 4;' - print ' }' - print '#endif' - print '' - - - need_blank = 0 - if self.do_swap: - for param in f.parameterIterateGlxSend(): - if param.count_parameter_list: - o = param.offset - count = param.get_element_count() - type_size = param.size() / count - - if param.counter: - count_name = param.counter - else: - count_name = str(count) - - # This is basically an ugly special- - # case for glCallLists. - - if type_size == 1: - x = [] - x.append( [1, ['BYTE', 'UNSIGNED_BYTE', '2_BYTES', '3_BYTES', '4_BYTES']] ) - x.append( [2, ['SHORT', 'UNSIGNED_SHORT']] ) - x.append( [4, ['INT', 'UNSIGNED_INT', 'FLOAT']] ) - - print ' switch(%s) {' % (param.count_parameter_list[0]) - for sub in x: - for t_name in sub[1]: - print ' case GL_%s:' % (t_name) - - if sub[0] == 1: - print ' %s = (%s) (pc + %s); break;' % (param.name, param.type_string(), o) - else: - swap_func = self.swap_name(sub[0]) - print ' %s = (%s) %s( (%s *) (pc + %s), %s ); break;' % (param.name, param.type_string(), swap_func, self.real_types[sub[0]], o, count_name) - print ' default:' - print ' return;' - print ' }' - else: - swap_func = self.swap_name(type_size) - compsize = self.size_call(f, 1) - print ' %s = (%s) %s( (%s *) (pc + %s), %s );' % (param.name, param.type_string(), swap_func, self.real_types[type_size], o, compsize) - - need_blank = 1 - - else: - for param in f.parameterIterateGlxSend(): - if param.count_parameter_list: - print '%s %s = (%s) (pc + %s);' % (indent, param.name, param.type_string(), param.offset) - need_blank = 1 - - - if need_blank: - print '' - - - return - - - def printSingleFunction(self, f, name): - if name not in f.glx_vendorpriv_names: - print ' xGLXSingleReq * const req = (xGLXSingleReq *) pc;' - else: - print ' xGLXVendorPrivateReq * const req = (xGLXVendorPrivateReq *) pc;' - - print ' int error;' - - if self.do_swap: - print ' __GLXcontext * const cx = __glXForceCurrent(cl, bswap_CARD32( &req->contextTag ), &error);' - else: - print ' __GLXcontext * const cx = __glXForceCurrent(cl, req->contextTag, &error);' - - print '' - if name not in f.glx_vendorpriv_names: - print ' pc += __GLX_SINGLE_HDR_SIZE;' - else: - print ' pc += __GLX_VENDPRIV_HDR_SIZE;' - - print ' if ( cx != NULL ) {' - self.common_func_print_just_start(f, " ") - - - if f.return_type != 'void': - print ' %s retval;' % (f.return_type) - retval_string = "retval" - retval_assign = "retval = " - else: - retval_string = "0" - retval_assign = "" - - - type_size = 0 - answer_string = "dummy_answer" - answer_count = "0" - is_array_string = "GL_FALSE" - - for param in f.parameterIterateOutputs(): - answer_type = param.get_base_type_string() - if answer_type == "GLvoid": - answer_type = "GLubyte" - - - c = param.get_element_count() - type_size = (param.size() / c) - if type_size == 1: - size_scale = "" - else: - size_scale = " * %u" % (type_size) - - - if param.count_parameter_list: - print ' const GLuint compsize = %s;' % (self.size_call(f, 1)) - print ' %s answerBuffer[200];' % (answer_type) - print ' %s %s = __glXGetAnswerBuffer(cl, compsize%s, answerBuffer, sizeof(answerBuffer), %u);' % (param.type_string(), param.name, size_scale, type_size ) - answer_string = param.name - answer_count = "compsize" - - print '' - print ' if (%s == NULL) return BadAlloc;' % (param.name) - print ' __glXClearErrorOccured();' - print '' - elif param.counter: - print ' %s answerBuffer[200];' % (answer_type) - print ' %s %s = __glXGetAnswerBuffer(cl, %s%s, answerBuffer, sizeof(answerBuffer), %u);' % (param.type_string(), param.name, param.counter, size_scale, type_size) - answer_string = param.name - answer_count = param.counter - elif c >= 1: - print ' %s %s[%u];' % (answer_type, param.name, c) - answer_string = param.name - answer_count = "%u" % (c) - - if f.reply_always_array: - is_array_string = "GL_TRUE" - - - self.emit_function_call(f, retval_assign, " ") - - - if f.needs_reply(): - if self.do_swap: - for param in f.parameterIterateOutputs(): - c = param.get_element_count() - type_size = (param.size() / c) - - if type_size > 1: - swap_name = self.swap_name( type_size ) - print ' (void) %s( (uint%u_t *) %s, %s );' % (swap_name, 8 * type_size, param.name, answer_count) - - - reply_func = '__glXSendReplySwap' - else: - reply_func = '__glXSendReply' - - print ' %s(cl->client, %s, %s, %u, %s, %s);' % (reply_func, answer_string, answer_count, type_size, is_array_string, retval_string) - #elif f.note_unflushed: - # print ' cx->hasUnflushedCommands = GL_TRUE;' - - print ' error = Success;' - print ' }' - print '' - print ' return error;' - return - - - def printRenderFunction(self, f): - # There are 4 distinct phases in a rendering dispatch function. - # In the first phase we compute the sizes and offsets of each - # element in the command. In the second phase we (optionally) - # re-align 64-bit data elements. In the third phase we - # (optionally) byte-swap array data. Finally, in the fourth - # phase we actually dispatch the function. - - self.common_func_print_just_start(f, "") - - images = f.get_images() - if len(images): - if self.do_swap: - pre = "bswap_CARD32( & " - post = " )" - else: - pre = "" - post = "" - - img = images[0] - - # swapBytes and lsbFirst are single byte fields, so - # the must NEVER be byte-swapped. - - if not (img.img_type == "GL_BITMAP" and img.img_format == "GL_COLOR_INDEX"): - print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SWAP_BYTES, hdr->swapBytes) );' - - print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_LSB_FIRST, hdr->lsbFirst) );' - - print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_ROW_LENGTH, (GLint) %shdr->rowLength%s) );' % (pre, post) - if img.depth: - print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_IMAGE_HEIGHT, (GLint) %shdr->imageHeight%s) );' % (pre, post) - print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_ROWS, (GLint) %shdr->skipRows%s) );' % (pre, post) - if img.depth: - print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_IMAGES, (GLint) %shdr->skipImages%s) );' % (pre, post) - print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_PIXELS, (GLint) %shdr->skipPixels%s) );' % (pre, post) - print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_ALIGNMENT, (GLint) %shdr->alignment%s) );' % (pre, post) - print '' - - - self.emit_function_call(f, "", "") - return - - -if __name__ == '__main__': - file_name = "gl_API.xml" - - try: - (args, trail) = getopt.getopt(sys.argv[1:], "f:m:s") - except Exception,e: - show_usage() - - mode = "dispatch_c" - do_swap = 0 - for (arg,val) in args: - if arg == "-f": - file_name = val - elif arg == "-m": - mode = val - elif arg == "-s": - do_swap = 1 - - if mode == "dispatch_c": - printer = PrintGlxDispatchFunctions(do_swap) - elif mode == "dispatch_h": - printer = PrintGlxDispatch_h() - else: - show_usage() - - api = gl_XML.parse_GL_API( file_name, glX_proto_common.glx_proto_item_factory() ) - - printer.Print( api ) diff --git a/src/mesa/glapi/glX_proto_send.py b/src/mesa/glapi/glX_proto_send.py deleted file mode 100644 index daca1b767a3..00000000000 --- a/src/mesa/glapi/glX_proto_send.py +++ /dev/null @@ -1,1042 +0,0 @@ -#!/usr/bin/env python - -# (C) Copyright IBM Corporation 2004, 2005 -# 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 -# 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. -# -# Authors: -# Ian Romanick -# Jeremy Kolb - -import gl_XML, glX_XML, glX_proto_common, license -import sys, getopt, copy, string - -def convertStringForXCB(str): - tmp = "" - special = [ "ARB" ] - i = 0 - while i < len(str): - if str[i:i+3] in special: - tmp = '%s_%s' % (tmp, string.lower(str[i:i+3])) - i = i + 2; - elif str[i].isupper(): - tmp = '%s_%s' % (tmp, string.lower(str[i])) - else: - tmp = '%s%s' % (tmp, str[i]) - i += 1 - return tmp - -def hash_pixel_function(func): - """Generate a 'unique' key for a pixel function. The key is based on - the parameters written in the command packet. This includes any - padding that might be added for the original function and the 'NULL - image' flag.""" - - - h = "" - hash_pre = "" - hash_suf = "" - for param in func.parameterIterateGlxSend(): - if param.is_image(): - [dim, junk, junk, junk, junk] = param.get_dimensions() - - d = (dim + 1) & ~1 - hash_pre = "%uD%uD_" % (d - 1, d) - - if param.img_null_flag: - hash_suf = "_NF" - - h += "%u" % (param.size()) - - if func.pad_after(param): - h += "4" - - - n = func.name.replace("%uD" % (dim), "") - n = "__glx_%s_%uD%uD" % (n, d - 1, d) - - h = hash_pre + h + hash_suf - return [h, n] - - -class glx_pixel_function_stub(glX_XML.glx_function): - """Dummy class used to generate pixel "utility" functions that are - shared by multiple dimension image functions. For example, these - objects are used to generate shared functions used to send GLX - protocol for TexImage1D and TexImage2D, TexSubImage1D and - TexSubImage2D, etc.""" - - def __init__(self, func, name): - # The parameters to the utility function are the same as the - # parameters to the real function except for the added "pad" - # parameters. - - self.name = name - self.images = [] - self.parameters = [] - self.parameters_by_name = {} - for _p in func.parameterIterator(): - p = copy.copy(_p) - self.parameters.append(p) - self.parameters_by_name[ p.name ] = p - - - if p.is_image(): - self.images.append(p) - p.height = "height" - - if p.img_yoff == None: - p.img_yoff = "yoffset" - - if p.depth: - if p.extent == None: - p.extent = "extent" - - if p.img_woff == None: - p.img_woff = "woffset" - - - pad_name = func.pad_after(p) - if pad_name: - pad = copy.copy(p) - pad.name = pad_name - self.parameters.append(pad) - self.parameters_by_name[ pad.name ] = pad - - - self.return_type = func.return_type - - self.glx_rop = ~0 - self.glx_sop = 0 - self.glx_vendorpriv = 0 - - self.glx_doubles_in_order = func.glx_doubles_in_order - - self.vectorequiv = None - self.output = None - self.can_be_large = func.can_be_large - self.reply_always_array = func.reply_always_array - self.dimensions_in_reply = func.dimensions_in_reply - self.img_reset = None - - self.server_handcode = 0 - self.client_handcode = 0 - self.ignore = 0 - - self.count_parameter_list = func.count_parameter_list - self.counter_list = func.counter_list - self.offsets_calculated = 0 - return - - -class PrintGlxProtoStubs(glX_proto_common.glx_print_proto): - def __init__(self): - glX_proto_common.glx_print_proto.__init__(self) - self.name = "glX_proto_send.py (from Mesa)" - self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2004, 2005", "IBM") - - - self.last_category = "" - self.generic_sizes = [3, 4, 6, 8, 12, 16, 24, 32] - self.pixel_stubs = {} - self.debug = 0 - return - - def printRealHeader(self): - print '' - print '#include ' - print '#include "indirect.h"' - print '#include "glxclient.h"' - print '#include "indirect_size.h"' - print '#include "dispatch.h"' - print '#include "glapi.h"' - print '#include "glthread.h"' - print '#include ' - print '#ifdef USE_XCB' - print '#include ' - print '#include ' - print '#include ' - print '#endif /* USE_XCB */' - - print '' - print '#define __GLX_PAD(n) (((n) + 3) & ~3)' - print '' - self.printFastcall() - self.printNoinline() - print '' - print '#if !defined __GNUC__ || __GNUC__ < 3' - print '# define __builtin_expect(x, y) x' - print '#endif' - print '' - print '/* If the size and opcode values are known at compile-time, this will, on' - print ' * x86 at least, emit them with a single instruction.' - print ' */' - print '#define emit_header(dest, op, size) \\' - print ' do { union { short s[2]; int i; } temp; \\' - print ' temp.s[0] = (size); temp.s[1] = (op); \\' - print ' *((int *)(dest)) = temp.i; } while(0)' - print '' - print """NOINLINE CARD32 -__glXReadReply( Display *dpy, size_t size, void * dest, GLboolean reply_is_always_array ) -{ - xGLXSingleReply reply; - - (void) _XReply(dpy, (xReply *) & reply, 0, False); - if (size != 0) { - if ((reply.length > 0) || reply_is_always_array) { - const GLint bytes = (reply_is_always_array) - ? (4 * reply.length) : (reply.size * size); - const GLint extra = 4 - (bytes & 3); - - _XRead(dpy, dest, bytes); - if ( extra < 4 ) { - _XEatData(dpy, extra); - } - } - else { - (void) memcpy( dest, &(reply.pad3), size); - } - } - - return reply.retval; -} - -NOINLINE void -__glXReadPixelReply( Display *dpy, __GLXcontext * gc, unsigned max_dim, - GLint width, GLint height, GLint depth, GLenum format, GLenum type, - void * dest, GLboolean dimensions_in_reply ) -{ - xGLXSingleReply reply; - GLint size; - - (void) _XReply(dpy, (xReply *) & reply, 0, False); - - if ( dimensions_in_reply ) { - width = reply.pad3; - height = reply.pad4; - depth = reply.pad5; - - if ((height == 0) || (max_dim < 2)) { height = 1; } - if ((depth == 0) || (max_dim < 3)) { depth = 1; } - } - - size = reply.length * 4; - if (size != 0) { - void * buf = Xmalloc( size ); - - if ( buf == NULL ) { - _XEatData(dpy, size); - __glXSetError(gc, GL_OUT_OF_MEMORY); - } - else { - const GLint extra = 4 - (size & 3); - - _XRead(dpy, buf, size); - if ( extra < 4 ) { - _XEatData(dpy, extra); - } - - __glEmptyImage(gc, 3, width, height, depth, format, type, - buf, dest); - Xfree(buf); - } - } -} - -#define X_GLXSingle 0 - -NOINLINE FASTCALL GLubyte * -__glXSetupSingleRequest( __GLXcontext * gc, GLint sop, GLint cmdlen ) -{ - xGLXSingleReq * req; - Display * const dpy = gc->currentDpy; - - (void) __glXFlushRenderBuffer(gc, gc->pc); - LockDisplay(dpy); - GetReqExtra(GLXSingle, cmdlen, req); - req->reqType = gc->majorOpcode; - req->contextTag = gc->currentContextTag; - req->glxCode = sop; - return (GLubyte *)(req) + sz_xGLXSingleReq; -} - -NOINLINE FASTCALL GLubyte * -__glXSetupVendorRequest( __GLXcontext * gc, GLint code, GLint vop, GLint cmdlen ) -{ - xGLXVendorPrivateReq * req; - Display * const dpy = gc->currentDpy; - - (void) __glXFlushRenderBuffer(gc, gc->pc); - LockDisplay(dpy); - GetReqExtra(GLXVendorPrivate, cmdlen, req); - req->reqType = gc->majorOpcode; - req->glxCode = code; - req->vendorCode = vop; - req->contextTag = gc->currentContextTag; - return (GLubyte *)(req) + sz_xGLXVendorPrivateReq; -} - -const GLuint __glXDefaultPixelStore[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 1 }; - -#define zero (__glXDefaultPixelStore+0) -#define one (__glXDefaultPixelStore+8) -#define default_pixel_store_1D (__glXDefaultPixelStore+4) -#define default_pixel_store_1D_size 20 -#define default_pixel_store_2D (__glXDefaultPixelStore+4) -#define default_pixel_store_2D_size 20 -#define default_pixel_store_3D (__glXDefaultPixelStore+0) -#define default_pixel_store_3D_size 36 -#define default_pixel_store_4D (__glXDefaultPixelStore+0) -#define default_pixel_store_4D_size 36 -""" - - for size in self.generic_sizes: - self.print_generic_function(size) - return - - - def printBody(self, api): - - self.pixel_stubs = {} - generated_stubs = [] - - for func in api.functionIterateGlx(): - if func.client_handcode: continue - - # If the function is a pixel function with a certain - # GLX protocol signature, create a fake stub function - # for it. For example, create a single stub function - # that is used to implement both glTexImage1D and - # glTexImage2D. - - if func.glx_rop != 0: - do_it = 0 - for image in func.get_images(): - if image.img_pad_dimensions: - do_it = 1 - break - - - if do_it: - [h, n] = hash_pixel_function(func) - - - self.pixel_stubs[ func.name ] = n - if h not in generated_stubs: - generated_stubs.append(h) - - fake_func = glx_pixel_function_stub( func, n ) - self.printFunction(fake_func, fake_func.name) - - - self.printFunction(func, func.name) - if func.glx_sop and func.glx_vendorpriv: - self.printFunction(func, func.glx_vendorpriv_names[0]) - - return - - - def printFunction(self, func, name): - footer = '}\n' - if func.glx_rop == ~0: - print 'static %s' % (func.return_type) - print '%s( unsigned opcode, unsigned dim, %s )' % (func.name, func.get_parameter_string()) - print '{' - else: - if func.has_different_protocol(name): - if func.return_type == "void": - ret_string = '' - else: - ret_string = "return " - - func_name = func.static_glx_name(name) - print '#define %s %d' % (func.opcode_vendor_name(name), func.glx_vendorpriv) - print '%s gl%s(%s)' % (func.return_type, func_name, func.get_parameter_string()) - print '{' - print ' __GLXcontext * const gc = __glXGetCurrentContext();' - print '' - print '#ifdef GLX_DIRECT_RENDERING' - print ' if (gc->driContext) {' - print ' %sCALL_%s(GET_DISPATCH(), (%s));' % (ret_string, func.name, func.get_called_parameter_string()) - print ' } else' - print '#endif' - print ' {' - - footer = '}\n}\n' - else: - print '#define %s %d' % (func.opcode_name(), func.opcode_value()) - - print '%s __indirect_gl%s(%s)' % (func.return_type, name, func.get_parameter_string()) - print '{' - - - if func.glx_rop != 0 or func.vectorequiv != None: - if len(func.images): - self.printPixelFunction(func) - else: - self.printRenderFunction(func) - elif func.glx_sop != 0 or func.glx_vendorpriv != 0: - self.printSingleFunction(func, name) - pass - else: - print "/* Missing GLX protocol for %s. */" % (name) - - print footer - return - - - def print_generic_function(self, n): - size = (n + 3) & ~3 - print """static FASTCALL NOINLINE void -generic_%u_byte( GLint rop, const void * ptr ) -{ - __GLXcontext * const gc = __glXGetCurrentContext(); - const GLuint cmdlen = %u; - - emit_header(gc->pc, rop, cmdlen); - (void) memcpy((void *)(gc->pc + 4), ptr, %u); - gc->pc += cmdlen; - if (__builtin_expect(gc->pc > gc->limit, 0)) { (void) __glXFlushRenderBuffer(gc, gc->pc); } -} -""" % (n, size + 4, size) - return - - - def common_emit_one_arg(self, p, pc, adjust, extra_offset): - if p.is_array(): - src_ptr = p.name - else: - src_ptr = "&" + p.name - - if p.is_padding: - print '(void) memset((void *)(%s + %u), 0, %s);' \ - % (pc, p.offset + adjust, p.size_string() ) - elif not extra_offset: - print '(void) memcpy((void *)(%s + %u), (void *)(%s), %s);' \ - % (pc, p.offset + adjust, src_ptr, p.size_string() ) - else: - print '(void) memcpy((void *)(%s + %u + %s), (void *)(%s), %s);' \ - % (pc, p.offset + adjust, extra_offset, src_ptr, p.size_string() ) - - def common_emit_args(self, f, pc, adjust, skip_vla): - extra_offset = None - - for p in f.parameterIterateGlxSend( not skip_vla ): - if p.name != f.img_reset: - self.common_emit_one_arg(p, pc, adjust, extra_offset) - - if p.is_variable_length(): - temp = p.size_string() - if extra_offset: - extra_offset += " + %s" % (temp) - else: - extra_offset = temp - - return - - - def pixel_emit_args(self, f, pc, large): - """Emit the arguments for a pixel function. This differs from - common_emit_args in that pixel functions may require padding - be inserted (i.e., for the missing width field for - TexImage1D), and they may also require a 'NULL image' flag - be inserted before the image data.""" - - if large: - adjust = 8 - else: - adjust = 4 - - for param in f.parameterIterateGlxSend(): - if not param.is_image(): - self.common_emit_one_arg(param, pc, adjust, None) - - if f.pad_after(param): - print '(void) memcpy((void *)(%s + %u), zero, 4);' % (pc, (param.offset + param.size()) + adjust) - - else: - [dim, width, height, depth, extent] = param.get_dimensions() - if f.glx_rop == ~0: - dim_str = "dim" - else: - dim_str = str(dim) - - if param.is_padding: - print '(void) memset((void *)(%s + %u), 0, %s);' \ - % (pc, (param.offset - 4) + adjust, param.size_string() ) - - if param.img_null_flag: - if large: - print '(void) memcpy((void *)(%s + %u), zero, 4);' % (pc, (param.offset - 4) + adjust) - else: - print '(void) memcpy((void *)(%s + %u), (void *)((%s == NULL) ? one : zero), 4);' % (pc, (param.offset - 4) + adjust, param.name) - - - pixHeaderPtr = "%s + %u" % (pc, adjust) - pcPtr = "%s + %u" % (pc, param.offset + adjust) - - if not large: - if param.img_send_null: - condition = '(compsize > 0) && (%s != NULL)' % (param.name) - else: - condition = 'compsize > 0' - - print 'if (%s) {' % (condition) - print ' (*gc->fillImage)(gc, %s, %s, %s, %s, %s, %s, %s, %s, %s);' % (dim_str, width, height, depth, param.img_format, param.img_type, param.name, pcPtr, pixHeaderPtr) - print '} else {' - print ' (void) memcpy( %s, default_pixel_store_%uD, default_pixel_store_%uD_size );' % (pixHeaderPtr, dim, dim) - print '}' - else: - print '__glXSendLargeImage(gc, compsize, %s, %s, %s, %s, %s, %s, %s, %s, %s);' % (dim_str, width, height, depth, param.img_format, param.img_type, param.name, pcPtr, pixHeaderPtr) - - return - - - def large_emit_begin(self, f, op_name = None): - if not op_name: - op_name = f.opcode_real_name() - - print 'const GLint op = %s;' % (op_name) - print 'const GLuint cmdlenLarge = cmdlen + 4;' - print 'GLubyte * const pc = __glXFlushRenderBuffer(gc, gc->pc);' - print '(void) memcpy((void *)(pc + 0), (void *)(&cmdlenLarge), 4);' - print '(void) memcpy((void *)(pc + 4), (void *)(&op), 4);' - return - - - def common_func_print_just_start(self, f, name): - print ' __GLXcontext * const gc = __glXGetCurrentContext();' - - # The only reason that single and vendor private commands need - # a variable called 'dpy' is becuase they use the SyncHandle - # macro. For whatever brain-dead reason, that macro is hard- - # coded to use a variable called 'dpy' instead of taking a - # parameter. - - # FIXME Simplify the logic related to skip_condition and - # FIXME condition_list in this function. Basically, remove - # FIXME skip_condition, and just append the "dpy != NULL" type - # FIXME condition to condition_list from the start. The only - # FIXME reason it's done in this confusing way now is to - # FIXME minimize the diffs in the generated code. - - if not f.glx_rop: - for p in f.parameterIterateOutputs(): - if p.is_image() and (p.img_format != "GL_COLOR_INDEX" or p.img_type != "GL_BITMAP"): - print ' const __GLXattribute * const state = gc->client_state_private;' - break - - print ' Display * const dpy = gc->currentDpy;' - skip_condition = "dpy != NULL" - elif f.can_be_large: - skip_condition = "gc->currentDpy != NULL" - else: - skip_condition = None - - - if f.return_type != 'void': - print ' %s retval = (%s) 0;' % (f.return_type, f.return_type) - - - if name != None and name not in f.glx_vendorpriv_names: - print '#ifndef USE_XCB' - self.emit_packet_size_calculation(f, 0) - if name != None and name not in f.glx_vendorpriv_names: - print '#endif' - - condition_list = [] - for p in f.parameterIterateCounters(): - condition_list.append( "%s >= 0" % (p.name) ) - # 'counter' parameters cannot be negative - print " if (%s < 0) {" % p.name - print " __glXSetError(gc, GL_INVALID_VALUE);" - if f.return_type != 'void': - print " return 0;" - else: - print " return;" - print " }" - - if skip_condition: - condition_list.append( skip_condition ) - - if len( condition_list ) > 0: - if len( condition_list ) > 1: - skip_condition = "(%s)" % (string.join( condition_list, ") && (" )) - else: - skip_condition = "%s" % (condition_list.pop(0)) - - print ' if (__builtin_expect(%s, 1)) {' % (skip_condition) - return 1 - else: - return 0 - - - def printSingleFunction(self, f, name): - self.common_func_print_just_start(f, name) - - if self.debug: - print ' printf( "Enter %%s...\\n", "gl%s" );' % (f.name) - - if name not in f.glx_vendorpriv_names: - - # XCB specific: - print '#ifdef USE_XCB' - if self.debug: - print ' printf("\\tUsing XCB.\\n");' - print ' xcb_connection_t *c = XGetXCBConnection(dpy);' - print ' (void) __glXFlushRenderBuffer(gc, gc->pc);' - xcb_name = 'xcb_glx%s' % convertStringForXCB(name) - - iparams=[] - extra_iparams = [] - output = None - for p in f.parameterIterator(): - if p.is_output: - output = p - - if p.is_image(): - if p.img_format != "GL_COLOR_INDEX" or p.img_type != "GL_BITMAP": - extra_iparams.append("state->storePack.swapEndian") - else: - extra_iparams.append("0") - - # Hardcode this in. lsb_first param (apparently always GL_FALSE) - # also present in GetPolygonStipple, but taken care of above. - if xcb_name == "xcb_glx_read_pixels": - extra_iparams.append("0") - else: - iparams.append(p.name) - - - xcb_request = '%s(%s)' % (xcb_name, ", ".join(["c", "gc->currentContextTag"] + iparams + extra_iparams)) - - if f.needs_reply(): - print ' %s_reply_t *reply = %s_reply(c, %s, NULL);' % (xcb_name, xcb_name, xcb_request) - if output and f.reply_always_array: - print ' (void)memcpy(%s, %s_data(reply), %s_data_length(reply) * sizeof(%s));' % (output.name, xcb_name, xcb_name, output.get_base_type_string()) - - elif output and not f.reply_always_array: - if not output.is_image(): - print ' if (%s_data_length(reply) == 0)' % (xcb_name) - print ' (void)memcpy(%s, &reply->datum, sizeof(reply->datum));' % (output.name) - print ' else' - print ' (void)memcpy(%s, %s_data(reply), %s_data_length(reply) * sizeof(%s));' % (output.name, xcb_name, xcb_name, output.get_base_type_string()) - - - if f.return_type != 'void': - print ' retval = reply->ret_val;' - print ' free(reply);' - else: - print ' ' + xcb_request + ';' - print '#else' - # End of XCB specific. - - - if f.parameters != []: - pc_decl = "GLubyte const * pc =" - else: - pc_decl = "(void)" - - if name in f.glx_vendorpriv_names: - print ' %s __glXSetupVendorRequest(gc, %s, %s, cmdlen);' % (pc_decl, f.opcode_real_name(), f.opcode_vendor_name(name)) - else: - print ' %s __glXSetupSingleRequest(gc, %s, cmdlen);' % (pc_decl, f.opcode_name()) - - self.common_emit_args(f, "pc", 0, 0) - - images = f.get_images() - - for img in images: - if img.is_output: - o = f.command_fixed_length() - 4 - print ' *(int32_t *)(pc + %u) = 0;' % (o) - if img.img_format != "GL_COLOR_INDEX" or img.img_type != "GL_BITMAP": - print ' * (int8_t *)(pc + %u) = state->storePack.swapEndian;' % (o) - - if f.img_reset: - print ' * (int8_t *)(pc + %u) = %s;' % (o + 1, f.img_reset) - - - return_name = '' - if f.needs_reply(): - if f.return_type != 'void': - return_name = " retval" - return_str = " retval = (%s)" % (f.return_type) - else: - return_str = " (void)" - - got_reply = 0 - - for p in f.parameterIterateOutputs(): - if p.is_image(): - [dim, w, h, d, junk] = p.get_dimensions() - if f.dimensions_in_reply: - print " __glXReadPixelReply(dpy, gc, %u, 0, 0, 0, %s, %s, %s, GL_TRUE);" % (dim, p.img_format, p.img_type, p.name) - else: - print " __glXReadPixelReply(dpy, gc, %u, %s, %s, %s, %s, %s, %s, GL_FALSE);" % (dim, w, h, d, p.img_format, p.img_type, p.name) - - got_reply = 1 - else: - if f.reply_always_array: - aa = "GL_TRUE" - else: - aa = "GL_FALSE" - - # gl_parameter.size() returns the size - # of the entire data item. If the - # item is a fixed-size array, this is - # the size of the whole array. This - # is not what __glXReadReply wants. It - # wants the size of a single data - # element in the reply packet. - # Dividing by the array size (1 for - # non-arrays) gives us this. - - s = p.size() / p.get_element_count() - print " %s __glXReadReply(dpy, %s, %s, %s);" % (return_str, s, p.name, aa) - got_reply = 1 - - - # If a reply wasn't read to fill an output parameter, - # read a NULL reply to get the return value. - - if not got_reply: - print " %s __glXReadReply(dpy, 0, NULL, GL_FALSE);" % (return_str) - - - elif self.debug: - # Only emit the extra glFinish call for functions - # that don't already require a reply from the server. - print ' __indirect_glFinish();' - - if self.debug: - print ' printf( "Exit %%s.\\n", "gl%s" );' % (name) - - - print ' UnlockDisplay(dpy); SyncHandle();' - - if name not in f.glx_vendorpriv_names: - print '#endif /* USE_XCB */' - - print ' }' - print ' return%s;' % (return_name) - return - - - def printPixelFunction(self, f): - if self.pixel_stubs.has_key( f.name ): - # Normally gl_function::get_parameter_string could be - # used. However, this call needs to have the missing - # dimensions (e.g., a fake height value for - # glTexImage1D) added in. - - p_string = "" - for param in f.parameterIterateGlxSend(): - if param.is_padding: - continue - - p_string += ", " + param.name - - if param.is_image(): - [dim, junk, junk, junk, junk] = param.get_dimensions() - - if f.pad_after(param): - p_string += ", 1" - - print ' %s(%s, %u%s );' % (self.pixel_stubs[f.name] , f.opcode_name(), dim, p_string) - return - - - if self.common_func_print_just_start(f, None): - trailer = " }" - else: - trailer = None - - - if f.can_be_large: - print 'if (cmdlen <= gc->maxSmallRenderCommandSize) {' - print ' if ( (gc->pc + cmdlen) > gc->bufEnd ) {' - print ' (void) __glXFlushRenderBuffer(gc, gc->pc);' - print ' }' - - if f.glx_rop == ~0: - opcode = "opcode" - else: - opcode = f.opcode_real_name() - - print 'emit_header(gc->pc, %s, cmdlen);' % (opcode) - - self.pixel_emit_args( f, "gc->pc", 0 ) - print 'gc->pc += cmdlen;' - print 'if (gc->pc > gc->limit) { (void) __glXFlushRenderBuffer(gc, gc->pc); }' - - if f.can_be_large: - print '}' - print 'else {' - - self.large_emit_begin(f, opcode) - self.pixel_emit_args(f, "pc", 1) - - print '}' - - if trailer: print trailer - return - - - def printRenderFunction(self, f): - # There is a class of GL functions that take a single pointer - # as a parameter. This pointer points to a fixed-size chunk - # of data, and the protocol for this functions is very - # regular. Since they are so regular and there are so many - # of them, special case them with generic functions. On - # x86, this saves about 26KB in the libGL.so binary. - - if f.variable_length_parameter() == None and len(f.parameters) == 1: - p = f.parameters[0] - if p.is_pointer(): - cmdlen = f.command_fixed_length() - if cmdlen in self.generic_sizes: - print ' generic_%u_byte( %s, %s );' % (cmdlen, f.opcode_real_name(), p.name) - return - - if self.common_func_print_just_start(f, None): - trailer = " }" - else: - trailer = None - - if self.debug: - print 'printf( "Enter %%s...\\n", "gl%s" );' % (f.name) - - if f.can_be_large: - print 'if (cmdlen <= gc->maxSmallRenderCommandSize) {' - print ' if ( (gc->pc + cmdlen) > gc->bufEnd ) {' - print ' (void) __glXFlushRenderBuffer(gc, gc->pc);' - print ' }' - - print 'emit_header(gc->pc, %s, cmdlen);' % (f.opcode_real_name()) - - self.common_emit_args(f, "gc->pc", 4, 0) - print 'gc->pc += cmdlen;' - print 'if (__builtin_expect(gc->pc > gc->limit, 0)) { (void) __glXFlushRenderBuffer(gc, gc->pc); }' - - if f.can_be_large: - print '}' - print 'else {' - - self.large_emit_begin(f) - self.common_emit_args(f, "pc", 8, 1) - - p = f.variable_length_parameter() - print ' __glXSendLargeCommand(gc, pc, %u, %s, %s);' % (p.offset + 8, p.name, p.size_string()) - print '}' - - if self.debug: - print '__indirect_glFinish();' - print 'printf( "Exit %%s.\\n", "gl%s" );' % (f.name) - - if trailer: print trailer - return - - -class PrintGlxProtoInit_c(gl_XML.gl_print_base): - def __init__(self): - gl_XML.gl_print_base.__init__(self) - - self.name = "glX_proto_send.py (from Mesa)" - self.license = license.bsd_license_template % ( \ -"""Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. -(C) Copyright IBM Corporation 2004""", "PRECISION INSIGHT, IBM") - return - - - def printRealHeader(self): - print """/** - * \\file indirect_init.c - * Initialize indirect rendering dispatch table. - * - * \\author Kevin E. Martin - * \\author Brian Paul - * \\author Ian Romanick - */ - -#include "indirect_init.h" -#include "indirect.h" -#include "glapi.h" - - -/** - * No-op function used to initialize functions that have no GLX protocol - * support. - */ -static int NoOp(void) -{ - return 0; -} - -/** - * Create and initialize a new GL dispatch table. The table is initialized - * with GLX indirect rendering protocol functions. - */ -__GLapi * __glXNewIndirectAPI( void ) -{ - __GLapi *glAPI; - GLuint entries; - - entries = _glapi_get_dispatch_table_size(); - glAPI = (__GLapi *) Xmalloc(entries * sizeof(void *)); - - /* first, set all entries to point to no-op functions */ - { - int i; - void **dispatch = (void **) glAPI; - for (i = 0; i < entries; i++) { - dispatch[i] = (void *) NoOp; - } - } - - /* now, initialize the entries we understand */""" - - def printRealFooter(self): - print """ - return glAPI; -} -""" - return - - - def printBody(self, api): - for [name, number] in api.categoryIterate(): - if number != None: - preamble = '\n /* %3u. %s */\n\n' % (int(number), name) - else: - preamble = '\n /* %s */\n\n' % (name) - - for func in api.functionIterateByCategory(name): - if func.client_supported_for_indirect(): - print '%s glAPI->%s = __indirect_gl%s;' % (preamble, func.name, func.name) - preamble = '' - - return - - -class PrintGlxProtoInit_h(gl_XML.gl_print_base): - def __init__(self): - gl_XML.gl_print_base.__init__(self) - - self.name = "glX_proto_send.py (from Mesa)" - self.license = license.bsd_license_template % ( \ -"""Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. -(C) Copyright IBM Corporation 2004""", "PRECISION INSIGHT, IBM") - self.header_tag = "_INDIRECT_H_" - - self.last_category = "" - return - - - def printRealHeader(self): - print """/** - * \\file - * Prototypes for indirect rendering functions. - * - * \\author Kevin E. Martin - * \\author Ian Romanick - */ -""" - self.printVisibility( "HIDDEN", "hidden" ) - self.printFastcall() - self.printNoinline() - - print """ -#include "glxclient.h" - -extern HIDDEN NOINLINE CARD32 __glXReadReply( Display *dpy, size_t size, - void * dest, GLboolean reply_is_always_array ); - -extern HIDDEN NOINLINE void __glXReadPixelReply( Display *dpy, - __GLXcontext * gc, unsigned max_dim, GLint width, GLint height, - GLint depth, GLenum format, GLenum type, void * dest, - GLboolean dimensions_in_reply ); - -extern HIDDEN NOINLINE FASTCALL GLubyte * __glXSetupSingleRequest( - __GLXcontext * gc, GLint sop, GLint cmdlen ); - -extern HIDDEN NOINLINE FASTCALL GLubyte * __glXSetupVendorRequest( - __GLXcontext * gc, GLint code, GLint vop, GLint cmdlen ); -""" - - - def printBody(self, api): - for func in api.functionIterateGlx(): - params = func.get_parameter_string() - - print 'extern HIDDEN %s __indirect_gl%s(%s);' % (func.return_type, func.name, params) - - for n in func.entry_points: - if func.has_different_protocol(n): - asdf = func.static_glx_name(n) - if asdf not in func.static_entry_points: - print 'extern HIDDEN %s gl%s(%s);' % (func.return_type, asdf, params) - else: - print 'GLAPI %s GLAPIENTRY gl%s(%s);' % (func.return_type, asdf, params) - - break - - - -def show_usage(): - print "Usage: %s [-f input_file_name] [-m output_mode] [-d]" % sys.argv[0] - print " -m output_mode Output mode can be one of 'proto', 'init_c' or 'init_h'." - print " -d Enable extra debug information in the generated code." - sys.exit(1) - - -if __name__ == '__main__': - file_name = "gl_API.xml" - - try: - (args, trail) = getopt.getopt(sys.argv[1:], "f:m:d") - except Exception,e: - show_usage() - - debug = 0 - mode = "proto" - for (arg,val) in args: - if arg == "-f": - file_name = val - elif arg == "-m": - mode = val - elif arg == "-d": - debug = 1 - - if mode == "proto": - printer = PrintGlxProtoStubs() - elif mode == "init_c": - printer = PrintGlxProtoInit_c() - elif mode == "init_h": - printer = PrintGlxProtoInit_h() - else: - show_usage() - - - printer.debug = debug - api = gl_XML.parse_GL_API( file_name, glX_XML.glx_item_factory() ) - - printer.Print( api ) diff --git a/src/mesa/glapi/glX_proto_size.py b/src/mesa/glapi/glX_proto_size.py deleted file mode 100644 index 95cb5110cc3..00000000000 --- a/src/mesa/glapi/glX_proto_size.py +++ /dev/null @@ -1,704 +0,0 @@ -#!/usr/bin/env python - -# (C) Copyright IBM Corporation 2004, 2005 -# 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 -# 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. -# -# Authors: -# Ian Romanick - -import gl_XML, glX_XML -import license -import sys, getopt, copy, string - - -class glx_enum_function: - def __init__(self, func_name, enum_dict): - self.name = func_name - self.mode = 1 - self.sig = None - - # "enums" is a set of lists. The element in the set is the - # value of the enum. The list is the list of names for that - # value. For example, [0x8126] = {"POINT_SIZE_MIN", - # "POINT_SIZE_MIN_ARB", "POINT_SIZE_MIN_EXT", - # "POINT_SIZE_MIN_SGIS"}. - - self.enums = {} - - # "count" is indexed by count values. Each element of count - # is a list of index to "enums" that have that number of - # associated data elements. For example, [4] = - # {GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION, - # GL_AMBIENT_AND_DIFFUSE} (the enum names are used here, - # but the actual hexadecimal values would be in the array). - - self.count = {} - - - # Fill self.count and self.enums using the dictionary of enums - # that was passed in. The generic Get functions (e.g., - # GetBooleanv and friends) are handled specially here. In - # the data the generic Get functions are refered to as "Get". - - if func_name in ["GetIntegerv", "GetBooleanv", "GetFloatv", "GetDoublev"]: - match_name = "Get" - else: - match_name = func_name - - mode_set = 0 - for enum_name in enum_dict: - e = enum_dict[ enum_name ] - - if e.functions.has_key( match_name ): - [count, mode] = e.functions[ match_name ] - - if mode_set and mode != self.mode: - raise RuntimeError("Not all enums for %s have the same mode." % (func_name)) - - self.mode = mode - - if self.enums.has_key( e.value ): - if e.name not in self.enums[ e.value ]: - self.enums[ e.value ].append( e ) - else: - if not self.count.has_key( count ): - self.count[ count ] = [] - - self.enums[ e.value ] = [ e ] - self.count[ count ].append( e.value ) - - - return - - - def signature( self ): - if self.sig == None: - self.sig = "" - for i in self.count: - if i == None: - raise RuntimeError("i is None. WTF?") - - self.count[i].sort() - for e in self.count[i]: - self.sig += "%04x,%d," % (e, i) - - return self.sig - - - def is_set( self ): - return self.mode - - - def PrintUsingTable(self): - """Emit the body of the __gl*_size function using a pair - of look-up tables and a mask. The mask is calculated such - that (e & mask) is unique for all the valid values of e for - this function. The result of (e & mask) is used as an index - into the first look-up table. If it matches e, then the - same entry of the second table is returned. Otherwise zero - is returned. - - It seems like this should cause better code to be generated. - However, on x86 at least, the resulting .o file is about 20% - larger then the switch-statment version. I am leaving this - code in because the results may be different on other - platforms (e.g., PowerPC or x86-64).""" - - return 0 - count = 0 - for a in self.enums: - count += 1 - - if self.count.has_key(-1): - return 0 - - # Determine if there is some mask M, such that M = (2^N) - 1, - # that will generate unique values for all of the enums. - - mask = 0 - for i in [1, 2, 3, 4, 5, 6, 7, 8]: - mask = (1 << i) - 1 - - fail = 0; - for a in self.enums: - for b in self.enums: - if a != b: - if (a & mask) == (b & mask): - fail = 1; - - if not fail: - break; - else: - mask = 0 - - if (mask != 0) and (mask < (2 * count)): - masked_enums = {} - masked_count = {} - - for i in range(0, mask + 1): - masked_enums[i] = "0"; - masked_count[i] = 0; - - for c in self.count: - for e in self.count[c]: - i = e & mask - enum_obj = self.enums[e][0] - masked_enums[i] = '0x%04x /* %s */' % (e, enum_obj.name ) - masked_count[i] = c - - - print ' static const GLushort a[%u] = {' % (mask + 1) - for e in masked_enums: - print ' %s, ' % (masked_enums[e]) - print ' };' - - print ' static const GLubyte b[%u] = {' % (mask + 1) - for c in masked_count: - print ' %u, ' % (masked_count[c]) - print ' };' - - print ' const unsigned idx = (e & 0x%02xU);' % (mask) - print '' - print ' return (e == a[idx]) ? (GLint) b[idx] : 0;' - return 1; - else: - return 0; - - - def PrintUsingSwitch(self, name): - """Emit the body of the __gl*_size function using a - switch-statement.""" - - print ' switch( e ) {' - - for c in self.count: - for e in self.count[c]: - first = 1 - - # There may be multiple enums with the same - # value. This happens has extensions are - # promoted from vendor-specific or EXT to - # ARB and to the core. Emit the first one as - # a case label, and emit the others as - # commented-out case labels. - - list = {} - for enum_obj in self.enums[e]: - list[ enum_obj.priority() ] = enum_obj.name - - keys = list.keys() - keys.sort() - for k in keys: - j = list[k] - if first: - print ' case GL_%s:' % (j) - first = 0 - else: - print '/* case GL_%s:*/' % (j) - - if c == -1: - print ' return __gl%s_variable_size( e );' % (name) - else: - print ' return %u;' % (c) - - print ' default: return 0;' - print ' }' - - - def Print(self, name): - print 'INTERNAL PURE FASTCALL GLint' - print '__gl%s_size( GLenum e )' % (name) - print '{' - - if not self.PrintUsingTable(): - self.PrintUsingSwitch(name) - - print '}' - print '' - - -class glx_server_enum_function(glx_enum_function): - def __init__(self, func, enum_dict): - glx_enum_function.__init__(self, func.name, enum_dict) - - self.function = func - return - - - def signature( self ): - if self.sig == None: - sig = glx_enum_function.signature(self) - - p = self.function.variable_length_parameter() - if p: - sig += "%u" % (p.size()) - - self.sig = sig - - return self.sig; - - - def Print(self, name, printer): - f = self.function - printer.common_func_print_just_header( f ) - - fixup = [] - - foo = {} - for param_name in f.count_parameter_list: - o = f.offset_of( param_name ) - foo[o] = param_name - - for param_name in f.counter_list: - o = f.offset_of( param_name ) - foo[o] = param_name - - keys = foo.keys() - keys.sort() - for o in keys: - p = f.parameters_by_name[ foo[o] ] - - printer.common_emit_one_arg(p, "pc", 0) - fixup.append( p.name ) - - - print ' GLsizei compsize;' - print '' - - printer.common_emit_fixups(fixup) - - print '' - print ' compsize = __gl%s_size(%s);' % (f.name, string.join(f.count_parameter_list, ",")) - p = f.variable_length_parameter() - print ' return __GLX_PAD(%s);' % (p.size_string()) - - print '}' - print '' - - -class PrintGlxSizeStubs_common(gl_XML.gl_print_base): - do_get = (1 << 0) - do_set = (1 << 1) - - def __init__(self, which_functions): - gl_XML.gl_print_base.__init__(self) - - self.name = "glX_proto_size.py (from Mesa)" - self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2004", "IBM") - - self.emit_set = ((which_functions & PrintGlxSizeStubs_common.do_set) != 0) - self.emit_get = ((which_functions & PrintGlxSizeStubs_common.do_get) != 0) - return - - -class PrintGlxSizeStubs_c(PrintGlxSizeStubs_common): - def printRealHeader(self): - print '' - print '#include ' - if self.emit_get: - print '#include "indirect_size_get.h"' - print '#include "glxserver.h"' - print '#include "indirect_util.h"' - - print '#include "indirect_size.h"' - - print '' - self.printPure() - print '' - self.printFastcall() - print '' - self.printVisibility( "INTERNAL", "internal" ) - print '' - print '' - print '#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__APPLE__)' - print '# undef HAVE_ALIAS' - print '#endif' - print '#ifdef HAVE_ALIAS' - print '# define ALIAS2(from,to) \\' - print ' INTERNAL PURE FASTCALL GLint __gl ## from ## _size( GLenum e ) \\' - print ' __attribute__ ((alias( # to )));' - print '# define ALIAS(from,to) ALIAS2( from, __gl ## to ## _size )' - print '#else' - print '# define ALIAS(from,to) \\' - print ' INTERNAL PURE FASTCALL GLint __gl ## from ## _size( GLenum e ) \\' - print ' { return __gl ## to ## _size( e ); }' - print '#endif' - print '' - print '' - - - def printBody(self, api): - enum_sigs = {} - aliases = [] - - for func in api.functionIterateGlx(): - ef = glx_enum_function( func.name, api.enums_by_name ) - if len(ef.enums) == 0: - continue - - if (ef.is_set() and self.emit_set) or (not ef.is_set() and self.emit_get): - sig = ef.signature() - if enum_sigs.has_key( sig ): - aliases.append( [func.name, enum_sigs[ sig ]] ) - else: - enum_sigs[ sig ] = func.name - ef.Print( func.name ) - - - for [alias_name, real_name] in aliases: - print 'ALIAS( %s, %s )' % (alias_name, real_name) - - - -class PrintGlxSizeStubs_h(PrintGlxSizeStubs_common): - def printRealHeader(self): - print """/** - * \\file - * Prototypes for functions used to determine the number of data elements in - * various GLX protocol messages. - * - * \\author Ian Romanick - */ -""" - self.printPure(); - print '' - self.printFastcall(); - print '' - self.printVisibility( "INTERNAL", "internal" ); - print '' - - - def printBody(self, api): - for func in api.functionIterateGlx(): - ef = glx_enum_function( func.name, api.enums_by_name ) - if len(ef.enums) == 0: - continue - - if (ef.is_set() and self.emit_set) or (not ef.is_set() and self.emit_get): - print 'extern INTERNAL PURE FASTCALL GLint __gl%s_size(GLenum);' % (func.name) - - -class PrintGlxReqSize_common(gl_XML.gl_print_base): - """Common base class for PrintGlxSizeReq_h and PrintGlxSizeReq_h. - - The main purpose of this common base class is to provide the infrastructure - for the derrived classes to iterate over the same set of functions. - """ - - def __init__(self): - gl_XML.gl_print_base.__init__(self) - - self.name = "glX_proto_size.py (from Mesa)" - self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005", "IBM") - - -class PrintGlxReqSize_h(PrintGlxReqSize_common): - def __init__(self): - PrintGlxReqSize_common.__init__(self) - self.header_tag = "_INDIRECT_REQSIZE_H_" - - - def printRealHeader(self): - self.printVisibility("HIDDEN", "hidden") - print '' - self.printPure() - print '' - - - def printBody(self, api): - for func in api.functionIterateGlx(): - if not func.ignore and func.has_variable_size_request(): - print 'extern PURE HIDDEN int __glX%sReqSize(const GLbyte *pc, Bool swap);' % (func.name) - - -class PrintGlxReqSize_c(PrintGlxReqSize_common): - """Create the server-side 'request size' functions. - - Create the server-side functions that are used to determine what the - size of a varible length command should be. The server then uses - this value to determine if the incoming command packed it malformed. - """ - - def __init__(self): - PrintGlxReqSize_common.__init__(self) - self.counter_sigs = {} - - - def printRealHeader(self): - print '' - print '#include ' - print '#include "glxserver.h"' - print '#include "glxbyteorder.h"' - print '#include "indirect_size.h"' - print '#include "indirect_reqsize.h"' - print '' - print '#define __GLX_PAD(x) (((x) + 3) & ~3)' - print '' - print '#if defined(__CYGWIN__) || defined(__MINGW32__)' - print '# undef HAVE_ALIAS' - print '#endif' - print '#ifdef HAVE_ALIAS' - print '# define ALIAS2(from,to) \\' - print ' GLint __glX ## from ## ReqSize( const GLbyte * pc, Bool swap ) \\' - print ' __attribute__ ((alias( # to )));' - print '# define ALIAS(from,to) ALIAS2( from, __glX ## to ## ReqSize )' - print '#else' - print '# define ALIAS(from,to) \\' - print ' GLint __glX ## from ## ReqSize( const GLbyte * pc, Bool swap ) \\' - print ' { return __glX ## to ## ReqSize( pc, swap ); }' - print '#endif' - print '' - print '' - - - def printBody(self, api): - aliases = [] - enum_functions = {} - enum_sigs = {} - - for func in api.functionIterateGlx(): - if not func.has_variable_size_request(): continue - - ef = glx_server_enum_function( func, api.enums_by_name ) - if len(ef.enums) == 0: continue - - sig = ef.signature() - - if not enum_functions.has_key(func.name): - enum_functions[ func.name ] = sig - - if not enum_sigs.has_key( sig ): - enum_sigs[ sig ] = ef - - - - for func in api.functionIterateGlx(): - # Even though server-handcode fuctions are on "the - # list", and prototypes are generated for them, there - # isn't enough information to generate a size - # function. If there was enough information, they - # probably wouldn't need to be handcoded in the first - # place! - - if func.server_handcode: continue - if not func.has_variable_size_request(): continue - - if enum_functions.has_key(func.name): - sig = enum_functions[func.name] - ef = enum_sigs[ sig ] - - if ef.name != func.name: - aliases.append( [func.name, ef.name] ) - else: - ef.Print( func.name, self ) - - elif func.images: - self.printPixelFunction(func) - elif func.has_variable_size_request(): - a = self.printCountedFunction(func) - if a: aliases.append(a) - - - for [alias_name, real_name] in aliases: - print 'ALIAS( %s, %s )' % (alias_name, real_name) - - return - - - def common_emit_fixups(self, fixup): - """Utility function to emit conditional byte-swaps.""" - - if fixup: - print ' if (swap) {' - for name in fixup: - print ' %s = bswap_32(%s);' % (name, name) - print ' }' - - return - - - def common_emit_one_arg(self, p, pc, adjust): - offset = p.offset - dst = p.string() - src = '(%s *)' % (p.type_string()) - print '%-18s = *%11s(%s + %u);' % (dst, src, pc, offset + adjust); - return - - - def common_func_print_just_header(self, f): - print 'int' - print '__glX%sReqSize( const GLbyte * pc, Bool swap )' % (f.name) - print '{' - - - def printPixelFunction(self, f): - self.common_func_print_just_header(f) - - f.offset_of( f.parameters[0].name ) - [dim, w, h, d, junk] = f.get_images()[0].get_dimensions() - - print ' GLint row_length = * (GLint *)(pc + 4);' - - if dim < 3: - fixup = ['row_length', 'skip_rows', 'alignment'] - print ' GLint image_height = 0;' - print ' GLint skip_images = 0;' - print ' GLint skip_rows = * (GLint *)(pc + 8);' - print ' GLint alignment = * (GLint *)(pc + 16);' - else: - fixup = ['row_length', 'image_height', 'skip_rows', 'skip_images', 'alignment'] - print ' GLint image_height = * (GLint *)(pc + 8);' - print ' GLint skip_rows = * (GLint *)(pc + 16);' - print ' GLint skip_images = * (GLint *)(pc + 20);' - print ' GLint alignment = * (GLint *)(pc + 32);' - - img = f.images[0] - for p in f.parameterIterateGlxSend(): - if p.name in [w, h, d, img.img_format, img.img_type, img.img_target]: - self.common_emit_one_arg(p, "pc", 0) - fixup.append( p.name ) - - print '' - - self.common_emit_fixups(fixup) - - if img.img_null_flag: - print '' - print ' if (*(CARD32 *) (pc + %s))' % (img.offset - 4) - print ' return 0;' - - print '' - print ' return __glXImageSize(%s, %s, %s, %s, %s, %s,' % (img.img_format, img.img_type, img.img_target, w, h, d ) - print ' image_height, row_length, skip_images,' - print ' skip_rows, alignment);' - print '}' - print '' - return - - - def printCountedFunction(self, f): - - sig = "" - offset = 0 - fixup = [] - params = [] - plus = '' - size = '' - param_offsets = {} - - # Calculate the offset of each counter parameter and the - # size string for the variable length parameter(s). While - # that is being done, calculate a unique signature for this - # function. - - for p in f.parameterIterateGlxSend(): - if p.is_counter: - fixup.append( p.name ) - params.append( p ) - elif p.counter: - s = p.size() - if s == 0: s = 1 - - sig += "(%u,%u)" % (f.offset_of(p.counter), s) - size += '%s%s' % (plus, p.size_string()) - plus = ' + ' - - - # If the calculated signature matches a function that has - # already be emitted, don't emit this function. Instead, add - # it to the list of function aliases. - - if self.counter_sigs.has_key(sig): - n = self.counter_sigs[sig]; - alias = [f.name, n] - else: - alias = None - self.counter_sigs[sig] = f.name - - self.common_func_print_just_header(f) - - for p in params: - self.common_emit_one_arg(p, "pc", 0) - - - print '' - self.common_emit_fixups(fixup) - print '' - - print ' return __GLX_PAD(%s);' % (size) - print '}' - print '' - - return alias - - -def show_usage(): - print "Usage: %s [-f input_file_name] -m output_mode [--only-get | --only-set] [--get-alias-set]" % sys.argv[0] - print " -m output_mode Output mode can be one of 'size_c' or 'size_h'." - print " --only-get Only emit 'get'-type functions." - print " --only-set Only emit 'set'-type functions." - print "" - print "By default, both 'get' and 'set'-type functions are emitted." - sys.exit(1) - - -if __name__ == '__main__': - file_name = "gl_API.xml" - - try: - (args, trail) = getopt.getopt(sys.argv[1:], "f:m:h:", ["only-get", "only-set", "header-tag"]) - except Exception,e: - show_usage() - - mode = None - header_tag = None - which_functions = PrintGlxSizeStubs_common.do_get | PrintGlxSizeStubs_common.do_set - - for (arg,val) in args: - if arg == "-f": - file_name = val - elif arg == "-m": - mode = val - elif arg == "--only-get": - which_functions = PrintGlxSizeStubs_common.do_get - elif arg == "--only-set": - which_functions = PrintGlxSizeStubs_common.do_set - elif (arg == '-h') or (arg == "--header-tag"): - header_tag = val - - if mode == "size_c": - printer = PrintGlxSizeStubs_c( which_functions ) - elif mode == "size_h": - printer = PrintGlxSizeStubs_h( which_functions ) - if header_tag: - printer.header_tag = header_tag - elif mode == "reqsize_c": - printer = PrintGlxReqSize_c() - elif mode == "reqsize_h": - printer = PrintGlxReqSize_h() - else: - show_usage() - - api = gl_XML.parse_GL_API( file_name, glX_XML.glx_item_factory() ) - - - printer.Print( api ) diff --git a/src/mesa/glapi/glX_server_table.py b/src/mesa/glapi/glX_server_table.py deleted file mode 100644 index f3962f875b0..00000000000 --- a/src/mesa/glapi/glX_server_table.py +++ /dev/null @@ -1,411 +0,0 @@ -#!/bin/env python - -# (C) Copyright IBM Corporation 2005, 2006 -# 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 -# 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. -# -# Authors: -# Ian Romanick - -import gl_XML, glX_XML, glX_proto_common, license -import sys, getopt - - -def log2(value): - for i in range(0, 30): - p = 1 << i - if p >= value: - return i - - return -1 - - -def round_down_to_power_of_two(n): - """Returns the nearest power-of-two less than or equal to n.""" - - for i in range(30, 0, -1): - p = 1 << i - if p <= n: - return p - - return -1 - - -class function_table: - def __init__(self, name, do_size_check): - self.name_base = name - self.do_size_check = do_size_check - - - self.max_bits = 1 - self.next_opcode_threshold = (1 << self.max_bits) - self.max_opcode = 0 - - self.functions = {} - self.lookup_table = [] - - # Minimum number of opcodes in a leaf node. - self.min_op_bits = 3 - self.min_op_count = (1 << self.min_op_bits) - return - - - def append(self, opcode, func): - self.functions[opcode] = func - - if opcode > self.max_opcode: - self.max_opcode = opcode - - if opcode > self.next_opcode_threshold: - bits = log2(opcode) - if (1 << bits) <= opcode: - bits += 1 - - self.max_bits = bits - self.next_opcode_threshold = 1 << bits - return - - - def divide_group(self, min_opcode, total): - """Divide the group starting min_opcode into subgroups. - Returns a tuple containing the number of bits consumed by - the node, the list of the children's tuple, and the number - of entries in the final array used by this node and its - children, and the depth of the subtree rooted at the node.""" - - remaining_bits = self.max_bits - total - next_opcode = min_opcode + (1 << remaining_bits) - empty_children = 0 - - for M in range(0, remaining_bits): - op_count = 1 << (remaining_bits - M); - child_count = 1 << M; - - empty_children = 0 - full_children = 0 - for i in range(min_opcode, next_opcode, op_count): - used = 0 - empty = 0 - - for j in range(i, i + op_count): - if self.functions.has_key(j): - used += 1; - else: - empty += 1; - - - if empty == op_count: - empty_children += 1 - - if used == op_count: - full_children += 1 - - if (empty_children > 0) or (full_children == child_count) or (op_count <= self.min_op_count): - break - - - # If all the remaining bits are used by this node, as is the - # case when M is 0 or remaining_bits, the node is a leaf. - - if (M == 0) or (M == remaining_bits): - return [remaining_bits, [], 0, 0] - else: - children = [] - count = 1 - depth = 1 - all_children_are_nonempty_leaf_nodes = 1 - for i in range(min_opcode, next_opcode, op_count): - n = self.divide_group(i, total + M) - - if not (n[1] == [] and not self.is_empty_leaf(i, n[0])): - all_children_are_nonempty_leaf_nodes = 0 - - children.append(n) - count += n[2] + 1 - - if n[3] >= depth: - depth = n[3] + 1 - - # If all of the child nodes are non-empty leaf nodes, pull - # them up and make this node a leaf. - - if all_children_are_nonempty_leaf_nodes: - return [remaining_bits, [], 0, 0] - else: - return [M, children, count, depth] - - - def is_empty_leaf(self, base_opcode, M): - for op in range(base_opcode, base_opcode + (1 << M)): - if self.functions.has_key(op): - return 0 - break - - return 1 - - - def dump_tree(self, node, base_opcode, remaining_bits, base_entry, depth): - M = node[0] - children = node[1] - child_M = remaining_bits - M - - - # This actually an error condition. - if children == []: - return - - print ' /* [%u] -> opcode range [%u, %u], node depth %u */' % (base_entry, base_opcode, base_opcode + (1 << remaining_bits), depth) - print ' %u,' % (M) - - base_entry += (1 << M) + 1 - - child_index = base_entry - child_base_opcode = base_opcode - for child in children: - if child[1] == []: - if self.is_empty_leaf(child_base_opcode, child_M): - print ' EMPTY_LEAF,' - else: - # Emit the index of the next dispatch - # function. Then add all the - # dispatch functions for this leaf - # node to the dispatch function - # lookup table. - - print ' LEAF(%u),' % (len(self.lookup_table)) - - for op in range(child_base_opcode, child_base_opcode + (1 << child_M)): - if self.functions.has_key(op): - func = self.functions[op] - size = func.command_fixed_length() - - if func.glx_rop != 0: - size += 4 - - size = ((size + 3) & ~3) - - if func.has_variable_size_request(): - size_name = "__glX%sReqSize" % (func.name) - else: - size_name = "" - - if func.glx_vendorpriv == op: - func_name = func.glx_vendorpriv_names[0] - else: - func_name = func.name - - temp = [op, "__glXDisp_%s" % (func_name), "__glXDispSwap_%s" % (func_name), size, size_name] - else: - temp = [op, "NULL", "NULL", 0, ""] - - self.lookup_table.append(temp) - else: - print ' %u,' % (child_index) - child_index += child[2] - - child_base_opcode += 1 << child_M - - print '' - - child_index = base_entry - for child in children: - if child[1] != []: - self.dump_tree(child, base_opcode, remaining_bits - M, child_index, depth + 1) - child_index += child[2] - - base_opcode += 1 << (remaining_bits - M) - - - def Print(self): - # Each dispatch table consists of two data structures. - # - # The first structure is an N-way tree where the opcode for - # the function is the key. Each node switches on a range of - # bits from the opcode. M bits are extracted from the opcde - # and are used as an index to select one of the N, where - # N = 2^M, children. - # - # The tree is stored as a flat array. The first value is the - # number of bits, M, used by the node. For inner nodes, the - # following 2^M values are indexes into the array for the - # child nodes. For leaf nodes, the followign 2^M values are - # indexes into the second data structure. - # - # If an inner node's child index is 0, the child is an empty - # leaf node. That is, none of the opcodes selectable from - # that child exist. Since most of the possible opcode space - # is unused, this allows compact data storage. - # - # The second data structure is an array of pairs of function - # pointers. Each function contains a pointer to a protocol - # decode function and a pointer to a byte-swapped protocol - # decode function. Elements in this array are selected by the - # leaf nodes of the first data structure. - # - # As the tree is traversed, an accumulator is kept. This - # accumulator counts the bits of the opcode consumed by the - # traversal. When accumulator + M = B, where B is the - # maximum number of bits in an opcode, the traversal has - # reached a leaf node. The traversal starts with the most - # significant bits and works down to the least significant - # bits. - # - # Creation of the tree is the most complicated part. At - # each node the elements are divided into groups of 2^M - # elements. The value of M selected is the smallest possible - # value where all of the groups are either empty or full, or - # the groups are a preset minimum size. If all the children - # of a node are non-empty leaf nodes, the children are merged - # to create a single leaf node that replaces the parent. - - tree = self.divide_group(0, 0) - - print '/*****************************************************************/' - print '/* tree depth = %u */' % (tree[3]) - print 'static const int_fast16_t %s_dispatch_tree[%u] = {' % (self.name_base, tree[2]) - self.dump_tree(tree, 0, self.max_bits, 0, 1) - print '};\n' - - # After dumping the tree, dump the function lookup table. - - print 'static const void *%s_function_table[%u][2] = {' % (self.name_base, len(self.lookup_table)) - index = 0 - for func in self.lookup_table: - opcode = func[0] - name = func[1] - name_swap = func[2] - - print ' /* [% 3u] = %5u */ {%s, %s},' % (index, opcode, name, name_swap) - - index += 1 - - print '};\n' - - if self.do_size_check: - var_table = [] - - print 'static const int_fast16_t %s_size_table[%u][2] = {' % (self.name_base, len(self.lookup_table)) - index = 0 - var_table = [] - for func in self.lookup_table: - opcode = func[0] - fixed = func[3] - var = func[4] - - if var != "": - var_offset = "%2u" % (len(var_table)) - var_table.append(var) - else: - var_offset = "~0" - - print ' /* [%3u] = %5u */ {%3u, %s},' % (index, opcode, fixed, var_offset) - index += 1 - - - print '};\n' - - - print 'static const gl_proto_size_func %s_size_func_table[%u] = {' % (self.name_base, len(var_table)) - for func in var_table: - print ' %s,' % (func) - - print '};\n' - - - print 'const struct __glXDispatchInfo %s_dispatch_info = {' % (self.name_base) - print ' %u,' % (self.max_bits) - print ' %s_dispatch_tree,' % (self.name_base) - print ' %s_function_table,' % (self.name_base) - if self.do_size_check: - print ' %s_size_table,' % (self.name_base) - print ' %s_size_func_table' % (self.name_base) - else: - print ' NULL,' - print ' NULL' - print '};\n' - return - - -class PrintGlxDispatchTables(glX_proto_common.glx_print_proto): - def __init__(self): - gl_XML.gl_print_base.__init__(self) - self.name = "glX_server_table.py (from Mesa)" - self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005, 2006", "IBM") - - self.rop_functions = function_table("Render", 1) - self.sop_functions = function_table("Single", 0) - self.vop_functions = function_table("VendorPriv", 0) - return - - - def printRealHeader(self): - print '#include ' - print '#include "glxserver.h"' - print '#include "glxext.h"' - print '#include "indirect_dispatch.h"' - print '#include "indirect_reqsize.h"' - print '#include "g_disptab.h"' - print '#include "indirect_table.h"' - print '' - return - - - def printBody(self, api): - for f in api.functionIterateAll(): - if not f.ignore and f.vectorequiv == None: - if f.glx_rop != 0: - self.rop_functions.append(f.glx_rop, f) - if f.glx_sop != 0: - self.sop_functions.append(f.glx_sop, f) - if f.glx_vendorpriv != 0: - self.vop_functions.append(f.glx_vendorpriv, f) - - self.sop_functions.Print() - self.rop_functions.Print() - self.vop_functions.Print() - return - - -if __name__ == '__main__': - file_name = "gl_API.xml" - - try: - (args, trail) = getopt.getopt(sys.argv[1:], "f:m") - except Exception,e: - show_usage() - - mode = "table_c" - for (arg,val) in args: - if arg == "-f": - file_name = val - elif arg == "-m": - mode = val - - if mode == "table_c": - printer = PrintGlxDispatchTables() - else: - show_usage() - - - api = gl_XML.parse_GL_API( file_name, glX_XML.glx_item_factory() ) - - - printer.Print( api ) diff --git a/src/mesa/glapi/gl_API.dtd b/src/mesa/glapi/gl_API.dtd deleted file mode 100644 index 30c646c9244..00000000000 --- a/src/mesa/glapi/gl_API.dtd +++ /dev/null @@ -1,140 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/mesa/glapi/gl_API.xml b/src/mesa/glapi/gl_API.xml deleted file mode 100644 index fbf8b0c3e4a..00000000000 --- a/src/mesa/glapi/gl_API.xml +++ /dev/null @@ -1,12505 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/mesa/glapi/gl_SPARC_asm.py b/src/mesa/glapi/gl_SPARC_asm.py deleted file mode 100644 index 33e752df38c..00000000000 --- a/src/mesa/glapi/gl_SPARC_asm.py +++ /dev/null @@ -1,275 +0,0 @@ -#!/usr/bin/env python - -# (C) Copyright IBM Corporation 2004 -# 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 -# 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. -# -# Authors: -# Ian Romanick - -import license -import gl_XML, glX_XML -import sys, getopt - -class PrintGenericStubs(gl_XML.gl_print_base): - def __init__(self): - gl_XML.gl_print_base.__init__(self) - self.name = "gl_SPARC_asm.py (from Mesa)" - self.license = license.bsd_license_template % ( \ -"""Copyright (C) 1999-2003 Brian Paul All Rights Reserved. -(C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM") - - - def printRealHeader(self): - print '#include "glapi/glapioffsets.h"' - print '' - print '#ifdef __arch64__' - print '#define GL_OFF(N)\t((N) * 8)' - print '#define GL_LL\t\tldx' - print '#define GL_TIE_LD(SYM)\t%tie_ldx(SYM)' - print '#define GL_STACK_SIZE\t128' - print '#else' - print '#define GL_OFF(N)\t((N) * 4)' - print '#define GL_LL\t\tld' - print '#define GL_TIE_LD(SYM)\t%tie_ld(SYM)' - print '#define GL_STACK_SIZE\t64' - print '#endif' - print '' - print '#define GLOBL_FN(x) .globl x ; .type x, @function' - print '#define HIDDEN(x) .hidden x' - print '' - print '\t.register %g2, #scratch' - print '\t.register %g3, #scratch' - print '' - print '\t.text' - print '' - print '\tGLOBL_FN(__glapi_sparc_icache_flush)' - print '\tHIDDEN(__glapi_sparc_icache_flush)' - print '\t.type\t__glapi_sparc_icache_flush, @function' - print '__glapi_sparc_icache_flush: /* %o0 = insn_addr */' - print '\tflush\t%o0' - print '\tretl' - print '\t nop' - print '' - print '\t.align\t32' - print '' - print '\t.type\t__glapi_sparc_get_pc, @function' - print '__glapi_sparc_get_pc:' - print '\tretl' - print '\t add\t%o7, %g2, %g2' - print '\t.size\t__glapi_sparc_get_pc, .-__glapi_sparc_get_pc' - print '' - print '#ifdef GLX_USE_TLS' - print '' - print '\tGLOBL_FN(__glapi_sparc_get_dispatch)' - print '\tHIDDEN(__glapi_sparc_get_dispatch)' - print '__glapi_sparc_get_dispatch:' - print '\tmov\t%o7, %g1' - print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2' - print '\tcall\t__glapi_sparc_get_pc' - print '\tadd\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2' - print '\tmov\t%g1, %o7' - print '\tsethi\t%tie_hi22(_glapi_tls_Dispatch), %g1' - print '\tadd\t%g1, %tie_lo10(_glapi_tls_Dispatch), %g1' - print '\tGL_LL\t[%g2 + %g1], %g2, GL_TIE_LD(_glapi_tls_Dispatch)' - print '\tretl' - print '\t mov\t%g2, %o0' - print '' - print '\t.data' - print '\t.align\t32' - print '' - print '\t/* --> sethi %hi(_glapi_tls_Dispatch), %g1 */' - print '\t/* --> or %g1, %lo(_glapi_tls_Dispatch), %g1 */' - print '\tGLOBL_FN(__glapi_sparc_tls_stub)' - print '\tHIDDEN(__glapi_sparc_tls_stub)' - print '__glapi_sparc_tls_stub: /* Call offset in %g3 */' - print '\tmov\t%o7, %g1' - print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2' - print '\tcall\t__glapi_sparc_get_pc' - print '\tadd\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2' - print '\tmov\t%g1, %o7' - print '\tsrl\t%g3, 10, %g3' - print '\tsethi\t%tie_hi22(_glapi_tls_Dispatch), %g1' - print '\tadd\t%g1, %tie_lo10(_glapi_tls_Dispatch), %g1' - print '\tGL_LL\t[%g2 + %g1], %g2, GL_TIE_LD(_glapi_tls_Dispatch)' - print '\tGL_LL\t[%g7+%g2], %g1' - print '\tGL_LL\t[%g1 + %g3], %g1' - print '\tjmp\t%g1' - print '\t nop' - print '\t.size\t__glapi_sparc_tls_stub, .-__glapi_sparc_tls_stub' - print '' - print '#define GL_STUB(fn, off)\t\t\t\t\\' - print '\tGLOBL_FN(fn);\t\t\t\t\t\\' - print 'fn:\tba\t__glapi_sparc_tls_stub;\t\t\t\\' - print '\t sethi\tGL_OFF(off), %g3;\t\t\t\\' - print '\t.size\tfn,.-fn;' - print '' - print '#elif defined(PTHREADS)' - print '' - print '\t/* 64-bit 0x00 --> sethi %hh(_glapi_Dispatch), %g1 */' - print '\t/* 64-bit 0x04 --> sethi %lm(_glapi_Dispatch), %g2 */' - print '\t/* 64-bit 0x08 --> or %g1, %hm(_glapi_Dispatch), %g1 */' - print '\t/* 64-bit 0x0c --> sllx %g1, 32, %g1 */' - print '\t/* 64-bit 0x10 --> add %g1, %g2, %g1 */' - print '\t/* 64-bit 0x14 --> ldx [%g1 + %lo(_glapi_Dispatch)], %g1 */' - print '' - print '\t/* 32-bit 0x00 --> sethi %hi(_glapi_Dispatch), %g1 */' - print '\t/* 32-bit 0x04 --> ld [%g1 + %lo(_glapi_Dispatch)], %g1 */' - print '' - print '\t.data' - print '\t.align\t32' - print '' - print '\tGLOBL_FN(__glapi_sparc_pthread_stub)' - print '\tHIDDEN(__glapi_sparc_pthread_stub)' - print '__glapi_sparc_pthread_stub: /* Call offset in %g3 */' - print '\tmov\t%o7, %g1' - print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2' - print '\tcall\t__glapi_sparc_get_pc' - print '\t add\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2' - print '\tmov\t%g1, %o7' - print '\tsethi\t%hi(_glapi_Dispatch), %g1' - print '\tor\t%g1, %lo(_glapi_Dispatch), %g1' - print '\tsrl\t%g3, 10, %g3' - print '\tGL_LL\t[%g2+%g1], %g2' - print '\tGL_LL\t[%g2], %g1' - print '\tcmp\t%g1, 0' - print '\tbe\t2f' - print '\t nop' - print '1:\tGL_LL\t[%g1 + %g3], %g1' - print '\tjmp\t%g1' - print '\t nop' - print '2:\tsave\t%sp, GL_STACK_SIZE, %sp' - print '\tmov\t%g3, %l0' - print '\tcall\t_glapi_get_dispatch' - print '\t nop' - print '\tmov\t%o0, %g1' - print '\tmov\t%l0, %g3' - print '\tba\t1b' - print '\t restore %g0, %g0, %g0' - print '\t.size\t__glapi_sparc_pthread_stub, .-__glapi_sparc_pthread_stub' - print '' - print '#define GL_STUB(fn, off)\t\t\t\\' - print '\tGLOBL_FN(fn);\t\t\t\t\\' - print 'fn:\tba\t__glapi_sparc_pthread_stub;\t\\' - print '\t sethi\tGL_OFF(off), %g3;\t\t\\' - print '\t.size\tfn,.-fn;' - print '' - print '#else /* Non-threaded version. */' - print '' - print '\t.type __glapi_sparc_nothread_stub, @function' - print '__glapi_sparc_nothread_stub: /* Call offset in %g3 */' - print '\tmov\t%o7, %g1' - print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2' - print '\tcall\t__glapi_sparc_get_pc' - print '\t add\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2' - print '\tmov\t%g1, %o7' - print '\tsrl\t%g3, 10, %g3' - print '\tsethi\t%hi(_glapi_Dispatch), %g1' - print '\tor\t%g1, %lo(_glapi_Dispatch), %g1' - print '\tGL_LL\t[%g2+%g1], %g2' - print '\tGL_LL\t[%g2], %g1' - print '\tGL_LL\t[%g1 + %g3], %g1' - print '\tjmp\t%g1' - print '\t nop' - print '\t.size\t__glapi_sparc_nothread_stub, .-__glapi_sparc_nothread_stub' - print '' - print '#define GL_STUB(fn, off)\t\t\t\\' - print '\tGLOBL_FN(fn);\t\t\t\t\\' - print 'fn:\tba\t__glapi_sparc_nothread_stub;\t\\' - print '\t sethi\tGL_OFF(off), %g3;\t\t\\' - print '\t.size\tfn,.-fn;' - print '' - print '#endif' - print '' - print '#define GL_STUB_ALIAS(fn, alias) \\' - print ' .globl fn; \\' - print ' .set fn, alias' - print '' - print '\t.text' - print '\t.align\t32' - print '' - print '\t.globl\tgl_dispatch_functions_start' - print '\tHIDDEN(gl_dispatch_functions_start)' - print 'gl_dispatch_functions_start:' - print '' - return - - def printRealFooter(self): - print '' - print '\t.globl\tgl_dispatch_functions_end' - print '\tHIDDEN(gl_dispatch_functions_end)' - print 'gl_dispatch_functions_end:' - return - - def printBody(self, api): - for f in api.functionIterateByOffset(): - name = f.dispatch_name() - - print '\tGL_STUB(gl%s, _gloffset_%s)' % (name, f.name) - - if not f.is_static_entry_point(f.name): - print '\tHIDDEN(gl%s)' % (name) - - for f in api.functionIterateByOffset(): - name = f.dispatch_name() - - if f.is_static_entry_point(f.name): - for n in f.entry_points: - if n != f.name: - text = '\tGL_STUB_ALIAS(gl%s, gl%s)' % (n, f.name) - - if f.has_different_protocol(n): - print '#ifndef GLX_INDIRECT_RENDERING' - print text - print '#endif' - else: - print text - - return - - -def show_usage(): - print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0] - sys.exit(1) - -if __name__ == '__main__': - file_name = "gl_API.xml" - mode = "generic" - - try: - (args, trail) = getopt.getopt(sys.argv[1:], "m:f:") - except Exception,e: - show_usage() - - for (arg,val) in args: - if arg == '-m': - mode = val - elif arg == "-f": - file_name = val - - if mode == "generic": - printer = PrintGenericStubs() - else: - print "ERROR: Invalid mode \"%s\" specified." % mode - show_usage() - - api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory()) - printer.Print(api) diff --git a/src/mesa/glapi/gl_XML.py b/src/mesa/glapi/gl_XML.py deleted file mode 100644 index a10a35e513c..00000000000 --- a/src/mesa/glapi/gl_XML.py +++ /dev/null @@ -1,967 +0,0 @@ -#!/usr/bin/env python - -# (C) Copyright IBM Corporation 2004, 2005 -# 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 -# 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. -# -# Authors: -# Ian Romanick - -import libxml2 -import re, sys, string -import typeexpr - - -def parse_GL_API( file_name, factory = None ): - doc = libxml2.readFile( file_name, None, libxml2.XML_PARSE_XINCLUDE + libxml2.XML_PARSE_NOBLANKS + libxml2.XML_PARSE_DTDVALID + libxml2.XML_PARSE_DTDATTR + libxml2.XML_PARSE_DTDLOAD + libxml2.XML_PARSE_NOENT ) - ret = doc.xincludeProcess() - - if not factory: - factory = gl_item_factory() - - api = factory.create_item( "api", None, None ) - api.process_element( doc ) - - # After the XML has been processed, we need to go back and assign - # dispatch offsets to the functions that request that their offsets - # be assigned by the scripts. Typically this means all functions - # that are not part of the ABI. - - for func in api.functionIterateByCategory(): - if func.assign_offset: - func.offset = api.next_offset; - api.next_offset += 1 - - doc.freeDoc() - - return api - - -def is_attr_true( element, name ): - """Read a name value from an element's attributes. - - The value read from the attribute list must be either 'true' or - 'false'. If the value is 'false', zero will be returned. If the - value is 'true', non-zero will be returned. An exception will be - raised for any other value.""" - - value = element.nsProp( name, None ) - if value == "true": - return 1 - elif value == "false": - return 0 - else: - raise RuntimeError('Invalid value "%s" for boolean "%s".' % (value, name)) - - -class gl_print_base: - """Base class of all API pretty-printers. - - In the model-view-controller pattern, this is the view. Any derived - class will want to over-ride the printBody, printRealHader, and - printRealFooter methods. Some derived classes may want to over-ride - printHeader and printFooter, or even Print (though this is unlikely). - """ - - def __init__(self): - # Name of the script that is generating the output file. - # Every derived class should set this to the name of its - # source file. - - self.name = "a" - - - # License on the *generated* source file. This may differ - # from the license on the script that is generating the file. - # Every derived class should set this to some reasonable - # value. - # - # See license.py for an example of a reasonable value. - - self.license = "The license for this file is unspecified." - - - # The header_tag is the name of the C preprocessor define - # used to prevent multiple inclusion. Typically only - # generated C header files need this to be set. Setting it - # causes code to be generated automatically in printHeader - # and printFooter. - - self.header_tag = None - - - # List of file-private defines that must be undefined at the - # end of the file. This can be used in header files to define - # names for use in the file, then undefine them at the end of - # the header file. - - self.undef_list = [] - return - - - def Print(self, api): - self.printHeader() - self.printBody(api) - self.printFooter() - return - - - def printHeader(self): - """Print the header associated with all files and call the printRealHeader method.""" - - print '/* DO NOT EDIT - This file generated automatically by %s script */' \ - % (self.name) - print '' - print '/*' - print ' * ' + self.license.replace('\n', '\n * ') - print ' */' - print '' - if self.header_tag: - print '#if !defined( %s )' % (self.header_tag) - print '# define %s' % (self.header_tag) - print '' - self.printRealHeader(); - return - - - def printFooter(self): - """Print the header associated with all files and call the printRealFooter method.""" - - self.printRealFooter() - - if self.undef_list: - print '' - for u in self.undef_list: - print "# undef %s" % (u) - - if self.header_tag: - print '' - print '#endif /* !defined( %s ) */' % (self.header_tag) - - - def printRealHeader(self): - """Print the "real" header for the created file. - - In the base class, this function is empty. All derived - classes should over-ride this function.""" - return - - - def printRealFooter(self): - """Print the "real" footer for the created file. - - In the base class, this function is empty. All derived - classes should over-ride this function.""" - return - - - def printPure(self): - """Conditionally define `PURE' function attribute. - - Conditionally defines a preprocessor macro `PURE' that wraps - GCC's `pure' function attribute. The conditional code can be - easilly adapted to other compilers that support a similar - feature. - - The name is also added to the file's undef_list. - """ - self.undef_list.append("PURE") - print """# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) -# define PURE __attribute__((pure)) -# else -# define PURE -# endif""" - return - - - def printFastcall(self): - """Conditionally define `FASTCALL' function attribute. - - Conditionally defines a preprocessor macro `FASTCALL' that - wraps GCC's `fastcall' function attribute. The conditional - code can be easilly adapted to other compilers that support a - similar feature. - - The name is also added to the file's undef_list. - """ - - self.undef_list.append("FASTCALL") - print """# if defined(__i386__) && defined(__GNUC__) && !defined(__CYGWIN__) && !defined(__MINGW32__) -# define FASTCALL __attribute__((fastcall)) -# else -# define FASTCALL -# endif""" - return - - - def printVisibility(self, S, s): - """Conditionally define visibility function attribute. - - Conditionally defines a preprocessor macro name S that wraps - GCC's visibility function attribute. The visibility used is - the parameter s. The conditional code can be easilly adapted - to other compilers that support a similar feature. - - The name is also added to the file's undef_list. - """ - - self.undef_list.append(S) - print """# if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))) && defined(__ELF__) -# define %s __attribute__((visibility("%s"))) -# else -# define %s -# endif""" % (S, s, S) - return - - - def printNoinline(self): - """Conditionally define `NOINLINE' function attribute. - - Conditionally defines a preprocessor macro `NOINLINE' that - wraps GCC's `noinline' function attribute. The conditional - code can be easilly adapted to other compilers that support a - similar feature. - - The name is also added to the file's undef_list. - """ - - self.undef_list.append("NOINLINE") - print """# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) -# define NOINLINE __attribute__((noinline)) -# else -# define NOINLINE -# endif""" - return - - -def real_function_name(element): - name = element.nsProp( "name", None ) - alias = element.nsProp( "alias", None ) - - if alias: - return alias - else: - return name - - -def real_category_name(c): - if re.compile("[1-9][0-9]*[.][0-9]+").match(c): - return "GL_VERSION_" + c.replace(".", "_") - else: - return c - - -def classify_category(name, number): - """Based on the category name and number, select a numerical class for it. - - Categories are divided into four classes numbered 0 through 3. The - classes are: - - 0. Core GL versions, sorted by version number. - 1. ARB extensions, sorted by extension number. - 2. Non-ARB extensions, sorted by extension number. - 3. Un-numbered extensions, sorted by extension name. - """ - - try: - core_version = float(name) - except Exception,e: - core_version = 0.0 - - if core_version > 0.0: - cat_type = 0 - key = name - elif name.startswith("GL_ARB_") or name.startswith("GLX_ARB_") or name.startswith("WGL_ARB_"): - cat_type = 1 - key = int(number) - else: - if number != None: - cat_type = 2 - key = int(number) - else: - cat_type = 3 - key = name - - - return [cat_type, key] - - -def create_parameter_string(parameters, include_names): - """Create a parameter string from a list of gl_parameters.""" - - list = [] - for p in parameters: - if p.is_padding: - continue - - if include_names: - list.append( p.string() ) - else: - list.append( p.type_string() ) - - if len(list) == 0: list = ["void"] - - return string.join(list, ", ") - - -class gl_item: - def __init__(self, element, context): - self.context = context - self.name = element.nsProp( "name", None ) - self.category = real_category_name( element.parent.nsProp( "name", None ) ) - return - - -class gl_type( gl_item ): - def __init__(self, element, context): - gl_item.__init__(self, element, context) - self.size = int( element.nsProp( "size", None ), 0 ) - - te = typeexpr.type_expression( None ) - tn = typeexpr.type_node() - tn.size = int( element.nsProp( "size", None ), 0 ) - tn.integer = not is_attr_true( element, "float" ) - tn.unsigned = is_attr_true( element, "unsigned" ) - tn.name = "GL" + self.name - te.set_base_type_node( tn ) - - self.type_expr = te - return - - - def get_type_expression(self): - return self.type_expr - - -class gl_enum( gl_item ): - def __init__(self, element, context): - gl_item.__init__(self, element, context) - self.value = int( element.nsProp( "value", None ), 0 ) - - temp = element.nsProp( "count", None ) - if not temp or temp == "?": - self.default_count = -1 - else: - try: - c = int(temp) - except Exception,e: - raise RuntimeError('Invalid count value "%s" for enum "%s" in function "%s" when an integer was expected.' % (temp, self.name, n)) - - self.default_count = c - - return - - - def priority(self): - """Calculate a 'priority' for this enum name. - - When an enum is looked up by number, there may be many - possible names, but only one is the 'prefered' name. The - priority is used to select which name is the 'best'. - - Highest precedence is given to core GL name. ARB extension - names have the next highest, followed by EXT extension names. - Vendor extension names are the lowest. - """ - - if self.name.endswith( "_BIT" ): - bias = 1 - else: - bias = 0 - - if self.category.startswith( "GL_VERSION_" ): - priority = 0 - elif self.category.startswith( "GL_ARB_" ): - priority = 2 - elif self.category.startswith( "GL_EXT_" ): - priority = 4 - else: - priority = 6 - - return priority + bias - - - -class gl_parameter: - def __init__(self, element, context): - self.name = element.nsProp( "name", None ) - - ts = element.nsProp( "type", None ) - self.type_expr = typeexpr.type_expression( ts, context ) - - temp = element.nsProp( "variable_param", None ) - if temp: - self.count_parameter_list = temp.split( ' ' ) - else: - self.count_parameter_list = [] - - # The count tag can be either a numeric string or the name of - # a variable. If it is the name of a variable, the int(c) - # statement will throw an exception, and the except block will - # take over. - - c = element.nsProp( "count", None ) - try: - count = int(c) - self.count = count - self.counter = None - except Exception,e: - count = 1 - self.count = 0 - self.counter = c - - self.count_scale = int(element.nsProp( "count_scale", None )) - - elements = (count * self.count_scale) - if elements == 1: - elements = 0 - - #if ts == "GLdouble": - # print '/* stack size -> %s = %u (before)*/' % (self.name, self.type_expr.get_stack_size()) - # print '/* # elements = %u */' % (elements) - self.type_expr.set_elements( elements ) - #if ts == "GLdouble": - # print '/* stack size -> %s = %u (after) */' % (self.name, self.type_expr.get_stack_size()) - - self.is_client_only = is_attr_true( element, 'client_only' ) - self.is_counter = is_attr_true( element, 'counter' ) - self.is_output = is_attr_true( element, 'output' ) - - - # Pixel data has special parameters. - - self.width = element.nsProp('img_width', None) - self.height = element.nsProp('img_height', None) - self.depth = element.nsProp('img_depth', None) - self.extent = element.nsProp('img_extent', None) - - self.img_xoff = element.nsProp('img_xoff', None) - self.img_yoff = element.nsProp('img_yoff', None) - self.img_zoff = element.nsProp('img_zoff', None) - self.img_woff = element.nsProp('img_woff', None) - - self.img_format = element.nsProp('img_format', None) - self.img_type = element.nsProp('img_type', None) - self.img_target = element.nsProp('img_target', None) - - self.img_pad_dimensions = is_attr_true( element, 'img_pad_dimensions' ) - self.img_null_flag = is_attr_true( element, 'img_null_flag' ) - self.img_send_null = is_attr_true( element, 'img_send_null' ) - - self.is_padding = is_attr_true( element, 'padding' ) - return - - - def compatible(self, other): - return 1 - - - def is_array(self): - return self.is_pointer() - - - def is_pointer(self): - return self.type_expr.is_pointer() - - - def is_image(self): - if self.width: - return 1 - else: - return 0 - - - def is_variable_length(self): - return len(self.count_parameter_list) or self.counter - - - def is_64_bit(self): - count = self.type_expr.get_element_count() - if count: - if (self.size() / count) == 8: - return 1 - else: - if self.size() == 8: - return 1 - - return 0 - - - def string(self): - return self.type_expr.original_string + " " + self.name - - - def type_string(self): - return self.type_expr.original_string - - - def get_base_type_string(self): - return self.type_expr.get_base_name() - - - def get_dimensions(self): - if not self.width: - return [ 0, "0", "0", "0", "0" ] - - dim = 1 - w = self.width - h = "1" - d = "1" - e = "1" - - if self.height: - dim = 2 - h = self.height - - if self.depth: - dim = 3 - d = self.depth - - if self.extent: - dim = 4 - e = self.extent - - return [ dim, w, h, d, e ] - - - def get_stack_size(self): - return self.type_expr.get_stack_size() - - - def size(self): - if self.is_image(): - return 0 - else: - return self.type_expr.get_element_size() - - - def get_element_count(self): - c = self.type_expr.get_element_count() - if c == 0: - return 1 - - return c - - - def size_string(self, use_parens = 1): - s = self.size() - if self.counter or self.count_parameter_list: - list = [ "compsize" ] - - if self.counter and self.count_parameter_list: - list.append( self.counter ) - elif self.counter: - list = [ self.counter ] - - if s > 1: - list.append( str(s) ) - - if len(list) > 1 and use_parens : - return "(%s)" % (string.join(list, " * ")) - else: - return string.join(list, " * ") - - elif self.is_image(): - return "compsize" - else: - return str(s) - - - def format_string(self): - if self.type_expr.original_string == "GLenum": - return "0x%x" - else: - return self.type_expr.format_string() - - - -class gl_function( gl_item ): - def __init__(self, element, context): - self.context = context - self.name = None - - self.entry_points = [] - self.return_type = "void" - self.parameters = [] - self.offset = -1 - self.initialized = 0 - self.images = [] - - self.assign_offset = 0 - - self.static_entry_points = [] - - # Track the parameter string (for the function prototype) - # for each entry-point. This is done because some functions - # change their prototype slightly when promoted from extension - # to ARB extension to core. glTexImage3DEXT and glTexImage3D - # are good examples of this. Scripts that need to generate - # code for these differing aliases need to real prototype - # for each entry-point. Otherwise, they may generate code - # that won't compile. - - self.parameter_strings = {} - - self.process_element( element ) - - return - - - def process_element(self, element): - name = element.nsProp( "name", None ) - alias = element.nsProp( "alias", None ) - - if is_attr_true(element, "static_dispatch"): - self.static_entry_points.append(name) - - self.entry_points.append( name ) - if alias: - true_name = alias - else: - true_name = name - - # Only try to set the offset when a non-alias - # entry-point is being processes. - - offset = element.nsProp( "offset", None ) - if offset: - try: - o = int( offset ) - self.offset = o - except Exception, e: - self.offset = -1 - if offset == "assign": - self.assign_offset = 1 - - - if not self.name: - self.name = true_name - elif self.name != true_name: - raise RuntimeError("Function true name redefined. Was %s, now %s." % (self.name, true_name)) - - - # There are two possible cases. The first time an entry-point - # with data is seen, self.initialized will be 0. On that - # pass, we just fill in the data. The next time an - # entry-point with data is seen, self.initialized will be 1. - # On that pass we have to make that the new values match the - # valuse from the previous entry-point. - - parameters = [] - return_type = "void" - child = element.children - while child: - if child.type == "element": - if child.name == "return": - return_type = child.nsProp( "type", None ) - elif child.name == "param": - param = self.context.factory.create_item( "parameter", child, self.context) - parameters.append( param ) - - child = child.next - - - if self.initialized: - if self.return_type != return_type: - raise RuntimeError( "Return type changed in %s. Was %s, now %s." % (name, self.return_type, return_type)) - - if len(parameters) != len(self.parameters): - raise RuntimeError( "Parameter count mismatch in %s. Was %d, now %d." % (name, len(self.parameters), len(parameters))) - - for j in range(0, len(parameters)): - p1 = parameters[j] - p2 = self.parameters[j] - if not p1.compatible( p2 ): - raise RuntimeError( 'Parameter type mismatch in %s. "%s" was "%s", now "%s".' % (name, p2.name, p2.type_expr.original_string, p1.type_expr.original_string)) - - - if true_name == name or not self.initialized: - self.return_type = return_type - self.parameters = parameters - - for param in self.parameters: - if param.is_image(): - self.images.append( param ) - - if element.children: - self.initialized = 1 - self.parameter_strings[name] = create_parameter_string(parameters, 1) - else: - self.parameter_strings[name] = None - - return - - - def get_images(self): - """Return potentially empty list of input images.""" - return self.images - - - def parameterIterator(self): - return self.parameters.__iter__(); - - - def get_parameter_string(self, entrypoint = None): - if entrypoint: - s = self.parameter_strings[ entrypoint ] - if s: - return s - - return create_parameter_string( self.parameters, 1 ) - - def get_called_parameter_string(self): - p_string = "" - comma = "" - - for p in self.parameterIterator(): - p_string = p_string + comma + p.name - comma = ", " - - return p_string - - - def is_abi(self): - return (self.offset >= 0 and not self.assign_offset) - - def is_static_entry_point(self, name): - return name in self.static_entry_points - - def dispatch_name(self): - if self.name in self.static_entry_points: - return self.name - else: - return "_dispatch_stub_%u" % (self.offset) - - def static_name(self, name): - if name in self.static_entry_points: - return name - else: - return "_dispatch_stub_%u" % (self.offset) - - -class gl_item_factory: - """Factory to create objects derived from gl_item.""" - - def create_item(self, item_name, element, context): - if item_name == "function": - return gl_function(element, context) - if item_name == "type": - return gl_type(element, context) - elif item_name == "enum": - return gl_enum(element, context) - elif item_name == "parameter": - return gl_parameter(element, context) - elif item_name == "api": - return gl_api(self) - else: - return None - - -class gl_api: - def __init__(self, factory): - self.functions_by_name = {} - self.enums_by_name = {} - self.types_by_name = {} - - self.category_dict = {} - self.categories = [{}, {}, {}, {}] - - self.factory = factory - - self.next_offset = 0 - - typeexpr.create_initial_types() - return - - - def process_element(self, doc): - element = doc.children - while element.type != "element" or element.name != "OpenGLAPI": - element = element.next - - if element: - self.process_OpenGLAPI(element) - return - - - def process_OpenGLAPI(self, element): - child = element.children - while child: - if child.type == "element": - if child.name == "category": - self.process_category( child ) - elif child.name == "OpenGLAPI": - self.process_OpenGLAPI( child ) - - child = child.next - - return - - - def process_category(self, cat): - cat_name = cat.nsProp( "name", None ) - cat_number = cat.nsProp( "number", None ) - - [cat_type, key] = classify_category(cat_name, cat_number) - self.categories[cat_type][key] = [cat_name, cat_number] - - child = cat.children - while child: - if child.type == "element": - if child.name == "function": - func_name = real_function_name( child ) - - temp_name = child.nsProp( "name", None ) - self.category_dict[ temp_name ] = [cat_name, cat_number] - - if self.functions_by_name.has_key( func_name ): - func = self.functions_by_name[ func_name ] - func.process_element( child ) - else: - func = self.factory.create_item( "function", child, self ) - self.functions_by_name[ func_name ] = func - - if func.offset >= self.next_offset: - self.next_offset = func.offset + 1 - - - elif child.name == "enum": - enum = self.factory.create_item( "enum", child, self ) - self.enums_by_name[ enum.name ] = enum - elif child.name == "type": - t = self.factory.create_item( "type", child, self ) - self.types_by_name[ "GL" + t.name ] = t - - - child = child.next - - return - - - def functionIterateByCategory(self, cat = None): - """Iterate over functions by category. - - If cat is None, all known functions are iterated in category - order. See classify_category for details of the ordering. - Within a category, functions are sorted by name. If cat is - not None, then only functions in that category are iterated. - """ - lists = [{}, {}, {}, {}] - - for func in self.functionIterateAll(): - [cat_name, cat_number] = self.category_dict[func.name] - - if (cat == None) or (cat == cat_name): - [func_cat_type, key] = classify_category(cat_name, cat_number) - - if not lists[func_cat_type].has_key(key): - lists[func_cat_type][key] = {} - - lists[func_cat_type][key][func.name] = func - - - functions = [] - for func_cat_type in range(0,4): - keys = lists[func_cat_type].keys() - keys.sort() - - for key in keys: - names = lists[func_cat_type][key].keys() - names.sort() - - for name in names: - functions.append(lists[func_cat_type][key][name]) - - return functions.__iter__() - - - def functionIterateByOffset(self): - max_offset = -1 - for func in self.functions_by_name.itervalues(): - if func.offset > max_offset: - max_offset = func.offset - - - temp = [None for i in range(0, max_offset + 1)] - for func in self.functions_by_name.itervalues(): - if func.offset != -1: - temp[ func.offset ] = func - - - list = [] - for i in range(0, max_offset + 1): - if temp[i]: - list.append(temp[i]) - - return list.__iter__(); - - - def functionIterateAll(self): - return self.functions_by_name.itervalues() - - - def enumIterateByName(self): - keys = self.enums_by_name.keys() - keys.sort() - - list = [] - for enum in keys: - list.append( self.enums_by_name[ enum ] ) - - return list.__iter__() - - - def categoryIterate(self): - """Iterate over categories. - - Iterate over all known categories in the order specified by - classify_category. Each iterated value is a tuple of the - name and number (which may be None) of the category. - """ - - list = [] - for cat_type in range(0,4): - keys = self.categories[cat_type].keys() - keys.sort() - - for key in keys: - list.append(self.categories[cat_type][key]) - - return list.__iter__() - - - def get_category_for_name( self, name ): - if self.category_dict.has_key(name): - return self.category_dict[name] - else: - return ["", None] - - - def typeIterate(self): - return self.types_by_name.itervalues() - - - def find_type( self, type_name ): - if type_name in self.types_by_name: - return self.types_by_name[ type_name ].type_expr - else: - print "Unable to find base type matching \"%s\"." % (type_name) - return None diff --git a/src/mesa/glapi/gl_and_glX_API.xml b/src/mesa/glapi/gl_and_glX_API.xml deleted file mode 100644 index 34c977e9c0c..00000000000 --- a/src/mesa/glapi/gl_and_glX_API.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/src/mesa/glapi/gl_apitemp.py b/src/mesa/glapi/gl_apitemp.py deleted file mode 100644 index 41a40fbeb68..00000000000 --- a/src/mesa/glapi/gl_apitemp.py +++ /dev/null @@ -1,320 +0,0 @@ -#!/usr/bin/env python - -# (C) Copyright IBM Corporation 2004, 2005 -# 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 -# 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. -# -# Authors: -# Ian Romanick - -import gl_XML, glX_XML -import license -import sys, getopt - -class PrintGlOffsets(gl_XML.gl_print_base): - def __init__(self, es=False): - gl_XML.gl_print_base.__init__(self) - - self.name = "gl_apitemp.py (from Mesa)" - self.license = license.bsd_license_template % ( \ -"""Copyright (C) 1999-2001 Brian Paul All Rights Reserved. -(C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM") - - self.es = es - - self.undef_list.append( "KEYWORD1" ) - self.undef_list.append( "KEYWORD1_ALT" ) - self.undef_list.append( "KEYWORD2" ) - self.undef_list.append( "NAME" ) - self.undef_list.append( "DISPATCH" ) - self.undef_list.append( "RETURN_DISPATCH" ) - self.undef_list.append( "DISPATCH_TABLE_NAME" ) - self.undef_list.append( "UNUSED_TABLE_NAME" ) - self.undef_list.append( "TABLE_ENTRY" ) - - - def printFunction(self, f, name): - p_string = "" - o_string = "" - t_string = "" - comma = "" - - if f.is_static_entry_point(name): - keyword = "KEYWORD1" - else: - keyword = "KEYWORD1_ALT" - - n = f.static_name(name) - - for p in f.parameterIterator(): - if p.is_padding: - continue - - if p.is_pointer(): - cast = "(const void *) " - else: - cast = "" - - t_string = t_string + comma + p.format_string() - p_string = p_string + comma + p.name - o_string = o_string + comma + cast + p.name - comma = ", " - - - if f.return_type != 'void': - dispatch = "RETURN_DISPATCH" - else: - dispatch = "DISPATCH" - - need_proto = False - if not f.is_static_entry_point(name): - need_proto = True - elif self.es: - cat, num = api.get_category_for_name(name) - if (cat.startswith("es") or cat.startswith("GL_OES")): - need_proto = True - if need_proto: - print '%s %s KEYWORD2 NAME(%s)(%s);' % (keyword, f.return_type, n, f.get_parameter_string(name)) - print '' - - print '%s %s KEYWORD2 NAME(%s)(%s)' % (keyword, f.return_type, n, f.get_parameter_string(name)) - print '{' - if p_string == "": - print ' %s(%s, (), (F, "gl%s();\\n"));' \ - % (dispatch, f.name, name) - else: - print ' %s(%s, (%s), (F, "gl%s(%s);\\n", %s));' \ - % (dispatch, f.name, p_string, name, t_string, o_string) - print '}' - print '' - return - - def printRealHeader(self): - print '' - self.printVisibility( "HIDDEN", "hidden" ) - print """ -/* - * This file is a template which generates the OpenGL API entry point - * functions. It should be included by a .c file which first defines - * the following macros: - * KEYWORD1 - usually nothing, but might be __declspec(dllexport) on Win32 - * KEYWORD2 - usually nothing, but might be __stdcall on Win32 - * NAME(n) - builds the final function name (usually add "gl" prefix) - * DISPATCH(func, args, msg) - code to do dispatch of named function. - * msg is a printf-style debug message. - * RETURN_DISPATCH(func, args, msg) - code to do dispatch with a return value - * - * Here is an example which generates the usual OpenGL functions: - * #define KEYWORD1 - * #define KEYWORD2 - * #define NAME(func) gl##func - * #define DISPATCH(func, args, msg) \\ - * struct _glapi_table *dispatch = CurrentDispatch; \\ - * (*dispatch->func) args - * #define RETURN DISPATCH(func, args, msg) \\ - * struct _glapi_table *dispatch = CurrentDispatch; \\ - * return (*dispatch->func) args - * - */ - - -#if defined( NAME ) -#ifndef KEYWORD1 -#define KEYWORD1 -#endif - -#ifndef KEYWORD1_ALT -#define KEYWORD1_ALT HIDDEN -#endif - -#ifndef KEYWORD2 -#define KEYWORD2 -#endif - -#ifndef DISPATCH -#error DISPATCH must be defined -#endif - -#ifndef RETURN_DISPATCH -#error RETURN_DISPATCH must be defined -#endif - -""" - return - - - - def printInitDispatch(self, api): - print """ -#endif /* defined( NAME ) */ - -/* - * This is how a dispatch table can be initialized with all the functions - * we generated above. - */ -#ifdef DISPATCH_TABLE_NAME - -#ifndef TABLE_ENTRY -#error TABLE_ENTRY must be defined -#endif - -#ifdef _GLAPI_SKIP_NORMAL_ENTRY_POINTS -#error _GLAPI_SKIP_NORMAL_ENTRY_POINTS must not be defined -#endif - -_glapi_proc DISPATCH_TABLE_NAME[] = {""" - for f in api.functionIterateByOffset(): - print ' TABLE_ENTRY(%s),' % (f.dispatch_name()) - - print ' /* A whole bunch of no-op functions. These might be called' - print ' * when someone tries to call a dynamically-registered' - print ' * extension function without a current rendering context.' - print ' */' - for i in range(1, 100): - print ' TABLE_ENTRY(Unused),' - - print '};' - print '#endif /* DISPATCH_TABLE_NAME */' - print '' - return - - - def printAliasedTable(self, api): - print """ -/* - * This is just used to silence compiler warnings. - * We list the functions which are not otherwise used. - */ -#ifdef UNUSED_TABLE_NAME -_glapi_proc UNUSED_TABLE_NAME[] = {""" - - normal_entries = [] - proto_entries = [] - for f in api.functionIterateByOffset(): - normal_ents, proto_ents = self.classifyEntryPoints(f) - - # exclude f.name - if f.name in normal_ents: - normal_ents.remove(f.name) - elif f.name in proto_ents: - proto_ents.remove(f.name) - - normal_ents = [f.static_name(ent) for ent in normal_ents] - proto_ents = [f.static_name(ent) for ent in proto_ents] - - normal_entries.extend(normal_ents) - proto_entries.extend(proto_ents) - - print '#ifndef _GLAPI_SKIP_NORMAL_ENTRY_POINTS' - for ent in normal_entries: - print ' TABLE_ENTRY(%s),' % (ent) - print '#endif /* _GLAPI_SKIP_NORMAL_ENTRY_POINTS */' - print '#ifndef _GLAPI_SKIP_PROTO_ENTRY_POINTS' - for ent in proto_entries: - print ' TABLE_ENTRY(%s),' % (ent) - print '#endif /* _GLAPI_SKIP_PROTO_ENTRY_POINTS */' - - print '};' - print '#endif /*UNUSED_TABLE_NAME*/' - print '' - return - - - def classifyEntryPoints(self, func): - normal_names = [] - normal_stubs = [] - proto_names = [] - proto_stubs = [] - # classify the entry points - for name in func.entry_points: - if func.has_different_protocol(name): - if func.is_static_entry_point(name): - proto_names.append(name) - else: - proto_stubs.append(name) - else: - if func.is_static_entry_point(name): - normal_names.append(name) - else: - normal_stubs.append(name) - # there can be at most one stub for a function - if normal_stubs: - normal_names.append(normal_stubs[0]) - elif proto_stubs: - proto_names.append(proto_stubs[0]) - - return (normal_names, proto_names) - - def printBody(self, api): - normal_entry_points = [] - proto_entry_points = [] - for func in api.functionIterateByOffset(): - normal_ents, proto_ents = self.classifyEntryPoints(func) - normal_entry_points.append((func, normal_ents)) - proto_entry_points.append((func, proto_ents)) - - print '#ifndef _GLAPI_SKIP_NORMAL_ENTRY_POINTS' - print '' - for func, ents in normal_entry_points: - for ent in ents: - self.printFunction(func, ent) - print '' - print '#endif /* _GLAPI_SKIP_NORMAL_ENTRY_POINTS */' - print '' - print '/* these entry points might require different protocols */' - print '#ifndef _GLAPI_SKIP_PROTO_ENTRY_POINTS' - print '' - for func, ents in proto_entry_points: - for ent in ents: - self.printFunction(func, ent) - print '' - print '#endif /* _GLAPI_SKIP_PROTO_ENTRY_POINTS */' - print '' - - self.printInitDispatch(api) - self.printAliasedTable(api) - return - - -def show_usage(): - print "Usage: %s [-f input_file_name] [-c]" % sys.argv[0] - print "-c Enable compatibility with OpenGL ES." - sys.exit(1) - -if __name__ == '__main__': - file_name = "gl_API.xml" - - try: - (args, trail) = getopt.getopt(sys.argv[1:], "f:c") - except Exception,e: - show_usage() - - es = False - for (arg,val) in args: - if arg == "-f": - file_name = val - elif arg == "-c": - es = True - - api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory()) - - printer = PrintGlOffsets(es) - printer.Print(api) diff --git a/src/mesa/glapi/gl_enums.py b/src/mesa/glapi/gl_enums.py deleted file mode 100644 index 3a9ea3c86c7..00000000000 --- a/src/mesa/glapi/gl_enums.py +++ /dev/null @@ -1,243 +0,0 @@ -#!/usr/bin/python2 -# -*- Mode: Python; py-indent-offset: 8 -*- - -# (C) Copyright Zack Rusin 2005 -# 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 -# 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. -# -# Authors: -# Zack Rusin - -import license -import gl_XML -import sys, getopt - -class PrintGlEnums(gl_XML.gl_print_base): - - def __init__(self): - gl_XML.gl_print_base.__init__(self) - - self.name = "gl_enums.py (from Mesa)" - self.license = license.bsd_license_template % ( \ -"""Copyright (C) 1999-2005 Brian Paul All Rights Reserved.""", "BRIAN PAUL") - self.enum_table = {} - - - def printRealHeader(self): - print '#include "main/glheader.h"' - print '#include "main/mfeatures.h"' - print '#include "main/enums.h"' - print '#include "main/imports.h"' - print '' - print 'typedef struct {' - print ' size_t offset;' - print ' int n;' - print '} enum_elt;' - print '' - return - - def print_code(self): - print """ -typedef int (*cfunc)(const void *, const void *); - -/** - * Compare a key name to an element in the \c all_enums array. - * - * \c bsearch always passes the key as the first parameter and the pointer - * to the array element as the second parameter. We can elimiate some - * extra work by taking advantage of that fact. - * - * \param a Pointer to the desired enum name. - * \param b Pointer to an element of the \c all_enums array. - */ -static int compar_name( const char *a, const enum_elt *b ) -{ - return strcmp( a, & enum_string_table[ b->offset ] ); -} - -/** - * Compare a key enum value to an element in the \c all_enums array. - * - * \c bsearch always passes the key as the first parameter and the pointer - * to the array element as the second parameter. We can elimiate some - * extra work by taking advantage of that fact. - * - * \param a Pointer to the desired enum name. - * \param b Pointer to an index into the \c all_enums array. - */ -static int compar_nr( const int *a, const unsigned *b ) -{ - return a[0] - all_enums[*b].n; -} - - -static char token_tmp[20]; - -const char *_mesa_lookup_enum_by_nr( int nr ) -{ - unsigned * i; - - i = (unsigned *) _mesa_bsearch(& nr, reduced_enums, - Elements(reduced_enums), - sizeof(reduced_enums[0]), - (cfunc) compar_nr); - - if ( i != NULL ) { - return & enum_string_table[ all_enums[ *i ].offset ]; - } - else { - /* this is not re-entrant safe, no big deal here */ - sprintf(token_tmp, "0x%x", nr); - return token_tmp; - } -} - -/* Get the name of an enum given that it is a primitive type. Avoids - * GL_FALSE/GL_POINTS ambiguity and others. - */ -const char *_mesa_lookup_prim_by_nr( int nr ) -{ - switch (nr) { - case GL_POINTS: return "GL_POINTS"; - case GL_LINES: return "GL_LINES"; - case GL_LINE_STRIP: return "GL_LINE_STRIP"; - case GL_LINE_LOOP: return "GL_LINE_LOOP"; - case GL_TRIANGLES: return "GL_TRIANGLES"; - case GL_TRIANGLE_STRIP: return "GL_TRIANGLE_STRIP"; - case GL_TRIANGLE_FAN: return "GL_TRIANGLE_FAN"; - case GL_QUADS: return "GL_QUADS"; - case GL_QUAD_STRIP: return "GL_QUAD_STRIP"; - case GL_POLYGON: return "GL_POLYGON"; - case GL_POLYGON+1: return "OUTSIDE_BEGIN_END"; - default: return ""; - } -} - - - -int _mesa_lookup_enum_by_name( const char *symbol ) -{ - enum_elt * f = NULL; - - if ( symbol != NULL ) { - f = (enum_elt *) _mesa_bsearch(symbol, all_enums, - Elements(all_enums), - sizeof( enum_elt ), - (cfunc) compar_name); - } - - return (f != NULL) ? f->n : -1; -} - -""" - return - - - def printBody(self, api): - self.process_enums( api ) - - keys = self.enum_table.keys() - keys.sort() - - name_table = [] - enum_table = {} - - for enum in keys: - low_pri = 9 - for [name, pri] in self.enum_table[ enum ]: - name_table.append( [name, enum] ) - - if pri < low_pri: - low_pri = pri - enum_table[enum] = name - - - name_table.sort() - - string_offsets = {} - i = 0; - print 'LONGSTRING static const char enum_string_table[] = ' - for [name, enum] in name_table: - print ' "%s\\0"' % (name) - string_offsets[ name ] = i - i += len(name) + 1 - - print ' ;' - print '' - - - print 'static const enum_elt all_enums[%u] =' % (len(name_table)) - print '{' - for [name, enum] in name_table: - print ' { %5u, 0x%08X }, /* %s */' % (string_offsets[name], enum, name) - print '};' - print '' - - print 'static const unsigned reduced_enums[%u] =' % (len(keys)) - print '{' - for enum in keys: - name = enum_table[ enum ] - if [name, enum] not in name_table: - print ' /* Error! %s, 0x%04x */ 0,' % (name, enum) - else: - i = name_table.index( [name, enum] ) - - print ' %4u, /* %s */' % (i, name) - print '};' - - - self.print_code() - return - - - def process_enums(self, api): - self.enum_table = {} - - for obj in api.enumIterateByName(): - if obj.value not in self.enum_table: - self.enum_table[ obj.value ] = [] - - - name = "GL_" + obj.name - priority = obj.priority() - self.enum_table[ obj.value ].append( [name, priority] ) - - -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 = PrintGlEnums() - printer.Print( api ) diff --git a/src/mesa/glapi/gl_offsets.py b/src/mesa/glapi/gl_offsets.py deleted file mode 100644 index 54867b34634..00000000000 --- a/src/mesa/glapi/gl_offsets.py +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env python - -# (C) Copyright IBM Corporation 2004, 2005 -# 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 -# 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. -# -# Authors: -# Ian Romanick - -import gl_XML -import license -import sys, getopt - -class PrintGlOffsets(gl_XML.gl_print_base): - def __init__(self, es=False): - gl_XML.gl_print_base.__init__(self) - - self.es = es - self.name = "gl_offsets.py (from Mesa)" - self.header_tag = '_GLAPI_OFFSETS_H_' - self.license = license.bsd_license_template % ( \ -"""Copyright (C) 1999-2001 Brian Paul All Rights Reserved. -(C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM") - return - - def printBody(self, api): - print '/* this file should not be included directly in mesa */' - print '' - - functions = [] - abi_functions = [] - alias_functions = [] - count = 0 - for f in api.functionIterateByOffset(): - if not f.is_abi(): - functions.append( [f, count] ) - count += 1 - else: - abi_functions.append( f ) - - if self.es: - # remember functions with aliases - if len(f.entry_points) > 1: - alias_functions.append(f) - - for f in abi_functions: - print '#define _gloffset_%s %d' % (f.name, f.offset) - last_static = f.offset - - print '' - print '#if !defined(_GLAPI_USE_REMAP_TABLE)' - print '' - - for [f, index] in functions: - print '#define _gloffset_%s %d' % (f.name, f.offset) - - print '#define _gloffset_FIRST_DYNAMIC %d' % (api.next_offset) - - print '' - print '#else' - print '' - - for [f, index] in functions: - print '#define _gloffset_%s driDispatchRemapTable[%s_remap_index]' % (f.name, f.name) - - print '' - print '#endif /* !defined(_GLAPI_USE_REMAP_TABLE) */' - - if alias_functions: - print '' - print '/* define aliases for compatibility */' - for f in alias_functions: - for name in f.entry_points: - if name != f.name: - print '#define _gloffset_%s _gloffset_%s' % (name, f.name) - return - - -def show_usage(): - print "Usage: %s [-f input_file_name] [-c]" % sys.argv[0] - print " -c Enable compatibility with OpenGL ES." - sys.exit(1) - -if __name__ == '__main__': - file_name = "gl_API.xml" - - try: - (args, trail) = getopt.getopt(sys.argv[1:], "f:c") - except Exception,e: - show_usage() - - es = False - for (arg,val) in args: - if arg == "-f": - file_name = val - elif arg == "-c": - es = True - - api = gl_XML.parse_GL_API( file_name ) - - printer = PrintGlOffsets(es) - printer.Print( api ) diff --git a/src/mesa/glapi/gl_procs.py b/src/mesa/glapi/gl_procs.py deleted file mode 100644 index 5de61fbdfe9..00000000000 --- a/src/mesa/glapi/gl_procs.py +++ /dev/null @@ -1,215 +0,0 @@ -#!/usr/bin/env python - -# (C) Copyright IBM Corporation 2004, 2005 -# 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 -# 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. -# -# Authors: -# Ian Romanick - -import license -import gl_XML, glX_XML -import sys, getopt - -class PrintGlProcs(gl_XML.gl_print_base): - def __init__(self, long_strings, es=False): - gl_XML.gl_print_base.__init__(self) - - self.es = es - self.long_strings = long_strings - self.name = "gl_procs.py (from Mesa)" - self.license = license.bsd_license_template % ( \ -"""Copyright (C) 1999-2001 Brian Paul All Rights Reserved. -(C) Copyright IBM Corporation 2004, 2006""", "BRIAN PAUL, IBM") - - - def printRealHeader(self): - print """ -/* This file is only included by glapi.c and is used for - * the GetProcAddress() function - */ - -typedef struct { - GLint Name_offset; -#if defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING) - _glapi_proc Address; -#endif - GLuint Offset; -} glprocs_table_t; - -#if !defined(NEED_FUNCTION_POINTER) && !defined(GLX_INDIRECT_RENDERING) -# define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , o } -#elif defined(NEED_FUNCTION_POINTER) && !defined(GLX_INDIRECT_RENDERING) -# define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f1 , o } -#elif defined(NEED_FUNCTION_POINTER) && defined(GLX_INDIRECT_RENDERING) -# define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f2 , o } -#elif !defined(NEED_FUNCTION_POINTER) && defined(GLX_INDIRECT_RENDERING) -# define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f3 , o } -#endif - -""" - return - - def printRealFooter(self): - print '' - print '#undef NAME_FUNC_OFFSET' - return - - def printFunctionString(self, name): - if self.long_strings: - print ' "gl%s\\0"' % (name) - else: - print " 'g','l',", - for c in name: - print "'%s'," % (c), - - print "'\\0'," - - - def printBody(self, api): - print '' - if self.long_strings: - print 'static const char gl_string_table[] =' - else: - print 'static const char gl_string_table[] = {' - - base_offset = 0 - table = [] - for func in api.functionIterateByOffset(): - name = func.dispatch_name() - self.printFunctionString(func.name) - table.append((base_offset, "gl" + name, "gl" + name, "NULL", func.name)) - - # The length of the function's name, plus 2 for "gl", - # plus 1 for the NUL. - - base_offset += len(func.name) + 3 - - - for func in api.functionIterateByOffset(): - for n in func.entry_points: - if n != func.name: - name = func.dispatch_name() - self.printFunctionString( n ) - - if func.has_different_protocol(n): - alt_name = "gl" + func.static_glx_name(n) - table.append((base_offset, "gl" + name, alt_name, alt_name, func.name)) - else: - table.append((base_offset, "gl" + name, "gl" + name, "NULL", func.name)) - - base_offset += len(n) + 3 - - - if self.long_strings: - print ' ;' - else: - print '};' - - print '' - print '' - print "#ifdef USE_MGL_NAMESPACE" - for func in api.functionIterateByOffset(): - for n in func.entry_points: - if (not func.is_static_entry_point(func.name)) or (func.has_different_protocol(n) and not func.is_static_entry_point(n)): - print '#define gl_dispatch_stub_%u mgl_dispatch_stub_%u' % (func.offset, func.offset) - break - print "#endif /* USE_MGL_NAMESPACE */" - print '' - print '' - print '#if defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING)' - for func in api.functionIterateByOffset(): - for n in func.entry_points: - if (not func.is_static_entry_point(func.name)) or (func.has_different_protocol(n) and not func.is_static_entry_point(n)): - print '%s GLAPIENTRY gl_dispatch_stub_%u(%s);' % (func.return_type, func.offset, func.get_parameter_string()) - break - - if self.es: - categories = {} - for func in api.functionIterateByOffset(): - for n in func.entry_points: - cat, num = api.get_category_for_name(n) - if (cat.startswith("es") or cat.startswith("GL_OES")): - if not categories.has_key(cat): - categories[cat] = [] - proto = 'GLAPI %s GLAPIENTRY %s(%s);' \ - % (func.return_type, "gl" + n, func.get_parameter_string(n)) - categories[cat].append(proto) - if categories: - print '' - print '/* OpenGL ES specific prototypes */' - print '' - keys = categories.keys() - keys.sort() - for key in keys: - print '/* category %s */' % key - print "\n".join(categories[key]) - print '' - - print '#endif /* defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING) */' - - print '' - print 'static const glprocs_table_t static_functions[] = {' - - for info in table: - print ' NAME_FUNC_OFFSET(%5u, %s, %s, %s, _gloffset_%s),' % info - - print ' NAME_FUNC_OFFSET(-1, NULL, NULL, NULL, 0)' - print '};' - return - - -def show_usage(): - print "Usage: %s [-f input_file_name] [-m mode] [-c]" % sys.argv[0] - print "-c Enable compatibility with OpenGL ES." - print "-m mode mode can be one of:" - print " long - Create code for compilers that can handle very" - print " long string constants. (default)" - print " short - Create code for compilers that can only handle" - print " ANSI C89 string constants." - sys.exit(1) - -if __name__ == '__main__': - file_name = "gl_API.xml" - - try: - (args, trail) = getopt.getopt(sys.argv[1:], "f:m:c") - except Exception,e: - show_usage() - - long_string = 1 - es = False - for (arg,val) in args: - if arg == "-f": - file_name = val - elif arg == "-m": - if val == "short": - long_string = 0 - elif val == "long": - long_string = 1 - else: - show_usage() - elif arg == "-c": - es = True - - api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory()) - printer = PrintGlProcs(long_string, es) - printer.Print(api) diff --git a/src/mesa/glapi/gl_table.py b/src/mesa/glapi/gl_table.py deleted file mode 100644 index 3bd7569e92a..00000000000 --- a/src/mesa/glapi/gl_table.py +++ /dev/null @@ -1,229 +0,0 @@ -#!/usr/bin/python2 - -# (C) Copyright IBM Corporation 2004 -# 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 -# 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. -# -# Authors: -# Ian Romanick - -import gl_XML -import license -import sys, getopt - -class PrintGlTable(gl_XML.gl_print_base): - def __init__(self, es=False): - gl_XML.gl_print_base.__init__(self) - - self.es = es - self.header_tag = '_GLAPI_TABLE_H_' - self.name = "gl_table.py (from Mesa)" - self.license = license.bsd_license_template % ( \ -"""Copyright (C) 1999-2003 Brian Paul All Rights Reserved. -(C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM") - return - - - def printBody(self, api): - for f in api.functionIterateByOffset(): - arg_string = f.get_parameter_string() - print ' %s (GLAPIENTRYP %s)(%s); /* %d */' % (f.return_type, f.name, arg_string, f.offset) - - - def printRealHeader(self): - print '#ifndef GLAPIENTRYP' - print '# ifndef GLAPIENTRY' - print '# define GLAPIENTRY' - print '# endif' - print '' - print '# define GLAPIENTRYP GLAPIENTRY *' - print '#endif' - print '' - print '' - print 'struct _glapi_table' - print '{' - return - - - def printRealFooter(self): - print '};' - return - - -class PrintRemapTable(gl_XML.gl_print_base): - def __init__(self, es=False): - gl_XML.gl_print_base.__init__(self) - - self.es = es - self.header_tag = '_GLAPI_DISPATCH_H_' - self.name = "gl_table.py (from Mesa)" - self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM") - return - - - def printRealHeader(self): - print """ -/* this file should not be included directly in mesa */ - -/** - * \\file glapidispatch.h - * Macros for handling GL dispatch tables. - * - * For each known GL function, there are 3 macros in this file. The first - * macro is named CALL_FuncName and is used to call that GL function using - * the specified dispatch table. The other 2 macros, called GET_FuncName - * can SET_FuncName, are used to get and set the dispatch pointer for the - * named function in the specified dispatch table. - */ -""" - - return - - def printBody(self, api): - print '#define CALL_by_offset(disp, cast, offset, parameters) \\' - print ' (*(cast (GET_by_offset(disp, offset)))) parameters' - print '#define GET_by_offset(disp, offset) \\' - print ' (offset >= 0) ? (((_glapi_proc *)(disp))[offset]) : NULL' - print '#define SET_by_offset(disp, offset, fn) \\' - print ' do { \\' - print ' if ( (offset) < 0 ) { \\' - print ' /* fprintf( stderr, "[%s:%u] SET_by_offset(%p, %d, %s)!\\n", */ \\' - print ' /* __func__, __LINE__, disp, offset, # fn); */ \\' - print ' /* abort(); */ \\' - print ' } \\' - print ' else { \\' - print ' ( (_glapi_proc *) (disp) )[offset] = (_glapi_proc) fn; \\' - print ' } \\' - print ' } while(0)' - print '' - - functions = [] - abi_functions = [] - alias_functions = [] - count = 0 - for f in api.functionIterateByOffset(): - if not f.is_abi(): - functions.append( [f, count] ) - count += 1 - else: - abi_functions.append( f ) - - if self.es: - # remember functions with aliases - if len(f.entry_points) > 1: - alias_functions.append(f) - - - for f in abi_functions: - print '#define CALL_%s(disp, parameters) (*((disp)->%s)) parameters' % (f.name, f.name) - print '#define GET_%s(disp) ((disp)->%s)' % (f.name, f.name) - print '#define SET_%s(disp, fn) ((disp)->%s = fn)' % (f.name, f.name) - - - print '' - print '#if !defined(_GLAPI_USE_REMAP_TABLE)' - print '' - - for [f, index] in functions: - print '#define CALL_%s(disp, parameters) (*((disp)->%s)) parameters' % (f.name, f.name) - print '#define GET_%s(disp) ((disp)->%s)' % (f.name, f.name) - print '#define SET_%s(disp, fn) ((disp)->%s = fn)' % (f.name, f.name) - - print '' - print '#else' - print '' - print '#define driDispatchRemapTable_size %u' % (count) - print 'extern int driDispatchRemapTable[ driDispatchRemapTable_size ];' - print '' - - for [f, index] in functions: - print '#define %s_remap_index %u' % (f.name, index) - - print '' - - for [f, index] in functions: - arg_string = gl_XML.create_parameter_string( f.parameters, 0 ) - cast = '%s (GLAPIENTRYP)(%s)' % (f.return_type, arg_string) - - print '#define CALL_%s(disp, parameters) CALL_by_offset(disp, (%s), driDispatchRemapTable[%s_remap_index], parameters)' % (f.name, cast, f.name) - print '#define GET_%s(disp) GET_by_offset(disp, driDispatchRemapTable[%s_remap_index])' % (f.name, f.name) - print '#define SET_%s(disp, fn) SET_by_offset(disp, driDispatchRemapTable[%s_remap_index], fn)' % (f.name, f.name) - - - print '' - print '#endif /* !defined(_GLAPI_USE_REMAP_TABLE) */' - - if alias_functions: - print '' - print '/* define aliases for compatibility */' - for f in alias_functions: - for name in f.entry_points: - if name != f.name: - print '#define CALL_%s(disp, parameters) CALL_%s(disp, parameters)' % (name, f.name) - print '#define GET_%s(disp) GET_%s(disp)' % (name, f.name) - print '#define SET_%s(disp, fn) SET_%s(disp, fn)' % (name, f.name) - print '' - - print '#if defined(_GLAPI_USE_REMAP_TABLE)' - for f in alias_functions: - for name in f.entry_points: - if name != f.name: - print '#define %s_remap_index %s_remap_index' % (name, f.name) - print '#endif /* defined(_GLAPI_USE_REMAP_TABLE) */' - print '' - - return - - -def show_usage(): - print "Usage: %s [-f input_file_name] [-m mode] [-c]" % sys.argv[0] - print " -m mode Mode can be 'table' or 'remap_table'." - print " -c Enable compatibility with OpenGL ES." - sys.exit(1) - -if __name__ == '__main__': - file_name = "gl_API.xml" - - try: - (args, trail) = getopt.getopt(sys.argv[1:], "f:m:c") - except Exception,e: - show_usage() - - mode = "table" - es = False - for (arg,val) in args: - if arg == "-f": - file_name = val - elif arg == "-m": - mode = val - elif arg == "-c": - es = True - - if mode == "table": - printer = PrintGlTable(es) - elif mode == "remap_table": - printer = PrintRemapTable(es) - else: - show_usage() - - api = gl_XML.parse_GL_API( file_name ) - - printer.Print( api ) diff --git a/src/mesa/glapi/gl_x86-64_asm.py b/src/mesa/glapi/gl_x86-64_asm.py deleted file mode 100644 index 31c1a2b93a8..00000000000 --- a/src/mesa/glapi/gl_x86-64_asm.py +++ /dev/null @@ -1,334 +0,0 @@ -#!/usr/bin/env python - -# (C) Copyright IBM Corporation 2005 -# 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 -# 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. -# -# Authors: -# Ian Romanick - -import license -import gl_XML, glX_XML -import sys, getopt, copy - -def should_use_push(registers): - for [reg, offset] in registers: - if reg[1:4] == "xmm": - return 0 - - N = len(registers) - return (N & 1) != 0 - - -def local_size(registers): - # The x86-64 ABI says "the value (%rsp - 8) is always a multiple of - # 16 when control is transfered to the function entry point." This - # means that the local stack usage must be (16*N)+8 for some value - # of N. (16*N)+8 = (8*(2N))+8 = 8*(2N+1). As long as N is odd, we - # meet this requirement. - - N = (len(registers) | 1) - return 8*N - - -def save_all_regs(registers): - adjust_stack = 0 - if not should_use_push(registers): - adjust_stack = local_size(registers) - print '\tsubq\t$%u, %%rsp' % (adjust_stack) - - for [reg, stack_offset] in registers: - save_reg( reg, stack_offset, adjust_stack ) - return - - -def restore_all_regs(registers): - adjust_stack = 0 - if not should_use_push(registers): - adjust_stack = local_size(registers) - - temp = copy.deepcopy(registers) - while len(temp): - [reg, stack_offset] = temp.pop() - restore_reg(reg, stack_offset, adjust_stack) - - if adjust_stack: - print '\taddq\t$%u, %%rsp' % (adjust_stack) - return - - -def save_reg(reg, offset, use_move): - if use_move: - if offset == 0: - print '\tmovq\t%s, (%%rsp)' % (reg) - else: - print '\tmovq\t%s, %u(%%rsp)' % (reg, offset) - else: - print '\tpushq\t%s' % (reg) - - return - - -def restore_reg(reg, offset, use_move): - if use_move: - if offset == 0: - print '\tmovq\t(%%rsp), %s' % (reg) - else: - print '\tmovq\t%u(%%rsp), %s' % (offset, reg) - else: - print '\tpopq\t%s' % (reg) - - return - - -class PrintGenericStubs(gl_XML.gl_print_base): - - def __init__(self): - gl_XML.gl_print_base.__init__(self) - - self.name = "gl_x86-64_asm.py (from Mesa)" - self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM") - return - - - def get_stack_size(self, f): - size = 0 - for p in f.parameterIterator(): - size += p.get_stack_size() - - return size - - - def printRealHeader(self): - print "/* If we build with gcc's -fvisibility=hidden flag, we'll need to change" - print " * the symbol visibility mode to 'default'." - print ' */' - print '' - print '#include "x86/assyntax.h"' - print '' - print '#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303' - print '# pragma GCC visibility push(default)' - print '# define HIDDEN(x) .hidden x' - print '#else' - print '# define HIDDEN(x)' - print '#endif' - print '' - print '# if defined(USE_MGL_NAMESPACE)' - print '# define GL_PREFIX(n) GLNAME(CONCAT(mgl,n))' - print '# define _glapi_Dispatch _mglapi_Dispatch' - print '# else' - print '# define GL_PREFIX(n) GLNAME(CONCAT(gl,n))' - print '# endif' - print '' - print '#if defined(PTHREADS) || defined(SOLARIS_THREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)' - print '# define THREADS' - print '#endif' - print '' - print '\t.text' - print '' - print '#ifdef GLX_USE_TLS' - print '' - print '\t.globl _x86_64_get_get_dispatch; HIDDEN(_x86_64_get_get_dispatch)' - print '_x86_64_get_get_dispatch:' - print '\tlea\t_x86_64_get_dispatch(%rip), %rax' - print '\tret' - print '' - print '\t.p2align\t4,,15' - print '_x86_64_get_dispatch:' - print '\tmovq\t_glapi_tls_Dispatch@GOTTPOFF(%rip), %rax' - print '\tmovq\t%fs:(%rax), %rax' - print '\tret' - print '\t.size\t_x86_64_get_dispatch, .-_x86_64_get_dispatch' - print '' - print '#elif defined(PTHREADS)' - print '' - print '\t.extern\t_glapi_Dispatch' - print '\t.extern\t_gl_DispatchTSD' - print '\t.extern\tpthread_getspecific' - print '' - print '\t.p2align\t4,,15' - print '_x86_64_get_dispatch:' - print '\tmovq\t_gl_DispatchTSD(%rip), %rdi' - print '\tjmp\tpthread_getspecific@PLT' - print '' - print '#elif defined(THREADS)' - print '' - print '\t.extern\t_glapi_get_dispatch' - print '' - print '#endif' - print '' - return - - - def printRealFooter(self): - print '' - print '#if defined(GLX_USE_TLS) && defined(__linux__)' - print ' .section ".note.ABI-tag", "a"' - print ' .p2align 2' - print ' .long 1f - 0f /* name length */' - print ' .long 3f - 2f /* data length */' - print ' .long 1 /* note length */' - print '0: .asciz "GNU" /* vendor name */' - print '1: .p2align 2' - print '2: .long 0 /* note data: the ABI tag */' - print ' .long 2,4,20 /* Minimum kernel version w/TLS */' - print '3: .p2align 2 /* pad out section */' - print '#endif /* GLX_USE_TLS */' - print '' - print '#if defined (__ELF__) && defined (__linux__)' - print ' .section .note.GNU-stack,"",%progbits' - print '#endif' - return - - - def printFunction(self, f): - - # The x86-64 ABI divides function parameters into a couple - # classes. For the OpenGL interface, the only ones that are - # relevent are INTEGER and SSE. Basically, the first 8 - # GLfloat or GLdouble parameters are placed in %xmm0 - %xmm7, - # the first 6 non-GLfloat / non-GLdouble parameters are placed - # in registers listed in int_parameters. - # - # If more parameters than that are required, they are passed - # on the stack. Therefore, we just have to make sure that - # %esp hasn't changed when we jump to the actual function. - # Since we're jumping to the function (and not calling it), we - # have to make sure of that anyway! - - int_parameters = ["%rdi", "%rsi", "%rdx", "%rcx", "%r8", "%r9"] - - int_class = 0 - sse_class = 0 - stack_offset = 0 - registers = [] - for p in f.parameterIterator(): - type_name = p.get_base_type_string() - - if p.is_pointer() or (type_name != "GLfloat" and type_name != "GLdouble"): - if int_class < 6: - registers.append( [int_parameters[int_class], stack_offset] ) - int_class += 1 - stack_offset += 8 - else: - if sse_class < 8: - registers.append( ["%%xmm%u" % (sse_class), stack_offset] ) - sse_class += 1 - stack_offset += 8 - - if ((int_class & 1) == 0) and (sse_class == 0): - registers.append( ["%rbp", 0] ) - - - name = f.dispatch_name() - - print '\t.p2align\t4,,15' - print '\t.globl\tGL_PREFIX(%s)' % (name) - print '\t.type\tGL_PREFIX(%s), @function' % (name) - if not f.is_static_entry_point(f.name): - print '\tHIDDEN(GL_PREFIX(%s))' % (name) - print 'GL_PREFIX(%s):' % (name) - print '#if defined(GLX_USE_TLS)' - print '\tcall\t_x86_64_get_dispatch@PLT' - print '\tmovq\t%u(%%rax), %%r11' % (f.offset * 8) - print '\tjmp\t*%r11' - print '#elif defined(PTHREADS)' - - save_all_regs(registers) - print '\tcall\t_x86_64_get_dispatch@PLT' - restore_all_regs(registers) - - if f.offset == 0: - print '\tmovq\t(%rax), %r11' - else: - print '\tmovq\t%u(%%rax), %%r11' % (f.offset * 8) - - print '\tjmp\t*%r11' - - print '#else' - print '\tmovq\t_glapi_Dispatch(%rip), %rax' - print '\ttestq\t%rax, %rax' - print '\tje\t1f' - print '\tmovq\t%u(%%rax), %%r11' % (f.offset * 8) - print '\tjmp\t*%r11' - print '1:' - - save_all_regs(registers) - print '\tcall\t_glapi_get_dispatch' - restore_all_regs(registers) - - print '\tmovq\t%u(%%rax), %%r11' % (f.offset * 8) - print '\tjmp\t*%r11' - print '#endif /* defined(GLX_USE_TLS) */' - - print '\t.size\tGL_PREFIX(%s), .-GL_PREFIX(%s)' % (name, name) - print '' - return - - - def printBody(self, api): - for f in api.functionIterateByOffset(): - self.printFunction(f) - - - for f in api.functionIterateByOffset(): - dispatch = f.dispatch_name() - for n in f.entry_points: - if n != f.name: - if f.is_static_entry_point(n): - text = '\t.globl GL_PREFIX(%s) ; .set GL_PREFIX(%s), GL_PREFIX(%s)' % (n, n, dispatch) - - if f.has_different_protocol(n): - print '#ifndef GLX_INDIRECT_RENDERING' - print text - print '#endif' - else: - print text - - return - -def show_usage(): - print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0] - sys.exit(1) - -if __name__ == '__main__': - file_name = "gl_API.xml" - mode = "generic" - - try: - (args, trail) = getopt.getopt(sys.argv[1:], "m:f:") - except Exception,e: - show_usage() - - for (arg,val) in args: - if arg == '-m': - mode = val - elif arg == "-f": - file_name = val - - if mode == "generic": - printer = PrintGenericStubs() - else: - print "ERROR: Invalid mode \"%s\" specified." % mode - show_usage() - - api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory()) - printer.Print(api) diff --git a/src/mesa/glapi/gl_x86_asm.py b/src/mesa/glapi/gl_x86_asm.py deleted file mode 100644 index d210f3a2481..00000000000 --- a/src/mesa/glapi/gl_x86_asm.py +++ /dev/null @@ -1,270 +0,0 @@ -#!/usr/bin/env python - -# (C) Copyright IBM Corporation 2004, 2005 -# 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 -# 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. -# -# Authors: -# Ian Romanick - -import license -import gl_XML, glX_XML -import sys, getopt - -class PrintGenericStubs(gl_XML.gl_print_base): - - def __init__(self): - gl_XML.gl_print_base.__init__(self) - - self.name = "gl_x86_asm.py (from Mesa)" - self.license = license.bsd_license_template % ( \ -"""Copyright (C) 1999-2001 Brian Paul All Rights Reserved. -(C) Copyright IBM Corporation 2004, 2005""", "BRIAN PAUL, IBM") - return - - - def get_stack_size(self, f): - size = 0 - for p in f.parameterIterator(): - if p.is_padding: - continue - - size += p.get_stack_size() - - return size - - - def printRealHeader(self): - print '#include "x86/assyntax.h"' - print '#include "glapi/glapioffsets.h"' - print '' - print '#if defined(STDCALL_API)' - print '# if defined(USE_MGL_NAMESPACE)' - print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n2))' - print '# else' - print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n2))' - print '# endif' - print '#else' - print '# if defined(USE_MGL_NAMESPACE)' - print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n))' - print '# define _glapi_Dispatch _mglapi_Dispatch' - print '# else' - print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n))' - print '# endif' - print '#endif' - print '' - print '#define GL_OFFSET(x) CODEPTR(REGOFF(4 * x, EAX))' - print '' - print '#if defined(GNU_ASSEMBLER) && !defined(__DJGPP__) && !defined(__MINGW32__) && !defined(__APPLE__)' - print '#define GLOBL_FN(x) GLOBL x ; .type x, function' - print '#else' - print '#define GLOBL_FN(x) GLOBL x' - print '#endif' - print '' - print '#if defined(PTHREADS) || defined(SOLARIS_THREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)' - print '# define THREADS' - print '#endif' - print '' - print '#ifdef GLX_USE_TLS' - print '' - print '#ifdef GLX_X86_READONLY_TEXT' - print '# define CTX_INSNS MOV_L(GS:(EAX), EAX)' - print '#else' - print '# define CTX_INSNS NOP /* Pad for init_glapi_relocs() */' - print '#endif' - print '' - print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\' - print 'ALIGNTEXT16;\t\t\t\t\t\t\\' - print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\' - print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\' - print '\tCALL(_x86_get_dispatch) ;\t\t\t\\' - print '\tCTX_INSNS ; \\' - print '\tJMP(GL_OFFSET(off))' - print '' - print '#elif defined(PTHREADS)' - print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\' - print 'ALIGNTEXT16;\t\t\t\t\t\t\\' - print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\' - print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\' - print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\' - print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\' - print '\tJE(1f) ;\t\t\t\t\t\\' - print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\' - print '1:\tCALL(_x86_get_dispatch) ;\t\t\t\\' - print '\tJMP(GL_OFFSET(off))' - print '#elif defined(THREADS)' - print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\' - print 'ALIGNTEXT16;\t\t\t\t\t\t\\' - print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\' - print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\' - print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\' - print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\' - print '\tJE(1f) ;\t\t\t\t\t\\' - print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\' - print '1:\tCALL(_glapi_get_dispatch) ;\t\t\t\\' - print '\tJMP(GL_OFFSET(off))' - print '#else /* Non-threaded version. */' - print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\' - print 'ALIGNTEXT16;\t\t\t\t\t\t\\' - print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\' - print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\' - print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\' - print '\tJMP(GL_OFFSET(off))' - print '#endif' - print '' - print '#ifdef HAVE_ALIAS' - print '# define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt)\t\\' - print '\t.globl\tGL_PREFIX(fn, fn_alt) ;\t\t\t\\' - print '\t.set\tGL_PREFIX(fn, fn_alt), GL_PREFIX(alias, alias_alt)' - print '#else' - print '# define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt)\t\\' - print ' GL_STUB(fn, off, fn_alt)' - print '#endif' - print '' - print 'SEG_TEXT' - print '' - print '#ifdef GLX_USE_TLS' - print '' - print '\tGLOBL\tGLNAME(_x86_get_dispatch)' - print '\tHIDDEN(GLNAME(_x86_get_dispatch))' - print 'ALIGNTEXT16' - print 'GLNAME(_x86_get_dispatch):' - print '\tcall 1f' - print '1:\tpopl %eax' - print '\taddl $_GLOBAL_OFFSET_TABLE_+[.-1b], %eax' - print '\tmovl _glapi_tls_Dispatch@GOTNTPOFF(%eax), %eax' - print '\tret' - print '' - print '#elif defined(PTHREADS)' - print 'EXTERN GLNAME(_glapi_Dispatch)' - print 'EXTERN GLNAME(_gl_DispatchTSD)' - print 'EXTERN GLNAME(pthread_getspecific)' - print '' - print 'ALIGNTEXT16' - print 'GLNAME(_x86_get_dispatch):' - print '\tSUB_L(CONST(24), ESP)' - print '\tPUSH_L(GLNAME(_gl_DispatchTSD))' - print '\tCALL(GLNAME(pthread_getspecific))' - print '\tADD_L(CONST(28), ESP)' - print '\tRET' - print '#elif defined(THREADS)' - print 'EXTERN GLNAME(_glapi_get_dispatch)' - print '#endif' - print '' - - print '#if defined( GLX_USE_TLS ) && !defined( GLX_X86_READONLY_TEXT )' - print '\t\t.section\twtext, "awx", @progbits' - print '#endif /* defined( GLX_USE_TLS ) */' - - print '' - print '\t\tALIGNTEXT16' - print '\t\tGLOBL GLNAME(gl_dispatch_functions_start)' - print '\t\tHIDDEN(GLNAME(gl_dispatch_functions_start))' - print 'GLNAME(gl_dispatch_functions_start):' - print '' - return - - - def printRealFooter(self): - print '' - print '\t\tGLOBL\tGLNAME(gl_dispatch_functions_end)' - print '\t\tHIDDEN(GLNAME(gl_dispatch_functions_end))' - print '\t\tALIGNTEXT16' - print 'GLNAME(gl_dispatch_functions_end):' - print '' - print '#if defined(GLX_USE_TLS) && defined(__linux__)' - print ' .section ".note.ABI-tag", "a"' - print ' .p2align 2' - print ' .long 1f - 0f /* name length */' - print ' .long 3f - 2f /* data length */' - print ' .long 1 /* note length */' - print '0: .asciz "GNU" /* vendor name */' - print '1: .p2align 2' - print '2: .long 0 /* note data: the ABI tag */' - print ' .long 2,4,20 /* Minimum kernel version w/TLS */' - print '3: .p2align 2 /* pad out section */' - print '#endif /* GLX_USE_TLS */' - print '' - print '#if defined (__ELF__) && defined (__linux__)' - print ' .section .note.GNU-stack,"",%progbits' - print '#endif' - return - - - def printBody(self, api): - for f in api.functionIterateByOffset(): - name = f.dispatch_name() - stack = self.get_stack_size(f) - alt = "%s@%u" % (name, stack) - - print '\tGL_STUB(%s, _gloffset_%s, %s)' % (name, f.name, alt) - - if not f.is_static_entry_point(f.name): - print '\tHIDDEN(GL_PREFIX(%s, %s))' % (name, alt) - - - for f in api.functionIterateByOffset(): - name = f.dispatch_name() - stack = self.get_stack_size(f) - alt = "%s@%u" % (name, stack) - - if f.is_static_entry_point(f.name): - for n in f.entry_points: - if n != f.name: - alt2 = "%s@%u" % (n, stack) - text = '\tGL_STUB_ALIAS(%s, _gloffset_%s, %s, %s, %s)' % (n, f.name, alt2, f.name, alt) - - if f.has_different_protocol(n): - print '#ifndef GLX_INDIRECT_RENDERING' - print text - print '#endif' - else: - print text - - return - -def show_usage(): - print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0] - sys.exit(1) - -if __name__ == '__main__': - file_name = "gl_API.xml" - mode = "generic" - - try: - (args, trail) = getopt.getopt(sys.argv[1:], "m:f:") - except Exception,e: - show_usage() - - for (arg,val) in args: - if arg == '-m': - mode = val - elif arg == "-f": - file_name = val - - if mode == "generic": - printer = PrintGenericStubs() - else: - print "ERROR: Invalid mode \"%s\" specified." % mode - show_usage() - - api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory()) - printer.Print(api) diff --git a/src/mesa/glapi/license.py b/src/mesa/glapi/license.py deleted file mode 100644 index 02181648e4b..00000000000 --- a/src/mesa/glapi/license.py +++ /dev/null @@ -1,47 +0,0 @@ -# (C) Copyright IBM Corporation 2004 -# 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 -# 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. -# -# Authors: -# Ian Romanick - -bsd_license_template = """%s -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, 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 -%s, -AND/OR THEIR 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.""" diff --git a/src/mesa/glapi/mesadef.py b/src/mesa/glapi/mesadef.py deleted file mode 100644 index 38b0246ba5b..00000000000 --- a/src/mesa/glapi/mesadef.py +++ /dev/null @@ -1,216 +0,0 @@ -#!/usr/bin/env python - - -# Mesa 3-D graphics library -# Version: 4.1 -# -# 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 -# 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. - - -# Generate the mesa.def file for Windows. -# -# Usage: -# mesadef.py >mesa.def -# Then copy to src/mesa/drivers/windows/gdi -# -# Dependencies: -# The apispec file must be in the current directory. - - - -import apiparser -import string - - -def PrintHead(): - print '; DO NOT EDIT - This file generated automatically by mesadef.py script' - print 'DESCRIPTION \'Mesa (OpenGL work-alike) for Win32\'' - print 'VERSION 6.0' - print ';' - print '; Module definition file for Mesa (OPENGL32.DLL)' - print ';' - print '; Note: The OpenGL functions use the STDCALL' - print '; function calling convention. Microsoft\'s' - print '; OPENGL32 uses this convention and so must the' - print '; Mesa OPENGL32 so that the Mesa DLL can be used' - print '; as a drop-in replacement.' - print ';' - print '; The linker exports STDCALL entry points with' - print '; \'decorated\' names; e.g., _glBegin@0, where the' - print '; trailing number is the number of bytes of ' - print '; parameter data pushed onto the stack. The' - print '; callee is responsible for popping this data' - print '; off the stack, usually via a RETF n instruction.' - print ';' - print '; However, the Microsoft OPENGL32.DLL does not export' - print '; the decorated names, even though the calling convention' - print '; is STDCALL. So, this module definition file is' - print '; needed to force the Mesa OPENGL32.DLL to export the' - print '; symbols in the same manner as the Microsoft DLL.' - print '; Were it not for this problem, this file would not' - print '; be needed (for the gl* functions) since the entry' - print '; points are compiled with dllexport declspec.' - print ';' - print '; However, this file is still needed to export "internal"' - print '; Mesa symbols for the benefit of the OSMESA32.DLL.' - print ';' - print 'EXPORTS' - return -#enddef - - -def PrintTail(): - print ';' - print '; WGL API' - print '\twglChoosePixelFormat' - print '\twglCopyContext' - print '\twglCreateContext' - print '\twglCreateLayerContext' - print '\twglDeleteContext' - print '\twglDescribeLayerPlane' - print '\twglDescribePixelFormat' - print '\twglGetCurrentContext' - print '\twglGetCurrentDC' - print '\twglGetExtensionsStringARB' - print '\twglGetLayerPaletteEntries' - print '\twglGetPixelFormat' - print '\twglGetProcAddress' - print '\twglMakeCurrent' - print '\twglRealizeLayerPalette' - print '\twglSetLayerPaletteEntries' - print '\twglSetPixelFormat' - print '\twglShareLists' - print '\twglSwapBuffers' - print '\twglSwapLayerBuffers' - print '\twglUseFontBitmapsA' - print '\twglUseFontBitmapsW' - print '\twglUseFontOutlinesA' - print '\twglUseFontOutlinesW' - print ';' - print '; Mesa internals - mostly for OSMESA' - print '\t_ac_CreateContext' - print '\t_ac_DestroyContext' - print '\t_ac_InvalidateState' - print '\t_glapi_get_context' - print '\t_glapi_get_proc_address' - print '\t_mesa_buffer_data' - print '\t_mesa_buffer_map' - print '\t_mesa_buffer_subdata' - print '\t_mesa_choose_tex_format' - print '\t_mesa_compressed_texture_size' - print '\t_mesa_create_framebuffer' - print '\t_mesa_create_visual' - print '\t_mesa_delete_buffer_object' - print '\t_mesa_delete_texture_object' - print '\t_mesa_destroy_framebuffer' - print '\t_mesa_destroy_visual' - print '\t_mesa_enable_1_3_extensions' - print '\t_mesa_enable_1_4_extensions' - print '\t_mesa_enable_1_5_extensions' - print '\t_mesa_enable_sw_extensions' - print '\t_mesa_error' - print '\t_mesa_free_context_data' - print '\t_mesa_get_current_context' - print '\t_mesa_init_default_imports' - print '\t_mesa_initialize_context' - print '\t_mesa_make_current' - print '\t_mesa_new_buffer_object' - print '\t_mesa_new_texture_object' - print '\t_mesa_problem' - print '\t_mesa_ResizeBuffersMESA' - print '\t_mesa_store_compressed_teximage1d' - print '\t_mesa_store_compressed_teximage2d' - print '\t_mesa_store_compressed_teximage3d' - print '\t_mesa_store_compressed_texsubimage1d' - print '\t_mesa_store_compressed_texsubimage2d' - print '\t_mesa_store_compressed_texsubimage3d' - print '\t_mesa_store_teximage1d' - print '\t_mesa_store_teximage2d' - print '\t_mesa_store_teximage3d' - print '\t_mesa_store_texsubimage1d' - print '\t_mesa_store_texsubimage2d' - print '\t_mesa_store_texsubimage3d' - print '\t_mesa_test_proxy_teximage' - print '\t_mesa_Viewport' - print '\t_mesa_meta_CopyColorSubTable' - print '\t_mesa_meta_CopyColorTable' - print '\t_mesa_meta_CopyConvolutionFilter1D' - print '\t_mesa_meta_CopyConvolutionFilter2D' - print '\t_mesa_meta_CopyTexImage1D' - print '\t_mesa_meta_CopyTexImage2D' - print '\t_mesa_meta_CopyTexSubImage1D' - print '\t_mesa_meta_CopyTexSubImage2D' - print '\t_mesa_meta_CopyTexSubImage3D' - print '\t_swrast_Accum' - print '\t_swrast_alloc_buffers' - print '\t_swrast_Bitmap' - print '\t_swrast_CopyPixels' - print '\t_swrast_DrawPixels' - print '\t_swrast_GetDeviceDriverReference' - print '\t_swrast_Clear' - print '\t_swrast_choose_line' - print '\t_swrast_choose_triangle' - print '\t_swrast_CreateContext' - print '\t_swrast_DestroyContext' - print '\t_swrast_InvalidateState' - print '\t_swrast_ReadPixels' - print '\t_swrast_zbuffer_address' - print '\t_swsetup_Wakeup' - print '\t_swsetup_CreateContext' - print '\t_swsetup_DestroyContext' - print '\t_swsetup_InvalidateState' - print '\t_tnl_CreateContext' - print '\t_tnl_DestroyContext' - print '\t_tnl_InvalidateState' - print '\t_tnl_MakeCurrent' - print '\t_tnl_run_pipeline' -#enddef - - -records = [] - -def FindOffset(funcName): - for (name, alias, offset) in records: - if name == funcName: - return offset - #endif - #endfor - return -1 -#enddef - - -def EmitEntry(name, returnType, argTypeList, argNameList, alias, offset): - if alias == '': - dispatchName = name - else: - dispatchName = alias - if offset < 0: - offset = FindOffset(dispatchName) - if offset >= 0 and string.find(name, "unused") == -1: - print '\tgl%s' % (name) - # save this info in case we need to look up an alias later - records.append((name, dispatchName, offset)) - -#enddef - - -PrintHead() -apiparser.ProcessSpecFile("APIspec", EmitEntry) -PrintTail() diff --git a/src/mesa/glapi/next_available_offset.sh b/src/mesa/glapi/next_available_offset.sh deleted file mode 100755 index e7d6c2f4afa..00000000000 --- a/src/mesa/glapi/next_available_offset.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash -# -# (C) Copyright IBM Corporation 2004 -# 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 -# 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. -# -# Authors: -# Ian Romanick - -# Trivial shell script to search the API definition file and print out the -# next numerically available API entry-point offset. This could probably -# be made smarter, but it would be better to use the existin Python -# framework to do that. This is just a quick-and-dirty hack. - -num=$(grep 'offset="' gl_API.xml |\ - sed 's/.\+ offset="//g;s/".*$//g' |\ - grep -v '?' |\ - sort -rn |\ - head -1) - -echo $((num + 1)) diff --git a/src/mesa/glapi/remap_helper.py b/src/mesa/glapi/remap_helper.py deleted file mode 100644 index d93c7a42855..00000000000 --- a/src/mesa/glapi/remap_helper.py +++ /dev/null @@ -1,226 +0,0 @@ -#!/usr/bin/env python - -# Copyright (C) 2009 Chia-I Wu -# 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 ", "Chia-I Wu") - return - - - def printRealHeader(self): - print '#include "glapi/dispatch.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 '' - - # collect functions by versions/extensions - extension_functions = {} - abi_extensions = [] - for f in api.functionIterateAll(): - for n in f.entry_points: - category, num = api.get_category_for_name(n) - # consider only GL_VERSION_X_Y or extensions - c = gl_XML.real_category_name(category) - if c.startswith("GL_"): - if not extension_functions.has_key(c): - extension_functions[c] = [] - extension_functions[c].append(f) - # remember the ext names of the ABI - if (f.is_abi() and n == f.name and - c not in abi_extensions): - abi_extensions.append(c) - # ignore the ABI itself - for ext in abi_extensions: - extension_functions.pop(ext) - - 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 and has alt names - if f.is_abi() and len(f.entry_points) > 1: - 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 ) diff --git a/src/mesa/glapi/typeexpr.py b/src/mesa/glapi/typeexpr.py deleted file mode 100644 index 8ba7de48627..00000000000 --- a/src/mesa/glapi/typeexpr.py +++ /dev/null @@ -1,292 +0,0 @@ -#!/usr/bin/env python - -# (C) Copyright IBM Corporation 2005 -# 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 -# 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. -# -# Authors: -# Ian Romanick - -import string, copy - -class type_node: - def __init__(self): - self.pointer = 0 # bool - self.const = 0 # bool - self.signed = 1 # bool - self.integer = 1 # bool - - # If elements is set to non-zero, then field is an array. - self.elements = 0 - - self.name = None - self.size = 0 # type's size in bytes - return - - - def string(self): - """Return string representation of this type_node.""" - s = "" - - if self.pointer: - s = "* " - - if self.const: - s += "const " - - if not self.pointer: - if self.integer: - if self.signed: - s += "signed " - else: - s += "unsigned " - - if self.name: - s += "%s " % (self.name) - - return s - - -class type_table: - def __init__(self): - self.types_by_name = {} - return - - - def add_type(self, type_expr): - self.types_by_name[ type_expr.get_base_name() ] = type_expr - return - - - def find_type(self, name): - if name in self.types_by_name: - return self.types_by_name[ name ] - else: - return None - - -def create_initial_types(): - tt = type_table() - - basic_types = [ - ("char", 1, 1), - ("short", 2, 1), - ("int", 4, 1), - ("long", 4, 1), - ("float", 4, 0), - ("double", 8, 0), - ("enum", 4, 1) - ] - - for (type_name, type_size, integer) in basic_types: - te = type_expression(None) - tn = type_node() - tn.name = type_name - tn.size = type_size - tn.integer = integer - te.expr.append(tn) - tt.add_type( te ) - - type_expression.built_in_types = tt - return - - -class type_expression: - built_in_types = None - - def __init__(self, type_string, extra_types = None): - self.expr = [] - - if not type_string: - return - - self.original_string = type_string - - if not type_expression.built_in_types: - raise RuntimeError("create_initial_types must be called before creating type_expression objects.") - - # Replace '*' with ' * ' in type_string. Then, split the string - # into tokens, separated by spaces. - tokens = string.split( string.replace( type_string, "*", " * " ) ) - - const = 0 - t = None - signed = 0 - unsigned = 0 - - for i in tokens: - if i == "const": - if t and t.pointer: - t.const = 1 - else: - const = 1 - elif i == "signed": - signed = 1 - elif i == "unsigned": - unsigned = 1 - elif i == "*": - # This is a quirky special-case because of the - # way the C works for types. If 'unsigned' is - # specified all by itself, it is treated the - # same as "unsigned int". - - if unsigned: - self.set_base_type( "int", signed, unsigned, const, extra_types ) - const = 0 - signed = 0 - unsigned = 0 - - if not self.expr: - raise RuntimeError("Invalid type expression (dangling pointer)") - - if signed: - raise RuntimeError("Invalid type expression (signed / unsigned applied to pointer)") - - t = type_node() - t.pointer = 1 - self.expr.append( t ) - else: - if self.expr: - raise RuntimeError('Invalid type expression (garbage after pointer qualifier -> "%s")' % (self.original_string)) - - self.set_base_type( i, signed, unsigned, const, extra_types ) - const = 0 - signed = 0 - unsigned = 0 - - if signed and unsigned: - raise RuntimeError("Invalid type expression (both signed and unsigned specified)") - - - if const: - raise RuntimeError("Invalid type expression (dangling const)") - - if unsigned: - raise RuntimeError("Invalid type expression (dangling signed)") - - if signed: - raise RuntimeError("Invalid type expression (dangling unsigned)") - - return - - - def set_base_type(self, type_name, signed, unsigned, const, extra_types): - te = type_expression.built_in_types.find_type( type_name ) - if not te: - te = extra_types.find_type( type_name ) - - if not te: - raise RuntimeError('Unknown base type "%s".' % (type_name)) - - self.expr = copy.deepcopy(te.expr) - - t = self.expr[ len(self.expr) - 1 ] - t.const = const - if signed: - t.signed = 1 - elif unsigned: - t.signed = 0 - - - def set_base_type_node(self, tn): - self.expr = [tn] - return - - - def set_elements(self, count): - tn = self.expr[0] - - tn.elements = count - return - - - def string(self): - s = "" - for t in self.expr: - s += t.string() - - return s - - - def get_base_type_node(self): - return self.expr[0] - - - def get_base_name(self): - if len(self.expr): - return self.expr[0].name - else: - return None - - - def get_element_size(self): - tn = self.expr[0] - - if tn.elements: - return tn.elements * tn.size - else: - return tn.size - - - def get_element_count(self): - tn = self.expr[0] - return tn.elements - - - def get_stack_size(self): - tn = self.expr[ len(self.expr) - 1 ] - - if tn.elements or tn.pointer: - return 4 - elif not tn.integer: - return tn.size - else: - return 4 - - - def is_pointer(self): - tn = self.expr[ len(self.expr) - 1 ] - return tn.pointer - - - def format_string(self): - tn = self.expr[ len(self.expr) - 1 ] - if tn.pointer: - return "%p" - elif not tn.integer: - return "%f" - else: - return "%d" - - - -if __name__ == '__main__': - - types_to_try = [ "int", "int *", "const int *", "int * const", "const int * const", \ - "unsigned * const *", \ - "float", "const double", "double * const"] - - create_initial_types() - - for t in types_to_try: - print 'Trying "%s"...' % (t) - te = type_expression( t ) - print 'Got "%s" (%u, %u).' % (te.string(), te.get_stack_size(), te.get_element_size())