From: José Fonseca Date: Tue, 4 Dec 2012 13:04:14 +0000 (+0000) Subject: d3dretrace: Dump D3D11 images/shaders too. X-Git-Url: https://git.cworth.org/git?p=apitrace;a=commitdiff_plain;h=1592ad278ba90ed2d5f6fa2b49fadf2cc6e4e77e d3dretrace: Dump D3D11 images/shaders too. --- diff --git a/retrace/d3d10state.cpp b/retrace/d3d10state.cpp index 15be6c4..d5e41da 100644 --- a/retrace/d3d10state.cpp +++ b/retrace/d3d10state.cpp @@ -28,10 +28,8 @@ #include -#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 index 0000000..b480bd6 --- /dev/null +++ b/retrace/d3d10state.hpp @@ -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 + + +#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_ diff --git a/retrace/d3d11state.cpp b/retrace/d3d11state.cpp index 05885f4..bc8f7c4 100644 --- a/retrace/d3d11state.cpp +++ b/retrace/d3d11state.cpp @@ -29,18 +29,62 @@ #include #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(json, "VS", pVertexShader); + pVertexShader->Release(); + } + + ID3D11GeometryShader *pGeometryShader = NULL; + pDeviceContext->GSGetShader(&pGeometryShader, NULL, NULL); + if (pGeometryShader) { + dumpShader(json, "GS", pGeometryShader); + pGeometryShader->Release(); + } + + ID3D11PixelShader *pPixelShader = NULL; + pDeviceContext->PSGetShader(&pPixelShader, NULL, NULL); + if (pPixelShader) { + dumpShader(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); } diff --git a/retrace/d3d11state_images.cpp b/retrace/d3d11state_images.cpp index 9c6ff87..fda85b1 100644 --- a/retrace/d3d11state_images.cpp +++ b/retrace/d3d11state_images.cpp @@ -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 */ diff --git a/retrace/d3dstate.hpp b/retrace/d3dstate.hpp index 09e82a2..86614d5 100644 --- a/retrace/d3dstate.hpp +++ b/retrace/d3dstate.hpp @@ -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);