1 ##########################################################################
3 # Copyright 2008-2009 VMware, Inc.
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:
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
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
24 ##########################################################################/
28 from dlltrace import DllTracer
29 from trace import getWrapperInterfaceName
30 from specs import stdapi
31 from specs.stdapi import API
32 from specs import dxgi
33 from specs import d3d10
34 from specs import d3d10_1
35 from specs import d3d11
38 class D3DCommonTracer(DllTracer):
40 def serializeArgValue(self, function, arg):
41 # Dump shaders as strings
42 if isinstance(arg.type, stdapi.Blob) and arg.name.startswith('pShaderBytecode'):
43 print ' DumpShader(trace::localWriter, %s, %s);' % (arg.name, arg.type.size)
46 # Serialize the swapchain dimensions
47 if function.name == 'CreateSwapChain' and arg.name == 'pDesc' \
48 or arg.name == 'pSwapChainDesc':
49 print r' DXGI_SWAP_CHAIN_DESC *_pSwapChainDesc = NULL;'
50 print r' DXGI_SWAP_CHAIN_DESC _SwapChainDesc;'
51 print r' if (%s) {' % arg.name
52 print r' _SwapChainDesc = *%s;' % arg.name
53 if function.name != 'CreateSwapChain' or not self.interface.name.endswith('DWM'):
54 # Obtain size from the window
56 print r' if (GetClientRect(%s->OutputWindow, &_rect)) {' % arg.name
57 print r' if (%s->BufferDesc.Width == 0) {' % arg.name
58 print r' _SwapChainDesc.BufferDesc.Width = _rect.right - _rect.left;'
60 print r' if (%s->BufferDesc.Height == 0) {' % arg.name
61 print r' _SwapChainDesc.BufferDesc.Height = _rect.bottom - _rect.top;'
65 # Obtain size from the output
66 print r' DXGI_OUTPUT_DESC _OutputDesc;'
67 print r' if (SUCCEEDED(pOutput->GetDesc(&_OutputDesc))) {'
68 print r' _SwapChainDesc.BufferDesc.Width = _OutputDesc.DesktopCoordinates.right - _OutputDesc.DesktopCoordinates.left;'
69 print r' _SwapChainDesc.BufferDesc.Height = _OutputDesc.DesktopCoordinates.bottom - _OutputDesc.DesktopCoordinates.top;'
71 print r' _pSwapChainDesc = &_SwapChainDesc;'
73 self.serializeValue(arg.type, '_pSwapChainDesc')
76 DllTracer.serializeArgValue(self, function, arg)
78 # Interfaces that need book-keeping for maps
85 def enumWrapperInterfaceVariables(self, interface):
86 variables = DllTracer.enumWrapperInterfaceVariables(self, interface)
88 # Add additional members to track maps
89 if interface.hasBase(*self.mapInterfaces):
91 ('_MAP_DESC', '_MapDesc', None),
96 def implementWrapperInterfaceMethodBody(self, interface, base, method):
97 if method.name in ('Map', 'Unmap'):
98 # On D3D11 Map/Unmap is not a resource method, but a context method instead.
99 resourceArg = method.getArgByName('pResource')
100 if resourceArg is None:
103 wrapperInterfaceName = getWrapperInterfaceName(resourceArg.type.type)
104 print ' %s * _pResource = static_cast<%s*>(%s);' % (wrapperInterfaceName, wrapperInterfaceName, resourceArg.name)
105 pResource = '_pResource'
107 if method.name == 'Unmap':
108 print ' _MAP_DESC _MapDesc = %s->_MapDesc;' % pResource
109 #print r' os::log("%%p -> %%p+%%lu\n", %s,_MapDesc.pData, (unsigned long)_MapDesc.Size);' % pResource
110 print ' if (_MapDesc.Size && _MapDesc.pData) {'
111 self.emit_memcpy('_MapDesc.pData', '_MapDesc.pData', '_MapDesc.Size')
114 DllTracer.implementWrapperInterfaceMethodBody(self, interface, base, method)
116 if method.name == 'Map':
117 # NOTE: recursive locks are explicitely forbidden
118 print ' _MAP_DESC _MapDesc;'
119 print ' if (SUCCEEDED(_result)) {'
120 print ' _getMapDesc(_this, %s, _MapDesc);' % ', '.join(method.argNames())
122 print ' _MapDesc.pData = NULL;'
123 print ' _MapDesc.Size = 0;'
125 #print r' os::log("%%p <- %%p+%%lu\n", %s,_MapDesc.pData, (unsigned long)_MapDesc.Size);' % pResource
126 print ' %s->_MapDesc = _MapDesc;' % pResource
129 if __name__ == '__main__':
130 print '#define INITGUID'
132 print '#include "trace_writer_local.hpp"'
133 print '#include "os.hpp"'
135 print '#include "d3dcommonshader.hpp"'
138 moduleNames = sys.argv[1:]
143 api.addModule(dxgi.dxgi)
145 if 'd3d10' in moduleNames:
146 if 'd3d10_1' in moduleNames:
147 print r'#include "d3d10_1imports.hpp"'
148 api.addModule(d3d10_1.d3d10_1)
150 print r'#include "d3d10imports.hpp"'
151 print r'#include "d3d10size.hpp"'
152 api.addModule(d3d10.d3d10)
154 if 'd3d11' in moduleNames:
155 print r'#include "d3d11imports.hpp"'
156 if 'd3d11_1' in moduleNames:
157 print '#include <d3d11_1.h>'
158 from specs import d3d11_1
159 print r'#include "d3d11size.hpp"'
160 api.addModule(d3d11.d3d11)
162 tracer = D3DCommonTracer()