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 | |
| 45 | DllTracer.serializeArgValue(self, function, arg) |
José Fonseca | 0168b51 | 2012-11-03 18:44:36 +0000 | [diff] [blame] | 46 | |
| 47 | def enumWrapperInterfaceVariables(self, interface): |
| 48 | variables = DllTracer.enumWrapperInterfaceVariables(self, interface) |
| 49 | |
| 50 | # Add additional members to track maps |
| 51 | if interface.getMethodByName('Map') is not None: |
| 52 | variables += [ |
| 53 | ('VOID *', '_pMappedData', '0'), |
| 54 | ('size_t', '_MappedSize', '0'), |
| 55 | ] |
| 56 | |
| 57 | return variables |
| 58 | |
| 59 | def implementWrapperInterfaceMethodBody(self, interface, base, method): |
| 60 | if method.name == 'Unmap': |
| 61 | print ' if (_MappedSize && _pMappedData) {' |
| 62 | self.emit_memcpy('_pMappedData', '_pMappedData', '_MappedSize') |
| 63 | print ' }' |
| 64 | |
| 65 | DllTracer.implementWrapperInterfaceMethodBody(self, interface, base, method) |
| 66 | |
| 67 | if method.name == 'Map': |
| 68 | # NOTE: recursive locks are explicitely forbidden |
| 69 | print ' if (SUCCEEDED(_result)) {' |
| 70 | print ' _getMapInfo(_this, %s, _pMappedData, _MappedSize);' % ', '.join(method.argNames()) |
| 71 | print ' } else {' |
| 72 | print ' _pMappedData = NULL;' |
| 73 | print ' _MappedSize = 0;' |
| 74 | print ' }' |
| 75 | |
| 76 | |
José Fonseca | 20aa935 | 2012-11-23 14:34:29 +0000 | [diff] [blame^] | 77 | if __name__ == '__main__': |
| 78 | print '#define INITGUID' |
| 79 | print |
| 80 | print '#include "trace_writer_local.hpp"' |
| 81 | print '#include "os.hpp"' |
| 82 | print |
| 83 | print '#include "d3dcommonshader.hpp"' |
| 84 | print |
| 85 | |
| 86 | moduleNames = sys.argv[1:] |
| 87 | |
| 88 | api = API() |
| 89 | |
| 90 | if moduleNames: |
| 91 | api.addModule(dxgi) |
| 92 | |
| 93 | if 'd3d10' in moduleNames: |
| 94 | if 'd3d10_1' in moduleNames: |
| 95 | print r'#include "d3d10_1imports.hpp"' |
| 96 | # D3D10CreateBlob is duplicated in d3d10 and d3d10_1 |
| 97 | d3d10_1.functions = [function for function in d3d10_1.functions if function.name != 'D3D10CreateBlob'] |
| 98 | api.addModule(d3d10_1) |
| 99 | else: |
| 100 | print r'#include "d3d10imports.hpp"' |
| 101 | print r'#include "d3d10size.hpp"' |
| 102 | api.addModule(d3d10) |
| 103 | |
| 104 | if 'd3d11' in moduleNames: |
| 105 | print r'#include "d3d11imports.hpp"' |
| 106 | if 'd3d11_1' in moduleNames: |
| 107 | print '#include <d3d11_1.h>' |
| 108 | import specs.d3d11_1 |
| 109 | print r'#include "d3d11size.hpp"' |
| 110 | api.addModule(d3d11) |
| 111 | |
| 112 | tracer = D3DCommonTracer() |
| 113 | tracer.traceApi(api) |