José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 1 | ########################################################################## |
| 2 | # |
| 3 | # Copyright 2011 Jose Fonseca |
| 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 | """D3D retracer generator.""" |
| 28 | |
| 29 | |
José Fonseca | 6f81033 | 2012-11-11 10:05:09 +0000 | [diff] [blame] | 30 | import sys |
José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 31 | from dllretrace import DllRetracer as Retracer |
José Fonseca | 75cbb8c | 2013-02-12 16:19:23 +0000 | [diff] [blame] | 32 | import specs.dxgi |
José Fonseca | 6f81033 | 2012-11-11 10:05:09 +0000 | [diff] [blame] | 33 | from specs.stdapi import API |
José Fonseca | 3be2c67 | 2015-02-06 15:36:40 +0000 | [diff] [blame] | 34 | from specs.winapi import LPCSTR |
José Fonseca | 6f81033 | 2012-11-11 10:05:09 +0000 | [diff] [blame] | 35 | from specs.dxgi import dxgi |
Jose Fonseca | a92e0c4 | 2015-03-14 10:49:23 +0000 | [diff] [blame] | 36 | from specs.d3d10 import d3d10, d3d10_1 |
José Fonseca | 6f81033 | 2012-11-11 10:05:09 +0000 | [diff] [blame] | 37 | from specs.d3d11 import d3d11 |
Jose Fonseca | feb8f7d | 2016-02-01 14:14:00 +0000 | [diff] [blame] | 38 | from specs.dcomp import dcomp |
José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 39 | |
| 40 | |
| 41 | class D3DRetracer(Retracer): |
| 42 | |
José Fonseca | e381485 | 2012-11-11 09:45:06 +0000 | [diff] [blame] | 43 | def retraceApi(self, api): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 44 | print('// Swizzling mapping for lock addresses, mapping a (pDeviceContext, pResource, Subresource) -> void *') |
| 45 | print('typedef std::pair< IUnknown *, UINT > SubresourceKey;') |
| 46 | print('static std::map< IUnknown *, std::map< SubresourceKey, void * > > g_Maps;') |
| 47 | print() |
José Fonseca | 73341c2 | 2012-11-24 13:04:42 +0000 | [diff] [blame] | 48 | self.table_name = 'd3dretrace::dxgi_callbacks' |
José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 49 | |
José Fonseca | e381485 | 2012-11-11 09:45:06 +0000 | [diff] [blame] | 50 | Retracer.retraceApi(self, api) |
José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 51 | |
José Fonseca | 4f49d21 | 2012-11-14 14:02:35 +0000 | [diff] [blame] | 52 | createDeviceFunctionNames = [ |
| 53 | "D3D10CreateDevice", |
| 54 | "D3D10CreateDeviceAndSwapChain", |
| 55 | "D3D10CreateDevice1", |
| 56 | "D3D10CreateDeviceAndSwapChain1", |
| 57 | "D3D11CreateDevice", |
| 58 | "D3D11CreateDeviceAndSwapChain", |
| 59 | ] |
José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 60 | |
José Fonseca | 4f49d21 | 2012-11-14 14:02:35 +0000 | [diff] [blame] | 61 | def invokeFunction(self, function): |
| 62 | if function.name in self.createDeviceFunctionNames: |
| 63 | # create windows as neccessary |
| 64 | if 'pSwapChainDesc' in function.argNames(): |
Danylo Piliaiev | e0bfba6 | 2019-06-06 13:36:08 +0300 | [diff] [blame] | 65 | print(r' if (pSwapChainDesc) {') |
| 66 | print(r' d3dretrace::createWindowForSwapChain(pSwapChainDesc);') |
| 67 | print(r' }') |
José Fonseca | 4f49d21 | 2012-11-14 14:02:35 +0000 | [diff] [blame] | 68 | |
José Fonseca | 4f49d21 | 2012-11-14 14:02:35 +0000 | [diff] [blame] | 69 | # Compensate for the fact we don't trace DXGI object creation |
| 70 | if function.name.startswith('D3D11CreateDevice'): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 71 | print(r' if (DriverType == D3D_DRIVER_TYPE_UNKNOWN && !pAdapter) {') |
| 72 | print(r' DriverType = D3D_DRIVER_TYPE_HARDWARE;') |
| 73 | print(r' }') |
José Fonseca | ea79919 | 2012-11-13 21:37:24 +0000 | [diff] [blame] | 74 | |
José Fonseca | 42b89fc | 2012-11-27 12:19:45 +0000 | [diff] [blame] | 75 | if function.name.startswith('D3D10CreateDevice'): |
José Fonseca | 7bcc96c | 2012-12-05 19:28:22 +0000 | [diff] [blame] | 76 | # Toggle debugging |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 77 | print(r' if (retrace::debug >= 2) {') |
| 78 | print(r' Flags |= D3D10_CREATE_DEVICE_DEBUG;') |
| 79 | print(r' } else if (retrace::debug < 0) {') |
| 80 | print(r' Flags &= ~D3D10_CREATE_DEVICE_DEBUG;') |
| 81 | print(r' }') |
José Fonseca | 7bcc96c | 2012-12-05 19:28:22 +0000 | [diff] [blame] | 82 | |
| 83 | # Force driver |
Jose Fonseca | ab709df | 2020-05-29 18:41:46 +0100 | [diff] [blame] | 84 | self.forceDriver('D3D10_DRIVER_TYPE_HARDWARE') |
José Fonseca | 7bcc96c | 2012-12-05 19:28:22 +0000 | [diff] [blame] | 85 | |
José Fonseca | 42b89fc | 2012-11-27 12:19:45 +0000 | [diff] [blame] | 86 | if function.name.startswith('D3D11CreateDevice'): |
José Fonseca | 7bcc96c | 2012-12-05 19:28:22 +0000 | [diff] [blame] | 87 | # Toggle debugging |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 88 | print(r' if (retrace::debug >= 2) {') |
| 89 | print(r' Flags |= D3D11_CREATE_DEVICE_DEBUG;') |
| 90 | print(r' } else if (retrace::debug < 0) {') |
| 91 | print(r' Flags &= ~D3D11_CREATE_DEVICE_DEBUG;') |
| 92 | print(r' }') |
| 93 | print(r' if (IsWindows8OrGreater()) {') |
| 94 | print(r' Flags |= D3D11_CREATE_DEVICE_DISABLE_GPU_TIMEOUT;') |
| 95 | print(r' }') |
José Fonseca | 7bcc96c | 2012-12-05 19:28:22 +0000 | [diff] [blame] | 96 | |
| 97 | # Force driver |
Jose Fonseca | ab709df | 2020-05-29 18:41:46 +0100 | [diff] [blame] | 98 | self.forceDriver('D3D_DRIVER_TYPE_UNKNOWN') |
José Fonseca | 42b89fc | 2012-11-27 12:19:45 +0000 | [diff] [blame] | 99 | |
José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 100 | Retracer.invokeFunction(self, function) |
| 101 | |
Jose Fonseca | f39fd60 | 2017-08-23 15:13:39 +0100 | [diff] [blame] | 102 | def doInvokeFunction(self, function): |
| 103 | Retracer.doInvokeFunction(self, function) |
| 104 | |
| 105 | # Handle missing debug layer. While it's possible to detect whether |
| 106 | # the debug layers are present, by creating a null device, and checking |
| 107 | # the result. It's simpler to retry. |
| 108 | if function.name.startswith('D3D10CreateDevice'): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 109 | print(r' if ((_result == E_FAIL || _result == DXGI_ERROR_SDK_COMPONENT_MISSING) && (Flags & D3D10_CREATE_DEVICE_DEBUG)) {') |
| 110 | print(r' retrace::warning(call) << "Direct3D 10.x SDK Debug Layer (d3d10sdklayers.dll) not available, continuing without debug output\n";') |
| 111 | print(r' Flags &= ~D3D10_CREATE_DEVICE_DEBUG;') |
Jose Fonseca | f39fd60 | 2017-08-23 15:13:39 +0100 | [diff] [blame] | 112 | Retracer.doInvokeFunction(self, function) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 113 | print(r' }') |
Jose Fonseca | f39fd60 | 2017-08-23 15:13:39 +0100 | [diff] [blame] | 114 | if function.name.startswith('D3D11CreateDevice'): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 115 | print(r' if ((_result == E_FAIL || _result == DXGI_ERROR_SDK_COMPONENT_MISSING) && (Flags & D3D11_CREATE_DEVICE_DEBUG)) {') |
| 116 | print(r' retrace::warning(call) << "Direct3D 11.x SDK Debug Layer (d3d11*sdklayers.dll) not available, continuing without debug output\n";') |
| 117 | print(r' Flags &= ~D3D11_CREATE_DEVICE_DEBUG;') |
Jose Fonseca | f39fd60 | 2017-08-23 15:13:39 +0100 | [diff] [blame] | 118 | Retracer.doInvokeFunction(self, function) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 119 | print(r' }') |
Jose Fonseca | f39fd60 | 2017-08-23 15:13:39 +0100 | [diff] [blame] | 120 | |
Jose Fonseca | d0094a2 | 2017-05-30 12:31:37 +0100 | [diff] [blame] | 121 | def handleFailure(self, interface, methodOrFunction): |
Jose Fonseca | 5c487ec | 2015-06-02 22:16:52 +0100 | [diff] [blame] | 122 | # Catch when device is removed, and report the reason. |
Jose Fonseca | d0094a2 | 2017-05-30 12:31:37 +0100 | [diff] [blame] | 123 | if interface is not None: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 124 | print(r' if (_result == DXGI_ERROR_DEVICE_REMOVED) {') |
Jose Fonseca | d0094a2 | 2017-05-30 12:31:37 +0100 | [diff] [blame] | 125 | getDeviceRemovedReasonMethod = interface.getMethodByName("GetDeviceRemovedReason") |
| 126 | if getDeviceRemovedReasonMethod is not None: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 127 | print(r' HRESULT _reason = _this->GetDeviceRemovedReason();') |
| 128 | print(r' retrace::failed(call, _reason);') |
Jose Fonseca | a42384c | 2018-01-12 15:37:52 +0000 | [diff] [blame] | 129 | getDeviceMethod = interface.getMethodByName("GetDevice") |
| 130 | if getDeviceMethod is not None and len(getDeviceMethod.args) == 1: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 131 | print(r' com_ptr<%s> _pDevice;' % getDeviceMethod.args[0].type.type.type) |
| 132 | print(r' _this->GetDevice(&_pDevice);') |
| 133 | print(r' HRESULT _reason = _pDevice->GetDeviceRemovedReason();') |
| 134 | print(r' retrace::failed(call, _reason);') |
| 135 | print(r' exit(EXIT_FAILURE);') |
| 136 | print(r' }') |
Jose Fonseca | 5c487ec | 2015-06-02 22:16:52 +0100 | [diff] [blame] | 137 | |
Jose Fonseca | d0094a2 | 2017-05-30 12:31:37 +0100 | [diff] [blame] | 138 | Retracer.handleFailure(self, interface, methodOrFunction) |
Jose Fonseca | 5c487ec | 2015-06-02 22:16:52 +0100 | [diff] [blame] | 139 | |
Jose Fonseca | ab709df | 2020-05-29 18:41:46 +0100 | [diff] [blame] | 140 | def forceDriver(self, driverType): |
José Fonseca | 82ea89d | 2012-12-05 19:34:26 +0000 | [diff] [blame] | 141 | # This can only work when pAdapter is NULL. For non-NULL pAdapter we |
| 142 | # need to override inside the EnumAdapters call below |
Jose Fonseca | ab709df | 2020-05-29 18:41:46 +0100 | [diff] [blame] | 143 | print(r' com_ptr<IDXGIFactory1> _pFactory;') |
| 144 | print(r' com_ptr<IDXGIAdapter> _pAdapter;') |
| 145 | print(r' if (pAdapter == nullptr && retrace::driver != retrace::DRIVER_DEFAULT) {') |
| 146 | print(r' _result = CreateDXGIFactory1(IID_IDXGIFactory1, (void **)&_pFactory);') |
| 147 | print(r' assert(SUCCEEDED(_result));') |
| 148 | print(r' _result = d3dretrace::createAdapter(_pFactory, IID_IDXGIAdapter1, (void **)&_pAdapter);') |
| 149 | print(r' pAdapter = _pAdapter;') |
| 150 | print(r' DriverType = %s;' % driverType) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 151 | print(r' Software = NULL;') |
| 152 | print(r' }') |
José Fonseca | 42b89fc | 2012-11-27 12:19:45 +0000 | [diff] [blame] | 153 | |
Jose Fonseca | 2d78bef | 2016-05-19 15:10:23 +0100 | [diff] [blame] | 154 | def doInvokeInterfaceMethod(self, interface, method): |
Jose Fonseca | 7f95b87 | 2020-04-29 19:48:15 +0100 | [diff] [blame] | 155 | if interface.name.startswith('IDXGIAdapter') and method.name == 'EnumOutputs': |
| 156 | print(r' if (Output != 0) {') |
| 157 | print(r' retrace::warning(call) << "ignoring output " << Output << "\n";') |
| 158 | print(r' Output = 0;') |
| 159 | print(r' }') |
| 160 | |
Jose Fonseca | 33eb5f3 | 2020-04-29 19:49:21 +0100 | [diff] [blame] | 161 | # GPU counters are vendor specific and likely to fail, so use a |
| 162 | # timestamp query instead, which is guaranteed to succeed |
| 163 | if method.name == 'CreateCounter': |
| 164 | if interface.name.startswith('ID3D10'): |
| 165 | print(r' D3D10_QUERY_DESC _queryDesc;') |
| 166 | print(r' _queryDesc.Query = D3D10_QUERY_TIMESTAMP;') |
| 167 | print(r' _queryDesc.MiscFlags = 0;') |
| 168 | print(r' _result = _this->CreateQuery(&_queryDesc, reinterpret_cast<ID3D10Query **>(ppCounter));') |
| 169 | return |
| 170 | if interface.name.startswith('ID3D11'): |
| 171 | print(r' D3D11_QUERY_DESC _queryDesc;') |
| 172 | print(r' _queryDesc.Query = D3D11_QUERY_TIMESTAMP;') |
| 173 | print(r' _queryDesc.MiscFlags = 0;') |
| 174 | print(r' _result = _this->CreateQuery(&_queryDesc, reinterpret_cast<ID3D11Query **>(ppCounter));') |
| 175 | return |
| 176 | |
Jose Fonseca | 2d78bef | 2016-05-19 15:10:23 +0100 | [diff] [blame] | 177 | Retracer.doInvokeInterfaceMethod(self, interface, method) |
| 178 | |
Jose Fonseca | 9579650 | 2018-11-20 13:11:31 +0000 | [diff] [blame] | 179 | # Force driver |
| 180 | if interface.name.startswith('IDXGIFactory') and method.name.startswith('EnumAdapters'): |
Jose Fonseca | ab709df | 2020-05-29 18:41:46 +0100 | [diff] [blame] | 181 | print(r' if (Adapter != 0) {') |
| 182 | print(r' retrace::warning(call) << "ignoring non-default adapter " << Adapter << "\n";') |
| 183 | print(r' Adapter = 0;') |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 184 | print(r' }') |
Jose Fonseca | ab709df | 2020-05-29 18:41:46 +0100 | [diff] [blame] | 185 | print(r' if (retrace::driver != retrace::DRIVER_DEFAULT) {') |
| 186 | print(r' _result = d3dretrace::createAdapter(_this, IID_IDXGIAdapter1, (void **)ppAdapter);') |
Jose Fonseca | 0aa0403 | 2020-05-22 20:51:24 +0100 | [diff] [blame] | 187 | print(r' } else {') |
Jose Fonseca | 9579650 | 2018-11-20 13:11:31 +0000 | [diff] [blame] | 188 | Retracer.doInvokeInterfaceMethod(self, interface, method) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 189 | print(r' }') |
Jose Fonseca | 9579650 | 2018-11-20 13:11:31 +0000 | [diff] [blame] | 190 | return |
| 191 | |
| 192 | if interface.name.startswith('IDXGIFactory') and method.name == 'CreateSoftwareAdapter': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 193 | print(r' const char *szSoftware = NULL;') |
| 194 | print(r' switch (retrace::driver) {') |
| 195 | print(r' case retrace::DRIVER_REFERENCE:') |
| 196 | print(r' szSoftware = "d3d11ref.dll";') |
| 197 | print(r' break;') |
| 198 | print(r' case retrace::DRIVER_MODULE:') |
| 199 | print(r' szSoftware = retrace::driverModule;') |
| 200 | print(r' break;') |
| 201 | print(r' case retrace::DRIVER_SOFTWARE:') |
| 202 | print(r' default:') |
| 203 | print(r' szSoftware = "d3d10warp.dll";') |
| 204 | print(r' break;') |
| 205 | print(r' }') |
| 206 | print(r' Module = LoadLibraryA("d3d10warp");') |
| 207 | print(r' if (!Module) {') |
| 208 | print(r' retrace::warning(call) << "failed to load " << szSoftware << "\n";') |
| 209 | print(r' }') |
Jose Fonseca | 9579650 | 2018-11-20 13:11:31 +0000 | [diff] [blame] | 210 | Retracer.doInvokeInterfaceMethod(self, interface, method) |
| 211 | |
Jose Fonseca | 2d78bef | 2016-05-19 15:10:23 +0100 | [diff] [blame] | 212 | # Keep retrying ID3D11VideoContext::DecoderBeginFrame when returns E_PENDING |
| 213 | if interface.name == 'ID3D11VideoContext' and method.name == 'DecoderBeginFrame': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 214 | print(r' while (_result == D3DERR_WASSTILLDRAWING || _result == E_PENDING) {') |
| 215 | print(r' Sleep(1);') |
Jose Fonseca | 2d78bef | 2016-05-19 15:10:23 +0100 | [diff] [blame] | 216 | Retracer.doInvokeInterfaceMethod(self, interface, method) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 217 | print(r' }') |
Jose Fonseca | 2d78bef | 2016-05-19 15:10:23 +0100 | [diff] [blame] | 218 | |
José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 219 | def invokeInterfaceMethod(self, interface, method): |
| 220 | # keep track of the last used device for state dumping |
José Fonseca | 944088e | 2012-11-20 14:47:03 +0000 | [diff] [blame] | 221 | if interface.name in ('ID3D10Device', 'ID3D10Device1'): |
| 222 | if method.name == 'Release': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 223 | print(r' if (call.ret->toUInt() == 0) {') |
| 224 | print(r' d3d10Dumper.unbindDevice(_this);') |
| 225 | print(r' }') |
José Fonseca | 944088e | 2012-11-20 14:47:03 +0000 | [diff] [blame] | 226 | else: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 227 | print(r' d3d10Dumper.bindDevice(_this);') |
Jose Fonseca | 4a1c7aa | 2015-08-10 16:53:49 +0100 | [diff] [blame] | 228 | if interface.name.startswith('ID3D11DeviceContext'): |
José Fonseca | 5773beb | 2012-11-14 11:46:58 +0000 | [diff] [blame] | 229 | if method.name == 'Release': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 230 | print(r' if (call.ret->toUInt() == 0) {') |
| 231 | print(r' d3d11Dumper.unbindDevice(_this);') |
| 232 | print(r' }') |
José Fonseca | 5773beb | 2012-11-14 11:46:58 +0000 | [diff] [blame] | 233 | else: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 234 | print(r' d3d11Dumper.bindDevice(_this);') |
José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 235 | |
José Fonseca | 1e309b4 | 2014-09-18 11:08:09 +0100 | [diff] [blame] | 236 | # intercept private interfaces |
José Fonseca | d59843c | 2014-08-22 16:59:25 +0100 | [diff] [blame] | 237 | if method.name == 'QueryInterface': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 238 | print(r' if (!d3dretrace::overrideQueryInterface(_this, riid, ppvObj, &_result)) {') |
José Fonseca | 75cbb8c | 2013-02-12 16:19:23 +0000 | [diff] [blame] | 239 | Retracer.invokeInterfaceMethod(self, interface, method) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 240 | print(r' }') |
José Fonseca | 75cbb8c | 2013-02-12 16:19:23 +0000 | [diff] [blame] | 241 | return |
| 242 | |
José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 243 | # create windows as neccessary |
| 244 | if method.name == 'CreateSwapChain': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 245 | print(r' d3dretrace::createWindowForSwapChain(pDesc);') |
Jose Fonseca | dafb4ea | 2015-08-10 14:40:22 +0100 | [diff] [blame] | 246 | if method.name == 'CreateSwapChainForHwnd': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 247 | print(r' hWnd = d3dretrace::createWindow(pDesc->Width, pDesc->Height);') |
| 248 | print(r' // DXGI_SCALING_NONE is only supported on Win8 and beyond') |
| 249 | print(r' if (pDesc->Scaling == DXGI_SCALING_NONE && !IsWindows8OrGreater()) {') |
| 250 | print(r' pDesc->Scaling = DXGI_SCALING_STRETCH;') |
| 251 | print(r' }') |
José Fonseca | e23a6be | 2014-09-14 20:30:00 +0100 | [diff] [blame] | 252 | if method.name == 'CreateSwapChainForComposition': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 253 | print(r' HWND hWnd = d3dretrace::createWindow(pDesc->Width, pDesc->Height);') |
| 254 | print(r' _result = _this->CreateSwapChainForHwnd(pDevice, hWnd, pDesc, NULL, pRestrictToOutput, ppSwapChain);') |
Jose Fonseca | 5c487ec | 2015-06-02 22:16:52 +0100 | [diff] [blame] | 255 | self.checkResult(interface, method) |
José Fonseca | e23a6be | 2014-09-14 20:30:00 +0100 | [diff] [blame] | 256 | return |
Jose Fonseca | feb8f7d | 2016-02-01 14:14:00 +0000 | [diff] [blame] | 257 | if method.name == 'CreateTargetForHwnd': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 258 | print(r' hwnd = d3dretrace::createWindow(1024, 768);') |
José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 259 | |
José Fonseca | 7618cb9 | 2014-08-28 16:00:48 +0100 | [diff] [blame] | 260 | if method.name == 'SetFullscreenState': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 261 | print(r' if (retrace::forceWindowed) {') |
| 262 | print(r' DXGI_SWAP_CHAIN_DESC Desc;') |
| 263 | print(r' _this->GetDesc(&Desc);') |
| 264 | print(r' if (Desc.BufferDesc.Format != DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM) {') |
| 265 | print(r' Fullscreen = FALSE;') |
| 266 | print(r' pTarget = nullptr;') |
| 267 | print(r' }') |
| 268 | print(r' }') |
José Fonseca | 7618cb9 | 2014-08-28 16:00:48 +0100 | [diff] [blame] | 269 | |
José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 270 | # notify frame has been completed |
Jose Fonseca | ced9c1c | 2015-08-10 15:10:37 +0100 | [diff] [blame] | 271 | if interface.name.startswith('IDXGISwapChain') and method.name.startswith('Present'): |
| 272 | if interface.name.startswith('IDXGISwapChainDWM'): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 273 | print(r' com_ptr<IDXGISwapChain> pSwapChain;') |
| 274 | print(r' if (SUCCEEDED(_this->QueryInterface(IID_IDXGISwapChain, (void **) &pSwapChain))) {') |
| 275 | print(r' dxgiDumper.bindDevice(pSwapChain);') |
| 276 | print(r' } else {') |
| 277 | print(r' assert(0);') |
| 278 | print(r' }') |
José Fonseca | 29d4bda | 2014-02-28 17:50:24 +0000 | [diff] [blame] | 279 | else: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 280 | print(r' dxgiDumper.bindDevice(_this);') |
Jose Fonseca | 0f541f4 | 2019-07-03 13:46:05 +0100 | [diff] [blame] | 281 | print(r' if ((Flags & DXGI_PRESENT_TEST) == 0) {') |
| 282 | print(r' retrace::frameComplete(call);') |
| 283 | print(r' }') |
José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 284 | |
| 285 | if 'pSharedResource' in method.argNames(): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 286 | print(r' if (pSharedResource) {') |
| 287 | print(r' retrace::warning(call) << "shared surfaces unsupported\n";') |
| 288 | print(r' pSharedResource = NULL;') |
| 289 | print(r' }') |
José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 290 | |
José Fonseca | e23a6be | 2014-09-14 20:30:00 +0100 | [diff] [blame] | 291 | if interface.name.startswith('ID3D10Device') and method.name.startswith('OpenSharedResource'): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 292 | print(r' retrace::warning(call) << "replacing shared resource with checker pattern\n";') |
| 293 | print(r' _result = d3dretrace::createSharedResource(_this, ReturnedInterface, ppResource);') |
Jose Fonseca | 5c487ec | 2015-06-02 22:16:52 +0100 | [diff] [blame] | 294 | self.checkResult(interface, method) |
José Fonseca | 999284f | 2013-02-19 13:29:26 +0000 | [diff] [blame] | 295 | return |
Jose Fonseca | 559b5f8 | 2015-07-17 16:58:50 +0100 | [diff] [blame] | 296 | if interface.name.startswith('ID3D11Device') and method.name == 'OpenSharedResource': |
| 297 | # Some applications (e.g., video playing in IE11) create shared resources within the same process. |
| 298 | # TODO: Generalize to other OpenSharedResource variants |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 299 | print(r' retrace::map<HANDLE>::const_iterator it = _shared_handle_map.find(hResource);') |
| 300 | print(r' if (it == _shared_handle_map.end()) {') |
| 301 | print(r' retrace::warning(call) << "replacing shared resource with checker pattern\n";') |
| 302 | print(r' _result = d3dretrace::createSharedResource(_this, ReturnedInterface, ppResource);') |
Jose Fonseca | 559b5f8 | 2015-07-17 16:58:50 +0100 | [diff] [blame] | 303 | self.checkResult(interface, method) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 304 | print(r' } else {') |
| 305 | print(r' hResource = it->second;') |
Jose Fonseca | 559b5f8 | 2015-07-17 16:58:50 +0100 | [diff] [blame] | 306 | Retracer.invokeInterfaceMethod(self, interface, method) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 307 | print(r' }') |
Jose Fonseca | 559b5f8 | 2015-07-17 16:58:50 +0100 | [diff] [blame] | 308 | return |
José Fonseca | 2b66b93 | 2014-07-30 17:31:52 +0100 | [diff] [blame] | 309 | if interface.name.startswith('ID3D11Device') and method.name.startswith('OpenSharedResource'): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 310 | print(r' retrace::warning(call) << "replacing shared resource with checker pattern\n";') |
| 311 | print(r' _result = d3dretrace::createSharedResource(_this, ReturnedInterface, ppResource);') |
José Fonseca | 2b66b93 | 2014-07-30 17:31:52 +0100 | [diff] [blame] | 312 | if method.name == 'OpenSharedResourceByName': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 313 | print(r' (void)lpName;') |
| 314 | print(r' (void)dwDesiredAccess;') |
Jose Fonseca | df91377 | 2015-07-17 16:54:47 +0100 | [diff] [blame] | 315 | else: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 316 | print(r' (void)hResource;') |
Jose Fonseca | 5c487ec | 2015-06-02 22:16:52 +0100 | [diff] [blame] | 317 | self.checkResult(interface, method) |
José Fonseca | 2b66b93 | 2014-07-30 17:31:52 +0100 | [diff] [blame] | 318 | return |
José Fonseca | 999284f | 2013-02-19 13:29:26 +0000 | [diff] [blame] | 319 | |
| 320 | if method.name == 'Map': |
| 321 | # Reset _DO_NOT_WAIT flags. Otherwise they may fail, and we have no |
| 322 | # way to cope with it (other than retry). |
| 323 | mapFlagsArg = method.getArgByName('MapFlags') |
| 324 | for flag in mapFlagsArg.type.values: |
| 325 | if flag.endswith('_MAP_FLAG_DO_NOT_WAIT'): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 326 | print(r' MapFlags &= ~%s;' % flag) |
José Fonseca | 999284f | 2013-02-19 13:29:26 +0000 | [diff] [blame] | 327 | |
José Fonseca | 7af569a | 2014-09-04 19:08:45 +0100 | [diff] [blame] | 328 | if method.name.startswith('UpdateSubresource'): |
José Fonseca | c9cc24e | 2014-06-13 19:06:51 +0100 | [diff] [blame] | 329 | # The D3D10 debug layer is buggy (or at least inconsistent with the |
| 330 | # runtime), as it seems to estimate and enforce the data size based on the |
| 331 | # SrcDepthPitch, even for non 3D textures, but in some traces |
| 332 | # SrcDepthPitch is garbagge for non 3D textures. |
| 333 | # XXX: It also seems to expect padding bytes at the end of the last |
| 334 | # row, but we never record (or allocate) those... |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 335 | print(r' if (retrace::debug >= 2 && pDstBox && pDstBox->front == 0 && pDstBox->back == 1) {') |
| 336 | print(r' SrcDepthPitch = 0;') |
| 337 | print(r' }') |
José Fonseca | c9cc24e | 2014-06-13 19:06:51 +0100 | [diff] [blame] | 338 | |
José Fonseca | 0688d2e | 2014-08-19 20:43:21 +0100 | [diff] [blame] | 339 | if method.name == 'SetGammaControl': |
| 340 | # This method is only supported while in full-screen mode |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 341 | print(r' if (retrace::forceWindowed) {') |
| 342 | print(r' return;') |
| 343 | print(r' }') |
José Fonseca | 0688d2e | 2014-08-19 20:43:21 +0100 | [diff] [blame] | 344 | |
Jose Fonseca | 60e6514 | 2017-06-09 13:06:32 +0100 | [diff] [blame] | 345 | if method.name == 'GetData': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 346 | print(r' pData = _allocator.alloc(DataSize);') |
| 347 | print(r' do {') |
Jose Fonseca | 60e6514 | 2017-06-09 13:06:32 +0100 | [diff] [blame] | 348 | self.doInvokeInterfaceMethod(interface, method) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 349 | print(r' GetDataFlags = 0; // Prevent infinite loop') |
| 350 | print(r' } while (_result == S_FALSE);') |
Jose Fonseca | 60e6514 | 2017-06-09 13:06:32 +0100 | [diff] [blame] | 351 | self.checkResult(interface, method) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 352 | print(r' return;') |
Jose Fonseca | 60e6514 | 2017-06-09 13:06:32 +0100 | [diff] [blame] | 353 | |
Jose Fonseca | bfdf93e | 2019-06-26 13:03:27 +0100 | [diff] [blame] | 354 | if method.name in ('CreateTexture1D', 'CreateTexture2D', 'CreateTexture3D', 'CreateBuffer'): |
Jose Fonseca | 3d2b3fe | 2019-06-28 14:32:14 +0100 | [diff] [blame] | 355 | # We don't capture multiple processes, so ignore keyed mutexes to avoid deadlocks |
| 356 | print(r' if (pDesc->MiscFlags & D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX) {') |
| 357 | print(r' pDesc->MiscFlags &= ~D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;') |
| 358 | print(r' pDesc->MiscFlags |= D3D11_RESOURCE_MISC_SHARED;') |
| 359 | print(r' }') |
Jose Fonseca | bfdf93e | 2019-06-26 13:03:27 +0100 | [diff] [blame] | 360 | |
Jose Fonseca | 7da30bb | 2019-07-29 14:17:14 +0100 | [diff] [blame] | 361 | if method.name == 'ReleaseSync': |
| 362 | # We must flush the device that used this surface, as per |
| 363 | # https://docs.microsoft.com/en-us/windows/win32/api/d3d10/nf-d3d10-id3d10device-opensharedresource |
| 364 | print(r''' |
| 365 | com_ptr<ID3D11DeviceChild> pDeviceChild; |
| 366 | com_ptr<ID3D11Device> pDevice; |
| 367 | com_ptr<ID3D11DeviceContext> pDeviceContext; |
| 368 | HRESULT hr = _this->QueryInterface(IID_ID3D11DeviceChild, (void **)&pDeviceChild); |
| 369 | if (SUCCEEDED(hr)) { |
| 370 | pDeviceChild->GetDevice(&pDevice); |
| 371 | pDevice->GetImmediateContext(&pDeviceContext); |
| 372 | pDeviceContext->Flush(); |
| 373 | } else { |
| 374 | retrace::warning(call) << "ReleaseSync without D3D11 device\n"; |
| 375 | } |
| 376 | (void)Key; |
| 377 | (void)_result; |
| 378 | ''') |
| 379 | return |
José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 380 | |
Jose Fonseca | 7da30bb | 2019-07-29 14:17:14 +0100 | [diff] [blame] | 381 | Retracer.invokeInterfaceMethod(self, interface, method) |
Jose Fonseca | 4d5cfa4 | 2015-07-17 16:21:05 +0100 | [diff] [blame] | 382 | |
José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 383 | # process events after presents |
Jose Fonseca | ced9c1c | 2015-08-10 15:10:37 +0100 | [diff] [blame] | 384 | if interface.name.startswith('IDXGISwapChain') and method.name.startswith('Present'): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 385 | print(r' d3dretrace::processEvents();') |
José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 386 | |
José Fonseca | 6ca2008 | 2014-10-07 21:39:43 +0100 | [diff] [blame] | 387 | if method.name in ('Map', 'Unmap'): |
| 388 | if interface.name.startswith('ID3D11DeviceContext'): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 389 | print(' void * & _pbData = g_Maps[_this][SubresourceKey(pResource, Subresource)];') |
José Fonseca | 6ca2008 | 2014-10-07 21:39:43 +0100 | [diff] [blame] | 390 | else: |
| 391 | subresourceArg = method.getArgByName('Subresource') |
| 392 | if subresourceArg is None: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 393 | print(' UINT Subresource = 0;') |
| 394 | print(' void * & _pbData = g_Maps[0][SubresourceKey(_this, Subresource)];') |
José Fonseca | 6ca2008 | 2014-10-07 21:39:43 +0100 | [diff] [blame] | 395 | |
José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 396 | if method.name == 'Map': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 397 | print(' _MAP_DESC _MapDesc;') |
| 398 | print(' _getMapDesc(_this, %s, _MapDesc);' % ', '.join(method.argNames())) |
| 399 | print(' size_t _MappedSize = _MapDesc.Size;') |
| 400 | print(' if (_MapDesc.Size) {') |
| 401 | print(' _pbData = _MapDesc.pData;') |
Jeff Muizelaar | 97244f9 | 2013-11-19 15:17:45 -0500 | [diff] [blame] | 402 | if interface.name.startswith('ID3D11DeviceContext'): |
Jose Fonseca | 1e3c0f7 | 2015-07-20 21:50:42 +0100 | [diff] [blame] | 403 | # Prevent false warnings on 1D and 2D resources, since the |
| 404 | # pitches are often junk there... |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 405 | print(' _normalizeMap(pResource, pMappedResource);') |
Jeff Muizelaar | 97244f9 | 2013-11-19 15:17:45 -0500 | [diff] [blame] | 406 | else: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 407 | print(' _pbData = _MapDesc.pData;') |
| 408 | print(' } else {') |
| 409 | print(' return;') |
| 410 | print(' }') |
Zack Rusin | 1cb7b77 | 2018-02-09 11:36:11 -0500 | [diff] [blame] | 411 | |
José Fonseca | 610942b | 2012-11-08 10:46:03 +0000 | [diff] [blame] | 412 | if method.name == 'Unmap': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 413 | print(' if (_pbData) {') |
| 414 | print(' retrace::delRegionByPointer(_pbData);') |
| 415 | print(' _pbData = 0;') |
| 416 | print(' }') |
José Fonseca | 6f81033 | 2012-11-11 10:05:09 +0000 | [diff] [blame] | 417 | |
Jose Fonseca | 2d78bef | 2016-05-19 15:10:23 +0100 | [diff] [blame] | 418 | if interface.name.startswith('ID3D11VideoContext'): |
| 419 | if method.name == 'GetDecoderBuffer': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 420 | print(' if (*ppBuffer && *pBufferSize) {') |
| 421 | print(' g_Maps[nullptr][SubresourceKey(_this, Type)] = *ppBuffer;') |
| 422 | print(' }') |
Jose Fonseca | 2d78bef | 2016-05-19 15:10:23 +0100 | [diff] [blame] | 423 | if method.name == 'ReleaseDecoderBuffer': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 424 | print(' SubresourceKey _mappingKey(_this, Type);') |
| 425 | print(' void *_pBuffer = g_Maps[nullptr][_mappingKey];') |
| 426 | print(' if (_pBuffer) {') |
| 427 | print(' retrace::delRegionByPointer(_pBuffer);') |
| 428 | print(' g_Maps[nullptr][_mappingKey] = 0;') |
| 429 | print(' }') |
Jose Fonseca | 2d78bef | 2016-05-19 15:10:23 +0100 | [diff] [blame] | 430 | |
José Fonseca | 1d4fd14 | 2012-11-28 15:06:22 +0000 | [diff] [blame] | 431 | # Attach shader byte code for lookup |
| 432 | if 'pShaderBytecode' in method.argNames(): |
| 433 | ppShader = method.args[-1] |
| 434 | assert ppShader.output |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 435 | print(r' if (retrace::dumpingState && SUCCEEDED(_result)) {') |
| 436 | print(r' (*%s)->SetPrivateData(d3dstate::GUID_D3DSTATE, BytecodeLength, pShaderBytecode);' % ppShader.name) |
| 437 | print(r' }') |
José Fonseca | 1d4fd14 | 2012-11-28 15:06:22 +0000 | [diff] [blame] | 438 | |
Zack Rusin | 1cb7b77 | 2018-02-09 11:36:11 -0500 | [diff] [blame] | 439 | if method.name == 'CreateBuffer': |
| 440 | ppBuffer = method.args[-1] |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 441 | print(r' if (retrace::dumpingState && SUCCEEDED(_result)) {') |
| 442 | print(r' char label[32];') |
| 443 | print(r' _snprintf(label, sizeof label, "0x%%llx", call.arg(%u).toArray()->values[0]->toUIntPtr());' % ppBuffer.index) |
| 444 | print(r' (*%s)->SetPrivateData(WKPDID_D3DDebugObjectName, strlen(label)+1, label);' % ppBuffer.name) |
| 445 | print(r' }') |
Zack Rusin | 1cb7b77 | 2018-02-09 11:36:11 -0500 | [diff] [blame] | 446 | |
Jose Fonseca | 37f769f | 2017-06-16 17:57:39 +0100 | [diff] [blame] | 447 | def retraceInterfaceMethodBody(self, interface, method): |
| 448 | Retracer.retraceInterfaceMethodBody(self, interface, method) |
| 449 | |
| 450 | # Add pitch swizzling information to the region |
Jose Fonseca | b2754af | 2017-06-19 14:22:55 +0100 | [diff] [blame] | 451 | if method.name == 'Map' and interface.name not in ('ID3D10Buffer', 'ID3D10Texture1D'): |
| 452 | if interface.name.startswith('ID3D11DeviceContext'): |
| 453 | outArg = method.getArgByName('pMappedResource') |
| 454 | memberNames = ('pData', 'RowPitch', 'DepthPitch') |
| 455 | elif interface.name.startswith('ID3D10'): |
| 456 | outArg = method.args[-1] |
| 457 | memberNames = ('pData', 'RowPitch', 'DepthPitch') |
| 458 | elif interface.name == 'IDXGISurface': |
| 459 | outArg = method.getArgByName('pLockedRect') |
| 460 | memberNames = ('pBits', 'Pitch', None) |
| 461 | else: |
| 462 | raise NotImplementedError |
| 463 | struct = outArg.type.type |
| 464 | dataMemberName, rowPitchMemberName, depthPitchMemberName = memberNames |
| 465 | dataMemberIndex = struct.getMemberByName(dataMemberName) |
| 466 | rowPitchMemberIndex = struct.getMemberByName(rowPitchMemberName) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 467 | print(r' if (_pbData && %s->%s != 0) {' % (outArg.name, rowPitchMemberName)) |
| 468 | print(r' const trace::Array *_%s = call.arg(%u).toArray();' % (outArg.name, outArg.index)) |
| 469 | print(r' if (%s) {' % outArg.name) |
| 470 | print(r' const trace::Struct *_struct = _%s->values[0]->toStruct();' % (outArg.name)) |
| 471 | print(r' if (_struct) {') |
| 472 | print(r' unsigned long long traceAddress = _struct->members[%u]->toUIntPtr();' % dataMemberIndex) |
| 473 | print(r' int traceRowPitch = _struct->members[%u]->toSInt();' % rowPitchMemberIndex) |
| 474 | print(r' int realRowPitch = %s->%s;' % (outArg.name, rowPitchMemberName)) |
| 475 | print(r' if (realRowPitch && traceRowPitch != realRowPitch) {') |
| 476 | print(r' retrace::setRegionPitch(traceAddress, 2, traceRowPitch, realRowPitch);') |
| 477 | print(r' }') |
Jose Fonseca | b2754af | 2017-06-19 14:22:55 +0100 | [diff] [blame] | 478 | try: |
| 479 | depthPitchMemberIndex = struct.getMemberByName(depthPitchMemberName) |
| 480 | except ValueError: |
| 481 | assert len(struct.members) < 3 |
| 482 | pass |
| 483 | else: |
| 484 | assert depthPitchMemberName == 'DepthPitch' |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 485 | print(r' if (%s->DepthPitch) {' % outArg.name) |
| 486 | print(r' retrace::checkMismatch(call, "DepthPitch", _struct->members[%u], %s->DepthPitch);' % (struct.getMemberByName('DepthPitch'), outArg.name)) |
| 487 | print(r' }') |
| 488 | print(r' }') |
| 489 | print(r' }') |
| 490 | print(r' }') |
Jose Fonseca | 37f769f | 2017-06-16 17:57:39 +0100 | [diff] [blame] | 491 | |
| 492 | |
José Fonseca | 3be2c67 | 2015-02-06 15:36:40 +0000 | [diff] [blame] | 493 | def extractArg(self, function, arg, arg_type, lvalue, rvalue): |
| 494 | # Set object names |
| 495 | if function.name == 'SetPrivateData' and arg.name == 'pData': |
| 496 | iid = function.args[0].name |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 497 | print(r' if (%s != WKPDID_D3DDebugObjectName) {' % iid) |
| 498 | print(r' return;') |
| 499 | print(r' }') |
José Fonseca | 3be2c67 | 2015-02-06 15:36:40 +0000 | [diff] [blame] | 500 | # Interpret argument as string |
| 501 | Retracer.extractArg(self, function, arg, LPCSTR, lvalue, rvalue) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 502 | print(r' if (!pData) {') |
| 503 | print(r' return;') |
| 504 | print(r' }') |
| 505 | print(r' assert(DataSize >= strlen((const char *)pData));') |
| 506 | print(r' // Some applications include the trailing zero terminator in the data') |
| 507 | print(r' DataSize = strlen((const char *)pData);') |
José Fonseca | 3be2c67 | 2015-02-06 15:36:40 +0000 | [diff] [blame] | 508 | return |
| 509 | |
| 510 | Retracer.extractArg(self, function, arg, arg_type, lvalue, rvalue) |
| 511 | |
José Fonseca | 6f81033 | 2012-11-11 10:05:09 +0000 | [diff] [blame] | 512 | |
| 513 | def main(): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 514 | print(r'#define INITGUID') |
| 515 | print() |
| 516 | print(r'#include <string.h>') |
| 517 | print() |
| 518 | print(r'#include <iostream>') |
| 519 | print() |
| 520 | print(r'#include "d3dretrace.hpp"') |
| 521 | print(r'#include "os_version.hpp"') |
| 522 | print() |
| 523 | print(r'#include "d3dretrace_dxgi.hpp"') |
| 524 | print(r'#include "d3d10imports.hpp"') |
| 525 | print(r'#include "d3d10size.hpp"') |
| 526 | print(r'#include "d3d10state.hpp"') |
| 527 | print(r'#include "d3d11imports.hpp"') |
| 528 | print(r'#include "d3d11size.hpp"') |
| 529 | print(r'#include "dcompimports.hpp"') |
| 530 | print(r'#include "d3dstate.hpp"') |
| 531 | print(r'#include "d3d9imports.hpp" // D3DERR_WASSTILLDRAWING') |
| 532 | print() |
| 533 | print('''static d3dretrace::D3DDumper<IDXGISwapChain> dxgiDumper;''') |
| 534 | print('''static d3dretrace::D3DDumper<ID3D10Device> d3d10Dumper;''') |
| 535 | print('''static d3dretrace::D3DDumper<ID3D11DeviceContext> d3d11Dumper;''') |
| 536 | print() |
José Fonseca | 6f81033 | 2012-11-11 10:05:09 +0000 | [diff] [blame] | 537 | |
| 538 | api = API() |
José Fonseca | 50bee95 | 2015-02-07 22:32:19 +0000 | [diff] [blame] | 539 | api.addModule(dxgi) |
| 540 | api.addModule(d3d10) |
| 541 | api.addModule(d3d10_1) |
| 542 | api.addModule(d3d11) |
Jose Fonseca | feb8f7d | 2016-02-01 14:14:00 +0000 | [diff] [blame] | 543 | api.addModule(dcomp) |
José Fonseca | fc58d05 | 2014-06-13 12:47:19 +0100 | [diff] [blame] | 544 | |
José Fonseca | 6f81033 | 2012-11-11 10:05:09 +0000 | [diff] [blame] | 545 | retracer = D3DRetracer() |
| 546 | retracer.retraceApi(api) |
| 547 | |
| 548 | |
| 549 | if __name__ == '__main__': |
| 550 | main() |