How do I use Metal Performance Counters?
Generated on 7/31/2024
1 search

This post is brought to you by Tailscan,
the best devtool for Tailwind CSS.
To use Metal Performance Counters, you can leverage the suite of Metal tools available in Xcode for debugging and profiling your game. Here are the steps and tools you can use:
-
Prepare Your Shaders for Debugging and Profiling:
- Add
-Zi
and-Qembed_debug
as arguments for the DXC command when compiling your shaders. This ensures that the Metal shader converter propagates the debug information to the Metal libraries. - Rebuild your shaders with the debug information.
- Add
-
Use Metal Tools in Xcode:
- Runtime Validation: This helps catch common issues in both API usage and shader code. It includes API validation and shader validation.
- Metal Performance HUD: Provides an overlay for real-time performance metrics of your game.
- Metal Debugger: Offers advanced debugging and profiling workflows such as analyzing dependencies, investigating visual artifacts, and profiling shaders.
- Metal System Trace and Instruments: Helps measure and analyze your game's overall impact on the system.
-
Profiling Workflows:
- Analyze dependencies and investigate visual artifacts.
- Profile shaders to understand their performance characteristics.
- Use Metal System Trace and Instruments to get a comprehensive view of your game's performance.
For more detailed steps on configuring your shaders and using these tools, you can refer to the "Debug and profile with Metal tools" chapter in the session Port advanced games to Apple platforms.
Relevant Sessions
These sessions provide comprehensive insights into using Metal tools for debugging and profiling, which includes the use of Metal Performance Counters.

Port advanced games to Apple platforms
Discover how simple it can be to reach players on Apple platforms worldwide. We’ll show you how to evaluate your Windows executable on Apple silicon, start your game port with code samples, convert your shader code to Metal, and bring your game to Mac, iPhone, and iPad. Explore enhanced Metal tools that understand HLSL shaders to validate, debug, and profile your ported shaders on Metal.

Accelerate machine learning with Metal
Learn how to accelerate your machine learning transformer models with new features in Metal Performance Shaders Graph. We’ll also cover how to improve your model’s compute bandwidth and quality, and visualize it in the all new MPSGraph viewer.