You never need to recreate the device, you only do that once. For some changes you can call ResizeBuffers or ResizeTargets on the swap chain, however to change the MSAA mode you need to to create a new swap chain. You can do that using a DXGI factory.
In most cases you don't actually want to create your swap chain with MSAA enabled...typically you want to create it without MSAA, and use an MSAA render target instead. Then you can just resolve the MSAA render target to the backbuffer as the final step.
Ah, thanks! Noticed that ResizeTargets could also change the refresh rate, compared to ResizeBuffers, so that's good. But how exactly do I create a render target with MSAA enabled? I currently create my render target view like this (like the SlimDX samples do it):
// Create a render target using (var resource = Resource.FromSwapChain<Texture2D>(swapChain, 0)) renderTarget = new RenderTargetView(device, resource);
But with this way I can't really change any MSAA settings. I'm assuming you're talking about the SampleDescription property of the Texture2DDescription structure? So I guess I need to create my own Texture2D to use as render target instead of using the FromSwapChain<Texture2D> method?
I tried creating a render target with MSAA and this is what I came up with:
// Create a render target Texture2DDescription renderTargetTextureDescription = new Texture2DDescription(); renderTargetTextureDescription.ArraySize = 1; renderTargetTextureDescription.BindFlags = BindFlags.RenderTarget; renderTargetTextureDescription.CpuAccessFlags = CpuAccessFlags.None; renderTargetTextureDescription.Format = Format.R32G32B32A32_Float; renderTargetTextureDescription.Height = Options.ResolutionHeight; renderTargetTextureDescription.MipLevels = 1; renderTargetTextureDescription.OptionFlags = ResourceOptionFlags.None; renderTargetTextureDescription.SampleDescription = new SampleDescription(Options.MultiSampleCount, Options.MultiSampleQuality); renderTargetTextureDescription.Usage = ResourceUsage.Default; renderTargetTextureDescription.Width = Options.ResolutionWidth; RenderTargetViewDescription renderTargetViewDescription = new RenderTargetViewDescription(); renderTargetViewDescription.Dimension = RenderTargetViewDimension.Texture2D; renderTargetViewDescription.MipSlice = 0; renderTargetViewDescription.Format = renderTargetTextureDescription.Format; //using (var resource = Resource.FromSwapChain<Texture2D>(swapChain, 0)) using (var resource = new Texture2D(device, renderTargetTextureDescription)) renderTarget = new RenderTargetView(device, resource, renderTargetViewDescription);
But now my screen only turns black. Anyone that can see what's wrong with my code?
Thanks in advance!