Skip to content

Commit

Permalink
Improved varjo poll workararound
Browse files Browse the repository at this point in the history
  • Loading branch information
BuzzteeBear committed Dec 19, 2024
1 parent 7f65288 commit e9e9585
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion SharedProperties.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<VersionMajor>0</VersionMajor>
<VersionMinor>3</VersionMinor>
<VersionPatch>8</VersionPatch>
<VersionRevision>3</VersionRevision>
<VersionRevision>4</VersionRevision>
</PropertyGroup>
<ItemGroup>
<BuildMacro Include="VersionString">
Expand Down
24 changes: 17 additions & 7 deletions XR_APILAYER_NOVENDOR_motion_compensation/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ namespace openxr_api_layer
{
m_Initialized = false;
}
GetConfig()->GetBool(Cfg::PhysicalEarly, m_PhysicalEarlyInit);
}

// enable / disable graphical overlay initialization
Expand Down Expand Up @@ -292,7 +293,6 @@ namespace openxr_api_layer
TraceLocalActivity(local);
TraceLoggingWriteStart(local, "OpenXrLayer::xrPollEvent", TLXArg(instance, "Instance"));

m_VarjoPollWorkaround = false;
const XrResult result = OpenXrApi::xrPollEvent(instance, eventData);

if (m_Enabled)
Expand Down Expand Up @@ -330,13 +330,23 @@ namespace openxr_api_layer
if (const auto event = reinterpret_cast<const XrEventDataSessionStateChanged*>(eventData);
event && event->session == m_Session)
{
Log("session transitioned to %s", xr::ToCString(event->state));
if (event->state == XR_SESSION_STATE_UNKNOWN || event->state > XR_SESSION_STATE_EXITING)
{
ErrorLog("%s: unknown state: %d", __FUNCTION__, event->state);
}
else
{
Log("session transitioned to %s", xr::ToCString(event->state));
m_SessionState = event->state;
m_LastSessionTransition = m_LastFrameTime;
if (XR_SESSION_STATE_FOCUSED == m_SessionState)
{
if (m_VarjoPollWorkaround && m_PhysicalEarlyInit)
{
SyncActions("xrPollEvent");
}
m_VarjoPollWorkaround = false;
}
if (m_Overlay)
{
m_Overlay->m_SessionVisible =
Expand Down Expand Up @@ -383,6 +393,7 @@ namespace openxr_api_layer
m_Session = *session;
m_LastFrameTime = 0;
m_UpdateRefSpaceTime = 0;
m_LastSessionTransition = 0;
DestroyTrackerActions("xrCreateSession");

if (m_Overlay && m_Overlay->m_MarkersInitialized && m_CompositionFrameworkFactory)
Expand All @@ -391,9 +402,7 @@ namespace openxr_api_layer
m_Overlay->m_D3D12inUse = m_CompositionFrameworkFactory->IsUsingD3D12(*session);
}

if (bool earlyPhysicalInit; m_PhysicalEnabled &&
GetConfig()->GetBool(Cfg::PhysicalEarly, earlyPhysicalInit) &&
earlyPhysicalInit)
if (m_PhysicalEarlyInit)
{
Log("performing early initialization of physical tracker");
// initialize everything except tracker
Expand Down Expand Up @@ -1446,13 +1455,14 @@ namespace openxr_api_layer

std::unique_lock lock(m_FrameLock);

if (m_VarjoPollWorkaround && m_Enabled && m_PhysicalEnabled && !m_SuppressInteraction)
if (m_VarjoPollWorkaround && m_Enabled && m_PhysicalEnabled && !m_SuppressInteraction &&
m_LastSessionTransition < m_LastFrameTime - 1000000000)
{
TraceLoggingWriteTagged(local, "OpenXrLayer::xrBeginFrame", TLArg(true, "PollWorkaround"));

// call xrPollEvent (if the app hasn't already) to acquire focus
XrEventDataBuffer buf{XR_TYPE_EVENT_DATA_BUFFER};
OpenXrApi::xrPollEvent(GetXrInstance(), &buf);
xrPollEvent(GetXrInstance(), &buf);
}

if (m_Overlay && m_Overlay->m_MarkersInitialized)
Expand Down
3 changes: 3 additions & 0 deletions XR_APILAYER_NOVENDOR_motion_compensation/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ namespace openxr_api_layer
std::string m_RuntimeName;
bool m_Enabled{false};
bool m_PhysicalEnabled{false};
bool m_PhysicalEarlyInit{false};
bool m_VirtualTrackerUsed{false};
bool m_CompensateControllers{false};
bool m_SuppressInteraction{false};
Expand All @@ -172,6 +173,8 @@ namespace openxr_api_layer
bool m_SyncActionHint{false};
XrTime m_LastFrameTime{0};
XrTime m_UpdateRefSpaceTime{0};
XrTime m_LastSessionTransition{0};
XrSessionState m_SessionState{XR_SESSION_STATE_UNKNOWN};
std::chrono::time_point<std::chrono::steady_clock> m_LastActionSync{std::chrono::steady_clock::now()};
std::set<XrSpace> m_StaticRefSpaces{};
std::map<XrSpace, std::pair<XrPosef, XrPosef>> m_RefToStageMap{};
Expand Down

0 comments on commit e9e9585

Please sign in to comment.