summaryrefslogtreecommitdiffstats
path: root/src/mesa/glapi/glX_server_table.py
diff options
context:
space:
mode:
authorJulien Cristau <[email protected]>2007-02-01 11:50:36 +0100
committerJulien Cristau <[email protected]>2007-02-01 11:50:36 +0100
commit2634f06c2095b79d4252bb81c0b0272139dad890 (patch)
tree855ba634812939982daa999dc44365a4d889d11e /src/mesa/glapi/glX_server_table.py
parent7549426a168f3803d6023622dd9e630a5fa2faf6 (diff)
parenteb667b979bc941f05b8f40a2fc39af6fac960ac5 (diff)
Merge branch 'upstream-experimental' into debian-experimental
Conflicts: progs/util/README progs/util/glstate.c progs/util/glstate.h progs/util/sampleMakefile src/glu/sgi/libnurbs/interface/bezierEval.h src/glu/sgi/libnurbs/interface/bezierPatch.cc src/glu/sgi/libnurbs/interface/bezierPatch.h src/glu/sgi/libnurbs/interface/bezierPatchMesh.cc src/glu/sgi/libnurbs/interface/bezierPatchMesh.h src/glu/sgi/libnurbs/interface/glcurveval.cc src/glu/sgi/libnurbs/interface/glimports.h src/glu/sgi/libnurbs/interface/glinterface.cc src/glu/sgi/libnurbs/interface/glrenderer.h src/glu/sgi/libnurbs/interface/incurveeval.cc src/glu/sgi/libnurbs/interface/insurfeval.cc src/glu/sgi/libnurbs/interface/mystdio.h src/glu/sgi/libnurbs/interface/mystdlib.h src/glu/sgi/libnurbs/internals/arc.h src/glu/sgi/libnurbs/internals/arcsorter.cc src/glu/sgi/libnurbs/internals/arcsorter.h src/glu/sgi/libnurbs/internals/arctess.h src/glu/sgi/libnurbs/internals/backend.cc src/glu/sgi/libnurbs/internals/backend.h src/glu/sgi/libnurbs/internals/basiccrveval.h src/glu/sgi/libnurbs/internals/basicsurfeval.h src/glu/sgi/libnurbs/internals/bezierarc.h src/glu/sgi/libnurbs/internals/bin.cc src/glu/sgi/libnurbs/internals/bin.h src/glu/sgi/libnurbs/internals/bufpool.cc src/glu/sgi/libnurbs/internals/bufpool.h src/glu/sgi/libnurbs/internals/cachingeval.cc src/glu/sgi/libnurbs/internals/cachingeval.h src/glu/sgi/libnurbs/internals/ccw.cc src/glu/sgi/libnurbs/internals/coveandtiler.h src/glu/sgi/libnurbs/internals/curve.cc src/glu/sgi/libnurbs/internals/curve.h src/glu/sgi/libnurbs/internals/curvelist.cc src/glu/sgi/libnurbs/internals/curvelist.h src/glu/sgi/libnurbs/internals/curvesub.cc src/glu/sgi/libnurbs/internals/dataTransform.cc src/glu/sgi/libnurbs/internals/dataTransform.h src/glu/sgi/libnurbs/internals/defines.h src/glu/sgi/libnurbs/internals/displaylist.cc src/glu/sgi/libnurbs/internals/displaylist.h src/glu/sgi/libnurbs/internals/displaymode.h src/glu/sgi/libnurbs/internals/flist.cc src/glu/sgi/libnurbs/internals/flist.h src/glu/sgi/libnurbs/internals/flistsorter.cc src/glu/sgi/libnurbs/internals/flistsorter.h src/glu/sgi/libnurbs/internals/gridline.h src/glu/sgi/libnurbs/internals/gridtrimvertex.h src/glu/sgi/libnurbs/internals/gridvertex.h src/glu/sgi/libnurbs/internals/hull.cc src/glu/sgi/libnurbs/internals/hull.h src/glu/sgi/libnurbs/internals/intersect.cc src/glu/sgi/libnurbs/internals/jarcloc.h src/glu/sgi/libnurbs/internals/knotvector.h src/glu/sgi/libnurbs/internals/mapdesc.cc src/glu/sgi/libnurbs/internals/mapdesc.h src/glu/sgi/libnurbs/internals/mapdescv.cc src/glu/sgi/libnurbs/internals/maplist.cc src/glu/sgi/libnurbs/internals/maplist.h src/glu/sgi/libnurbs/internals/mesher.cc src/glu/sgi/libnurbs/internals/mesher.h src/glu/sgi/libnurbs/internals/monoTriangulationBackend.cc src/glu/sgi/libnurbs/internals/monotonizer.cc src/glu/sgi/libnurbs/internals/monotonizer.h src/glu/sgi/libnurbs/internals/myassert.h src/glu/sgi/libnurbs/internals/mycode.cc src/glu/sgi/libnurbs/internals/mystring.h src/glu/sgi/libnurbs/internals/nurbsconsts.h src/glu/sgi/libnurbs/internals/nurbstess.cc src/glu/sgi/libnurbs/internals/patch.cc src/glu/sgi/libnurbs/internals/patch.h src/glu/sgi/libnurbs/internals/patchlist.cc src/glu/sgi/libnurbs/internals/patchlist.h src/glu/sgi/libnurbs/internals/pwlarc.h src/glu/sgi/libnurbs/internals/quilt.cc src/glu/sgi/libnurbs/internals/quilt.h src/glu/sgi/libnurbs/internals/reader.cc src/glu/sgi/libnurbs/internals/reader.h src/glu/sgi/libnurbs/internals/renderhints.cc src/glu/sgi/libnurbs/internals/renderhints.h src/glu/sgi/libnurbs/internals/simplemath.h src/glu/sgi/libnurbs/internals/slicer.cc src/glu/sgi/libnurbs/internals/slicer.h src/glu/sgi/libnurbs/internals/sorter.cc src/glu/sgi/libnurbs/internals/sorter.h src/glu/sgi/libnurbs/internals/splitarcs.cc src/glu/sgi/libnurbs/internals/subdivider.h src/glu/sgi/libnurbs/internals/tobezier.cc src/glu/sgi/libnurbs/internals/trimline.cc src/glu/sgi/libnurbs/internals/trimline.h src/glu/sgi/libnurbs/internals/trimregion.cc src/glu/sgi/libnurbs/internals/trimregion.h src/glu/sgi/libnurbs/internals/trimvertex.h src/glu/sgi/libnurbs/internals/trimvertpool.cc src/glu/sgi/libnurbs/internals/trimvertpool.h src/glu/sgi/libnurbs/internals/types.h src/glu/sgi/libnurbs/internals/uarray.cc src/glu/sgi/libnurbs/internals/uarray.h src/glu/sgi/libnurbs/internals/varray.cc src/glu/sgi/libnurbs/internals/varray.h src/glu/sgi/libnurbs/nurbtess/definitions.h src/glu/sgi/libnurbs/nurbtess/directedLine.h src/glu/sgi/libnurbs/nurbtess/glimports.h src/glu/sgi/libnurbs/nurbtess/gridWrap.cc src/glu/sgi/libnurbs/nurbtess/gridWrap.h src/glu/sgi/libnurbs/nurbtess/monoChain.cc src/glu/sgi/libnurbs/nurbtess/monoChain.h src/glu/sgi/libnurbs/nurbtess/monoTriangulation.cc src/glu/sgi/libnurbs/nurbtess/monoTriangulation.h src/glu/sgi/libnurbs/nurbtess/mystdio.h src/glu/sgi/libnurbs/nurbtess/mystdlib.h src/glu/sgi/libnurbs/nurbtess/partitionX.cc src/glu/sgi/libnurbs/nurbtess/partitionX.h src/glu/sgi/libnurbs/nurbtess/partitionY.cc src/glu/sgi/libnurbs/nurbtess/partitionY.h src/glu/sgi/libnurbs/nurbtess/polyDBG.h src/glu/sgi/libnurbs/nurbtess/polyUtil.cc src/glu/sgi/libnurbs/nurbtess/polyUtil.h src/glu/sgi/libnurbs/nurbtess/primitiveStream.cc src/glu/sgi/libnurbs/nurbtess/primitiveStream.h src/glu/sgi/libnurbs/nurbtess/quicksort.cc src/glu/sgi/libnurbs/nurbtess/quicksort.h src/glu/sgi/libnurbs/nurbtess/rectBlock.cc src/glu/sgi/libnurbs/nurbtess/rectBlock.h src/glu/sgi/libnurbs/nurbtess/sampleComp.cc src/glu/sgi/libnurbs/nurbtess/sampleComp.h src/glu/sgi/libnurbs/nurbtess/sampleCompBot.cc src/glu/sgi/libnurbs/nurbtess/sampleCompBot.h src/glu/sgi/libnurbs/nurbtess/sampleCompRight.cc src/glu/sgi/libnurbs/nurbtess/sampleCompRight.h src/glu/sgi/libnurbs/nurbtess/sampleCompTop.cc src/glu/sgi/libnurbs/nurbtess/sampleCompTop.h src/glu/sgi/libnurbs/nurbtess/sampleMonoPoly.cc src/glu/sgi/libnurbs/nurbtess/sampleMonoPoly.h src/glu/sgi/libnurbs/nurbtess/sampledLine.cc src/glu/sgi/libnurbs/nurbtess/sampledLine.h src/glu/sgi/libnurbs/nurbtess/searchTree.cc src/glu/sgi/libnurbs/nurbtess/searchTree.h src/glu/sgi/libnurbs/nurbtess/zlassert.h src/glu/sgi/libtess/README src/glu/sgi/libtess/alg-outline src/glu/sgi/libtess/dict-list.h src/glu/sgi/libtess/dict.c src/glu/sgi/libtess/dict.h src/glu/sgi/libtess/geom.c src/glu/sgi/libtess/memalloc.c src/glu/sgi/libtess/memalloc.h src/glu/sgi/libtess/mesh.c src/glu/sgi/libtess/mesh.h src/glu/sgi/libtess/normal.h src/glu/sgi/libtess/priorityq-heap.c src/glu/sgi/libtess/priorityq-heap.h src/glu/sgi/libtess/priorityq-sort.h src/glu/sgi/libtess/priorityq.c src/glu/sgi/libtess/priorityq.h src/glu/sgi/libtess/render.c src/glu/sgi/libtess/render.h src/glu/sgi/libtess/sweep.h src/glu/sgi/libtess/tess.h src/glu/sgi/libtess/tessmono.c src/glu/sgi/libtess/tessmono.h src/glu/sgi/libutil/error.c src/glu/sgi/libutil/glue.c src/glu/sgi/libutil/gluint.h src/glu/sgi/libutil/project.c src/glu/sgi/libutil/registry.c
Diffstat (limited to 'src/mesa/glapi/glX_server_table.py')
-rw-r--r--src/mesa/glapi/glX_server_table.py411
1 files changed, 411 insertions, 0 deletions
diff --git a/src/mesa/glapi/glX_server_table.py b/src/mesa/glapi/glX_server_table.py
new file mode 100644
index 00000000000..f3962f875b0
--- /dev/null
+++ b/src/mesa/glapi/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 <[email protected]>
+
+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 <inttypes.h>'
+ 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 )