Repository navigation
How to use the GPU backend
The GPU backend runs the rasterizer as a kernel with one thread per pixel. It needs MAX and a supported accelerator. Nothing else in the project needs either.
uv pip install "max==26.6.0"On macOS, also install Apple's Metal toolchain. Xcode does not install it by default:
xcodebuild -downloadComponent MetalToolchainWithout it every kernel fails with Metal Compiler failed to compile metallib. That message looks like a code error and is not.
The same message also comes when Apple's Metal linker, air-lld, crashes. Mojo shows no other text. To find the cause, look for a new air-lld-*.ips report in ~/Library/Logs/DiagnosticReports/. Then compile one kernel at a time with DeviceContext.compile_function to find the kernel that crashes it. Two known causes are a whole struct loaded through a cast device pointer, and a branch in level_filter. The code now avoids both.
make gpu-statusThe status command runs tools/gpu_status.mojo. It checks physical devices through MAX. A compiler target alone does not establish device availability.
make check-gpuWithout a physical device, the command reports the device tests as skipped and runs the host layout tests. With a device, it also compiles and runs the GPU parity suite. A detection error fails the check.
The suite runs under a time budget of 300 seconds. A hang fails the run instead of looking slow. Raise the budget on a machine with a slow first kernel compile:
make test-gpu GPU_BUDGET=600Prepare the triangles with the CPU renderer, then draw them on the device:
from render.gpu import render_triangles
var corners = renderer.prepare(scene, assets, camera)
var lighting = Lighting(scene)
var image = render_triangles(
corners, width, height, background, SHADE_TEXTURE, assets.textures, lighting
)For many frames, hold a GpuRenderer so the device buffers survive between frames. See GPU backend.
make benchThis times the CPU and GPU rasterizers across image sizes. The GPU numbers include allocation and the copy back.
The backend runs under CUDA on WSL 2. Read The CUDA teardown hang if the second renderer in a process hangs.
Tutorials
How-to
Reference
- Scene graph
- Rotations
- Cameras
- Geometry
- Geometry addons
- Lofts and clipping groups
- Sculptor
- Procedural generators
- Meshes and assets
- Lines
- Points and sprites
- Helpers
- Scene objects
- Animated objects
- Raycasting
- Curves and paths
- Animation
- Skinning
- Materials
- Node materials
- TSL functions
- Lights
- Lighting addons
- Fog
- Textures
- Renderer
- Renderer hooks and material flags
- Rasterization
- GPU backend
- Render target
- Post-processing
- GPU computation
- Compute nodes
- Progressive light map
- Gaussian splats
- Voxel global illumination
- SVG renderer
- Image files
- Image decode queue
- Model files
- More model files
- Exporters
- Scene JSON
- Windowing and controls
- Math
- Norm consumers
- Math addons
- Units
- Coverage tool
- Commands
- Examples
- Benchmarks
- Extensions
- Shared physics
- Physics query snapshots
- Continuous collision
- Tick force restoration
- Water
- Animals
- Buildings
- CARLA
- Femur
- Tibia
- Fibula
- Patella
- Knee
- Muscles
- Vessels
- Lymph
- Nerves
- Integument
- Leg
- Foot
- Pelvis
- Torso
- Arm
- Hand
- Head
- Genome
- Game humanoid
- Humanoid fidelity
- Audio-aligned game faces
- Converted assets
- Mesh quality
- Segment inertia
Explanation
- Software rasterizer
- Scene graph as an array
- Linear color
- Normals are not colors
- Perspective correction
- Fixed-point coverage
- Per-fragment shading
- Mipmaps
- Sorted transparency
- Types and checks
- Render hooks as a trait
- Shared CPU and GPU code
- Bands and threads
- PNG structure
- Extensions beside the port
- CUDA teardown hang
- Mojo compiler hang