2

I'm calling this method:

http://msdn.microsoft.com/en-us/library/dd371264(VS.85).aspx

The call fails with E_NOINTERFACE. The documentation is especially unhelpful as to why this may happen. I've enabled all of the DirectX 11 debug stuff and that's the best I got. I know that I have a valid IDXGISurface1* (also tried IDXGISurface) and the other parameters are set correctly. Any ideas as to why this call may fail?

Edit:

I also am having problems creating D3D11 devices. If I pass nullptr as the IDXGIAdapter* argument in D3D11CreateDeviceAndSwapChain, it works fine, but if I enumerate the adapters myself and pass in a pointer (the only one returned), it fails with invalid argument. The MSDN documentation explicitly says that if nullptr is passed, then the system uses the first return from EnumAdapters1. I am running a DX11 system.

Puppy
  • 144,682
  • 38
  • 256
  • 465

2 Answers2

7

Direct2D only works when you create a Direct3D 10.1 device, but it can share surfaces with Direct3D 11. All you need to do is create both devices and render all of your Direct2D content to a texture that you share between them. I use this technique in my own applications to use Direct2D with Direct3D 11. It incurs a slight cost, but it is small and constant per frame.

A basic outline of the process you will need to use is:

  1. Create your Direct3D 11 device like you do normally.
  2. Create a texture with the D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX option in order to allow access to the ID3D11KeyedMutex interface.
  3. Use the GetSharedHandle to get a handle to the texture that can be shared among devices.
  4. Create a Direct3D 10.1 device, ensuring that it is created on the same adapter.
  5. Use OpenSharedResource function on the Direct3D 10.1 device to get a version of the texture for Direct3D 10.1.
  6. Get access to the D3D10 KeyedMutex interface for the texture.
  7. Use the Direct3D 10.1 version of the texture to create the RenderTarget using Direct2D.
  8. When you want to render with D2D, use the keyed mutex to lock the texture for the D3D10 device. Then, acquire it in D3D11 and render the texture like you were probably already trying to do.

It's not trivial, but it works well, and it is the way that they intended you to interoperate between them. Windows 8 looks like it will introduce full D3D11 compatibility, so it will be just as simple as you expect.

zhuman - MSFT
  • 1,028
  • 12
  • 16
  • 1
    It works great! I had to use OpenSharedResource1(). Also, a shared texture was black when I was using AcquireSync() improperly. So it's very important to use AcquireSync()/ReleaseSync() with proper parameters or you might end up thinking that content of the texture is just black. – Tomasz Jarosik Jun 29 '14 at 17:41
2

Direct2D uses D3D10 devices not D3D11 devices. D3D11 device is probably that is reported as lacking interface by that E_NOINTERFACE.

Öö Tiib
  • 10,809
  • 25
  • 44
  • `http://msdn.microsoft.com/en-us/library/ee913554(VS.85).aspx` says that any DXGI1.1 technology, including DX11, can share surfaces. – Puppy Dec 19 '10 at 23:05
  • there are troubles like you describe. See http://www.gamedev.net/community/forums/topic.asp?topic_id=547920 – Öö Tiib Dec 19 '10 at 23:14
  • Goddamnit. So the D3D11 interface can't render it's own text, and it can't interop with D2D. That's just great. – Puppy Dec 20 '10 at 00:22