]> git.cworth.org Git - apitrace/commitdiff
Handle vertex attriv locations correctly.
authorJosé Fonseca <jfonseca@vmware.com>
Mon, 23 May 2011 20:20:31 +0000 (21:20 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Mon, 23 May 2011 20:20:31 +0000 (21:20 +0100)
However, this does nothing for old traces which do not use
glBindAttribLocation, except than an warning message.

glapi.py
glretrace.py
gltrace.py

index 271be71bd11bb6cad87944e1f7a3bb1a734f104e..93e6942d2c8d53e1e2de634a9a0dfd020b0897bf 100644 (file)
--- a/glapi.py
+++ b/glapi.py
@@ -573,7 +573,7 @@ glapi.add_functions([
     GlFunction(Void, "glGetActiveAttrib", [(GLprogram, "program"), (GLuint, "index"), (GLsizei, "bufSize"), Out(Pointer(GLsizei), "length"), Out(Pointer(GLint), "size"), Out(Pointer(GLenum), "type"), Out(GLstring, "name")], sideeffects=False),
     GlFunction(Void, "glGetActiveUniform", [(GLprogram, "program"), (GLuint, "index"), (GLsizei, "bufSize"), Out(Pointer(GLsizei), "length"), Out(Pointer(GLint), "size"), Out(Pointer(GLenum), "type"), Out(GLstring, "name")], sideeffects=False),
     GlFunction(Void, "glGetAttachedShaders", [(GLprogram, "program"), (GLsizei, "maxCount"), Out(Pointer(GLsizei), "count"), Out(Array(GLuint, "(count ? *count : maxCount)"), "obj")], sideeffects=False),
-    GlFunction(GLint, "glGetAttribLocation", [(GLprogram, "program"), (Const(GLstring), "name")], sideeffects=False),
+    GlFunction(GLint, "glGetAttribLocation", [(GLprogram, "program"), (Const(GLstring), "name")]),
     GlFunction(Void, "glGetProgramiv", [(GLprogram, "program"), (GLenum, "pname"), Out(Array(GLint, "__gl_param_size(pname)"), "params")], sideeffects=False),
     GlFunction(Void, "glGetProgramInfoLog", [(GLprogram, "program"), (GLsizei, "bufSize"), Out(Pointer(GLsizei), "length"), Out(GLstring, "infoLog")], sideeffects=False),
     GlFunction(Void, "glGetShaderiv", [(GLshader, "shader"), (GLenum, "pname"), Out(Array(GLint, "__gl_param_size(pname)"), "params")], sideeffects=False),
@@ -964,7 +964,7 @@ glapi.add_functions([
     # GL_ARB_vertex_shader
     GlFunction(Void, "glBindAttribLocationARB", [(GLhandleARB, "programObj"), (GLuint, "index"), (Const(GLstringARB), "name")]),
     GlFunction(Void, "glGetActiveAttribARB", [(GLhandleARB, "programObj"), (GLuint, "index"), (GLsizei, "maxLength"), Out(Pointer(GLsizei), "length"), Out(Pointer(GLint), "size"), Out(Pointer(GLenum), "type"), Out(GLstringARB, "name")], sideeffects=False),
-    GlFunction(GLint, "glGetAttribLocationARB", [(GLhandleARB, "programObj"), (Const(GLstringARB), "name")], sideeffects=False),
+    GlFunction(GLint, "glGetAttribLocationARB", [(GLhandleARB, "programObj"), (Const(GLstringARB), "name")]),
 
     # GL_ARB_draw_buffers
     GlFunction(Void, "glDrawBuffersARB", [(GLsizei, "n"), (Const(Array(GLenum, "n")), "bufs")]),
index 0267d1e4a28c75c03f7d20d640552f352819647c..ef7f8aaa8d321f4fcf4dab10ab6a47d1d850ed57 100644 (file)
@@ -212,6 +212,11 @@ class GlRetracer(Retracer):
                 print r'             std::cerr << call.no << ": warning: " << infoLog << "\n";'
                 print r'             delete [] infoLog;'
                 print r'        }'
+            if function.name in ('glGetAttribLocation', 'glGetAttribLocationARB'):
+                print r'    GLint __orig_result = call.ret->toSInt();'
+                print r'    if (__result != __orig_result) {'
+                print r'        std::cerr << call.no << ": warning vertex attrib location mismatch " << __orig_result << " -> " << __result << "\n";'
+                print r'    }'
             print '    }'
 
     def extract_arg(self, function, arg, arg_type, lvalue, rvalue):
index 62e307e30daa95da8c6cf19a9bd4615df0d1a375..47be12afa7015473ebd76dc8e31d04950c122980 100644 (file)
@@ -372,8 +372,53 @@ class GlTracer(Tracer):
             print '    }'
         # FIXME: glFlushMappedNamedBufferRangeEXT
 
+        # Don't leave vertex attrib locations to chance.  Instead emit fake
+        # glBindAttribLocation calls to ensure that the same locations will be
+        # used when retracing.  Trying to remap locations after the fact would
+        # 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)
+            print '    GLint active_attributes = 0;'
+            print '    __glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &active_attributes);'
+            print '    for (GLuint attrib = 0; attrib < active_attributes; ++attrib) {'
+            print '        GLint size = 0;'
+            print '        GLenum type = 0;'
+            print '        GLchar name[256];'
+            # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256
+            print '        __glGetActiveAttrib(program, attrib, sizeof name, NULL, &size, &type, name);'
+            print '        GLint location = __glGetAttribLocation(program, name);'
+            print '        if (location >= 0) {'
+            bind_function = glapi.glapi.get_function_by_name('glBindAttribLocation')
+            self.fake_call(bind_function, ['program', 'location', 'name'])
+            print '        }'
+            print '    }'
+        if function.name == 'glLinkProgramARB':
+            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 '        GLint size = 0;'
+            print '        GLenum type = 0;'
+            print '        GLcharARB name[256];'
+            # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256
+            print '        __glGetActiveAttribARB(programObj, attrib, sizeof name, NULL, &size, &type, name);'
+            print '        GLint location = __glGetAttribLocationARB(programObj, name);'
+            print '        if (location >= 0) {'
+            bind_function = glapi.glapi.get_function_by_name('glBindAttribLocationARB')
+            self.fake_call(bind_function, ['programObj', 'location', 'name'])
+            print '        }'
+            print '    }'
+
         Tracer.trace_function_impl_body(self, function)
 
+    def dispatch_function(self, function):
+        if function.name in ('glLinkProgram', 'glLinkProgramARB'):
+            # These functions have been dispatched already
+            return
+
+        Tracer.dispatch_function(self, function)
+
     def emit_memcpy(self, dest, src, length):
         print '        unsigned __call = Trace::BeginEnter(__memcpy_sig);'
         print '        Trace::BeginArg(0);'