Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

CreateSwapChainForHwnd failing with DXGI_ERROR_INVALID_CALL #431

Closed
jnm2 opened this issue Jul 2, 2014 · 7 comments
Closed

CreateSwapChainForHwnd failing with DXGI_ERROR_INVALID_CALL #431

jnm2 opened this issue Jul 2, 2014 · 7 comments

Comments

@jnm2
Copy link

jnm2 commented Jul 2, 2014

I would like to use some of the features of the IDXGISwapChain1 interface, targeting Windows 7 and up. According to MSDN docs for IDXGIFactory2::CreateSwapChainForHwnd there are cases where Windows 7 can successfully call this function:

DXGI_SCALING_NONE is not supported on Windows 7 or Windows Server 2008 R2 with the Platform Update for Windows 7 installed and causes CreateSwapChainForHwnd to return DXGI_ERROR_INVALID_CALL when called.

I haven't been able to use this from SharpDX via the SwapChain1 constructor. It does give an Invalid Call error with any parameters I've tried. Am I doing something wrong or can this be fixed?

Example code:

var d3device = new SharpDX.Direct3D11.Device(DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport);
var dxgiDevice = d3device.QueryInterface<SharpDX.DXGI.Device1>();
var dxgiFactory = dxgiDevice.Adapter.GetParent<SharpDX.DXGI.Factory2>();

// This works:
var oldSwapChain = new SwapChain(dxgiFactory, d3device, new SwapChainDescription
{
    BufferCount = 2,
    ModeDescription = new ModeDescription { Format = Format.B8G8R8A8_UNorm },
    IsWindowed = true,
    SampleDescription = new SampleDescription { Count = 1, Quality = 0 },
    Usage = SharpDX.DXGI.Usage.RenderTargetOutput,
    OutputHandle = handle
});

// This gives DXGI_ERROR_INVALID_CALL
var desc1 = new SwapChainDescription1
{
    Stereo = false,
    Width = 400,
    Height = 400,
    BufferCount = 2,
    SampleDescription = new SampleDescription(1, 0),
    Usage = SharpDX.DXGI.Usage.RenderTargetOutput,
    Format = Format.B8G8R8A8_UNorm,
    AlphaMode = SharpDX.DXGI.AlphaMode.Premultiplied,
    Scaling = Scaling.None,
    Flags = SwapChainFlags.None,
    SwapEffect = SwapEffect.FlipSequential
};
var newFeatureSwapChain = new SwapChain1(dxgiFactory, d3device, handle, ref desc1);
@xoofx
Copy link
Member

xoofx commented Jul 8, 2014

It should work (dunno about specifically this code, but accessing some API from W7 is fine) Have you correctly installed the platform update for Win7?

@jnm2
Copy link
Author

jnm2 commented Jul 8, 2014

You're right, it should work. I have nothing to go on. The platform update came through over a year ago via Windows Update.

@xoofx
Copy link
Member

xoofx commented Jul 8, 2014

What gives debug output on the device? (as explained here)

@jnm2
Copy link
Author

jnm2 commented Jul 8, 2014

When I do that, I first get:

Microsoft C++ exception: _com_error at memory location 0x0000000023BBDD20.

Then if I hit Continue, I get the SharpDXException:

HRESULT: [0x887A0001], Module: [SharpDX.DXGI], ApiCode: [DXGI_ERROR_INVALID_CALL/InvalidCall], Message: Unknown

@xoofx
Copy link
Member

xoofx commented Jul 9, 2014

This code is not even running on Windows 8. Have you really tried to run this on Windows 8? Also, when turning debugging on device, I get a self-explanatory message, so please, take the time to dig more into this.

DXGI ERROR: IDXGIFactory::CreateSwapChain: Alpha blended swapchains must be created with CreateSwapChainForComposition, or CreateSwapChainForCoreWindow with the DXGI_SWAP_CHAIN_FLAG_FOREGROUND_LAYER flag. DXGI_SWAP_CHAIN_DESC{ SwapChainType = ..._HWND, BufferDesc = DXGI_MODE_DESC1{Width = 400, Height = 400, RefreshRate = DXGI_RATIONAL{ Numerator = 0, Denominator = 1 }, Format = B8G8R8A8_UNORM, ScanlineOrdering = ..._UNSPECIFIED, Scaling = ..._UNSPECIFIED, Stereo = FALSE }, SampleDesc = DXGI_SAMPLE_DESC{ Count = 1, Quality = 0 }, BufferUsage = 0x20, BufferCount = 2, OutputWindow = 0x00040882, Scaling = ..._NONE, Windowed = TRUE, SwapEffect = ..._FLIP_SEQUENTIAL, AlphaMode = ..._PREMULTIPLIED, Flags = 0x0 } [ MISCELLANEOUS ERROR #183: ]
First-chance exception at 0x75301D4D in TestDXGIFactory2.exe: Microsoft C++ exception: _com_error at memory location 0x00A5E90C.
A first chance exception of type 'SharpDX.SharpDXException' occurred in SharpDX.dll
An unhandled exception of type 'SharpDX.SharpDXException' occurred in SharpDX.dll
Additional information: 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.

@jnm2
Copy link
Author

jnm2 commented Jul 9, 2014

I do not have access to a Windows 8 machine at work. (Personally, I prefer 8.)

I apologize for my apparent ignorance. Would you mind taking the time to explain how I can get a debug dump such as the one you have there? I have native debugging on and am creating the Direct3D11 device with the Debug flag, and that gives the _com_error above. What could I do differently?

@xoofx
Copy link
Member

xoofx commented Jul 9, 2014

Well, may be the debug is not working for this particular API on Windows 7. Don't have any W7 so can't confirm.

@xoofx xoofx closed this as completed Oct 31, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants