VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/packer/packer.py@ 37216

Last change on this file since 37216 was 33475, checked in by vboxsync, 14 years ago

crOpenGL/wddm: multithreading fix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.8 KB
Line 
1# Copyright (c) 2001, Stanford University
2# All rights reserved.
3#
4# See the file LICENSE.txt for information on redistributing this software.
5
6# This script generates the packer.c file from the gl_header.parsed file.
7
8import sys, string, re
9
10import apiutil
11
12
13
14def WriteData( offset, arg_type, arg_name, is_swapped ):
15 """Return a string to write a variable to the packing buffer."""
16 retval = 9
17 if apiutil.IsPointer(arg_type):
18 retval = "\tWRITE_NETWORK_POINTER( %d, (void *) %s );" % (offset, arg_name )
19 else:
20 if is_swapped:
21 if arg_type == "GLfloat" or arg_type == "GLclampf":
22 retval = "\tWRITE_DATA( %d, GLuint, SWAPFLOAT(%s) );" % (offset, arg_name)
23 elif arg_type == "GLdouble" or arg_type == "GLclampd":
24 retval = "\tWRITE_SWAPPED_DOUBLE( %d, %s );" % (offset, arg_name)
25 elif apiutil.sizeof(arg_type) == 1:
26 retval = "\tWRITE_DATA( %d, %s, %s );" % (offset, arg_type, arg_name)
27 elif apiutil.sizeof(arg_type) == 2:
28 retval = "\tWRITE_DATA( %d, %s, SWAP16(%s) );" % (offset, arg_type, arg_name)
29 elif apiutil.sizeof(arg_type) == 4:
30 retval = "\tWRITE_DATA( %d, %s, SWAP32(%s) );" % (offset, arg_type, arg_name)
31 else:
32 if arg_type == "GLdouble" or arg_type == "GLclampd":
33 retval = "\tWRITE_DOUBLE( %d, %s );" % (offset, arg_name)
34 else:
35 retval = "\tWRITE_DATA( %d, %s, %s );" % (offset, arg_type, arg_name)
36 if retval == 9:
37 print >>sys.stderr, "no retval for %s %s" % (arg_name, arg_type)
38 assert 0
39 return retval
40
41
42def UpdateCurrentPointer( func_name ):
43 m = re.search( r"^(Color|Normal)([1234])(ub|b|us|s|ui|i|f|d)$", func_name )
44 if m :
45 k = m.group(1)
46 name = '%s%s' % (k[:1].lower(),k[1:])
47 type = m.group(3) + m.group(2)
48 print "\tpc->current.c.%s.%s = data_ptr;" % (name,type)
49 return
50
51 m = re.search( r"^(SecondaryColor)(3)(ub|b|us|s|ui|i|f|d)EXT$", func_name )
52 if m :
53 k = m.group(1)
54 name = 'secondaryColor'
55 type = m.group(3) + m.group(2)
56 print "\tpc->current.c.%s.%s = data_ptr;" % (name,type)
57 return
58
59 m = re.search( r"^(TexCoord)([1234])(ub|b|us|s|ui|i|f|d)$", func_name )
60 if m :
61 k = m.group(1)
62 name = 'texCoord'
63 type = m.group(3) + m.group(2)
64 print "\tpc->current.c.%s.%s[0] = data_ptr;" % (name,type)
65 return
66
67 m = re.search( r"^(MultiTexCoord)([1234])(ub|b|us|s|ui|i|f|d)ARB$", func_name )
68 if m :
69 k = m.group(1)
70 name = 'texCoord'
71 type = m.group(3) + m.group(2)
72 print "\tpc->current.c.%s.%s[texture-GL_TEXTURE0_ARB] = data_ptr + 4;" % (name,type)
73 return
74
75 m = re.match( r"^(Index)(ub|b|us|s|ui|i|f|d)$", func_name )
76 if m :
77 k = m.group(1)
78 name = 'index'
79 type = m.group(2) + "1"
80 print "\tpc->current.c.%s.%s = data_ptr;" % (name,type)
81 return
82
83 m = re.match( r"^(EdgeFlag)$", func_name )
84 if m :
85 k = m.group(1)
86 name = 'edgeFlag'
87 type = "l1"
88 print "\tpc->current.c.%s.%s = data_ptr;" % (name,type)
89 return
90
91 m = re.match( r"^(FogCoord)(f|d)EXT$", func_name )
92 if m :
93 k = m.group(1)
94 name = 'fogCoord'
95 type = m.group(2) + "1"
96 print "\tpc->current.c.%s.%s = data_ptr;" % (name,type)
97 return
98
99
100 m = re.search( r"^(VertexAttrib)([1234])N?(ub|b|s|f|d)(NV|ARB)$", func_name )
101 if m :
102 k = m.group(1)
103 name = 'vertexAttrib'
104 type = m.group(3) + m.group(2)
105 # Add 12 to skip the packet length, opcode and index fields
106 print "\tpc->current.c.%s.%s[index] = data_ptr + 12;" % (name,type)
107 if m.group(4) == "ARB" or m.group(4) == "NV":
108 print "\tpc->current.attribsUsedMask |= (1 << index);"
109 return
110
111
112
113def PrintFunc( func_name, params, is_swapped, can_have_pointers ):
114 """Emit a packer function."""
115 if is_swapped:
116 print 'void PACK_APIENTRY crPack%sSWAP( %s )' % (func_name, apiutil.MakeDeclarationString(params))
117 else:
118 print 'void PACK_APIENTRY crPack%s( %s )' % (func_name, apiutil.MakeDeclarationString(params))
119 print '{'
120 print '\tCR_GET_PACKER_CONTEXT(pc);'
121
122 # Save original function name
123 orig_func_name = func_name
124
125 # Convert to a non-vector version of the function if possible
126 func_name = apiutil.NonVectorFunction( func_name )
127 if not func_name:
128 func_name = orig_func_name
129
130 # Check if there are any pointer parameters.
131 # That's usually a problem so we'll emit an error function.
132 nonVecParams = apiutil.Parameters(func_name)
133 bail_out = 0
134 for (name, type, vecSize) in nonVecParams:
135 if apiutil.IsPointer(type) and vecSize == 0 and not can_have_pointers:
136 bail_out = 1
137 if bail_out:
138 for (name, type, vecSize) in nonVecParams:
139 print '\t(void)%s;' % (name)
140 print '\tcrError ( "%s needs to be special cased %d %d!");' % (func_name, vecSize, can_have_pointers)
141 print '\t(void) pc;'
142 print '}'
143 # XXX we should really abort here
144 return
145
146 if "extpack" in apiutil.ChromiumProps(func_name):
147 is_extended = 1
148 else:
149 is_extended = 0
150
151
152 print "\tunsigned char *data_ptr;"
153 print '\t(void) pc;'
154 #if func_name == "Enable" or func_name == "Disable":
155 # print "\tCRASSERT(!pc->buffer.geometry_only); /* sanity check */"
156
157 for index in range(0,len(params)):
158 (name, type, vecSize) = params[index]
159 if vecSize>0 and func_name!=orig_func_name:
160 print " if (!%s) {" % name
161 # Know the reason for this one, so avoid the spam.
162 if orig_func_name != "SecondaryColor3fvEXT":
163 print " crDebug(\"App passed NULL as %s for %s\");" % (name, orig_func_name)
164 print " return;"
165 print " }"
166
167 packet_length = apiutil.PacketLength(nonVecParams)
168
169 if packet_length == 0 and not is_extended:
170 print "\tCR_GET_BUFFERED_POINTER_NO_ARGS( pc );"
171 elif func_name[:9] == "Translate" or func_name[:5] == "Color":
172 # XXX WTF is the purpose of this?
173 if is_extended:
174 packet_length += 8
175 print "\tCR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH( pc, %d, GL_TRUE );" % packet_length
176 else:
177 if is_extended:
178 packet_length += 8
179 print "\tCR_GET_BUFFERED_POINTER( pc, %d );" % packet_length
180 UpdateCurrentPointer( func_name )
181
182 if is_extended:
183 counter = 8
184 print WriteData( 0, 'GLint', packet_length, is_swapped )
185 print WriteData( 4, 'GLenum', apiutil.ExtendedOpcodeName( func_name ), is_swapped )
186 else:
187 counter = 0
188
189 # Now emit the WRITE_() macros for all parameters
190 for index in range(0,len(params)):
191 (name, type, vecSize) = params[index]
192 # if we're converting a vector-valued function to a non-vector func:
193 if vecSize > 0 and func_name != orig_func_name:
194 ptrType = apiutil.PointerType(type)
195 for i in range(0, vecSize):
196 print WriteData( counter + i * apiutil.sizeof(ptrType),
197 ptrType, "%s[%d]" % (name, i), is_swapped )
198 # XXX increment counter here?
199 else:
200 print WriteData( counter, type, name, is_swapped )
201 if apiutil.IsPointer(type):
202 counter += apiutil.PointerSize()
203 else:
204 counter += apiutil.sizeof(type)
205
206 # finish up
207 if is_extended:
208 print "\tWRITE_OPCODE( pc, CR_EXTEND_OPCODE );"
209 else:
210 print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName( func_name )
211
212 print '\tCR_UNLOCK_PACKER_CONTEXT(pc);'
213 print '}\n'
214
215
216
217
218apiutil.CopyrightC()
219
220print """
221/* DO NOT EDIT - THIS FILE GENERATED BY THE packer.py SCRIPT */
222
223/* For each of the OpenGL functions we have a packer function which
224 * packs the function's opcode and arguments into a buffer.
225 */
226
227#include "packer.h"
228#include "cr_opcodes.h"
229
230"""
231
232
233keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")
234
235for func_name in keys:
236 if apiutil.FindSpecial( "packer", func_name ):
237 continue
238
239 if not apiutil.HasPackOpcode(func_name):
240 continue
241
242 pointers_ok = 0
243
244 return_type = apiutil.ReturnType(func_name)
245 params = apiutil.Parameters(func_name)
246
247 if return_type != 'void':
248 # Yet another gross hack for glGetString
249 if string.find( return_type, '*' ) == -1:
250 return_type = return_type + " *"
251 params.append(("return_value", return_type, 0))
252
253 if "get" in apiutil.Properties(func_name):
254 pointers_ok = 1
255 params.append(("writeback", "int *", 0))
256
257 if func_name == 'Writeback':
258 pointers_ok = 1
259
260 PrintFunc( func_name, params, 0, pointers_ok )
261 PrintFunc( func_name, params, 1, pointers_ok )
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette