Roberto Lopez Mendez and Stephen Barton
In a previous blog, Stephen Barton described the steps to build a Unity application with Mali Graphics Debugger (MGD) support, using a non-rooted device.
More recently, thanks to the collaboration of the Arm Tools and Gaming & Graphics teams with Unity, it has been possible to significantly simplify this process for applications using OpenGL ES. It’s now possible for Unity to detect the presence of the libMGD.so library in the project and load it automatically when the application is built with Development Build mode enabled. Development Build in Unity is used to enable built-in profiler functionality and also make the Autoconnect Profiler and Script Debugging options available.
In this blog we provide not only the newly simplified steps to build an OpenGL ES Unity application with MGD support, but also the steps to build a Vulkan Unity application with MGD support. For the purposes of this blog we assume we are working with a non-rooted device.
MGD library loading has been integrated into Unity so developers can quickly and easily use MGD to profile OpenGL ES applications. From Unity 5.6 onwards, developers must follow the steps listed below:
Figure 1. MGD library libMGD.so in the Asset/Plugins/Android Unity project folder.
Figure 2. Unity Build Options dialog windows with Development Build option enabled.
adb forward tcp:5002 tcp:5002
Figure 3. MGD Daemon application running on Android host device listing installed application linked with MGD library.
Figure 4. MGD registering traces from a Unity OpenGL ES application.
MGD also supports debugging of graphics applications developed with Vulkan. The debugging process in the new graphics API is completely different from OpenGL ES. In OpenGL ES, validation is performed right up front using an error-checking mechanism which is part of the pipeline. This type of validation mechanism causes the CPU to spend a significant amount of time in error checking. Vulkan has been designed to offer maximum performance so debugging is performed through validation layers that can be injected into the system at runtime. MGD interceptor library works like a validation layer.
To add validation layers to a Unity Android application based on Vulkan you must copy the libraries into the project folder Assets/Plugins/Android/libs/armeabi-v7a. To build a Vulkan application with MGD support you must also copy the MGD library in the same folder.
The pre-requisites are the same as previously listed for OpenGL ES applications.
The steps to add MGD support to a Unity application developed with Vulkan are listed below:
Figure 5. MGD validation layer libVkLayerMGD32.so in the Asset/Plugins/Android/libs/armeabi-v7a Unity project folder.
adb shellsetprop debug.vulkan.layers VK_LAYER_ARM_MGD
adb shell
setprop debug.vulkan.layers VK_LAYER_ARM_MGD
This command tells the Vulkan loader to load the layer with the name VK_LAYER_ARM_MGD.
Figure 6. MGD registering traces from a Unity Vulkan application.
Arm’s collaboration with Unity has made it much easier to build Unity applications for Android with MGD support. Now developers can use MGD to profile Unity applications on the device with just a few quick steps. We hope this will encourage more developers to try MGD and take advantage of its many features.