]> git.cworth.org Git - apitrace/blobdiff - retrace/d3dcommonretrace.py
retrace: Just warn in face of an unexpected non-null object.
[apitrace] / retrace / d3dcommonretrace.py
index add1a5040a87710615ac02e89e1921ced48524a5..7a64d81a1348105d49e328412879e456f98f3223 100644 (file)
@@ -47,24 +47,50 @@ class D3DRetracer(Retracer):
 
         Retracer.retraceApi(self, api)
 
-    def invokeFunction(self, function):
-        # create windows as neccessary
-        if function.name in ('D3D10CreateDeviceAndSwapChain', 'D3D10CreateDeviceAndSwapChain1', 'D3D11CreateDeviceAndSwapChain'):
-            print r'    pSwapChainDesc->OutputWindow = d3dretrace::createWindow(512, 512);'
+    createDeviceFunctionNames = [
+        "D3D10CreateDevice",
+        "D3D10CreateDeviceAndSwapChain",
+        "D3D10CreateDevice1",
+        "D3D10CreateDeviceAndSwapChain1",
+        "D3D11CreateDevice",
+        "D3D11CreateDeviceAndSwapChain",
+    ]
 
-        if 'Software' in function.argNames():
-            print r'    if (Software) {'
-            print r'        retrace::warning(call) << "software device\n";'
-            print r'        Software = LoadLibraryA("d3d10warp");'
-            print r'    }'
+    def invokeFunction(self, function):
+        if function.name in self.createDeviceFunctionNames:
+            # create windows as neccessary
+            if 'pSwapChainDesc' in function.argNames():
+                print r'    pSwapChainDesc->OutputWindow = d3dretrace::createWindow(512, 512);'
+
+            # Compensate for the fact we don't trace the software renderer
+            # module LoadLibrary call
+            if 'Software' in function.argNames():
+                print r'    if (Software) {'
+                print r'        retrace::warning(call) << "using WARP for software device\n";'
+                print r'        Software = LoadLibraryA("d3d10warp");'
+                print r'    }'
+
+            # Compensate for the fact we don't trace DXGI object creation
+            if function.name.startswith('D3D11CreateDevice'):
+                print r'    if (DriverType == D3D_DRIVER_TYPE_UNKNOWN && !pAdapter) {'
+                print r'        DriverType = D3D_DRIVER_TYPE_HARDWARE;'
+                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 ('ID3D10Device', 'ID3D10Device1'):
+            if method.name == 'Release':
+                print r'    d3d10Dumper.unbindDevice(_this);'
+            else:
+                print r'    d3d10Dumper.bindDevice(_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':
@@ -86,23 +112,22 @@ class D3DRetracer(Retracer):
         if method.name == 'Present':
             print r'    d3dretrace::processEvents();'
 
-        # check errors
-        if str(method.type) == 'HRESULT':
-            print r'    if (FAILED(_result)) {'
-            print r'        retrace::warning(call) << "failed\n";'
-            print r'    }'
-
         if method.name == 'Map':
             print '    VOID *_pbData = NULL;'
             print '    size_t _MappedSize = 0;'
             print '    _getMapInfo(_this, %s, _pbData, _MappedSize);' % ', '.join(method.argNames())
-            print '    _maps[_this] = _pbData;'
+            print '    if (_MappedSize) {'
+            print '        _maps[_this] = _pbData;'
+            print '    } else {'
+            print '        return;'
+            print '    }'
         
         if method.name == 'Unmap':
             print '    VOID *_pbData = 0;'
             print '    _pbData = _maps[_this];'
             print '    if (_pbData) {'
             print '        retrace::delRegionByPointer(_pbData);'
+            print '        _maps[_this] = 0;'
             print '    }'
 
 
@@ -117,8 +142,10 @@ def main():
     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"'
@@ -129,13 +156,22 @@ def main():
             print r'#include "d3d10imports.hpp"'
         print r'#include "d3d10size.hpp"'
         api.addModule(d3d10)
+        print
+        print '''static d3dretrace::D3DDumper<ID3D10Device> d3d10Dumper;'''
+        print
+
     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)