zum Inhalt springen

C++ Compile Time Polymorphism for Ray Tracing

Stefan Zellmann, Ulrich Lang
Proceedings of the 22nd International Symposium on Vision, Modeling and Visualization (VMV 2017), Bonn, Germany, September 25-27, 2017 (accepted for publication).


Download link (authors' preview)

Benchmark source code on github

Reducing the amount of conditional branching instructions in innermost loops is crucial for high performance code on contemporary hardware architectures. In the context of ray tracing algorithms, typical examples for branching in inner loops are the decisions what type of primitive a ray should be tested against for intersection, or which BRDF implementation should be evaluated at a point of intersection. Runtime polymorphism, which is often used in those cases, can lead to highly expressive but poorly performing code. Optimization strategies often involve reduced feature sets (e.g. by simply supporting only a single geometric primitive type), or an upstream sorting step followed by multiple ray tracing kernel executions, which effectively places the branching instruction outside the inner loop. In this paper we propose C++ compile time polymorphism as an alternative optimization strategy that does on its own not reduce branching, but that can be used to write highly expressive code without sacrificing optimization potential such as early binding or inlining of tiny functions. We present an implementation with modern C++ that we integrate into a ray tracing template library. We evaluate our approach on CPU and GPU architectures.