SteamVR Frame spikes when creating a single thread

112 views Asked by At

I have a native C++ application that uses SteamVR/OpenVR. During some frames I am creating multiple threads to distribute some work. All of those threads must finish before continuing, so I instantly call join on them.

Despite the multithreaded calculations taking no longer than 1ms, the frame time - as indicated by the Frame-Synchronisation window available through SteamVR - still skyrockets way above 16ms (the scale stops at 16).

The problem can by easily replicated by just starting a single, empty thread in the OpenVR sample project hellovr_opengl and joining it immediately afterwards. In my case I inserted this code snippet inside the MainApplication's RenderFrame() function but anywhere else works just as well:

auto tempStart = std::chrono::high_resolution_clock::now();
std::thread t([]() {});
t.join();
auto tempEnd = std::chrono::high_resolution_clock::now();
std::cout << "Time: " << std::chrono::duration_cast<std::chrono::milliseconds>(tempEnd - tempStart).count() << std::endl;

In my own application I got those high frame times every single frame. When reproducing the issue in the OpenVR sample project, it only seems to happen every few frames but it is still very frequent:

enter image description here

I am aware of course that I should probably pool threads if I reuse them every frame but in any case, creating (and joining) a single (or even a few) threads should not take that long. And as the time measurement shows, it doesn't even come close to 16ms. So why does OpenVR stall for such a long time?

0

There are 0 answers