Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode logging: "Metal API Validation Enabled"

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?

like image 943
pkamb Avatar asked Mar 11 '20 22:03

pkamb


People also ask

How do I enable Metal API validation in Xcode?

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.

How to fix shader validation error in Xcode?

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.

Does Metal API validation work with the GPU?

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:

How do I enable debug symbols in Xcode?

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.


3 Answers

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

like image 54
pkamb Avatar answered Oct 22 '22 14:10

pkamb


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.

like image 25
McKinley Avatar answered Oct 22 '22 12:10

McKinley


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.

like image 22
Frank Avatar answered Oct 22 '22 12:10

Frank