José Fonseca | ff0b1ee | 2012-10-25 12:17:39 +0100 | [diff] [blame] | 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 | |
José Fonseca | 20aa935 | 2012-11-23 14:34:29 +0000 | [diff] [blame] | 27 | import sys |
José Fonseca | ff0b1ee | 2012-10-25 12:17:39 +0100 | [diff] [blame] | 28 | from dlltrace import DllTracer |
| 29 | from specs import stdapi |
José Fonseca | 20aa935 | 2012-11-23 14:34:29 +0000 | [diff] [blame] | 30 | from specs.stdapi import API |
| 31 | from specs.dxgi import dxgi |
| 32 | from specs.d3d10 import d3d10 |
| 33 | from specs.d3d10_1 import d3d10_1 |
| 34 | from specs.d3d11 import d3d11 |
José Fonseca | ff0b1ee | 2012-10-25 12:17:39 +0100 | [diff] [blame] | 35 | |
| 36 | |
| 37 | class D3DCommonTracer(DllTracer): |
| 38 | |
| 39 | def serializeArgValue(self, function, arg): |
| 40 | # Dump shaders as strings |
| 41 | if isinstance(arg.type, stdapi.Blob) and arg.name.startswith('pShaderBytecode'): |
| 42 | print ' DumpShader(trace::localWriter, %s, %s);' % (arg.name, arg.type.size) |
| 43 | return |
| 44 | |
José Fonseca | 419d768 | 2013-02-22 10:24:31 +0000 | [diff] [blame] | 45 | # Serialize the swapchain dimensions |
José Fonseca | 2b6d24e | 2013-02-22 15:00:26 +0000 | [diff] [blame] | 46 | if function.name == 'CreateSwapChain' and arg.name == 'pDesc' \ |
| 47 | or arg.name == 'pSwapChainDesc': |
| 48 | print r' DXGI_SWAP_CHAIN_DESC *_pSwapChainDesc = NULL;' |
| 49 | print r' DXGI_SWAP_CHAIN_DESC _SwapChainDesc;' |
| 50 | print r' if (%s) {' % arg.name |
| 51 | print r' _SwapChainDesc = *%s;' % arg.name |
| 52 | if function.name != 'CreateSwapChain' or not self.interface.name.endswith('DWM'): |
José Fonseca | 419d768 | 2013-02-22 10:24:31 +0000 | [diff] [blame] | 53 | # Obtain size from the window |
| 54 | print r' RECT _rect;' |
José Fonseca | 2b6d24e | 2013-02-22 15:00:26 +0000 | [diff] [blame] | 55 | print r' if (GetClientRect(%s->OutputWindow, &_rect)) {' % arg.name |
| 56 | print r' if (%s->BufferDesc.Width == 0) {' % arg.name |
| 57 | print r' _SwapChainDesc.BufferDesc.Width = _rect.right - _rect.left;' |
José Fonseca | 419d768 | 2013-02-22 10:24:31 +0000 | [diff] [blame] | 58 | print r' }' |
José Fonseca | 2b6d24e | 2013-02-22 15:00:26 +0000 | [diff] [blame] | 59 | print r' if (%s->BufferDesc.Height == 0) {' % arg.name |
| 60 | print r' _SwapChainDesc.BufferDesc.Height = _rect.bottom - _rect.top;' |
José Fonseca | 419d768 | 2013-02-22 10:24:31 +0000 | [diff] [blame] | 61 | print r' }' |
| 62 | print r' }' |
| 63 | else: |
| 64 | # Obtain size from the output |
| 65 | print r' DXGI_OUTPUT_DESC _OutputDesc;' |
| 66 | print r' if (SUCCEEDED(pOutput->GetDesc(&_OutputDesc))) {' |
José Fonseca | 2b6d24e | 2013-02-22 15:00:26 +0000 | [diff] [blame] | 67 | print r' _SwapChainDesc.BufferDesc.Width = _OutputDesc.DesktopCoordinates.right - _OutputDesc.DesktopCoordinates.left;' |
| 68 | print r' _SwapChainDesc.BufferDesc.Height = _OutputDesc.DesktopCoordinates.bottom - _OutputDesc.DesktopCoordinates.top;' |
José Fonseca | 419d768 | 2013-02-22 10:24:31 +0000 | [diff] [blame] | 69 | print r' }' |
José Fonseca | 2b6d24e | 2013-02-22 15:00:26 +0000 | [diff] [blame] | 70 | print r' _pSwapChainDesc = &_SwapChainDesc;' |
José Fonseca | 419d768 | 2013-02-22 10:24:31 +0000 | [diff] [blame] | 71 | print r' }' |
José Fonseca | 2b6d24e | 2013-02-22 15:00:26 +0000 | [diff] [blame] | 72 | self.serializeValue(arg.type, '_pSwapChainDesc') |
José Fonseca | 419d768 | 2013-02-22 10:24:31 +0000 | [diff] [blame] | 73 | return |
| 74 | |
José Fonseca | ff0b1ee | 2012-10-25 12:17:39 +0100 | [diff] [blame] | 75 | DllTracer.serializeArgValue(self, function, arg) |
José Fonseca | 0168b51 | 2012-11-03 18:44:36 +0000 | [diff] [blame] | 76 | |
| 77 | def enumWrapperInterfaceVariables(self, interface): |
| 78 | variables = DllTracer.enumWrapperInterfaceVariables(self, interface) |
| 79 | |
| 80 | # Add additional members to track maps |
| 81 | if interface.getMethodByName('Map') is not None: |
| 82 | variables += [ |
José Fonseca | 003b8be | 2013-05-29 19:59:40 +0100 | [diff] [blame^] | 83 | ('_MAP_DESC', '_MapDesc', None), |
José Fonseca | 0168b51 | 2012-11-03 18:44:36 +0000 | [diff] [blame] | 84 | ] |
| 85 | |
| 86 | return variables |
| 87 | |
| 88 | def implementWrapperInterfaceMethodBody(self, interface, base, method): |
| 89 | if method.name == 'Unmap': |
José Fonseca | 003b8be | 2013-05-29 19:59:40 +0100 | [diff] [blame^] | 90 | print ' if (_MapDesc.Size && _MapDesc.pData) {' |
| 91 | self.emit_memcpy('_MapDesc.pData', '_MapDesc.pData', '_MapDesc.Size') |
José Fonseca | 0168b51 | 2012-11-03 18:44:36 +0000 | [diff] [blame] | 92 | print ' }' |
| 93 | |
| 94 | DllTracer.implementWrapperInterfaceMethodBody(self, interface, base, method) |
| 95 | |
| 96 | if method.name == 'Map': |
| 97 | # NOTE: recursive locks are explicitely forbidden |
| 98 | print ' if (SUCCEEDED(_result)) {' |
José Fonseca | 003b8be | 2013-05-29 19:59:40 +0100 | [diff] [blame^] | 99 | print ' _getMapDesc(_this, %s, _MapDesc);' % ', '.join(method.argNames()) |
José Fonseca | 0168b51 | 2012-11-03 18:44:36 +0000 | [diff] [blame] | 100 | print ' } else {' |
José Fonseca | 003b8be | 2013-05-29 19:59:40 +0100 | [diff] [blame^] | 101 | print ' _MapDesc.pData = NULL;' |
| 102 | print ' _MapDesc.Size = 0;' |
José Fonseca | 0168b51 | 2012-11-03 18:44:36 +0000 | [diff] [blame] | 103 | print ' }' |
| 104 | |
| 105 | |
José Fonseca | 20aa935 | 2012-11-23 14:34:29 +0000 | [diff] [blame] | 106 | if __name__ == '__main__': |
| 107 | print '#define INITGUID' |
| 108 | print |
| 109 | print '#include "trace_writer_local.hpp"' |
| 110 | print '#include "os.hpp"' |
| 111 | print |
| 112 | print '#include "d3dcommonshader.hpp"' |
| 113 | print |
| 114 | |
| 115 | moduleNames = sys.argv[1:] |
| 116 | |
| 117 | api = API() |
| 118 | |
| 119 | if moduleNames: |
| 120 | api.addModule(dxgi) |
| 121 | |
| 122 | if 'd3d10' in moduleNames: |
| 123 | if 'd3d10_1' in moduleNames: |
| 124 | print r'#include "d3d10_1imports.hpp"' |
José Fonseca | 20aa935 | 2012-11-23 14:34:29 +0000 | [diff] [blame] | 125 | api.addModule(d3d10_1) |
| 126 | else: |
| 127 | print r'#include "d3d10imports.hpp"' |
| 128 | print r'#include "d3d10size.hpp"' |
| 129 | api.addModule(d3d10) |
| 130 | |
| 131 | if 'd3d11' in moduleNames: |
| 132 | print r'#include "d3d11imports.hpp"' |
| 133 | if 'd3d11_1' in moduleNames: |
| 134 | print '#include <d3d11_1.h>' |
| 135 | import specs.d3d11_1 |
| 136 | print r'#include "d3d11size.hpp"' |
| 137 | api.addModule(d3d11) |
| 138 | |
| 139 | tracer = D3DCommonTracer() |
| 140 | tracer.traceApi(api) |