Skip to content

Commit e1efc14

Browse files
committed
openvr: Improve frame pacing
1 parent 2f9d9e3 commit e1efc14

4 files changed

Lines changed: 39 additions & 16 deletions

File tree

src/Backends/DeferredBackend.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,15 @@ namespace gamescope
381381
return m_pChild->ShouldFitWindows();
382382
}
383383

384+
void OnEndFrame() override
385+
{
386+
{
387+
std::shared_lock lock{ m_mutInit };
388+
if ( m_bInittedChild )
389+
m_pChild->OnEndFrame();
390+
}
391+
}
392+
384393
protected:
385394

386395
virtual void OnBackendBlobDestroyed( BackendBlob *pBlob ) override

src/Backends/OpenVRBackend.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,6 @@ namespace gamescope
427427

428428
GetVBlankTimer().MarkVBlank( ulNow, true );
429429

430-
// Nudge so that steamcompmgr releases commits.
431-
nudge_steamcompmgr();
432-
433430
// Flush out any pending commits -> visible
434431
// and any visible commits -> release.
435432
{
@@ -455,6 +452,9 @@ namespace gamescope
455452
m_pForwarderPlanesInFlight.clear();
456453
}
457454

455+
// Nudge so that steamcompmgr releases commits.
456+
nudge_steamcompmgr();
457+
458458
ProcessVRInput();
459459
}
460460
}
@@ -989,6 +989,18 @@ namespace gamescope
989989
return false;
990990
}
991991

992+
void OnEndFrame() override
993+
{
994+
GetVBlankTimer().UpdateWasCompositing( true );
995+
GetVBlankTimer().UpdateLastDrawTime( get_time_in_nanos() - g_SteamCompMgrVBlankTime.ulWakeupTime );
996+
997+
int32_t nNewRefreshRate = (int32_t) ConvertHztomHz( roundf( vr::VRSystem()->GetFloatTrackedDeviceProperty( vr::k_unTrackedDeviceIndex_Hmd, vr::Prop_DisplayFrequency_Float ) ) );
998+
if ( g_nOutputRefresh != nNewRefreshRate )
999+
g_nOutputRefresh = nNewRefreshRate;
1000+
1001+
PollState();
1002+
}
1003+
9921004
const char *GetOverlayKey() const { return m_szOverlayKey.c_str(); }
9931005
const char *GetAppOverlayKey() const { return m_szAppOverlayKey.c_str(); }
9941006
const char *GetOverlayName() const { return m_pchOverlayName; }
@@ -1650,16 +1662,6 @@ namespace gamescope
16501662
m_Planes[i].Present( nullptr );
16511663
}
16521664

1653-
1654-
GetVBlankTimer().UpdateWasCompositing( true );
1655-
GetVBlankTimer().UpdateLastDrawTime( get_time_in_nanos() - g_SteamCompMgrVBlankTime.ulWakeupTime );
1656-
1657-
int32_t nNewRefreshRate = (int32_t) ConvertHztomHz( roundf( vr::VRSystem()->GetFloatTrackedDeviceProperty( vr::k_unTrackedDeviceIndex_Hmd, vr::Prop_DisplayFrequency_Float ) ) );
1658-
if ( g_nOutputRefresh != nNewRefreshRate )
1659-
g_nOutputRefresh = nNewRefreshRate;
1660-
1661-
m_pBackend->PollState();
1662-
16631665
return 0;
16641666
}
16651667

src/backend.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ namespace gamescope
394394

395395
virtual bool ShouldFitWindows() = 0;
396396

397+
virtual void OnEndFrame() = 0;
398+
397399
static IBackend *Get();
398400
template <typename T>
399401
static bool Set();
@@ -430,6 +432,8 @@ namespace gamescope
430432
virtual bool NewlyInitted() override { return false; }
431433

432434
virtual bool ShouldFitWindows() override { return true; }
435+
436+
virtual void OnEndFrame() override {}
433437
};
434438

435439
// This is a blob of data that may be associated with

src/steamcompmgr.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ LogScope g_WaitableLog("waitable");
131131

132132
gamescope::ConVar<bool> cv_overlay_unmultiplied_alpha{ "overlay_unmultiplied_alpha", false };
133133

134+
gamescope::ConVar<bool> cv_vr_show_forwarded_overlays{ "vr_show_forwarded_overlays", false };
135+
134136
std::string *g_pVROverlayKey = nullptr;
135137
bool g_bWasPartialComposite = false;
136138

@@ -2463,6 +2465,8 @@ static void ForwardVROverlayTargets()
24632465
}
24642466
}
24652467
}
2468+
2469+
gpuvis_trace_printf( "Forward VR Overlays" );
24662470
}
24672471

24682472
gamescope::ConVar<bool> cv_paint_primary_plane{ "paint_primary_plane", true };
@@ -3669,7 +3673,7 @@ found:;
36693673
}
36703674

36713675
// Skip overlay targets
3672-
if ( w->oulTargetVROverlay )
3676+
if ( w->oulTargetVROverlay && !cv_vr_show_forwarded_overlays )
36733677
{
36743678
continue;
36753679
}
@@ -4561,7 +4565,7 @@ handle_desktop_window(steamcompmgr_win_t *w)
45614565
if ( w->type != steamcompmgr_win_type_t::XWAYLAND )
45624566
return;
45634567

4564-
if ( w->xwayland().a.override_redirect || w->oulTargetVROverlay )
4568+
if ( w->xwayland().a.override_redirect || ( w->oulTargetVROverlay && !cv_vr_show_forwarded_overlays ) )
45654569
return;
45664570

45674571
if ( win_maybe_a_dropdown( w ) || win_is_useless( w ) )
@@ -5224,7 +5228,7 @@ damage_win(xwayland_ctx_t *ctx, XDamageNotifyEvent *de)
52245228
bool bCareAboutWindow = true;
52255229

52265230
if ( win_is_useless( w ) || w->IsAnyOverlay() ||
5227-
w->oulTargetVROverlay || w->isSysTrayIcon ||
5231+
( w->oulTargetVROverlay && !cv_vr_show_forwarded_overlays ) || w->isSysTrayIcon ||
52285232
w->xwayland().a.map_state != IsViewable )
52295233
{
52305234
bCareAboutWindow = false;
@@ -8959,10 +8963,14 @@ steamcompmgr_main(int argc, char **argv)
89598963
ForwardVROverlayTargets();
89608964

89618965
g_bUpdateForwardedVROverlays = false;
8966+
8967+
bPainted = true;
89628968
}
89638969

89648970
if ( bPainted )
89658971
{
8972+
GetBackend()->OnEndFrame();
8973+
89668974
hasRepaint = false;
89678975
hasRepaintNonBasePlane = false;
89688976
nIgnoredOverlayRepaints = 0;

0 commit comments

Comments
 (0)