Debugging Tools
Filament provides several tools and features for debugging rendering issues, shader problems, and performance bottlenecks.matdbg - Material Debugger
The Material Debugger (matdbg) is a web-based tool for debugging and live-editing Filament shaders.
Capabilities
- OpenGL: Edit GLSL shaders in real-time
- Metal: Edit MSL (Metal Shading Language)
- Vulkan: Edit transpiled GLSL, view disassembled SPIR-V
- WebGPU: Edit WGSL shaders
Setup for Desktop
- Build with matdbg enabled:
-d flag enables FILAMENT_ENABLE_MATDBG and -f forces CMake to regenerate.
- Set the debug port:
- Launch your application and open
http://localhost:8080in your browser.
Setup for Android
-
Enable matdbg in CMake by setting
FILAMENT_ENABLE_MATDBG=ONin your build configuration. -
Add internet permissions to your
AndroidManifest.xml:
- Forward the debug port:
- Access the debugger at
http://localhost:8081
Using matdbg
Selecting Materials
- Open the matdbg page in your browser
- Select a material from the upper-left pane
- Select a shader variant (active variants are shown in bold)
- View or edit shader code in the main editor
Editing Shaders
You can modify GLSL or MSL code directly:- Make your edits in the shader editor
- Click
[rebuild]or press Cmd+S (Mac) / Ctrl+S (Windows/Linux) - Changes apply immediately if the shader compiles successfully
Keyboard Shortcuts
| Action | Shortcut |
|---|---|
| Save/Rebuild shader | Cmd+S / Ctrl+S |
| Navigate materials | Shift+Ctrl+Up/Down |
| Navigate variants | Shift+Ctrl+Left/Right |
Architecture
matdbg consists of:- C++ Server: Embedded civetweb HTTP/WebSocket server
- JavaScript Client: Web app using lit-html and Monaco Editor
C++ Server API
HTTP API
GET /api/matids Returns array of material IDs:matid={id}- Material IDtype=[glsl|spirv|msl|wgsl]- Shader languageglindex={n}/vkindex={n}/metalindex={n}- Variant index
Debug Registry
Filament provides a debug registry for runtime inspection:Validation and Assertions
Build Configurations
Filament supports different build types:ASAN/UBSAN Builds
Detect memory errors and undefined behavior:Resource Tracking
Leak Detection
Filament tracks all resources and warns about leaks:Resource Counts
Query resource counts:Handle Validation
Check if resources are valid:Backend Debugging
Command Logging
Enable command logging in debug builds by modifyingCommandStream.h:
Driver Debugging
Backend drivers support debug hooks:Frame Capture
Use platform-specific tools:RenderDoc (OpenGL, Vulkan)
- Launch your app through RenderDoc
- Press F12 to capture a frame
- Analyze draw calls, shaders, and resources
Xcode (Metal)
- Run your app with Metal frame capture enabled
- Click the camera icon in Xcode
- Inspect GPU workload and shader performance
Android GPU Inspector (Vulkan)
- Install Android GPU Inspector
- Connect to your device
- Capture and analyze frames
Common Debug Scenarios
Shader Compilation Errors
Black Screen Issues
-
Check clear color:
-
Verify view setup:
-
Check renderable bounds:
Performance Issues
Use frame timing:Build Options
CMake Options
Key debugging options:Easy Build Script
Best Practices
Do’s
✓ Use debug builds during development✓ Enable matdbg for shader debugging
✓ Check resource counts regularly
✓ Destroy resources properly
✓ Use validation layers (Vulkan)
✓ Profile with platform tools
Don’ts
✗ Don’t ignore warnings about leaked resources✗ Don’t disable handle validation in development
✗ Don’t skip proper cleanup
✗ Don’t ignore frame timing information
Example: Complete Debug Setup
See Also
- Performance Optimization - Profiling and optimization
- Building Filament - Build configuration
- matdbg Documentation - Full matdbg reference