Unity Vulkan



With the announcement of Android N back a few months ago, Google mentioned that Android would be supporting the new Vulkan graphics API . If you haven’t heard of Vulkan then we have a full rundown in our Vulkan – everything you need to know article, plus we did a deep dive into making high performance 3D apps with Vulkan. One key question is this, how does Vulkan perform compared to OpenGL ES 3.1 and OpenGL ES 2.0? Decimal plugin. Let’s find out.

Vulkan is a low level graphics API developed as a successor to OpenGL, which was originally released in the early 90’s. Vulkan was developed by The Khronos Group, a non-profit industry consortium. Vulkan is a fairly new graphics API, with numerous features that make it an improvement over OpenGL ES. Unlike OpenGL ES, Vulkan is a stateless API, meaning that there is no underlying state that the driver needs to store between commands.

Methodology of the tests

At the moment, there is no easy way to test Vulkan versus OpenGL ES 3.1 on Android. My go to 3D engine Unreal Engine does not support the Android-24 API, so while Vulkan is technically supported, I was not able to get Vulkan working on my Nexus 6P to do this.

Vulkan

Instead, I will be using Nvidia’s samples for this article to test Vulkan, OpenGL ES 3.1 and OpenGL ES 2.0 on my desktop for performance tests and Unreal Engine for graphics comparisons between Vulkan on mobile with OpenGL ES 2.0, OpenGL ES 3.1. In the Nvidia tests the CPU and GPU usage will all be monitored and the graphics quality will be noted in the Unreal Engine tests. Let’s get started with graphics.

Graphics comparison


Vulkan offers greater performance compared to its OpenGL brothers and greater control of the hardware allowing for a boost in graphics quality do to better optimizations. But how does this translate into the real world?

Compared to OpenGL ES 3.1, at least in Unreal Engine made for mobile, there is no difference in graphics. That being said, most games run in OpenGL ES 2,0, and there is a huge difference here, which you can see above. The problem with OpenGL ES 3.1 is that while the graphics look immensely better than OpenGL ES 2.0, the performance hit is so great that games are basically not playable, looking at the image above comparing OpenGL ES 2.0 and 3.1 on my Nexus 6P shows that the exact same scene runs at a third of the frames per second compared to OpenGL ES 2.0. This is where Vulkan comes in, offering at least the same in graphics quality, but with improved performance. So how does Vulkan do?

Performance comparison


Vulkan does amazing actually, the results show that Vulkan more than triples the FPS compared to OpenGL ES 3.1. There are a few reasons to why this is. First, it may be hard to see in the picture, but my computer’s CPU usage is more than doubled on all 8 threads and my computer is able to handle two million fish per second compared to around 900 thousand while using OpenGL ES 3.1. The multithreading capabilities are a lot better with Vulkan, allowing for all 8 cores to get a workout, not just one.


The CPU usage reported in task manager is more than likely a bit misleading. I believe this is the case because Vulkan spreads out the load of this example across all 8 cores, instead of just one with OpenGL ES 3.1. So while it is technically using more of my CPU, the CPU is not as stressed as the work is spread out between the cores. Notice that the RAM usage does not change between tests as well.

Looking at the draw calls, Vulkan allows for a little more than 3 times the amount compared to OpenGL ES 3.1. A “draw call” is how many objects are being drawn on the screen at a time. Usually, you want this number to be lower, as performance can suffer, but in this case, the new API stomps all over ES 3.1 while still having a higher draw call.

Unity Vulkan

Looking at the GPU usage while running these tests, it’s about the same, with about 20 percent GPU usage in Unreal Engine and 4 percent for the Nvidia test. OpenGL ES 3.1 used about an extra percent than its newer brother. While this is essentially nothing to my desktop, on a phone this could be a huge difference and we could see 10-20 percent GPU difference possibly. What is actually giving it better performance is the lower level control and relying on the developer more than the drivers to decide where your device’s resources go.

For calculating orbital state vectors of satellites, SGP4 (simplified perturbations model) is often used in conjunction with two-line element sets to calculate future positions of orbiting objects. What are the parameters and steps used in the SGP4 method to make these predictions? I am looking for an in depth source about how the model works. SGP4 is an analytic method based on a general perturbation theory for generating ephemerides for satellites in earth-centered orbits. It is the proper means for correctly propagating a USSTRATCOM Joint Space Operations Center (JSpOC) Two Line Element (TLE). Sgp4. The SGP4 propagator generates ephemeris in the True Equator Mean Equinox coordinate system based on the epoch of the specified GP data. In addition to certain meta-data, the information contained in the GP data is a set of mean orbital elements that are specific to the SGP4 propagator.

Looking at this data, Vulkan still will not perform as well as the lower graphics capable OpenGL ES 2.0, as Vulkan displays a lot more on screen and the scenes it can render are a lot more complex, but this is to be expected.

Imagination has also observed similar results in their tests. Showing that the CPU load is spread across the four cores and the FPS increases by quite a bit. This test really shows how well the new API works with multiple threads and how much it benefits from doing this.

What does this mean for Android?

This is an interesting question, as at the time of writing, there are only a few devices that are actually able to utilize Vulkan. While new flagship devices running Android 7.0 will most likely support Vulkan, it will take awhile for developers to integrate the new API into their games, especially since third party engines do not fully have Vulkan integrated for Android, like Unreal Engine. Or not at all, like Unity.

All of this will come with time, of course, but I would not hold my breath, as there are a few stars that need to be aligned before your device supports the new API. For reference, Vulkan will be supported on Snapdragon 8xx and up with Adreno 4xx GPUs and up and Exynos 5433, 7420 and 8890 and presumably everything proceeding those models. Once Vulkan is used correctly, games will see a massive jump in quality with very little to no penalties as the API and hardware advances over the years. This is definitely an exciting time to be a developer and gamer.

Wrap Up

Vulkan looks very promising for not just Android, but also for the desktop. The numbers do not lie, and Vulkan beats OpenGL ES 3.1 no problem. The real question is how fast will developers start implementing the new API in their games. As engines progress and development gets easier, I see no reason why not to.

Let us know in comments what you think of these results!

About

This tutorial will teach you the basics of using the Vulkangraphics and compute API. Vulkan is a new API by the Khronos group(known for OpenGL) that provides a much better abstraction of modern graphicscards. This new interface allows you to better describe what your applicationintends to do, which can lead to better performance and less surprising driverbehavior compared to existing APIs like OpenGLand Direct3D. The ideas behind Vulkanare similar to those of Direct3D 12and Metal, but Vulkan has theadvantage of being fully cross-platform and allows you to develop for Windows,Linux and Android at the same time.

However, the price you pay for these benefits is that you have to work with asignificantly more verbose API. Every detail related to the graphics API needsto be set up from scratch by your application, including initial frame buffercreation and memory management for objects like buffers and texture images. Thegraphics driver will do a lot less hand holding, which means that you will haveto do more work in your application to ensure correct behavior.

The takeaway message here is that Vulkan is not for everyone. It is targeted atprogrammers who are enthusiastic about high performance computer graphics, andare willing to put some work in. If you are more interested in game development,rather than computer graphics, then you may wish to stick to OpenGL or Direct3D,which will not be deprecated in favor of Vulkan anytime soon. Anotheralternative is to use an engine like Unreal Engineor Unity, which will beable to use Vulkan while exposing a much higher level API to you.

With that out of the way, let's cover some prerequisites for following thistutorial:

  • A graphics card and driver compatible with Vulkan (NVIDIA, AMD, Intel)
  • Experience with C++ (familiarity with RAII, initializer lists)
  • A compiler with decent support of C++17 features (Visual Studio 2017+, GCC 7+, Or Clang 5+)
  • Some existing experience with 3D computer graphics

This tutorial will not assume knowledge of OpenGL or Direct3D concepts, but itdoes require you to know the basics of 3D computer graphics. It will not explainthe math behind perspective projection, for example. See this online bookfor a great introduction of computer graphics concepts. Some other great computer graphics resources are:

  • Vulkan being used in a real engine in the open-source Quake and DOOM 3

You can use C instead of C++ if you want, but you will have to use a differentlinear algebra library and you will be on your own in terms of code structuring.We will use C++ features like classes and RAII to organize logic and resourcelifetimes. There is also an alternative version of this tutorial available for Rust developers.

To make it easier to follow along for developers using other programming languages, and to get some experience with the base API we'll be using the original C API to work with Vulkan. If you are using C++, however, you may prefer using the newer Vulkan-Hpp bindings that abstract some of the dirty work and help prevent certain classes of errors.

E-book

Unity Vulkan Commandbuffer

If you prefer to read this tutorial as an e-book, then you can download an EPUBor PDF version here:

Tutorial structure

We'll start with an overview of how Vulkan works and the work we'll have to doto get the first triangle on the screen. The purpose of all the smaller stepswill make more sense after you've understood their basic role in the wholepicture. Next, we'll set up the development environment with the Vulkan SDK,the GLM library for linear algebra operations andGLFW for window creation. The tutorial will cover howto set these up on Windows with Visual Studio, and on Ubuntu Linux with GCC.

After that we'll implement all of the basic components of a Vulkan program thatare necessary to render your first triangle. Each chapter will follow roughlythe following structure:

  • Introduce a new concept and its purpose
  • Use all of the relevant API calls to integrate it into your program
  • Abstract parts of it into helper functions

Although each chapter is written as a follow-up on the previous one, it is alsopossible to read the chapters as standalone articles introducing a certainVulkan feature. That means that the site is also useful as a reference. All ofthe Vulkan functions and types are linked to the specification, so you can clickthem to learn more. Vulkan is a very new API, so there may be some shortcomingsin the specification itself. You are encouraged to submit feedback tothis Khronos repository.

As mentioned before, the Vulkan API has a rather verbose API with manyparameters to give you maximum control over the graphics hardware. This causesbasic operations like creating a texture to take a lot of steps that have to berepeated every time. Therefore we'll be creating our own collection of helperfunctions throughout the tutorial.

Every chapter will also conclude with a link to the full code listing up to thatpoint. You can refer to it if you have any doubts about the structure of thecode, or if you're dealing with a bug and want to compare. All of the code fileshave been tested on graphics cards from multiple vendors to verify correctness.Each chapter also has a comment section at the end where you can ask anyquestions that are relevant to the specific subject matter. Please specify yourplatform, driver version, source code, expected behavior and actual behavior tohelp us help you.

This tutorial is intended to be a community effort. Vulkan is still a very newAPI and best practices have not really been established yet. If you have anytype of feedback on the tutorial and site itself, then please don't hesitate tosubmit an issue or pull request to the GitHub repository.You can watch the repository to be notified of updates to the tutorial.

After you've gone through the ritual of drawing your very first Vulkan poweredtriangle onscreen, we'll start expanding the program to include lineartransformations, textures and 3D models.

Unity And Vulkan

If you've played with graphics APIs before, then you'll know that there can be alot of steps until the first geometry shows up on the screen. There are many ofthese initial steps in Vulkan, but you'll see that each of the individual stepsis easy to understand and does not feel redundant. It's also important to keepin mind that once you have that boring looking triangle, drawing fully textured3D models does not take that much extra work, and each step beyond that point ismuch more rewarding.

If you encounter any problems while following the tutorial, then first check theFAQ to see if your problem and its solution is already listed there. If you arestill stuck after that, then feel free to ask for help in the comment section ofthe closest related chapter.

Unity Vulkan Ray Tracing

Ready to dive into the future of high performance graphics APIs? Let's go!

Unity Vulkan Android

Please enable JavaScript to view the comments powered by Disqus.



Comments are closed.