VirtualBox

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

最後變更 在這個檔案從62863是 52570,由 vboxsync 提交於 10 年 前

crOpenGL: debugging

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

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