CRDBGPTR_CHECKNZ(&cr_server.return_ptr); crMemcpy( &(rb->writeback_ptr), &(cr_server.writeback_ptr), sizeof( rb->writeback_ptr ) ); crMemcpy( &(rb->readback_ptr), &(cr_server.return_ptr), sizeof( rb->readback_ptr ) ); crMemcpy( rb+1, payload, payload_len ); crNetSend( cr_server.curClient->conn, NULL, rb, msg_len ); CRDBGPTR_SETZ(&cr_server.writeback_ptr); CRDBGPTR_SETZ(&cr_server.return_ptr); crFree( rb ); } """ 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("server", func_name): continue if "VBox" == apiutil.Category(func_name): continue if return_type != 'void': print '%s SERVER_DISPATCH_APIENTRY crServerDispatch%s( %s )' % ( return_type, func_name, apiutil.MakeDeclarationString(params)) print '{' print '\t%s retval;' % return_type print '\tretval = cr_server.head_spu->dispatch_table.%s( %s );' % ( func_name, apiutil.MakeCallString(params)) print '\tcrServerReturnValue( &retval, sizeof(retval) );' print '\treturn retval; /* WILL PROBABLY BE IGNORED */' print '}'
"packspu_vertex", func_name): continue if "get" in apiutil.Properties(func_name): continue # Ok, need to find out more about this function. Apiutil to our rescue # Initialize functionCouldDL = 0 functionUsesClientState = 0 functionTracksState = 0 functionPacks = apiutil.CanPack(func_name) functionFlushes = 0 functionReadsBack = 0 functionParamsString = apiutil.MakeCallString(params) packerParamsString = functionParamsString dlmParamsString = functionParamsString # If you can be compiled in a display list we'll have to check with DLM if apiutil.CanCompile(func_name): functionCouldDL = 1 # packspu_flush_special (barriers, semaphores) need to go right away if apiutil.FindSpecial("packspu_flush", func_name): functionFlushes = 1 # serverdependent functions are packed, sent immediately, # and a response is read if "serverdependent" in chromiumProps: functionPacks = 1
crWarning("Incorrect local state in %s for %%x param %%i", pname, i); crWarning("Expected %%i but got %%i", (int)localparams[i], (int)params[i]); } } crFree(localparams); return; } else #endif { crState%s(pname, params); return; } } """ % (params[-1][1], params[-1][1], func_name, func_name, apiutil.MakeCallString(params), func_name, func_name)) if func_name in vertattr_get_funcs: print(""" if (pname != GL_CURRENT_VERTEX_ATTRIB_ARB) { #ifdef DEBUG %s localparams; localparams = (%s) crAlloc(__numValues(pname) * sizeof(*localparams)); crState%s(index, pname, localparams); crPack%s(index, %s, &writeback); packspuFlush( (void *) thread ); CRPACKSPU_WRITEBACK_WAIT(thread, writeback); for (i=0; i<crStateHlpComponentsCount(pname); ++i) { if (localparams[i] != params[i])
print """ /* DO NOT EDIT - this file generated by replicatespu_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 "replicatespu.h" #include "replicatespu_proto.h" """ for func_name in apiutil.AllSpecials("replicatespu_flush"): return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print 'void REPLICATESPU_APIENTRY replicatespu_%s( %s )' % ( func_name, apiutil.MakeDeclarationString(params)) print '{' print '\tGET_THREAD(thread);' 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)) print '\t}' print '\treplicatespuFlush( (void *) thread );' print '}\n'
"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 ""
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("")
from __future__ import print_function import sys import apiutil apiutil.CopyrightC() print(""" #include "cr_server.h" #include "feedbackspu.h" #include "feedbackspu_proto.h" """) custom = ["CreateContext", "VBoxCreateContext", "MakeCurrent", "DestroyContext"] keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt") for func_name in keys: if apiutil.FindSpecial( "feedback_state", func_name ): if func_name in custom: continue 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('}')
crWarning("Expected %%i but got %%i", (int)localparams[i], (int)params[i]); } } crFree(localparams); return; } else #endif { crState%s(&pack_spu.StateTracker, pname, params); return; } } """ % (params[-1][1], params[-1][1], func_name, func_name, apiutil.MakeCallString(params), func_name, func_name)) if func_name in vertattr_get_funcs: print(""" if (pname != GL_CURRENT_VERTEX_ATTRIB_ARB) { #ifdef DEBUG %s localparams; localparams = (%s) crAlloc(__numValues(pname) * sizeof(*localparams)); crState%s(&pack_spu.StateTracker, index, pname, localparams); crPack%s(index, %s, &writeback); packspuFlush( (void *) thread ); CRPACKSPU_WRITEBACK_WAIT(thread, writeback); for (i=0; i<crStateHlpComponentsCount(pname); ++i) { if (localparams[i] != params[i])
# Skip this function if we have a non-generated implementation if apiutil.FindSpecial("replicate", func_name): print '/* %s not generated: special implementation exists */' % func_name lastWasComment = 1 continue # Also skip this function if there's a trivial implementation # (i.e. one that degenerates to solely the use of crPack functions) # Otherwise, generate the function body. # The outgoing call string is based on the parameters. State-based # functions and pixelstore-based functions will require extended # call strings. basicCallString = apiutil.MakeCallString(params) needDL = 0 needThread = 0 needClientState = 0 needFlush = 0 needTrackState = 0 needWriteback = 0 needPack = apiutil.CanPack(func_name) packCallString = basicCallString dlmCallString = basicCallString # Queries can either be handled by a pack/writeback, or by # a crState call, depending on whether the query is # server-dependent or not. if "serverdependent" in chromiumProps: needPack = 1
crWarning("Expected %%i but got %%i", (int)localparams[i], (int)params[i]); } } crFree(localparams); return; } else #endif { crState%s(pname, params); return; } } """ % (params[-1][1], params[-1][1], func_name, func_name, apiutil.MakeCallString(params), func_name, func_name) if func_name in vertattr_get_funcs: print """ if (pname != GL_CURRENT_VERTEX_ATTRIB_ARB) { #ifdef DEBUG %s localparams; localparams = (%s) crAlloc(__numValues(pname) * sizeof(*localparams)); crState%s(index, pname, localparams); crPack%s(index, %s, &writeback); packspuFlush( (void *) thread ); CRPACKSPU_WRITEBACK_WAIT(thread, writeback); for (i=0; i<crStateHlpComponentsCount(pname); ++i) { if (localparams[i] != params[i])
from get_components import *; keys = apiutil.GetDispatchedFunctions("../glapi_parser/APIspec.txt") for func_name in keys: #(return_type, arg_names, arg_types) = gl_mapping[func_name] if ("get" in apiutil.Properties(func_name) and apiutil.ReturnType(func_name) == "void" and not apiutil.FindSpecial( "server", func_name )): params = apiutil.Parameters(func_name) print 'void SERVER_DISPATCH_APIENTRY crServerDispatch%s( %s )' % (func_name, apiutil.MakeDeclarationString( params ) ) print '{' lastParam = params[-1] assert apiutil.IsPointer(lastParam[1]) local_argtype = apiutil.PointerType(lastParam[1]) local_argname = 'local_%s' % lastParam[0] print '\t%s %s[%d];' % ( local_argtype, local_argname, max_components[func_name] ) print '\t(void) %s;' % lastParam[0] params[-1] = (local_argname, local_argtype, 0) print '\tcr_server.head_spu->dispatch_table.%s( %s );' % ( func_name, apiutil.MakeCallString(params) ) if func_name in no_pnames: print '\tcrServerReturnValue( &(%s[0]), %d*sizeof(%s) );' % (local_argname, max_components[func_name], local_argtype ); else: print '\tcrServerReturnValue( &(%s[0]), lookupComponents(pname)*sizeof(%s) );' % (local_argname, local_argtype ); print '}\n'
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 '}'
print '\t\tpname == GL_PACK_ROW_LENGTH ||' print '\t\tpname == GL_PACK_SKIP_PIXELS ||' print '\t\tpname == GL_PACK_LSB_FIRST ||' print '\t\tpname == GL_PACK_SWAP_BYTES ||' print '#ifdef CR_OPENGL_VERSION_1_2' print '\t\tpname == GL_PACK_IMAGE_HEIGHT ||' print '#endif' print '\t\tpname == GL_PACK_SKIP_ROWS) {' print '\t\t\tcrState%s( pname, params );' % func_name print '\t\t\treturn;' print '\t}' params.append(("&writeback", "foo", 0)) print '\tif (pack_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)) print '\t}' print '\tpackspuFlush( (void *) thread );' print '\twhile (writeback)' print '\t\tcrNetRecv();' lastParamName = params[-2][0] if return_type != 'void': print '\tif (pack_spu.swap)' print '\t{' print '\t\treturn_val = (%s) SWAP32(return_val);' % return_type print '\t}'
CRCurrentStatePointers crServerCurrent; """ for func_name in apiutil.AllSpecials("../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() 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: current = 1 name = string.lower(m.group(1)[:1]) + m.group(1)[1:]
""" 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 ", print "\ttab->%s( %s );" % (func_name, apiutil.MakeCallString(params)) print "}" print "" print "SPUDispatchTable stubThreadsafeDispatch = {" for func_name in keys: print "\tts_%s," % func_name print "\tNULL, /* copyList */" print "\tNULL, /* copy_of */" print "\t0, /* mark */" print "\tNULL /* server */" print "};"
thread->BeginEndState = (thread->BeginEndState + 1) % 4; return; } break; } DoVertex(); } """ keys = apiutil.GetDispatchedFunctions("../glapi_parser/APIspec.txt") for func_name in apiutil.AllSpecials( "packspu_vertex" ): params = apiutil.Parameters(func_name) print 'void PACKSPU_APIENTRY packspu_%s( %s )' % ( func_name, apiutil.MakeDeclarationString(params) ) print '{' print '\tGET_THREAD(thread);' print '\n\t/* DLMs for state resume */' print '\tif (IN_DL(thread))' print '\t\tcrDLMCompile%s(%s);' % (func_name, apiutil.MakeCallString(params)) print '\t' print '\tif (pack_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 ) ) print '\t}' print '\tRunState();' print '}'