Monogame: GraphicsDeviceManager.PreferMultiSampling does not work using the MonoGame NuGet package

Created on 7 Feb 2018  路  4Comments  路  Source: MonoGame/MonoGame

Setting graphics.PreferMultiSampling = true; on Xbox One results in a NoSuitableGraphicsDeviceException with an InnerException message of

HRESULT: [0x887A0001], Module: [SharpDX.DXGI], ApiCode: [DXGI_ERROR_INVALID_CALL/InvalidCall], Message: The application made a call that is invalid. Either the parameters of the call or the state of some object was incorrect.
Enable the D3D debug layer in order to see details via debug messages.

and the following stack trace:
at SharpDX.Result.CheckError() at SharpDX.DXGI.Factory2.CreateSwapChainForCoreWindow(ComObject deviceRef, ComObject windowRef, SwapChainDescription1& descRef, Output restrictToOutputRef, SwapChain1 swapChainOut) at Microsoft.Xna.Framework.Graphics.GraphicsDevice.CreateSizeDependentResources() at Microsoft.Xna.Framework.Graphics.GraphicsDevice.Initialize() at Microsoft.Xna.Framework.Graphics.GraphicsDevice..ctor(GraphicsAdapter adapter, GraphicsProfile graphicsProfile, PresentationParameters presentationParameters) at Microsoft.Xna.Framework.GraphicsDeviceManager.CreateDevice(GraphicsDeviceInformation gdi) at Microsoft.Xna.Framework.GraphicsDeviceManager.CreateDevice()

DirectX Help Wanted

Most helpful comment

I've been having this same issue for a while now and couldn't get multisampling to work on Xbox One or Windows 10 using Monogame.Framework.WindowsUniveral. I was hoping I could force the SampleDescription values as a temporary fix, but unfortunately that doesn't seem like a solution that works.

Here are my findings so far:

  • The crash happens here when setting PreferMultiSampling to true inside the GraphicsDeviceManager constructor:
    GraphicsDevice.DirectX.cs, CreateSizeDependentResources(), Line 352, _swapChain = new SwapChain1(dxgiFactory2, dxgiDevice2, ref desc, null);
  • With PreferMultiSampling set to true, then the above crash line contains desc.SampleDescription.Count = 8 and desc.SampleDescription.Quality = 0
  • Setting PreferMultiSampling outside of the graphics constructor and applying will result in a black screen rather than a crash
  • Manually forcing the count and quality to the following values still causes a crash: 8:1, 4:0, 4:1, 2:1, 2:0
  • Manually forcing the count and quality to 1:0 works (although this is the same as not using multisampling at all)
  • In Monogame 3.6 the quality was set to (int)SharpDX.Direct3D11.StandardMultisampleQualityLevels.StandardMultisamplePattern which had a value of -1. This code has disappeared in 3.7, although forcing the quality to -1 in 3.7 still doesn't work
  • The D3D debug layer adds the following line to the output window (which I've only just noticed)
    DXGI ERROR: IDXGIFactory::CreateSwapChain: Flip model swapchains (DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL and DXGI_SWAP_EFFECT_FLIP_DISCARD) do not support multisampling. DXGI_SWAP_CHAIN_DESC{ SwapChainType = ..._Composition, BufferDesc = DXGI_MODE_DESC1{Width = 1280, Height = 720, RefreshRate = DXGI_RATIONAL{ Numerator = 0, Denominator = 1 }, Format = R8G8B8A8_UNORM, ScanlineOrdering = ..._UNSPECIFIED, Scaling = ..._UNSPECIFIED, Stereo = FALSE }, SampleDesc = DXGI_SAMPLE_DESC{ Count = 8, Quality = 0 }, BufferUsage = 0x20, BufferCount = 2, OutputWindow = 0x0000000000000000, Scaling = ..._STRETCH, Windowed = TRUE, SwapEffect = ..._FLIP_SEQUENTIAL, AlphaMode = ..._UNSPECIFIED, Flags = 0x0 } [ MISCELLANEOUS ERROR #102: ]

Looking into the D3D error (https://msdn.microsoft.com/en-us/library/bb173077.aspx#DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL) it seems to suggest the backbuffer doesn't support multisampling directly. Another post (https://stackoverflow.com/questions/20251550/enabling-antialiasing-in-windows-store-apps) suggested that UWP apps need to always use rendertargets for multisampling.

If this is the case rendering to a rendertarget first should work fine. However as it will require PreferMultiSampling to be set to false for the UWP platform to work then PresentationParameters.MultiSampleCount will also be set to zero, which could usually be used when creating a rendertarget with the correct multisample count. For now forcing the value to 8 on Xbox One or making GraphicsDevice.GetClampedMultisampleCount publically accessible should work when creating the rendertarget.

Hope that helps.

All 4 comments

Hrm. Tried it on Windows as well, same error. I think it has to do with the multisamplecount defaulting to zero in MonoGame. In XNA, (on a different machine, though), the value appears to 'default' to 8.

I am not sure if the two are related but I am getting a similar error with the MG tests.

multisampleerror

You should read this as "Expected: 32 But was: 16". The order of parameters is wrong in Assert.Equal inside the test.

I've been having this same issue for a while now and couldn't get multisampling to work on Xbox One or Windows 10 using Monogame.Framework.WindowsUniveral. I was hoping I could force the SampleDescription values as a temporary fix, but unfortunately that doesn't seem like a solution that works.

Here are my findings so far:

  • The crash happens here when setting PreferMultiSampling to true inside the GraphicsDeviceManager constructor:
    GraphicsDevice.DirectX.cs, CreateSizeDependentResources(), Line 352, _swapChain = new SwapChain1(dxgiFactory2, dxgiDevice2, ref desc, null);
  • With PreferMultiSampling set to true, then the above crash line contains desc.SampleDescription.Count = 8 and desc.SampleDescription.Quality = 0
  • Setting PreferMultiSampling outside of the graphics constructor and applying will result in a black screen rather than a crash
  • Manually forcing the count and quality to the following values still causes a crash: 8:1, 4:0, 4:1, 2:1, 2:0
  • Manually forcing the count and quality to 1:0 works (although this is the same as not using multisampling at all)
  • In Monogame 3.6 the quality was set to (int)SharpDX.Direct3D11.StandardMultisampleQualityLevels.StandardMultisamplePattern which had a value of -1. This code has disappeared in 3.7, although forcing the quality to -1 in 3.7 still doesn't work
  • The D3D debug layer adds the following line to the output window (which I've only just noticed)
    DXGI ERROR: IDXGIFactory::CreateSwapChain: Flip model swapchains (DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL and DXGI_SWAP_EFFECT_FLIP_DISCARD) do not support multisampling. DXGI_SWAP_CHAIN_DESC{ SwapChainType = ..._Composition, BufferDesc = DXGI_MODE_DESC1{Width = 1280, Height = 720, RefreshRate = DXGI_RATIONAL{ Numerator = 0, Denominator = 1 }, Format = R8G8B8A8_UNORM, ScanlineOrdering = ..._UNSPECIFIED, Scaling = ..._UNSPECIFIED, Stereo = FALSE }, SampleDesc = DXGI_SAMPLE_DESC{ Count = 8, Quality = 0 }, BufferUsage = 0x20, BufferCount = 2, OutputWindow = 0x0000000000000000, Scaling = ..._STRETCH, Windowed = TRUE, SwapEffect = ..._FLIP_SEQUENTIAL, AlphaMode = ..._UNSPECIFIED, Flags = 0x0 } [ MISCELLANEOUS ERROR #102: ]

Looking into the D3D error (https://msdn.microsoft.com/en-us/library/bb173077.aspx#DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL) it seems to suggest the backbuffer doesn't support multisampling directly. Another post (https://stackoverflow.com/questions/20251550/enabling-antialiasing-in-windows-store-apps) suggested that UWP apps need to always use rendertargets for multisampling.

If this is the case rendering to a rendertarget first should work fine. However as it will require PreferMultiSampling to be set to false for the UWP platform to work then PresentationParameters.MultiSampleCount will also be set to zero, which could usually be used when creating a rendertarget with the correct multisample count. For now forcing the value to 8 on Xbox One or making GraphicsDevice.GetClampedMultisampleCount publically accessible should work when creating the rendertarget.

Hope that helps.

~Fixed in #5477.~

EDIT: I messed up, this isn't fixed. Leaving this closed in favour of #6442.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

griseus picture griseus  路  5Comments

harry-cpp picture harry-cpp  路  5Comments

SenpaiSharp picture SenpaiSharp  路  3Comments

bjornenalfa picture bjornenalfa  路  5Comments

dazinator picture dazinator  路  5Comments