Differentiable Slang: A Shading Language for Renderers That Learn

NVIDIA just released a SIGGRAPH Asia 2023 research paper, SLANG.D: Fast, Modular and Differentiable Shader Programming. The paper shows how a single language…

Sai Bangaru
11 min readadvanced
--
View Original

Overview

NVIDIA's Differentiable Slang is a new shading language designed to unify real-time, inverse, and differentiable rendering, enabling seamless integration of machine learning with graphics programming. The language supports automatic differentiation and is built on a modular programming model, making it easier to create differentiable renderers from existing graphics code.

What You'll Learn

1

How to integrate machine learning with real-time rendering using Differentiable Slang

2

Why automatic differentiation is crucial for modern graphics programming

3

How to convert existing graphics code into differentiable renderers

4

When to use Slang for building custom PyTorch plugins

Prerequisites & Requirements

  • Understanding of graphics programming concepts
  • Familiarity with shader programming languages like HLSL or GLSL(optional)
  • Experience with machine learning frameworks such as PyTorch(optional)

Key Questions Answered

What is Differentiable Slang and how does it enhance rendering?
Differentiable Slang is an open-source shading language that integrates automatic differentiation into graphics programming. It allows developers to create differentiable renderers from existing graphics code, enabling the use of gradient-based optimization techniques in real-time rendering applications.
How does Slang facilitate the integration of machine learning with graphics?
Slang enables graphics developers to use gradient-based optimization for traditional graphics problems, allowing for the learning of mipmap hierarchies and other optimizations. It also generates custom PyTorch plugins from shader code, bridging the gap between graphics and ML training frameworks.
What performance benefits does Slang provide for differentiable programming?
Slang's automatic differentiation allows for significant performance optimizations by controlling how gradient values are stored and computed. This can lead to up to 10x training speedups compared to traditional PyTorch operations, especially for small neural networks integrated within graphics workloads.
What challenges does Slang address in differentiable graphics pipelines?
Slang addresses the complexities of automatic differentiation in graphics by incorporating it as a first-class citizen in the language, type system, and optimization passes. This reduces the need for hand-derived gradients and simplifies the integration of differentiable programming in existing graphics codebases.

Key Statistics & Figures

Training speedup
up to 10x
Compared to the same small-network and graphics workloads written with standard PyTorch operations.
Code reuse
90%
Existing real-time path tracer code was reused when transforming it into a differentiable path tracer.
Shader code lines reused
over 5K
Lines of preexisting shader code were reused in building the differentiable path tracer.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Shading Language
Slang
Used for real-time graphics programming and automatic differentiation.
Backend
Cuda
Utilized for generating custom PyTorch plugins and optimizing performance.
Shading Language
Hlsl
Targeted for use with Direct3D pipelines.
Shading Language
Glsl
Targeted for use with OpenGL and Vulkan.
Machine Learning Framework
Pytorch
Integrated for training and inference of neural networks alongside graphics workloads.

Key Actionable Insights

1
Integrating Differentiable Slang into your graphics pipeline can streamline the process of making existing renderers differentiable without extensive code rewrites.
This is particularly beneficial for teams looking to leverage machine learning techniques in rendering without starting from scratch, thus saving time and resources.
2
Utilizing Slang's automatic differentiation can significantly enhance the performance of small neural networks within graphics applications.
By avoiding multiple kernel launches and optimizing memory access, developers can achieve faster training times and improved efficiency in real-time graphics workloads.
3
Adopting Slang allows for the seamless generation of derivatives across multiple platforms, including CUDA, HLSL, and GLSL.
This flexibility supports long-term code maintenance and reduces the risk of bugs that arise from maintaining separate codebases for different platforms.

Common Pitfalls

1
Many developers struggle with hand-derived gradients in graphics programming, which can be tedious and error-prone.
This often leads to difficulties in modifying algorithms or integrating them into larger systems. Using Slang's automatic differentiation can alleviate these issues by automating the gradient generation process.

Related Concepts

Differentiable Rendering Techniques
Machine Learning In Graphics Programming
Automatic Differentiation Methods