Multi-threading- using deferred rendering

Aug 28, 2008 at 1:42 AM
Has anyone tried using a deferred rendering approach to the multi-threading issue?

What I mean is start 2 threads, one physics, one everything else including rendering. Then the rendering thread just always waits on the physics thread to finish.

So basically both threads can run concurrently. 

Of course a list of positions, rotations, etc. will have to be copied into a thread-safe container.
Sep 5, 2008 at 11:34 PM
Replying to this discussion to keep it on the first page.

I also want to know other peoples experiences with multithreading the Farseer Physics engine, as I am going to create a sample with multithreading this weekend. :)
Sep 9, 2008 at 5:39 PM
Time to spill be beans :)

I tried to get a multithreading sample of Farseer going in the weekend. Not using ordinary threading but using the new Parallel FX framework from Microsoft. It's a nice scalable framework that I think will replace the System.Threading namespace one day.

But, I never got it going like I wanted it to. A got a lower framerate with it than without it. I tried implementing it into the broadphase/narrowphase collision detection and also into some other places. The problem was that the overhead of using multithreading was greater than the benefits. Farseer just does not do any huge calculations or uses algorithms that can have a major benefit of multithreading.

Multithreading single sections of the code instead of the whole engine does not offer higher performance, but will make the engine able to manage a lot more objects. I have also been thinking about doing some kind of seperation of objects based on what area they were in, and then do the calculations on each area independent of the others. But this has a very low usablility as it would only benefit games with thousands of objects.

I've asked JeroMiya for help. He has posted some prototype code for multithreading (Look here) but I do currently not have the time to try it out. If anyone decides to give it a shot, please keep us posted on the progress.

Monster (form the same thread as JeroMiya) also wrote that he had implemented a multithreaded farseer implementation with use of the Monitor class, I have not contacted him yet, but I will if JeroMiya does not reply or can't implement it for whatever reason.
Sep 15, 2008 at 6:07 PM
As I promised I contacted Monster (Laszlo Perneky) and asked if he wanted to help. I was very happy to hear that he wants to give it a try with implementing multithreading.

He send me an example of using multithreading and it looked very nice. As soon as I get any updates, I will report back.
Sep 16, 2008 at 1:51 AM
@genbox - I'd love to have a look at that code if you don't mind. I will be needing multithreading in my game whenever I get some time to work on it. Also, I do have a chain constructor nearly finished. I'll send you my demos when I get a chance, I've got so much going on right now I'm dizzy just thinking about it.
Sep 16, 2008 at 8:58 AM
Indeed. Send me a mail and I will reply with the code attached.

I'd love to take a look at the chain constructor. Ideas like that are always welcome.