Xcode logging: "Metal API Validation Enabled" - ios

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?

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

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.

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.

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.

Related

'Incorrect Type of Metal Texture' - Fixed by Disabling Metal API Validation. Why?

I am loading a 3D object into ARKit on a MTLDevice with textures programmatically (.dae + .jpg) and it has transparency. However, when I set the objectNode.transparency property to anything other than 1.0 (the default float value), then I receive the following error and the app crashes: Function(commonprofile_frag): incorrect type of texture (MTLTextureTypeCubeArray) bound at texture binding at index 7 (expect MTLTextureTypeCube) for u_radianceTexture[0].' I have looked at Apple's documentation and developer blog and it seemed to be an error from an earlier Xcode version - however I am running the latest full release - 10.1 (10B61).
It turns out I actually solved this by popping into the Product>Scheme>EditScheme>Options tab and disabling "Metal API Validation". Everything seems to be working properly as of now... does this expose to scrutiny from Apple and/or possible errors? Why did this work as a solution?

Could Xcode affect app performance while debugging?

I have an application written in Swift on SceneKit + Metal. When I build and run the app from Xcode fps counter shows 40fps. But if I run the app myself by tapping the icon on springboard fps counter shows 60fps. How could it be? Could Xcode somehow affect app performance while debugging? I have no idea how this all works, but I suppose there could be some hooks for debugging to work correctly which affect performance. If so, can I opt-in from this?
I'm aware of different build flags for debug and release builds, but I don't make release build. Performance differs in the same debug build while running from Xcode vs when I run the app manually on the phone.
By default, Xcode enables the Metal validation layer. That does a bunch of additional checking of how you're using it to catch incorrect uses. The additional checking is slow, which is why Metal doesn't do it unless validation is enabled.
This can be changed in Xcode's Scheme editor. This is documented in Apple's Metal Programming Guide.
A nice tutorial on iOS Assembly. This might be insightful on the topic
As stated, this is because the compiler is in debug mode, meaning no optimizations are made. If you turn optimizations on, then you’ll see a much smaller function generated.
And also check out this answer about changing optimization levels.
I've experimented with different options in scheme editor and have find out that Debug executable checkbox affected performance in my case. So my assumption about debugger was right, but I didn't know about that checkbox before.

How to automate mac app using Xcode?

I try to add UI test cases to our existing mac application. I already tried UI test cases for iOS, which includes the following steps
I choosed Appium instead of Apple's UIAutomator, because I want to maintain the same flow for our Android apps too.
To proceed the automation, I need to set Labels/Values/Identifiers to the elements. So that they can be accessible. We used drawRect method in most parts, so I followed this post to make drawed components accessible.
I can set/read elements in iOS. What I did is, whenever I draw an element, I simply created an UIAccessibilityElement and added in the corresponding view.
Now, I'm trying to write UI tests for our mac application. As Appium does not have support to the mac application, I considered to use Apple's XCTest UI recording/playback to automate my mac application.
Here is the steps that I took:
NSAccessibility is the class that provides accessibility to the mac application
With XCTest, If I knew a particular elements (say a button) identifier/label, I can proceed with automated tap action
Unlike UIAccessibility, NSAccessibility is a role based object. That is, we need to mention which type of accessibility element that we are going to define.
To start the automation process, I took my mac applications left panel, which has five buttons aligned vertically in it
I set identifiers to those buttons. Then I opened Accessibility Inspector and opened my mac app. The values are properly set.
Then I tried to use record option in XCTest. When tapping the button, crashes the app with the error
"Recorder Service Error: Left Mouse Down: Failed to find matching
element".
I posted about it here.
Questions:
Can someone suggest me the right path to automate mac application? Am I going in the right way?
I googled a lot to see a working sample code about how to implement NSAccessibility. But I can not found anything. Can someone share any useful links/samples?
All I need is, to get elements by identifier/label. Accessibility Inspector shows the right value where as XCTest can not read the identifiers. Did anyone face this issue?
Thanks in Advance

uploading firmware to particle io's photon

I am receiving an "Error 1" when using particle io relay - I am using the same exact firmware found here: https://github.com/spark/relayshield. What do I need to change?
1_Blink_a_Relay.cpp:2:37: fatal error: RelayShield/RelayShield.h: No such file or directory
#include "RelayShield/RelayShield.h"
It looks like your code can't find the library you're trying to import. Often (and especially when adapting Arduino code for Particle), the folder name for a library needs to be removed. Try #include "RelayShield.h instead.
If that doesn't work, please provide a little more information, such as your development environment. (Are you using Particle's web-based IDE? Did you import the library from there?)
Cheers!
If you are using the web ide, the one at build.particle.io, then you have to include the library. You have to go to the fifth item on the left menu bar, after flash, compile, save, and code. It should say library, and looks like a bookmark. Click on that. It will pop out a view. Scroll down until you see the Community Library search bar. And search for RelayShield. It will show you the "RELAYSHIELD", which currently is used by 520 people (or something like that). Click on that, and it will open the library. Scroll down on the left side (the one that pops up) until you see the button "Include in App". Click on that, and select your app. After you click on that, it will bring up your app. Then scroll down on that popped out view, until you see "Add to this App". Just click on this button, and then it will include that library in your project.
For Particle Dev on Desktop, it is a lot harder. If you are using Particle Dev, please reply, and I will give you the solution for that. It is very hard to manage libraries with Particle Dev. However, if you want to use the Serial Monitor while using the Particle Build on the internet, what you can do is that you do the regular serial commands on the Particle Build (build.particle.io), and open the Serial monitor on Particle Dev after also connecting to your Particle photon

Distriqt Google Plus ANE - Issues on Android & Conflict with Milkman GoViral ANE

I am currently working with Distriqt G+ ANE. My setup is this:
AIR 16 with correct dx.jar provided in Distriqt tutorials.
Using the Demoproject provided with District ANE
Samsung Galaxy S-Plus (GT-I9001) with Android 2.3.6 for testing
OAUTH IDs all set up correctly, it works perfectly on iOS
GooglePlay and Core ANEs are included (even though former not necessary on iOS)
Problem #1:
So i get the following very weird behavior with demo project (on Android):
first call to signIn just does nothing.
second call to signIn takes me to google plus application.
i can select the account i want to use. but i can click on it and nothing happens. i can click 2-3 times usually.
it switches back to the app, but triggers none of the event handlers
-> steps are repeatable and i never get any events back
if you search for the app id in the cat log the only thing are the traces from the app and
08-19 18:18:32.031 I/GLSUser (4626): [GLSUser] getTokenFromGoogle
[account: , callingPkg: air.my.com.zas.lefiner, service:
oauth2:https://www.googleapis.com/auth/plus.login
Problem #2:
If i try to implement this into my main app which uses several other ANEs.
<extensionID>com.distriqt.PushNotifications</extensionID>
<extensionID>com.itpointlab.ane.FlashLight</extensionID>
<extensionID>com.milkmangames.extensions.GoViral</extensionID>
<extensionID>com.distriqt.GooglePlus</extensionID>
<extensionID>com.distriqt.Core</extensionID>
<extensionID>com.distriqt.GooglePlayServices</extensionID>
I can't compile. With a very long error.
dx tool failed:warning: Ignoring InnerClasses attribute for an
anonymous inner class (com.facebook.AppEventsLogger$1) that doesn't
come with an associated EnclosingMethod attribute. This class was
probably produced by a compiler that did not target the modern .class
file format. The recommended solution is to recompile the class from
source, using an up-to-date compiler and without specifying any
"-target" type options. The consequence of ignoring this warning is
that reflective operations on this class will incorrectly indicate
that it is not an inner class.
This block is repeated with dozens of other classes most of them in com.milkmangames.extensions.* some also having cryptic names like c.m.x.a.gv.al
At the end there is a memory error:
UNEXPECTED TOP-LEVEL ERROR: java.lang.OutOfMemoryError: Java heap
space at com.android.dx.util.IntList.growIfNeeded(IntList.java:274)
at com.android.dx.util.IntList.add(IntList.java:217)
...
Has anybody ever encountered similar problems with these 2 ANEs or just the G+ ANE on the old android phone?
Your first issue sounds like a problem with the SHA-1 Certificate. You should make sure you are following the instructions to correctly generate this and that you have added this correctly to your console project.
http://airnativeextensions.com/extension/com.distriqt.GooglePlus#get-started
You can find more information on the certificate here: https://developers.google.com/+/mobile/android/getting-started
This is very important on Android and incorrectly matching this to the signature/certificate used to sign your application will cause the login to fail as you are experiencing.

Resources