Original Post
Hi, I'm investigating a puzzling overhead I'm having while multithreading an opengl renderer. I'll skip the details but what I basically have is instead of doing Render() on the same thread as anything else, I set an event that wakes up the render thread which then calls Render. For debugging purposes I currently have the main thread immediately wait for the rendering to be finished with its frame before continuing. This is so I can keep exactly the same behavior as the single threaded code. Thus what I have is instead of calling Render from the main thread, it's called from the render thread, that's it, verify and debugged! ;) The puzzling part is that code adds a overhead of approx 10ms to my rendering! The only overhead that should append is the one from context switching, but I've timed it to only 0.02ms. It's not also some sort of global lock since while the render thread is working, the main thread is sleeping and vice-versa. Intel Thread Profiler shows it's constantly context switching to a thread internal to the driver called DrvCopyContext (nvidia hw). The question is why?! The only thing different from my single and multi threaded application is the fact that the Render function is called on a separate thread and the rendering context is created on that thread. After all the tests I've done, I'm now clueless! Could it be because the rendering context is created on a different thread than it used to be? Does it needs to be created on the same thread the window is on? That defeat all purposed of multi threading! I'll appreciate any feedback/clues you can give me! Thanks francis