Multithreading
How to implement multithreading with OpenGL, I was thinking single context two threads system. But i cant find any tutorial for OpenGL.
If there is anyone who delt with this problem please let me know.
OpenGL, as far as I know, doesn't natively contain any type of multithreading system. You should either A) use OS-specific API functions (for example, CreateThread() in Win32) or B) use another third party library. I highly recommend boost::threads, for good cross-platform functionality.
SDL also supports cross platform threading:
http://www.libsdl.org/index.php
Cheers,
- llvllatrix
http://www.libsdl.org/index.php
Cheers,
- llvllatrix
Note also, that OpenGL functions are not thread safe, and nor are most windowing systems, so all windowing system and opengl calls will either have to be synchronised (using mutexes, etc.), or only called from a single thread.
Worse than the lack of any native threading safety, OpenGL contexts (HGLRC on windows) are bound to a specific thread when set as current. So in order to move OGL calls from one thread to another, you need to wglMakeCurrent( hDC, NULL ); in the old thread and wglMakeCurrent( hDC, hRC ); in the new one.
The rule of thumb with OpenGL and threads is:
Just don't freaking do it.
Localize all your rendering calls to a single thread, and use other threads for other things. All of OpenGL's calls are already buffered and run asynchronously anyway.
The rule of thumb with OpenGL and threads is:
Just don't freaking do it.
Localize all your rendering calls to a single thread, and use other threads for other things. All of OpenGL's calls are already buffered and run asynchronously anyway.
Well I'm trying to work out a way to support HT(Hyper Threading) and/or SMP(Symmetric Multi Processing).
I saw the way it was implemented in Q3 but it was a bit more complicated. So I was searching for some tutorials and could not find any.
Except this but its quite brief www.ati.com/developer/ gdc/GDC2005_OpenGL_Performance.pdf
I saw the way it was implemented in Q3 but it was a bit more complicated. So I was searching for some tutorials and could not find any.
Except this but its quite brief www.ati.com/developer/ gdc/GDC2005_OpenGL_Performance.pdf
Allthough computer graphics is the champion of paralellism, it is allso it's strongest opponent.
I love to see a paralell capable graphics API/graphics accelerator but i just don't see that happening in the near future, perhaps in 3-5 years, but not before that.
I know how it could be done, i know the benefits of doing so, but they more or less laughed at me for sugesting anything like that on the openGL forums.
So before they decide that it's time for a change, well do as Promit suggest, Just don't freaking do it.
Pre processing on the other hand should work like a charm to have multithreaded (if you do it right that is).
I love to see a paralell capable graphics API/graphics accelerator but i just don't see that happening in the near future, perhaps in 3-5 years, but not before that.
I know how it could be done, i know the benefits of doing so, but they more or less laughed at me for sugesting anything like that on the openGL forums.
So before they decide that it's time for a change, well do as Promit suggest, Just don't freaking do it.
Pre processing on the other hand should work like a charm to have multithreaded (if you do it right that is).
Quote:Original post by lc_overlord
I know how it could be done, i know the benefits of doing so, but they more or less laughed at me for sugesting anything like that on the openGL forums.
Sorry, I don't poke on other gamedev forums. Could you please share with me/us your insights?
By the way, hyper threading is marketing hype. Don't get me wrong: having multiple logical threads is a good idea. It's the fact it doesn't need a special name or functionality.
To support HT, your program just needs to have support for threading. Then, when the OS supports and detects the threads, will mark them as affine threads. By using thread affinities, data caches can be shared much more efficiently.
I heard there are some ways to declare this explicitly but I'm not catched up with this.
A thread-friendly architecture also helps in making HT more efficient than real multi-CPU threading (proportionally), but nothing like having two real CPU cores on die.
Quote:Original post by Krohm
Sorry, I don't poke on other gamedev forums. Could you please share with me/us your insights?
No i made that post about a year ago on the opengGL.org forums.
basicly what i want it to be is a way to have two or more separate rendering pipelines, this way you could render shadows or whatever on one while doing the textures on the other at the same time.
The openGL commands would be fairly simple, perhaps something like this.
glGet(GL_MAX THREADS); <-returns the number of avalible threads
glActiveMultithread(GL_THREAD_1); <- for the default thread
glActiveMultithread(GL_THREAD_2); <- for the next thread
glActiveMultithread(GL_THREAD_1|GL_THREAD_2); <- for both threads
the threads would then render to separate FBO's and then you combine those before putting it in the backbuffer, it's pretty simple really and it give realtime 3d rendering a chance to take advantage of multithreaded dual core CPUs the but on the downside is the fact that graphics cards have to be redesigned a tiny bit to alow for this.
Quote:Original post by Krohm
To support HT, your program just needs to have support for threading.
Actuarly you don't have to do anything, it helps programs run smoother, that's all, not faster.
The effect is pretty aparent in some games where the gameplay is less jerky than before , but at the same framerate.
it's only when you actuarly have two physical cores when you "need" to add threading.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement