Changeset 20813 in vbox
- Timestamp:
- Jun 23, 2009 10:19:57 AM (15 years ago)
- File:
-
- 1 edited
-
trunk/src/VBox/GuestHost/OpenGL/packer/packer.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/OpenGL/packer/packer.py
r15532 r20813 13 13 14 14 def WriteData( offset, arg_type, arg_name, is_swapped ): 15 """Return a string to write a variable to the packing buffer."""16 retval = 917 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 039 return retval15 """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 40 41 41 42 42 def 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 return50 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 return58 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 return66 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 return74 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 return82 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 return90 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 return98 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 fields106 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 return43 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 110 111 111 112 112 113 113 def 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 '\tGET_PACKER_CONTEXT(pc);'121 122 # Save original function name123 orig_func_name = func_name124 125 # Convert to a non-vector version of the function if possible126 func_name = apiutil.NonVectorFunction( func_name )127 if not func_name:128 func_name = orig_func_name129 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 = 0134 for (name, type, vecSize) in nonVecParams:135 if apiutil.IsPointer(type) and vecSize == 0 and not can_have_pointers:136 bail_out = 1137 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 here144 return145 146 if "extpack" in apiutil.ChromiumProps(func_name):147 is_extended = 1148 else:149 is_extended = 0150 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 packet_length = apiutil.PacketLength(nonVecParams)158 159 if packet_length == 0 and not is_extended:160 print "\tGET_BUFFERED_POINTER_NO_ARGS( pc );"161 elif func_name[:9] == "Translate" or func_name[:5] == "Color":162 # XXX WTF is the purpose of this?163 if is_extended:164 packet_length += 8165 print "\tGET_BUFFERED_POINTER_NO_BEGINEND_FLUSH( pc, %d );" % packet_length166 else:167 if is_extended:168 packet_length += 8169 print "\tGET_BUFFERED_POINTER( pc, %d );" % packet_length170 UpdateCurrentPointer( func_name )171 172 if is_extended:173 counter = 8174 print WriteData( 0, 'GLint', packet_length, is_swapped )175 print WriteData( 4, 'GLenum', apiutil.ExtendedOpcodeName( func_name ), is_swapped )176 else:177 counter = 0178 179 # Now emit the WRITE_() macros for all parameters180 for index in range(0,len(params)):181 (name, type, vecSize) = params[index]182 # if we're converting a vector-valued function to a non-vector func:183 if vecSize > 0 and func_name != orig_func_name:184 ptrType = apiutil.PointerType(type)185 for i in range(0, vecSize):186 print WriteData( counter + i * apiutil.sizeof(ptrType),187 ptrType, "%s[%d]" % (name, i), is_swapped )188 # XXX increment counter here?189 else:190 print WriteData( counter, type, name, is_swapped )191 if apiutil.IsPointer(type):192 counter += apiutil.PointerSize()193 else:194 counter += apiutil.sizeof(type)195 196 # finish up197 if is_extended:198 print "\tWRITE_OPCODE( pc, CR_EXTEND_OPCODE );"199 else:200 print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName( func_name )201 print '}\n'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 '\tGET_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 packet_length = apiutil.PacketLength(nonVecParams) 158 159 if packet_length == 0 and not is_extended: 160 print "\tGET_BUFFERED_POINTER_NO_ARGS( pc );" 161 elif func_name[:9] == "Translate" or func_name[:5] == "Color": 162 # XXX WTF is the purpose of this? 163 if is_extended: 164 packet_length += 8 165 print "\tGET_BUFFERED_POINTER_NO_BEGINEND_FLUSH( pc, %d );" % packet_length 166 else: 167 if is_extended: 168 packet_length += 8 169 print "\tGET_BUFFERED_POINTER( pc, %d );" % packet_length 170 UpdateCurrentPointer( func_name ) 171 172 if is_extended: 173 counter = 8 174 print WriteData( 0, 'GLint', packet_length, is_swapped ) 175 print WriteData( 4, 'GLenum', apiutil.ExtendedOpcodeName( func_name ), is_swapped ) 176 else: 177 counter = 0 178 179 # Now emit the WRITE_() macros for all parameters 180 for index in range(0,len(params)): 181 (name, type, vecSize) = params[index] 182 # if we're converting a vector-valued function to a non-vector func: 183 if vecSize > 0 and func_name != orig_func_name: 184 ptrType = apiutil.PointerType(type) 185 for i in range(0, vecSize): 186 print WriteData( counter + i * apiutil.sizeof(ptrType), 187 ptrType, "%s[%d]" % (name, i), is_swapped ) 188 # XXX increment counter here? 189 else: 190 print WriteData( counter, type, name, is_swapped ) 191 if apiutil.IsPointer(type): 192 counter += apiutil.PointerSize() 193 else: 194 counter += apiutil.sizeof(type) 195 196 # finish up 197 if is_extended: 198 print "\tWRITE_OPCODE( pc, CR_EXTEND_OPCODE );" 199 else: 200 print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName( func_name ) 201 print '}\n' 202 202 203 203 … … 222 222 223 223 for func_name in keys: 224 if apiutil.FindSpecial( "packer", func_name ):225 continue226 227 if not apiutil.HasPackOpcode(func_name):228 continue229 230 pointers_ok = 0231 232 return_type = apiutil.ReturnType(func_name)233 params = apiutil.Parameters(func_name)234 235 if return_type != 'void':236 # Yet another gross hack for glGetString237 if string.find( return_type, '*' ) == -1:238 return_type = return_type + " *"239 params.append(("return_value", return_type, 0))240 241 if "get" in apiutil.Properties(func_name):242 pointers_ok = 1243 params.append(("writeback", "int *", 0))244 245 if func_name == 'Writeback':246 pointers_ok = 1247 248 PrintFunc( func_name, params, 0, pointers_ok )249 PrintFunc( func_name, params, 1, pointers_ok )224 if apiutil.FindSpecial( "packer", func_name ): 225 continue 226 227 if not apiutil.HasPackOpcode(func_name): 228 continue 229 230 pointers_ok = 0 231 232 return_type = apiutil.ReturnType(func_name) 233 params = apiutil.Parameters(func_name) 234 235 if return_type != 'void': 236 # Yet another gross hack for glGetString 237 if string.find( return_type, '*' ) == -1: 238 return_type = return_type + " *" 239 params.append(("return_value", return_type, 0)) 240 241 if "get" in apiutil.Properties(func_name): 242 pointers_ok = 1 243 params.append(("writeback", "int *", 0)) 244 245 if func_name == 'Writeback': 246 pointers_ok = 1 247 248 PrintFunc( func_name, params, 0, pointers_ok ) 249 PrintFunc( func_name, params, 1, pointers_ok )
Note:
See TracChangeset
for help on using the changeset viewer.

