X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=wrappers%2Fdxgitrace.py;h=45767a0f6761410ac9908599496e7a9ffb9b91c4;hb=da55940db71e6e09ba54eadb707dd5e6b43b5442;hp=440d691e50d4dbdd11fe972c1d5d6816ae3c67aa;hpb=419d768ef3a05f3245efb653767340a915569d0d;p=apitrace diff --git a/wrappers/dxgitrace.py b/wrappers/dxgitrace.py index 440d691..45767a0 100644 --- a/wrappers/dxgitrace.py +++ b/wrappers/dxgitrace.py @@ -26,12 +26,13 @@ import sys from dlltrace import DllTracer +from trace import getWrapperInterfaceName from specs import stdapi from specs.stdapi import API -from specs.dxgi import dxgi -from specs.d3d10 import d3d10 -from specs.d3d10_1 import d3d10_1 -from specs.d3d11 import d3d11 +from specs import dxgi +from specs import d3d10 +from specs import d3d10_1 +from specs import d3d11 class D3DCommonTracer(DllTracer): @@ -43,64 +44,86 @@ class D3DCommonTracer(DllTracer): return # Serialize the swapchain dimensions - if function.name == 'CreateSwapChain' and arg.name == 'pDesc': - print r' DXGI_SWAP_CHAIN_DESC *_pDesc = NULL;' - print r' DXGI_SWAP_CHAIN_DESC _Desc;' - print r' if (pDesc) {' - print r' _Desc = *pDesc;' - if not self.interface.name.endswith('DWM'): + if function.name == 'CreateSwapChain' and arg.name == 'pDesc' \ + or arg.name == 'pSwapChainDesc': + print r' DXGI_SWAP_CHAIN_DESC *_pSwapChainDesc = NULL;' + print r' DXGI_SWAP_CHAIN_DESC _SwapChainDesc;' + print r' if (%s) {' % arg.name + print r' _SwapChainDesc = *%s;' % arg.name + if function.name != 'CreateSwapChain' or not self.interface.name.endswith('DWM'): # Obtain size from the window print r' RECT _rect;' - print r' if (GetClientRect(pDesc->OutputWindow, &_rect)) {' - print r' if (pDesc->BufferDesc.Width == 0) {' - print r' _Desc.BufferDesc.Width = _rect.right - _rect.left;' + print r' if (GetClientRect(%s->OutputWindow, &_rect)) {' % arg.name + print r' if (%s->BufferDesc.Width == 0) {' % arg.name + print r' _SwapChainDesc.BufferDesc.Width = _rect.right - _rect.left;' print r' }' - print r' if (pDesc->BufferDesc.Height == 0) {' - print r' _Desc.BufferDesc.Height = _rect.bottom - _rect.top;' + print r' if (%s->BufferDesc.Height == 0) {' % arg.name + print r' _SwapChainDesc.BufferDesc.Height = _rect.bottom - _rect.top;' print r' }' print r' }' else: # Obtain size from the output print r' DXGI_OUTPUT_DESC _OutputDesc;' print r' if (SUCCEEDED(pOutput->GetDesc(&_OutputDesc))) {' - print r' _Desc.BufferDesc.Width = _OutputDesc.DesktopCoordinates.right - _OutputDesc.DesktopCoordinates.left;' - print r' _Desc.BufferDesc.Height = _OutputDesc.DesktopCoordinates.bottom - _OutputDesc.DesktopCoordinates.top;' + print r' _SwapChainDesc.BufferDesc.Width = _OutputDesc.DesktopCoordinates.right - _OutputDesc.DesktopCoordinates.left;' + print r' _SwapChainDesc.BufferDesc.Height = _OutputDesc.DesktopCoordinates.bottom - _OutputDesc.DesktopCoordinates.top;' print r' }' - print r' _pDesc = &_Desc;' + print r' _pSwapChainDesc = &_SwapChainDesc;' print r' }' - self.serializeValue(arg.type, '_pDesc') + self.serializeValue(arg.type, '_pSwapChainDesc') return DllTracer.serializeArgValue(self, function, arg) + + # Interfaces that need book-keeping for maps + mapInterfaces = ( + dxgi.IDXGISurface, + d3d10.ID3D10Resource, + d3d11.ID3D11Resource, + ) def enumWrapperInterfaceVariables(self, interface): variables = DllTracer.enumWrapperInterfaceVariables(self, interface) # Add additional members to track maps - if interface.getMethodByName('Map') is not None: + if interface.hasBase(*self.mapInterfaces): variables += [ - ('VOID *', '_pMappedData', '0'), - ('size_t', '_MappedSize', '0'), + ('_MAP_DESC', '_MapDesc', None), ] return variables def implementWrapperInterfaceMethodBody(self, interface, base, method): + if method.name in ('Map', 'Unmap'): + # On D3D11 Map/Unmap is not a resource method, but a context method instead. + resourceArg = method.getArgByName('pResource') + if resourceArg is None: + pResource = 'this' + else: + wrapperInterfaceName = getWrapperInterfaceName(resourceArg.type.type) + print ' %s * _pResource = static_cast<%s*>(%s);' % (wrapperInterfaceName, wrapperInterfaceName, resourceArg.name) + pResource = '_pResource' + if method.name == 'Unmap': - print ' if (_MappedSize && _pMappedData) {' - self.emit_memcpy('_pMappedData', '_pMappedData', '_MappedSize') + print ' _MAP_DESC _MapDesc = %s->_MapDesc;' % pResource + #print r' os::log("%%p -> %%p+%%lu\n", %s,_MapDesc.pData, (unsigned long)_MapDesc.Size);' % pResource + print ' if (_MapDesc.Size && _MapDesc.pData) {' + self.emit_memcpy('_MapDesc.pData', '_MapDesc.pData', '_MapDesc.Size') print ' }' DllTracer.implementWrapperInterfaceMethodBody(self, interface, base, method) if method.name == 'Map': # NOTE: recursive locks are explicitely forbidden + print ' _MAP_DESC _MapDesc;' print ' if (SUCCEEDED(_result)) {' - print ' _getMapInfo(_this, %s, _pMappedData, _MappedSize);' % ', '.join(method.argNames()) + print ' _getMapDesc(_this, %s, _MapDesc);' % ', '.join(method.argNames()) print ' } else {' - print ' _pMappedData = NULL;' - print ' _MappedSize = 0;' + print ' _MapDesc.pData = NULL;' + print ' _MapDesc.Size = 0;' print ' }' + #print r' os::log("%%p <- %%p+%%lu\n", %s,_MapDesc.pData, (unsigned long)_MapDesc.Size);' % pResource + print ' %s->_MapDesc = _MapDesc;' % pResource if __name__ == '__main__': @@ -117,24 +140,24 @@ if __name__ == '__main__': api = API() if moduleNames: - api.addModule(dxgi) + api.addModule(dxgi.dxgi) if 'd3d10' in moduleNames: if 'd3d10_1' in moduleNames: print r'#include "d3d10_1imports.hpp"' - api.addModule(d3d10_1) + api.addModule(d3d10_1.d3d10_1) else: print r'#include "d3d10imports.hpp"' print r'#include "d3d10size.hpp"' - api.addModule(d3d10) + api.addModule(d3d10.d3d10) if 'd3d11' in moduleNames: print r'#include "d3d11imports.hpp"' if 'd3d11_1' in moduleNames: print '#include ' - import specs.d3d11_1 + from specs import d3d11_1 print r'#include "d3d11size.hpp"' - api.addModule(d3d11) + api.addModule(d3d11.d3d11) tracer = D3DCommonTracer() tracer.traceApi(api)