Sign in to follow this  

Threads in a game

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

Hi all, I have heard that some people say that a game like Doom 3 absolutely need thread in its code, but I know that thread in a game is good especially in a multiprocessor system, or I'm wrong ? If someone use threads and he work on different pieces of window, when the window is able to work with alone rendering context, the RC does it suffers stress ? Thanks [Edited by - Elementer on May 12, 2005 2:29:24 PM]

Share this post


Link to post
Share on other sites
Threads are indeed necessary to fully utilise multi-processor or multi-core hardware, since they allow your code to be run in parallel, meaning you're getting more than one thing done at once. There are a whole load of issues with using threads safely though, and different strategies for parallelising your code, which are both big topics in themselves.

I'm afraid I don't quite understand what your second question is.

Share this post


Link to post
Share on other sites
Is this what you are asking?

If two threads are both rendering to the same window, can the window be overloaded with work?

That is unlikley because all rendering goes through the same gfx card and only one operation can be sent to the card at a time (basically). If a game use multiple threads they should try and work on different things instead. I.e. one thread does physics simulation, another do AI, and a third does the rest.
[Edit]Clarification. A window is never overloaded with work. The application could however be render-bound, meaning that the thread(s) have to wait for the gfx-card to complete. Maybe that's what you meant with the question[/Edit]

Share this post


Link to post
Share on other sites
Quote:
Original post by Elementer
Hi all,
I have heard that some people say that a game like Doom 3 absolutely need thread in its code, but I know that thread in a game is good especially in a multiprocessor system, or I'm wrong ? If someone use threads and he work on different pieces of window, when the window is able to work with alone rendering context, the RC does it suffers stress ?


Since Doom 3 does a lot of aux processing of a lot of systems - it definitly needed threads. There was so much going on that that design would really help them. [dont quote me on that though].

If you do have a multiprocessor or even a logical/physical multicore - such as P4 w/ HT - then using threads can provide some increases in performance - but it really just depends on what you are doing.

In your question - yes the RC would be stressed since a thread should not modify the same data at the same time as another thread. I cannot see right now why you would need to use several different threads to work on different parts of the screen - that is a design flaw that will not work (in my educated oopinion, but anyone correct me if I'm wrong).

Here's how that system would have to work -
Thread 1 acquiers RC and locks it
Thread 2 cannot do anything but wait
Thread 1 draws updates and unlocks
Thread 2 now acquires and locks it
Thread 1 has to wait
Thread 2 draws updates and unlocks it

And this process is repeated again and again. THere is too much voerhead added just by having 2 threads continously waiting and wasting time doing nothing than if you just had one thread do all of it at once - which is how a lot of games do it.

I'm not saying that this system is essentiall bad or is not used - but I have yet to know anyone who has done this in a commercial product. I could potentially see how this threaded desing could be used - having one thread do all the drawing, antoher thread do all the manipulating and so on, so it could be a possiblility.

I hope this helps some!

- Drew

Share this post


Link to post
Share on other sites
Quote:
Original post by Elementer
... some people say that a game like Doom 3 absolutely need thread in its code ...
Don't believe everything you hear. There is nothing about "a game like Doom 3" that absolutely needs threads. However, there are certain times when it is a good idea to use multiple threads and lots of times when it isn't.
Quote:
Original post by Elementer
... I know that thread in a game is good especially in a multiprocessor system ...
Multiple threads on a multi-processor system is good.

Share this post


Link to post
Share on other sites
Ok, thanks !
I thought the same things, I had heard some absurdities from some people and I wanted to know some other opinion ;)

Thanks

[Edited by - Elementer on May 12, 2005 2:32:56 PM]

Share this post


Link to post
Share on other sites
I'll just throw my cat into the soup...

A project I did a while ago used the AR toolkit to do camera based tracking in 3d..
The thing is, ARtoolkit is entirly C.. and not perticuarly elegant C either, but that meant it was definitly not thread-friendly (~20mb of globals)...

So I spent a lot of time reworking some of it to allow me to thread it off, so my two cameras would be processed on seperate threads...

But the point is, an interesting side effect happened..

With pentium 4s and hyper threading, the idea is that if the floating point unit is busy, then the P4 will fill up the integer unit with another thread... And vica-versa...

The thing was, the ARtoolkit was pretty much all integer maths.. Whereas the 3D engine doing all the rendering was mostly completly floating point...
The end result was, my personal machine, a 2.53ghz P4 without HT ran about 30% slower than the distribution PC, which had a 2.4ghz P4 with HT...

So threading the app made a very noticable difference.

la de da.

Share this post


Link to post
Share on other sites

This topic is 4735 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this