Jump to content
  • Advertisement
Sign in to follow this  

DX11 Resolvesubresource, why no error without AA?

This topic is 437 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all,

I've just implemented a screenshot function for my engine, using dx11.
This all works fine, also when the rendertarget has MSAA applied, then I use resolvesubresource into an additional rendertarget.

Basically, without AA:

- copy primary RT to RT with usage STAGING and CPU access (staging texture)
- map the RT, copy the pixel data and unmap

And with AA:

- copy primary RT with AA to temporary 1 without AA (usage default, no CPU access) (resolve texture)
- copy temporary RT without AA to new RT with usage STAGING and CPU access (staging texture)
- map the RT, copy the pixel data and unmap

So it all works fine, I applied a branch for MSAA enabled/ disabled.

My question; according to the MSDN documentation, "Resolvesubresource", should only work when 'source' has >1 samples and 'dest' has 1 sample (in the desc). But somehow the process with the resolve texture, including using 'resolvesubresource', also works when I don't have MSAA enabled. So both source + dest has 1 sample.

I would expect the D3D debugger/ logging to give an error or at least a warning.
Below the code in which this applies (don't mind it not being optimized/ cleaned up yet, just for illustration)

std::vector<char> DX11RenderTarget::GetRGBByteArray() const
	CComPtr<ID3D11Device> myDev;
	CComPtr<ID3D11DeviceContext> myDevContext;

	// resolve texture
	tempRTDesc.Width				= mWidth;
	tempRTDesc.Height				= mHeight;
	tempRTDesc.MipLevels			= 1;
	tempRTDesc.ArraySize			= 1;
	tempRTDesc.Format				= mDXGIFormat;
	tempRTDesc.BindFlags			= 0;
	tempRTDesc.MiscFlags			= 0;
	tempRTDesc.SampleDesc.Count		= 1;
	tempRTDesc.SampleDesc.Quality	= 0;
	tempRTDesc.Usage			= D3D11_USAGE_DEFAULT;
	tempRTDesc.CPUAccessFlags	= 0;

	CComPtr<ID3D11Texture2D> tempTex;
	CComPtr<ID3D11Texture2D> anotherTempTex;
	myDev->CreateTexture2D(&tempRTDesc, 0, &tempTex);			// add check if(FAILED), logging

	myDevContext->ResolveSubresource(tempTex, 0, mBuffer, 0, GetDXGIFormat(mBufferFormat));		// format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB ; not flexible now

	// staging texture
	tempRTDesc.Usage				= D3D11_USAGE_STAGING;
	tempRTDesc.CPUAccessFlags		= D3D11_CPU_ACCESS_READ;

	myDev->CreateTexture2D(&tempRTDesc, 0, &anotherTempTex);			// add check if(FAILED), logging
	myDevContext->CopyResource(anotherTempTex, tempTex);	

	// map, copy pixels and unmap
	myDevContext->Map(anotherTempTex, 0, D3D11_MAP_READ, 0, &loadPixels);

 	std::vector<char> image(mWidth*mHeight*3);

	char *texPtr = (char*)loadPixels.pData;
	int currPos = 0;
	for(size_t row=0;row<mHeight;++row)
		texPtr = (char*)loadPixels.pData + loadPixels.RowPitch * row;

		for(size_t j=0;j<mWidth*4;j+=4)		// RGBA, skip Alpha
			image[currPos] = texPtr[j];
			image[currPos+1] = texPtr[j+1];
			image[currPos+2] = texPtr[j+2];
			currPos += 3;
	myDevContext->Unmap(anotherTempTex, 0);

	return image;


Edited by cozzie

Share this post

Link to post
Share on other sites

I've known this to work in the past as well. It's probably just for convenience that it was made to work with 1 -> 1 Resolves. It may even boil down to a 'Copy' somewhere further down the stack. I wouldn't complain though!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!