X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=retrace%2Fd3d10state_images.cpp;h=1fc44926c467304c45234c2df327b7f7751f0156;hb=06e495aaa6693dd618f01d311a436b0b9831efbb;hp=53d5b9125de75abf16a075fde09367cd6aec1df6;hpb=c8695f74ce1ee6a93dee4b3f7da5a70a64706c82;p=apitrace diff --git a/retrace/d3d10state_images.cpp b/retrace/d3d10state_images.cpp index 53d5b91..1fc4492 100644 --- a/retrace/d3d10state_images.cpp +++ b/retrace/d3d10state_images.cpp @@ -29,7 +29,7 @@ #include #include -#include "image.hpp" +#include "os.hpp" #include "json.hpp" #include "d3d10imports.hpp" #include "d3dstate.hpp" @@ -252,25 +252,92 @@ getRenderTargetViewImage(ID3D10Device *pDevice, goto no_map; } - image = new image::Image(Width, Height, 4); - if (!image) { - goto no_image; + image = ConvertImage(Desc.Format, + MappedSubresource.pData, + MappedSubresource.RowPitch, + Width, Height); + + unmapResource(pStagingResource, Subresource); +no_map: + if (pStagingResource) { + pStagingResource->Release(); + } +no_staging: + if (pResource) { + pResource->Release(); + } + return image; +} + +static image::Image * +getDepthStencilViewImage(ID3D10Device *pDevice, + ID3D10DepthStencilView *pDepthStencilView) { + image::Image *image = NULL; + D3D10_DEPTH_STENCIL_VIEW_DESC Desc; + ID3D10Resource *pResource = NULL; + ID3D10Resource *pStagingResource = NULL; + UINT Width, Height, Depth; + UINT MipSlice; + UINT Subresource; + D3D10_MAPPED_TEXTURE3D MappedSubresource; + HRESULT hr; + + if (!pDepthStencilView) { + return NULL; + } + + pDepthStencilView->GetResource(&pResource); + assert(pResource); + + pDepthStencilView->GetDesc(&Desc); + + hr = stageResource(pDevice, pResource, &pStagingResource, &Width, &Height, &Depth); + if (FAILED(hr)) { + goto no_staging; + } + + // TODO: Take the slice in consideration + switch (Desc.ViewDimension) { + case D3D10_DSV_DIMENSION_TEXTURE1D: + MipSlice = Desc.Texture1D.MipSlice; + break; + case D3D10_DSV_DIMENSION_TEXTURE1DARRAY: + MipSlice = Desc.Texture1DArray.MipSlice; + break; + case D3D10_DSV_DIMENSION_TEXTURE2D: + MipSlice = Desc.Texture2D.MipSlice; + MipSlice = 0; + break; + case D3D10_DSV_DIMENSION_TEXTURE2DARRAY: + MipSlice = Desc.Texture2DArray.MipSlice; + break; + case D3D10_DSV_DIMENSION_TEXTURE2DMS: + MipSlice = 0; + break; + case D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY: + MipSlice = 0; + break; + case D3D10_SRV_DIMENSION_UNKNOWN: + default: + assert(0); + goto no_map; } - assert(image->stride() > 0); - - hr = ConvertFormat(Desc.Format, - MappedSubresource.pData, - MappedSubresource.RowPitch, - DXGI_FORMAT_R8G8B8A8_UNORM, - image->start(), - image->stride(), - Width, Height); + Subresource = MipSlice; + + Width = std::max(Width >> MipSlice, 1U); + Height = std::max(Height >> MipSlice, 1U); + Depth = std::max(Depth >> MipSlice, 1U); + + hr = mapResource(pStagingResource, Subresource, D3D10_MAP_READ, 0, &MappedSubresource); if (FAILED(hr)) { - delete image; - image = NULL; + goto no_map; } -no_image: + image = ConvertImage(Desc.Format, + MappedSubresource.pData, + MappedSubresource.RowPitch, + Width, Height); + unmapResource(pStagingResource, Subresource); no_map: if (pStagingResource) { @@ -306,7 +373,9 @@ dumpFramebuffer(JSONWriter &json, ID3D10Device *pDevice) json.beginObject(); ID3D10RenderTargetView *pRenderTargetViews[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT]; - pDevice->OMGetRenderTargets(D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, pRenderTargetViews, NULL); + ID3D10DepthStencilView *pDepthStencilView; + pDevice->OMGetRenderTargets(D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT, pRenderTargetViews, + &pDepthStencilView); for (UINT i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i) { if (!pRenderTargetViews[i]) { @@ -326,6 +395,19 @@ dumpFramebuffer(JSONWriter &json, ID3D10Device *pDevice) pRenderTargetViews[i]->Release(); } + if (pDepthStencilView) { + image::Image *image; + image = getDepthStencilViewImage(pDevice, pDepthStencilView); + if (image) { + json.beginMember("DEPTH_STENCIL"); + json.writeImage(image, "UNKNOWN"); + json.endMember(); + } + + pDepthStencilView->Release(); + + } + json.endObject(); json.endMember(); // framebuffer }