Managing Shader Code Complexity in NVIDIA Omniverse

The NVIDIA Omniverse team is building one of the most ambitious graphics systems ever created. 

To build systems at this scale, we took a fresh look at how a shading language could be enhanced with modern language constructs while preserving the requirements for high performance. The resulting language, called Slang, is used to implement the NVIDIA Omniverse RTX Renderer and other core graphics capabilities in Omniverse. Slang has been instrumental in managing the complexity of the RTX renderer.

Using Slang in Omniverse

Developers implementing high-quality interactive graphics need their shader codebase to be scalable and maintainable so it can easily be extended with new rendering algorithms, run at the fastest possible performance, and support multiple graphics APIs. Interactive rendering engines typically tackle these challenges by building a complex system of engine-specific preprocessing tools to manage shader code. These custom tools stitch together and specialize code for different engine features, translate code to different graphics APIs, and manage platform-specific code variants. Working with these custom tools adds to the burden of maintaining large shader codebases, and makes them harder to modify to support new rendering algorithms and GPU features.

The image depicts the room used for the NVIDIA RTX Marbles at Night demo. There is a large table in the frame covered with books and art supplies, forming a course that marbles can roll through. It is dark outside, and the scene is illuminated by many small light sources scattered on the table, and also strings of lights hanging in the room.

Researchers at NVIDIA postulated that a more powerful shading language could eliminate these burdensome engine-specific tools by adopting constructs from modern general-purpose languages like Rust and Swift. The Slang language emerged following years of graphics language research collaboration between NVIDIA Research, Carnegie Mellon and Stanford Universities. Slang is compatible with existing HLSL, and adds modern language features that increase developer productivity without compromising the high performance required by real-time graphics systems.

Slang and its features are leveraged in NVIDIA Omniverse Kit, Omniverse Create, and the Omniverse RTX Renderer. The NVIDIA Material Definition Language (MDL) is used to author materials, which operate harmoniously with the rendering algorithms written using Slang. Together, these two innovations express cutting-edge rendering techniques to produce Omniverse’s imagery. 

The image depicts two flow charts. The first is labeled as "typical engine architecture" and depicts snippets of HLSL code being fed into a custom preprocessor and then a custom cross-compiler, and then one of fxc, dxc, or glslang to produce DXBC, DXIL, or SPIR-V, respectively. The second shows shade code modules being passed to the Slang compiler to directly produce DXBC, DXIL, or SPIR-V with no need for custom preprocessing steps.

Examples of Slang’s advanced language mechanisms used in Omniverse include: 

  • Developers use interfaces to define and enforce the contract between GPU software components. For example, an interface IMaterial can define how a path tracer written in Slang interacts with materials. 
  • Generics allow code to work with any implementation of an interface, while still generating efficient specialized GPU kernels. For example, path tracing code written with generics can be specialized to different materials defined using MDL. 
  • Slang directly supports modules, so that developers can logically decompose their GPU code like they would Python application code. Slang modules can be compiled and validated offline, and then linked at runtime to produce new or extended renderers. Compiled modules can be obfuscated to protect sensitive portions of GPU rendering code.
The image depicts code written in the Slang programming language. The code uses "import Lighting" to import a separately-compiled module, defines an "interface IMaterial" to describe the requirements for materials in a renderer, and then defines a generic shader function "closestHitM, L>" that can work with any material type and light type.

The Slang language has helped NVIDIA Omniverse meet its requirements for portable, modular/extensible, and high-performance GPU programming — and the Slang project is still growing and evolving. The Slang language and compiler are developed as open-source software (github.com/shader-slang/slang), and we look forward to engaging with the community of developers using Omniverse Kit to further our goal of making high-performance graphics programming as productive and enjoyable as possible. 

Learn more about NVIDIA Omniverse at GTC, which starts on April 12. Register for free and join us to get an exclusive look at some of the latest features and capabilities of Omniverse.



Explore topics