From 003b8be61dbaf747100f9e7f788f3b95a55bbd52 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 29 May 2013 19:59:40 +0100 Subject: [PATCH] dxgi(re)trace: Organize mapping info into a structure. --- helpers/d3d10size.hpp | 48 +++++++++++++++++++++--------------------- helpers/d3d11size.hpp | 12 +++++------ helpers/dxgisize.hpp | 27 ++++++++++++++++++------ retrace/dxgiretrace.py | 10 ++++----- wrappers/dxgitrace.py | 13 ++++++------ wrappers/trace.py | 3 ++- 6 files changed, 64 insertions(+), 49 deletions(-) diff --git a/helpers/d3d10size.hpp b/helpers/d3d10size.hpp index 6441bdc..d15e2ec 100644 --- a/helpers/d3d10size.hpp +++ b/helpers/d3d10size.hpp @@ -108,10 +108,10 @@ _calcSubresourceSize(const D3D10_TEXTURE3D_DESC *pDesc, UINT Subresource, UINT R } static inline void -_getMapInfo(ID3D10Buffer *pResource, D3D10_MAP MapType, UINT MapFlags, void * * ppData, - void * & pMappedData, size_t & MappedSize) { - pMappedData = 0; - MappedSize = 0; +_getMapDesc(ID3D10Buffer *pResource, D3D10_MAP MapType, UINT MapFlags, void * * ppData, + _MAP_DESC & MapDesc) { + MapDesc.pData = 0; + MapDesc.Size = 0; if (MapType == D3D10_MAP_READ) { return; @@ -120,15 +120,15 @@ _getMapInfo(ID3D10Buffer *pResource, D3D10_MAP MapType, UINT MapFlags, void * * D3D10_BUFFER_DESC Desc; pResource->GetDesc(&Desc); - pMappedData = *ppData; - MappedSize = Desc.ByteWidth; + MapDesc.pData = *ppData; + MapDesc.Size = Desc.ByteWidth; } static inline void -_getMapInfo(ID3D10Texture1D *pResource, UINT Subresource, D3D10_MAP MapType, UINT MapFlags, void * * ppData, - void * & pMappedData, size_t & MappedSize) { - pMappedData = 0; - MappedSize = 0; +_getMapDesc(ID3D10Texture1D *pResource, UINT Subresource, D3D10_MAP MapType, UINT MapFlags, void * * ppData, + _MAP_DESC & MapDesc) { + MapDesc.pData = 0; + MapDesc.Size = 0; if (MapType == D3D10_MAP_READ) { return; @@ -137,15 +137,15 @@ _getMapInfo(ID3D10Texture1D *pResource, UINT Subresource, D3D10_MAP MapType, UIN D3D10_TEXTURE1D_DESC Desc; pResource->GetDesc(&Desc); - pMappedData = *ppData; - MappedSize = _calcSubresourceSize(&Desc, Subresource); + MapDesc.pData = *ppData; + MapDesc.Size = _calcSubresourceSize(&Desc, Subresource); } static inline void -_getMapInfo(ID3D10Texture2D *pResource, UINT Subresource, D3D10_MAP MapType, UINT MapFlags, D3D10_MAPPED_TEXTURE2D * pMappedTex2D, - void * & pMappedData, size_t & MappedSize) { - pMappedData = 0; - MappedSize = 0; +_getMapDesc(ID3D10Texture2D *pResource, UINT Subresource, D3D10_MAP MapType, UINT MapFlags, D3D10_MAPPED_TEXTURE2D * pMappedTex2D, + _MAP_DESC & MapDesc) { + MapDesc.pData = 0; + MapDesc.Size = 0; if (MapType == D3D10_MAP_READ) { return; @@ -154,15 +154,15 @@ _getMapInfo(ID3D10Texture2D *pResource, UINT Subresource, D3D10_MAP MapType, UIN D3D10_TEXTURE2D_DESC Desc; pResource->GetDesc(&Desc); - pMappedData = pMappedTex2D->pData; - MappedSize = _calcSubresourceSize(&Desc, Subresource, pMappedTex2D->RowPitch); + MapDesc.pData = pMappedTex2D->pData; + MapDesc.Size = _calcSubresourceSize(&Desc, Subresource, pMappedTex2D->RowPitch); } static inline void -_getMapInfo(ID3D10Texture3D *pResource, UINT Subresource, D3D10_MAP MapType, UINT MapFlags, D3D10_MAPPED_TEXTURE3D * pMappedTex3D, - void * & pMappedData, size_t & MappedSize) { - pMappedData = 0; - MappedSize = 0; +_getMapDesc(ID3D10Texture3D *pResource, UINT Subresource, D3D10_MAP MapType, UINT MapFlags, D3D10_MAPPED_TEXTURE3D * pMappedTex3D, + _MAP_DESC & MapDesc) { + MapDesc.pData = 0; + MapDesc.Size = 0; if (MapType == D3D10_MAP_READ) { return; @@ -171,8 +171,8 @@ _getMapInfo(ID3D10Texture3D *pResource, UINT Subresource, D3D10_MAP MapType, UIN D3D10_TEXTURE3D_DESC Desc; pResource->GetDesc(&Desc); - pMappedData = pMappedTex3D->pData; - MappedSize = _calcSubresourceSize(&Desc, Subresource, pMappedTex3D->RowPitch, pMappedTex3D->DepthPitch); + MapDesc.pData = pMappedTex3D->pData; + MapDesc.Size = _calcSubresourceSize(&Desc, Subresource, pMappedTex3D->RowPitch, pMappedTex3D->DepthPitch); } diff --git a/helpers/d3d11size.hpp b/helpers/d3d11size.hpp index ed75d64..2ac5309 100644 --- a/helpers/d3d11size.hpp +++ b/helpers/d3d11size.hpp @@ -180,17 +180,17 @@ _calcSubresourceSize(ID3D11Resource *pDstResource, UINT DstSubresource, const D3 static inline void -_getMapInfo(ID3D11DeviceContext* pContext, ID3D11Resource * pResource, UINT Subresource, D3D11_MAP MapType, UINT MapFlags, D3D11_MAPPED_SUBRESOURCE * pMappedResource, - void * & pMappedData, size_t & MappedSize) { - pMappedData = 0; - MappedSize = 0; +_getMapDesc(ID3D11DeviceContext* pContext, ID3D11Resource * pResource, UINT Subresource, D3D11_MAP MapType, UINT MapFlags, D3D11_MAPPED_SUBRESOURCE * pMappedResource, + _MAP_DESC & MapDesc) { + MapDesc.pData = 0; + MapDesc.Size = 0; if (MapType == D3D11_MAP_READ) { return; } - pMappedData = pMappedResource->pData; - MappedSize = _calcSubresourceSize(pResource, Subresource, NULL, pMappedResource->RowPitch, pMappedResource->DepthPitch); + MapDesc.pData = pMappedResource->pData; + MapDesc.Size = _calcSubresourceSize(pResource, Subresource, NULL, pMappedResource->RowPitch, pMappedResource->DepthPitch); } diff --git a/helpers/dxgisize.hpp b/helpers/dxgisize.hpp index a2749ff..cbe526f 100644 --- a/helpers/dxgisize.hpp +++ b/helpers/dxgisize.hpp @@ -44,6 +44,21 @@ #include "os.hpp" +/** + * Information about active sub-resource maps + */ +struct _MAP_DESC +{ + VOID * pData; + size_t Size; + + _MAP_DESC(void) : + pData(0), + Size(0) + {} +}; + + static size_t _calcDataSize(DXGI_FORMAT Format, UINT Width, UINT Height, UINT RowPitch, UINT Depth = 1, UINT DepthPitch = 0) { if (Width == 0 || Height == 0 || Depth == 0) { @@ -229,10 +244,10 @@ _getNumMipLevels(UINT Width, UINT Height = 1, UINT Depth = 1) { static inline void -_getMapInfo(IDXGISurface *pResource, DXGI_MAPPED_RECT * pLockedRect, UINT MapFlags, - void * & pMappedData, size_t & MappedSize) { - pMappedData = 0; - MappedSize = 0; +_getMapDesc(IDXGISurface *pResource, DXGI_MAPPED_RECT * pLockedRect, UINT MapFlags, + _MAP_DESC & MapDesc) { + MapDesc.pData = 0; + MapDesc.Size = 0; if (!(MapFlags & DXGI_MAP_WRITE)) { return; @@ -244,8 +259,8 @@ _getMapInfo(IDXGISurface *pResource, DXGI_MAPPED_RECT * pLockedRect, UINT MapFla return; } - pMappedData = pLockedRect->pBits; - MappedSize = _calcDataSize(Desc.Format, Desc.Width, Desc.Height, pLockedRect->Pitch); + MapDesc.pData = pLockedRect->pBits; + MapDesc.Size = _calcDataSize(Desc.Format, Desc.Width, Desc.Height, pLockedRect->Pitch); } diff --git a/retrace/dxgiretrace.py b/retrace/dxgiretrace.py index 1be70fe..e37e49a 100644 --- a/retrace/dxgiretrace.py +++ b/retrace/dxgiretrace.py @@ -286,11 +286,11 @@ createWindow(DXGI_SWAP_CHAIN_DESC *pSwapChainDesc) { print r' d3dretrace::processEvents();' if method.name == 'Map': - print ' VOID *_pbData = NULL;' - print ' size_t _MappedSize = 0;' - print ' _getMapInfo(_this, %s, _pbData, _MappedSize);' % ', '.join(method.argNames()) - print ' if (_MappedSize) {' - print ' _maps[_this] = _pbData;' + print ' _MAP_DESC _MapDesc;' + print ' _getMapDesc(_this, %s, _MapDesc);' % ', '.join(method.argNames()) + print ' size_t _MappedSize = _MapDesc.Size;' + print ' if (_MapDesc.Size) {' + print ' _maps[_this] = _MapDesc.pData;' print ' } else {' print ' return;' print ' }' diff --git a/wrappers/dxgitrace.py b/wrappers/dxgitrace.py index 0ecaed2..122b773 100644 --- a/wrappers/dxgitrace.py +++ b/wrappers/dxgitrace.py @@ -80,16 +80,15 @@ class D3DCommonTracer(DllTracer): # Add additional members to track maps if interface.getMethodByName('Map') is not None: variables += [ - ('VOID *', '_pMappedData', '0'), - ('size_t', '_MappedSize', '0'), + ('_MAP_DESC', '_MapDesc', None), ] return variables def implementWrapperInterfaceMethodBody(self, interface, base, method): if method.name == 'Unmap': - print ' if (_MappedSize && _pMappedData) {' - self.emit_memcpy('_pMappedData', '_pMappedData', '_MappedSize') + print ' if (_MapDesc.Size && _MapDesc.pData) {' + self.emit_memcpy('_MapDesc.pData', '_MapDesc.pData', '_MapDesc.Size') print ' }' DllTracer.implementWrapperInterfaceMethodBody(self, interface, base, method) @@ -97,10 +96,10 @@ class D3DCommonTracer(DllTracer): if method.name == 'Map': # NOTE: recursive locks are explicitely forbidden 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 ' }' diff --git a/wrappers/trace.py b/wrappers/trace.py index 252db49..4abd20e 100644 --- a/wrappers/trace.py +++ b/wrappers/trace.py @@ -627,7 +627,8 @@ class Tracer: # Private constructor print '%s::%s(%s * pInstance) {' % (getWrapperInterfaceName(interface), getWrapperInterfaceName(interface), interface.name) for type, name, value in self.enumWrapperInterfaceVariables(interface): - print ' %s = %s;' % (name, value) + if value is not None: + print ' %s = %s;' % (name, value) print '}' print -- 2.43.0