1 #ifndef _GLSCALIBRATION_HPP 2 #define _GLSCALIBRATION_HPP 3 /*------------------------------------------------------------------------- 4 * drawElements Quality Program OpenGL (ES) Module 5 * ----------------------------------------------- 6 * 7 * Copyright 2014 The Android Open Source Project 8 * 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 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 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. 20 * 21 *//*! 22 * \file 23 * \brief Calibration tools. 24 *//*--------------------------------------------------------------------*/ 25 26 #include "tcuDefs.hpp" 27 #include "tcuTestCase.hpp" 28 #include "tcuTestLog.hpp" 29 #include "tcuVector.hpp" 30 #include "gluRenderContext.hpp" 31 32 #include <limits> 33 34 namespace deqp 35 { 36 namespace gls 37 { 38 39 struct LineParameters 40 { 41 float offset; 42 float coefficient; 43 LineParametersdeqp::gls::LineParameters44 LineParameters(float offset_, float coefficient_) : offset(offset_), coefficient(coefficient_) 45 { 46 } 47 }; 48 49 // Basic Theil-Sen linear estimate. Calculates median of all possible slope coefficients through two of the data points 50 // and median of offsets corresponding with the median slope 51 LineParameters theilSenLinearRegression(const std::vector<tcu::Vec2> &dataPoints); 52 53 struct LineParametersWithConfidence 54 { 55 float offset; 56 float offsetConfidenceUpper; 57 float offsetConfidenceLower; 58 59 float coefficient; 60 float coefficientConfidenceUpper; 61 float coefficientConfidenceLower; 62 63 float confidence; 64 }; 65 66 // Median-of-medians version of Theil-Sen estimate. Calculates median of medians of slopes through a point and all other points. 67 // Confidence interval is given as the range that contains the given fraction of all slopes/offsets 68 LineParametersWithConfidence theilSenSiegelLinearRegression(const std::vector<tcu::Vec2> &dataPoints, 69 float reportedConfidence); 70 71 struct MeasureState 72 { MeasureStatedeqp::gls::MeasureState73 MeasureState(void) : maxNumFrames(0), frameShortcutTime(std::numeric_limits<float>::infinity()), numDrawCalls(0) 74 { 75 } 76 77 void clear(void); 78 void start(int maxNumFrames, float frameShortcutTime, int numDrawCalls); 79 80 bool isDone(void) const; 81 uint64_t getTotalTime(void) const; 82 83 int maxNumFrames; 84 float frameShortcutTime; 85 int numDrawCalls; 86 std::vector<uint64_t> frameTimes; 87 }; 88 89 struct CalibrateIteration 90 { CalibrateIterationdeqp::gls::CalibrateIteration91 CalibrateIteration(int numDrawCalls_, float frameTime_) : numDrawCalls(numDrawCalls_), frameTime(frameTime_) 92 { 93 } 94 CalibrateIterationdeqp::gls::CalibrateIteration95 CalibrateIteration(void) : numDrawCalls(0), frameTime(0.0f) 96 { 97 } 98 99 int numDrawCalls; 100 float frameTime; 101 }; 102 103 struct CalibratorParameters 104 { CalibratorParametersdeqp::gls::CalibratorParameters105 CalibratorParameters( 106 int numInitialCalls_, 107 int maxCalibrateIterationFrames_, //!< Maximum (and default) number of frames per one calibrate iteration. 108 float 109 calibrateIterationShortcutThresholdMs_, //!< If the times of two consecutive frames exceed this, stop the iteration even if maxCalibrateIterationFrames isn't reached. 110 int maxCalibrateIterations_, float targetFrameTimeMs_, float frameTimeCapMs_, float targetMeasureDurationMs_) 111 : numInitialCalls(numInitialCalls_) 112 , maxCalibrateIterationFrames(maxCalibrateIterationFrames_) 113 , calibrateIterationShortcutThreshold(1000.0f * calibrateIterationShortcutThresholdMs_) 114 , maxCalibrateIterations(maxCalibrateIterations_) 115 , targetFrameTimeUs(1000.0f * targetFrameTimeMs_) 116 , frameTimeCapUs(1000.0f * frameTimeCapMs_) 117 , targetMeasureDurationUs(1000.0f * targetMeasureDurationMs_) 118 { 119 } 120 121 int numInitialCalls; 122 int maxCalibrateIterationFrames; 123 float calibrateIterationShortcutThreshold; 124 int maxCalibrateIterations; 125 float targetFrameTimeUs; 126 float frameTimeCapUs; 127 float targetMeasureDurationUs; 128 }; 129 130 class TheilSenCalibrator 131 { 132 public: 133 enum State 134 { 135 STATE_RECOMPUTE_PARAMS = 0, 136 STATE_MEASURE, 137 STATE_FINISHED, 138 139 STATE_LAST 140 }; 141 142 TheilSenCalibrator(void); 143 TheilSenCalibrator(const CalibratorParameters ¶ms); 144 ~TheilSenCalibrator(void); 145 146 void clear(void); 147 void clear(const CalibratorParameters ¶ms); 148 149 State getState(void) const; getCallCount(void) const150 int getCallCount(void) const 151 { 152 return m_measureState.numDrawCalls; 153 } 154 155 // Should be called when getState() returns STATE_RECOMPUTE_PARAMS 156 void recomputeParameters(void); 157 158 // Should be called when getState() returns STATE_MEASURE 159 void recordIteration(uint64_t frameTime); 160 getParameters(void) const161 const CalibratorParameters &getParameters(void) const 162 { 163 return m_params; 164 } getMeasureState(void) const165 const MeasureState &getMeasureState(void) const 166 { 167 return m_measureState; 168 } getCalibrationInfo(void) const169 const std::vector<CalibrateIteration> &getCalibrationInfo(void) const 170 { 171 return m_calibrateIterations; 172 } 173 174 private: 175 enum InternalState 176 { 177 INTERNALSTATE_CALIBRATING = 0, 178 INTERNALSTATE_RUNNING, 179 INTERNALSTATE_FINISHED, 180 181 INTERNALSTATE_LAST 182 }; 183 184 CalibratorParameters m_params; 185 186 InternalState m_state; 187 MeasureState m_measureState; 188 189 std::vector<CalibrateIteration> m_calibrateIterations; 190 }; 191 192 void logCalibrationInfo(tcu::TestLog &log, const TheilSenCalibrator &calibrator); 193 194 } // namespace gls 195 } // namespace deqp 196 197 #endif // _GLSCALIBRATION_HPP 198