]> git.cworth.org Git - apitrace/commitdiff
Try to disassemble d3d10 shaders too.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 13 May 2012 14:08:37 +0000 (15:08 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 13 May 2012 14:08:37 +0000 (15:08 +0100)
wrappers/CMakeLists.txt
wrappers/d3d10shader.cpp [new file with mode: 0644]
wrappers/d3d10shader.hpp [new file with mode: 0644]
wrappers/d3d10trace.py

index 5e61ed392abc3c5ef5fa260042bbcc94c5344b6d..a33350470730fe5d4245a5a66dc81180448e194f 100644 (file)
@@ -130,7 +130,7 @@ if (WIN32)
                 ${CMAKE_SOURCE_DIR}/specs/winapi.py
                 ${CMAKE_SOURCE_DIR}/specs/stdapi.py
         )
-        add_library (d3d10trace MODULE d3d10.def d3d10trace.cpp)
+        add_library (d3d10trace MODULE d3d10.def d3d10trace.cpp d3d10shader.cpp)
         target_link_libraries (d3d10trace
             common
             ${ZLIB_LIBRARIES}
diff --git a/wrappers/d3d10shader.cpp b/wrappers/d3d10shader.cpp
new file mode 100644 (file)
index 0000000..3670f2f
--- /dev/null
@@ -0,0 +1,115 @@
+/**************************************************************************
+ *
+ * Copyright 2011 Jose Fonseca
+ * Copyright 2008-2009 VMware, Inc.
+ * 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 "d3d10shader.hpp"
+
+
+struct ID3D10Blob : public IUnknown {
+public:
+    virtual LPVOID STDMETHODCALLTYPE GetBufferPointer( void) = 0;
+    virtual SIZE_T STDMETHODCALLTYPE GetBufferSize( void) = 0;
+};
+
+typedef ID3D10Blob ID3DBlob;
+typedef ID3DBlob* LPD3DBLOB;
+
+#define D3D_DISASM_ENABLE_COLOR_CODE            0x00000001
+#define D3D_DISASM_ENABLE_DEFAULT_VALUE_PRINTS  0x00000002
+#define D3D_DISASM_ENABLE_INSTRUCTION_NUMBERING 0x00000004
+#define D3D_DISASM_ENABLE_INSTRUCTION_CYCLE     0x00000008
+#define D3D_DISASM_DISABLE_DEBUG_INFO           0x00000010
+#define D3D_DISASM_ENABLE_INSTRUCTION_OFFSET    0x00000020
+#define D3D_DISASM_INSTRUCTION_ONLY             0x00000040
+
+typedef HRESULT
+(WINAPI *PFND3DDISASSEMBLE)(
+    LPCVOID pSrcData,
+    SIZE_T SrcDataSize,
+    UINT Flags,
+    LPCSTR szComments,
+    ID3DBlob **ppDisassembly
+);
+
+
+static HMODULE hD3DCompilerModule = NULL;
+static PFND3DDISASSEMBLE pfnD3DDisassemble = NULL;
+
+
+void DumpShader(trace::Writer &writer, const void *pShaderBytecode, SIZE_T BytecodeLength)
+{
+    static BOOL firsttime = TRUE;
+
+    if (firsttime) {
+        if (!hD3DCompilerModule) {
+            int version;
+            for (version = 44; version >= 33; --version) {
+                char filename[256];
+                _snprintf(filename, sizeof(filename), "d3dcompiler_%u.dll", version);
+                hD3DCompilerModule = LoadLibraryA(filename);
+                if (hD3DCompilerModule) {
+                    break;
+                }
+            }
+        }
+
+        if (hD3DCompilerModule) {
+            if (!pfnD3DDisassemble) {
+                pfnD3DDisassemble = (PFND3DDISASSEMBLE)GetProcAddress(hD3DCompilerModule, "D3DDisassemble");
+            }
+        }
+
+        firsttime = FALSE;
+    }
+
+    /*
+     * TODO: Fallback to D3D10DisassembleShader, which should be always present.
+     */
+
+    LPD3DBLOB pDisassembly = NULL;
+    HRESULT hr = E_FAIL;
+
+    if (pfnD3DDisassemble) {
+        hr = pfnD3DDisassemble(pShaderBytecode, BytecodeLength, 0, NULL, &pDisassembly);
+    }
+
+    if (SUCCEEDED(hr)) {
+        writer.beginRepr();
+        writer.writeString((const char *)pDisassembly->GetBufferPointer(), pDisassembly->GetBufferSize());
+    }
+
+    writer.writeBlob(pShaderBytecode, BytecodeLength);
+
+    if (pDisassembly) {
+        pDisassembly->Release();
+    }
+    
+    if (SUCCEEDED(hr)) {
+        writer.endRepr();
+    }
+}
diff --git a/wrappers/d3d10shader.hpp b/wrappers/d3d10shader.hpp
new file mode 100644 (file)
index 0000000..b447b48
--- /dev/null
@@ -0,0 +1,38 @@
+/**************************************************************************
+ *
+ * Copyright 2011 Jose Fonseca
+ * Copyright 2008-2009 VMware, Inc.
+ * 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 _D3D10SHADER_HPP_
+#define _D3D10SHADER_HPP_
+
+
+#include <windows.h>
+
+#include "trace_writer.hpp"
+
+void DumpShader(trace::Writer &writer, const void *pShaderBytecode, SIZE_T BytecodeLength);
+
+
+#endif /* _D3D10SHADER_HPP_ */
index 3529d582039f95db441796ad21b9ef54d08c5c8e..d43f042b08f2a8e6efa1328f045b524f24cc88ac 100644 (file)
 
 
 from dlltrace import DllTracer
+from specs import stdapi
 from specs.d3d10misc import d3d10
 
 
+class D3D10Tracer(DllTracer):
+
+    def serializeArgValue(self, function, arg):
+        # Dump shaders as strings
+        if isinstance(arg.type, stdapi.Blob) and arg.name.startswith('pShaderBytecode'):
+            print '    DumpShader(trace::localWriter, %s, %s);' % (arg.name, arg.type.size)
+            return
+
+        DllTracer.serializeArgValue(self, function, arg)
+
 if __name__ == '__main__':
     print '#define INITGUID'
     print
@@ -35,6 +46,7 @@ if __name__ == '__main__':
     print '#include "os.hpp"'
     print
     print '#include "d3d10imports.hpp"'
+    print '#include "d3d10shader.hpp"'
     print
-    tracer = DllTracer('d3d10.dll')
+    tracer = D3D10Tracer('d3d10.dll')
     tracer.traceApi(d3d10)