X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=wrappers%2Fgltrace.py;h=7bf2a3507a4169dec9b56c8ef5cdcf055fb09408;hb=0b5b75e507df681260ea9c43b142ee48fff780c5;hp=cf84ac56a4c05212ac2d4a7486c89c88152c3460;hpb=151c370e340598cc2279e14e4513fa3247add12a;p=apitrace diff --git a/wrappers/gltrace.py b/wrappers/gltrace.py index cf84ac5..7bf2a35 100644 --- a/wrappers/gltrace.py +++ b/wrappers/gltrace.py @@ -329,9 +329,21 @@ class GlTracer(Tracer): Tracer.traceApi(self, api) print 'static %s _wrapProcAddress(%s procName, %s procPtr) {' % (retType, argType, retType) + + # Provide fallback functions to missing debug functions print ' if (!procPtr) {' - print ' return procPtr;' + else_ = '' + for function_name in self.debug_functions: + if self.api.getFunctionByName(function_name): + print ' %sif (strcmp("%s", (const char *)procName) == 0) {' % (else_, function_name) + print ' return (%s)&%s;' % (retType, function_name) + print ' }' + else_ = 'else ' + print ' %s{' % else_ + print ' return NULL;' + print ' }' print ' }' + for function in api.getAllFunctions(): ptype = function_pointer_type(function) pvalue = function_pointer_value(function) @@ -357,7 +369,7 @@ class GlTracer(Tracer): print ' }' print print ' GLint buffer_binding = 0;' - print ' _glGetIntegerv(target, &buffer_binding);' + print ' _glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &buffer_binding);' print ' if (buffer_binding > 0) {' print ' gltrace::Buffer & buf = ctx->buffers[buffer_binding];' print ' buf.getSubData(offset, size, data);' @@ -684,6 +696,8 @@ class GlTracer(Tracer): Tracer.traceFunctionImplBody(self, function) + # These entrypoints are only expected to be implemented by tools; + # drivers will probably not implement them. marker_functions = [ # GL_GREMEDY_string_marker 'glStringMarkerGREMEDY', @@ -695,17 +709,55 @@ class GlTracer(Tracer): 'glPopGroupMarkerEXT', ] + # These entrypoints may be implemented by drivers, but are also very useful + # for debugging / analysis tools. + debug_functions = [ + # GL_KHR_debug + 'glDebugMessageControl', + 'glDebugMessageInsert', + 'glDebugMessageCallback', + 'glGetDebugMessageLog', + 'glPushDebugGroup', + 'glPopDebugGroup', + 'glObjectLabel', + 'glGetObjectLabel', + 'glObjectPtrLabel', + 'glGetObjectPtrLabel', + # GL_ARB_debug_output + 'glDebugMessageControlARB', + 'glDebugMessageInsertARB', + 'glDebugMessageCallbackARB', + 'glGetDebugMessageLogARB', + # GL_AMD_debug_output + 'glDebugMessageEnableAMD', + 'glDebugMessageInsertAMD', + 'glDebugMessageCallbackAMD', + 'glGetDebugMessageLogAMD', + ] + def invokeFunction(self, function): if function.name in ('glLinkProgram', 'glLinkProgramARB'): # These functions have been dispatched already return + Tracer.invokeFunction(self, function) + + def doInvokeFunction(self, function): + # Same as invokeFunction() but called both when trace is enabled or disabled. + # + # Used to modify the behavior of GL entry-points. + + # Override GL extensions + if function.name in ('glGetString', 'glGetIntegerv', 'glGetStringi'): + Tracer.doInvokeFunction(self, function, prefix = 'gltrace::_', suffix = '_override') + return + # We implement GL_EXT_debug_marker, GL_GREMEDY_*, etc., and not the # driver if function.name in self.marker_functions: return - if function.name in ('glXGetProcAddress', 'glXGetProcAddressARB', 'wglGetProcAddress'): + if function.name in self.getProcAddressFunctionNames: else_ = '' for marker_function in self.marker_functions: if self.api.getFunctionByName(marker_function): @@ -714,16 +766,19 @@ class GlTracer(Tracer): print ' }' else_ = 'else ' print ' %s{' % else_ - Tracer.invokeFunction(self, function) - print ' }' - return + Tracer.doInvokeFunction(self, function) - # Override GL extensions - if function.name in ('glGetString', 'glGetIntegerv', 'glGetStringi'): - Tracer.invokeFunction(self, function, prefix = 'gltrace::_', suffix = '_override') + # Replace function addresses with ours + # XXX: Doing this here instead of wrapRet means that the trace will + # contain the addresses of the wrapper functions, and not the real + # functions, but in practice this should make no difference. + if function.name in self.getProcAddressFunctionNames: + print ' _result = _wrapProcAddress(%s, _result);' % (function.args[0].name,) + + print ' }' return - Tracer.invokeFunction(self, function) + Tracer.doInvokeFunction(self, function) buffer_targets = [ 'ARRAY_BUFFER', @@ -742,10 +797,6 @@ class GlTracer(Tracer): def wrapRet(self, function, instance): Tracer.wrapRet(self, function, instance) - # Replace function addresses with ours - if function.name in self.getProcAddressFunctionNames: - print ' %s = _wrapProcAddress(%s, %s);' % (instance, function.args[0].name, instance) - # Keep track of buffer mappings if function.name in ('glMapBuffer', 'glMapBufferARB'): print ' struct buffer_mapping *mapping = get_buffer_mapping(target);'