From af366b25cb9db606ec37069119b428fb9be4a163 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 7 Nov 2012 20:00:46 +0000 Subject: [PATCH] d3dretrace: Basic d3d10 support. --- helpers/dxgisize.hpp | 2 + retrace/CMakeLists.txt | 24 +++++++- retrace/d3d10retrace.py | 111 ++++++++++++++++++++++++++++++++++++ retrace/d3dretrace.hpp | 1 + retrace/d3dretrace_main.cpp | 1 + specs/d3d10.py | 8 +-- specs/d3d10effect.py | 4 +- 7 files changed, 144 insertions(+), 7 deletions(-) create mode 100644 retrace/d3d10retrace.py diff --git a/helpers/dxgisize.hpp b/helpers/dxgisize.hpp index 3048d3f..a2749ff 100644 --- a/helpers/dxgisize.hpp +++ b/helpers/dxgisize.hpp @@ -41,6 +41,8 @@ #include +#include "os.hpp" + static size_t _calcDataSize(DXGI_FORMAT Format, UINT Width, UINT Height, UINT RowPitch, UINT Depth = 1, UINT DepthPitch = 0) { diff --git a/retrace/CMakeLists.txt b/retrace/CMakeLists.txt index aaaa006..69612f0 100644 --- a/retrace/CMakeLists.txt +++ b/retrace/CMakeLists.txt @@ -128,7 +128,7 @@ if (ENABLE_EGL AND X11_FOUND AND NOT WIN32 AND NOT APPLE) install (TARGETS eglretrace RUNTIME DESTINATION bin) endif () -if (WIN32 AND DirectX_D3DX9_INCLUDE_DIR) +if (WIN32 AND DirectX_D3DX9_INCLUDE_DIR AND DirectX_D3D10_INCLUDE_DIR) add_custom_command ( OUTPUT d3dretrace_d3d9.cpp COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9retrace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3dretrace_d3d9.cpp @@ -144,10 +144,32 @@ if (WIN32 AND DirectX_D3DX9_INCLUDE_DIR) ${CMAKE_SOURCE_DIR}/specs/stdapi.py ) + add_custom_command ( + OUTPUT d3dretrace_d3d10.cpp + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10retrace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3dretrace_d3d10.cpp + DEPENDS + d3d10retrace.py + dllretrace.py + retrace.py + ${CMAKE_SOURCE_DIR}/dispatch/dispatch.py + ${CMAKE_SOURCE_DIR}/specs/d3d10.py + ${CMAKE_SOURCE_DIR}/specs/d3d10misc.py + ${CMAKE_SOURCE_DIR}/specs/d3d10sdklayers.py + ${CMAKE_SOURCE_DIR}/specs/d3d10shader.py + ${CMAKE_SOURCE_DIR}/specs/d3d10effect.py + ${CMAKE_SOURCE_DIR}/specs/d3dcommon.py + ${CMAKE_SOURCE_DIR}/specs/dxgi.py + ${CMAKE_SOURCE_DIR}/specs/dxgitype.py + ${CMAKE_SOURCE_DIR}/specs/dxgiformat.py + ${CMAKE_SOURCE_DIR}/specs/winapi.py + ${CMAKE_SOURCE_DIR}/specs/stdapi.py + ) + include_directories (SYSTEM ${DirectX_D3DX9_INCLUDE_DIR}) add_executable (d3dretrace d3dretrace_main.cpp d3dretrace_d3d9.cpp + d3dretrace_d3d10.cpp d3dretrace_ws.cpp d3d9state.cpp d3d9state_images.cpp diff --git a/retrace/d3d10retrace.py b/retrace/d3d10retrace.py new file mode 100644 index 0000000..ee8736b --- /dev/null +++ b/retrace/d3d10retrace.py @@ -0,0 +1,111 @@ +########################################################################## +# +# Copyright 2011 Jose Fonseca +# All Rights Reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +##########################################################################/ + + +"""D3D retracer generator.""" + + +from dllretrace import DllRetracer as Retracer +import specs.stdapi as stdapi +from specs.d3d10 import * + + +class D3DRetracer(Retracer): + + def retraceApi(self, api): + print '// Swizzling mapping for lock addresses' + print 'static std::map _maps;' + print + + self.table_name = 'd3dretrace::%s_callbacks' % api.name.lower() + + Retracer.retraceApi(self, api) + + def invokeFunction(self, function): + # create windows as neccessary + if function.name == 'D3D10CreateDeviceAndSwapChain': + print r' pSwapChainDesc->OutputWindow = d3dretrace::createWindow(512, 512);' + + Retracer.invokeFunction(self, function) + + def invokeInterfaceMethod(self, interface, method): + # keep track of the last used device for state dumping + #if interface.name in ('IDirect3DDevice9', 'IDirect3DDevice9Ex'): + # print r' d3dretrace::pLastDirect3DDevice9 = _this;' + + # create windows as neccessary + if method.name == 'CreateSwapChain': + print r' pDesc->OutputWindow = d3dretrace::createWindow(512, 512);' + + # notify frame has been completed + if method.name == 'Present': + print r' retrace::frameComplete(call);' + + if 'pSharedResource' in method.argNames(): + print r' if (pSharedResource) {' + print r' retrace::warning(call) << "shared surfaces unsupported\n";' + print r' pSharedResource = NULL;' + print r' }' + + Retracer.invokeInterfaceMethod(self, interface, method) + + # process events after presents + if method.name == 'Present': + print r' d3dretrace::processEvents();' + + # check errors + if str(method.type) == 'HRESULT': + print r' if (FAILED(_result)) {' + print r' retrace::warning(call) << "failed\n";' + print r' }' + + if method.name == 'Map': + print ' VOID *_pbData = NULL;' + print ' size_t _MappedSize = 0;' + print ' _getMapInfo(_this, %s, _pbData, _MappedSize);' % ', '.join(method.argNames()) + print ' _maps[_this] = _pbData;' + + if method.name == 'Unmap': + print ' VOID *_pbData = 0;' + print ' _pbData = _maps[_this];' + print ' if (_pbData) {' + print ' retrace::delRegionByPointer(_pbData);' + print ' }' + + +if __name__ == '__main__': + print r''' +#include + +#include + +#include "d3d10imports.hpp" +#include "d3d10size.hpp" +#include "d3dretrace.hpp" + +''' + + retracer = D3DRetracer() + retracer.retraceApi(d3d10) diff --git a/retrace/d3dretrace.hpp b/retrace/d3dretrace.hpp index b552c0b..c4e5bb4 100644 --- a/retrace/d3dretrace.hpp +++ b/retrace/d3dretrace.hpp @@ -45,6 +45,7 @@ extern IDirect3DDevice9 *pLastDirect3DDevice9; extern const retrace::Entry d3d9_callbacks[]; +extern const retrace::Entry d3d10_callbacks[]; HWND diff --git a/retrace/d3dretrace_main.cpp b/retrace/d3dretrace_main.cpp index 7471195..5806546 100644 --- a/retrace/d3dretrace_main.cpp +++ b/retrace/d3dretrace_main.cpp @@ -55,6 +55,7 @@ void retrace::addCallbacks(retrace::Retracer &retracer) { retracer.addCallbacks(d3dretrace::d3d9_callbacks); + retracer.addCallbacks(d3dretrace::d3d10_callbacks); } diff --git a/specs/d3d10.py b/specs/d3d10.py index 7b0f182..9a25327 100644 --- a/specs/d3d10.py +++ b/specs/d3d10.py @@ -603,12 +603,12 @@ D3D10_VIEWPORT = Struct("D3D10_VIEWPORT", [ ]) D3D10_MAPPED_TEXTURE2D = Struct("D3D10_MAPPED_TEXTURE2D", [ - (OpaquePointer(Void), "pData"), + (LinearPointer(Void, "_MappedSize"), "pData"), (UINT, "RowPitch"), ]) D3D10_MAPPED_TEXTURE3D = Struct("D3D10_MAPPED_TEXTURE3D", [ - (OpaquePointer(Void), "pData"), + (LinearPointer(Void, "_MappedSize"), "pData"), (UINT, "RowPitch"), (UINT, "DepthPitch"), ]) @@ -722,13 +722,13 @@ ID3D10Resource.methods += [ ] ID3D10Buffer.methods += [ - Method(HRESULT, "Map", [(D3D10_MAP, "MapType"), (D3D10_MAP_FLAG, "MapFlags"), Out(Pointer(OpaquePointer(Void)), "ppData")]), + Method(HRESULT, "Map", [(D3D10_MAP, "MapType"), (D3D10_MAP_FLAG, "MapFlags"), Out(Pointer(LinearPointer(Void, "_MappedSize")), "ppData")]), Method(Void, "Unmap", []), Method(Void, "GetDesc", [Out(Pointer(D3D10_BUFFER_DESC), "pDesc")], sideeffects=False), ] ID3D10Texture1D.methods += [ - Method(HRESULT, "Map", [(UINT, "Subresource"), (D3D10_MAP, "MapType"), (D3D10_MAP_FLAG, "MapFlags"), Out(Pointer(OpaquePointer(Void)), "ppData")]), + Method(HRESULT, "Map", [(UINT, "Subresource"), (D3D10_MAP, "MapType"), (D3D10_MAP_FLAG, "MapFlags"), Out(Pointer(LinearPointer(Void, "_MappedSize")), "ppData")]), Method(Void, "Unmap", [(UINT, "Subresource")]), Method(Void, "GetDesc", [Out(Pointer(D3D10_TEXTURE1D_DESC), "pDesc")], sideeffects=False), ] diff --git a/specs/d3d10effect.py b/specs/d3d10effect.py index 9a5e89e..401808d 100644 --- a/specs/d3d10effect.py +++ b/specs/d3d10effect.py @@ -177,8 +177,8 @@ ID3D10EffectVariable.methods += [ StdMethod(ObjPointer(ID3D10EffectDepthStencilVariable), "AsDepthStencil", []), StdMethod(ObjPointer(ID3D10EffectRasterizerVariable), "AsRasterizer", []), StdMethod(ObjPointer(ID3D10EffectSamplerVariable), "AsSampler", []), - StdMethod(HRESULT, "SetRawValue", [(OpaquePointer(Void), "pData"), (UINT, "Offset"), (UINT, "ByteCount")]), - StdMethod(HRESULT, "GetRawValue", [Out(OpaquePointer(Void), "pData"), (UINT, "Offset"), (UINT, "ByteCount")]), + StdMethod(HRESULT, "SetRawValue", [(Blob(Void, "ByteCount"), "pData"), (UINT, "Offset"), (UINT, "ByteCount")]), + StdMethod(HRESULT, "GetRawValue", [Out(OpaqueBlob(Void, "ByteCount"), "pData"), (UINT, "Offset"), (UINT, "ByteCount")], sideeffects=False), ] ID3D10EffectScalarVariable.methods += [ -- 2.43.0