]> git.cworth.org Git - apitrace/blob - wrappers/dxgitrace.py
retrace: Implement glxCopySubBufferMESA
[apitrace] / wrappers / dxgitrace.py
1 ##########################################################################
2 #
3 # Copyright 2008-2009 VMware, Inc.
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 import sys
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
36
37
38 class D3DCommonTracer(DllTracer):
39
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)
44             return
45
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
55                 print r'        RECT _rect;'
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;'
59                 print r'            }'
60                 print r'            if (%s->BufferDesc.Height == 0) {' % arg.name
61                 print r'                _SwapChainDesc.BufferDesc.Height = _rect.bottom - _rect.top;'
62                 print r'            }'
63                 print r'        }'
64             else:
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;'
70                 print r'        }'
71             print r'        _pSwapChainDesc = &_SwapChainDesc;'
72             print r'    }'
73             self.serializeValue(arg.type, '_pSwapChainDesc')
74             return
75
76         DllTracer.serializeArgValue(self, function, arg)
77
78     # Interfaces that need book-keeping for maps
79     mapInterfaces = (
80         dxgi.IDXGISurface,
81         d3d10.ID3D10Resource,
82         d3d11.ID3D11Resource,
83     )
84     
85     def enumWrapperInterfaceVariables(self, interface):
86         variables = DllTracer.enumWrapperInterfaceVariables(self, interface)
87         
88         # Add additional members to track maps
89         if interface.hasBase(*self.mapInterfaces):
90             variables += [
91                 ('_MAP_DESC', '_MapDesc', None),
92             ]
93
94         return variables
95
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:
101                 pResource = 'this'
102             else:
103                 wrapperInterfaceName = getWrapperInterfaceName(resourceArg.type.type)
104                 print '    %s * _pResource = static_cast<%s*>(%s);' % (wrapperInterfaceName, wrapperInterfaceName, resourceArg.name)
105                 pResource = '_pResource'
106
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')
112             print '    }'
113
114         DllTracer.implementWrapperInterfaceMethodBody(self, interface, base, method)
115
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())
121             print '    } else {'
122             print '        _MapDesc.pData = NULL;'
123             print '        _MapDesc.Size = 0;'
124             print '    }'
125             #print r'    os::log("%%p <- %%p+%%lu\n", %s,_MapDesc.pData, (unsigned long)_MapDesc.Size);' % pResource
126             print '    %s->_MapDesc = _MapDesc;' % pResource
127
128
129 if __name__ == '__main__':
130     print '#define INITGUID'
131     print
132     print '#include "trace_writer_local.hpp"'
133     print '#include "os.hpp"'
134     print
135     print '#include "d3dcommonshader.hpp"'
136     print
137
138     moduleNames = sys.argv[1:]
139
140     api = API()
141     
142     if moduleNames:
143         api.addModule(dxgi.dxgi)
144     
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)
149         else:
150             print r'#include "d3d10imports.hpp"'
151         print r'#include "d3d10size.hpp"'
152         api.addModule(d3d10.d3d10)
153
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)
161
162     tracer = D3DCommonTracer()
163     tracer.traceApi(api)