]> git.cworth.org Git - apitrace/blobdiff - gltrace.py
Implement getTime for OS X
[apitrace] / gltrace.py
index 8043e80544ea1d4ead9964ada0b2c13fee367299..2125ac302b3b43afb5d01d165f50222675cc4cfa 100644 (file)
@@ -31,7 +31,7 @@ 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
+from trace import Tracer
 
 
 class TypeGetter(stdapi.Visitor):
@@ -42,10 +42,10 @@ class TypeGetter(stdapi.Visitor):
         self.long_suffix = long_suffix
         self.ext_suffix = ext_suffix
 
-    def visit_const(self, const):
+    def visitConst(self, const):
         return self.visit(const.type)
 
-    def visit_alias(self, alias):
+    def visitAlias(self, alias):
         if alias.expr == 'GLboolean':
             if self.long_suffix:
                 suffix = 'Booleanv'
@@ -80,13 +80,13 @@ class TypeGetter(stdapi.Visitor):
         function_name = self.prefix + suffix + self.ext_suffix
         return function_name, arg_type
     
-    def visit_enum(self, enum):
+    def visitEnum(self, enum):
         return self.visit(glapi.GLint)
 
-    def visit_bitmask(self, bitmask):
+    def visitBitmask(self, bitmask):
         return self.visit(glapi.GLint)
 
-    def visit_opaque(self, pointer):
+    def visitOpaque(self, pointer):
         return self.prefix + 'Pointerv' + self.ext_suffix, 'GLvoid *'
 
 
@@ -112,19 +112,6 @@ class GlTracer(Tracer):
 
         print '#include "gltrace.hpp"'
         print
-        print 'enum tracer_context_profile {'
-        print '    PROFILE_COMPAT,'
-        print '    PROFILE_ES1,'
-        print '    PROFILE_ES2,'
-        print '};'
-        print
-        print 'struct tracer_context {'
-        print '    enum tracer_context_profile profile;'
-        print '    bool user_arrays;'
-        print '    bool user_arrays_arb;'
-        print '    bool user_arrays_nv;'
-        print '};'
-        print
         
         # Which glVertexAttrib* variant to use
         print 'enum vertex_attrib {'
@@ -133,15 +120,16 @@ class GlTracer(Tracer):
         print '    VERTEX_ATTRIB_NV,'
         print '};'
         print
-        print 'static tracer_context *__get_context(void)'
+        print 'gltrace::Context *'
+        print 'gltrace::getContext(void)'
         print '{'
         print '    // TODO return the context set by other APIs (GLX, EGL, and etc.)'
-        print '    static tracer_context __ctx = { PROFILE_COMPAT, false, false, false };'
+        print '    static gltrace::Context __ctx = { gltrace::PROFILE_COMPAT, false, false, false };'
         print '    return &__ctx;'
         print '}'
         print
         print 'static vertex_attrib __get_vertex_attrib(void) {'
-        print '    tracer_context *ctx = __get_context();'
+        print '    gltrace::Context *ctx = gltrace::getContext();'
         print '    if (ctx->user_arrays_arb || ctx->user_arrays_nv) {'
         print '        GLboolean __vertex_program = GL_FALSE;'
         print '        __glGetBooleanv(GL_VERTEX_PROGRAM_ARB, &__vertex_program);'
@@ -163,7 +151,7 @@ class GlTracer(Tracer):
         # Whether we need user arrays
         print 'static inline bool __need_user_arrays(void)'
         print '{'
-        print '    tracer_context *ctx = __get_context();'
+        print '    gltrace::Context *ctx = gltrace::getContext();'
         print '    if (!ctx->user_arrays) {'
         print '        return false;'
         print '    }'
@@ -171,9 +159,9 @@ class GlTracer(Tracer):
 
         for camelcase_name, uppercase_name in self.arrays:
             # in which profile is the array available?
-            profile_check = 'ctx->profile == PROFILE_COMPAT'
+            profile_check = 'ctx->profile == gltrace::PROFILE_COMPAT'
             if camelcase_name in self.arrays_es1:
-                profile_check = '(' + profile_check + ' || ctx->profile == PROFILE_ES1)';
+                profile_check = '(' + profile_check + ' || ctx->profile == gltrace::PROFILE_ES1)';
 
             function_name = 'gl%sPointer' % camelcase_name
             enable_name = 'GL_%s_ARRAY' % uppercase_name
@@ -194,7 +182,7 @@ class GlTracer(Tracer):
             print
 
         print '    // ES1 does not support generic vertex attributes'
-        print '    if (ctx->profile == PROFILE_ES1)'
+        print '    if (ctx->profile == gltrace::PROFILE_ES1)'
         print '        return false;'
         print
         print '    vertex_attrib __vertex_attrib = __get_vertex_attrib();'
@@ -319,6 +307,14 @@ class GlTracer(Tracer):
         print '}'
         print
 
+        # states such as GL_UNPACK_ROW_LENGTH are not available in GLES
+        print 'static inline bool'
+        print 'can_unpack_subimage(void) {'
+        print '    gltrace::Context *ctx = gltrace::getContext();'
+        print '    return (ctx->profile == gltrace::PROFILE_COMPAT);'
+        print '}'
+        print
+
     array_pointer_function_names = set((
         "glVertexPointer",
         "glNormalPointer",
@@ -398,19 +394,19 @@ class GlTracer(Tracer):
          'GL_T4F_C4F_N3F_V4F',
     ]
 
-    def trace_function_impl_body(self, function):
+    def traceFunctionImplBody(self, function):
         # Defer tracing of user array pointers...
         if function.name in self.array_pointer_function_names:
             print '    GLint __array_buffer = 0;'
             print '    __glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &__array_buffer);'
             print '    if (!__array_buffer) {'
-            print '        tracer_context *ctx = __get_context();'
+            print '        gltrace::Context *ctx = gltrace::getContext();'
             print '        ctx->user_arrays = true;'
             if function.name == "glVertexAttribPointerARB":
                 print '        ctx->user_arrays_arb = true;'
             if function.name == "glVertexAttribPointerNV":
                 print '        ctx->user_arrays_nv = true;'
-            self.dispatch_function(function)
+            self.invokeFunction(function)
 
             # And also break down glInterleavedArrays into the individual calls
             if function.name == 'glInterleavedArrays':
@@ -446,7 +442,7 @@ class GlTracer(Tracer):
                     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)
+                    self.serializeValue(glapi.GLenum, enable_name)
                     print '            trace::localWriter.endArg();'
                     print '            trace::localWriter.endEnter();'
                     print '            trace::localWriter.beginLeave(__call);'
@@ -465,11 +461,21 @@ class GlTracer(Tracer):
             print '    }'
         
         # Emit a fake memcpy on buffer uploads
-        if function.name in ('glUnmapBuffer', 'glUnmapBufferARB', ):
+        if function.name in ('glUnmapBuffer', 'glUnmapBufferARB', 'glUnmapBufferOES'):
             print '    struct buffer_mapping *mapping = get_buffer_mapping(target);'
             print '    if (mapping && mapping->write && !mapping->explicit_flush) {'
             self.emit_memcpy('mapping->map', 'mapping->map', 'mapping->length')
             print '    }'
+        if function.name == 'glUnmapNamedBufferEXT':
+            print '    GLint access = 0;'
+            print '    glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_ACCESS, &access);'
+            print '    if ((access & GL_MAP_WRITE_BIT) & !(access & GL_MAP_FLUSH_EXPLICIT_BIT)) {'
+            print '        GLvoid *map = NULL;'
+            print '        glGetNamedBufferPointervEXT(buffer, GL_BUFFER_MAP_POINTER, &map);'
+            print '        GLint length = 0;'
+            print '        glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_MAP_LENGTH, &length);'
+            self.emit_memcpy('map', 'map', 'length')
+            print '    }'
         if function.name in ('glFlushMappedBufferRange', 'glFlushMappedBufferRangeAPPLE'):
             print '    struct buffer_mapping *mapping = get_buffer_mapping(target);'
             print '    if (mapping) {'
@@ -479,7 +485,12 @@ class GlTracer(Tracer):
             print '        //assert(offset + length <= mapping->length);'
             self.emit_memcpy('(char *)mapping->map + offset', '(const char *)mapping->map + offset', 'length')
             print '    }'
-        # FIXME: glFlushMappedNamedBufferRangeEXT
+        if function.name == 'glFlushMappedNamedBufferRangeEXT':
+            print '    GLvoid *map = NULL;'
+            print '    glGetNamedBufferPointervEXT(buffer, GL_BUFFER_MAP_POINTER, &map);'
+            print '    if (map) {'
+            self.emit_memcpy('(char *)map + offset', '(const char *)map + offset', 'length')
+            print '    }'
 
         # Don't leave vertex attrib locations to chance.  Instead emit fake
         # glBindAttribLocation calls to ensure that the same locations will be
@@ -487,7 +498,7 @@ class GlTracer(Tracer):
         # be an herculian task given that vertex attrib locations appear in
         # many entry-points, including non-shader related ones.
         if function.name == 'glLinkProgram':
-            Tracer.dispatch_function(self, function)
+            Tracer.invokeFunction(self, function)
             print '    GLint active_attributes = 0;'
             print '    __glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &active_attributes);'
             print '    for (GLint attrib = 0; attrib < active_attributes; ++attrib) {'
@@ -505,7 +516,7 @@ class GlTracer(Tracer):
             print '        }'
             print '    }'
         if function.name == 'glLinkProgramARB':
-            Tracer.dispatch_function(self, function)
+            Tracer.invokeFunction(self, function)
             print '    GLint active_attributes = 0;'
             print '    __glGetObjectParameterivARB(programObj, GL_OBJECT_ACTIVE_ATTRIBUTES_ARB, &active_attributes);'
             print '    for (GLint attrib = 0; attrib < active_attributes; ++attrib) {'
@@ -523,68 +534,68 @@ class GlTracer(Tracer):
             print '        }'
             print '    }'
 
-        Tracer.trace_function_impl_body(self, function)
+        Tracer.traceFunctionImplBody(self, function)
 
-    gremedy_functions = [
+    marker_functions = [
+        # GL_GREMEDY_string_marker
         'glStringMarkerGREMEDY',
+        # GL_GREMEDY_frame_terminator
         'glFrameTerminatorGREMEDY',
+        # GL_EXT_debug_marker
+        'glInsertEventMarkerEXT',
+        'glPushGroupMarkerEXT',
+        'glPopGroupMarkerEXT',
     ]
 
-    def dispatch_function(self, function):
+    def invokeFunction(self, function):
         if function.name in ('glLinkProgram', 'glLinkProgramARB'):
             # These functions have been dispatched already
             return
 
-        # We implement the GREMEDY extensions, not the driver
-        if function.name in self.gremedy_functions:
+        # 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_ = 'if'
-            for gremedy_function in self.gremedy_functions:
-                print '    %s (strcmp("%s", (const char *)%s) == 0) {' % (if_, gremedy_function, function.args[0].name)
-                print '        __result = (%s)&%s;' % (function.type, gremedy_function)
-                print '    }'
-                if_ = 'else if'
-            print '    else {'
-            Tracer.dispatch_function(self, function)
+            else_ = ''
+            for marker_function in self.marker_functions:
+                if self.api.get_function_by_name(marker_function):
+                    print '    %sif (strcmp("%s", (const char *)%s) == 0) {' % (else_, marker_function, function.args[0].name)
+                    print '        __result = (%s)&%s;' % (function.type, marker_function)
+                    print '    }'
+                else_ = 'else '
+            print '    %s{' % else_
+            Tracer.invokeFunction(self, function)
             print '    }'
             return
 
         # Override GL extensions
         if function.name in ('glGetString', 'glGetIntegerv', 'glGetStringi'):
-            Tracer.dispatch_function(self, function, prefix = 'gltrace::__', suffix = '_override')
+            Tracer.invokeFunction(self, function, prefix = 'gltrace::__', suffix = '_override')
             return
 
-        Tracer.dispatch_function(self, function)
-
-    def emit_memcpy(self, dest, src, length):
-        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();'
-       
+        Tracer.invokeFunction(self, function)
+
     buffer_targets = [
         'ARRAY_BUFFER',
         'ELEMENT_ARRAY_BUFFER',
         'PIXEL_PACK_BUFFER',
         'PIXEL_UNPACK_BUFFER',
+        'UNIFORM_BUFFER',
+        'TEXTURE_BUFFER',
+        'TRANSFORM_FEEDBACK_BUFFER',
+        'COPY_READ_BUFFER',
+        'COPY_WRITE_BUFFER',
+        'DRAW_INDIRECT_BUFFER',
+        'ATOMIC_COUNTER_BUFFER',
     ]
 
-    def wrap_ret(self, function, instance):
-        Tracer.wrap_ret(self, function, instance)
+    def wrapRet(self, function, instance):
+        Tracer.wrapRet(self, function, instance)
 
             
-        if function.name in ('glMapBuffer', 'glMapBufferARB'):
+        if function.name in ('glMapBuffer', 'glMapBufferARB', 'glMapBufferOES'):
             print '    struct buffer_mapping *mapping = get_buffer_mapping(target);'
             print '    if (mapping) {'
             print '        mapping->map = %s;' % (instance)
@@ -657,7 +668,7 @@ class GlTracer(Tracer):
         'glTextureSubImage3DEXT',
     ])
 
-    def dump_arg_instance(self, function, arg):
+    def serializeArgValue(self, function, arg):
         if function.name in self.draw_function_names and arg.name == 'indices':
             print '    GLint __element_array_buffer = 0;'
             print '    __glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &__element_array_buffer);'
@@ -673,7 +684,7 @@ class GlTracer(Tracer):
             else:
                 print '        trace::localWriter.writeBlob(%s, count*__gl_type_size(type));' % (arg.name)
             print '    } else {'
-            Tracer.dump_arg_instance(self, function, arg)
+            Tracer.serializeArgValue(self, function, arg)
             print '    }'
             return
 
@@ -683,14 +694,14 @@ class GlTracer(Tracer):
                 or (isinstance(arg.type, stdapi.Const) \
                     and isinstance(arg.type.type, stdapi.Blob))):
             print '    {'
-            print '        tracer_context *ctx = __get_context();'
+            print '        gltrace::Context *ctx = gltrace::getContext();'
             print '        GLint __unpack_buffer = 0;'
-            print '        if (ctx->profile == PROFILE_COMPAT)'
+            print '        if (ctx->profile == gltrace::PROFILE_COMPAT)'
             print '            __glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &__unpack_buffer);'
             print '        if (__unpack_buffer) {'
             print '            trace::localWriter.writeOpaque(%s);' % arg.name
             print '        } else {'
-            Tracer.dump_arg_instance(self, function, arg)
+            Tracer.serializeArgValue(self, function, arg)
             print '        }'
             print '    }'
             return
@@ -704,13 +715,13 @@ class GlTracer(Tracer):
             assert function.args[arg.index - 1].name == 'pname'
             assert function.args[arg.index - 1].type == glapi.GLenum
             print '    if (is_symbolic_pname(pname) && is_symbolic_param(%s)) {' % arg.name
-            dump_instance(glapi.GLenum, arg.name)
+            self.serializeValue(glapi.GLenum, arg.name)
             print '    } else {'
-            Tracer.dump_arg_instance(self, function, arg)
+            Tracer.serializeArgValue(self, function, arg)
             print '    }'
             return
 
-        Tracer.dump_arg_instance(self, function, arg)
+        Tracer.serializeArgValue(self, function, arg)
 
     def footer(self, api):
         Tracer.footer(self, api)
@@ -719,13 +730,13 @@ class GlTracer(Tracer):
         # update the state
         print 'static void __trace_user_arrays(GLuint maxindex)'
         print '{'
-        print '    tracer_context *ctx = __get_context();'
+        print '    gltrace::Context *ctx = gltrace::getContext();'
 
         for camelcase_name, uppercase_name in self.arrays:
             # in which profile is the array available?
-            profile_check = 'ctx->profile == PROFILE_COMPAT'
+            profile_check = 'ctx->profile == gltrace::PROFILE_COMPAT'
             if camelcase_name in self.arrays_es1:
-                profile_check = '(' + profile_check + ' || ctx->profile == PROFILE_ES1)';
+                profile_check = '(' + profile_check + ' || ctx->profile == gltrace::PROFILE_ES1)';
 
             function_name = 'gl%sPointer' % camelcase_name
             enable_name = 'GL_%s_ARRAY' % uppercase_name
@@ -758,7 +769,7 @@ class GlTracer(Tracer):
                 assert not arg.output
                 print '            trace::localWriter.beginArg(%u);' % (arg.index,)
                 if arg.name != 'pointer':
-                    dump_instance(arg.type, arg.name)
+                    self.serializeValue(arg.type, arg.name)
                 else:
                     print '            trace::localWriter.writeBlob((const void *)%s, __size);' % (arg.name)
                 print '            trace::localWriter.endArg();'
@@ -784,7 +795,7 @@ class GlTracer(Tracer):
         # alias, and they need to be considered independently.
         #
         print '    // ES1 does not support generic vertex attributes'
-        print '    if (ctx->profile == PROFILE_ES1)'
+        print '    if (ctx->profile == gltrace::PROFILE_ES1)'
         print '        return;'
         print
         print '    vertex_attrib __vertex_attrib = __get_vertex_attrib();'
@@ -836,7 +847,7 @@ class GlTracer(Tracer):
                 assert not arg.output
                 print '                    trace::localWriter.beginArg(%u);' % (arg.index,)
                 if arg.name != 'pointer':
-                    dump_instance(arg.type, arg.name)
+                    self.serializeValue(arg.type, arg.name)
                 else:
                     print '                    trace::localWriter.writeBlob((const void *)%s, __size);' % (arg.name)
                 print '                    trace::localWriter.endArg();'
@@ -863,7 +874,7 @@ class GlTracer(Tracer):
             print '    GLint client_active_texture = 0;'
             print '    __glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE, &client_active_texture);'
             print '    GLint max_texture_coords = 0;'
-            print '    if (ctx->profile == PROFILE_COMPAT)'
+            print '    if (ctx->profile == gltrace::PROFILE_COMPAT)'
             print '        __glGetIntegerv(GL_MAX_TEXTURE_COORDS, &max_texture_coords);'
             print '    else'
             print '        __glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_texture_coords);'
@@ -906,7 +917,7 @@ class GlTracer(Tracer):
         for arg, instance in zip(function.args, args):
             assert not arg.output
             print '            trace::localWriter.beginArg(%u);' % (arg.index,)
-            dump_instance(arg.type, instance)
+            self.serializeValue(arg.type, instance)
             print '            trace::localWriter.endArg();'
         print '            trace::localWriter.endEnter();'
         print '            trace::localWriter.beginLeave(__fake_call);'