Jump to content
  • Advertisement
Sign in to follow this  
Nathan Drake

DX11 Enable MSAA in DirectX 11

This topic is 1000 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

Hello guys, sup wink.png

 

Anti Aliasing in DX11 can be used if I set number of samples equal to 4 and set the sample quality to 1 and set View Dimension of the Dpeth Stencil view desc to D3D11_DSV_DIMENSION_TEXTURE2DMS.

 

but i have some question about it:

 

1. I can't apply this on my backbuffer, if i do, i'll get the complete black screen. (don't know what is the reason)

 

2. the only option i had was Depth/Stencil buffer but after applying these settings, i still didn't receive the correct result from my output. but based on MSDN resource when I create my Texture2D using CreateTexture2D(), the second attribute pInitialData can't be null if i want to use Multi Samples. but i don't know to what I have to set the pSysMem ?

 

3. since i use RenderToTexture method, am I have to apply these adjustments on those textures that i render my scene on them ?

 

4. is there any kind of limits for number of AA samples ?

 

 

you can take a look at my codes if you want :

	//Describe our SwapChain Buffer
	DXGI_MODE_DESC bufferDesc;

	ZeroMemory(&bufferDesc, sizeof(DXGI_MODE_DESC));	

	bufferDesc.Width = Width;
	bufferDesc.Height = Height;
	bufferDesc.RefreshRate.Numerator = 60;
	bufferDesc.RefreshRate.Denominator = 1;
	//bufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	bufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
	bufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
	bufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;

	//Describe our SwapChain
	DXGI_SWAP_CHAIN_DESC swapChainDesc;

	ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));

	swapChainDesc.BufferDesc = bufferDesc;
	swapChainDesc.SampleDesc.Count = 1;
	swapChainDesc.SampleDesc.Quality = 0;
	swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	swapChainDesc.BufferCount = 1;
	swapChainDesc.OutputWindow = hwnd;
	swapChainDesc.Windowed = TRUE;
	swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;


	//Create our SwapChain
	hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL,
		D3D11_SDK_VERSION, &swapChainDesc, &SwapChain, &d3d11Device, NULL, &d3d11DevCon);

	//Create our BackBuffer
	ID3D11Texture2D* BackBuffer;
	hr = SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&BackBuffer);

	//Create our Render Target
	hr = d3d11Device->CreateRenderTargetView(BackBuffer, NULL, &renderTargetView);
	BackBuffer->Release();

	//Describe our Depth/Stencil Buffer
	D3D11_TEXTURE2D_DESC depthStencilDesc;

	depthStencilDesc.Width = Width;
	depthStencilDesc.Height = Height;
	depthStencilDesc.MipLevels = 1;
	depthStencilDesc.ArraySize = 1;
	depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
	depthStencilDesc.SampleDesc.Count = 4;
	depthStencilDesc.SampleDesc.Quality = 1;
	depthStencilDesc.Usage = D3D11_USAGE_DEFAULT;
	depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
	depthStencilDesc.CPUAccessFlags = 0;
	depthStencilDesc.MiscFlags = 0;

	D3D11_DEPTH_STENCIL_VIEW_DESC _depthStencilViewDesc;
	ZeroMemory(&_depthStencilViewDesc, sizeof(D3D11_DEPTH_STENCIL_VIEW_DESC));
	_depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
	_depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS;
	_depthStencilViewDesc.Texture2D.MipSlice = 0;

	//Create the Depth/Stencil View
	d3d11Device->CreateTexture2D(&depthStencilDesc, NULL, &depthStencilBuffer);
	d3d11Device->CreateDepthStencilView(depthStencilBuffer, &_depthStencilViewDesc, &depthStencilView);
Edited by Nathan Drake

Share this post


Link to post
Share on other sites
Advertisement
On point 2 I think you've misread it; the data pointer must be null when creating a multi-sampled texture as there is no way to upload multisample data to the GPU. Multisample textures are only useful as render targets (and for sampling from once they have been rendered to) and thus can not be immutable.

Share this post


Link to post
Share on other sites

Thanks for your reply

 

when i set Quality to 0 and sample counts to 8, it gives me blank screen.

 

I've checked my graphics card to see up to how many samples it can support

	for (UINT sampleCount = 1; sampleCount <= D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; sampleCount++)
	{
		UINT maxQuality;
		hr = d3d11Device->CheckMultisampleQualityLevels(
			DXGI_FORMAT_D24_UNORM_S8_UINT, sampleCount, &maxQuality);

		if (maxQuality > 0)
		{
			maxQuality--;
		}

		if (hr != S_OK)
		{
			return false;
		}
	}

and sampleCount goes until 33. does it mean that i can use 33 samples in my program ?

Share this post


Link to post
Share on other sites

Hi,

 

Here are two different ways I set my quality, they may not be the best ways to do it:

 
UINT msaa_quality;
 
// method 1
 
msaa_quality = D3D11_STANDARD_MULTISAMPLE_PATTERN;
 
// method 2
 
DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM; // or the format you're using
UINT msaa_samples = 4; // or 2, 8, etc.
 
hResult = d3d_device->CheckMultisampleQualityLevels(DXGI_FORMAT_R8G8B8A8_UNORM, msaa_samples, &msaa_quality);
msaa_quality--;
 
Edited by Endemoniada

Share this post


Link to post
Share on other sites
the simplest source to your answers is to enable the d3d debug runtime.
usually, when the output is purely black, it means you do something forbidden.
the debug output will tell you what and usually give you hints how to do it right.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!