VirtualBox

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

Last change on this file since 52451 was 52451, checked in by vboxsync, 10 years ago

crOpenGL: command blocks flushing

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.9 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 uint8_t first;
214 uint8_t last;
215
216 if (!num_opcodes)
217 return CR_UNPACK_BUFFER_TYPE_GENERIC;
218
219 first = pu8Codes[0];
220 last = pu8Codes[1-(int)num_opcodes];
221
222 switch (last)
223 {
224 case CR_CMDBLOCKFLUSH_OPCODE:
225 return CR_UNPACK_BUFFER_TYPE_CMDBLOCK_FLUSH;
226 case CR_CMDBLOCKEND_OPCODE:
227 return (first == CR_CMDBLOCKBEGIN_OPCODE) ? CR_UNPACK_BUFFER_TYPE_GENERIC : CR_UNPACK_BUFFER_TYPE_CMDBLOCK_END;
228 default:
229 return (first != CR_CMDBLOCKBEGIN_OPCODE) ? CR_UNPACK_BUFFER_TYPE_GENERIC : CR_UNPACK_BUFFER_TYPE_CMDBLOCK_BEGIN;
230 }
231}
232
233void crUnpack( const void *data, const void *opcodes,
234 unsigned int num_opcodes, SPUDispatchTable *table )
235{
236 unsigned int i;
237 const unsigned char *unpack_opcodes;
238 if (table != cr_lastDispatch)
239 {
240 crSPUCopyDispatchTable( &cr_unpackDispatch, table );
241 cr_lastDispatch = table;
242 }
243
244 unpack_opcodes = (const unsigned char *)opcodes;
245 cr_unpackData = (const unsigned char *)data;
246
247#if defined(CR_UNPACK_DEBUG_OPCODES) || defined(CR_UNPACK_DEBUG_LAST_OPCODES)
248 crDebug("crUnpack: %d opcodes", num_opcodes);
249#endif
250
251 for (i = 0 ; i < num_opcodes ; i++)
252 {
253
254 CRDBGPTR_CHECKZ(writeback_ptr);
255 CRDBGPTR_CHECKZ(return_ptr);
256
257 /*crDebug(\"Unpacking opcode \%d\", *unpack_opcodes);*/
258 switch( *unpack_opcodes )
259 {"""
260
261#
262# Emit switch cases for all unextended opcodes
263#
264for func_name in keys:
265 if "pack" in apiutil.ChromiumProps(func_name):
266 print '\t\t\tcase %s:' % apiutil.OpcodeName( func_name )
267 if not apiutil.OpcodeName(func_name) in nodebug_opcodes:
268 print """
269#ifdef CR_UNPACK_DEBUG_LAST_OPCODES
270 if (i==(num_opcodes-1))
271#endif
272#if defined(CR_UNPACK_DEBUG_OPCODES) || defined(CR_UNPACK_DEBUG_LAST_OPCODES)
273 crDebug("Unpack: %s");
274#endif """ % apiutil.OpcodeName(func_name)
275 print '\t\t\t\tcrUnpack%s(); \n\t\t\t\tbreak;' % func_name
276
277print """
278 case CR_EXTEND_OPCODE:
279 #ifdef CR_UNPACK_DEBUG_OPCODES
280 crUnpackExtendDbg();
281 #else
282 # ifdef CR_UNPACK_DEBUG_LAST_OPCODES
283 if (i==(num_opcodes-1)) crUnpackExtendDbg();
284 else
285 # endif
286 crUnpackExtend();
287 #endif
288 break;
289 case CR_CMDBLOCKBEGIN_OPCODE:
290 case CR_CMDBLOCKEND_OPCODE:
291 case CR_CMDBLOCKFLUSH_OPCODE:
292 case CR_NOP_OPCODE:
293 INCR_DATA_PTR_NO_ARGS( );
294 break;
295 default:
296 crError( "Unknown opcode: %d", *unpack_opcodes );
297 break;
298 }
299
300 CRDBGPTR_CHECKZ(writeback_ptr);
301 CRDBGPTR_CHECKZ(return_ptr);
302
303 unpack_opcodes--;
304 }
305}"""
306
307
308#
309# Emit unpack functions for extended opcodes, non-special functions only.
310#
311for func_name in keys:
312 if ("extpack" in apiutil.ChromiumProps(func_name)
313 and not apiutil.FindSpecial("unpacker", func_name)):
314 return_type = apiutil.ReturnType(func_name)
315 params = apiutil.Parameters(func_name)
316 print 'static void crUnpackExtend%s(void)' % func_name
317 print '{'
318 MakeNormalCall( return_type, func_name, params, 8 )
319 print '}\n'
320
321print 'static void crUnpackExtend(void)'
322print '{'
323print '\tGLenum extend_opcode = %s;' % ReadData( 4, 'GLenum' );
324print ''
325print '\t/*crDebug(\"Unpacking extended opcode \%d", extend_opcode);*/'
326print '\tswitch( extend_opcode )'
327print '\t{'
328
329
330#
331# Emit switch statement for extended opcodes
332#
333for func_name in keys:
334 if "extpack" in apiutil.ChromiumProps(func_name):
335 print '\t\tcase %s:' % apiutil.ExtendedOpcodeName( func_name )
336# print '\t\t\t\tcrDebug("Unpack: %s");' % apiutil.ExtendedOpcodeName( func_name )
337 print '\t\t\tcrUnpackExtend%s( );' % func_name
338 print '\t\t\tbreak;'
339
340print """ default:
341 crError( "Unknown extended opcode: %d", (int) extend_opcode );
342 break;
343 }
344 INCR_VAR_PTR();
345}"""
346
347print 'static void crUnpackExtendDbg(void)'
348print '{'
349print '\tGLenum extend_opcode = %s;' % ReadData( 4, 'GLenum' );
350print ''
351print '\t/*crDebug(\"Unpacking extended opcode \%d", extend_opcode);*/'
352print '\tswitch( extend_opcode )'
353print '\t{'
354
355
356#
357# Emit switch statement for extended opcodes
358#
359for func_name in keys:
360 if "extpack" in apiutil.ChromiumProps(func_name):
361 print '\t\tcase %s:' % apiutil.ExtendedOpcodeName( func_name )
362 if not apiutil.ExtendedOpcodeName(func_name) in nodebug_extopcodes:
363 print '\t\t\tcrDebug("Unpack: %s");' % apiutil.ExtendedOpcodeName( func_name )
364 print '\t\t\tcrUnpackExtend%s( );' % func_name
365 print '\t\t\tbreak;'
366
367print """ default:
368 crError( "Unknown extended opcode: %d", (int) extend_opcode );
369 break;
370 }
371 INCR_VAR_PTR();
372}"""
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