#include <iostream>
-#include "d3d11imports.hpp"
-#include "json.hpp"
-#include "d3dshader.hpp"
-#include "d3dstate.hpp"
+#include "d3d10imports.hpp"
+#include "d3d10state.hpp"
namespace d3dstate {
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)
{
--- /dev/null
+/**************************************************************************
+ *
+ * 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_
#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);
}
#include "image.hpp"
#include "d3d11imports.hpp"
+#include "d3d10state.hpp"
namespace d3dstate {
}
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;
const unsigned char *src;
unsigned char *dst;
- pDevice->OMGetRenderTargets(1, &pRenderTargetView, NULL);
if (!pRenderTargetView) {
- goto no_rendertarget;
+ return NULL;
}
pRenderTargetView->GetResource(&pResource);
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;
}
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);
}
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 */
image::Image *
getRenderTargetImage(ID3D11DeviceContext *pDeviceContext);
+void
+dumpFramebuffer(JSONWriter &json, ID3D11DeviceContext *pDeviceContext);
+
void
dumpDevice(std::ostream &os, ID3D11DeviceContext *pDeviceContext);