D2X-XL Worklog
Notes on features and problems from the development of D2X-XL, newest first.
Speedup #2: Illumination |
|
When doing some testing I noticed a massive performance degradation in level 4 of Yokelassence's mission 'The Sphere'. Looking into the issue revealed that it had to do with an excessive amount (over 1100) dynamic (i.e. variable, moving or destructible) lights in that mine, which was particularly impacting object rendering. The reason is that the light sources affecting visible objects were determined segment by segment, as this was how the objects were ordered for rendering. So I rewrote that part of the renderer to take advantage of multi threading when available. Pitfalls ... Since this code calls the OpenGL driver for rendering there were a few pitfalls though. I couldn't just split rendering up into several threads each handling a segment of the mine, computing the lighting and rendering the objects inside that segment, because a thread doesn't inherit the OpenGL context of its parent process and hence calling OpenGL from it causes the graphics driver to crash. This made it necessary to use a semaphore mechanism to synchronize the illumination and render processes. ... and their solution So what I did was to put the light calculation into threads and have each lighting thread stop after it had computed a segment's light and only proceed when the main process had rendered the objects in that thread. Since Visual C++ 9 (VS 2008) doesn't support OpenMP version 3, I couldn't use the OpenMP 3 task pragma and had resort to SDL threads. A problem with SDL's multi threading support is that it is somewhat rudimentary; I didn't find an elegant way to have the lighting and render processes communicate via semaphores and had to go for a brute force approach by polling global variables instead, which works well enough though. I also had to make sure one CPU core was reserved for the main thread doing the rendering, so this enhancement requires at least a triple core CPU. Results Optimizing path finding and illumination resulted in an approximately twofold acceleration of the renderer, which of course is most noteable in huge levels with massive numbers of effects and objects. Sirius' map 'Anthology', which is my favorite test subject since I am using it for such a long time to collect D2X-XL performance data already, shows a speed increase when rendering the entire level in the textured automap with effects turned on and objects visible from less than 5 fps to around 8 fps. (Core i7 920 @3.2 GHz, Radeon 4890 @ 1920x1200x32).
|




