MCPcopy Create free account
hub / github.com/LibreVR/Revive / ovr_GetPredictedDisplayTime

Function ovr_GetPredictedDisplayTime

ReviveXR/REV_CAPI.cpp:1241–1282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1239}
1240
1241OVR_PUBLIC_FUNCTION(double) ovr_GetPredictedDisplayTime(ovrSession session, long long frameIndex)
1242{
1243 if (!session)
1244 return ovr_GetTimeInSeconds();
1245
1246 REV_TRACE(ovr_GetPredictedDisplayTime);
1247 XR_FUNCTION(session->Instance, ConvertTimeToWin32PerformanceCounterKHR);
1248
1249 MICROPROFILE_META_CPU("Predict Frame", (int)frameIndex);
1250
1251 XrIndexedFrameState* CurrentFrame = session->CurrentFrame;
1252 XrTime displayTime = CurrentFrame->predictedDisplayTime;
1253 if (frameIndex > CurrentFrame->frameIndex)
1254 {
1255 // There is no predicted display period for this frame yet, synthesize one
1256 displayTime += CurrentFrame->predictedDisplayPeriod * (frameIndex - CurrentFrame->frameIndex);
1257 }
1258 else if (frameIndex < CurrentFrame->frameIndex)
1259 {
1260 // We keep a history of older frames, check if this is within the history range
1261 // If not, then synthesize an older display time
1262 long long delta = CurrentFrame->frameIndex - frameIndex;
1263 if (delta < ovrMaxProvidedFrameStats)
1264 displayTime = session->FrameStats[frameIndex % ovrMaxProvidedFrameStats].predictedDisplayTime;
1265 else
1266 displayTime -= CurrentFrame->predictedDisplayPeriod * delta;
1267 }
1268
1269 static double PerfFrequencyInverse = 0.0;
1270 if (PerfFrequencyInverse == 0.0)
1271 {
1272 LARGE_INTEGER freq;
1273 QueryPerformanceFrequency(&freq);
1274 PerfFrequencyInverse = 1.0 / (double)freq.QuadPart;
1275 }
1276
1277 LARGE_INTEGER li;
1278 if (XR_FAILED(ConvertTimeToWin32PerformanceCounterKHR(session->Instance, displayTime, &li)))
1279 return 0.0;
1280
1281 return li.QuadPart * PerfFrequencyInverse;
1282}
1283
1284OVR_PUBLIC_FUNCTION(double) ovr_GetTimeInSeconds()
1285{

Callers

nothing calls this directly

Calls 1

ovr_GetTimeInSecondsFunction · 0.70

Tested by

no test coverage detected