I'm building a macOS app via Xcode. Every time I build, I get the log output:
Metal API Validation Enabled
To my knowledge my app is not using any Metal features. I'm not using hardware-accelerated 3D graphics or shaders or video game features or anything like that.
Why is Xcode printing Metal API log output?
Is Metal being used in my app? Can I or should I disable it?
How can I disable this "Metal API Validation Enabled" log message?
Xcode offers Metal API validation, which you can use to trace obscure issues. To enable Metal API validation in Xcode: In Unity, build your Project for iOS. This generates an Xcode project.
Once the layer's enabled, you still need to enable the Metal diagnostics breakpoint. The Metal diagnostics break point tells Xcode to stop the execution of the program when a shader validation error occurs and to show the recorded GPU and CPU backtrace for that error.
Yes, even if your code isn't interacting directly with the GPU, many high-level frameworks do -- specifically Core Image, SpriteKit, and SceneKit. For example, I narrowed the pesky "Metal API Validation Enabled" message in my app down to this line:
That should automatically happen if you're using a debug scheme in Xcode. But if you're invoking the Metal frontend manually, symbols can be enabled by adding the -g flag. If any of your libraries are compiled from source online, debug symbols will automatically be enabled.
Toggle Metal API Validation via your Xcode Scheme:
Scheme > Edit Scheme... > Run > Diagnostics > Metal API Validation.
It's a checkbox, so the possible options are Enabled
or Disabled
.
Disabling sets the key enableGPUValidationMode = 1
in your .xcscheme
file.
After disabling, Xcode no longer logs the "Metal API Validation Enabled" log message.
Note: In Xcode 11 and below, the option appears in the "Options" tab of the Scheme Editor (instead of the "Diagnostics" tab).
Select your scheme at the top of the window. Click Edit Scheme
in the drop-down, go to Diagnostics
and untick the Metal API Validation
checkbox.
Yes, even if your code isn't interacting directly with the GPU, many high-level frameworks do -- specifically Core Image
, SpriteKit
, and SceneKit
. For example, I narrowed the pesky "Metal API Validation Enabled" message in my app down to this line:
layer.backgroundColor = NSColor(patternImage: image).cgColor
Enabling validation makes every Metal API call be checked, which causes a "small, but measurable, impact on CPU performance." The purpose of this validation is to
check for code that calls the Metal API incorrectly, including errors in resource creation, encoding Metal commands, and other common tasks.
There's a very low chance that Apple frameworks like Core Image are using the Metal API incorrectly, so if your app only uses those high-level Apple frameworks, then I'd say you should feel safe to disable API validation. Getting rid of that damn output message is worth the risk.
I had the exact same message.
I had a .onDelete(perform: deleteLocations)
at the end of a scrollview closure.
I changed the scrollview to a list and the message went away.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With