VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/unpacker/unpack.py@ 51442

Last change on this file since 51442 was 50975, checked in by vboxsync, 11 years ago

crOpenGL build fix take 2

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.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
6import sys
7
8import apiutil
9
10
11apiutil.CopyrightC()
12
13print """/* DO NOT EDIT! THIS CODE IS AUTOGENERATED BY unpack.py */
14
15#include "unpacker.h"
16#include "cr_opcodes.h"
17#include "cr_error.h"
18#include "cr_mem.h"
19#include "cr_spu.h"
20#include "unpack_extend.h"
21#include <stdio.h>
22#include <memory.h>
23
24#include <iprt/cdefs.h>
25
26DECLEXPORT(const unsigned char *) cr_unpackData = NULL;
27SPUDispatchTable cr_unpackDispatch;
28
29static void crUnpackExtend(void);
30static void crUnpackExtendDbg(void);
31
32/*#define CR_UNPACK_DEBUG_OPCODES*/
33/*#define CR_UNPACK_DEBUG_LAST_OPCODES*/
34"""
35
36nodebug_opcodes = [
37 "CR_MULTITEXCOORD2FARB_OPCODE",
38 "CR_VERTEX3F_OPCODE",
39 "CR_NORMAL3F_OPCODE",
40 "CR_COLOR4UB_OPCODE",
41 "CR_LOADIDENTITY_OPCODE",
42 "CR_MATRIXMODE_OPCODE",
43 "CR_LOADMATRIXF_OPCODE",
44 "CR_DISABLE_OPCODE",
45 "CR_COLOR4F_OPCODE",
46 "CR_ENABLE_OPCODE",
47 "CR_BEGIN_OPCODE",
48 "CR_END_OPCODE",
49 "CR_SECONDARYCOLOR3FEXT_OPCODE"
50]
51
52nodebug_extopcodes = [
53 "CR_ACTIVETEXTUREARB_EXTEND_OPCODE"
54]
55
56#
57# Useful functions
58#
59
60def ReadData( offset, arg_type ):
61 """Emit a READ_DOUBLE or READ_DATA call for pulling a GL function
62 argument out of the buffer's operand area."""
63 if arg_type == "GLdouble" or arg_type == "GLclampd":
64 retval = "READ_DOUBLE( %d )" % offset
65 else:
66 retval = "READ_DATA( %d, %s )" % (offset, arg_type)
67 return retval
68
69
70def FindReturnPointer( return_type, params ):
71 """For GL functions that return values (either as the return value or
72 through a pointer parameter) emit a SET_RETURN_PTR call."""
73 arg_len = apiutil.PacketLength( params )
74 if (return_type != 'void'):
75 print '\tSET_RETURN_PTR( %d );' % (arg_len + 8) # extended opcode plus packet length
76 else:
77 paramList = [ ('foo', 'void *', 0) ]
78 print '\tSET_RETURN_PTR( %d );' % (arg_len + 8 - apiutil.PacketLength(paramList))
79
80
81def FindWritebackPointer( return_type, params ):
82 """Emit a SET_WRITEBACK_PTR call."""
83 arg_len = apiutil.PacketLength( params )
84 if return_type != 'void':
85 paramList = [ ('foo', 'void *', 0) ]
86 arg_len += apiutil.PacketLength( paramList )
87
88 print '\tSET_WRITEBACK_PTR( %d );' % (arg_len + 8) # extended opcode plus packet length
89
90
91def MakeNormalCall( return_type, func_name, params, counter_init = 0 ):
92 counter = counter_init
93 copy_of_params = params[:]
94
95 for i in range( 0, len(params) ):
96 (name, type, vecSize) = params[i]
97 if apiutil.IsPointer(copy_of_params[i][1]):
98 params[i] = ('NULL', type, vecSize)
99 copy_of_params[i] = (copy_of_params[i][0], 'void', 0)
100 if not "get" in apiutil.Properties(func_name):
101 print '\tcrError( "%s needs to be special cased!" );' % func_name
102 else:
103 print "\t%s %s = %s;" % ( copy_of_params[i][1], name, ReadData( counter, copy_of_params[i][1] ) )
104 counter += apiutil.sizeof(copy_of_params[i][1])
105
106 if ("get" in apiutil.Properties(func_name)):
107 FindReturnPointer( return_type, params )
108 FindWritebackPointer( return_type, params )
109
110 if return_type != "void":
111 print "\t(void)",
112 else:
113 print "\t",
114 print "cr_unpackDispatch.%s( %s );" % (func_name, apiutil.MakeCallString(params))
115
116
117def MakeVectorCall( return_type, func_name, arg_type ):
118 """Convert a call like glVertex3f to glVertex3fv."""
119 vec_func = apiutil.VectorFunction(func_name)
120 params = apiutil.Parameters(vec_func)
121 assert len(params) == 1
122 (arg_name, vecType, vecSize) = params[0]
123
124 if arg_type == "GLdouble" or arg_type == "GLclampd":
125 print "#ifdef CR_UNALIGNED_ACCESS_OKAY"
126 print "\tcr_unpackDispatch.%s((%s) cr_unpackData);" % (vec_func, vecType)
127 print "#else"
128 for index in range(0, vecSize):
129 print "\tGLdouble v" + `index` + " = READ_DOUBLE(", `index * 8`, ");"
130 if return_type != "void":
131 print "\t(void) cr_unpackDispatch.%s(" % func_name,
132 else:
133 print "\tcr_unpackDispatch.%s(" % func_name,
134 for index in range(0, vecSize):
135 print "v" + `index`,
136 if index != vecSize - 1:
137 print ",",
138 print ");"
139 print "#endif"
140 else:
141 print "\tcr_unpackDispatch.%s((%s) cr_unpackData);" % (vec_func, vecType)
142
143
144
145keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")
146
147
148#
149# Generate unpack functions for all the simple functions.
150#
151for func_name in keys:
152 if (not "pack" in apiutil.ChromiumProps(func_name) or
153 apiutil.FindSpecial( "unpacker", func_name )):
154 continue
155
156 params = apiutil.Parameters(func_name)
157 return_type = apiutil.ReturnType(func_name)
158
159 print "static void crUnpack%s(void)" % func_name
160 print "{"
161
162 vector_func = apiutil.VectorFunction(func_name)
163 if (vector_func and len(apiutil.Parameters(vector_func)) == 1):
164 MakeVectorCall( return_type, func_name, params[0][1] )
165 else:
166 MakeNormalCall( return_type, func_name, params )
167 packet_length = apiutil.PacketLength( params )
168 if packet_length == 0:
169 print "\tINCR_DATA_PTR_NO_ARGS( );"
170 else:
171 print "\tINCR_DATA_PTR( %d );" % packet_length
172 print "}\n"
173
174
175#
176# Emit some code
177#
178print """
179typedef struct __dispatchNode {
180 const unsigned char *unpackData;
181 struct __dispatchNode *next;
182} DispatchNode;
183
184static DispatchNode *unpackStack = NULL;
185
186static SPUDispatchTable *cr_lastDispatch = NULL;
187
188void crUnpackPush(void)
189{
190 DispatchNode *node = (DispatchNode*)crAlloc( sizeof( *node ) );
191 node->next = unpackStack;
192 unpackStack = node;
193 node->unpackData = cr_unpackData;
194}
195
196void crUnpackPop(void)
197{
198 DispatchNode *node = unpackStack;
199
200 if (!node)
201 {
202 crError( "crUnpackPop called with an empty stack!" );
203 }
204 unpackStack = node->next;
205 cr_unpackData = node->unpackData;
206 crFree( node );
207}
208
209CR_UNPACK_BUFFER_TYPE crUnpackGetBufferType(const void *opcodes, unsigned int num_opcodes)
210{
211 const uint8_t *pu8Codes = (const uint8_t *)opcodes;
212
213 CR_UNPACK_BUFFER_TYPE enmType;
214 uint8_t first;
215 uint8_t last;
216
217 if (!num_opcodes)
218 return CR_UNPACK_BUFFER_TYPE_GENERIC;
219
220 first = pu8Codes[0];
221 last = pu8Codes[1-(int)num_opcodes];
222
223 enmType = (first != CR_CMDBLOCKBEGIN_OPCODE) ? CR_UNPACK_BUFFER_TYPE_GENERIC : CR_UNPACK_BUFFER_TYPE_CMDBLOCK_BEGIN;
224
225 if (last != CR_CMDBLOCKEND_OPCODE)
226 return enmType;
227
228 /* last is CMDBLOCKEND*/
229 return (enmType == CR_UNPACK_BUFFER_TYPE_CMDBLOCK_BEGIN) ? CR_UNPACK_BUFFER_TYPE_GENERIC : CR_UNPACK_BUFFER_TYPE_CMDBLOCK_END;
230}
231
232void crUnpack( const void *data, const void *opcodes,
233 unsigned int num_opcodes, SPUDispatchTable *table )
234{
235 unsigned int i;
236 const unsigned char *unpack_opcodes;
237 if (table != cr_lastDispatch)
238 {
239 crSPUCopyDispatchTable( &cr_unpackDispatch, table );
240 cr_lastDispatch = table;
241 }
242
243 unpack_opcodes = (const unsigned char *)opcodes;
244 cr_unpackData = (const unsigned char *)data;
245
246#if defined(CR_UNPACK_DEBUG_OPCODES) || defined(CR_UNPACK_DEBUG_LAST_OPCODES)
247 crDebug("crUnpack: %d opcodes", num_opcodes);
248#endif
249
250 for (i = 0 ; i < num_opcodes ; i++)
251 {
252
253 CRDBGPTR_CHECKZ(writeback_ptr);
254 CRDBGPTR_CHECKZ(return_ptr);
255
256 /*crDebug(\"Unpacking opcode \%d\", *unpack_opcodes);*/
257 switch( *unpack_opcodes )
258 {"""
259
260#
261# Emit switch cases for all unextended opcodes
262#
263for func_name in keys:
264 if "pack" in apiutil.ChromiumProps(func_name):
265 print '\t\t\tcase %s:' % apiutil.OpcodeName( func_name )
266 if not apiutil.OpcodeName(func_name) in nodebug_opcodes:
267 print """
268#ifdef CR_UNPACK_DEBUG_LAST_OPCODES
269 if (i==(num_opcodes-1))
270#endif
271#if defined(CR_UNPACK_DEBUG_OPCODES) || defined(CR_UNPACK_DEBUG_LAST_OPCODES)
272 crDebug("Unpack: %s");
273#endif """ % apiutil.OpcodeName(func_name)
274 print '\t\t\t\tcrUnpack%s(); \n\t\t\t\tbreak;' % func_name
275
276print """
277 case CR_EXTEND_OPCODE:
278 #ifdef CR_UNPACK_DEBUG_OPCODES
279 crUnpackExtendDbg();
280 #else
281 # ifdef CR_UNPACK_DEBUG_LAST_OPCODES
282 if (i==(num_opcodes-1)) crUnpackExtendDbg();
283 else
284 # endif
285 crUnpackExtend();
286 #endif
287 break;
288 case CR_CMDBLOCKBEGIN_OPCODE:
289 case CR_CMDBLOCKEND_OPCODE:
290 case CR_NOP_OPCODE:
291 INCR_DATA_PTR_NO_ARGS( );
292 break;
293 default:
294 crError( "Unknown opcode: %d", *unpack_opcodes );
295 break;
296 }
297
298 CRDBGPTR_CHECKZ(writeback_ptr);
299 CRDBGPTR_CHECKZ(return_ptr);
300
301 unpack_opcodes--;
302 }
303}"""
304
305
306#
307# Emit unpack functions for extended opcodes, non-special functions only.
308#
309for func_name in keys:
310 if ("extpack" in apiutil.ChromiumProps(func_name)
311 and not apiutil.FindSpecial("unpacker", func_name)):
312 return_type = apiutil.ReturnType(func_name)
313 params = apiutil.Parameters(func_name)
314 print 'static void crUnpackExtend%s(void)' % func_name
315 print '{'
316 MakeNormalCall( return_type, func_name, params, 8 )
317 print '}\n'
318
319print 'static void crUnpackExtend(void)'
320print '{'
321print '\tGLenum extend_opcode = %s;' % ReadData( 4, 'GLenum' );
322print ''
323print '\t/*crDebug(\"Unpacking extended opcode \%d", extend_opcode);*/'
324print '\tswitch( extend_opcode )'
325print '\t{'
326
327
328#
329# Emit switch statement for extended opcodes
330#
331for func_name in keys:
332 if "extpack" in apiutil.ChromiumProps(func_name):
333 print '\t\tcase %s:' % apiutil.ExtendedOpcodeName( func_name )
334# print '\t\t\t\tcrDebug("Unpack: %s");' % apiutil.ExtendedOpcodeName( func_name )
335 print '\t\t\tcrUnpackExtend%s( );' % func_name
336 print '\t\t\tbreak;'
337
338print """ default:
339 crError( "Unknown extended opcode: %d", (int) extend_opcode );
340 break;
341 }
342 INCR_VAR_PTR();
343}"""
344
345print 'static void crUnpackExtendDbg(void)'
346print '{'
347print '\tGLenum extend_opcode = %s;' % ReadData( 4, 'GLenum' );
348print ''
349print '\t/*crDebug(\"Unpacking extended opcode \%d", extend_opcode);*/'
350print '\tswitch( extend_opcode )'
351print '\t{'
352
353
354#
355# Emit switch statement for extended opcodes
356#
357for func_name in keys:
358 if "extpack" in apiutil.ChromiumProps(func_name):
359 print '\t\tcase %s:' % apiutil.ExtendedOpcodeName( func_name )
360 if not apiutil.ExtendedOpcodeName(func_name) in nodebug_extopcodes:
361 print '\t\t\tcrDebug("Unpack: %s");' % apiutil.ExtendedOpcodeName( func_name )
362 print '\t\t\tcrUnpackExtend%s( );' % func_name
363 print '\t\t\tbreak;'
364
365print """ default:
366 crError( "Unknown extended opcode: %d", (int) extend_opcode );
367 break;
368 }
369 INCR_VAR_PTR();
370}"""
Note: See TracBrowser for help on using the repository browser.

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