blob: b1fed0c5151c34fed8fdc2f4117af010aec99c08 [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
34from specs import d3d10_1
35from specs import d3d11
José Fonsecaff0b1ee2012-10-25 12:17:39 +010036
37
38class 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
José Fonseca419d7682013-02-22 10:24:31 +000046 # Serialize the swapchain dimensions
José Fonseca2b6d24e2013-02-22 15:00:26 +000047 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'):
José Fonseca419d7682013-02-22 10:24:31 +000054 # Obtain size from the window
55 print r' RECT _rect;'
José Fonseca2b6d24e2013-02-22 15:00:26 +000056 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;'
José Fonseca419d7682013-02-22 10:24:31 +000059 print r' }'
José Fonseca2b6d24e2013-02-22 15:00:26 +000060 print r' if (%s->BufferDesc.Height == 0) {' % arg.name
61 print r' _SwapChainDesc.BufferDesc.Height = _rect.bottom - _rect.top;'
José Fonseca419d7682013-02-22 10:24:31 +000062 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))) {'
José Fonseca2b6d24e2013-02-22 15:00:26 +000068 print r' _SwapChainDesc.BufferDesc.Width = _OutputDesc.DesktopCoordinates.right - _OutputDesc.DesktopCoordinates.left;'
69 print r' _SwapChainDesc.BufferDesc.Height = _OutputDesc.DesktopCoordinates.bottom - _OutputDesc.DesktopCoordinates.top;'
José Fonseca419d7682013-02-22 10:24:31 +000070 print r' }'
José Fonseca2b6d24e2013-02-22 15:00:26 +000071 print r' _pSwapChainDesc = &_SwapChainDesc;'
José Fonseca419d7682013-02-22 10:24:31 +000072 print r' }'
José Fonseca2b6d24e2013-02-22 15:00:26 +000073 self.serializeValue(arg.type, '_pSwapChainDesc')
José Fonseca419d7682013-02-22 10:24:31 +000074 return
75
José Fonsecaff0b1ee2012-10-25 12:17:39 +010076 DllTracer.serializeArgValue(self, function, arg)
José Fonseca5abf5602013-05-30 14:00:44 +010077
78 # Interfaces that need book-keeping for maps
79 mapInterfaces = (
80 dxgi.IDXGISurface,
81 d3d10.ID3D10Resource,
82 d3d11.ID3D11Resource,
83 )
José Fonseca0168b512012-11-03 18:44:36 +000084
85 def enumWrapperInterfaceVariables(self, interface):
86 variables = DllTracer.enumWrapperInterfaceVariables(self, interface)
87
88 # Add additional members to track maps
José Fonseca5abf5602013-05-30 14:00:44 +010089 if interface.hasBase(*self.mapInterfaces):
José Fonseca0168b512012-11-03 18:44:36 +000090 variables += [
José Fonseca003b8be2013-05-29 19:59:40 +010091 ('_MAP_DESC', '_MapDesc', None),
José Fonseca0168b512012-11-03 18:44:36 +000092 ]
93
94 return variables
95
96 def implementWrapperInterfaceMethodBody(self, interface, base, method):
José Fonseca5abf5602013-05-30 14:00:44 +010097 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
José Fonseca0168b512012-11-03 18:44:36 +0000107 if method.name == 'Unmap':
José Fonseca5abf5602013-05-30 14:00:44 +0100108 print ' _MAP_DESC _MapDesc = %s->_MapDesc;' % pResource
109 #print r' os::log("%%p -> %%p+%%lu\n", %s,_MapDesc.pData, (unsigned long)_MapDesc.Size);' % pResource
José Fonseca003b8be2013-05-29 19:59:40 +0100110 print ' if (_MapDesc.Size && _MapDesc.pData) {'
José Fonseca6f0e3032014-06-25 01:00:35 +0100111 self.emit_memcpy('_MapDesc.pData', '_MapDesc.Size')
José Fonseca0168b512012-11-03 18:44:36 +0000112 print ' }'
113
114 DllTracer.implementWrapperInterfaceMethodBody(self, interface, base, method)
115
116 if method.name == 'Map':
117 # NOTE: recursive locks are explicitely forbidden
José Fonseca5abf5602013-05-30 14:00:44 +0100118 print ' _MAP_DESC _MapDesc;'
José Fonseca0168b512012-11-03 18:44:36 +0000119 print ' if (SUCCEEDED(_result)) {'
José Fonseca003b8be2013-05-29 19:59:40 +0100120 print ' _getMapDesc(_this, %s, _MapDesc);' % ', '.join(method.argNames())
José Fonseca0168b512012-11-03 18:44:36 +0000121 print ' } else {'
José Fonseca003b8be2013-05-29 19:59:40 +0100122 print ' _MapDesc.pData = NULL;'
123 print ' _MapDesc.Size = 0;'
José Fonseca0168b512012-11-03 18:44:36 +0000124 print ' }'
José Fonseca5abf5602013-05-30 14:00:44 +0100125 #print r' os::log("%%p <- %%p+%%lu\n", %s,_MapDesc.pData, (unsigned long)_MapDesc.Size);' % pResource
126 print ' %s->_MapDesc = _MapDesc;' % pResource
José Fonseca0168b512012-11-03 18:44:36 +0000127
128
José Fonseca20aa9352012-11-23 14:34:29 +0000129if __name__ == '__main__':
José Fonsecafc58d052014-06-13 12:47:19 +0100130 print r'#define INITGUID'
José Fonseca20aa9352012-11-23 14:34:29 +0000131 print
José Fonsecafc58d052014-06-13 12:47:19 +0100132 print r'#include "trace_writer_local.hpp"'
133 print r'#include "os.hpp"'
José Fonseca20aa9352012-11-23 14:34:29 +0000134 print
José Fonsecafc58d052014-06-13 12:47:19 +0100135 print r'#include "d3dcommonshader.hpp"'
José Fonseca20aa9352012-11-23 14:34:29 +0000136 print
José Fonsecafc58d052014-06-13 12:47:19 +0100137 print r'#include "d3d10imports.hpp"'
138 print r'#include "d3d10size.hpp"'
139 print r'#include "d3d11imports.hpp"'
140 print r'#include "d3d11size.hpp"'
141 print
José Fonseca20aa9352012-11-23 14:34:29 +0000142
143 api = API()
José Fonsecafc58d052014-06-13 12:47:19 +0100144 api.addModule(dxgi.dxgi)
145 api.addModule(d3d10.d3d10)
146 api.addModule(d3d10_1.d3d10_1)
147 api.addModule(d3d11.d3d11)
José Fonseca20aa9352012-11-23 14:34:29 +0000148
149 tracer = D3DCommonTracer()
150 tracer.traceApi(api)