microsoft / angle

ANGLE: OpenGL ES to DirectX translation
Other
615 stars 166 forks source link

Multi-threading with multiple D3D devices #78

Closed abucur closed 7 years ago

abucur commented 8 years ago

Hello!

The use case is to support rendering in multiple threads completely isolated from each other. No shared resources, contexts and so on (more exactly, there can be many isolated windows, each with its own SwapChainPanel)

After looking a bit in the code it seems that multi-threaded rendering "should" be possible if each thread gets its own D3D device. From a very high level this seems to reduce the amount of data shared by the threads to a minimum and it makes the use case mentioned above possible to implement without serializing everything on a single thread.

  1. Is this approach feasible? If not, where is synchronization required when each thread has one display, one D3D device, one renderer and so on?
  2. What would be the downsides of having a D3D device per EGL display in regards of memory and throughput? From a throughput point of it seems to be the best solution as it requires minimum synchronization.
  3. If it is feasible, what's the recommended way to instantiate a D3D device per display?
  4. Using eglCreateDeviceANGLE? This API seems to work only with D3D11 which is unfortunate (though I'm not aware of how many D3D9 only devices are out there).
  5. Using eglGetPlatformDisplayEXT with, for example, a static counter as EGLNativeDisplayType. I haven't got the time to test it, but from the code it looks like it will fall through nicely and it will properly create a device as requested in the attributes list.

Thanks for your help!

austinkinross commented 8 years ago

Hi Andrei,

Yes, creating multiple D3D devices is a supported way of achieving this for D3D11. To answer some of your questions:

Thanks!

abucur commented 8 years ago

Great info, thanks a lot! I'm really happy to hear this is a supported use case.

austinkinross commented 8 years ago

The reason we recommend minimizing the number of SwapChainPanel is mostly because they are heavyweight objects. There isn't a certain number of SwapChainPanels after which you'll hit bad performance; you'll just take a performance hit for each one you create. It's a good idea to try to reduce the total number of them across your application.

Of course, if you are rendering OpenGL ES content to multiple windows then you'll need multiple SwapChainPanels- you can't avoid that. :-)

austinkinross commented 7 years ago

I believe your questions have been answered, so I'm closing out this issue. Feel free to reactivate it if you have further questions on this topic!