blob: 9cd5da51f579cad0011edc22e80aa7071a351862 [file] [log] [blame]
José Fonseca610942b2012-11-08 10:46:03 +00001##########################################################################
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
José Fonseca6f810332012-11-11 10:05:09 +000030import sys
José Fonseca610942b2012-11-08 10:46:03 +000031from dllretrace import DllRetracer as Retracer
José Fonseca6f810332012-11-11 10:05:09 +000032from specs.stdapi import API
33from specs.dxgi import dxgi
34from specs.d3d10 import d3d10
35from specs.d3d10_1 import d3d10_1
36from specs.d3d11 import d3d11
José Fonseca610942b2012-11-08 10:46:03 +000037
38
39class D3DRetracer(Retracer):
40
José Fonsecae3814852012-11-11 09:45:06 +000041 def retraceApi(self, api):
42 print '''
43image::Image *
44retrace::getSnapshot(void) {
45 return NULL;
46}
47
48
49bool
50retrace::dumpState(std::ostream &os)
51{
52 return false;
53}
54'''
55
José Fonseca610942b2012-11-08 10:46:03 +000056 print '// Swizzling mapping for lock addresses'
57 print 'static std::map<void *, void *> _maps;'
58 print
59
60 self.table_name = 'd3dretrace::d3d_callbacks'
61
José Fonsecae3814852012-11-11 09:45:06 +000062 Retracer.retraceApi(self, api)
José Fonseca610942b2012-11-08 10:46:03 +000063
64 def invokeFunction(self, function):
65 # create windows as neccessary
66 if function.name in ('D3D10CreateDeviceAndSwapChain', 'D3D10CreateDeviceAndSwapChain1', 'D3D11CreateDeviceAndSwapChain'):
67 print r' pSwapChainDesc->OutputWindow = d3dretrace::createWindow(512, 512);'
68
69 Retracer.invokeFunction(self, function)
70
71 def invokeInterfaceMethod(self, interface, method):
72 # keep track of the last used device for state dumping
73 #if interface.name in ('IDirect3DDevice9', 'IDirect3DDevice9Ex'):
74 # print r' d3dretrace::pLastDirect3DDevice9 = _this;'
75
76 # create windows as neccessary
77 if method.name == 'CreateSwapChain':
78 print r' pDesc->OutputWindow = d3dretrace::createWindow(512, 512);'
79
80 # notify frame has been completed
81 if method.name == 'Present':
82 print r' retrace::frameComplete(call);'
83
84 if 'pSharedResource' in method.argNames():
85 print r' if (pSharedResource) {'
86 print r' retrace::warning(call) << "shared surfaces unsupported\n";'
87 print r' pSharedResource = NULL;'
88 print r' }'
89
90 Retracer.invokeInterfaceMethod(self, interface, method)
91
92 # process events after presents
93 if method.name == 'Present':
94 print r' d3dretrace::processEvents();'
95
96 # check errors
97 if str(method.type) == 'HRESULT':
98 print r' if (FAILED(_result)) {'
99 print r' retrace::warning(call) << "failed\n";'
100 print r' }'
101
102 if method.name == 'Map':
103 print ' VOID *_pbData = NULL;'
104 print ' size_t _MappedSize = 0;'
105 print ' _getMapInfo(_this, %s, _pbData, _MappedSize);' % ', '.join(method.argNames())
106 print ' _maps[_this] = _pbData;'
107
108 if method.name == 'Unmap':
109 print ' VOID *_pbData = 0;'
110 print ' _pbData = _maps[_this];'
111 print ' if (_pbData) {'
112 print ' retrace::delRegionByPointer(_pbData);'
113 print ' }'
José Fonseca6f810332012-11-11 10:05:09 +0000114
115
116def main():
117 print r'''#include <string.h>'''
118 print
119 print r'#include <iostream>'
120 print
121 print r'#include "d3dretrace.hpp"'
122 print
123
124 moduleNames = sys.argv[1:]
125
126 api = API()
127 if moduleNames:
128 api.addModule(dxgi)
129 if 'd3d10' in moduleNames:
130 if 'd3d10_1' in moduleNames:
131 print r'#include "d3d10_1imports.hpp"'
132 # D3D10CreateBlob is duplicated in d3d10 and d3d10_1
133 d3d10_1.functions = [function for function in d3d10_1.functions if function.name != 'D3D10CreateBlob']
134 api.addModule(d3d10_1)
135 else:
136 print r'#include "d3d10imports.hpp"'
137 print r'#include "d3d10size.hpp"'
138 api.addModule(d3d10)
139 if 'd3d11' in moduleNames:
140 print r'#include "d3d11imports.hpp"'
141 if 'd3d11_1' in moduleNames:
142 print '#include <d3d11_1.h>'
143 import specs.d3d11_1
144 print r'#include "d3d11size.hpp"'
145 api.addModule(d3d11)
146
147 retracer = D3DRetracer()
148 retracer.retraceApi(api)
149
150
151if __name__ == '__main__':
152 main()