]> git.cworth.org Git - apitrace/commitdiff
d3dretrace: Dump D3D11 images/shaders too.
authorJosé Fonseca <jfonseca@vmware.com>
Tue, 4 Dec 2012 13:04:14 +0000 (13:04 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Tue, 4 Dec 2012 13:04:14 +0000 (13:04 +0000)
retrace/d3d10state.cpp
retrace/d3d10state.hpp [new file with mode: 0644]
retrace/d3d11state.cpp
retrace/d3d11state_images.cpp
retrace/d3dstate.hpp

index 15be6c48ceb930bac3f122bb48ea59075fd80c5d..d5e41da04146d3597264ed8f1dbea2e74c0f46c6 100644 (file)
 
 #include <iostream>
 
-#include "d3d11imports.hpp"
-#include "json.hpp"
-#include "d3dshader.hpp"
-#include "d3dstate.hpp"
+#include "d3d10imports.hpp"
+#include "d3d10state.hpp"
 
 
 namespace d3dstate {
@@ -41,46 +39,6 @@ const GUID
 GUID_D3DSTATE = {0x7D71CAC9,0x7F58,0x432C,{0xA9,0x75,0xA1,0x9F,0xCF,0xCE,0xFD,0x14}};
 
 
-template< class T >
-inline void
-dumpShader(JSONWriter &json, const char *name, T *pShader) {
-    if (!pShader) {
-        return;
-    }
-
-    HRESULT hr;
-
-    /*
-     * There is no method to get the shader byte code, so the creator is supposed to
-     * attach it via the SetPrivateData method.
-     */
-    UINT BytecodeLength = 0;
-    char dummy;
-    hr = pShader->GetPrivateData(GUID_D3DSTATE, &BytecodeLength, &dummy);
-    if (hr != DXGI_ERROR_MORE_DATA) {
-        return;
-    }
-
-    void *pShaderBytecode = malloc(BytecodeLength);
-    if (!pShaderBytecode) {
-        return;
-    }
-
-    hr = pShader->GetPrivateData(GUID_D3DSTATE, &BytecodeLength, pShaderBytecode);
-    if (SUCCEEDED(hr)) {
-        IDisassemblyBuffer *pDisassembly = NULL;
-        hr = DisassembleShader(pShaderBytecode, BytecodeLength, &pDisassembly);
-        if (SUCCEEDED(hr)) {
-            json.beginMember(name);
-            json.writeString((const char *)pDisassembly->GetBufferPointer() /*, pDisassembly->GetBufferSize() */);
-            json.endMember();
-            pDisassembly->Release();
-        }
-    }
-
-    free(pShaderBytecode);
-}
-
 static void
 dumpShaders(JSONWriter &json, ID3D10Device *pDevice)
 {
diff --git a/retrace/d3d10state.hpp b/retrace/d3d10state.hpp
new file mode 100644 (file)
index 0000000..b480bd6
--- /dev/null
@@ -0,0 +1,84 @@
+/**************************************************************************
+ *
+ * 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 _DXGISTATE_HPP_
+#define _DXGISTATE_HPP_
+
+
+#include <windows.h>
+
+
+#include "json.hpp"
+#include "d3dshader.hpp"
+#include "d3dstate.hpp"
+
+
+namespace d3dstate {
+
+
+template< class T >
+inline void
+dumpShader(JSONWriter &json, const char *name, T *pShader) {
+    if (!pShader) {
+        return;
+    }
+
+    HRESULT hr;
+
+    /*
+     * There is no method to get the shader byte code, so the creator is supposed to
+     * attach it via the SetPrivateData method.
+     */
+    UINT BytecodeLength = 0;
+    char dummy;
+    hr = pShader->GetPrivateData(GUID_D3DSTATE, &BytecodeLength, &dummy);
+    if (hr != DXGI_ERROR_MORE_DATA) {
+        return;
+    }
+
+    void *pShaderBytecode = malloc(BytecodeLength);
+    if (!pShaderBytecode) {
+        return;
+    }
+
+    hr = pShader->GetPrivateData(GUID_D3DSTATE, &BytecodeLength, pShaderBytecode);
+    if (SUCCEEDED(hr)) {
+        IDisassemblyBuffer *pDisassembly = NULL;
+        hr = DisassembleShader(pShaderBytecode, BytecodeLength, &pDisassembly);
+        if (SUCCEEDED(hr)) {
+            json.beginMember(name);
+            json.writeString((const char *)pDisassembly->GetBufferPointer() /*, pDisassembly->GetBufferSize() */);
+            json.endMember();
+            pDisassembly->Release();
+        }
+    }
+
+    free(pShaderBytecode);
+}
+
+
+} /* namespace d3dstate */
+
+#endif // _DXGISTATE_HPP_
index 05885f4cd2cde494760cd8e8627aaacd15f82371..bc8f7c44b2618f366585322c1deb8f14385ba6c5 100644 (file)
 #include <iostream>
 
 #include "d3d11imports.hpp"
-#include "json.hpp"
+#include "d3d10state.hpp"
 
 
 namespace d3dstate {
 
 
+static void
+dumpShaders(JSONWriter &json, ID3D11DeviceContext *pDeviceContext)
+{
+    json.beginMember("shaders");
+    json.beginObject();
+
+    ID3D11VertexShader *pVertexShader = NULL;
+    pDeviceContext->VSGetShader(&pVertexShader, NULL, NULL);
+    if (pVertexShader) {
+        dumpShader<ID3D11DeviceChild>(json, "VS", pVertexShader);
+        pVertexShader->Release();
+    }
+
+    ID3D11GeometryShader *pGeometryShader = NULL;
+    pDeviceContext->GSGetShader(&pGeometryShader, NULL, NULL);
+    if (pGeometryShader) {
+        dumpShader<ID3D11DeviceChild>(json, "GS", pGeometryShader);
+        pGeometryShader->Release();
+    }
+
+    ID3D11PixelShader *pPixelShader = NULL;
+    pDeviceContext->PSGetShader(&pPixelShader, NULL, NULL);
+    if (pPixelShader) {
+        dumpShader<ID3D11DeviceChild>(json, "PS", pPixelShader);
+    }
+
+    json.endObject();
+    json.endMember(); // shaders
+}
+
+
 void
 dumpDevice(std::ostream &os, ID3D11DeviceContext *pDeviceContext)
 {
     JSONWriter json(os);
 
     /* TODO */
+    json.beginMember("parameters");
+    json.beginObject();
+    json.endObject();
+    json.endMember(); // parameters
+
+    dumpShaders(json, pDeviceContext);
+
+    json.beginMember("textures");
+    json.beginObject();
+    json.endObject();
+    json.endMember(); // textures
+
+    dumpFramebuffer(json, pDeviceContext);
 }
 
 
index 9c6ff87d1835b45640b7b6d2adbc96f10b927484..fda85b15f05d8973b76450caed1b9295ed0f8f9c 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "image.hpp"
 #include "d3d11imports.hpp"
+#include "d3d10state.hpp"
 
 
 namespace d3dstate {
@@ -140,9 +141,10 @@ stageResource(ID3D11DeviceContext *pDeviceContext,
 }
 
 image::Image *
-getRenderTargetImage(ID3D11DeviceContext *pDevice) {
+getRenderTargetViewImage(ID3D11DeviceContext *pDevice,
+                         ID3D11RenderTargetView *pRenderTargetView) {
     image::Image *image = NULL;
-    ID3D11RenderTargetView *pRenderTargetView = NULL;
+    ;
     D3D11_RENDER_TARGET_VIEW_DESC Desc;
     ID3D11Resource *pResource = NULL;
     ID3D11Resource *pStagingResource = NULL;
@@ -154,9 +156,8 @@ getRenderTargetImage(ID3D11DeviceContext *pDevice) {
     const unsigned char *src;
     unsigned char *dst;
 
-    pDevice->OMGetRenderTargets(1, &pRenderTargetView, NULL);
     if (!pRenderTargetView) {
-        goto no_rendertarget;
+        return NULL;
     }
 
     pRenderTargetView->GetResource(&pResource);
@@ -164,7 +165,8 @@ getRenderTargetImage(ID3D11DeviceContext *pDevice) {
 
     pRenderTargetView->GetDesc(&Desc);
     if (Desc.Format != DXGI_FORMAT_R8G8B8A8_UNORM &&
-        Desc.Format != DXGI_FORMAT_R32G32B32A32_FLOAT) {
+        Desc.Format != DXGI_FORMAT_R32G32B32A32_FLOAT &&
+        Desc.Format != DXGI_FORMAT_B8G8R8A8_UNORM) {
         std::cerr << "warning: unsupported DXGI format " << Desc.Format << "\n";
         goto no_staging;
     }
@@ -235,6 +237,13 @@ getRenderTargetImage(ID3D11DeviceContext *pDevice) {
                 dst[4*x + 2] = ((float *)src)[4*x + 2] * scale;
                 dst[4*x + 3] = ((float *)src)[4*x + 3] * scale;
             }
+        } else if (Desc.Format == DXGI_FORMAT_B8G8R8A8_UNORM) {
+            for (unsigned x = 0; x < Width; ++x) {
+                dst[4*x + 0] = src[4*x + 2];
+                dst[4*x + 1] = src[4*x + 1];
+                dst[4*x + 2] = src[4*x + 0];
+                dst[4*x + 3] = src[4*x + 3];
+            }
         } else {
             assert(0);
         }
@@ -252,12 +261,57 @@ no_staging:
     if (pResource) {
         pResource->Release();
     }
+    return image;
+}
+
+
+
+
+image::Image *
+getRenderTargetImage(ID3D11DeviceContext *pDevice) {
+    ID3D11RenderTargetView *pRenderTargetView = NULL;
+    pDevice->OMGetRenderTargets(1, &pRenderTargetView, NULL);
+
+    image::Image *image = NULL;
     if (pRenderTargetView) {
+        image = getRenderTargetViewImage(pDevice, pRenderTargetView);
         pRenderTargetView->Release();
     }
-no_rendertarget:
+
     return image;
 }
 
 
+void
+dumpFramebuffer(JSONWriter &json, ID3D11DeviceContext *pDevice)
+{
+    json.beginMember("framebuffer");
+    json.beginObject();
+
+    ID3D11RenderTargetView *pRenderTargetViews[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
+    pDevice->OMGetRenderTargets(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, pRenderTargetViews, NULL);
+
+    for (UINT i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i) {
+        if (!pRenderTargetViews[i]) {
+            continue;
+        }
+
+        image::Image *image;
+        image = getRenderTargetViewImage(pDevice, pRenderTargetViews[i]);
+        if (image) {
+            char label[64];
+            _snprintf(label, sizeof label, "RENDER_TARGET_%u", i);
+            json.beginMember(label);
+            json.writeImage(image, "UNKNOWN");
+            json.endMember(); // RENDER_TARGET_*
+        }
+
+        pRenderTargetViews[i]->Release();
+    }
+
+    json.endObject();
+    json.endMember(); // framebuffer
+}
+
+
 } /* namespace d3dstate */
index 09e82a2805a96ae711cd647b4f94f8b584fa6b81..86614d565b414760d5c151d34bf01e4ed19dfd62 100644 (file)
@@ -70,6 +70,9 @@ dumpDevice(std::ostream &os, ID3D10Device *pDevice);
 image::Image *
 getRenderTargetImage(ID3D11DeviceContext *pDeviceContext);
 
+void
+dumpFramebuffer(JSONWriter &json, ID3D11DeviceContext *pDeviceContext);
+
 void
 dumpDevice(std::ostream &os, ID3D11DeviceContext *pDeviceContext);