From: José Fonseca Date: Mon, 20 May 2013 12:41:55 +0000 (+0100) Subject: d3dstate: Dump depth-stencil images. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=56bf7086eb523e64a181ded24d9c100dcaaa8026;p=apitrace d3dstate: Dump depth-stencil images. Only the depth values are written so far. --- diff --git a/retrace/d3d10state_images.cpp b/retrace/d3d10state_images.cpp index ca40837..1fc4492 100644 --- a/retrace/d3d10state_images.cpp +++ b/retrace/d3d10state_images.cpp @@ -269,6 +269,87 @@ no_staging: 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; + } + 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)) { + goto no_map; + } + + 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; +} + image::Image * getRenderTargetImage(ID3D10Device *pDevice) { @@ -292,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]) { @@ -312,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 } diff --git a/retrace/d3d11state_images.cpp b/retrace/d3d11state_images.cpp index 08f745d..1fcc80c 100644 --- a/retrace/d3d11state_images.cpp +++ b/retrace/d3d11state_images.cpp @@ -142,7 +142,7 @@ stageResource(ID3D11DeviceContext *pDeviceContext, return hr; } -image::Image * +static image::Image * getRenderTargetViewImage(ID3D11DeviceContext *pDevice, ID3D11RenderTargetView *pRenderTargetView) { image::Image *image = NULL; @@ -229,6 +229,87 @@ no_staging: return image; } +static image::Image * +getDepthStencilViewImage(ID3D11DeviceContext *pDevice, + ID3D11DepthStencilView *pDepthStencilView) { + image::Image *image = NULL; + D3D11_DEPTH_STENCIL_VIEW_DESC Desc; + ID3D11Resource *pResource = NULL; + ID3D11Resource *pStagingResource = NULL; + UINT Width, Height, Depth; + UINT MipSlice; + UINT Subresource; + D3D11_MAPPED_SUBRESOURCE 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 D3D11_DSV_DIMENSION_TEXTURE1D: + MipSlice = Desc.Texture1D.MipSlice; + break; + case D3D11_DSV_DIMENSION_TEXTURE1DARRAY: + MipSlice = Desc.Texture1DArray.MipSlice; + break; + case D3D11_DSV_DIMENSION_TEXTURE2D: + MipSlice = Desc.Texture2D.MipSlice; + MipSlice = 0; + break; + case D3D11_DSV_DIMENSION_TEXTURE2DARRAY: + MipSlice = Desc.Texture2DArray.MipSlice; + break; + case D3D11_DSV_DIMENSION_TEXTURE2DMS: + MipSlice = 0; + break; + case D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY: + MipSlice = 0; + break; + case D3D11_SRV_DIMENSION_UNKNOWN: + default: + assert(0); + goto no_map; + } + Subresource = MipSlice; + + Width = std::max(Width >> MipSlice, 1U); + Height = std::max(Height >> MipSlice, 1U); + Depth = std::max(Depth >> MipSlice, 1U); + + hr = pDevice->Map(pStagingResource, Subresource, D3D11_MAP_READ, 0, &MappedSubresource); + if (FAILED(hr)) { + goto no_map; + } + + image = ConvertImage(Desc.Format, + MappedSubresource.pData, + MappedSubresource.RowPitch, + Width, Height); + + pDevice->Unmap(pStagingResource, Subresource); +no_map: + if (pStagingResource) { + pStagingResource->Release(); + } +no_staging: + if (pResource) { + pResource->Release(); + } + return image; +} + image::Image * getRenderTargetImage(ID3D11DeviceContext *pDevice) { @@ -252,7 +333,9 @@ dumpFramebuffer(JSONWriter &json, ID3D11DeviceContext *pDevice) json.beginObject(); ID3D11RenderTargetView *pRenderTargetViews[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT]; - pDevice->OMGetRenderTargets(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, pRenderTargetViews, NULL); + ID3D11DepthStencilView *pDepthStencilView; + pDevice->OMGetRenderTargets(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, pRenderTargetViews, + &pDepthStencilView); for (UINT i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i) { if (!pRenderTargetViews[i]) { @@ -272,6 +355,19 @@ dumpFramebuffer(JSONWriter &json, ID3D11DeviceContext *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 }