I am developping an application using SharpDX and on one of my machines the call
_swapChain = new SwapChain(factory, _device, desc);
fails with the error message
HRESULT: [0x887A0001], Module: [SharpDX.DXGI], ApiCode: [DXGI_ERROR_INVALID_CALL/InvalidCall], Message: Unknown
When I googled the error I found this where it states:
DXGI_ERROR_INVALID_CALL (0x887A0001)
The application provided invalid parameter data; this must be debugged and fixed before the application is released.
But how?
The error message does not give me any indication whatsoever to why the creation failed.
I checked the debug layer output but that only shows Info. No Warning, no Error, nothing. The factory and the device are created just fine and I tried several combinations of parameters in my SwapChainDescription but the error always remains the same.
How am I supposed to find out what triggers the error?
Just to be clear: I am not so much looking for a solution for my specific problem as I am wondering how I would go about debugging such a problem in general.
This is the boiled down code:
const int MAXFPS = 60;
const Format PIXELFORMAT = Format.R8G8B8A8_UNorm;
// Create device
_device = new Device(DriverType.Hardware, DeviceCreationFlags.None); // Or DeviceCreationFlags.Debug
// SwapChain description
var desc = new SwapChainDescription()
{
BufferCount = 2, // I tried 1 too
ModeDescription = new ModeDescription(_renderSize.Width, _renderSize.Height,
new Rational(MAXFPS, 1), PIXELFORMAT),
IsWindowed = true,
OutputHandle = _hwnd,
SampleDescription = _samples,
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
// Create SwapChain
var factory = new SharpDX.DXGI.Factory();
_swapChain = new SwapChain(factory, _device, desc);
I confirmed the sample description is valid using
_device.CheckMultisampleQualityLevels(PIXELFORMAT, _samples.Count) > _samples.Quality
(though, those are 1 and 0 anyway), that the format is supported using
_device.CheckFormatSupport(PIXELFORMAT).HasFlag(FormatSupport.RenderTarget)
and also checked that
_hwnd != IntPtr.Zero
_renderSize.Width > 0
_renderSize.Height > 0
What else to check?
Update: I was able to fix the problem following the advice from here:
I changed this
Device device = new Device(DriverType.Hardware, DeviceCreationFlags.None);
Factory factory = new Factory();
SwapChain swapChain = new SwapChain(factory, device, desc);
to
Factory factory = new Factory();
var adapter = factory.GetAdapter(0);
Device device = new Device(adapter, DeviceCreationFlags.None);
SwapChain swapChain = new SwapChain(factory, device, desc);