]> git.cworth.org Git - apitrace/blobdiff - wrappers/d3dshader.cpp
Preserve both D3D9 shader byte code, and disassembly.
[apitrace] / wrappers / d3dshader.cpp
index ee9cd9a55d8f1516d9def454f122a3511904aa37..7a1e5520796c0f7527c292aa1384180423530933 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "d3dshader.hpp"
 #include "d3d9imports.hpp"
+#include "d3dsize.hpp"
 
 
 typedef HRESULT
@@ -43,6 +44,12 @@ typedef HRESULT
 void DumpShader(trace::Writer &writer, const DWORD *tokens)
 {
     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;
 
@@ -74,23 +81,25 @@ found:
         firsttime = FALSE;
     }
 
-    if (pfnD3DXDisassembleShader) {
-        LPD3DXBUFFER pDisassembly = NULL;
-        HRESULT hr;
+    LPD3DXBUFFER pDisassembly = NULL;
+    HRESULT hr = E_FAIL;
 
+    if (pfnD3DXDisassembleShader) {
         hr = pfnD3DXDisassembleShader(tokens, FALSE, NULL, &pDisassembly);
-        if (hr == D3D_OK) {
-            writer.writeString((const char *)pDisassembly->GetBufferPointer());
-        }
-
-        if (pDisassembly) {
-            pDisassembly->Release();
-        }
+    }
 
-        if (hr == D3D_OK) {
-            return;
-        }
+    if (hr == D3D_OK) {
+        writer.beginRepr();
+        writer.writeString((const char *)pDisassembly->GetBufferPointer(), pDisassembly->GetBufferSize());
     }
 
-    writer.writePointer((UINT_PTR)tokens);
+    writer.writeBlob(tokens, _shaderSize(tokens));
+
+    if (pDisassembly) {
+        pDisassembly->Release();
+    }
+    
+    if (hr == D3D_OK) {
+        writer.endRepr();
+    }
 }