Question

So I have recently started using SharpDX, and have stumbled into a problem. I have no idea how to get SharpDX to multisample. I have found two things related; you can specify a SampleDescription when creating the SwapChainDescription, but any input other than (1, 0) throws a Wrong Parameter exception.

The other thing I found was SamplerState, which I put on my pixel shader, didn't do anything. I played around a lot with the parameters, but there was no visible change whatsoever.

I am sure I am missing something, but without any previous directX knowlegde I have no idea really what exactly to look for.

Was it helpful?

Solution

This will come in handy in your case:

int maxsamples = Device.MultisampleCountMaximum;

int res = device.CheckMultisampleQualityLevels(SharpDX.DXGI.Format.R8G8B8A8_UNorm, samplecount);

If res returns 0 then this Sample count is not supported.

Also please note that some options are not compatible, so if you create your SwapChain with:

sd.Usage = (other usages) | Usage.UnorderedAccess;

You are not allowed to use multisampling.

Another very useful technique to spot the problems for those errors:

Create your device with DeviceCreationFlags.Debug

In your startup project properties (debug section), tick "Enable native code debugging".

Any API call that fails will give you an error description in the debug output window.

OTHER TIPS

I had the same problem, could not get Multisampling to work until I enabled the debugging and got a good hint (really wished I had done this hours ago and saved a whole lot of testing!).

Initially I read somewhere that the DepthStencilBuffer had the same SampleDescription as the Render texture - but I'm not so sure as it appears to work without this as a quick test just showed.

The thing for me was to create the DepthStencilView with a DepthStencilViewDescription that has "Dimension = DepthStencilViewDimension.Texture2DMultisampled".

Just a heads up on when you are doing multisampling.

When you set your rendertarget, if passing a rendertarget and depthstencil, you need to ensure they both have the same multisampling level.

So, for rendering to the backbuffer you have defined with MSAA, you will need to create a depth buffer with the same MSAA level.

BUT, if you are have a rendertarget that will be a texture that is fed back into the pipeline, you can define a non MSAA texture and a NON MSAA depth buffer, which is handy as you can use a sampler on the texture (you cant use a normal sampler for a MSAA Resource texture).

Most of this info maybe not new for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top