X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=gltrace.py;h=a0d155e13388490d292e26d0cb7f4527a22f5bed;hb=b4a3d1495a5e92ba23bf463bcea34a6e75b55294;hp=af5714242e5a7a148a1befc4d928bd929000405b;hpb=8f34d34693077e6377a8e75ba537069ac368f35b;p=apitrace diff --git a/gltrace.py b/gltrace.py index af57142..a0d155e 100644 --- a/gltrace.py +++ b/gltrace.py @@ -27,10 +27,10 @@ """GL tracing generator.""" -import stdapi -import glapi -import glparams -from glxapi import glxapi +import specs.stdapi as stdapi +import specs.glapi as glapi +import specs.glparams as glparams +from specs.glxapi import glxapi from trace import Tracer, dump_instance @@ -233,25 +233,22 @@ class GlTracer(Tracer): print print 'static inline struct buffer_mapping *' print 'get_buffer_mapping(GLenum target) {' - print ' switch(target) {' + print ' switch (target) {' for target in self.buffer_targets: print ' case GL_%s:' % target print ' return & __%s_mapping;' % target.lower() print ' default:' - print ' OS::DebugMessage("apitrace: warning: unknown buffer target 0x%04X\\n", target);' + print ' os::DebugMessage("apitrace: warning: unknown buffer target 0x%04X\\n", target);' print ' return NULL;' print ' }' print '}' print - # Generate memcpy's signature - self.trace_function_decl(glapi.memcpy) - # Generate a helper function to determine whether a parameter name # refers to a symbolic value or not print 'static bool' print 'is_symbolic_pname(GLenum pname) {' - print ' switch(pname) {' + print ' switch (pname) {' for function, type, count, name in glparams.parameters: if type is glapi.GLenum: print ' case %s:' % name @@ -275,7 +272,7 @@ class GlTracer(Tracer): # Generate a helper function to know how many elements a parameter has print 'static size_t' print '__gl_param_size(GLenum pname) {' - print ' switch(pname) {' + print ' switch (pname) {' for function, type, count, name in glparams.parameters: if type is not None: print ' case %s: return %u;' % (name, count) @@ -285,7 +282,7 @@ class GlTracer(Tracer): print ' return num_compressed_texture_formats;' print ' }' print ' default:' - print r' OS::DebugMessage("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);' + print r' os::DebugMessage("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);' print ' return 1;' print ' }' print '}' @@ -330,12 +327,15 @@ class GlTracer(Tracer): 'glMultiDrawArrays', 'glMultiDrawElements', 'glDrawArraysInstanced', + "glDrawArraysInstancedBaseInstance", 'glDrawElementsInstanced', 'glDrawArraysInstancedARB', 'glDrawElementsInstancedARB', 'glDrawElementsBaseVertex', 'glDrawRangeElementsBaseVertex', 'glDrawElementsInstancedBaseVertex', + "glDrawElementsInstancedBaseInstance", + "glDrawElementsInstancedBaseVertexBaseInstance", 'glMultiDrawElementsBaseVertex', 'glDrawArraysIndirect', 'glDrawElementsIndirect', @@ -411,14 +411,14 @@ class GlTracer(Tracer): # Emit a fake function print ' {' - print ' static const Trace::FunctionSig &__sig = %s ? __glEnableClientState_sig : __glDisableClientState_sig;' % flag_name - print ' unsigned __call = __writer.beginEnter(&__sig);' - print ' __writer.beginArg(0);' + print ' static const trace::FunctionSig &__sig = %s ? __glEnableClientState_sig : __glDisableClientState_sig;' % flag_name + print ' unsigned __call = trace::localWriter.beginEnter(&__sig);' + print ' trace::localWriter.beginArg(0);' dump_instance(glapi.GLenum, enable_name) - print ' __writer.endArg();' - print ' __writer.endEnter();' - print ' __writer.beginLeave(__call);' - print ' __writer.endLeave();' + print ' trace::localWriter.endArg();' + print ' trace::localWriter.endEnter();' + print ' trace::localWriter.beginLeave(__call);' + print ' trace::localWriter.endLeave();' print ' }' print ' return;' @@ -439,14 +439,13 @@ class GlTracer(Tracer): self.emit_memcpy('mapping->map', 'mapping->map', 'mapping->length') print ' }' if function.name in ('glFlushMappedBufferRange', 'glFlushMappedBufferRangeAPPLE'): - # TODO: avoid copying [0, offset] bytes print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' print ' if (mapping) {' if function.name.endswith('APPLE'): print ' GLsizeiptr length = size;' print ' mapping->explicit_flush = true;' print ' //assert(offset + length <= mapping->length);' - self.emit_memcpy('mapping->map', 'mapping->map', 'offset + length') + self.emit_memcpy('(char *)mapping->map + offset', '(const char *)mapping->map + offset', 'length') print ' }' # FIXME: glFlushMappedNamedBufferRangeEXT @@ -459,7 +458,7 @@ class GlTracer(Tracer): Tracer.dispatch_function(self, function) print ' GLint active_attributes = 0;' print ' __glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &active_attributes);' - print ' for (GLuint attrib = 0; attrib < active_attributes; ++attrib) {' + print ' for (GLint attrib = 0; attrib < active_attributes; ++attrib) {' print ' GLint size = 0;' print ' GLenum type = 0;' print ' GLchar name[256];' @@ -477,7 +476,7 @@ class GlTracer(Tracer): Tracer.dispatch_function(self, function) print ' GLint active_attributes = 0;' print ' __glGetObjectParameterivARB(programObj, GL_OBJECT_ACTIVE_ATTRIBUTES_ARB, &active_attributes);' - print ' for (GLuint attrib = 0; attrib < active_attributes; ++attrib) {' + print ' for (GLint attrib = 0; attrib < active_attributes; ++attrib) {' print ' GLint size = 0;' print ' GLenum type = 0;' print ' GLcharARB name[256];' @@ -520,22 +519,27 @@ class GlTracer(Tracer): print ' }' return + # Override GL extensions + if function.name in ('glGetString', 'glGetIntegerv', 'glGetStringi'): + Tracer.dispatch_function(self, function, prefix = 'gltrace::__', suffix = '_override') + return + Tracer.dispatch_function(self, function) def emit_memcpy(self, dest, src, length): - print ' unsigned __call = __writer.beginEnter(&__memcpy_sig);' - print ' __writer.beginArg(0);' - print ' __writer.writeOpaque(%s);' % dest - print ' __writer.endArg();' - print ' __writer.beginArg(1);' - print ' __writer.writeBlob(%s, %s);' % (src, length) - print ' __writer.endArg();' - print ' __writer.beginArg(2);' - print ' __writer.writeUInt(%s);' % length - print ' __writer.endArg();' - print ' __writer.endEnter();' - print ' __writer.beginLeave(__call);' - print ' __writer.endLeave();' + print ' unsigned __call = trace::localWriter.beginEnter(&trace::memcpy_sig);' + print ' trace::localWriter.beginArg(0);' + print ' trace::localWriter.writeOpaque(%s);' % dest + print ' trace::localWriter.endArg();' + print ' trace::localWriter.beginArg(1);' + print ' trace::localWriter.writeBlob(%s, %s);' % (src, length) + print ' trace::localWriter.endArg();' + print ' trace::localWriter.beginArg(2);' + print ' trace::localWriter.writeUInt(%s);' % length + print ' trace::localWriter.endArg();' + print ' trace::localWriter.endEnter();' + print ' trace::localWriter.beginLeave(__call);' + print ' trace::localWriter.endLeave();' buffer_targets = [ 'ARRAY_BUFFER', @@ -547,16 +551,6 @@ class GlTracer(Tracer): def wrap_ret(self, function, instance): Tracer.wrap_ret(self, function, instance) - if function.name == 'glGetString': - print ' if (__result) {' - print ' switch (name) {' - print ' case GL_EXTENSIONS:' - print ' __result = gltrace::translateExtensionsString(__result);' - print ' break;' - print ' default:' - print ' break;' - print ' }' - print ' }' if function.name in ('glMapBuffer', 'glMapBufferARB'): print ' struct buffer_mapping *mapping = get_buffer_mapping(target);' @@ -637,15 +631,15 @@ class GlTracer(Tracer): print ' __glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &__element_array_buffer);' print ' if (!__element_array_buffer) {' if isinstance(arg.type, stdapi.Array): - print ' __writer.beginArray(%s);' % arg.type.length + print ' trace::localWriter.beginArray(%s);' % arg.type.length print ' for(GLsizei i = 0; i < %s; ++i) {' % arg.type.length - print ' __writer.beginElement();' - print ' __writer.writeBlob(%s[i], count[i]*__gl_type_size(type));' % (arg.name) - print ' __writer.endElement();' + print ' trace::localWriter.beginElement();' + print ' trace::localWriter.writeBlob(%s[i], count[i]*__gl_type_size(type));' % (arg.name) + print ' trace::localWriter.endElement();' print ' }' - print ' __writer.endArray();' + print ' trace::localWriter.endArray();' else: - print ' __writer.writeBlob(%s, count*__gl_type_size(type));' % (arg.name) + print ' trace::localWriter.writeBlob(%s, count*__gl_type_size(type));' % (arg.name) print ' } else {' Tracer.dump_arg_instance(self, function, arg) print ' }' @@ -660,7 +654,7 @@ class GlTracer(Tracer): print ' GLint __unpack_buffer = 0;' print ' __glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &__unpack_buffer);' print ' if (__unpack_buffer) {' - print ' __writer.writeOpaque(%s);' % arg.name + print ' trace::localWriter.writeOpaque(%s);' % arg.name print ' } else {' Tracer.dump_arg_instance(self, function, arg) print ' }' @@ -670,7 +664,7 @@ class GlTracer(Tracer): # Several GL state functions take GLenum symbolic names as # integer/floats; so dump the symbolic name whenever possible if function.name.startswith('gl') \ - and arg.type in (glapi.GLint, glapi.GLfloat) \ + and arg.type in (glapi.GLint, glapi.GLfloat, glapi.GLdouble) \ and arg.name == 'param': assert arg.index > 0 assert function.args[arg.index - 1].name == 'pname' @@ -698,7 +692,7 @@ class GlTracer(Tracer): binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name function = api.get_function_by_name(function_name) - print ' // %s' % function.name + print ' // %s' % function.prototype() self.array_trace_prolog(api, uppercase_name) self.array_prolog(api, uppercase_name) print ' if (__glIsEnabled(%s)) {' % enable_name @@ -718,19 +712,19 @@ class GlTracer(Tracer): # Emit a fake function self.array_trace_intermezzo(api, uppercase_name) - print ' unsigned __call = __writer.beginEnter(&__%s_sig);' % (function.name,) + print ' unsigned __call = trace::localWriter.beginEnter(&__%s_sig);' % (function.name,) for arg in function.args: assert not arg.output - print ' __writer.beginArg(%u);' % (arg.index,) + print ' trace::localWriter.beginArg(%u);' % (arg.index,) if arg.name != 'pointer': dump_instance(arg.type, arg.name) else: - print ' __writer.writeBlob((const void *)%s, __size);' % (arg.name) - print ' __writer.endArg();' + print ' trace::localWriter.writeBlob((const void *)%s, __size);' % (arg.name) + print ' trace::localWriter.endArg();' - print ' __writer.endEnter();' - print ' __writer.beginLeave(__call);' - print ' __writer.endLeave();' + print ' trace::localWriter.endEnter();' + print ' trace::localWriter.beginLeave(__call);' + print ' trace::localWriter.endLeave();' print ' }' print ' }' self.array_epilog(api, uppercase_name) @@ -755,7 +749,9 @@ class GlTracer(Tracer): else: SUFFIX = suffix function_name = 'glVertexAttribPointer' + suffix - print ' // %s' % function_name + function = api.get_function_by_name(function_name) + + print ' // %s' % function.prototype() print ' if (__vertex_attrib == VERTEX_ATTRIB%s) {' % SUFFIX if suffix == 'NV': print ' GLint __max_vertex_attribs = 16;' @@ -775,8 +771,6 @@ class GlTracer(Tracer): print ' __glGetVertexAttribiv%s(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING%s, &__binding);' % (suffix, SUFFIX) print ' if (!__binding) {' - function = api.get_function_by_name(function_name) - # Get the arguments via glGet* for arg in function.args[1:]: if suffix == 'NV': @@ -791,19 +785,19 @@ class GlTracer(Tracer): print ' size_t __size = __%s_size(%s, maxindex);' % (function.name, arg_names) # Emit a fake function - print ' unsigned __call = __writer.beginEnter(&__%s_sig);' % (function.name,) + print ' unsigned __call = trace::localWriter.beginEnter(&__%s_sig);' % (function.name,) for arg in function.args: assert not arg.output - print ' __writer.beginArg(%u);' % (arg.index,) + print ' trace::localWriter.beginArg(%u);' % (arg.index,) if arg.name != 'pointer': dump_instance(arg.type, arg.name) else: - print ' __writer.writeBlob((const void *)%s, __size);' % (arg.name) - print ' __writer.endArg();' + print ' trace::localWriter.writeBlob((const void *)%s, __size);' % (arg.name) + print ' trace::localWriter.endArg();' - print ' __writer.endEnter();' - print ' __writer.beginLeave(__call);' - print ' __writer.endLeave();' + print ' trace::localWriter.endEnter();' + print ' trace::localWriter.beginLeave(__call);' + print ' trace::localWriter.endLeave();' print ' }' print ' }' print ' }' @@ -825,7 +819,7 @@ class GlTracer(Tracer): print ' GLint max_texture_coords = 0;' print ' __glGetIntegerv(GL_MAX_TEXTURE_COORDS, &max_texture_coords);' print ' for (GLint unit = 0; unit < max_texture_coords; ++unit) {' - print ' GLenum texture = GL_TEXTURE0 + unit;' + print ' GLint texture = GL_TEXTURE0 + unit;' print ' __glClientActiveTexture(texture);' def array_trace_prolog(self, api, uppercase_name): @@ -859,15 +853,15 @@ class GlTracer(Tracer): self.fake_call(function, [texture]) def fake_call(self, function, args): - print ' unsigned __fake_call = __writer.beginEnter(&__%s_sig);' % (function.name,) + print ' unsigned __fake_call = trace::localWriter.beginEnter(&__%s_sig);' % (function.name,) for arg, instance in zip(function.args, args): assert not arg.output - print ' __writer.beginArg(%u);' % (arg.index,) + print ' trace::localWriter.beginArg(%u);' % (arg.index,) dump_instance(arg.type, instance) - print ' __writer.endArg();' - print ' __writer.endEnter();' - print ' __writer.beginLeave(__fake_call);' - print ' __writer.endLeave();' + print ' trace::localWriter.endArg();' + print ' trace::localWriter.endEnter();' + print ' trace::localWriter.beginLeave(__fake_call);' + print ' trace::localWriter.endLeave();'