Runtime Generated Code with C++
Posted by Kaya Kupferschmidt • Wednesday, February 9. 2005 • Category: C++
While I was designing the architecture of my 3d graphics library (Project Magnum), enabling high performance was a critical design goal. But with the addition of abstraction layers, some doubts about the whole approach began to rise in my head, as each layer will inevitabely eat some CPU time and therefore means a decrease in performance. Abstraction in C++ often means the usage of virtual functions, which cannot be inlined by the compiler and whcih are even more expensive than a normal function call. Especially with the new processors having very long pipelines, each jump or call will introduce considerable costs in terms of CPU cycles.
I was thinking about a good solution that on the one hand would still support a high level of abstraction and on the other hand would eliminate the need of virtual function calls. Soon I realized that in many cases, the overhead of virtual functions and abstract interfaces is not really needed with static geometry. In these cases the geometry is created once and does not change much during later execution, but still each call to the render method would incurr a series of virtual calls in order to set the correct shader, material, textures etc. But in the case of static models, the decisions, which routines are ultimately called by the virtual functions, would never change.
I was thinking about a good solution that on the one hand would still support a high level of abstraction and on the other hand would eliminate the need of virtual function calls. Soon I realized that in many cases, the overhead of virtual functions and abstract interfaces is not really needed with static geometry. In these cases the geometry is created once and does not change much during later execution, but still each call to the render method would incurr a series of virtual calls in order to set the correct shader, material, textures etc. But in the case of static models, the decisions, which routines are ultimately called by the virtual functions, would never change.


