Hello.
I wish to enable multisampling in my WinRT sharpDX application.
To do that I tried to create depthStencilState, depthStencilBuffer, depthStencilView, renderTargetView,
Then apply it to device:
GraphicsDevice.SetDepthStencilState(depthStencilState);
GraphicsDevice.SetRenderTargets(depthStencilBuffer, renderTargetView);
and clear targets before drawing:
GraphicsDevice.Clear(renderTargetView, Color.CornflowerBlue);
GraphicsDevice.Clear(depthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0);
Bur when I set renger targets, I receive following error:
D3D11 ERROR: ID3D11DeviceContext::OMSetRenderTargets: The RenderTargetView at slot 0 is not compatable with the DepthStencilView. DepthStencilViews may only be used with RenderTargetViews if the effective dimensions of the Views are equal, as well as the Resource types, multisample count, and multisample quality. The RenderTargetView at slot 0 has (w:1920,h:1080,as:1), while the Resource is a Texture2D with (mc:1,mq:0). The DepthStencilView has (w:1920,h:1080,as:1), while the Resource is a Texture2D with (mc:4,mq:0). [ STATE_SETTING ERROR #388: OMSETRENDERTARGETS_INVALIDVIEW]
Here is my resources creation code:
private RenderTargetView renderTargetView;
private DepthStencilView depthStencilView;
private DepthStencilBuffer depthStencilBuffer;
Texture2DDescription depthBufferDescription = new Texture2DDescription();
depthBufferDescription.Width = (int)SwapChainPanel.ActualWidth;
depthBufferDescription.Height = (int)SwapChainPanel.ActualHeight;
depthBufferDescription.MipLevels = 1;
depthBufferDescription.ArraySize = 1;
depthBufferDescription.Format = Format.D32_Float;
depthBufferDescription.SampleDescription.Count = 4;
depthBufferDescription.SampleDescription.Quality = 0;
depthBufferDescription.Usage = ResourceUsage.Default;
depthBufferDescription.BindFlags = BindFlags.DepthStencil;
depthBufferDescription.CpuAccessFlags = 0;
depthBufferDescription.OptionFlags = 0;
DepthStencilStateDescription depthStencilDescription = new DepthStencilStateDescription();
depthStencilDescription.IsDepthEnabled = true;
depthStencilDescription.DepthWriteMask = DepthWriteMask.All;
depthStencilDescription.DepthComparison = Comparison.Less;
depthStencilDescription.IsStencilEnabled = true;
depthStencilDescription.StencilReadMask = 0xFF;
depthStencilDescription.StencilWriteMask = 0xFF;
//????????? ???????? ???? ??????? ???????
depthStencilDescription.FrontFace.FailOperation = StencilOperation.Keep;
depthStencilDescription.FrontFace.DepthFailOperation = StencilOperation.Increment;
depthStencilDescription.FrontFace.PassOperation = StencilOperation.Keep;
depthStencilDescription.FrontFace.Comparison = Comparison.Always;
//????????? ????????, ???? ??????? ?? ???????? ???????
depthStencilDescription.BackFace.FailOperation = StencilOperation.Keep;
depthStencilDescription.BackFace.DepthFailOperation = StencilOperation.Decrement;
depthStencilDescription.BackFace.PassOperation = StencilOperation.Keep;
depthStencilDescription.BackFace.Comparison = Comparison.Always;
DepthStencilViewDescription depthStencilViewDescription = new DepthStencilViewDescription();
depthStencilViewDescription.Format = Format.D32_Float;
depthStencilViewDescription.Dimension = DepthStencilViewDimension.Texture2DMultisampled;
depthStencilViewDescription.Flags = DepthStencilViewFlags.None;
RenderTargetViewDescription renderTargetViewDescription = new RenderTargetViewDescription();
renderTargetViewDescription.Format = GraphicsDevice.BackBuffer.Format;
renderTargetViewDescription.Dimension = RenderTargetViewDimension.Texture2DMultisampled;
depthStencilState =
ToDispose(SharpDX.Toolkit.Graphics.DepthStencilState.New(GraphicsDevice, depthStencilDescription));
depthStencilBuffer = ToDispose(DepthStencilBuffer.New(GraphicsDevice, depthBufferDescription));
depthStencilView = ToDispose(new DepthStencilView(GraphicsDevice, GraphicsDevice.DepthStencilBuffer, depthStencilViewDescription));
renderTargetView = ToDispose(new RenderTargetView(GraphicsDevice, GraphicsDevice.BackBuffer, renderTargetViewDescription));
GraphicsDevice.SetDepthStencilState(depthStencilState);
GraphicsDevice.SetRenderTargets(depthStencilBuffer, renderTargetView);
I am using SharpDX Toolkit.
Could someone say what I am missng and how to get it work with multisampling?