Skip to content

KDGpu 0.5.0 is here! Our Vulkan wrapper now has OpenXR integration and more.

Since we first announced it last year, our Vulkan wrapper KDGpu has been busy evolving to meet customer needs and our own. Our last post announced the public release of v0.1.0, and version 0.5.0 is available today. It’s never been easier to interact with modern graphics technologies, enabling you to focus on the big picture instead of hassling with the intricacies and nuances of Vulkan.

Screenshot of the PBR example in the new KDGpu Examples repository. It showcases a rendered flight helmet on a wooden base.

The PBR example in the new KDGpu Examples repository.

Wider device support

KDGpu now supports a wider array of devices, such as older versions of Android. For some context, additional features in Vulkan are supported by extensions. If said features become part of the “core” specification, they are automatically included in Vulkan 1.2, 1.3 and so on. In the past, KDGpu required the device to fully support Vulkan 1.2, which limited what devices you could target. In newer KDGpu versions (>0.4.6) it will now run on certain 1.1 devices (like the Meta Quest) as long as the required extensions are supported.

A KDGpu example running natively on an Android device. It comprises of a rotating multicolored triangle on a gray background.

A KDGpu example running natively on an Android device.

We also added native examples for Android, which can be ran straight from Android Studio! There’s also better iOS support alongside a native Apple example.

Screenshot of the KDGpu Hello Triangle example running in the iOS simulator. It's displaying a slightly cut off multi-color triangle on a gray background.

the KDGpu Hello Triangle example running in the iOS simulator

External memory and images support

When writing applications using KDGpu, you will inevitably have to interface with other APIs or libraries that don’t support it or maybe not even Vulkan specifically. For example, if you generate an image using Vulkan graphics and then need to pass that to CUDA for further processing. Now with KDGpu it’s possible to grab texture and buffer objects and get their external memory handles:

const TextureOptions textureOptions = {
    .type = TextureType::TextureType2D,
    .format = Format::R8G8B8A8_SNORM,
    .extent = { 512, 512, 1 },
    .mipLevels = 1,
    .usage = TextureUsageFlagBits::SampledBit,
    .memoryUsage = MemoryUsage::GpuOnly,
    .externalMemoryHandleType = ExternalMemoryHandleTypeFlagBits::OpaqueFD,

Texture t = device.createTexture(textureOptions);
const MemoryHandle externalHandleOrFD = t.externalMemoryHandle();

Additionally, we have added methods to adopt existing VkImages as native KDGpu objects to better support libraries like OpenXR.

Easy & fast XR

OpenXR is the leading API used for writing cross-platform VR/AR experiences. Like Vulkan, code directly using OpenXR tends to be verbose and requires a lot of setup. To alleviate this, KDGpu now includes an optional library called KDXr. It wraps OpenXR, and it even easily integrates into KDGpu. It takes care of initialization, has the C++ classes you expect and can make it painless to integrate XR functionality into your application including support for XR compositor layers, head tracking, input handling and haptic feedback.

For example, to set up a projection view you subclass the ProjectionLayer type:

class ProjectionLayer : public XrProjectionLayer

And implement the required methods like renderView() to start rendering into each eye:

void ProjectionLayer::renderView()

    // Update the scene data once per frame
    if (m_currentViewIndex == 0) {

    // Update the per-view camera matrices

    auto commandRecorder = m_device->createCommandRecorder();

    // Set up the render pass using the current color and depth texture views
    m_opaquePassOptions.colorAttachments[0].view = m_colorSwapchains[m_currentViewIndex].textureViews[m_currentColorImageIndex];
    m_opaquePassOptions.depthStencilAttachment.view = m_depthSwapchains[m_currentViewIndex].textureViews[m_currentDepthImageIndex];
    auto opaquePass = commandRecorder.beginRenderPass(m_opaquePassOptions);

   // Do the rest of your rendering commands to this pass...

And add this layer to the compositor, in our examples this is abstracted away for you:

// Create a projection layer to render the 3D scene
const XrProjectionLayerOptions projectionLayerOptions = {
    .device = &m_device,
    .queue = &m_queue,
    .session = &m_session,
    .colorSwapchainFormat = m_colorSwapchainFormat,
    .depthSwapchainFormat = m_depthSwapchainFormat,
    .samples = m_samples.get()
m_projectionLayer = createCompositorLayer<ProjectionLayer>(projectionLayerOptions);

You can view the complete example here. In this new release, we’re continuing to work on multiview support! KDXr supports multiview out of the box (see the example layer code) and you can check out the multiview example.

More in-depth examples are now available

The examples sitting in our main repository are no more than small tests, which don’t show the true benefits of using KDGpu in large graphical applications. So, in addition to our previous examples, we now have a dedicated KDGpu Examples repository!

Screenshot from our NBody Compute example. It's a ton of multi-color particles being simulated on the GPU.

Screenshot from our N-Body Compute example.

And more!

There are also small improvements such as being able to request custom extensions and ignore specific validation layer warnings. Check out the changelog on GitHub for a full list of what’s been changed.

Let us know what you think about the improvements we’ve made, and what could be useful for you in the future!

About KDAB

If you like this article and want to read similar material, consider subscribing via our RSS feed.

Subscribe to KDAB TV for similar informative short video content.

KDAB provides market leading software consulting and development services and training in Qt, C++ and 3D/OpenGL. Contact us.

Categories: KDAB Blogs / Technical / Vulkan

Tags: / /
Leave a Reply

Your email address will not be published. Required fields are marked *