def wrap_struct(functionName): params = apiutil.Parameters(functionName) argstring = apiutil.MakeDeclarationString(params) extendedArgstring = argstring props = apiutil.Properties(functionName) if "useclient" in props or "pixelstore" in props: extendedArgstring += ", CRClientState *c" # We'll keep track of all the parameters that require pointers. # They'll require special handling later. (pointers, pointername, pointerarg, pointertype, pointersize, pointercomment) = GetPointerInfo(functionName) # Start writing the header print 'struct instance%s {' % (functionName) print ' DLMInstanceList *next;' print ' DLMInstanceList *stateNext;' print ' int cbInstance;' print ' VBoxDLOpCode iVBoxOpCode;' print ' void (DLM_APIENTRY *execute)(DLMInstanceList *instance, SPUDispatchTable *dispatchTable);' for (name, type, vecSize) in params: # Watch out for the word "const" (which should be ignored) # and for types that end in "*" (which are pointers and need # special treatment) words = type.split() if words[0] == 'const': words = words[1:] if words[0] != "void": print ' %s %s;' % (' '.join(words), name) # If any argument was a pointer, we need a special pointer data # array. The pointer data will be stored into this array, and # references to the array will be generated as parameters. if len(pointers) == 1: if pointersize == None: print " /* Oh no - pointer parameter %s found, but no pointer class specified and can't guess */" % pointername else: if pointersize == 'special': print ' %s %s[1];%s' % (pointertype, pointerarg, pointercomment) else: print ' %s %s[%s];%s' % (pointertype, pointerarg, pointersize, pointercomment) elif len(pointers) > 1: print ' %s %s[1];%s' % (pointertype, pointerarg, pointercomment) print '};' # Pointers only happen with instances if len(pointers) > 1 or (len(pointers) == 1 and pointersize == 'special'): print 'int crdlm_pointers_%s(struct instance%s *instance, %s);' % ( functionName, functionName, extendedArgstring) # See if the GL function must sometimes allow passthrough even # if the display list is open if "checklist" in apiutil.ChromiumProps(functionName): print 'int crdlm_checklist_%s(%s);' % (functionName, argstring) return
def PrintGet(record): argList = apiutil.MakeDeclarationString(record.params) if record.category == "Chromium": prefix = "cr" else: prefix = "gl" if 'get' in record.props: print '%s %s%s(%s);' % (record.returnType, prefix, record.name, argList )
def PrintRecord(record): argList = apiutil.MakeDeclarationString(record.params) if record.category == "Chromium": prefix = "cr" else: prefix = "gl" print '%s %s%s(%s);' % (record.returnType, prefix, record.name, argList ) if len(record.props) > 0: print ' /* %s */' % string.join(record.props, ' ')
def PrintEnum(record): paramList = apiutil.MakeDeclarationString(record.params) if record.category == "Chromium": prefix = "cr" else: prefix = "gl" for (name, type, vecSize) in record.params: if type == "GLenum" : for i in range(len(record.paramprop)): (name,enums) = record.paramprop[i] print 'name = %s' % name print 'enums = %s' % enums
def GenerateNop(func_name): return_type = apiutil.ReturnType(func_name); params = apiutil.Parameters(func_name) print 'static %s GLLOADER_APIENTRY Nop%s(%s)' % (return_type, func_name, apiutil.MakeDeclarationString(params)) print '{' for (name, type, vecSize) in params: if name != "": print '\t(void) %s;' % name if apiutil.ReturnType(func_name) != 'void': print '\treturn 0;' print '}' print ''
def EmitFunctions(): offset = 0 for func_name in keys: retType = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print 'static ' + retType + ' APIHISTOGRAMSPU_APIENTRY' print 'histo' + func_name + '(' + apiutil.MakeDeclarationString( params) + ')' print '{' print '\tHistogram[' + str(offset) + '].count++;' if retType != 'void': print '\treturn ' print '\tapihistogram_spu.super.' + func_name + '(' + apiutil.MakeCallString( params) + ');' print '}' print '' offset += 1 return
def PrintDynProto(func_name, f): if apiutil.FindSpecial( "packertest", func_name ): return if not allfuncs: if not apiutil.HasPackOpcode(func_name): return pointers_ok = 0 params = apiutil.Parameters(func_name) if "Chromium" == apiutil.Category(func_name): is_extended = 1 else: is_extended = 0 if is_extended: f.write( "typedef %s (APIENTRY *gl%s_t) (%s);\n" % (return_type,func_name,apiutil.MakeDeclarationString(params))) f.write( "static gl%s_t %s_func;\n" % (func_name,func_name))
apiutil.CopyrightC() print """ #include <stdio.h> #include "cr_server.h" #include "cr_packfunctions.h" #include "replicatespu.h" """ for func_name in keys: return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) if (apiutil.FindSpecial( "replicatespu_state", func_name ) or apiutil.FindSpecial( "replicatespu_get", func_name)): print 'extern %s REPLICATESPU_APIENTRY replicatespu_%s( %s );' % ( return_type, func_name, apiutil.MakeDeclarationString( params ) ) for func_name in keys: return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) if (apiutil.FindSpecial( "replicatespu_state", func_name ) or apiutil.FindSpecial( "replicatespu_get", func_name)): print '%s REPLICATESPU_APIENTRY replicatespu_%s( %s )' % ( return_type, func_name, apiutil.MakeDeclarationString( params ) ) print '{' if apiutil.FindSpecial( "replicatespu_state", func_name ): print '\tif (replicate_spu.swap)' print '\t{' print '\t\tcrPack%sSWAP( %s );' % (func_name, apiutil.MakeCallString( params ) ) print '\t}' print '\telse' print '\t{' print '\t\tcrPack%s( %s );' % (func_name, apiutil.MakeCallString( params ) )
def GenerateEntrypoints(hacks=[]): """Emit code for all the OpenGL/Chromium entrypoints. hacks is an optional list of functions which are special cased. """ apiutil.CopyrightC() print('#define GL_GLEXT_PROTOTYPES') print('#include <stdio.h>') print('#include <stdlib.h>') print('#include <GL/gl.h>') print('#include "chromium.h"') print('#include "stub.h"') print('#include "dri_glx.h"') print('') print('#ifdef __GNUC__') print('# if (__GNUC__ << 16) + __GNUC_MINOR__ >= 0x40002') print('# pragma GCC diagnostic ignored "-Wunused-parameter"') print('# endif') print('#endif') # Get sorted list of dispatched functions. # The order is very important - it must match cr_opcodes.h # and spu_dispatch_table.h keys = apiutil.GetDispatchedFunctions(sys.argv[1] + "/APIspec.txt") for index in range(len(keys)): func_name = keys[index] if apiutil.Category(func_name) == "Chromium": # this function is defined in stub.c continue return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) if func_name in hacks: print("/* hacked entrypoint: %s */" % func_name) if func_name == "TexImage3D": # Pretty common: internalformat is GLenum, not GLint print( "void glTexImage3D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels )" ) print("{") print( "\tglim.TexImage3D( target, level, (GLint) internalformat, width, height, depth, border, format, type, pixels );" ) print("}") elif func_name == "TexImage2D": # Pretty common: internalformat is GLenum, not GLint print( "void glTexImage2D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )" ) print("{") print( "\tglim.TexImage2D( target, level, (GLint) internalformat, width, height, border, format, type, pixels );" ) print("}") elif func_name == "TexImage1D": # Pretty common: internalformat is GLenum, not GLint print( "void glTexImage1D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels )" ) print("{") print( "\tglim.TexImage1D( target, level, (GLint) internalformat, width, border, format, type, pixels );" ) print("}") elif func_name == "EdgeFlagPointer": # second arg is GLboolean instead of GLvoid print( "void glEdgeFlagPointer( GLsizei stride, const GLboolean *pointer )" ) print("{") print("\tglim.EdgeFlagPointer( stride, pointer );") print("}") elif func_name == "ProgramParameters4fvNV": print( "void glProgramParameters4fvNV( GLenum target, GLuint index, GLuint num, const GLfloat *params )" ) print("{") print( "\tglim.ProgramParameters4fvNV( target, index, num, params );" ) print("}") elif func_name == "MultiDrawElementsEXT": print( "void glMultiDrawElementsEXT(GLenum mode, GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount)" ) print("{") print( "\tglim.MultiDrawElementsEXT(mode, count,type, indices, primcount);" ) print("}") elif func_name == "ProgramParameters4dvNV": print( "void glProgramParameters4dvNV( GLenum target, GLuint index, GLuint num, const GLdouble *params )" ) print("{") print( "\tglim.ProgramParameters4dvNV( target, index, num, params );" ) print("}") else: # the usual path print("%s VBOXGLTAG(gl%s)(%s);" % (return_type, func_name, apiutil.MakeDeclarationString(params))) print("") print("%s VBOXGLTAG(gl%s)(%s)" % (return_type, func_name, apiutil.MakeDeclarationString(params))) print("{") print("\t", end="") if return_type != "void": print("return ", end=" ") print("glim.%s(%s);" % (func_name, apiutil.MakeCallString(params))) print("}") print("") print('/*') print('* Aliases') print('*/') # Now loop over all the functions and take care of any aliases allkeys = apiutil.GetAllFunctions(sys.argv[1] + "/APIspec.txt") for func_name in allkeys: if "omit" in apiutil.ChromiumProps(func_name): continue if func_name in keys: # we already processed this function earlier continue # alias is the function we're aliasing alias = apiutil.Alias(func_name) if alias: if func_name in hacks: print("/* hacked entrypoint: %s */" % func_name) if func_name == "MultiDrawArrays": print( "void glMultiDrawArrays( GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount )" ) print("{") print( "\tglim.MultiDrawArraysEXT( mode, (GLint*)first, (GLsizei*)count, primcount );" ) print("}") elif func_name == "BufferData": print( "void glBufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage)" ) print("{") print("\tglim.BufferDataARB(target, size, data, usage);") print("}") elif func_name == "BufferSubData": print( "void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data)" ) print("{") print( "\tglim.BufferSubDataARB(target, offset, size, data);") print("}") elif func_name == "GetBufferSubData": print( "void glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data)" ) print("{") print( "\tglim.GetBufferSubDataARB(target, offset, size, data);" ) print("}") else: return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print("%s VBOXGLTAG(gl%s)(%s);" % (return_type, func_name, apiutil.MakeDeclarationString(params))) print("") print("%s VBOXGLTAG(gl%s)(%s)" % (return_type, func_name, apiutil.MakeDeclarationString(params))) print("{") print("\t", end="") if return_type != "void": print("return ", end=" ") print("glim.%s(%s);" % (alias, apiutil.MakeCallString(params))) print("}") print("") print('/*') print('* No-op stubs') print('*/') # Now generate no-op stub functions for func_name in allkeys: if "stub" in apiutil.ChromiumProps(func_name): return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print("%s VBOXGLTAG(gl%s)(%s);" % (return_type, func_name, apiutil.MakeDeclarationString(params))) print("") print("%s VBOXGLTAG(gl%s)(%s)" % (return_type, func_name, apiutil.MakeDeclarationString(params))) print("{") if return_type != "void": print("return (%s) 0" % return_type) print("}") print("")
print """ #ifndef HIDDENLINE_SPU_PROTO_H #define HIDDENLINE_SPU_PROTO_H 1 """ keys = apiutil.GetDispatchedFunctions("../../glapi_parser/APIspec.txt") # Determine which functions to ignore ignore_functions = [] for func_name in keys: if ("get" in apiutil.Properties(func_name) or "setclient" in apiutil.Properties(func_name) or "useclient" in apiutil.Properties(func_name) or apiutil.Category(func_name) == "Chromium" or apiutil.Category(func_name) == "GL_chromium"): ignore_functions.append(func_name) specials = apiutil.AllSpecials( "hiddenline" ) + apiutil.AllSpecials( "hiddenline_pixel" ) # emit prototypes for func_name in specials: return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print 'extern %s HIDDENLINESPU_APIENTRY hiddenlinespu_%s(%s);' % (return_type, func_name, apiutil.MakeDeclarationString(params)) print """ #endif """
'GetTexGeniv': 'SWAP32', 'GetTexLevelParameterfv': 'SWAPFLOAT', 'GetTexLevelParameteriv': 'SWAP32', 'GetTexParameterfv': 'SWAPFLOAT', 'GetTexParameteriv': 'SWAP32' } keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt") for func_name in keys: params = apiutil.Parameters(func_name) return_type = apiutil.ReturnType(func_name) if apiutil.FindSpecial( "packspu", func_name ): continue if "get" in apiutil.Properties(func_name): print('%s PACKSPU_APIENTRY packspu_%s(%s)' % ( return_type, func_name, apiutil.MakeDeclarationString( params ) )) print('{') print('\tGET_THREAD(thread);') print('\tint writeback = 1;') if return_type != 'void': print('\t%s return_val = (%s) 0;' % (return_type, return_type)) params.append( ("&return_val", "foo", 0) ) if (func_name in easy_swaps and easy_swaps[func_name] != '0') or func_name in simple_funcs or func_name in hard_funcs: print('\tunsigned int i;') print('\tif (!CRPACKSPU_IS_WDDM_CRHGSMI() && !(pack_spu.thread[pack_spu.idxThreadInUse].netServer.conn->actual_network))') print('\t{') print('\t\tcrError( "packspu_%s doesn\'t work when there\'s no actual network involved!\\nTry using the simplequery SPU in your chain!" );' % func_name) print('\t}') if func_name in simple_funcs: print(""" if (crPackIsPixelStoreParm(pname)
def wrap_compile(functionName): params = apiutil.Parameters(functionName) return_type = apiutil.ReturnType(functionName) # Make sure the return type is void. It's nonsensical to compile # an element with any other return type. if return_type != 'void': print '/* Nonsense: DL function %s has a %s return type?!? */' % ( functionName, return_type) # Define a structure to hold all the parameters. Note that the # top parameters must exactly match the DLMInstanceList structure # in include/cr_dlm.h, or everything will break horribly. # Start off by getting all the pointer info we could ever use # from the parameters (pointers, pointername, pointerarg, pointertype, pointersize, pointercomment) = GetPointerInfo(functionName) # Finally, the compile wrapper. This one will diverge strongly # depending on whether or not there are pointer parameters. callstring = apiutil.MakeCallString(params) argstring = apiutil.MakeDeclarationString(params) props = apiutil.Properties(functionName) if "useclient" in props or "pixelstore" in props: callstring += ", c" argstring += ", CRClientState *c" print 'void DLM_APIENTRY crDLMCompile%s(%s)' % (functionName, argstring) print '{' print ' CRDLMContextState *state = CURRENT_STATE();' print ' struct instance%s *instance;' % (functionName) # The calling SPU is supposed to verify that the element is supposed to be # compiled before it is actually compiled; typically, this is done based # on whether a glNewList has been executed more recently than a glEndList. # But some functions are dual-natured, sometimes being compiled, and sometimes # being executed immediately. We can check for this here. if "checklist" in apiutil.ChromiumProps(functionName): print ' if (crDLMCheckList%s(%s))' % ( functionName, apiutil.MakeCallString(params)) print ' {' print ' crdlm_error(__LINE__, __FILE__, GL_INVALID_OPERATION,' print ' "this instance of function %s should not be compiled");' % functionName print ' return;' print ' }' if len(pointers) > 1 or pointersize == 'special': # Pass NULL, to just allocate space print ' instance = crCalloc(sizeof(struct instance%s) + crdlm_pointers_%s(NULL, %s));' % ( functionName, functionName, callstring) else: print ' instance = crCalloc(sizeof(struct instance%s));' % ( functionName) print ' if (!instance)' print ' {' print ' crdlm_error(__LINE__, __FILE__, GL_OUT_OF_MEMORY,' print ' "out of memory adding %s to display list");' % ( functionName) print ' return;' print ' }' # Put in the fields that must always exist print ' instance->execute = execute%s;' % functionName # Apply all the simple (i.e. non-pointer) parameters for index in range(len(params)): if index not in pointers: name = params[index][0] print ' instance->%s = %s;' % (name, name) # We need to know instance size in bytes in order to save its state later. print ' instance->cbInstance = sizeof(struct instance%s);' % functionName # Set OPCODE. print ' instance->iVBoxOpCode = VBOX_DL_OPCODE_%s;' % functionName # If there's a pointer parameter, apply it. if len(pointers) == 1: print ' if (%s == NULL)' % (params[pointers[0]][0]) print ' instance->%s = NULL;' % (params[pointers[0]][0]) print ' else' print ' instance->%s = instance->%s;' % (params[pointers[0]][0], pointerarg) if pointersize == 'special': print ' instance->cbInstance += crdlm_pointers_%s(instance, %s);' % ( functionName, callstring) else: print ' crMemcpy((void *)instance->%s, (void *) %s, %s*sizeof(%s));' % ( params[pointers[0]][0], params[pointers[0]][0], pointersize, pointertype) elif len(pointers) == 2: # this seems to work print ' instance->cbInstance += crdlm_pointers_%s(instance, %s);' % ( functionName, callstring) elif len(pointers) > 2: print "#error don't know how to handle pointer parameters for %s" % ( functionName) # Add the element to the current display list AddInstanceToList(' ') # If the element is a state-changing element, add it to the current state list if apiutil.SetsTrackedState(functionName): AddInstanceToStateList(' ') print '}'
from __future__ import print_function import sys import apiutil apiutil.CopyrightC() print(""" /* DO NOT EDIT - this file generated by packspu_flush.py script */ /* These are otherwise ordinary functions which require that the buffer be * flushed immediately after packing the function. */ #include "cr_glstate.h" #include "cr_packfunctions.h" #include "packspu.h" #include "packspu_proto.h" """) keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt") for func_name in apiutil.AllSpecials( "packspu_flush" ): params = apiutil.Parameters(func_name) print('void PACKSPU_APIENTRY packspu_%s(%s)' % ( func_name, apiutil.MakeDeclarationString(params))) print('{') print('\tGET_THREAD(thread);') print('\tcrPack%s(%s);' % ( func_name, apiutil.MakeCallString( params ) )) print('\tpackspuFlush( (void *) thread );') print('}\n')
# OK, generate a crPackFooBar() prototype for this function return_type = apiutil.ReturnType(func_name) args = apiutil.Parameters(func_name) if return_type != 'void': if apiutil.IsPointer(return_type): args.append(("return_value", return_type, 0)) else: args.append(("return_value", return_type + "*", 0)) elif "pixelstore" in apiutil.Properties(func_name): args.append(("packstate", "const CRPixelPackState *", 0)) if "get" in apiutil.Properties(func_name): args.append(("writeback", "int *", 0)) print 'void PACK_APIENTRY crPack%s( %s );' % ( func_name, apiutil.MakeDeclarationString(args)) print 'void PACK_APIENTRY crPack%sSWAP( %s );' % ( func_name, apiutil.MakeDeclarationString(args)) # Now generate special BBOX, COUNT, SWAP variations on the glVertex and # glVertexAttrib functions. for func_name in keys: if (func_name[0:6] == "Vertex" and "pervertex" in apiutil.Properties(func_name) and ("pack" in apiutil.ChromiumProps(func_name) or apiutil.NonVectorFunction(func_name) != '')): assert apiutil.ReturnType(func_name) == "void" args = apiutil.Parameters(func_name) print 'void PACK_APIENTRY crPack%sBBOX(%s);' % (
"DrawRangeElements" ] keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt") for func_name in keys: if "Chromium" == apiutil.Category(func_name): continue if func_name == "BoundsInfoCR": continue return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) if func_name in commoncall_special: print "%s vboxDD_gl%s( %s )" % (return_type, func_name, apiutil.MakeDeclarationString(params) ) else: if apiutil.MakeDeclarationString(params)=="void": print "%s vboxDD_gl%s( GLcontext *ctx )" % (return_type, func_name ) else: print "%s vboxDD_gl%s( GLcontext *ctx, %s )" % (return_type, func_name, apiutil.MakeDeclarationString(params) ) print "{" if return_type != "void": print "\treturn ", print "\tcr_gl%s( %s );" % (func_name, apiutil.MakeCallString(params)) print "}" print ""
apiutil.CopyrightC() print(""" /* DO NOT EDIT - THIS FILE GENERATED BY THE tsfuncs.py SCRIPT */ #include "stub.h" """) keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt") for func_name in keys: return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print("static %s SPULOAD_APIENTRY ts_%s(%s)" % (return_type, func_name, apiutil.MakeDeclarationString(params) )) print("{") print("\tSPUDispatchTable *tab = (SPUDispatchTable *) crGetTSD(&stub.dispatchTSD);") if return_type != "void": print("\treturn ", end=" ") print("\ttab->%s(%s);" % (func_name, apiutil.MakeCallString(params))) print("}") print("") print("SPUDispatchTable stubThreadsafeDispatch = {") for func_name in keys: print("\tts_%s," % func_name)
# All rights reserved. # # See the file LICENSE.txt for information on redistributing this software. import sys sys.path.append( "../glapi_parser" ) import apiutil apiutil.CopyrightC() print """ #include "cr_server.h" #include "feedbackspu.h" #include "feedbackspu_proto.h" """ keys = apiutil.GetDispatchedFunctions("../glapi_parser/APIspec.txt") for func_name in keys: if apiutil.FindSpecial( "feedback_state", func_name ): return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print '%s FEEDBACKSPU_APIENTRY feedbackspu_%s( %s )' % (return_type, func_name, apiutil.MakeDeclarationString(params)) print '{' print '\tcrState%s( %s );' % (func_name, apiutil.MakeCallString(params)) print '' print '\tfeedback_spu.super.%s( %s );' % (func_name, apiutil.MakeCallString(params)) print '}'
"EvalMesh2", "Rectf", "DrawArrays", "DrawElements", "DrawRangeElements" ] # Extern-like declarations keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt") for func_name in keys: if "Chromium" == apiutil.Category(func_name): continue if func_name == "BoundsInfoCR": continue return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) if func_name in commoncall_special: print "extern %s vboxDD_gl%s( %s );" % (return_type, func_name, apiutil.MakeDeclarationString( params )) else: if apiutil.MakeDeclarationString(params)=="void": print "extern %s vboxDD_gl%s( GLcontext *ctx );" % (return_type, func_name) else: print "extern %s vboxDD_gl%s( GLcontext *ctx, %s );" % (return_type, func_name, apiutil.MakeDeclarationString( params )) print "#endif /* __DD_GL_H__ */"
#include <stdio.h> #include "cr_spu.h" #include "feedbackspu.h" #include "feedbackspu_proto.h" #include "cr_packfunctions.h" #include "cr_glstate.h" """) keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt") for func_name in keys: return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) if apiutil.FindSpecial( "feedback", func_name ): print('static %s FEEDBACKSPU_APIENTRY feedbackspu_%s(%s)' % ( return_type, func_name, apiutil.MakeDeclarationString(params) )) print('{') print('\tfeedback_spu.super.%s(%s);' % ( func_name, apiutil.MakeCallString(params) )) print('}') print('') print('static %s FEEDBACKSPU_APIENTRY feedbackspu_FeedbackWrap%s(%s)' % ( return_type, func_name, apiutil.MakeDeclarationString(params) )) print('{') if len(params) == 0: print('\tcrStateFeedback%s(&feedback_spu.StateTracker);' % ( func_name, )) else: print('\tcrStateFeedback%s(&feedback_spu.StateTracker, %s);' % ( func_name, apiutil.MakeCallString(params) )) print('}') if apiutil.FindSpecial( "select", func_name ): print('static %s FEEDBACKSPU_APIENTRY feedbackspu_SelectWrap%s(%s)' % ( return_type, func_name, apiutil.MakeDeclarationString(params) )) print('{') if len(params) == 0:
pack_specials = [] keys = apiutil.GetDispatchedFunctions("../glapi_parser/APIspec.txt") # make list of special functions ## VMGL: Because of state resume, a few more functions have specialized ## implementations by the new autogen script for func_name in keys: if ("get" in apiutil.Properties(func_name) or apiutil.FindSpecial("packspu", func_name) or apiutil.FindSpecial("packspu_flush", func_name) or apiutil.FindSpecial("packspu_vertex", func_name) or apiutil.CanCompile(func_name) or apiutil.SetsTrackedState(func_name)): pack_specials.append(func_name) for func_name in keys: if apiutil.FindSpecial("packspu_unimplemented", func_name): continue if func_name in pack_specials: return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print 'extern %s PACKSPU_APIENTRY packspu_%s( %s );' % ( return_type, func_name, apiutil.MakeDeclarationString(params)) print """ #endif """
""" keys = apiutil.GetDispatchedFunctions("../glapi_parser/APIspec.txt") ## We will use the state tracker diff infrastructure to push OpenGL ## state to the new GL stub upon resume. Once computedd differences, ## the Diff Dispatch Table is invoked to perform whatever action you ## want on the diffed state. In our case, we simply want to send ## the state to new GL stub. This script generates s Diff Dispatch ## Table that does just that. It's exceedingly simple for non-pixel ## functions. We need to hack a default packing when shipping pixel ## functions calls. for func_name in apiutil.AllSpecials( "packspu_diffpixel" ): return_type = apiutil.ReturnType(func_name) decl = apiutil.MakeDeclarationString(apiutil.Parameters(func_name)) print 'extern %s PACKSPU_APIENTRY packspu_Diff%s( %s );' % ( return_type, func_name, decl ) print '\n' for func_name in apiutil.AllSpecials( "packspu_diffpixel" ): return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print '%s PACKSPU_APIENTRY packspu_Diff%s( %s )' % (return_type, func_name, apiutil.MakeDeclarationString( params ) ) print '{' params.append( ('&defaultPacking', 'blah', 0) ) print '\tif (pack_spu.swap)' print '\t{' print '\t\tcrPack%sSWAP( %s );' % (func_name, apiutil.MakeCallString( params ) ) print '\t}' print '\telse'
def GenerateEntrypoints(): apiutil.CopyrightC() print '#include "chromium.h"' print '#include "stub.h"' print '' print '#define NAKED __declspec(naked)' print '#define UNUSED(x) ((void)(x))' print '' # Get sorted list of dispatched functions. # The order is very important - it must match cr_opcodes.h # and spu_dispatch_table.h keys = apiutil.GetDispatchedFunctions(sys.argv[1] + "/APIspec.txt") for index in range(len(keys)): func_name = keys[index] if apiutil.Category(func_name) == "Chromium": continue if apiutil.Category(func_name) == "VBox": continue return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print "NAKED %s cr_gl%s( %s )" % ( return_type, func_name, apiutil.MakeDeclarationString(params)) print "{" print "\t__asm jmp [glim.%s]" % func_name for (name, type, vecSize) in params: print "\tUNUSED( %s );" % name print "}" print "" print '/*' print '* Aliases' print '*/' # Now loop over all the functions and take care of any aliases allkeys = apiutil.GetAllFunctions(sys.argv[1] + "/APIspec.txt") for func_name in allkeys: if "omit" in apiutil.ChromiumProps(func_name): continue if func_name in keys: # we already processed this function earlier continue # alias is the function we're aliasing alias = apiutil.Alias(func_name) if alias: return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print "NAKED %s cr_gl%s( %s )" % ( return_type, func_name, apiutil.MakeDeclarationString(params)) print "{" print "\t__asm jmp [glim.%s]" % alias for (name, type, vecSize) in params: print "\tUNUSED( %s );" % name print "}" print "" print '/*' print '* No-op stubs' print '*/' # Now generate no-op stub functions for func_name in allkeys: if "stub" in apiutil.ChromiumProps(func_name): return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print "NAKED %s cr_gl%s( %s )" % ( return_type, func_name, apiutil.MakeDeclarationString(params)) print "{" if return_type != "void": print "return (%s) 0" % return_type print "}" print ""
# Continue with functions that are auto-generated. if mode == 'header': print print "/* auto-generated compilation functions begin here */" for func_name in keys: props = apiutil.Properties(func_name) # We're interested in intercepting all calls that: # - can be put into a display list (i.e. "not ("nolist" in props)") # - change client-side state that affects saving DL elements (i.e. "setclient" in props) if apiutil.CanCompile(func_name): params = apiutil.Parameters(func_name) argstring = apiutil.MakeDeclarationString(params) if "useclient" in props or "pixelstore" in props: argstring = argstring + ", CRClientState *c" if mode == 'header': print 'extern void DLM_APIENTRY crDLMCompile%s(%s);' % (func_name, argstring) elif mode == 'defs': print "crDLMCompile%s" % func_name # Next make declarations for all the checklist functions. if mode == 'header': print """ /* auto-generated CheckList functions begin here. There is one for each * function that has a dual nature: even when there's an active glNewList, * sometimes they are compiled into the display list, and sometimes they
# Extern-like declarations keys = apiutil.GetAllFunctions("../glapi_parser/APIspec.txt") for func_name in keys: if "Chromium" == apiutil.Category(func_name): continue if func_name == "BoundsInfoCR": continue if "GL_chromium" == apiutil.Category(func_name): pass #continue return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print "%s cr_gl%s( %s );" % (return_type, func_name, apiutil.MakeDeclarationString(params)) print """ struct name_address { const char *name; CR_PROC address; }; static struct name_address functions[] = { """ keys = apiutil.GetAllFunctions("../glapi_parser/APIspec.txt") for func_name in keys: if "Chromium" == apiutil.Category(func_name): continue if func_name == "BoundsInfoCR":
#include "cr_unpack.h" CRCurrentStatePointers crServerCurrent; """) for func_name in apiutil.AllSpecials(sys.argv[1] + "/../state_tracker/state"): params = apiutil.Parameters(func_name) if (apiutil.FindSpecial("server", func_name) or "get" in apiutil.Properties(func_name)): continue wrap = apiutil.GetCategoryWrapper(func_name) if wrap: print('#if defined(CR_%s)' % wrap) print('void SERVER_DISPATCH_APIENTRY crServerDispatch%s(%s)' % (func_name, apiutil.MakeDeclarationString(params))) print('{') print('\tcrState%s(%s);' % (func_name, apiutil.MakeCallString(params))) print('\tcr_server.head_spu->dispatch_table.%s(%s);' % (func_name, apiutil.MakeCallString(params))) print('}') if wrap: print('#endif') keys = apiutil.GetDispatchedFunctions(sys.argv[1] + "/APIspec.txt") for func_name in keys: current = 0 array = "" condition = "" m = re.search(r"^(Color|Normal)([1234])(ub|b|us|s|ui|i|f|d)$", func_name) if m:
def PrintFunction(func_name, extSuffix, num_coords, argtype, do_swapped, do_count, do_vector): """ Generate all the functions named crPackVertex[234][dfis][v]BBOX() and crPackVertex[234][dfis][v]BBOX_COUNT(). We also handle glVertexAttrib*ARB. Note: func_name should not have an ARB suffix. """ if do_count: countSuffix = "_COUNT" else: countSuffix = "" if do_swapped: swapSuffix = "SWAP" else: swapSuffix = "" if func_name[0:12] == "VertexAttrib": isVertexAttrib = 1 else: isVertexAttrib = 0 if argtype[0] == "N": normalized = 1 else: normalized = 0 if argtype == "b" or argtype == "Nb": vector_type = "GLbyte" elif argtype == "ub" or argtype == "Nub": vector_type = "GLubyte" elif argtype == "s" or argtype == "Ns": vector_type = "GLshort" elif argtype == "us" or argtype == "Nus": vector_type = "GLushort" elif argtype == "i" or argtype == "Ni": vector_type = "GLint" elif argtype == "ui" or argtype == "Nui": vector_type = "GLuint" elif argtype == "f": vector_type = "GLfloat" elif argtype == "d": vector_type = "GLdouble" else: print "type is %s" % argtype abort() if do_vector: if isVertexAttrib: func_name = 'VertexAttrib%d%sv' % (num_coords, argtype) else: func_name = 'Vertex%d%sv' % (num_coords, argtype) params = apiutil.Parameters(func_name + extSuffix) print 'void PACK_APIENTRY crPack%sBBOX%s%s( %s )' % ( func_name + extSuffix, countSuffix, swapSuffix, apiutil.MakeDeclarationString(params)) print '{' if do_vector: # vector version packet_length = num_coords * apiutil.sizeof(vector_type) if isVertexAttrib: packet_length += 4 # for index if packet_length % 4 != 0: packet_length += 2 else: # non-vector packet_length = apiutil.PacketLength(params) if isVertexAttrib: packet_length += 0 # for index if packet_length % 4 != 0: packet_length += 2 print "\tGET_PACKER_CONTEXT(pc);" print "\tunsigned char *data_ptr;" if normalized: if argtype == "Nb": t = "B" elif argtype == "Ni": t = "I" elif argtype == "Nui": t = "UI" elif argtype == "Nub": t = "UB" elif argtype == "Ns": t = "S" elif argtype == "Nus": t = "US" else: abort() if do_vector: print "\tCREATE_%dD_VFLOATS_%s_NORMALIZED();" % (num_coords, t) else: print "\tCREATE_%dD_FLOATS_%s_NORMALIZED();" % (num_coords, t) else: if do_vector: print "\tCREATE_%dD_VFLOATS();" % num_coords else: print "\tCREATE_%dD_FLOATS();" % num_coords print "\tGET_BUFFERED%s_POINTER( pc, %d );" % (countSuffix, packet_length) # Bounding box code if isVertexAttrib: print "\tif (pc->updateBBOX && index == 0)" else: print "\tif (pc->updateBBOX)" print "\t{" if num_coords < 4: print "\t\tUPDATE_%dD_BBOX();" % num_coords else: print "\t\tUPDATE_3D_BBOX();" print "\t}" if isVertexAttrib: print "\tif (index > 0) {" t = argtype print "\t\tpc->current.c.vertexAttrib.%s%d[index] = data_ptr + 4;" % ( t, num_coords) print "\t\tpc->current.attribsUsedMask |= (1 << index);" if do_count: print "\t\tpc->current.vtx_count--;" print "\t}" fname = func_name + extSuffix if do_vector: # use non-vector opcode opcode = apiutil.OpcodeName(func_name[:-1] + extSuffix) else: opcode = apiutil.OpcodeName(func_name + extSuffix) counter = 0 if do_vector: if isVertexAttrib: if do_swapped: print "\tWRITE_DATA( 0, GLuint, SWAP32(index) );" else: print "\tWRITE_DATA( 0, GLuint, index );" counter += 4 argname = params[1][0] # skip 'index' parameter else: argname = params[0][0] for index in range(num_coords): print WriteData(counter, vector_type, "%s[%d]" % (argname, index), do_swapped) counter += apiutil.sizeof(vector_type) if isVertexAttrib: if do_vector == 2: # this is a bit of a hack print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName( func_name + "ARB") else: print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName( func_name[:-1] + "ARB") else: print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName( func_name[:-1]) else: for index in range(0, len(params)): (name, type, vecSize) = params[index] print WriteData(counter, type, name, do_swapped) counter += apiutil.sizeof(type) if isVertexAttrib: print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName(func_name + "ARB") else: print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName(func_name) print '}\n'
#endif #include "chromium.h" #include "state/cr_statetypes.h" #if defined(__cplusplus) extern "C" { #endif """) keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt") for func_name in keys: if ("get" in apiutil.Properties(func_name) or apiutil.FindSpecial( "server", func_name ) or apiutil.FindSpecial( sys.argv[1]+"/../state_tracker/state", func_name )): params = apiutil.Parameters(func_name) return_type = apiutil.ReturnType(func_name) print('%s SERVER_DISPATCH_APIENTRY crServerDispatch%s(%s);' % (return_type, func_name, apiutil.MakeDeclarationString( params ))) print(""" #if defined(__cplusplus) } #endif #endif /* SERVER_DISPATCH_HEADER */ """)
def PrintFunc(func_name, params, is_swapped, can_have_pointers): """Emit a packer function.""" if is_swapped: print 'void PACK_APIENTRY crPack%sSWAP( %s )' % ( func_name, apiutil.MakeDeclarationString(params)) else: print 'void PACK_APIENTRY crPack%s( %s )' % ( func_name, apiutil.MakeDeclarationString(params)) print '{' print '\tGET_PACKER_CONTEXT(pc);' # Save original function name orig_func_name = func_name # Convert to a non-vector version of the function if possible func_name = apiutil.NonVectorFunction(func_name) if not func_name: func_name = orig_func_name # Check if there are any pointer parameters. # That's usually a problem so we'll emit an error function. nonVecParams = apiutil.Parameters(func_name) bail_out = 0 for (name, type, vecSize) in nonVecParams: if apiutil.IsPointer(type) and vecSize == 0 and not can_have_pointers: bail_out = 1 if bail_out: for (name, type, vecSize) in nonVecParams: print '\t(void)%s;' % (name) print '\tcrError ( "%s needs to be special cased %d %d!");' % ( func_name, vecSize, can_have_pointers) print '\t(void) pc;' print '}' # XXX we should really abort here return if "extpack" in apiutil.ChromiumProps(func_name): is_extended = 1 else: is_extended = 0 print "\tunsigned char *data_ptr;" print '\t(void) pc;' #if func_name == "Enable" or func_name == "Disable": # print "\tCRASSERT(!pc->buffer.geometry_only); /* sanity check */" packet_length = apiutil.PacketLength(nonVecParams) if packet_length == 0 and not is_extended: print "\tGET_BUFFERED_POINTER_NO_ARGS( pc );" elif func_name[:9] == "Translate" or func_name[:5] == "Color": # XXX WTF is the purpose of this? if is_extended: packet_length += 8 print "\tGET_BUFFERED_POINTER_NO_BEGINEND_FLUSH( pc, %d );" % packet_length else: if is_extended: packet_length += 8 print "\tGET_BUFFERED_POINTER( pc, %d );" % packet_length UpdateCurrentPointer(func_name) if is_extended: counter = 8 print WriteData(0, 'GLint', packet_length, is_swapped) print WriteData(4, 'GLenum', apiutil.ExtendedOpcodeName(func_name), is_swapped) else: counter = 0 # Now emit the WRITE_() macros for all parameters for index in range(0, len(params)): (name, type, vecSize) = params[index] # if we're converting a vector-valued function to a non-vector func: if vecSize > 0 and func_name != orig_func_name: ptrType = apiutil.PointerType(type) for i in range(0, vecSize): print WriteData(counter + i * apiutil.sizeof(ptrType), ptrType, "%s[%d]" % (name, i), is_swapped) # XXX increment counter here? else: print WriteData(counter, type, name, is_swapped) if apiutil.IsPointer(type): counter += apiutil.PointerSize() else: counter += apiutil.sizeof(type) # finish up if is_extended: print "\tWRITE_OPCODE( pc, CR_EXTEND_OPCODE );" else: print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName(func_name) print '}\n'
#include "cr_mem.h" #include "cr_net.h" #include "server_dispatch.h" #include "server.h" """ from get_sizes import *; funcs = [ 'GetIntegerv', 'GetFloatv', 'GetDoublev', 'GetBooleanv' ] types = [ 'GLint', 'GLfloat', 'GLdouble', 'GLboolean' ] for index in range(len(funcs)): func_name = funcs[index] params = apiutil.Parameters(func_name) print 'void SERVER_DISPATCH_APIENTRY crServerDispatch%s( %s )' % ( func_name, apiutil.MakeDeclarationString(params)) print '{' print '\t%s *get_values;' % types[index] print '\tint tablesize;' print """ #ifdef CR_ARB_texture_compression if (GL_COMPRESSED_TEXTURE_FORMATS_ARB == pname) { GLint numtexfmts = 0; cr_server.head_spu->dispatch_table.GetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, &numtexfmts); tablesize = numtexfmts * sizeof(%s); } else #endif { tablesize = __numValues( pname ) * sizeof(%s);
"VertexAttrib1fvARB", "VertexAttrib2fARB", "VertexAttrib2fvARB", "VertexAttrib3fARB", "VertexAttrib3fvARB", "VertexAttrib4fARB", "VertexAttrib4fvARB", "EvalMesh1", "EvalMesh2", "Rectf", "DrawArrays", "DrawElements", "DrawRangeElements" ] # Extern-like declarations keys = apiutil.GetDispatchedFunctions(sys.argv[1] + "/APIspec.txt") for func_name in keys: if "Chromium" == apiutil.Category(func_name): continue if func_name == "BoundsInfoCR": continue return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) if func_name in commoncall_special: print "extern %s vboxDD_gl%s( %s );" % ( return_type, func_name, apiutil.MakeDeclarationString(params)) else: if apiutil.MakeDeclarationString(params) == "void": print "extern %s vboxDD_gl%s( GLcontext *ctx );" % (return_type, func_name) else: print "extern %s vboxDD_gl%s( GLcontext *ctx, %s );" % ( return_type, func_name, apiutil.MakeDeclarationString(params)) print "#endif /* __DD_GL_H__ */"