blob: c2b826a7b3b2d94de3fb1d19cb15fecb652d8ec1 [file] [log] [blame]
José Fonseca4106eb42011-09-21 08:12: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é Fonseca54f304a2012-01-14 19:33:08 +000027from dlltrace import DllTracer
José Fonseca04ac2fe2013-04-25 16:01:48 +010028from specs.stdapi import API, Pointer, ObjPointer
José Fonsecae354d8d2015-02-06 10:30:01 +000029from specs.d3d9 import d3d9, D3DSHADER9, IDirect3DSwapChain9Ex, d3dperf
Jose Fonsecaf2a13052015-07-16 12:56:54 +010030from specs.dxva2 import dxva2
José Fonseca12ac4282012-07-25 20:47:20 +010031
José Fonseca4106eb42011-09-21 08:12:39 +010032
33class D3D9Tracer(DllTracer):
34
José Fonseca54f304a2012-01-14 19:33:08 +000035 def serializeArgValue(self, function, arg):
José Fonseca4106eb42011-09-21 08:12:39 +010036 # Dump shaders as strings
José Fonseca112a1322012-04-27 17:15:32 +010037 if arg.type is D3DSHADER9:
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010038 print(' DumpShader(trace::localWriter, %s);' % (arg.name))
José Fonseca4106eb42011-09-21 08:12:39 +010039 return
40
José Fonseca54f304a2012-01-14 19:33:08 +000041 DllTracer.serializeArgValue(self, function, arg)
José Fonseca4106eb42011-09-21 08:12:39 +010042
José Fonseca04ac2fe2013-04-25 16:01:48 +010043 def wrapArg(self, function, arg):
44 # Correctly handle the wrapping of IDirect3DSwapChain9Ex objects
45 if function.name in ('GetSwapChain', 'CreateAdditionalSwapChain') \
46 and self.interface.name == 'IDirect3DDevice9Ex' \
47 and arg.name == 'pSwapChain':
48 self.wrapValue(Pointer(ObjPointer(IDirect3DSwapChain9Ex)), '((IDirect3DSwapChain9Ex**)pSwapChain)')
49 return
50
51 DllTracer.wrapArg(self, function, arg)
52
José Fonsecaacc90622012-05-02 13:10:07 +010053 def enumWrapperInterfaceVariables(self, interface):
54 variables = DllTracer.enumWrapperInterfaceVariables(self, interface)
José Fonseca0423d2c2012-01-20 19:16:17 +000055
José Fonseca3dfd4572012-11-03 16:58:34 +000056 # Add additional members to track locks
José Fonseca6d5372b2012-04-30 23:33:02 +010057 if interface.getMethodByName('Lock') is not None or \
José Fonseca93fa73a2012-05-01 22:28:28 +010058 interface.getMethodByName('LockRect') is not None or \
59 interface.getMethodByName('LockBox') is not None:
Jose Fonsecaef26cb82016-04-27 11:58:18 +010060 if interface.base.name == 'IDirect3DBaseTexture9':
Pavel Iline540b632014-10-12 15:09:57 +030061 variables += [
62 ('std::map<UINT, std::pair<size_t, VOID *> >', '_MappedData', 'std::map<UINT, std::pair<size_t, VOID *> >()'),
63 ]
64 else:
65 variables += [
66 ('size_t', '_MappedSize', '0'),
67 ('VOID *', 'm_pbData', '0'),
68 ]
José Fonseca0423d2c2012-01-20 19:16:17 +000069
Jose Fonsecaf6757272016-05-13 07:23:45 -070070 if interface.name == 'IDirectXVideoDecoder':
71 variables += [
72 ('std::map<UINT, std::pair<void *, UINT> >', '_MappedData', None),
73 ]
74
José Fonsecaacc90622012-05-02 13:10:07 +010075 return variables
José Fonsecad275d0a2012-04-30 23:18:05 +010076
José Fonseca4220b1b2012-02-03 19:05:29 +000077 def implementWrapperInterfaceMethodBody(self, interface, base, method):
José Fonseca93fa73a2012-05-01 22:28:28 +010078 if method.name in ('Unlock', 'UnlockRect', 'UnlockBox'):
Jose Fonsecaef26cb82016-04-27 11:58:18 +010079 if interface.base.name == 'IDirect3DBaseTexture9':
80 assert method.getArgByName('Level') is not None
Jose Fonsecaa0cd0972017-06-01 13:29:35 +010081 if method.getArgByName('FaceType'):
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010082 print(r' UINT _Key = static_cast<UINT>(FaceType) + Level*6;')
Jose Fonsecaa0cd0972017-06-01 13:29:35 +010083 else:
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010084 print(r' UINT _Key = Level;')
85 print(' std::map<UINT, std::pair<size_t, VOID *> >::iterator it = _MappedData.find(_Key);')
86 print(' if (it != _MappedData.end()) {')
Pavel Iline540b632014-10-12 15:09:57 +030087 self.emit_memcpy('(LPBYTE)it->second.second', 'it->second.first')
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010088 print(' _MappedData.erase(it);')
89 print(' }')
Pavel Iline540b632014-10-12 15:09:57 +030090 else:
Jose Fonsecaef26cb82016-04-27 11:58:18 +010091 assert method.getArgByName('Level') is None
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010092 print(' if (_MappedSize && m_pbData) {')
Pavel Iline540b632014-10-12 15:09:57 +030093 self.emit_memcpy('(LPBYTE)m_pbData', '_MappedSize')
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010094 print(' }')
José Fonseca0423d2c2012-01-20 19:16:17 +000095
Jose Fonsecaf6757272016-05-13 07:23:45 -070096 if interface.name == 'IDirectXVideoDecoder' and method.name == 'ReleaseBuffer':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010097 print(' std::map<UINT, std::pair<void *, UINT> >::iterator it = _MappedData.find(BufferType);')
98 print(' if (it != _MappedData.end()) {')
Jose Fonsecaf6757272016-05-13 07:23:45 -070099 self.emit_memcpy('it->second.first', 'it->second.second')
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100100 print(' _MappedData.erase(it);')
101 print(' }')
Jose Fonsecaf6757272016-05-13 07:23:45 -0700102
José Fonseca4220b1b2012-02-03 19:05:29 +0000103 DllTracer.implementWrapperInterfaceMethodBody(self, interface, base, method)
José Fonseca0423d2c2012-01-20 19:16:17 +0000104
José Fonseca6c77bd02012-05-02 13:15:39 +0100105 if method.name in ('Lock', 'LockRect', 'LockBox'):
Jose Fonsecaef26cb82016-04-27 11:58:18 +0100106 if interface.base.name == 'IDirect3DBaseTexture9':
107 assert method.getArgByName('Level') is not None
Jose Fonsecaa0cd0972017-06-01 13:29:35 +0100108 if method.getArgByName('FaceType'):
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100109 print(r' UINT _Key = static_cast<UINT>(FaceType) + Level*6;')
Jose Fonsecaa0cd0972017-06-01 13:29:35 +0100110 else:
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100111 print(r' UINT _Key = Level;')
112 print(' if (SUCCEEDED(_result) && !(Flags & D3DLOCK_READONLY)) {')
113 print(' size_t mappedSize;')
114 print(' VOID * pbData;')
115 print(' _getMapInfo(_this, %s, pbData, mappedSize);' % ', '.join(method.argNames()[:-1]))
116 print(' _MappedData[_Key] = std::make_pair(mappedSize, pbData);')
117 print(' } else {')
118 print(' _MappedData.erase(_Key);')
119 print(' }')
Pavel Iline540b632014-10-12 15:09:57 +0300120 else:
121 # FIXME: handle recursive locks
Jose Fonsecaef26cb82016-04-27 11:58:18 +0100122 assert method.getArgByName('Level') is None
Jose Fonsecac4fb8c92016-04-27 12:06:19 +0100123 if method.name == 'Lock':
124 # Ignore D3DLOCK_READONLY for buffers.
125 # https://github.com/apitrace/apitrace/issues/435
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100126 print(' if (SUCCEEDED(_result)) {')
Jose Fonsecac4fb8c92016-04-27 12:06:19 +0100127 else:
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100128 print(' if (SUCCEEDED(_result) && !(Flags & D3DLOCK_READONLY)) {')
129 print(' _getMapInfo(_this, %s, m_pbData, _MappedSize);' % ', '.join(method.argNames()[:-1]))
130 print(' } else {')
131 print(' m_pbData = NULL;')
132 print(' _MappedSize = 0;')
133 print(' }')
José Fonseca0423d2c2012-01-20 19:16:17 +0000134
Jose Fonsecaf6757272016-05-13 07:23:45 -0700135 if interface.name == 'IDirectXVideoDecoder' and method.name == 'GetBuffer':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100136 print(' if (SUCCEEDED(_result)) {')
137 print(' _MappedData[BufferType] = std::make_pair(*ppBuffer, *pBufferSize);')
138 print(' } else {')
139 print(' _MappedData[BufferType] = std::make_pair(nullptr, 0);')
140 print(' }')
Jose Fonsecaf6757272016-05-13 07:23:45 -0700141
José Fonseca4106eb42011-09-21 08:12:39 +0100142
143if __name__ == '__main__':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100144 print('#define INITGUID')
145 print()
146 print('#include "trace_writer_local.hpp"')
147 print('#include "os.hpp"')
148 print()
149 print('#include "d3d9imports.hpp"')
150 print('#include "d3d9size.hpp"')
151 print('#include "d3d9shader.hpp"')
152 print('#include "dxva2imports.hpp"')
153 print()
José Fonseca4106eb42011-09-21 08:12:39 +0100154
José Fonsecae354d8d2015-02-06 10:30:01 +0000155 d3d9.mergeModule(d3dperf)
156
José Fonseca72fb9ca2012-11-13 08:21:15 +0000157 api = API()
158 api.addModule(d3d9)
Jose Fonsecaf2a13052015-07-16 12:56:54 +0100159 api.addModule(dxva2)
José Fonseca72fb9ca2012-11-13 08:21:15 +0000160 tracer = D3D9Tracer()
161 tracer.traceApi(api)
Jose Fonseca80dc8462018-12-28 14:31:07 +0000162
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100163 print(r'EXTERN_C PUBLIC')
164 print(r'void __stdcall Direct3D9ForceHybridEnumeration(UINT uHybrid) {')
165 print(r' typedef void (WINAPI *PFNDIRECT3D9FORCEHYBRIDENUMERATION)(UINT);')
166 print(r' PFNDIRECT3D9FORCEHYBRIDENUMERATION pfnDirect3D9ForceHybridEnumeration =')
167 print(r' (PFNDIRECT3D9FORCEHYBRIDENUMERATION)g_modD3D9.getProcAddress(MAKEINTRESOURCEA(16));')
168 print(r' if (pfnDirect3D9ForceHybridEnumeration) {')
169 print(r' pfnDirect3D9ForceHybridEnumeration(uHybrid);')
170 print(r' } else {')
171 print(r' os::log("warning: ignoring call to unavailable function %s\n", __FUNCTION__);')
172 print(r' }')
173 print(r'}')
174 print()