Overview
Graphics rendering options:Hardware Acceleration
Uses GPU via DRI (Direct Rendering Infrastructure) for maximum performance
Software Rendering
Uses CPU via Mesa software renderer as a compatibility fallback
Hardware Acceleration (Recommended)
Hardware acceleration leverages your system’s GPU for graphics rendering, providing the best performance for games and graphical applications.Enabling Hardware Acceleration
Use the--device flag to map DRI devices into the container:
How It Works
The--device /dev/dri:/dev/dri flag maps Direct Rendering Infrastructure devices from your host system into the container:
DRI Device Mapping Details
DRI Device Mapping Details
Host devices mapped:
/dev/dri/card0: Primary GPU device node/dev/dri/card1: Secondary GPU (if present)/dev/dri/renderD128: Primary GPU render node/dev/dri/renderD129: Secondary GPU render node (if present)
--device <host-device>:<container-device>- Creates device nodes inside the container
- Grants the container direct access to GPU hardware
- Allows Mesa drivers to use hardware-accelerated OpenGL
When to Use Hardware Acceleration
Use hardware acceleration when:Performance Matters
You’re developing games that require:
- High frame rates (60+ FPS)
- Complex 3D rendering
- Shader effects
- Large textures
Performance Characteristics
Expected performance with hardware acceleration:
- Simple 2D games: 200-1000+ FPS
- Complex 2D games: 120-300 FPS
- 3D games: 60-120+ FPS (depending on complexity)
- GPU usage: 10-80% depending on workload
- CPU usage: Low (5-20%)
Software Rendering (Fallback)
Software rendering uses the CPU to perform graphics operations, providing compatibility when hardware acceleration isn’t available or isn’t working.Enabling Software Rendering
Set theLIBGL_ALWAYS_SOFTWARE environment variable:
Notice that the
--device /dev/dri:/dev/dri flag is not used in software rendering mode.How It Works
TheLIBGL_ALWAYS_SOFTWARE=1 environment variable:
Software Rendering Technical Details
Software Rendering Technical Details
What it does:
- Forces Mesa to use
llvmpipeorsoftpipesoftware renderers - Bypasses GPU hardware entirely
- Implements OpenGL in software using CPU
- Runs on any system regardless of GPU support
llvmpipe: LLVM-based software rasterizer (faster, preferred)softpipe: Reference software rasterizer (slower, but more compatible)- Full OpenGL 4.5+ support
- Multithreaded to use multiple CPU cores
When to Use Software Rendering
Use software rendering when:Hardware Issues
DRI/Mesa errors occurGPU drivers not properly configuredContainer can’t access GPU
Compatibility Testing
Testing on various systemsCI/CD pipelines without GPUHeadless servers
Development
Simple 2D prototypingNon-performance-critical workLearning Raylib basics
Troubleshooting
Diagnosing graphics issuesVerifying code logicIsolating GPU problems
Performance Characteristics
Software rendering is 10-50x slower than hardware acceleration, depending on the workload.Performance Comparison
Typical performance difference for a simple Raylib game:| Rendering Mode | FPS | CPU Usage | GPU Usage | Latency |
|---|---|---|---|---|
| Hardware (GPU) | 300+ | 10-15% | 30-50% | Less than 5ms |
| Software (CPU) | 45-60 | 80-100% | 0% | 15-20ms |
Troubleshooting Graphics Issues
Common Error Messages
Error: 'MESA: error: Failed to query drm device'
Error: 'MESA: error: Failed to query drm device'
Full error:Cause: Container can’t access DRI devices or GPU drivers aren’t loaded.Solutions:
-
Verify DRI devices exist on host:
-
Check if
--device /dev/dri:/dev/driflag is used -
Switch to software rendering:
Error: 'glx: failed to create dri3 screen'
Error: 'glx: failed to create dri3 screen'
Full error:Cause: DRI3 protocol issues or driver mismatch between host and container.Solutions:
- Use software rendering (see above)
-
Check Mesa version compatibility:
-
Ensure X11 socket is properly mounted:
Error: 'Failed to open DRM device'
Error: 'Failed to open DRM device'
Cause: Permissions issue accessing DRI devices.Solutions:
-
Check device permissions on host:
Devices should be readable by your user or group
video/render. -
Add your user to the appropriate groups:
Log out and back in for changes to take effect.
- Use software rendering as fallback
Poor Performance with Hardware Acceleration
Poor Performance with Hardware Acceleration
Symptoms: Low FPS despite using hardware acceleration.Diagnostics:
-
Check if GPU is actually being used:
Should show your GPU name, not “llvmpipe” or “softpipe”.
-
Verify DRI3 is being used:
- If showing software renderer, hardware acceleration isn’t working
- Follow troubleshooting steps above
- Check host GPU drivers are up to date
Diagnostic Commands
Run these inside the container to diagnose graphics issues:Choosing the Right Option
Best Practices
Development Workflow
- Development: Use hardware acceleration for real-time feedback
- Testing: Test with both modes to ensure compatibility
- Performance profiling: Use hardware mode to identify bottlenecks
- CI/CD: Use software mode for automated testing without GPU
- Deployment: Document which mode your game requires
Next Steps
Compiling Code
Learn how to compile and run Raylib programs
Example Projects
Try sample games and applications