Taking MSAA screenshot using D3DX10SaveTextureToFile()

| | August 10, 2015

I have some screenshot code (pasted below) which was working fine until I enabled MSAA. The first time I tried to use this code, it complained that the texture I’m creating needed to match the sample count of the source texture. Fine- my MSAA value is 8 currently, so I set the screenshot texture to a sample count of 8 also.

Now when I try to use the code, it complains:

ERROR: ID3D10Device::CreateTexture2D: A multisampled Texture2D cannot be bound to certain parts of the graphics pipeline, but must have at least one BindFlags bit set. The following BindFlags bits (0) cannot be set in this case: D3D10_BIND_VERTEX_BUFFER (0), D3D10_BIND_INDEX_BUFFER (0), D3D10_BIND_CONSTANT_BUFFER (0), D3D10_BIND_STREAM_OUTPUT (0)

Note- this happens when I call CreateTexture2D(). However, if I take the hint and try a BindFlag with my created texture (D3D10_BIND_RENDER_TARGET for example) I get the exact same error message when D3DX10SaveTextureToFile() is called.

Here is the code:

ID3D10Resource* pScreen;
mpRenderTargetView->GetResource( &pScreen );

HRESULT hr;

D3D10_TEXTURE2D_DESC texDesc;
texDesc.ArraySize = 1;
texDesc.BindFlags = D3D10_BIND_RENDER_TARGET;
texDesc.CPUAccessFlags = 0;
texDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;    
texDesc.Width = (unsigned int)mWindowSize.x;
texDesc.Height = (unsigned int)mWindowSize.y;
texDesc.MipLevels = 1;
texDesc.MiscFlags = 0;
texDesc.SampleDesc.Count = 8;
texDesc.SampleDesc.Quality = 0;
texDesc.Usage = D3D10_USAGE_DEFAULT;

ID3D10Texture2D *texture;
hr = mpD3DDevice->CreateTexture2D( &texDesc, 0, &texture );
mpD3DDevice->CopyResource( texture, pScreen );

char* filename = "TestFile.dds"

D3DX10SaveTextureToFile( texture, D3DX10_IFF_DDS, filename );
texture->Release();
pScreen->Release();

I should also mention that I’ve tried various file formats with no success yet. This function has been a real pain in the butt so if there’s a better way of doing this, I’d love to know it!

One Response to “Taking MSAA screenshot using D3DX10SaveTextureToFile()”

  1. I imagine it simply doesn’t understand multisampled images, I can’t think of an image format that supports them.

    ResolveSubresource(..) will let you copy from a multisampled source to a non-multisampled target, which you shouldn’t have trouble saving.

Leave a Reply