Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vsgvr could not automatically startup steamvr #15

Open
rhabacker opened this issue Nov 21, 2022 · 11 comments
Open

vsgvr could not automatically startup steamvr #15

rhabacker opened this issue Nov 21, 2022 · 11 comments

Comments

@rhabacker
Copy link
Contributor

rhabacker commented Nov 21, 2022

I compiled the binary example_vr on Linux with

$ mkdir ~/src
$ cd ~/src
$ git clone https://github.com/geefr/vsgvr.git
$cd vsgvr
$ cmake -B ../vsgvr-build
$ cmake --build ../vsgvr-build

Running the generated executable with steamVR installed and following the [runtime requirements] (https://github.com/ValveSoftware/SteamVR-for-Linux/blob/master/README.md#runtime-requirements) of steamVR on Linux with

$ ~/.steam/steam/ubuntu12_32/steam-runtime/run.sh ../vsgvr-build/example_vr

provides:

...
Mon Nov 21 2022 14:44:25.892871 - CIPCPipe::ConnectPipe(SteamVR_Namespace) is trying to connect to steamvr:SteamVR_Namespace.
Mon Nov 21 2022 14:44:25.920080 - CSharedResourceNamespaceClient::Init(): Namespace data 7335 received
Mon Nov 21 2022 14:44:25.920163 - CIPCPipe::ConnectPipe(VR_ServerPipe_7335) tries to connect to steamvr:VR_ServerPipe_7335
Mon Nov 21 2022 14:44:26.229832 - Successful response received from vrserver connect
Mon Nov 21 2022 14:44:26.231434 - Did not search for a good app key as Steam did not launch this app
Mon Nov 21 2022 14:44:26.231464 - App key after connection message:system.generated.openxr.vsgvr application.example_vr
Warning: Vulkan API higher than OpenXR maximum. Maximum tested version is 1.2.0
Mon Nov 21 2022 14:44:26.323988 - CSxrCompositorOpenVRGetVulkanGRaphicsDevice error: output device could not be determined.
VSG exception: The physical Vulkan device could not be retrieved by OpenXR (XR_ERROR_RUNTIME_FAILURE)

SteamVR must be started first to avoid this error message. For the variant with openvr this is not necessary, SteamVR is started automatically.

@geefr
Copy link
Owner

geefr commented Nov 21, 2022

What happens if you start without the run.sh? I've never used it, or needed to.

From the logs steamvr has been detected and initialised as the openxr runtime, it's just giving us an error when initialising vulkan. From the message "error: output device could not be determined." it looks like steamvr can't tell us which vulkan device should be used (Like it's supposed to, according to the openxr spec..)

What's your system, gpu, vr headset etc?

The eventual reason for the crash is I'm throwing an exception if any OpenXR errors occur. in this case perhaps we can catch it, and just select the first physical device on the system and hope for the best.

If this happened on a laptop, or something with 2 GPUs however we risk choosing the wrong one, and then initialisation would fail later. With OpenXR we have to render (or at least present) with the device it chooses, any selection we may want can be wrong.

@rhabacker
Copy link
Contributor Author

rhabacker commented Nov 21, 2022

What happens if you start without the run.sh?

The same

$ cd ~/src/vsgvr-build
$ ./example_vr 
VR Server (v1667521602)

Using breakpad crash handler
Setting breakpad minidump AppID = 250820
Forcing breakpad minidump interfaces to load
Looking up breakpad interfaces from steamclient
Calling BreakpadMiniDumpSystemInit
Warning: Vulkan API higher than OpenXR maximum. Maximum tested version is 1.2.0
VSG Exception: Failed to get Vulkan physical device from OpenXR (XR_ERROR_RUNTIME_FAILURE)

What's your system, gpu, vr headset etc?

Dual NVIDIA GTX 1070, Graphic driver version 525.53, HMD: HTC VIVE and all 3 monitors connected to gpu:0

@rhabacker
Copy link
Contributor Author

Here is a detailed log xrclient_example_vr.txt

@geefr
Copy link
Owner

geefr commented Nov 21, 2022

Okay thanks for testing, if you can it would be interesting to know:

  • What happens with only 1 GPU connected
  • What happens on the same machine when running Windows
    (I can test both of those at some point though. Normally I'm on a laptop but plenty of spare hardware)

Let's call it a bug, but perhaps it's one in steamvr. The spec is clear that we need to call it, but doesn't provide much on how the runtime may respond.

I know in the past steamvr has had issues with vulkan device selection on Linux, having had to disable my integrated GPU completely the last time I ran a desktop system, and plug the dedicated GPUs into specific slots..

A possible (bad psuedocode) fix for OpenXRGraphicsBindingVulkan.cpp would be something like this, ideally with:

  • Any runtime-specific quirks being on by default, but having some global vsgvr::config structure to control them
  • Plenty of warnings
  • If possible a best-guess at which of the GPUs is correct. In most cases I'd assume the first one on the pci bus, but I don't think vulkan specifies an order

As it currently stands though, an application will get an exception (albeit a generic one) and could choose to use a specific device - The user knows where the headset is connected if nothing else.

  VkPhysicalDevice OpenXRGraphicsBindingVulkan::getVulkanDeviceRequirements(vsg::ref_ptr<OpenXRInstance> xrInstance, vsg::ref_ptr<vsg::Instance> vkInstance, const VulkanRequirements& versionReqs)
  {
    if (vkInstance->apiVersion < versionReqs.minVersion) {
      throw Exception({ "OpenXR runtime doesn't support requested Vulkan version" });
    }

    VkPhysicalDevice vkPhysicalDevice;
    {
      auto fn = (PFN_xrGetVulkanGraphicsDeviceKHR)xr_pfn(xrInstance->getInstance(), "xrGetVulkanGraphicsDeviceKHR");
     try
{
      xr_check(fn(xrInstance->getInstance(), xrInstance->getSystem(), vkInstance->vk(), &vkPhysicalDevice), "Failed to get Vulkan physical device from OpenXR");
} catch (const vsg::Exception& e) {
    print_the_exception(e);

    ideally_only_if_running_steamvr_and_quirks_enabled?
    {
      devices = vkEnumeratePhysicalDevices();
      vkPhysicalDevice = devices[0];
      print_a_warning("Making an assumption about physical device, things may break later");
    }
}

    }
    return vkPhysicalDevice;
  }

@rhabacker rhabacker mentioned this issue Nov 22, 2022
@rhabacker
Copy link
Contributor Author

rhabacker commented Nov 23, 2022

The particular problem with SteamVR on Linux is that it turns off all monitors at startup, so it's hard to debug from the same host :-(

For the log I found a few details, when running the application:

$ XR_ENABLE_API_LAYERS=1 XR_LOADER_DEBUG=all  ../vsgvr-build/bin/vsgvrviewer
Verbose [GENERAL | xrCreateInstance | OpenXR-Loader] : Entering loader trampoline
Info [GENERAL |  | OpenXR-Loader] : Looking for openxr/1/active_runtime.json in XDG_CONFIG_HOME: /home/xxx/.config/openxr/1/active_runtime.json
Info [GENERAL |  | OpenXR-Loader] : RuntimeManifestFile::CreateIfValid - attempting to load /home/xxx/.config/openxr/1/active_runtime.json
Info [GENERAL | xrCreateInstance | OpenXR-Loader] : RuntimeInterface::LoadRuntime succeeded loading runtime defined in manifest file /home/xxx/.config/openxr/1/active_runtime.json using interface version 1 and OpenXR API version 1.0
Error [GENERAL | xrCreateInstance | OpenXR-Loader] : ApiLayerInterface::LoadApiLayers - failed to find layer 1
Error [GENERAL | xrCreateInstance | OpenXR-Loader] : ApiLayerInterface::LoadApiLayers - failed to find layer 1
Error [GENERAL | xrCreateInstance | OpenXR-Loader] : Failed loading layer information
Error [GENERAL | xrCreateInstance | OpenXR-Loader] : Failed loading layer information
Info [GENERAL | xrCreateInstance | OpenXR-Loader] : RuntimeInterface::UnloadRuntime - Unloading RuntimeInterface
Info [GENERAL |  | OpenXR-Loader] : RuntimeInterface being destroyed.
Error [GENERAL | xrCreateInstance | OpenXR-Loader] : xrCreateInstance failed
Error [GENERAL | xrCreateInstance | OpenXR-Loader] : xrCreateInstance failed
VSG Exception: Failed to create XR Instance (XR_ERROR_API_LAYER_NOT_PRESENT)

@rhabacker
Copy link
Contributor Author

Another variant is (without XR_ENABLE_API_LAYERS=1):

$ XR_LOADER_DEBUG=all ../vsgvr-build/bin/vsgvrviewer 
Verbose [GENERAL | xrCreateInstance | OpenXR-Loader] : Entering loader trampoline
Info [GENERAL |  | OpenXR-Loader] : Looking for openxr/1/active_runtime.json in XDG_CONFIG_HOME: /home/xxx/.config/openxr/1/active_runtime.json
Info [GENERAL |  | OpenXR-Loader] : RuntimeManifestFile::CreateIfValid - attempting to load /home/xxx/.config/openxr/1/active_runtime.json
Info [GENERAL | xrCreateInstance | OpenXR-Loader] : RuntimeInterface::LoadRuntime succeeded loading runtime defined in manifest file /home/xxx/.config/openxr/1/active_runtime.json using interface version 1 and OpenXR API version 1.0
Verbose [GENERAL | xrCreateInstance | OpenXR-Loader] : Entering LoaderInstance::CreateInstance
Verbose [GENERAL | xrCreateInstance | OpenXR-Loader] : Entering loader terminator
VR Server (v1667521602)

Using breakpad crash handler
Setting breakpad minidump AppID = 250820
Forcing breakpad minidump interfaces to load
Looking up breakpad interfaces from steamclient
Calling BreakpadMiniDumpSystemInit
Verbose [GENERAL | xrCreateInstance | OpenXR-Loader] : Completed loader terminator
Info [GENERAL | xrCreateInstance | OpenXR-Loader] : LoaderInstance::CreateInstance succeeded with 0 layers enabled and runtime interface - created instance = 0x0000000001950520
Verbose [GENERAL | xrCreateInstance | OpenXR-Loader] : Completed loader trampoline
0
Warning: Vulkan API higher than OpenXR maximum. Maximum tested version is 1.2.0
Verbose [GENERAL | xrDestroyInstance | OpenXR-Loader] : Entering loader trampoline
Verbose [GENERAL | xrDestroyInstance | OpenXR-Loader] : Entering loader terminator
Verbose [GENERAL | xrDestroyInstance | OpenXR-Loader] : Completed loader terminator
Verbose [GENERAL | xrDestroyInstance | OpenXR-Loader] : Completed loader trampoline
Info [GENERAL | xrDestroyInstance | OpenXR-Loader] : RuntimeInterface::UnloadRuntime - Unloading RuntimeInterface
Info [GENERAL |  | OpenXR-Loader] : RuntimeInterface being destroyed.
VSG Exception: Failed to get Vulkan physical device from OpenXR (XR_ERROR_RUNTIME_FAILURE)

@rhabacker
Copy link
Contributor Author

rhabacker commented Nov 23, 2022

What happens with only 1 GPU connected

After disabling the second graphics card the problem occurs the same way.

I also started SteamVR with null driver turned on, also shows the same problem, which let me think this is not a graphics card issue.

You can also reproduce the problem if, for example, the HDMI cable connection is disconnected on the HTC VIVE, which causes SteamVR to switch to null driver mode and open a separate window (monitor mode).

What happens on the same machine when running Windows

I'm currently not able to run Windows on the same host, but I ran vsgvr from a portable build generated from the https://build.opensuse.org/package/show/home:rhabacker:branches:games:mingw64/mingw64-vsgvr project on Windows 10, which shows the world scene which shows that the included packages (especially OpenXR) and vsgvr basically work with up to date vsg. Doing the same with a 32 bit variant did not work because SteamVR/32bit has no support for OpenXR.

@rhabacker
Copy link
Contributor Author

I looked a little deeper in this stuff and found out that in OpenXRGraphicsBindingVulkan::getVulkanDeviceRequirements()

  ....
    VkPhysicalDevice vkPhysicalDevice;
    {
      auto fn = (PFN_xrGetVulkanGraphicsDeviceKHR)xr_pfn(xrInstance->getInstance(), "xrGetVulkanGraphicsDeviceKHR");
      xr_check(fn(xrInstance->getInstance(), xrInstance->getSystem(), vkInstance->vk(), &vkPhysicalDevice), "Failed to get Vulkan physical device from OpenXR");

no physical vulkan device is returned.

In a debug session the mentioned variable fn showed:

fn	0x7ffff27cd820 <sxr_wrap_xrGetVulkanGraphicsDeviceKHR(XrInstance_T*, unsigned long, VkInstance_T*, 
VkPhysicalDevice_T**)>	XrResult (XrInstance_T *, unsigned long, VkInstance_T *, VkPhysicalDevice_T **)*

which is located in the SteamVR library vrclient.so

nm --demangle=auto ~/.local/share/Steam/steamapps/common/SteamVR/bin/linux64/vrclient.so | grep sxr_wrap_xrGetVulkanGraphicsDeviceKHR
0000000000165820 t sxr_wrap_xrGetVulkanGraphicsDeviceKHR(XrInstance_T*, unsigned long, VkInstance_T*, VkPhysicalDevice_T**)

@rhabacker
Copy link
Contributor Author

no physical vulkan device is returned.

As this time vsg already detected a valid physical vulkan device, which I used instead as return value:

     VkPhysicalDevice vkPhysicalDevice;
    {
      auto fn = (PFN_xrGetVulkanGraphicsDeviceKHR)xr_pfn(xrInstance->getInstance(), "xrGetVulkanGraphicsDevice
      XrResult result = fn(xrInstance->getInstance(), xrInstance->getSystem(), vkInstance->vk(), &vkPhysicalDevice);
      if (result == XR_ERROR_RUNTIME_FAILURE)
          vkPhysicalDevice = vkInstance->getPhysicalDevices().front()->vk();
      else
          xr_check(result, "Failed to get Vulkan physical device from OpenXR");
    }

With this change the next issue happens in OpenXRSession::createSession showing the following error message:

Thu Nov 24 2022 11:55:28.033588 - CSxrCompositorOpenVRGetVulkanGRaphicsDevice error: failed to determine output device
Thu Nov 24 2022 11:55:28.077469 - xrCreateSession: failed to call xrGetVulkanGraphicsDevice before xrCreateSession
VSG Exception: Failed to create OpenXR session (XR_ERROR_VALIDATION_FAILURE)

The mentioned symbol is also located in a library of the SteamVR runtime environment:

nm --demangle=auto  ~/.local/share/Steam/steamapps/common/SteamVR/bin/linux64/vrclient.so | grep -i GetVulkanGRaphicsDevice
...
000000000015d160 t CSxrCompositorOpenVR::GetVulkanGraphicsDevice(VkInstance_T*, VkPhysicalDevice_T*&)

which suggests that this problem is related to the implementation of OpenXR in the SteamVR runtime environment.

@geefr
Copy link
Owner

geefr commented Nov 24, 2022

"which suggests that this problem is related to the implementation of OpenXR in the SteamVR runtime environment."

Yes, that tracks with my assumptions / previous issues for SteamVR - It seems like they're not following the specification, or had some other failure internally, that wasn't trapped before the call to xrGetVulkanGraphicsDeviceKHR.

It's a case where I'm happy to add a workaround for SteamVR given the caveats mentioned earlier, but if they've got a bug it's really their problem. Using one of the physical devices from VSG/Vulkan is fine, we'd just need to get the correct one (which, it sounds like SteamVR doesn't actually know which device is correct in this case).

Thanks for the continued testing, it's all useful information to gather.

@geefr
Copy link
Owner

geefr commented Nov 27, 2022

Original issue of steamvr not-starting automatically - I've reproduced that on my laptop, either regular or beta branch of steamvr, rtx3060, vive..A slightly different log perhaps? I'm not sure where to debug from here.

VR Server (v1664827616)

Using breakpad crash handler
Setting breakpad minidump AppID = 250820
Forcing breakpad minidump interfaces to load
Looking up breakpad interfaces from steamclient
Calling BreakpadMiniDumpSystemInit
assert_20221127195018_4.dmp[19483]: Uploading dump (out-of-process)
/tmp/dumps/assert_20221127195018_4.dmp
assert_20221127195018_4.dmp[19483]: Finished uploading minidump (out-of-process): success = yes
assert_20221127195018_4.dmp[19483]: response: CrashID=bp-3cfb50e5-b001-4e4a-a50b-c743f2221127
assert_20221127195018_4.dmp[19483]: file ''/tmp/dumps/assert_20221127195018_4.dmp'', upload yes: ''CrashID=bp-3cfb50e5-b001-4e4a-a50b-c743f2221127''
Error [GENERAL | xrCreateInstance | OpenXR-Loader] : LoaderInstance::CreateInstance chained CreateInstance call failed
Error [GENERAL | xrCreateInstance | OpenXR-Loader] : xrCreateInstance failed
VSG Exception: Failed to create XR Instance (XR_ERROR_RUNTIME_FAILURE)

Couldn't reproduce the monitors turning off issue, seems fine for me. Running Xubuntu 20.04, so not-Wayland if that's relevant.

A good question would be whether steamvr auto-starts at all on Linux?

I don't think I've ever seen it happen for vsgvr, but does it happen for other applications?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants