I haven't been able to find a good answer regarding using DirectCompute on multiple threads in a program. I'm trying to add DirectCompute functionality to my program (a scientific app, not a game) to help with some of my algorithms. However, some of these algorithms can be run on both the UI thread, which uses D3D11 for rendering, and on a background thread. The Dispatch() call for a compute shader needs to be called on the D3D11DeviceContext, which should only be used on a single thread at a time, so I won't be able to use a single device+context across multiple threads. Some questions:
- I will need to create a device+context for each thread that's going to use DirectCompute, correct?
- A D3D11Device is not tied to the thread that created it, correct?
- In my UI thread, which has its own device+context for rendering, I can use a second device+context for DirectCompute, correct?
My thinking is to have a small cache of D3D11Device+D3D11DeviceContext structures that can be grabbed when needed for DirectCompute and released back to the cache when done. Does that make sense, and will it work?
Thanks