]> git.cworth.org Git - apitrace/blobdiff - retrace/glretrace.py
Add support for basic GPU profiling of draw calls to retrace.
[apitrace] / retrace / glretrace.py
index b7659ff1dd6bcd37e6268a3fa7b22c2c43a55527..440366cb87a85f22eb8fdb53201f46b435664cf0 100644 (file)
@@ -257,6 +257,11 @@ class GlRetracer(Retracer):
         if function.name == 'memcpy':
             print '    if (!dest || !src || !n) return;'
 
+        # Skip glEnable/Disable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB) as we don't
+        # faithfully set the CONTEXT_DEBUG_BIT_ARB flags on context creation.
+        if function.name in ('glEnable', 'glDisable'):
+            print '    if (cap == GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB) return;'
+
         # Destroy the buffer mapping
         if function.name in self.unmap_function_names:
             print r'        GLvoid *ptr = NULL;'
@@ -278,8 +283,67 @@ class GlRetracer(Retracer):
             print r'        } else {'
             print r'            retrace::warning(call) << "no current context\n";'
             print r'        }'
-        
-        Retracer.invokeFunction(self, function)
+
+        if function.name in ('glBindProgramPipeline', 'glBindProgramPipelineEXT'):
+            # Note if glBindProgramPipeline has ever been called
+            print r'    if (pipeline) {'
+            print r'        _pipelineHasBeenBound = true;'
+            print r'    }'
+
+        profileDraw = (
+            function.name in self.draw_array_function_names or
+            function.name in self.draw_elements_function_names or
+            function.name in self.draw_indirect_function_names or
+            function.name in self.misc_draw_function_names
+        )
+
+        # Only profile if not inside a list as the queries get inserted into lsit
+        if function.name == 'glNewList':
+            print r'    glretrace::insideList = true;';
+
+        if function.name == 'glEndList':
+            print r'    glretrace::insideList = false;';
+
+        if profileDraw:
+            print r'    if (!glretrace::insideList && retrace::profileGPU) {'
+            print r'        glretrace::beginProfileGPU(call);'
+            print r'    }'
+
+        if function.name == 'glCreateShaderProgramv':
+            # When dumping state, break down glCreateShaderProgramv so that the
+            # shader source can be recovered.
+            print r'    if (retrace::dumpingState) {'
+            print r'        GLuint _shader = glCreateShader(type);'
+            print r'        if (_shader) {'
+            print r'            glShaderSource(_shader, count, strings, NULL);'
+            print r'            glCompileShader(_shader);'
+            print r'            const GLuint _program = glCreateProgram();'
+            print r'            if (_program) {'
+            print r'                GLint compiled = GL_FALSE;'
+            print r'                glGetShaderiv(_shader, GL_COMPILE_STATUS, &compiled);'
+            print r'                glProgramParameteri(_program, GL_PROGRAM_SEPARABLE, GL_TRUE);'
+            print r'                if (compiled) {'
+            print r'                    glAttachShader(_program, _shader);'
+            print r'                    glLinkProgram(_program);'
+            print r'                    //glDetachShader(_program, _shader);'
+            print r'                }'
+            print r'                //append-shader-info-log-to-program-info-log'
+            print r'            }'
+            print r'            //glDeleteShader(_shader);'
+            print r'            _result = _program;'
+            print r'        } else {'
+            print r'            _result = 0;'
+            print r'        }'
+            print r'    } else {'
+            Retracer.invokeFunction(self, function)
+            print r'    }'
+        else:
+            Retracer.invokeFunction(self, function)
+
+        if profileDraw:
+            print r'    if (!glretrace::insideList && retrace::profileGPU) {'
+            print r'        glretrace::endProfileGPU(call);'
+            print r'    }'
 
         # Error checking
         if function.name == "glBegin":
@@ -306,7 +370,9 @@ class GlRetracer(Retracer):
                 print r'             retrace::warning(call) << infoLog << "\n";'
                 print r'             delete [] infoLog;'
                 print r'        }'
-            if function.name == 'glLinkProgram':
+            if function.name in ('glLinkProgram', 'glCreateShaderProgramv', 'glCreateShaderProgramEXT'):
+                if function.name != 'glLinkProgram':
+                    print r'        GLuint program = _result;'
                 print r'        GLint link_status = 0;'
                 print r'        glGetProgramiv(program, GL_LINK_STATUS, &link_status);'
                 print r'        if (!link_status) {'
@@ -397,9 +463,19 @@ class GlRetracer(Retracer):
 
         if arg.type is glapi.GLlocation \
            and 'program' not in function.argNames():
+            # Determine the active program for uniforms swizzling
             print '    GLint program = -1;'
-            print '    glGetIntegerv(GL_CURRENT_PROGRAM, &program);'
-        
+            print '    GLint pipeline = 0;'
+            print '    if (_pipelineHasBeenBound) {'
+            print '        glGetIntegerv(GL_PROGRAM_PIPELINE_BINDING, &pipeline);'
+            print '    }'
+            print '    if (pipeline) {'
+            print '        glGetProgramPipelineiv(pipeline, GL_ACTIVE_PROGRAM, &program);'
+            print '    } else {'
+            print '        glGetIntegerv(GL_CURRENT_PROGRAM, &program);'
+            print '    }'
+            print
+
         if arg.type is glapi.GLlocationARB \
            and 'programObj' not in function.argNames():
             print '    GLhandleARB programObj = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);'
@@ -431,6 +507,7 @@ if __name__ == '__main__':
 #include "glstate.hpp"
 
 
+static bool _pipelineHasBeenBound = false;
 '''
     api = glapi.glapi
     api.addApi(glesapi.glesapi)