]> git.cworth.org Git - apitrace/commitdiff
d3dretrace: Add d3d9 prefix to d3d9 specific files.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 7 Nov 2012 19:31:20 +0000 (19:31 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 7 Nov 2012 19:31:20 +0000 (19:31 +0000)
retrace/CMakeLists.txt
retrace/d3d9retrace.py [new file with mode: 0644]
retrace/d3d9state.cpp [new file with mode: 0644]
retrace/d3d9state.hpp [new file with mode: 0644]
retrace/d3d9state_images.cpp [new file with mode: 0644]
retrace/d3dretrace.py [deleted file]
retrace/d3dretrace_main.cpp
retrace/d3dstate.cpp [deleted file]
retrace/d3dstate.hpp [deleted file]
retrace/d3dstate_images.cpp [deleted file]

index 63fbed63fab1b7564b270661f14be07668955c3d..aaaa006beff61806f8215cb668c73eb239bfeada 100644 (file)
@@ -131,9 +131,9 @@ endif ()
 if (WIN32 AND DirectX_D3DX9_INCLUDE_DIR)
     add_custom_command (
         OUTPUT d3dretrace_d3d9.cpp
-        COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3dretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3dretrace_d3d9.cpp
+        COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9retrace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3dretrace_d3d9.cpp
         DEPENDS
-                d3dretrace.py
+                d3d9retrace.py
                 dllretrace.py
                 retrace.py
                 ${CMAKE_SOURCE_DIR}/dispatch/dispatch.py
@@ -149,8 +149,8 @@ if (WIN32 AND DirectX_D3DX9_INCLUDE_DIR)
         d3dretrace_main.cpp
         d3dretrace_d3d9.cpp
         d3dretrace_ws.cpp
-        d3dstate.cpp
-        d3dstate_images.cpp
+        d3d9state.cpp
+        d3d9state_images.cpp
     )
     target_link_libraries (d3dretrace
         retrace_common
diff --git a/retrace/d3d9retrace.py b/retrace/d3d9retrace.py
new file mode 100644 (file)
index 0000000..14b92ab
--- /dev/null
@@ -0,0 +1,113 @@
+##########################################################################
+#
+# 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.d3d9 import *
+
+
+class D3DRetracer(Retracer):
+
+    def retraceApi(self, api):
+        print '// Swizzling mapping for lock addresses'
+        print 'static std::map<void *, void *> _locks;'
+        print
+
+        self.table_name = 'd3dretrace::%s_callbacks' % api.name.lower()
+
+        Retracer.retraceApi(self, api)
+
+    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 in ('CreateDevice', 'CreateDeviceEx', 'CreateAdditionalSwapChain'):
+            print r'    HWND hWnd = d3dretrace::createWindow(pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight);'
+            print r'    pPresentationParameters->hDeviceWindow = hWnd;'
+            if 'hFocusWindow' in method.argNames():
+                print r'    hFocusWindow = hWnd;'
+
+        if method.name in ('Reset', 'ResetEx'):
+            print r'    if (pPresentationParameters->Windowed) {'
+            print r'        d3dretrace::resizeWindow(pPresentationParameters->hDeviceWindow, pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight);'
+            print r'    }'
+
+        # notify frame has been completed
+        if method.name == 'Present':
+            print r'    retrace::frameComplete(call);'
+            print r'    hDestWindowOverride = NULL;'
+
+        if 'pSharedHandle' in method.argNames():
+            print r'    if (pSharedHandle) {'
+            print r'        retrace::warning(call) << "shared surfaces unsupported\n";'
+            print r'        pSharedHandle = 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 in ('Lock', 'LockRect', 'LockBox'):
+            print '    VOID *_pbData = NULL;'
+            print '    size_t _LockedSize = 0;'
+            print '    _getLockInfo(_this, %s, _pbData, _LockedSize);' % ', '.join(method.argNames()[:-1])
+            print '    _locks[_this] = _pbData;'
+        
+        if method.name in ('Unlock', 'UnlockRect', 'UnlockBox'):
+            print '    VOID *_pbData = 0;'
+            print '    _pbData = _locks[_this];'
+            print '    if (_pbData) {'
+            print '        retrace::delRegionByPointer(_pbData);'
+            print '    }'
+
+
+if __name__ == '__main__':
+    print r'''
+#include <string.h>
+
+#include <iostream>
+
+#include "d3d9imports.hpp"
+#include "d3d9size.hpp"
+#include "d3dretrace.hpp"
+
+'''
+
+    retracer = D3DRetracer()
+    retracer.retraceApi(d3d9)
diff --git a/retrace/d3d9state.cpp b/retrace/d3d9state.cpp
new file mode 100644 (file)
index 0000000..73746e7
--- /dev/null
@@ -0,0 +1,165 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+
+#include <stdio.h>
+
+#include <iostream>
+
+#include "d3d9imports.hpp"
+#include "json.hpp"
+
+
+namespace d3dstate {
+
+
+typedef HRESULT
+(WINAPI *PD3DXDISASSEMBLESHADER)(
+    CONST DWORD *pShader,
+    BOOL EnableColorCode,
+    LPCSTR pComments,
+    LPD3DXBUFFER *ppDisassembly
+);
+
+
+HRESULT
+disassembleShader(const DWORD *tokens, LPD3DXBUFFER *ppDisassembly)
+{
+    static BOOL firsttime = TRUE;
+
+    /*
+     * TODO: Consider using d3dcompile_xx.dll per
+     * http://msdn.microsoft.com/en-us/library/windows/desktop/ee663275.aspx
+     */
+
+    static HMODULE hD3DXModule = NULL;
+    static PD3DXDISASSEMBLESHADER pfnD3DXDisassembleShader = NULL;
+
+    if (firsttime) {
+        if (!hD3DXModule) {
+            unsigned release;
+            int version;
+            for (release = 0; release <= 1; ++release) {
+                /* Version 41 corresponds to Mar 2009 version of DirectX Runtime / SDK */
+                for (version = 41; version >= 0; --version) {
+                    char filename[256];
+                    _snprintf(filename, sizeof(filename),
+                              "d3dx9%s%s%u.dll", release ? "" : "d", version ? "_" : "", version);
+                    hD3DXModule = LoadLibraryA(filename);
+                    if (hD3DXModule)
+                        goto found;
+                }
+            }
+found:
+            ;
+        }
+
+        if (hD3DXModule) {
+            if (!pfnD3DXDisassembleShader) {
+                pfnD3DXDisassembleShader = (PD3DXDISASSEMBLESHADER)GetProcAddress(hD3DXModule, "D3DXDisassembleShader");
+            }
+        }
+
+        firsttime = FALSE;
+    }
+
+    if (!pfnD3DXDisassembleShader) {
+        return E_FAIL;
+    }
+
+    return pfnD3DXDisassembleShader(tokens, FALSE, NULL, ppDisassembly);
+}
+
+
+template< class T >
+inline void
+dumpShader(JSONWriter &json, const char *name, T *pShader) {
+    if (!pShader) {
+        return;
+    }
+
+    HRESULT hr;
+
+    UINT SizeOfData = 0;
+
+    hr = pShader->GetFunction(NULL, &SizeOfData);
+    if (SUCCEEDED(hr)) {
+        void *pData;
+        pData = malloc(SizeOfData);
+        if (pData) {
+            hr = pShader->GetFunction(pData, &SizeOfData);
+            if (SUCCEEDED(hr)) {
+                LPD3DXBUFFER pDisassembly;
+
+                hr = disassembleShader((const DWORD *)pData, &pDisassembly);
+                if (SUCCEEDED(hr)) {
+                    json.beginMember(name);
+                    json.writeString((const char *)pDisassembly->GetBufferPointer() /*, pDisassembly->GetBufferSize() */);
+                    json.endMember();
+                    pDisassembly->Release();
+                }
+
+            }
+            free(pData);
+        }
+    }
+}
+
+static void
+dumpShaders(JSONWriter &json, IDirect3DDevice9 *pDevice)
+{
+    json.beginMember("shaders");
+
+    HRESULT hr;
+    json.beginObject();
+
+    IDirect3DVertexShader9 *pVertexShader = NULL;
+    hr = pDevice->GetVertexShader(&pVertexShader);
+    if (SUCCEEDED(hr)) {
+        dumpShader(json, "vertex", pVertexShader);
+    }
+
+    IDirect3DPixelShader9 *pPixelShader = NULL;
+    hr = pDevice->GetPixelShader(&pPixelShader);
+    if (SUCCEEDED(hr)) {
+        dumpShader(json, "pixel", pPixelShader);
+    }
+
+    json.endObject();
+    json.endMember(); // shaders
+}
+
+void
+dumpDevice(std::ostream &os, IDirect3DDevice9 *pDevice)
+{
+    JSONWriter json(os);
+
+    dumpShaders(json, pDevice);
+
+    /* TODO */
+}
+
+
+} /* namespace d3dstate */
diff --git a/retrace/d3d9state.hpp b/retrace/d3d9state.hpp
new file mode 100644 (file)
index 0000000..053e7df
--- /dev/null
@@ -0,0 +1,55 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#ifndef _D3D9STATE_HPP_
+#define _D3D9STATE_HPP_
+
+
+#include <iostream>
+
+
+struct IDirect3DDevice9;
+
+
+namespace image {
+    class Image;
+}
+
+
+namespace d3dstate {
+
+
+image::Image *
+getRenderTargetImage(IDirect3DDevice9 *pDevice);
+
+
+void
+dumpDevice(std::ostream &os, IDirect3DDevice9 *pDevice);
+
+
+} /* namespace d3dstate */
+
+
+#endif /* _D3DSTATE_HPP_ */
diff --git a/retrace/d3d9state_images.cpp b/retrace/d3d9state_images.cpp
new file mode 100644 (file)
index 0000000..855dede
--- /dev/null
@@ -0,0 +1,100 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+
+#include <assert.h>
+
+#include "image.hpp"
+#include "d3d9imports.hpp"
+
+
+namespace d3dstate {
+
+
+image::Image *
+getRenderTargetImage(IDirect3DDevice9 *pDevice) {
+    image::Image *image = NULL;
+    IDirect3DSurface9 *pRenderTarget = NULL;
+    D3DSURFACE_DESC Desc;
+    IDirect3DSurface9 *pStagingSurface = NULL;
+    D3DLOCKED_RECT LockedRect;
+    const unsigned char *src;
+    unsigned char *dst;
+    HRESULT hr;
+
+    hr = pDevice->GetRenderTarget(0, &pRenderTarget);
+    if (FAILED(hr)) {
+        goto no_rendertarget;
+    }
+    assert(pRenderTarget);
+
+    hr = pRenderTarget->GetDesc(&Desc);
+    assert(SUCCEEDED(hr));
+    assert(Desc.Format == D3DFMT_X8R8G8B8 || Desc.Format == D3DFMT_A8R8G8B8);
+
+    hr = pDevice->CreateOffscreenPlainSurface(Desc.Width, Desc.Height, Desc.Format, D3DPOOL_SYSTEMMEM, &pStagingSurface, NULL);
+    if (FAILED(hr)) {
+        goto no_staging;
+    }
+
+    hr = pDevice->GetRenderTargetData(pRenderTarget, pStagingSurface);
+    if (FAILED(hr)) {
+        goto no_rendertargetdata;
+    }
+
+    hr = pStagingSurface->LockRect(&LockedRect, NULL, D3DLOCK_READONLY);
+    if (FAILED(hr)) {
+        goto no_rendertargetdata;
+    }
+
+    image = new image::Image(Desc.Width, Desc.Height, 3, true);
+    if (!image) {
+        goto no_image;
+    }
+
+    dst = image->start();
+    src = (const unsigned char *)LockedRect.pBits;
+    for (unsigned y = 0; y < Desc.Height; ++y) {
+        for (unsigned x = 0; x < Desc.Width; ++x) {
+            dst[3*x + 0] = src[4*x + 2];
+            dst[3*x + 1] = src[4*x + 1];
+            dst[3*x + 2] = src[4*x + 0];
+        }
+        src += LockedRect.Pitch;
+        dst += image->stride();
+    }
+
+no_image:
+    pStagingSurface->UnlockRect();
+no_rendertargetdata:
+    pStagingSurface->Release();
+no_staging:
+    pRenderTarget->Release();
+no_rendertarget:
+    return image;
+}
+
+
+} /* namespace d3dstate */
diff --git a/retrace/d3dretrace.py b/retrace/d3dretrace.py
deleted file mode 100644 (file)
index 14b92ab..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-##########################################################################
-#
-# 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.d3d9 import *
-
-
-class D3DRetracer(Retracer):
-
-    def retraceApi(self, api):
-        print '// Swizzling mapping for lock addresses'
-        print 'static std::map<void *, void *> _locks;'
-        print
-
-        self.table_name = 'd3dretrace::%s_callbacks' % api.name.lower()
-
-        Retracer.retraceApi(self, api)
-
-    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 in ('CreateDevice', 'CreateDeviceEx', 'CreateAdditionalSwapChain'):
-            print r'    HWND hWnd = d3dretrace::createWindow(pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight);'
-            print r'    pPresentationParameters->hDeviceWindow = hWnd;'
-            if 'hFocusWindow' in method.argNames():
-                print r'    hFocusWindow = hWnd;'
-
-        if method.name in ('Reset', 'ResetEx'):
-            print r'    if (pPresentationParameters->Windowed) {'
-            print r'        d3dretrace::resizeWindow(pPresentationParameters->hDeviceWindow, pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight);'
-            print r'    }'
-
-        # notify frame has been completed
-        if method.name == 'Present':
-            print r'    retrace::frameComplete(call);'
-            print r'    hDestWindowOverride = NULL;'
-
-        if 'pSharedHandle' in method.argNames():
-            print r'    if (pSharedHandle) {'
-            print r'        retrace::warning(call) << "shared surfaces unsupported\n";'
-            print r'        pSharedHandle = 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 in ('Lock', 'LockRect', 'LockBox'):
-            print '    VOID *_pbData = NULL;'
-            print '    size_t _LockedSize = 0;'
-            print '    _getLockInfo(_this, %s, _pbData, _LockedSize);' % ', '.join(method.argNames()[:-1])
-            print '    _locks[_this] = _pbData;'
-        
-        if method.name in ('Unlock', 'UnlockRect', 'UnlockBox'):
-            print '    VOID *_pbData = 0;'
-            print '    _pbData = _locks[_this];'
-            print '    if (_pbData) {'
-            print '        retrace::delRegionByPointer(_pbData);'
-            print '    }'
-
-
-if __name__ == '__main__':
-    print r'''
-#include <string.h>
-
-#include <iostream>
-
-#include "d3d9imports.hpp"
-#include "d3d9size.hpp"
-#include "d3dretrace.hpp"
-
-'''
-
-    retracer = D3DRetracer()
-    retracer.retraceApi(d3d9)
index 9878fe3c87b059690527f6c6e44f523d72f4880d..7471195e42bbf98cbb5006f265bee1cdff47d943 100644 (file)
@@ -28,7 +28,7 @@
 
 #include "os_string.hpp"
 
-#include "d3dstate.hpp"
+#include "d3d9state.hpp"
 #include "retrace.hpp"
 #include "d3dretrace.hpp"
 
diff --git a/retrace/d3dstate.cpp b/retrace/d3dstate.cpp
deleted file mode 100644 (file)
index 73746e7..0000000
+++ /dev/null
@@ -1,165 +0,0 @@
-/**************************************************************************
- *
- * 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.
- *
- **************************************************************************/
-
-
-#include <stdio.h>
-
-#include <iostream>
-
-#include "d3d9imports.hpp"
-#include "json.hpp"
-
-
-namespace d3dstate {
-
-
-typedef HRESULT
-(WINAPI *PD3DXDISASSEMBLESHADER)(
-    CONST DWORD *pShader,
-    BOOL EnableColorCode,
-    LPCSTR pComments,
-    LPD3DXBUFFER *ppDisassembly
-);
-
-
-HRESULT
-disassembleShader(const DWORD *tokens, LPD3DXBUFFER *ppDisassembly)
-{
-    static BOOL firsttime = TRUE;
-
-    /*
-     * TODO: Consider using d3dcompile_xx.dll per
-     * http://msdn.microsoft.com/en-us/library/windows/desktop/ee663275.aspx
-     */
-
-    static HMODULE hD3DXModule = NULL;
-    static PD3DXDISASSEMBLESHADER pfnD3DXDisassembleShader = NULL;
-
-    if (firsttime) {
-        if (!hD3DXModule) {
-            unsigned release;
-            int version;
-            for (release = 0; release <= 1; ++release) {
-                /* Version 41 corresponds to Mar 2009 version of DirectX Runtime / SDK */
-                for (version = 41; version >= 0; --version) {
-                    char filename[256];
-                    _snprintf(filename, sizeof(filename),
-                              "d3dx9%s%s%u.dll", release ? "" : "d", version ? "_" : "", version);
-                    hD3DXModule = LoadLibraryA(filename);
-                    if (hD3DXModule)
-                        goto found;
-                }
-            }
-found:
-            ;
-        }
-
-        if (hD3DXModule) {
-            if (!pfnD3DXDisassembleShader) {
-                pfnD3DXDisassembleShader = (PD3DXDISASSEMBLESHADER)GetProcAddress(hD3DXModule, "D3DXDisassembleShader");
-            }
-        }
-
-        firsttime = FALSE;
-    }
-
-    if (!pfnD3DXDisassembleShader) {
-        return E_FAIL;
-    }
-
-    return pfnD3DXDisassembleShader(tokens, FALSE, NULL, ppDisassembly);
-}
-
-
-template< class T >
-inline void
-dumpShader(JSONWriter &json, const char *name, T *pShader) {
-    if (!pShader) {
-        return;
-    }
-
-    HRESULT hr;
-
-    UINT SizeOfData = 0;
-
-    hr = pShader->GetFunction(NULL, &SizeOfData);
-    if (SUCCEEDED(hr)) {
-        void *pData;
-        pData = malloc(SizeOfData);
-        if (pData) {
-            hr = pShader->GetFunction(pData, &SizeOfData);
-            if (SUCCEEDED(hr)) {
-                LPD3DXBUFFER pDisassembly;
-
-                hr = disassembleShader((const DWORD *)pData, &pDisassembly);
-                if (SUCCEEDED(hr)) {
-                    json.beginMember(name);
-                    json.writeString((const char *)pDisassembly->GetBufferPointer() /*, pDisassembly->GetBufferSize() */);
-                    json.endMember();
-                    pDisassembly->Release();
-                }
-
-            }
-            free(pData);
-        }
-    }
-}
-
-static void
-dumpShaders(JSONWriter &json, IDirect3DDevice9 *pDevice)
-{
-    json.beginMember("shaders");
-
-    HRESULT hr;
-    json.beginObject();
-
-    IDirect3DVertexShader9 *pVertexShader = NULL;
-    hr = pDevice->GetVertexShader(&pVertexShader);
-    if (SUCCEEDED(hr)) {
-        dumpShader(json, "vertex", pVertexShader);
-    }
-
-    IDirect3DPixelShader9 *pPixelShader = NULL;
-    hr = pDevice->GetPixelShader(&pPixelShader);
-    if (SUCCEEDED(hr)) {
-        dumpShader(json, "pixel", pPixelShader);
-    }
-
-    json.endObject();
-    json.endMember(); // shaders
-}
-
-void
-dumpDevice(std::ostream &os, IDirect3DDevice9 *pDevice)
-{
-    JSONWriter json(os);
-
-    dumpShaders(json, pDevice);
-
-    /* TODO */
-}
-
-
-} /* namespace d3dstate */
diff --git a/retrace/d3dstate.hpp b/retrace/d3dstate.hpp
deleted file mode 100644 (file)
index 33322a1..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/**************************************************************************
- *
- * 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.
- *
- **************************************************************************/
-
-#ifndef _D3DSTATE_HPP_
-#define _D3DSTATE_HPP_
-
-
-#include <iostream>
-
-
-struct IDirect3DDevice9;
-
-
-namespace image {
-    class Image;
-}
-
-
-namespace d3dstate {
-
-
-image::Image *
-getRenderTargetImage(IDirect3DDevice9 *pDevice);
-
-
-void
-dumpDevice(std::ostream &os, IDirect3DDevice9 *pDevice);
-
-
-} /* namespace d3dstate */
-
-
-#endif /* _D3DSTATE_HPP_ */
diff --git a/retrace/d3dstate_images.cpp b/retrace/d3dstate_images.cpp
deleted file mode 100644 (file)
index 855dede..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/**************************************************************************
- *
- * 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.
- *
- **************************************************************************/
-
-
-#include <assert.h>
-
-#include "image.hpp"
-#include "d3d9imports.hpp"
-
-
-namespace d3dstate {
-
-
-image::Image *
-getRenderTargetImage(IDirect3DDevice9 *pDevice) {
-    image::Image *image = NULL;
-    IDirect3DSurface9 *pRenderTarget = NULL;
-    D3DSURFACE_DESC Desc;
-    IDirect3DSurface9 *pStagingSurface = NULL;
-    D3DLOCKED_RECT LockedRect;
-    const unsigned char *src;
-    unsigned char *dst;
-    HRESULT hr;
-
-    hr = pDevice->GetRenderTarget(0, &pRenderTarget);
-    if (FAILED(hr)) {
-        goto no_rendertarget;
-    }
-    assert(pRenderTarget);
-
-    hr = pRenderTarget->GetDesc(&Desc);
-    assert(SUCCEEDED(hr));
-    assert(Desc.Format == D3DFMT_X8R8G8B8 || Desc.Format == D3DFMT_A8R8G8B8);
-
-    hr = pDevice->CreateOffscreenPlainSurface(Desc.Width, Desc.Height, Desc.Format, D3DPOOL_SYSTEMMEM, &pStagingSurface, NULL);
-    if (FAILED(hr)) {
-        goto no_staging;
-    }
-
-    hr = pDevice->GetRenderTargetData(pRenderTarget, pStagingSurface);
-    if (FAILED(hr)) {
-        goto no_rendertargetdata;
-    }
-
-    hr = pStagingSurface->LockRect(&LockedRect, NULL, D3DLOCK_READONLY);
-    if (FAILED(hr)) {
-        goto no_rendertargetdata;
-    }
-
-    image = new image::Image(Desc.Width, Desc.Height, 3, true);
-    if (!image) {
-        goto no_image;
-    }
-
-    dst = image->start();
-    src = (const unsigned char *)LockedRect.pBits;
-    for (unsigned y = 0; y < Desc.Height; ++y) {
-        for (unsigned x = 0; x < Desc.Width; ++x) {
-            dst[3*x + 0] = src[4*x + 2];
-            dst[3*x + 1] = src[4*x + 1];
-            dst[3*x + 2] = src[4*x + 0];
-        }
-        src += LockedRect.Pitch;
-        dst += image->stride();
-    }
-
-no_image:
-    pStagingSurface->UnlockRect();
-no_rendertargetdata:
-    pStagingSurface->Release();
-no_staging:
-    pRenderTarget->Release();
-no_rendertarget:
-    return image;
-}
-
-
-} /* namespace d3dstate */