Getting Started with Vulkan

An introduction to this guide on the simplest possible example of a Vulkan program.

This tutorial is a step-by-step guide to writing a basic Vulkan application. The example it is based upon - HelloAPI - is included with the PowerVR SDK.

Drawing a triangle is one of the most basic Vulkan applications which will produce some visible output. The example application which will be shown renders a textured triangle to screen which rotates in place for a pre-defined period. This makes it a great introduction to Vulkan programming.

Along the way, this guide will introduce the basic concepts of 3D rendering and Vulkan, as well as how to set up applications and draw simple primitives to screen.

What is Vulkan®?

Vulkan is a modern, streamlined API which has been designed to take advantage of modern hardware.

The most important features for developers are:

  • better use of multi-core CPUs
  • more direct control over the hardware
  • reduced driver overhead.

When used correctly, Vulkan should lead to better and more consistent application performance when compared to other high-level APIs such as OpenGL® ES. The trade-off is that a significantly greater amount of work required is to initially set up an application in Vulkan. The benefits of this extra work may not be apparent in simple applications, such as the one shown in this guide, but in more complex applications Vulkan can have a significant impact on performance compared to OpenGL ES.

Important notes about this guide

The header file for this example ("VulkanHelloAPI.h") defines the VulkanHelloAPI class which contains many of the functions and objects that are used throughout the code examples. Of particular importance is the AppManager custom struct which stores the handles to many of the Vulkan objects which will be created later in this guide.

The application also has a couple of additional dependencies which are included in the "VulkanHelloAPI.h" header file.

These are:

  • GLM - this is a mathematical library which is based on GLSL. It is used in this application to perform vector and matrix operations, for example calculating a projection matrix which transforms the triangle vertices to screen space. The glm files are included with the PowerVR SDK or can be downloaded separately.
  • vk_getProcAddrs.h - this header file sets up function pointers for Vulkan functions. Using this file avoids the Vulkan loader.
Important: The full source code for the application used in this guide is included with the PowerVR SDK as "HelloAPI". It can also be found on the PowerVR SDK GitHub.

Guide features

This guide contains many useful cross references and external links. In the code examples almost all called functions are linked to their internal definition or the Vulkan man pages. In addition there are links to the example application header file where appropriate.

PowerVR Framework

Finally, for a much quicker start to Vulkan, Imagination Technologies has developed the PowerVR Framework, which is included as part of the PowerVR SDK. This is a collection of libraries which are intended to speed up development with graphical APIs such as Vulkan and OpenGL ES and is also fully optimised for PowerVR development.

For Vulkan development, the Framework offers two powerful modules: PVRVk and PVRUtilsVk.

PVRVk

PVRVk is an abstraction of the raw API which wraps Vulkan objects in a C++ interface, allowing the application to take advantage of powerful C++ features such as reference counting and STL objects. In addition, it has many convenience features such as initialising Vulkan structs with sensible default values.

To see how PVRVk can greatly simplify Vulkan applications, feel free to contrast the example in this guide with the SDK example IntroducingPVRVk which uses PVRVk.

PVRUtilsVk

PVRUtilsVk further simplifies development with Vulkan by automating many of the tasks which are required for all Vulkan applications such as the creation of surfaces, devices, and queues. This reduces the amount of boilerplate code that needs to be written per application and means development can progress more quickly.

To see how PVRUtilsVk can simplify Vulkan applications even further, feel free to contrast with the example IntroducingPVRUtils found in the SDK, which uses PVRUtils and PVRVk.

The PowerVR Framework can be downloaded as part of the PowerVR SDK and Tools package, or is available on GitHub.