1 #ifndef _GLSCALIBRATION_HPP
2 #define _GLSCALIBRATION_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program OpenGL (ES) Module
5 * -----------------------------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Calibration tools.
24 *//*--------------------------------------------------------------------*/
26 #include "tcuDefs.hpp"
27 #include "tcuTestCase.hpp"
28 #include "tcuTestLog.hpp"
29 #include "tcuVector.hpp"
30 #include "gluRenderContext.hpp"
44 LineParameters (float offset_, float coefficient_) : offset(offset_), coefficient(coefficient_) {}
47 // Basic Theil-Sen linear estimate. Calculates median of all possible slope coefficients through two of the data points
48 // and median of offsets corresponding with the median slope
49 LineParameters theilSenLinearRegression (const std::vector<tcu::Vec2>& dataPoints);
51 struct LineParametersWithConfidence
54 float offsetConfidenceUpper;
55 float offsetConfidenceLower;
58 float coefficientConfidenceUpper;
59 float coefficientConfidenceLower;
64 // Median-of-medians version of Theil-Sen estimate. Calculates median of medians of slopes through a point and all other points.
65 // Confidence interval is given as the range that contains the given fraction of all slopes/offsets
66 LineParametersWithConfidence theilSenSiegelLinearRegression (const std::vector<tcu::Vec2>& dataPoints, float reportedConfidence);
72 , frameShortcutTime (std::numeric_limits<float>::infinity())
78 void start (int maxNumFrames, float frameShortcutTime, int numDrawCalls);
80 bool isDone (void) const;
81 deUint64 getTotalTime (void) const;
84 float frameShortcutTime;
86 std::vector<deUint64> frameTimes;
89 struct CalibrateIteration
91 CalibrateIteration (int numDrawCalls_, float frameTime_)
92 : numDrawCalls (numDrawCalls_)
93 , frameTime (frameTime_)
97 CalibrateIteration (void)
107 struct CalibratorParameters
109 CalibratorParameters (int numInitialCalls_,
110 int maxCalibrateIterationFrames_, //!< Maximum (and default) number of frames per one calibrate iteration.
111 float calibrateIterationShortcutThresholdMs_, //!< If the times of two consecutive frames exceed this, stop the iteration even if maxCalibrateIterationFrames isn't reached.
112 int maxCalibrateIterations_,
113 float targetFrameTimeMs_,
114 float frameTimeCapMs_,
115 float targetMeasureDurationMs_)
116 : numInitialCalls (numInitialCalls_)
117 , maxCalibrateIterationFrames (maxCalibrateIterationFrames_)
118 , calibrateIterationShortcutThreshold (1000.0f*calibrateIterationShortcutThresholdMs_)
119 , maxCalibrateIterations (maxCalibrateIterations_)
120 , targetFrameTimeUs (1000.0f*targetFrameTimeMs_)
121 , frameTimeCapUs (1000.0f*frameTimeCapMs_)
122 , targetMeasureDurationUs (1000.0f*targetMeasureDurationMs_)
127 int maxCalibrateIterationFrames;
128 float calibrateIterationShortcutThreshold;
129 int maxCalibrateIterations;
130 float targetFrameTimeUs;
131 float frameTimeCapUs;
132 float targetMeasureDurationUs;
135 class TheilSenCalibrator
140 STATE_RECOMPUTE_PARAMS = 0,
147 TheilSenCalibrator (void);
148 TheilSenCalibrator (const CalibratorParameters& params);
149 ~TheilSenCalibrator (void);
152 void clear (const CalibratorParameters& params);
154 State getState (void) const;
155 int getCallCount (void) const { return m_measureState.numDrawCalls; }
157 // Should be called when getState() returns STATE_RECOMPUTE_PARAMS
158 void recomputeParameters (void);
160 // Should be called when getState() returns STATE_MEASURE
161 void recordIteration (deUint64 frameTime);
163 const CalibratorParameters& getParameters (void) const { return m_params; }
164 const MeasureState& getMeasureState (void) const { return m_measureState; }
165 const std::vector<CalibrateIteration>& getCalibrationInfo (void) const { return m_calibrateIterations; }
170 INTERNALSTATE_CALIBRATING = 0,
171 INTERNALSTATE_RUNNING,
172 INTERNALSTATE_FINISHED,
177 CalibratorParameters m_params;
179 InternalState m_state;
180 MeasureState m_measureState;
182 std::vector<CalibrateIteration> m_calibrateIterations;
185 void logCalibrationInfo (tcu::TestLog& log, const TheilSenCalibrator& calibrator);
190 #endif // _GLSCALIBRATION_HPP