]> git.cworth.org Git - apitrace/blobdiff - retrace/d3dcommonretrace.py
d3dretrace: Basic D3D11 snap-shooting.
[apitrace] / retrace / d3dcommonretrace.py
index ea09eb01bab5e475411fde8b76757223d8246e5e..d3d68d1584ebe04bf661889e7f4ed6d06a64cbeb 100644 (file)
 """D3D retracer generator."""
 
 
+import sys
 from dllretrace import DllRetracer as Retracer
-import specs.stdapi as stdapi
+from specs.stdapi import API
+from specs.dxgi import dxgi
+from specs.d3d10 import d3d10
+from specs.d3d10_1 import d3d10_1
+from specs.d3d11 import d3d11
 
 
 class D3DRetracer(Retracer):
@@ -38,7 +43,7 @@ class D3DRetracer(Retracer):
         print 'static std::map<void *, void *> _maps;'
         print
 
-        self.table_name = 'd3dretrace::d3d_callbacks'
+        self.table_name = 'd3dretrace::d3d10_callbacks'
 
         Retracer.retraceApi(self, api)
 
@@ -47,12 +52,22 @@ class D3DRetracer(Retracer):
         if function.name in ('D3D10CreateDeviceAndSwapChain', 'D3D10CreateDeviceAndSwapChain1', 'D3D11CreateDeviceAndSwapChain'):
             print r'    pSwapChainDesc->OutputWindow = d3dretrace::createWindow(512, 512);'
 
+        if 'Software' in function.argNames():
+            print r'    if (Software) {'
+            print r'        retrace::warning(call) << "software device\n";'
+            print r'        Software = LoadLibraryA("d3d10warp");'
+            print r'    }'
+
         Retracer.invokeFunction(self, function)
 
+
     def invokeInterfaceMethod(self, interface, method):
         # keep track of the last used device for state dumping
-        #if interface.name in ('IDirect3DDevice9', 'IDirect3DDevice9Ex'):
-        #    print r'    d3dretrace::pLastDirect3DDevice9 = _this;'
+        if interface.name in ('ID3D11DeviceContext',):
+            if method.name == 'Release':
+                print r'    d3d11Dumper.unbindDevice(_this);'
+            else:
+                print r'    d3d11Dumper.bindDevice(_this);'
 
         # create windows as neccessary
         if method.name == 'CreateSwapChain':
@@ -92,3 +107,47 @@ class D3DRetracer(Retracer):
             print '    if (_pbData) {'
             print '        retrace::delRegionByPointer(_pbData);'
             print '    }'
+
+
+def main():
+    print r'''#include <string.h>'''
+    print
+    print r'#include <iostream>'
+    print
+    print r'#include "d3dretrace.hpp"'
+    print
+
+    moduleNames = sys.argv[1:]
+
+    api = API()
+    if moduleNames:
+        api.addModule(dxgi)
+    if 'd3d10' in moduleNames:
+        if 'd3d10_1' in moduleNames:
+            print r'#include "d3d10_1imports.hpp"'
+            # D3D10CreateBlob is duplicated in d3d10 and d3d10_1
+            d3d10_1.functions = [function for function in d3d10_1.functions if function.name != 'D3D10CreateBlob']
+            api.addModule(d3d10_1)
+        else:
+            print r'#include "d3d10imports.hpp"'
+        print r'#include "d3d10size.hpp"'
+        api.addModule(d3d10)
+    if 'd3d11' in moduleNames:
+        print r'#include "d3d11imports.hpp"'
+        if 'd3d11_1' in moduleNames:
+            print '#include <d3d11_1.h>'
+            import specs.d3d11_1
+        print r'#include "d3d11size.hpp"'
+        print r'#include "d3dstate.hpp"'
+        api.addModule(d3d11)
+        
+        print
+        print '''static d3dretrace::D3DDumper<ID3D11DeviceContext> d3d11Dumper;'''
+        print
+
+    retracer = D3DRetracer()
+    retracer.retraceApi(api)
+
+
+if __name__ == '__main__':
+    main()