Jump to content
  • Advertisement
Sign in to follow this  
newtechnology

Direct3D11 Multithreading

This topic is 1120 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

Haven't found a single example or tutorial explaining this. Can someone post some information and example code on this to guide me? I don't wanna do this for performance reasons. I just want to learn multithreaded programming in directx.

Share this post


Link to post
Share on other sites
Advertisement

The device can be used by any thread. Feel free to load textures/models etc on any or all threads.

Contexts can only be used by one thread (at a time), but you can create as many (deferred) contexts as you need.

When you've finished submitting draw calls to a deferred context, you can call FinishCommandList to turn it into a ID3D11CommandList. You can then hand this over to your "main" thread (the one that owns the immediate context), and it can call ExecuteCommandList to send those commands to the GPU.

tl;dr-
Main thread owns "immediate context" and submits command lists.
Worker threads own "deferred contexts" and create command lists.
Every thread can use the device.

 

From what I know, you use threads to do work in parallel to load as many resources as possible at a time. But In std::threads, to make it work properly, I've to use thread.join() with mainthread for the mainthread to wait for that thread to finish the execution. Doesn't this completely destroy the purpose of threads? This is just like calling functions then.

Edited by newtechnology

Share this post


Link to post
Share on other sites

From what I know, you use threads to do work in parallel to load as many resources as possible at a time. But In std::threads, to make it work properly, I've to use thread.join() with mainthread for the mainthread to wait for that thread to finish the execution. Doesn't this completely destroy the purpose of threads? This is just like calling functions then.


No, because you can launch multiple threads and then join on all of them. This means you can have X functions executing in parallel. This is often called a fork-join model.

That said, use a thread pool and a job system instead of spinning up a new thread for every function call. Threads are heinously expensive to spin up and tear down on many platforms, and they're still somewhat expensive everywhere else. The job system can still be used in a fork-join for simplicity, of course.

Share this post


Link to post
Share on other sites

As @MJP said you are unlikely to gain much performance using deferred contexts with D3D11 *unless* you are doing a lot of CPU intensive work that for whatever reason you cannot separate from your rendering logic *and* can actually be parallelised.

 

I've got a C#/SharpDX example https://github.com/spazzarama/Direct3D-Rendering-Cookbook/tree/master/Ch10_01DeferredRendering. You may need to take a good look at the code to work out how to drive it as it is assumed you are reading the book at the same time.

Edited by spazzarama

Share this post


Link to post
Share on other sites

Note that only NVIDIA drivers support driver command lists, on all other HIVs there is the runtime emulation behind the scene with the possibility of performance loss.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!