Metal for Ray Tracing Acceleration
Metal for Ray Tracing Acceleration
WWDC 2018
Metal performance Shaders
GPU — accelerated primitives, optimized for iOS and macOS
- Image processing
- Linear algebra
- Machine learning- inference and training (new)
- Ray tracing (new)
Ray Tracing
Tracing a ray’s path as it interacts with a scene
- Rendering
- Audio and physics simulation
- Collision detection
- AI and pathfinding
- Ambient occlusion, refraction, area lights, depth of field, motion blur
- Method of choice for photorealistic, offline rendering
- Significantly more computationally expensive — doing more work to simulate physical effects

Rasterization
- Projects triangles onto the screen one at a time
- Fast-method of choice for games and real-time applications
- Difficult to model behavior of light
Reflections
- Can be computed accurately with ray tracing

Soft shadows
- Can be computed directly with ray tracing
- Realistic transition from hard to soft shadows

Global illumination
- Naturally modeled with ray tracing

Rendering with Ray Tracing


MPSRayIntersector
- Ray intersector accelerates ray/triangle intersection tests on the GPU
- Accepts batches of rays in a Metal buffer
- Returns one intersection per ray
- Encodes into a Metal command buffer


Accelerating Ray/Scene Intersection

Ray Tracing with Metal Performance Shaders

Primary Rays and Shading

Creating an Intersector

Creating an Acceleration Structure



Generating Primary Rays

Finding Intersections with the Scene

Shading


Shadow Rays



Shadow Rays vs Primary Rays
- Maximum intersection distance
- Don’t need triangle index or barycentric coordinates
- Propagate color from shading kernel to final kernel

Customizing the Ray Struct
- Ray type is configurable
- Choose what data is provided to the intersector
- Append app — specific data


Finding Shadow Ray Intersections

Adding Ray Color to the Image

Secondary Rays



Updating Secondary Rays

Demo
Multi-GPU Ray Tracing
- Split work across GPUs
- Copy data between GPUs
- Synchronize execution
Splitting Work Across GPUs

Copying Scene Data

Creating a Shared CPU Allocation


Synchronizing with Metal Events

Load Balancing 👍
- GPUs can have different performance
- Some regions are more complex to render
- Adjust region sizes to keep GPUs fully utilized



Timing GPU Work
