Xcode logging: "Metal API Validation Enabled"
Asked Answered
S

5

40

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?

Sonata answered 11/3, 2020 at 22:49 Comment(0)
S
59

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).

Sonata answered 11/3, 2020 at 23:0 Comment(2)
What's it for..?Shaggy
Scheme > Edit Scheme... > Run > Options > Metal API Validation.Tazza
P
13

How to disable the message:

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.

Is Metal being used in my app?

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

Should I disable Metal API validation?

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.

Presa answered 16/1, 2022 at 6:0 Comment(1)
Great detail that the NSColor, etc., APIs are triggering the logging.Sonata
S
1

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.

Shortstop answered 11/7, 2020 at 13:36 Comment(0)
F
0

I recently started to work for an update to my macos app.

It worked well without errors but then i added a storyboard file from an older xcode project and when i fire .loadWindow() i saw these on my log:

  • "Metal API Validation Enabled"
  • "fopen failed for data file: errno = 2 (No such file or directory)"

Then i looked at the interface builder and one of my labels was in a weird position. So i centered that label and run app again and the "fopen failed for data file: errno = 2 (No such file or directory)" warning gone. It still says "Metal API Validation Enabled" whenever i load that window from that .storyboard file but that doesn't bother me.

So i think this is something about how operating system is drawing windows and views or maybe something about interface builder version difference.

Fawne answered 21/11, 2020 at 7:12 Comment(0)
K
0

Disable Metal API validation and it works great.

Edit Scheme -> Run -> diagnostics -> Metal API validation (Uncheck it)

enter image description here

Koah answered 2/5 at 5:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.