X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=retrace%2Fd3d11state_images.cpp;h=64169d41917c23aaa2c196c49124ad4a39b26008;hb=b9c20609ce007c6e07562df57b8a5d845061b9e4;hp=1fcc80cf1f6c25f88fd35f160630e1ae97ea6ab7;hpb=56bf7086eb523e64a181ded24d9c100dcaaa8026;p=apitrace diff --git a/retrace/d3d11state_images.cpp b/retrace/d3d11state_images.cpp index 1fcc80c..64169d4 100644 --- a/retrace/d3d11state_images.cpp +++ b/retrace/d3d11state_images.cpp @@ -142,18 +142,116 @@ stageResource(ID3D11DeviceContext *pDeviceContext, return hr; } +static image::Image * +getSubResourceImage(ID3D11DeviceContext *pDevice, + ID3D11Resource *pResource, + DXGI_FORMAT Format, + UINT MipSlice) +{ + image::Image *image = NULL; + ID3D11Resource *pStagingResource = NULL; + UINT Width, Height, Depth; + UINT SubResource = MipSlice; + D3D11_MAPPED_SUBRESOURCE MappedSubResource; + HRESULT hr; + + if (!pResource) { + return NULL; + } + + hr = stageResource(pDevice, pResource, &pStagingResource, &Width, &Height, &Depth); + if (FAILED(hr)) { + goto no_staging; + } + + 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(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; +} + + +static image::Image * +getShaderResourceViewImage(ID3D11DeviceContext *pDevice, + ID3D11ShaderResourceView *pShaderResourceView) { + D3D11_SHADER_RESOURCE_VIEW_DESC Desc; + ID3D11Resource *pResource = NULL; + UINT MipSlice; + + if (!pShaderResourceView) { + return NULL; + } + + pShaderResourceView->GetResource(&pResource); + assert(pResource); + + pShaderResourceView->GetDesc(&Desc); + + // TODO: Take the slice in consideration + switch (Desc.ViewDimension) { + case D3D11_SRV_DIMENSION_BUFFER: + MipSlice = 0; + break; + case D3D11_SRV_DIMENSION_TEXTURE1D: + MipSlice = Desc.Texture1D.MostDetailedMip; + break; + case D3D11_SRV_DIMENSION_TEXTURE1DARRAY: + MipSlice = Desc.Texture1DArray.MostDetailedMip; + break; + case D3D11_SRV_DIMENSION_TEXTURE2D: + MipSlice = Desc.Texture2D.MostDetailedMip; + break; + case D3D11_SRV_DIMENSION_TEXTURE2DARRAY: + MipSlice = Desc.Texture2DArray.MostDetailedMip; + break; + case D3D11_SRV_DIMENSION_TEXTURE2DMS: + MipSlice = 0; + break; + case D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY: + MipSlice = 0; + break; + case D3D11_SRV_DIMENSION_TEXTURE3D: + MipSlice = Desc.Texture3D.MostDetailedMip; + break; + case D3D11_SRV_DIMENSION_TEXTURECUBE: + MipSlice = Desc.TextureCube.MostDetailedMip; + break; + case D3D11_SRV_DIMENSION_UNKNOWN: + default: + assert(0); + return NULL; + } + + return getSubResourceImage(pDevice, pResource, Desc.Format, MipSlice); +} + + static image::Image * getRenderTargetViewImage(ID3D11DeviceContext *pDevice, ID3D11RenderTargetView *pRenderTargetView) { - image::Image *image = NULL; D3D11_RENDER_TARGET_VIEW_DESC Desc; ID3D11Resource *pResource = NULL; - ID3D11Resource *pStagingResource = NULL; - UINT Width, Height, Depth; UINT MipSlice; - UINT Subresource; - D3D11_MAPPED_SUBRESOURCE MappedSubresource; - HRESULT hr; if (!pRenderTargetView) { return NULL; @@ -164,11 +262,6 @@ getRenderTargetViewImage(ID3D11DeviceContext *pDevice, pRenderTargetView->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_RTV_DIMENSION_BUFFER: @@ -196,51 +289,22 @@ getRenderTargetViewImage(ID3D11DeviceContext *pDevice, case D3D11_RTV_DIMENSION_TEXTURE3D: MipSlice = Desc.Texture3D.MipSlice; break; - case D3D11_SRV_DIMENSION_UNKNOWN: + case D3D11_RTV_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; + return NULL; } - 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; + return getSubResourceImage(pDevice, pResource, Desc.Format, MipSlice); } + 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; @@ -251,11 +315,6 @@ getDepthStencilViewImage(ID3D11DeviceContext *pDevice, 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: @@ -266,7 +325,6 @@ getDepthStencilViewImage(ID3D11DeviceContext *pDevice, break; case D3D11_DSV_DIMENSION_TEXTURE2D: MipSlice = Desc.Texture2D.MipSlice; - MipSlice = 0; break; case D3D11_DSV_DIMENSION_TEXTURE2DARRAY: MipSlice = Desc.Texture2DArray.MipSlice; @@ -277,37 +335,45 @@ getDepthStencilViewImage(ID3D11DeviceContext *pDevice, case D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY: MipSlice = 0; break; - case D3D11_SRV_DIMENSION_UNKNOWN: + case D3D11_DSV_DIMENSION_UNKNOWN: default: assert(0); - goto no_map; + return NULL; } - Subresource = MipSlice; - Width = std::max(Width >> MipSlice, 1U); - Height = std::max(Height >> MipSlice, 1U); - Depth = std::max(Depth >> MipSlice, 1U); + return getSubResourceImage(pDevice, pResource, Desc.Format, MipSlice); +} - 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); +void +dumpTextures(JSONWriter &json, ID3D11DeviceContext *pDevice) +{ + json.beginMember("textures"); + json.beginObject(); - pDevice->Unmap(pStagingResource, Subresource); -no_map: - if (pStagingResource) { - pStagingResource->Release(); - } -no_staging: - if (pResource) { - pResource->Release(); + ID3D11ShaderResourceView *pShaderResourceViews[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT]; + pDevice->PSGetShaderResources(0, ARRAYSIZE(pShaderResourceViews), pShaderResourceViews); + + for (UINT i = 0; i < ARRAYSIZE(pShaderResourceViews); ++i) { + if (!pShaderResourceViews[i]) { + continue; + } + + image::Image *image; + image = getShaderResourceViewImage(pDevice, pShaderResourceViews[i]); + if (image) { + char label[64]; + _snprintf(label, sizeof label, "PS_RESOURCE_%u", i); + json.beginMember(label); + json.writeImage(image, "UNKNOWN"); + json.endMember(); // PS_RESOURCE_* + } + + pShaderResourceViews[i]->Release(); } - return image; + + json.endObject(); + json.endMember(); // textures } @@ -334,10 +400,10 @@ dumpFramebuffer(JSONWriter &json, ID3D11DeviceContext *pDevice) ID3D11RenderTargetView *pRenderTargetViews[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT]; ID3D11DepthStencilView *pDepthStencilView; - pDevice->OMGetRenderTargets(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, pRenderTargetViews, + pDevice->OMGetRenderTargets(ARRAYSIZE(pRenderTargetViews), pRenderTargetViews, &pDepthStencilView); - for (UINT i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i) { + for (UINT i = 0; i < ARRAYSIZE(pRenderTargetViews); ++i) { if (!pRenderTargetViews[i]) { continue; }