Links on Android Authority may earn us a commission. Learn more.
Making high performance 3D apps with Vulkan
What is Vulkan and how does it compare to OpenGL?
Vulkan is a next generation graphics API set to improve lower level performance and version control headaches. Vulkan is a lower level API than OpenGL, allowing for greater control of the hardware, although at the developer’s expense, as it will require a lot more work.
Speaking of version control, there is virtually no difference between Vulkan on mobile and Vulkan on desktop. So there shouldn’t be anymore “It works on OpenGL, why not OpenGL ES?!” problems that I have personally experienced in game development. This should make it a lot easier to not only get more performance out of your game (potentially), but also give a more streamlined experience without the need to redo assets because a certain API doesn’t perform the same as the other.
This is just like the DirectX 12 versus 11 comparison. The graphics won’t automatically be better, but with some work the games could be more efficient allowing for higher graphics presets, albeit with a higher learning curve as stated earlier. But the numbers do not lie, and in the video above, there is a real performance improvement. So any headaches should be worth it in the long run.
How to get Android Studio ready
First off, make sure you have Android Studio installed and it is the latest version, Android Studio will prompt you to update upon starting it up if you do not. Android Studio can be downloaded here, if you don’t already have it.
Next up, install the Android NDK, make sure it is at least version 12. There are few ways to install the NDK, the easiest way is to go to File > Settings > Android SDK > SDK Tools > NDK. Click the check box then click “Apply”, you will then be prompted that the NDK with be installed. If you prefer to install the Android NDK manually, you can do so here.
The last step is to make sure you have the latest N preview SDK installed. Go to File > Settings > Android SDK and click the N preview and N checkboxes and download them.
Looking at the samples
To open the the samples, unzip the folder and in Android Studio, open “vulkan-basic-samples-master\LunarGSamples\API-Samples\android” and click OK. This will load all of the samples provided with separate modules that you can run separately. You will notice that there are the standard Java versions and “native” versions of the modules, you will want to run the native versions to utilize the Vulkan API.
Depending on your version the Android N, you have have to go into the build gradle for the module you want to test and change “compileSdkVersion = “android-N”” to “compileSdkVersion = 24” as Google changed the API level in the latest preview. If you do not do this the module will not work on your device.
Once everything is ready to go, you can now dive in and start making apps. The example we will be looking at is the “drawcube” module. This module has no Java code, it is all C/C++ taking advantage of the Android NDK. This is more complicated than normal Android development, but luckily the Khronos Group does a great job with plenty of documentation to sift through.
The layout of the module is very similar to a natively developed app using the NDK, which is no surprise. There some special files though, including vulkan_wrapper.cpp and its .h counterpart. These basically manage the Vulkan API features in the app, making sure everything is in check, even if the device is running a version of Android that does not have a vulkan.so file but still supports the Vulkan API. This allows for greater compatibility. Most of the other files do not need to be messed with, except for drawcube.cpp of course.
Since Vulkan is cross platform, the other files in the directory are used to define the platform and make the project for said platforms. So to edit what is displayed on screen, drawcube.cpp is what you want to take a look at. This file handles the shaders and shader conversions as well as displaying the sample cube on the screen, before destroying it and closing the app.
Most of the code is pretty specific to Vulkan and the best way to learn what everything means to take a look at the quick start guide the Khronos Group put together. It is very similar to OpenGL development using the Android NDK, with a bit more of a learning curve. Vulkan is not just supported in Android Studio. Unreal Engine 4.12 supports it now and Unity may also hop on board. This is where most people may come across Vulkan development, as it is as simple as clicking a checkbox in Unreal Engine, for example.
Vulkan has a lot of potential, and now that it is officially supported in Android N, mobile gaming could see a huge boost in performance with apps being able to better utilize a device’s given hardware. This will of course come with some learning curves, but looking at the video from Imagination Technologies, the performance gains seem to be quite significant. Not to mention that engines like Unreal Engine already have it implemented, there is no reason to not at least give Vulkan a try. I know I will in my projects.
Let us know in the comments if you think Vulkan is everything it’s cracked up to be, and stay tuned to Android Authority for more Vulkan news!