Jump to content
  • Advertisement
Sign in to follow this  
kimchi325

DX11 [SlimDX][DX11] How to create more than one SwapChain?

This topic is 2601 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I see that the constructor for SwapChain takes a Factory, a ComObject, and a SwapChainDescription. I can't seem to figure out what should be passed for these arguments. It seems that I can not pass my previously-created SlimDX.Direct3D11.Device as the ComObject, or use it's ComPointer. I've looked around but I can't seem to find an example of how to create more than one SwapChain. Everything I have tried results in D3DERR_INVALIDCALL. I want to do this so I can support rendering to multiple panels.

Share this post


Link to post
Share on other sites
Advertisement
I didn't put much testing in it, but I just modified some working code of mine by creating a second swap chain and it didn't crash. I have not tried to use it, but this might give you a start:

Thats how I create the device:

_Factory = new Factory();
FeatureLevel[] featureLevels = new FeatureLevel[]{FeatureLevel.Level_11_0, FeatureLevel.Level_10_1};
DeviceCreationFlags creationFlag = 0;
#if DEBUG
createDeviceFlag |= DeviceCreationFlags.Debug;
#endif
int adapterCount = _Factory.GetAdapterCount();
for (int a=0; a < adapterCount; ++a)
{
Adapter adapter = _Factory.GetAdapter(a);
_Device = new Device(adapter, createDeviceFlag, featureLevels);
}
_UsedFeatureLevel = _Device.FeatureLevel;
_ImmediateContext = _Device.ImmediateContext;

And thats for creating the swap chain:

_SwapChain = new SwapChain(_Factory, _Device, new SwapChainDescription
{
BufferCount = 1,
Flags = SwapChainFlags.None,
IsWindowed = false,
ModeDescription = ModeDescription(_BackBufferDesc.Width, _BackBufferDesc.Height, new Rational(60, 1), _BackBufferDesc.Format), // Format = R8G8B8A8_UNorm
OutputHandle= panel1.Handle,
SampleDescription = _BackBufferDesc.SampleDescription, // new SampleDescription(1, 0)
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
});

Using the same code twice didn't give me an exception. I guess, using a different OutputHandle should be sufficient. (Although it didn't even throw when using the same handle.)

Share this post


Link to post
Share on other sites
Now you've beaten me, Tsus :)

Just did a quick check with this ("usual" CreateWithSwapChain device creation).

SlimDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, featureLevels, swapChainDesc, out device, out swapChain);
var swapChain2 = new SwapChain(device.Factory, device, swapChainDesc);


Succeeds. So, create your device with the debug flag and hopefully get a better feedback on that failure.

Share this post


Link to post
Share on other sites
Using your code instead of mine, I no longer get the error. Now I just have to figure out what I'm doing differently. :) Thanks so much for your help, I really appreciate it.

Share this post


Link to post
Share on other sites
Hey unbird, thanks for your reply. :) I am a little bit confused by your example. When you create the second SwapChain, it looks like device has a property called Factory that you pass as the first argument. In my case it seems that the device doesn't have such a property. Do you know what I might be missing there?

Share this post


Link to post
Share on other sites
Hmmm, I'm using the latest release (September), Version 2.0.12.43.

Also: It was a really quick check, haven't played around with multiple swap chains, so not sure if this is sane (and of course tying it to the same handle isn't really sensible). Rather go with Tsus' code.

Share this post


Link to post
Share on other sites
No wonder you had troubles. I just had a look at the new and old source code for that particular part. Looks convoluted to get the factory with the old lib, that's probably why they added that feature :)

And a small update: I checked if I could actually use that second swap chain (with according Texture2D and render target view) and it renders fine - same window handle still though. Cheers.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!