]> git.cworth.org Git - apitrace/commitdiff
d3dretrace: More robust against DXGI missing calls.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 14 Nov 2012 14:02:35 +0000 (14:02 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 14 Nov 2012 14:02:35 +0000 (14:02 +0000)
retrace/d3d9retrace.py
retrace/d3dcommonretrace.py
retrace/retrace.py

index 7c292f93aba8ce42c7e35e8ba6cde09cd67a8031..1b89b68f5e6a159ee8f33184ee1b91b3169a2626 100644 (file)
@@ -97,12 +97,6 @@ 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 in ('Lock', 'LockRect', 'LockBox'):
             print '    VOID *_pbData = NULL;'
             print '    size_t _MappedSize = 0;'
index d3d68d1584ebe04bf661889e7f4ed6d06a64cbeb..4496b2c2376ebfc9cc76f58313bfe0997ed09e01 100644 (file)
@@ -47,16 +47,34 @@ 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)
 
@@ -89,23 +107,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 '    }'
 
 
index 5b5812faa101feb04c651608c24561bf22d9f0af..c4ad2d2bb494aceb861dcf163818bb702af58622 100644 (file)
@@ -434,6 +434,7 @@ class Retracer:
         if function.type is not stdapi.Void:
             print '    _result = %s(%s);' % (function.name, arg_names)
             print '    (void)_result;'
+            self.checkResult(function.type)
         else:
             print '    %s(%s);' % (function.name, arg_names)
 
@@ -450,9 +451,16 @@ class Retracer:
         if method.type is not stdapi.Void:
             print '    _result = _this->%s(%s);' % (method.name, arg_names)
             print '    (void)_result;'
+            self.checkResult(method.type)
         else:
             print '    _this->%s(%s);' % (method.name, arg_names)
 
+    def checkResult(self, resultType):
+        if str(resultType) == 'HRESULT':
+            print r'    if (FAILED(_result)) {'
+            print r'        retrace::warning(call) << "failed\n";'
+            print r'    }'
+
     def filterFunction(self, function):
         return True