summaryrefslogtreecommitdiff
path: root/retrace
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2013-04-16 19:38:00 +0100
committerJosé Fonseca <jfonseca@vmware.com>2013-04-16 19:38:00 +0100
commitbbb9eb32a3ea1fad91ee376e30195e6b9a0be550 (patch)
tree09ed0ace767f7d7c040ad917bf9f8c83bb19c7d4 /retrace
parent8ce1e6652fe471c2fb64102930625de8b2a16907 (diff)
d3dretrace: Dump UINT formats too.
Diffstat (limited to 'retrace')
-rw-r--r--retrace/d3d10state_images.cpp24
-rw-r--r--retrace/d3d11state_images.cpp25
-rw-r--r--retrace/dxgistate.cpp171
-rw-r--r--retrace/dxgistate.hpp11
-rw-r--r--retrace/retrace_main.cpp2
5 files changed, 194 insertions, 39 deletions
diff --git a/retrace/d3d10state_images.cpp b/retrace/d3d10state_images.cpp
index 53d5b912..ca408374 100644
--- a/retrace/d3d10state_images.cpp
+++ b/retrace/d3d10state_images.cpp
@@ -29,7 +29,7 @@
#include <iostream>
#include <algorithm>
-#include "image.hpp"
+#include "os.hpp"
#include "json.hpp"
#include "d3d10imports.hpp"
#include "d3dstate.hpp"
@@ -252,25 +252,11 @@ getRenderTargetViewImage(ID3D10Device *pDevice,
goto no_map;
}
- image = new image::Image(Width, Height, 4);
- if (!image) {
- goto no_image;
- }
- assert(image->stride() > 0);
-
- hr = ConvertFormat(Desc.Format,
- MappedSubresource.pData,
- MappedSubresource.RowPitch,
- DXGI_FORMAT_R8G8B8A8_UNORM,
- image->start(),
- image->stride(),
- Width, Height);
- if (FAILED(hr)) {
- delete image;
- image = NULL;
- }
+ image = ConvertImage(Desc.Format,
+ MappedSubresource.pData,
+ MappedSubresource.RowPitch,
+ Width, Height);
-no_image:
unmapResource(pStagingResource, Subresource);
no_map:
if (pStagingResource) {
diff --git a/retrace/d3d11state_images.cpp b/retrace/d3d11state_images.cpp
index 60efc7d4..08f745dd 100644
--- a/retrace/d3d11state_images.cpp
+++ b/retrace/d3d11state_images.cpp
@@ -29,7 +29,8 @@
#include <iostream>
#include <algorithm>
-#include "image.hpp"
+#include "os.hpp"
+#include "json.hpp"
#include "d3d11imports.hpp"
#include "d3d10state.hpp"
#include "dxgistate.hpp"
@@ -211,25 +212,11 @@ getRenderTargetViewImage(ID3D11DeviceContext *pDevice,
goto no_map;
}
- image = new image::Image(Width, Height, 4);
- if (!image) {
- goto no_image;
- }
- assert(image->stride() > 0);
-
- hr = ConvertFormat(Desc.Format,
- MappedSubresource.pData,
- MappedSubresource.RowPitch,
- DXGI_FORMAT_R8G8B8A8_UNORM,
- image->start(),
- image->stride(),
- Width, Height);
- if (FAILED(hr)) {
- delete image;
- image = NULL;
- }
+ image = ConvertImage(Desc.Format,
+ MappedSubresource.pData,
+ MappedSubresource.RowPitch,
+ Width, Height);
-no_image:
pDevice->Unmap(pStagingResource, Subresource);
no_map:
if (pStagingResource) {
diff --git a/retrace/dxgistate.cpp b/retrace/dxgistate.cpp
index 4a69f3fe..45d46cea 100644
--- a/retrace/dxgistate.cpp
+++ b/retrace/dxgistate.cpp
@@ -24,6 +24,10 @@
**************************************************************************/
+#include <assert.h>
+
+#include "image.hpp"
+
#include "dxgistate.hpp"
#ifdef __MINGW32__
@@ -35,6 +39,141 @@
namespace d3dstate {
+static DXGI_FORMAT
+ChooseConversionFormat(DXGI_FORMAT Format)
+{
+ switch (Format) {
+
+ // Float
+ case DXGI_FORMAT_R32G32B32A32_FLOAT:
+ case DXGI_FORMAT_R32G32B32_FLOAT:
+ case DXGI_FORMAT_R16G16B16A16_FLOAT:
+ case DXGI_FORMAT_R32G32_FLOAT:
+ case DXGI_FORMAT_R11G11B10_FLOAT:
+ case DXGI_FORMAT_R16G16_FLOAT:
+ case DXGI_FORMAT_R32_FLOAT:
+ case DXGI_FORMAT_R16_FLOAT:
+ case DXGI_FORMAT_R9G9B9E5_SHAREDEXP:
+ case DXGI_FORMAT_BC6H_UF16:
+ case DXGI_FORMAT_BC6H_SF16:
+ return DXGI_FORMAT_R8G8B8A8_UNORM;
+
+ // Unsigned normalized
+ case DXGI_FORMAT_R16G16B16A16_UNORM:
+ case DXGI_FORMAT_R10G10B10A2_UNORM:
+ case DXGI_FORMAT_R8G8B8A8_UNORM:
+ case DXGI_FORMAT_R16G16_UNORM:
+ case DXGI_FORMAT_R8G8_UNORM:
+ case DXGI_FORMAT_R16_UNORM:
+ case DXGI_FORMAT_R8_UNORM:
+ case DXGI_FORMAT_A8_UNORM:
+ case DXGI_FORMAT_R1_UNORM:
+ case DXGI_FORMAT_R8G8_B8G8_UNORM:
+ case DXGI_FORMAT_G8R8_G8B8_UNORM:
+ case DXGI_FORMAT_BC1_UNORM:
+ case DXGI_FORMAT_BC2_UNORM:
+ case DXGI_FORMAT_BC3_UNORM:
+ case DXGI_FORMAT_BC4_UNORM:
+ case DXGI_FORMAT_BC5_UNORM:
+ case DXGI_FORMAT_B5G6R5_UNORM:
+ case DXGI_FORMAT_B5G5R5A1_UNORM:
+ case DXGI_FORMAT_B8G8R8A8_UNORM:
+ case DXGI_FORMAT_B8G8R8X8_UNORM:
+ case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM:
+ case DXGI_FORMAT_BC7_UNORM:
+ return DXGI_FORMAT_R8G8B8A8_UNORM;
+
+ // SRGB
+ case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
+ case DXGI_FORMAT_BC1_UNORM_SRGB:
+ case DXGI_FORMAT_BC2_UNORM_SRGB:
+ case DXGI_FORMAT_BC3_UNORM_SRGB:
+ case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
+ case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
+ case DXGI_FORMAT_BC7_UNORM_SRGB:
+ return DXGI_FORMAT_R8G8B8A8_UNORM;
+
+ // Signed normalized
+ case DXGI_FORMAT_R16G16B16A16_SNORM:
+ case DXGI_FORMAT_R8G8B8A8_SNORM:
+ case DXGI_FORMAT_R16G16_SNORM:
+ case DXGI_FORMAT_R8G8_SNORM:
+ case DXGI_FORMAT_R16_SNORM:
+ case DXGI_FORMAT_R8_SNORM:
+ case DXGI_FORMAT_BC4_SNORM:
+ case DXGI_FORMAT_BC5_SNORM:
+ return DXGI_FORMAT_R8G8B8A8_SNORM;
+
+ // Unsigned
+ case DXGI_FORMAT_R32G32B32A32_UINT:
+ case DXGI_FORMAT_R32G32B32_UINT:
+ case DXGI_FORMAT_R16G16B16A16_UINT:
+ case DXGI_FORMAT_R32G32_UINT:
+ case DXGI_FORMAT_R10G10B10A2_UINT:
+ case DXGI_FORMAT_R8G8B8A8_UINT:
+ case DXGI_FORMAT_R16G16_UINT:
+ case DXGI_FORMAT_R32_UINT:
+ case DXGI_FORMAT_R8G8_UINT:
+ case DXGI_FORMAT_R16_UINT:
+ case DXGI_FORMAT_R8_UINT:
+ return DXGI_FORMAT_R8G8B8A8_UINT;
+
+ // Signed
+ case DXGI_FORMAT_R32G32B32A32_SINT:
+ case DXGI_FORMAT_R32G32B32_SINT:
+ case DXGI_FORMAT_R16G16B16A16_SINT:
+ case DXGI_FORMAT_R32G32_SINT:
+ case DXGI_FORMAT_R8G8B8A8_SINT:
+ case DXGI_FORMAT_R16G16_SINT:
+ case DXGI_FORMAT_R32_SINT:
+ case DXGI_FORMAT_R8G8_SINT:
+ case DXGI_FORMAT_R16_SINT:
+ case DXGI_FORMAT_R8_SINT:
+ return DXGI_FORMAT_R8G8B8A8_SINT;
+
+ // Depth
+ case DXGI_FORMAT_D32_FLOAT:
+ case DXGI_FORMAT_D24_UNORM_S8_UINT:
+ case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:
+ case DXGI_FORMAT_D16_UNORM:
+ return DXGI_FORMAT_R8G8B8A8_UNORM;
+
+ // Typeless
+ case DXGI_FORMAT_UNKNOWN:
+ case DXGI_FORMAT_R32G32B32A32_TYPELESS:
+ case DXGI_FORMAT_R32G32B32_TYPELESS:
+ case DXGI_FORMAT_R16G16B16A16_TYPELESS:
+ case DXGI_FORMAT_R32G32_TYPELESS:
+ case DXGI_FORMAT_R32G8X24_TYPELESS:
+ case DXGI_FORMAT_R10G10B10A2_TYPELESS:
+ case DXGI_FORMAT_R8G8B8A8_TYPELESS:
+ case DXGI_FORMAT_R16G16_TYPELESS:
+ case DXGI_FORMAT_R32_TYPELESS:
+ case DXGI_FORMAT_R8G8_TYPELESS:
+ case DXGI_FORMAT_R16_TYPELESS:
+ case DXGI_FORMAT_R8_TYPELESS:
+ case DXGI_FORMAT_BC1_TYPELESS:
+ case DXGI_FORMAT_BC2_TYPELESS:
+ case DXGI_FORMAT_BC3_TYPELESS:
+ case DXGI_FORMAT_BC4_TYPELESS:
+ case DXGI_FORMAT_BC5_TYPELESS:
+ case DXGI_FORMAT_B8G8R8A8_TYPELESS:
+ case DXGI_FORMAT_B8G8R8X8_TYPELESS:
+ case DXGI_FORMAT_BC6H_TYPELESS:
+ case DXGI_FORMAT_BC7_TYPELESS:
+ case DXGI_FORMAT_R24G8_TYPELESS:
+ case DXGI_FORMAT_R24_UNORM_X8_TYPELESS:
+ case DXGI_FORMAT_X24_TYPELESS_G8_UINT:
+ case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS:
+ case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT:
+ return DXGI_FORMAT_UNKNOWN;
+
+ default:
+ return DXGI_FORMAT_R8G8B8A8_UNORM;
+ }
+}
+
+
/**
* Convert between DXGI formats.
*
@@ -85,4 +224,36 @@ ConvertFormat(DXGI_FORMAT SrcFormat,
}
+image::Image *
+ConvertImage(DXGI_FORMAT SrcFormat,
+ void *SrcData,
+ UINT SrcPitch,
+ UINT Width, UINT Height)
+{
+
+ DXGI_FORMAT DstFormat = ChooseConversionFormat(SrcFormat);
+ if (DstFormat == DXGI_FORMAT_UNKNOWN) {
+ return NULL;
+ }
+
+ image::Image *image = new image::Image(Width, Height, 4);
+ if (!image) {
+ return NULL;
+ }
+ assert(image->stride() > 0);
+
+ HRESULT hr;
+ hr = ConvertFormat(SrcFormat,
+ SrcData, SrcPitch,
+ DstFormat,
+ image->start(), image->stride(),
+ Width, Height);
+ if (FAILED(hr)) {
+ delete image;
+ image = NULL;
+ }
+
+ return image;
+}
+
} /* namespace d3dstate */
diff --git a/retrace/dxgistate.hpp b/retrace/dxgistate.hpp
index f633373f..326b50f0 100644
--- a/retrace/dxgistate.hpp
+++ b/retrace/dxgistate.hpp
@@ -34,6 +34,11 @@
#include <dxgi.h>
+namespace image {
+ class Image;
+}
+
+
namespace d3dstate {
@@ -46,6 +51,12 @@ ConvertFormat(DXGI_FORMAT SrcFormat,
UINT DstPitch,
UINT Width, UINT Height);
+image::Image *
+ConvertImage(DXGI_FORMAT SrcFormat,
+ void *SrcData,
+ UINT SrcPitch,
+ UINT Width, UINT Height);
+
} /* namespace d3dstate */
diff --git a/retrace/retrace_main.cpp b/retrace/retrace_main.cpp
index 0c358e18..2d3311fe 100644
--- a/retrace/retrace_main.cpp
+++ b/retrace/retrace_main.cpp
@@ -119,7 +119,7 @@ takeSnapshot(unsigned call_no) {
image::Image *src = dumper->getSnapshot();
if (!src) {
- std::cout << "Failed to get snapshot\n";
+ std::cerr << call_no << ": warning: failed to get snapshot\n";
return;
}