blob: 36941dffb5979e242981e729ab70a8a8e585abf7 [file] [log] [blame]
José Fonsecaff0b1ee2012-10-25 12:17:39 +01001##########################################################################
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
José Fonseca20aa9352012-11-23 14:34:29 +000027import sys
José Fonsecaff0b1ee2012-10-25 12:17:39 +010028from dlltrace import DllTracer
José Fonseca5abf5602013-05-30 14:00:44 +010029from trace import getWrapperInterfaceName
José Fonsecaff0b1ee2012-10-25 12:17:39 +010030from specs import stdapi
José Fonseca20aa9352012-11-23 14:34:29 +000031from specs.stdapi import API
José Fonseca5abf5602013-05-30 14:00:44 +010032from specs import dxgi
33from specs import d3d10
José Fonseca5abf5602013-05-30 14:00:44 +010034from specs import d3d11
Jose Fonsecabab19212016-01-31 23:58:30 +000035from specs import dcomp
José Fonsecae354d8d2015-02-06 10:30:01 +000036from specs import d3d9
José Fonsecaff0b1ee2012-10-25 12:17:39 +010037
38
39class D3DCommonTracer(DllTracer):
40
41 def serializeArgValue(self, function, arg):
42 # Dump shaders as strings
43 if isinstance(arg.type, stdapi.Blob) and arg.name.startswith('pShaderBytecode'):
44 print ' DumpShader(trace::localWriter, %s, %s);' % (arg.name, arg.type.size)
45 return
46
José Fonseca419d7682013-02-22 10:24:31 +000047 # Serialize the swapchain dimensions
José Fonseca2b6d24e2013-02-22 15:00:26 +000048 if function.name == 'CreateSwapChain' and arg.name == 'pDesc' \
49 or arg.name == 'pSwapChainDesc':
50 print r' DXGI_SWAP_CHAIN_DESC *_pSwapChainDesc = NULL;'
51 print r' DXGI_SWAP_CHAIN_DESC _SwapChainDesc;'
52 print r' if (%s) {' % arg.name
53 print r' _SwapChainDesc = *%s;' % arg.name
54 if function.name != 'CreateSwapChain' or not self.interface.name.endswith('DWM'):
José Fonseca419d7682013-02-22 10:24:31 +000055 # Obtain size from the window
56 print r' RECT _rect;'
José Fonseca2b6d24e2013-02-22 15:00:26 +000057 print r' if (GetClientRect(%s->OutputWindow, &_rect)) {' % arg.name
58 print r' if (%s->BufferDesc.Width == 0) {' % arg.name
59 print r' _SwapChainDesc.BufferDesc.Width = _rect.right - _rect.left;'
José Fonseca419d7682013-02-22 10:24:31 +000060 print r' }'
José Fonseca2b6d24e2013-02-22 15:00:26 +000061 print r' if (%s->BufferDesc.Height == 0) {' % arg.name
62 print r' _SwapChainDesc.BufferDesc.Height = _rect.bottom - _rect.top;'
José Fonseca419d7682013-02-22 10:24:31 +000063 print r' }'
64 print r' }'
65 else:
66 # Obtain size from the output
67 print r' DXGI_OUTPUT_DESC _OutputDesc;'
68 print r' if (SUCCEEDED(pOutput->GetDesc(&_OutputDesc))) {'
José Fonseca2b6d24e2013-02-22 15:00:26 +000069 print r' _SwapChainDesc.BufferDesc.Width = _OutputDesc.DesktopCoordinates.right - _OutputDesc.DesktopCoordinates.left;'
70 print r' _SwapChainDesc.BufferDesc.Height = _OutputDesc.DesktopCoordinates.bottom - _OutputDesc.DesktopCoordinates.top;'
José Fonseca419d7682013-02-22 10:24:31 +000071 print r' }'
José Fonseca2b6d24e2013-02-22 15:00:26 +000072 print r' _pSwapChainDesc = &_SwapChainDesc;'
José Fonseca419d7682013-02-22 10:24:31 +000073 print r' }'
José Fonseca2b6d24e2013-02-22 15:00:26 +000074 self.serializeValue(arg.type, '_pSwapChainDesc')
José Fonseca419d7682013-02-22 10:24:31 +000075 return
76
José Fonseca04ffbed2014-07-23 13:57:14 +010077 # Serialize object names
José Fonseca04ffbed2014-07-23 13:57:14 +010078 if function.name == 'SetPrivateData' and arg.name == 'pData':
79 iid = function.args[0].name
80 print r' if (%s == WKPDID_D3DDebugObjectName) {' % iid
81 print r' trace::localWriter.writeString(static_cast<const char *>(pData), DataSize);'
82 print r' } else {'
83 DllTracer.serializeArgValue(self, function, arg)
84 print r' }'
85 return
86
José Fonsecaff0b1ee2012-10-25 12:17:39 +010087 DllTracer.serializeArgValue(self, function, arg)
José Fonseca5abf5602013-05-30 14:00:44 +010088
89 # Interfaces that need book-keeping for maps
90 mapInterfaces = (
91 dxgi.IDXGISurface,
92 d3d10.ID3D10Resource,
José Fonseca5abf5602013-05-30 14:00:44 +010093 )
José Fonseca0168b512012-11-03 18:44:36 +000094
95 def enumWrapperInterfaceVariables(self, interface):
96 variables = DllTracer.enumWrapperInterfaceVariables(self, interface)
97
98 # Add additional members to track maps
José Fonseca5abf5602013-05-30 14:00:44 +010099 if interface.hasBase(*self.mapInterfaces):
José Fonseca0168b512012-11-03 18:44:36 +0000100 variables += [
José Fonseca6a940052014-10-07 21:39:06 +0100101 ('_MAP_DESC', 'm_MapDesc', None),
102 ]
103 if interface.hasBase(d3d11.ID3D11DeviceContext):
104 variables += [
105 ('std::map< std::pair<ID3D11Resource *, UINT>, _MAP_DESC >', 'm_MapDescs', None),
José Fonseca0168b512012-11-03 18:44:36 +0000106 ]
107
108 return variables
109
110 def implementWrapperInterfaceMethodBody(self, interface, base, method):
Jose Fonseca4713c3b2015-08-12 11:06:34 +0100111 if method.getArgByName('pInitialData'):
112 pDesc1 = method.getArgByName('pDesc1')
113 if pDesc1 is not None:
114 print r' %s pDesc = pDesc1;' % (pDesc1.type,)
115
José Fonseca5abf5602013-05-30 14:00:44 +0100116 if method.name in ('Map', 'Unmap'):
117 # On D3D11 Map/Unmap is not a resource method, but a context method instead.
118 resourceArg = method.getArgByName('pResource')
119 if resourceArg is None:
José Fonseca6a940052014-10-07 21:39:06 +0100120 print ' _MAP_DESC & _MapDesc = m_MapDesc;'
José Fonseca5abf5602013-05-30 14:00:44 +0100121 else:
José Fonseca6a940052014-10-07 21:39:06 +0100122 print ' _MAP_DESC & _MapDesc = m_MapDescs[std::pair<%s, UINT>(pResource, Subresource)];' % resourceArg.type
José Fonseca5abf5602013-05-30 14:00:44 +0100123
José Fonseca0168b512012-11-03 18:44:36 +0000124 if method.name == 'Unmap':
José Fonseca003b8be2013-05-29 19:59:40 +0100125 print ' if (_MapDesc.Size && _MapDesc.pData) {'
José Fonseca6f0e3032014-06-25 01:00:35 +0100126 self.emit_memcpy('_MapDesc.pData', '_MapDesc.Size')
José Fonseca0168b512012-11-03 18:44:36 +0000127 print ' }'
128
129 DllTracer.implementWrapperInterfaceMethodBody(self, interface, base, method)
130
131 if method.name == 'Map':
132 # NOTE: recursive locks are explicitely forbidden
133 print ' if (SUCCEEDED(_result)) {'
José Fonseca003b8be2013-05-29 19:59:40 +0100134 print ' _getMapDesc(_this, %s, _MapDesc);' % ', '.join(method.argNames())
José Fonseca0168b512012-11-03 18:44:36 +0000135 print ' } else {'
José Fonseca003b8be2013-05-29 19:59:40 +0100136 print ' _MapDesc.pData = NULL;'
137 print ' _MapDesc.Size = 0;'
José Fonseca0168b512012-11-03 18:44:36 +0000138 print ' }'
139
140
José Fonseca20aa9352012-11-23 14:34:29 +0000141if __name__ == '__main__':
Jose Fonsecabab19212016-01-31 23:58:30 +0000142 print r'#include "guids_defs.hpp"'
José Fonseca20aa9352012-11-23 14:34:29 +0000143 print
José Fonsecafc58d052014-06-13 12:47:19 +0100144 print r'#include "trace_writer_local.hpp"'
145 print r'#include "os.hpp"'
José Fonseca20aa9352012-11-23 14:34:29 +0000146 print
José Fonsecafc58d052014-06-13 12:47:19 +0100147 print r'#include "d3dcommonshader.hpp"'
José Fonseca20aa9352012-11-23 14:34:29 +0000148 print
José Fonsecafc58d052014-06-13 12:47:19 +0100149 print r'#include "d3d10imports.hpp"'
150 print r'#include "d3d10size.hpp"'
151 print r'#include "d3d11imports.hpp"'
152 print r'#include "d3d11size.hpp"'
Jose Fonsecabab19212016-01-31 23:58:30 +0000153 print r'#include "dcompimports.hpp"'
154 print r'#include "d2dimports.hpp" // WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT'
José Fonsecae354d8d2015-02-06 10:30:01 +0000155 print r'#include "d3d9imports.hpp" // D3DPERF_*'
José Fonsecafc58d052014-06-13 12:47:19 +0100156 print
José Fonseca20aa9352012-11-23 14:34:29 +0000157
158 api = API()
José Fonsecafc58d052014-06-13 12:47:19 +0100159 api.addModule(dxgi.dxgi)
160 api.addModule(d3d10.d3d10)
Jose Fonsecaa92e0c42015-03-14 10:49:23 +0000161 api.addModule(d3d10.d3d10_1)
José Fonsecafc58d052014-06-13 12:47:19 +0100162 api.addModule(d3d11.d3d11)
Jose Fonsecabab19212016-01-31 23:58:30 +0000163 api.addModule(dcomp.dcomp)
José Fonsecae354d8d2015-02-06 10:30:01 +0000164 api.addModule(d3d9.d3dperf)
José Fonseca20aa9352012-11-23 14:34:29 +0000165
166 tracer = D3DCommonTracer()
167 tracer.traceApi(api)