]> git.cworth.org Git - apitrace/commitdiff
D3D retrace checkpoint.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Mon, 23 Jan 2012 00:30:35 +0000 (00:30 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Mon, 23 Jan 2012 00:30:35 +0000 (00:30 +0000)
CMakeLists.txt
d3dretrace.hpp [new file with mode: 0644]
d3dretrace.py [new file with mode: 0644]
d3dretrace_main.cpp [new file with mode: 0644]
glretrace.hpp
glretrace_main.cpp
retrace.cpp
retrace.hpp
retrace.py
specs/stdapi.py
trace.py

index 24e2afc06bcdeb5e52a6e8ccb7ce9f3e1a2851de..a141e10abfdba92b4f2d48c7ba58a51b5af88c78 100755 (executable)
@@ -613,6 +613,21 @@ if (EGL_FOUND AND X11_FOUND AND NOT WIN32 AND NOT APPLE)
     install (TARGETS eglretrace RUNTIME DESTINATION bin) 
 endif ()
 
+if (WIN32 AND DirectX_D3DX9_INCLUDE_DIR)
+    add_custom_command (
+        OUTPUT d3dretrace_d3d9.cpp
+        COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3dretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3dretrace_d3d9.cpp
+        DEPENDS d3dretrace.py retrace.py specs/d3d9.py specs/d3d9types.py specs/d3d9caps.py specs/winapi.py specs/stdapi.py
+    )
+
+    include_directories (SYSTEM ${DirectX_D3DX9_INCLUDE_DIR})
+    add_executable (d3dretrace
+        retrace.cpp
+        d3dretrace_main.cpp
+        d3dretrace_d3d9.cpp
+    )
+endif ()
+
 ##############################################################################
 # CLI
 
diff --git a/d3dretrace.hpp b/d3dretrace.hpp
new file mode 100644 (file)
index 0000000..cac94cc
--- /dev/null
@@ -0,0 +1,41 @@
+/**************************************************************************
+ *
+ * Copyright 2012 Jose Fonseca
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef _D3DRETRACE_HPP_
+#define _D3DRETRACE_HPP_
+
+#include "retrace.hpp"
+
+
+namespace d3dretrace {
+
+
+extern const retrace::Entry d3d9_callbacks[];
+
+
+} /* namespace d3dretrace */
+
+
+#endif /* _D3DRETRACE_HPP_ */
diff --git a/d3dretrace.py b/d3dretrace.py
new file mode 100644 (file)
index 0000000..21c87b9
--- /dev/null
@@ -0,0 +1,52 @@
+##########################################################################
+#
+# Copyright 2011 Jose Fonseca
+# All Rights Reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+##########################################################################/
+
+
+"""GL retracer generator."""
+
+
+import specs.stdapi as stdapi
+from specs.d3d9 import d3d9
+from retrace import Retracer
+
+
+class D3DRetracer(Retracer):
+
+    table_name = 'd3dretrace::d3d9_callbacks'
+
+
+if __name__ == '__main__':
+    print r'''
+#include <string.h>
+
+#include <iostream>
+
+#include "d3d9imports.hpp"
+#include "d3dretrace.hpp"
+
+
+'''
+    retracer = D3DRetracer()
+    retracer.retraceApi(d3d9)
diff --git a/d3dretrace_main.cpp b/d3dretrace_main.cpp
new file mode 100644 (file)
index 0000000..133f3a7
--- /dev/null
@@ -0,0 +1,103 @@
+/**************************************************************************
+ *
+ * Copyright 2011 Jose Fonseca
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#include <string.h>
+
+#include "os_string.hpp"
+#include "retrace.hpp"
+#include "d3dretrace.hpp"
+
+
+namespace d3dretrace {
+
+static void display(void) {
+    retrace::Retracer retracer;
+
+    retracer.addCallbacks(d3d9_callbacks);
+
+    trace::Call *call;
+
+    while ((call = retrace::parser.parse_call())) {
+        retracer.retrace(*call);
+
+        delete call;
+    }
+
+    exit(0);
+}
+
+
+static void usage(void) {
+    std::cout << 
+        "Usage: d3dretrace [OPTION] TRACE\n"
+        "Replay TRACE.\n"
+        "\n"
+        "  -v           increase output verbosity\n"
+    ;
+}
+
+
+extern "C"
+int main(int argc, char **argv)
+{
+
+    int i;
+    for (i = 1; i < argc; ++i) {
+        const char *arg = argv[i];
+
+        if (arg[0] != '-') {
+            break;
+        }
+
+        if (!strcmp(arg, "--")) {
+            break;
+        } else if (!strcmp(arg, "--help")) {
+            usage();
+            return 0;
+        } else if (!strcmp(arg, "-v")) {
+            ++retrace::verbosity;
+        } else {
+            std::cerr << "error: unknown option " << arg << "\n";
+            usage();
+            return 1;
+        }
+    }
+
+    for ( ; i < argc; ++i) {
+        if (!retrace::parser.open(argv[i])) {
+            std::cerr << "error: failed to open " << argv[i] << "\n";
+            return 1;
+        }
+
+        display();
+
+        retrace::parser.close();
+    }
+
+    return 0;
+}
+
+} /* namespace glretrace */
index 41e2997c1482c126ae9b9c9f40180bb4f09a5fba..f7d244fa36290cf75e155d9e549ee1eb027de5ab 100644 (file)
@@ -26,7 +26,6 @@
 #ifndef _GLRETRACE_HPP_
 #define _GLRETRACE_HPP_
 
-#include "trace_parser.hpp"
 #include "glws.hpp"
 #include "retrace.hpp"
 
@@ -36,7 +35,6 @@ namespace glretrace {
 
 extern bool double_buffer;
 extern bool insideGlBeginEnd;
-extern trace::Parser parser;
 extern glws::Profile defaultProfile;
 extern glws::Visual *visual[glws::PROFILE_MAX];
 extern glws::Drawable *drawable;
index 12086321bd3a2bc94ef11a1b024e62ebecbe96c2..d80775f0ed3dd76c591c632e479065580c573939 100644 (file)
@@ -39,7 +39,6 @@ namespace glretrace {
 
 bool double_buffer = true;
 bool insideGlBeginEnd = false;
-trace::Parser parser;
 glws::Profile defaultProfile = glws::PROFILE_COMPAT;
 glws::Visual *visual[glws::PROFILE_MAX];
 glws::Drawable *drawable = NULL;
index 849c597f10cafaf64ef12b6d19a9266eab7b393b..fe0694d6a3726faf24b45df321160645a498fc69 100644 (file)
@@ -34,6 +34,9 @@
 namespace retrace {
 
 
+trace::Parser parser;
+
+
 int verbosity = 0;
 
 
index a59a6eb8901e97195d2f268082101a331396881b..33671411deb2a8b7841a078adfefc71d60fe273f 100644 (file)
 #include <ostream>
 
 #include "trace_model.hpp"
+#include "trace_parser.hpp"
 
 
 namespace retrace {
 
 
+extern trace::Parser parser;
+
+
 /**
  * Handle map.
  *
index 0e28d18b4a64618db8fb10b0e5b4faa407137df5..15cdaf5038e328d05e8646c564670d9ffe8c13fa 100644 (file)
@@ -207,11 +207,41 @@ class Retracer:
         print '}'
         print
 
+    def retraceInterfaceMethod(self, interface, method):
+        print 'static void retrace_%s__%s(trace::Call &call) {' % (interface.name, method.name)
+        self.retraceInterfaceMethodBody(interface, method)
+        print '}'
+        print
+
     def retraceFunctionBody(self, function):
         if not function.sideeffects:
             print '    (void)call;'
             return
 
+        self.deserializeArgs(function)
+        
+        self.invokeFunction(function)
+
+        self.swizzleValues(function)
+
+    def retraceInterfaceMethodBody(self, interface, method):
+        if not method.sideeffects:
+            print '    (void)call;'
+            return
+
+        self.deserializeThisPointer(interface)
+
+        self.deserializeArgs(method)
+        
+        self.invokeInterfaceMethod(interface, method)
+
+        self.swizzleValues(method)
+
+    def deserializeThisPointer(self, interface):
+        print '    %s *_this;' % (interface.name,)
+        # FIXME
+
+    def deserializeArgs(self, function):
         success = True
         for arg in function.args:
             arg_type = ConstRemover().visit(arg.type)
@@ -222,13 +252,17 @@ class Retracer:
             try:
                 self.extractArg(function, arg, arg_type, lvalue, rvalue)
             except NotImplementedError:
-                success = False
+                success =  False
                 print '    %s = 0; // FIXME' % arg.name
+
         if not success:
             print '    if (1) {'
             self.failFunction(function)
+            if function.name[-1].islower():
+                sys.stderr.write('warning: unsupported %s call\n' % function.name)
             print '    }'
-        self.invokeFunction(function)
+
+    def swizzleValues(self, function):
         for arg in function.args:
             if arg.output:
                 arg_type = ConstRemover().visit(arg.type)
@@ -245,9 +279,6 @@ class Retracer:
                 self.regiterSwizzledValue(function.type, lvalue, rvalue)
             except NotImplementedError:
                 print '    // XXX: result'
-        if not success:
-            if function.name[-1].islower():
-                sys.stderr.write('warning: unsupported %s call\n' % function.name)
 
     def failFunction(self, function):
         print '    if (retrace::verbosity >= 0) {'
@@ -274,32 +305,27 @@ class Retracer:
         else:
             print '    %s(%s);' % (function.name, arg_names)
 
+    def invokeInterfaceMethod(self, interface, method):
+        arg_names = ", ".join(method.argNames())
+        if method.type is not stdapi.Void:
+            print '    %s __result;' % (method.type)
+            print '    __result = _this->%s(%s);' % (method.name, arg_names)
+            print '    (void)__result;'
+        else:
+            print '    _this->%s(%s);' % (method.name, arg_names)
+
     def filterFunction(self, function):
         return True
 
     table_name = 'retrace::callbacks'
 
-    def retraceFunctions(self, functions):
-        functions = filter(self.filterFunction, functions)
-
-        for function in functions:
-            self.retraceFunction(function)
-
-        print 'const retrace::Entry %s[] = {' % self.table_name
-        for function in functions:
-            print '    {"%s", &retrace_%s},' % (function.name, function.name)
-        print '    {NULL, NULL}'
-        print '};'
-        print
-
-
     def retraceApi(self, api):
 
         print '#include "trace_parser.hpp"'
         print '#include "retrace.hpp"'
         print
 
-        types = api.all_types()
+        types = api.getAllTypes()
         handles = [type for type in types if isinstance(type, stdapi.Handle)]
         handle_names = set()
         for handle in handles:
@@ -312,5 +338,21 @@ class Retracer:
                 handle_names.add(handle.name)
         print
 
-        self.retraceFunctions(api.functions)
+        functions = filter(self.filterFunction, api.functions)
+        for function in functions:
+            self.retraceFunction(function)
+        interfaces = api.getAllInterfaces()
+        for interface in interfaces:
+            for method in interface.iterMethods():
+                self.retraceInterfaceMethod(interface, method)
+
+        print 'const retrace::Entry %s[] = {' % self.table_name
+        for function in functions:
+            print '    {"%s", &retrace_%s},' % (function.name, function.name)
+        for interface in interfaces:
+            for method in interface.iterMethods():
+                print '    {"%s::%s", &retrace_%s__%s},' % (interface.name, method.name, interface.name, method.name)
+        print '    {NULL, NULL}'
+        print '};'
+        print
 
index 44d4680a7e53467a8a464bddac2a2c63b2050416..61e2b21b756e2f241f2d8a7b130e07f18fbce58c 100644 (file)
@@ -551,6 +551,9 @@ class Rebuilder(Visitor):
     def visitOpaque(self, opaque):
         return opaque
 
+    def visitInterface(self, interface, *args, **kwargs):
+        return interface
+
     def visitPolymorphic(self, polymorphic):
         defaultType = self.visit(polymorphic.defaultType)
         switchExpr = polymorphic.switchExpr
@@ -644,7 +647,7 @@ class API:
         self.functions = []
         self.interfaces = []
 
-    def all_types(self):
+    def getAllTypes(self):
         collector = Collector()
         for function in self.functions:
             for arg in function.args:
@@ -658,6 +661,14 @@ class API:
                 collector.visit(method.type)
         return collector.types
 
+    def getAllInterfaces(self):
+        types = self.getAllTypes()
+        interfaces = [type for type in types if isinstance(type, Interface)]
+        for interface in self.interfaces:
+            if interface not in interfaces:
+                interfaces.append(interface)
+        return interfaces
+
     def addFunction(self, function):
         self.functions.append(function)
 
index 4d2f055794c4974646dcb0f27e2ee480e5d88236..0d973a21082bcd1989feeb9b39ad969c1a7a09bc 100644 (file)
--- a/trace.py
+++ b/trace.py
@@ -321,13 +321,13 @@ class Tracer:
         print
 
         # Generate the serializer functions
-        types = api.all_types()
+        types = api.getAllTypes()
         visitor = ComplexValueSerializer(self.serializerFactory())
         map(visitor.visit, types)
         print
 
         # Interfaces wrapers
-        interfaces = [type for type in types if isinstance(type, stdapi.Interface)]
+        interfaces = api.getAllInterfaces()
         map(self.declareWrapperInterface, interfaces)
         map(self.implementWrapperInterface, interfaces)
         print