From 69d1d82691171762074f3364737287c9b1b18192 Mon Sep 17 00:00:00 2001 From: walbourn_cp Date: Thu, 18 Oct 2012 15:25:20 -0700 Subject: [PATCH] ScreenGrab: Extra validation and typeless handling for capturing MSAA textures -http://directxtex.codeplex.com/workitem/810 --- Src/ScreenGrab.cpp | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/Src/ScreenGrab.cpp b/Src/ScreenGrab.cpp index 273937010..b7fa2d645 100644 --- a/Src/ScreenGrab.cpp +++ b/Src/ScreenGrab.cpp @@ -306,6 +306,36 @@ static void GetSurfaceInfo( _In_ size_t width, } +//-------------------------------------------------------------------------------------- +static DXGI_FORMAT EnsureNotTypeless( DXGI_FORMAT fmt ) +{ + // Assumes UNORM or FLOAT; doesn't use UINT or SINT + switch( fmt ) + { + case DXGI_FORMAT_R32G32B32A32_TYPELESS: return DXGI_FORMAT_R32G32B32A32_FLOAT; + case DXGI_FORMAT_R32G32B32_TYPELESS: return DXGI_FORMAT_R32G32B32_FLOAT; + case DXGI_FORMAT_R16G16B16A16_TYPELESS: return DXGI_FORMAT_R16G16B16A16_UNORM; + case DXGI_FORMAT_R32G32_TYPELESS: return DXGI_FORMAT_R32G32_FLOAT; + case DXGI_FORMAT_R10G10B10A2_TYPELESS: return DXGI_FORMAT_R10G10B10A2_UNORM; + case DXGI_FORMAT_R8G8B8A8_TYPELESS: return DXGI_FORMAT_R8G8B8A8_UNORM; + case DXGI_FORMAT_R16G16_TYPELESS: return DXGI_FORMAT_R16G16_UNORM; + case DXGI_FORMAT_R32_TYPELESS: return DXGI_FORMAT_R32_FLOAT; + case DXGI_FORMAT_R8G8_TYPELESS: return DXGI_FORMAT_R8G8_UNORM; + case DXGI_FORMAT_R16_TYPELESS: return DXGI_FORMAT_R16_UNORM; + case DXGI_FORMAT_R8_TYPELESS: return DXGI_FORMAT_R8_UNORM; + case DXGI_FORMAT_BC1_TYPELESS: return DXGI_FORMAT_BC1_UNORM; + case DXGI_FORMAT_BC2_TYPELESS: return DXGI_FORMAT_BC2_UNORM; + case DXGI_FORMAT_BC3_TYPELESS: return DXGI_FORMAT_BC3_UNORM; + case DXGI_FORMAT_BC4_TYPELESS: return DXGI_FORMAT_BC4_UNORM; + case DXGI_FORMAT_BC5_TYPELESS: return DXGI_FORMAT_BC5_UNORM; + case DXGI_FORMAT_B8G8R8A8_TYPELESS: return DXGI_FORMAT_B8G8R8A8_UNORM; + case DXGI_FORMAT_B8G8R8X8_TYPELESS: return DXGI_FORMAT_B8G8R8X8_UNORM; + case DXGI_FORMAT_BC7_TYPELESS: return DXGI_FORMAT_BC7_UNORM; + default: return fmt; + } +} + + //-------------------------------------------------------------------------------------- static HRESULT CaptureTexture( _In_ ID3D11DeviceContext* pContext, _In_ ID3D11Resource* pSource, @@ -346,12 +376,22 @@ static HRESULT CaptureTexture( _In_ ID3D11DeviceContext* pContext, assert( pTemp.Get() ); + DXGI_FORMAT fmt = EnsureNotTypeless( desc.Format ); + + UINT support = 0; + hr = d3dDevice->CheckFormatSupport( fmt, &support ); + if ( FAILED(hr) ) + return hr; + + if ( !(support & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE) ) + return E_FAIL; + for( UINT item = 0; item < desc.ArraySize; ++item ) { for( UINT level = 0; level < desc.MipLevels; ++level ) { UINT index = D3D11CalcSubresource( level, item, desc.MipLevels ); - pContext->ResolveSubresource( pTemp.Get(), index, pSource, index, desc.Format ); + pContext->ResolveSubresource( pTemp.Get(), index, pSource, index, fmt ); } }