]> git.cworth.org Git - apitrace/blob - retrace/d3dcommonretrace.py
d3dretrace: Basic D3D11 snap-shooting.
[apitrace] / retrace / d3dcommonretrace.py
1 ##########################################################################
2 #
3 # Copyright 2011 Jose Fonseca
4 # All Rights Reserved.
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 # THE SOFTWARE.
23 #
24 ##########################################################################/
25
26
27 """D3D retracer generator."""
28
29
30 import sys
31 from dllretrace import DllRetracer as Retracer
32 from specs.stdapi import API
33 from specs.dxgi import dxgi
34 from specs.d3d10 import d3d10
35 from specs.d3d10_1 import d3d10_1
36 from specs.d3d11 import d3d11
37
38
39 class D3DRetracer(Retracer):
40
41     def retraceApi(self, api):
42         print '// Swizzling mapping for lock addresses'
43         print 'static std::map<void *, void *> _maps;'
44         print
45
46         self.table_name = 'd3dretrace::d3d10_callbacks'
47
48         Retracer.retraceApi(self, api)
49
50     def invokeFunction(self, function):
51         # create windows as neccessary
52         if function.name in ('D3D10CreateDeviceAndSwapChain', 'D3D10CreateDeviceAndSwapChain1', 'D3D11CreateDeviceAndSwapChain'):
53             print r'    pSwapChainDesc->OutputWindow = d3dretrace::createWindow(512, 512);'
54
55         if 'Software' in function.argNames():
56             print r'    if (Software) {'
57             print r'        retrace::warning(call) << "software device\n";'
58             print r'        Software = LoadLibraryA("d3d10warp");'
59             print r'    }'
60
61         Retracer.invokeFunction(self, function)
62
63
64     def invokeInterfaceMethod(self, interface, method):
65         # keep track of the last used device for state dumping
66         if interface.name in ('ID3D11DeviceContext',):
67             if method.name == 'Release':
68                 print r'    d3d11Dumper.unbindDevice(_this);'
69             else:
70                 print r'    d3d11Dumper.bindDevice(_this);'
71
72         # create windows as neccessary
73         if method.name == 'CreateSwapChain':
74             print r'    pDesc->OutputWindow = d3dretrace::createWindow(512, 512);'
75
76         # notify frame has been completed
77         if method.name == 'Present':
78             print r'    retrace::frameComplete(call);'
79
80         if 'pSharedResource' in method.argNames():
81             print r'    if (pSharedResource) {'
82             print r'        retrace::warning(call) << "shared surfaces unsupported\n";'
83             print r'        pSharedResource = NULL;'
84             print r'    }'
85
86         Retracer.invokeInterfaceMethod(self, interface, method)
87
88         # process events after presents
89         if method.name == 'Present':
90             print r'    d3dretrace::processEvents();'
91
92         # check errors
93         if str(method.type) == 'HRESULT':
94             print r'    if (FAILED(_result)) {'
95             print r'        retrace::warning(call) << "failed\n";'
96             print r'    }'
97
98         if method.name == 'Map':
99             print '    VOID *_pbData = NULL;'
100             print '    size_t _MappedSize = 0;'
101             print '    _getMapInfo(_this, %s, _pbData, _MappedSize);' % ', '.join(method.argNames())
102             print '    _maps[_this] = _pbData;'
103         
104         if method.name == 'Unmap':
105             print '    VOID *_pbData = 0;'
106             print '    _pbData = _maps[_this];'
107             print '    if (_pbData) {'
108             print '        retrace::delRegionByPointer(_pbData);'
109             print '    }'
110
111
112 def main():
113     print r'''#include <string.h>'''
114     print
115     print r'#include <iostream>'
116     print
117     print r'#include "d3dretrace.hpp"'
118     print
119
120     moduleNames = sys.argv[1:]
121
122     api = API()
123     if moduleNames:
124         api.addModule(dxgi)
125     if 'd3d10' in moduleNames:
126         if 'd3d10_1' in moduleNames:
127             print r'#include "d3d10_1imports.hpp"'
128             # D3D10CreateBlob is duplicated in d3d10 and d3d10_1
129             d3d10_1.functions = [function for function in d3d10_1.functions if function.name != 'D3D10CreateBlob']
130             api.addModule(d3d10_1)
131         else:
132             print r'#include "d3d10imports.hpp"'
133         print r'#include "d3d10size.hpp"'
134         api.addModule(d3d10)
135     if 'd3d11' in moduleNames:
136         print r'#include "d3d11imports.hpp"'
137         if 'd3d11_1' in moduleNames:
138             print '#include <d3d11_1.h>'
139             import specs.d3d11_1
140         print r'#include "d3d11size.hpp"'
141         print r'#include "d3dstate.hpp"'
142         api.addModule(d3d11)
143         
144         print
145         print '''static d3dretrace::D3DDumper<ID3D11DeviceContext> d3d11Dumper;'''
146         print
147
148     retracer = D3DRetracer()
149     retracer.retraceApi(api)
150
151
152 if __name__ == '__main__':
153     main()