summaryrefslogtreecommitdiffstats
path: root/LibOVR/Src/CAPI/CAPI_FrameTimeManager.h
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-03-21 23:01:12 +0100
committerSven Gothel <[email protected]>2015-03-21 23:01:12 +0100
commit0c5c4be020c2d55540058a49b2a879f46d5a1e13 (patch)
tree00f84c2ca18cc233b826014094b9cad0769a3ea5 /LibOVR/Src/CAPI/CAPI_FrameTimeManager.h
parentcbbd775b6c754927632c333ff01424a0d2048c7c (diff)
parente490c3c7f7bb5461cfa78a214827aa534fb43a3e (diff)
Merge branch 'vanilla_0.4.4' and resolve conflicts
TODO: Validate for removed patches due to relocation Resolved Conflicts: LibOVR/Src/Kernel/OVR_ThreadsWinAPI.cpp LibOVR/Src/OVR_Linux_HMDDevice.cpp LibOVR/Src/OVR_OSX_HMDDevice.cpp LibOVR/Src/OVR_Profile.cpp LibOVR/Src/OVR_Sensor2Impl.cpp LibOVR/Src/OVR_SensorFusion.cpp LibOVR/Src/OVR_SensorImpl.cpp LibOVR/Src/OVR_Win32_DeviceStatus.cpp LibOVR/Src/OVR_Win32_HIDDevice.cpp LibOVR/Src/OVR_Win32_HIDDevice.h LibOVR/Src/OVR_Win32_HMDDevice.cpp
Diffstat (limited to 'LibOVR/Src/CAPI/CAPI_FrameTimeManager.h')
-rw-r--r--LibOVR/Src/CAPI/CAPI_FrameTimeManager.h123
1 files changed, 93 insertions, 30 deletions
diff --git a/LibOVR/Src/CAPI/CAPI_FrameTimeManager.h b/LibOVR/Src/CAPI/CAPI_FrameTimeManager.h
index 4693697..3973216 100644
--- a/LibOVR/Src/CAPI/CAPI_FrameTimeManager.h
+++ b/LibOVR/Src/CAPI/CAPI_FrameTimeManager.h
@@ -5,16 +5,16 @@ Content : Manage frame timing and pose prediction for rendering
Created : November 30, 2013
Authors : Volga Aksoy, Michael Antonov
-Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved.
+Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
-Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License");
+Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
you may not use the Oculus VR Rift SDK except in compliance with the License,
which is provided at the time of installation or download, or which
otherwise accompanies this software in either electronic or hard copy form.
You may obtain a copy of the License at
-http://www.oculusvr.com/licenses/LICENSE-3.1
+http://www.oculusvr.com/licenses/LICENSE-3.2
Unless required by applicable law or agreed to in writing, the Oculus VR SDK
distributed under the License is distributed on an "AS IS" BASIS,
@@ -31,29 +31,33 @@ limitations under the License.
#include "../Kernel/OVR_Timer.h"
#include "../Kernel/OVR_Math.h"
#include "../Util/Util_Render_Stereo.h"
-#include "../Util/Util_LatencyTest2.h"
namespace OVR { namespace CAPI {
+
//-------------------------------------------------------------------------------------
+// ***** TimeDeltaCollector
// Helper class to collect median times between frames, so that we know
// how long to wait.
struct TimeDeltaCollector
{
- TimeDeltaCollector() : Count(0) { }
+ TimeDeltaCollector() : Median(-1.0), Count(0), ReCalcMedian(true) { }
- void AddTimeDelta(double timeSeconds);
- void Clear() { Count = 0; }
+ void AddTimeDelta(double timeSeconds);
+ void Clear() { Count = 0; }
double GetMedianTimeDelta() const;
+ double GetMedianTimeDeltaNoFirmwareHack() const;
double GetCount() const { return Count; }
enum { Capacity = 12 };
-private:
- int Count;
+private:
double TimeBufferSeconds[Capacity];
+ mutable double Median;
+ int Count;
+ mutable bool ReCalcMedian;
};
@@ -85,7 +89,8 @@ public:
void MatchRecord(const Util::FrameTimeRecordSet &r);
- void GetLatencyTimings(float latencies[3]);
+ bool IsLatencyTimingAvailable();
+ void GetLatencyTimings(float& latencyRender, float& latencyTimewarp, float& latencyPostPresent);
void Reset();
@@ -130,7 +135,7 @@ public:
class FrameTimeManager
{
public:
- FrameTimeManager(bool vsyncEnabled = true);
+ FrameTimeManager(bool vsyncEnabled);
// Data that affects frame timing computation.
struct TimingInputs
@@ -191,40 +196,96 @@ public:
// Thread-safe function to query timing for a future frame
Timing GetFrameTiming(unsigned frameIndex);
- double GetEyePredictionTime(ovrEyeType eye);
- Transformf GetEyePredictionPose(ovrHmd hmd, ovrEyeType eye);
+ // if eye == ovrEye_Count, timing is for MidpointTime as opposed to any specific eye
+ double GetEyePredictionTime(ovrEyeType eye, unsigned int frameIndex);
+ ovrTrackingState GetEyePredictionTracking(ovrHmd hmd, ovrEyeType eye, unsigned int frameIndex);
+ Posef GetEyePredictionPose(ovrHmd hmd, ovrEyeType eye);
void GetTimewarpPredictions(ovrEyeType eye, double timewarpStartEnd[2]);
- void GetTimewarpMatrices(ovrHmd hmd, ovrEyeType eye, ovrPosef renderPose, ovrMatrix4f twmOut[2]);
+ void GetTimewarpMatrices(ovrHmd hmd, ovrEyeType eye, ovrPosef renderPose, ovrMatrix4f twmOut[2],double debugTimingOffsetInSeconds = 0.0);
// Used by renderer to determine if it should time distortion rendering.
bool NeedDistortionTimeMeasurement() const;
void AddDistortionTimeMeasurement(double distortionTimeSeconds);
- // DK2 Lateny test interface
-
- // Get next draw color for DK2 latency tester
- unsigned char GetFrameLatencyTestDrawColor()
- { return ScreenLatencyTracker.GetNextDrawColor(); }
+ // DK2 Latency test interface
+
+ // Get next draw color for DK2 latency tester (3-byte RGB)
+ void GetFrameLatencyTestDrawColor(unsigned char outColor[3])
+ {
+ outColor[0] = ScreenLatencyTracker.GetNextDrawColor();
+ outColor[1] = ScreenLatencyTracker.IsLatencyTimingAvailable() ? 255 : 0;
+ outColor[2] = ScreenLatencyTracker.IsLatencyTimingAvailable() ? 0 : 255;
+ }
// Must be called after EndFrame() to update latency tester timings.
// Must pass color reported by NextFrameColor for this frame.
- void UpdateFrameLatencyTrackingAfterEndFrame(unsigned char frameLatencyTestColor,
+ void UpdateFrameLatencyTrackingAfterEndFrame(unsigned char frameLatencyTestColor[3],
const Util::FrameTimeRecordSet& rs);
- void GetLatencyTimings(float latencies[3])
- { return ScreenLatencyTracker.GetLatencyTimings(latencies); }
-
+ void GetLatencyTimings(float& latencyRender, float& latencyTimewarp, float& latencyPostPresent)
+ {
+ return ScreenLatencyTracker.GetLatencyTimings(latencyRender, latencyTimewarp, latencyPostPresent);
+ }
const Timing& GetFrameTiming() const { return FrameTiming; }
private:
-
double calcFrameDelta() const;
double calcScreenDelay() const;
- double calcTimewarpWaitDelta() const;
+ double calcTimewarpWaitDelta() const;
+
+ //Revisit dynamic pre-Timewarp delay adjustment logic
+ /*
+ void updateTimewarpTiming();
+
+
+ // TimewarpDelayAdjuster implements a simple state machine that reduces the amount
+ // of time-warp waiting based on skipped frames.
+ struct TimewarpDelayAdjuster
+ {
+ enum StateInLevel
+ {
+ // We are ok at this level, and will be waiting for some time before trying to reduce.
+ State_WaitingToReduceLevel,
+ // After decrementing a level, we are verifying that this won't cause skipped frames.
+ State_VerifyingAfterReduce
+ };
+
+ enum {
+ MaxDelayLevel = 5,
+ MaxInfiniteTimingLevel = 3,
+ MaxTimeIndex = 6
+ };
+
+ StateInLevel State;
+ // Current level. Higher levels means larger delay reduction (smaller overall time-warp delay).
+ int DelayLevel;
+ // Index for the amount of time we'd wait in this level. If attempt to decrease level fails,
+ // with is incrementing causing the level to become "sticky".
+ int WaitTimeIndexForLevel[MaxTimeIndex + 1];
+ // We skip few frames after each escalation to avoid too rapid of a reduction.
+ int InitialFrameCounter;
+ // What th currect "reduction" currently is.
+ double TimewarpDelayReductionSeconds;
+ // When we should try changing the level again.
+ double DelayLevelFinishTime;
+
+ public:
+ TimewarpDelayAdjuster() { Reset(); }
+
+ void Reset();
+
+ void UpdateTimewarpWaitIfSkippedFrames(FrameTimeManager* manager,
+ double measuredFrameDelta,
+ double nextFrameTime);
+
+ double GetDelayReduction() const { return TimewarpDelayReductionSeconds; }
+ };
+ */
+
HmdRenderInfo RenderInfo;
// Timings are collected through a median filter, to avoid outliers.
@@ -236,8 +297,10 @@ private:
bool VsyncEnabled;
// Set if we are rendering via the SDK, so DistortionRenderTimes is valid.
bool DynamicPrediction;
- // Set if SDk is doing teh rendering.
+ // Set if SDk is doing the rendering.
bool SdkRender;
+ // Direct to rift.
+ bool DirectToRift;
// Total frame delay due to VsyncToFirstScanline, persistence and settle time.
// Computed from RenderInfor.Shutter.
@@ -245,11 +308,13 @@ private:
double NoVSyncToScanoutDelay;
double ScreenSwitchingDelay;
+ //Revisit dynamic pre-Timewarp delay adjustment logic
+ //TimewarpDelayAdjuster TimewarpAdjuster;
+
// Current (or last) frame timing info. Used as a source for LocklessTiming.
Timing FrameTiming;
// TBD: Don't we need NextFrame here as well?
- LocklessUpdater<Timing> LocklessTiming;
-
+ LocklessUpdater<Timing, Timing> LocklessTiming;
// IMU Read timings
double RenderIMUTimeSeconds;
@@ -260,5 +325,3 @@ private:
}} // namespace OVR::CAPI
#endif // OVR_CAPI_FrameTimeManager_h
-
-