Giter Club home page Giter Club logo

openxr-vulkan-example's Introduction

Teaser

Overview

This project demonstrates how you can write your own VR application using OpenXR 1.1 and Vulkan 1.3. These are its main features:

  • Basic rendering of example scene to the headset and into a resizeable mirror view on your desktop monitor.
  • Focus on easy to read and understand C++ without smart pointers, inheritance, templates, etc.
  • Usage of the Vulkan multiview extension for extra performance.
  • Warning-free code base spread over a small handful of classes.
  • No OpenXR or Vulkan validation errors or warnings.
  • CMake project setup for easy building.

Integrating both OpenXR and Vulkan yourself can be a daunting and painfully time-consuming task. Both APIs are very verbose and require the correct handling of countless minute details. This is why there are two main use cases where this project comes in handy:

  1. Fork the repository and use it as a starting point to save yourself weeks of tedious integration work before you get to the juicy bits of VR development.
  2. Reference the code while writing your own implementation from scratch, to help you out if you are stuck with a problem, or simply for inspiration.

Running the OpenXR Vulkan Example

  1. Download the latest release or build the project yourself with the steps below.
  2. Make sure your headset is connected to your computer.
  3. Run the program!

Building the OpenXR Vulkan Example

  1. Install the Vulkan SDK version 1.3 or newer.
  2. Install CMake version 3.1 or newer.
  3. Clone the repository and generate build files.
  4. Build!

The repository includes binaries for all dependencies except the Vulkan SDK on Windows. These can be found in the external folder. You will have to build these dependencies yourself on other platforms. Use the address and version tag or commit hash in version.txt to ensure compatibility. Please don't hesitate to open a pull request if you have built dependencies for previously unsupported platforms.

Attributions

Asset Title Author License
models/Beetle.obj Car Scene toivo CC BY 4.0
models/Bike.obj Sci-fi Hover Bike 04 taktelon CC BY 4.0
models/Car.obj GAZ-21 Ashkelon CC BY 4.0
models/Hand.obj Hand Anatomy Reference Ant B-D CC BY 4.0
models/Ruins.obj Ancient Ruins Pack Toni GarcΓ­a Vilche CC BY 4.0

openxr-vulkan-example's People

Contributors

janhsimon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

openxr-vulkan-example's Issues

No swapchain image has been acquired

Hello! Thanks for providing this sample, it is the best looking I found so far!

I am trying to run it on Windows 10, MSVC 2022 with a HP Reverb G2 headset. I installed a fresh Vulkan SDK 1.3.283.0.
Now as far as I know my headset doesn't support OpenXR with Vulkan, but with the help of this tool: https://github.com/mbucchia/OpenXR-Vk-D3D12, I managed to run Godot XR samples using the Vulkan renderer (called Forward+). So I assumed this sample should also work with my setup (this assumption can be easily wrong). I made sure to disable my OpenXR Toolkit.

I am getting the following validation errors in Debug, not sure if they are important:

[Vulkan] Validation Error: [ VUID-VkImageViewCreateInfo-image-04441 ] Object 0: handle = 0xe88693000000000c, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0xb75da543 | vkCreateImageView(): pCreateInfo->image (VkImage 0xe88693000000000c[]) was created with VkImageUsageFlags(0) but requires VK_IMAGE_USAGE_SAMPLED_BIT|VK_IMAGE_USAGE_STORAGE_BIT|VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT|VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT|VK_IMAGE_USAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR|VK_IMAGE_USAGE_FRAGMENT_DENSITY_MAP_BIT_EXT|VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR|VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR|VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR|VK_IMAGE_USAGE_VIDEO_ENCODE_DPB_BIT_KHR|VK_IMAGE_USAGE_SAMPLE_WEIGHT_BIT_QCOM|VK_IMAGE_USAGE_SAMPLE_BLOCK_MATCH_BIT_QCOM. The Vulkan spec states: image must have been created with a usage value containing at least one of the usages defined in the valid image usage list for image views (https://vulkan.lunarg.com/doc/view/1.3.283.0/windows/1.3-extensions/vkspec.html#VUID-VkImageViewCreateInfo-image-04441)
[Vulkan] Validation Error: [ VUID-VkImageViewCreateInfo-image-04441 ] Object 0: handle = 0x967dd1000000000e, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0xb75da543 | vkCreateImageView(): pCreateInfo->image (VkImage 0x967dd1000000000e[]) was created with VkImageUsageFlags(0) but requires VK_IMAGE_USAGE_SAMPLED_BIT|VK_IMAGE_USAGE_STORAGE_BIT|VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT|VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT|VK_IMAGE_USAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR|VK_IMAGE_USAGE_FRAGMENT_DENSITY_MAP_BIT_EXT|VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR|VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR|VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR|VK_IMAGE_USAGE_VIDEO_ENCODE_DPB_BIT_KHR|VK_IMAGE_USAGE_SAMPLE_WEIGHT_BIT_QCOM|VK_IMAGE_USAGE_SAMPLE_BLOCK_MATCH_BIT_QCOM. The Vulkan spec states: image must have been created with a usage value containing at least one of the usages defined in the valid image usage list for image views (https://vulkan.lunarg.com/doc/view/1.3.283.0/windows/1.3-extensions/vkspec.html#VUID-VkImageViewCreateInfo-image-04441)
[Vulkan] Validation Error: [ VUID-VkImageViewCreateInfo-image-04441 ] Object 0: handle = 0xd5b26f0000000010, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0xb75da543 | vkCreateImageView(): pCreateInfo->image (VkImage 0xd5b26f0000000010[]) was created with VkImageUsageFlags(0) but requires VK_IMAGE_USAGE_SAMPLED_BIT|VK_IMAGE_USAGE_STORAGE_BIT|VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT|VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT|VK_IMAGE_USAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR|VK_IMAGE_USAGE_FRAGMENT_DENSITY_MAP_BIT_EXT|VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR|VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR|VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR|VK_IMAGE_USAGE_VIDEO_ENCODE_DPB_BIT_KHR|VK_IMAGE_USAGE_SAMPLE_WEIGHT_BIT_QCOM|VK_IMAGE_USAGE_SAMPLE_BLOCK_MATCH_BIT_QCOM. The Vulkan spec states: image must have been created with a usage value containing at least one of the usages defined in the valid image usage list for image views (https://vulkan.lunarg.com/doc/view/1.3.283.0/windows/1.3-extensions/vkspec.html#VUID-VkImageViewCreateInfo-image-04441)
[Vulkan] Validation Error: [ VUID-VkGraphicsPipelineCreateInfo-None-09497 ] | MessageID = 0x5750c307 | vkCreateGraphicsPipelines(): pCreateInfos[0].flags (0x400) has VkPipelineCreateFlagBits values that requires the extensions VK_EXT_graphics_pipeline_library. The Vulkan spec states: If the pNext chain does not include a VkPipelineCreateFlags2CreateInfoKHR structure, flags must be a valid combination of VkPipelineCreateFlagBits values (https://vulkan.lunarg.com/doc/view/1.3.283.0/windows/1.3-extensions/vkspec.html#VUID-VkGraphicsPipelineCreateInfo-None-09497)
[Vulkan] Validation Error: [ VUID-VkGraphicsPipelineCreateInfo-None-09497 ] | MessageID = 0x5750c307 | vkCreateGraphicsPipelines(): pCreateInfos[0].flags (0x400) has VkPipelineCreateFlagBits values that requires the extensions VK_EXT_graphics_pipeline_library. The Vulkan spec states: If the pNext chain does not include a VkPipelineCreateFlags2CreateInfoKHR structure, flags must be a valid combination of VkPipelineCreateFlagBits values (https://vulkan.lunarg.com/doc/view/1.3.283.0/windows/1.3-extensions/vkspec.html#VUID-VkGraphicsPipelineCreateInfo-None-09497)

I am confused about the first ones regarding empty usage, because I confirmed ImageBuffer.cpp always assigning a non-zero usage.

The VR app does start up in my headset and keeps running, but I am only getting a black scene. Meanwhile this error is continuously logged:

Exception thrown at 0x00007FFD8167BA99 in openxr-vulkan-example.exe: Microsoft C++ exception: msxr::XrResultException at memory location 0x000000F8974FD890.
ERROR (OpenXR) : [xrReleaseSwapchainImage] No swapchain image has been acquired.

Please let me know if you have any suggestion.

Have you set this up to support any kind of batched "single pass rendering"?

Hey, nice project. Can you pls elaborate a little bit on how you render the geometry? Do you use the classic old multipass way of one swapchain per eye and render all geometry twice? Or do you use texture array / image array / target array, and batch-render each object to both indexes? Or do you use a double-wide swapchain with both eyes, with two different imageRects? πŸ™‚πŸ™ƒ

I'm new to openxr sdk, and am searching around for the sake of my sanity and reference/verification, if there are any boilerplates out there that have actually done some kind of single pass rendering with openxr. (nothing comes up in search beyond unity and unreal)

xrGetSystemId: -2

OS: Windows 10
Device: Oculus Quest 2
Runtime: SteamVR
OpenXR version: 1.0.22
OpenXR-SDK-Source version built: 1.0.26 (because, I don't need eye tracking, and Oculus Quest 2 dosn't has it)

Hi.
I create my own application to interact with VR and can you help me with it, pls? When I try to get system id, I get error code -2 (with your app the same behavior).
Maybe, you know how to fix it? Thx, in advance!

Some logs:

Verbose [GENERAL | xrCreateInstance | OpenXR-Loader] : Entering loader trampoline
Info [GENERAL |  | OpenXR-Loader] : RuntimeManifestFile::FindManifestFiles - using registry-specified runtime file C:\My\Steam\steamapps\common\SteamVR\steamxr_win64.json
Info [GENERAL |  | OpenXR-Loader] : RuntimeManifestFile::CreateIfValid - attempting to load C:\My\Steam\steamapps\common\SteamVR\steamxr_win64.json
Info [GENERAL | xrCreateInstance | OpenXR-Loader] : RuntimeInterface::LoadRuntime succeeded loading runtime defined in manifest file C:\My\Steam\steamapps\common\SteamVR\steamxr_win64.json using interface version 1 and OpenXR API version 1.0
Info [GENERAL | xrCreateInstance | OpenXR-Loader] : ApiLayerInterface::LoadApiLayers succeeded loading layer XR_APILAYER_MBUCCHIA_toolkit using interface version 1 and OpenXR API version 1.0
Info [GENERAL | xrCreateInstance | OpenXR-Loader] : ApiLayerInterface::LoadApiLayers succeeded loading layer XR_APILAYER_LUNARG_core_validation using interface version 1 and OpenXR API version 1.0
Verbose [GENERAL | xrCreateInstance | OpenXR-Loader] : Entering LoaderInstance::CreateInstance
Core Validation output type: text, first time = true
Verbose [GENERAL | xrCreateInstance | OpenXR-Loader] : Entering loader terminator
Verbose [GENERAL | xrCreateInstance | OpenXR-Loader] : Completed loader terminator
Verbose [GENERAL | xrDestroyInstance | OpenXR-Loader] : Entering loader terminator
Verbose [GENERAL | xrDestroyInstance | OpenXR-Loader] : Completed loader terminator
Core Validation output type: text, first time = false
Verbose [GENERAL | xrCreateInstance | OpenXR-Loader] : Entering loader terminator
Verbose [GENERAL | xrCreateInstance | OpenXR-Loader] : Completed loader terminator
Info [GENERAL | xrCreateInstance | OpenXR-Loader] : LoaderInstance::CreateInstance succeeded with 2 layers enabled and runtime interface - created instance = 0x00000296268fa580
Verbose [GENERAL | xrCreateInstance | OpenXR-Loader] : Completed loader trampoline
[VALID_ERROR | VUID-XrSystemProperties-next-next | xrGetSystemProperties]: Invalid structure(s) in "next" chain for XrSystemProperties struct "next"
  Objects:
   [0] - XrInstance (0x00000296268fa580)
[VALID_ERROR | VUID-xrGetSystemProperties-properties-parameter | xrGetSystemProperties]: Command xrGetSystemProperties param properties is invalid
  Objects:
   [0] - XrInstance (0x00000296268fa580)
Error: Failed to get system: -2

Some code:

XrInstance  createInstance(std::string_view appName)
{
    static const char *const layerNames[]{"XR_APILAYER_LUNARG_core_validation"};
    
    static const char *const extensionNames[]{
        "XR_KHR_vulkan_enable",
        "XR_KHR_vulkan_enable2",
        // "XR_EXT_hand_tracking",
#ifdef VR_GLOVES_DEBUG_MODE
        "XR_EXT_debug_utils"
#endif // VR_GLOVES_DEBUG_MODE
    };

    XrInstanceCreateInfo instanceCreateInfo{};
    instanceCreateInfo.type = XR_TYPE_INSTANCE_CREATE_INFO;
    instanceCreateInfo.createFlags = 0;

    ::strncpy(instanceCreateInfo.applicationInfo.applicationName, appName.data(),
              sizeof(instanceCreateInfo.applicationInfo.applicationName));

    instanceCreateInfo.applicationInfo.applicationVersion =
        XR_MAKE_VERSION(config::appVerMajor,
                        config::appVerMinor,
                        config::appVerPatch);

    ::strncpy(instanceCreateInfo.applicationInfo.engineName, appName.data(),
              sizeof(instanceCreateInfo.applicationInfo.engineName));

    instanceCreateInfo.applicationInfo.engineVersion =
        XR_MAKE_VERSION(config::appVerMajor,
                        config::appVerMinor,
                        config::appVerPatch);

    instanceCreateInfo.applicationInfo.apiVersion = XR_CURRENT_API_VERSION;
    instanceCreateInfo.enabledApiLayerCount = sizeof(layerNames) / sizeof(const char *);
    instanceCreateInfo.enabledApiLayerNames = layerNames;
    instanceCreateInfo.enabledExtensionCount = sizeof(extensionNames) / sizeof(const char *);
    instanceCreateInfo.enabledExtensionNames = extensionNames;

    XrInstance instance{XR_NULL_HANDLE};

    if (const XrResult result = ::xrCreateInstance(&instanceCreateInfo, &instance);
        result != XR_SUCCESS)
    {
        logger::log_error("Failed to create OpenXR instance: {}", result);
        return;
    }

   return instance;
}
XrSystemId getSystem(XrInstance instance)
{
    XrSystemGetInfo systemGetInfo{};
    systemGetInfo.type = XR_TYPE_SYSTEM_GET_INFO;
    systemGetInfo.formFactor = XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY;

    XrSystemId systemID;

    if (const XrResult result = ::xrGetSystem(instance, &systemGetInfo, &systemID);
        result != XR_SUCCESS)
    {
        logger::log_error("Failed to get system: {}", result);
        return XR_NULL_SYSTEM_ID;
    }

    return systemID;
}

Did a clone/build, only got left eye rendering

Hi thanks for doing this projects as I've been trying to get my head around Vulkan/OpenXR as a background thing and this helps a lot.

Anyway I've just done a clone and build using MSVS2019 & latest Vulkan SDK, all I get rendered is the cube in the left eye. The right eye and mirror display are black. I've not started to dig in to why but through you should know.

Also I've got WMR headset so I'm going through StreamVR, M$ will be M$

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.