1 #ifndef _GLSSHADERPERFORMANCEMEASURER_HPP 2 #define _GLSSHADERPERFORMANCEMEASURER_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 Shader performance measurer; handles calibration and measurement 24 *//*--------------------------------------------------------------------*/ 25 26 #include "tcuDefs.hpp" 27 #include "tcuTestCase.hpp" 28 #include "tcuVector.hpp" 29 #include "gluRenderContext.hpp" 30 #include "glsCalibration.hpp" 31 32 namespace deqp 33 { 34 namespace gls 35 { 36 37 enum PerfCaseType 38 { 39 CASETYPE_VERTEX = 0, 40 CASETYPE_FRAGMENT, 41 CASETYPE_BALANCED, 42 43 CASETYPE_LAST 44 }; 45 46 struct AttribSpec 47 { AttribSpecdeqp::gls::AttribSpec48 AttribSpec(const char *name_, const tcu::Vec4 &p00_, const tcu::Vec4 &p01_, const tcu::Vec4 &p10_, 49 const tcu::Vec4 &p11_) 50 : name(name_) 51 , p00(p00_) 52 , p01(p01_) 53 , p10(p10_) 54 , p11(p11_) 55 { 56 } 57 AttribSpecdeqp::gls::AttribSpec58 AttribSpec(void) 59 { 60 } 61 62 std::string name; 63 tcu::Vec4 p00; //!< Bottom left. 64 tcu::Vec4 p01; //!< Bottom right. 65 tcu::Vec4 p10; //!< Top left. 66 tcu::Vec4 p11; //!< Top right. 67 }; 68 69 class ShaderPerformanceMeasurer 70 { 71 public: 72 struct Result 73 { 74 float megaVertPerSec; 75 float megaFragPerSec; 76 Resultdeqp::gls::ShaderPerformanceMeasurer::Result77 Result(float megaVertPerSec_, float megaFragPerSec_) 78 : megaVertPerSec(megaVertPerSec_) 79 , megaFragPerSec(megaFragPerSec_) 80 { 81 } 82 }; 83 84 ShaderPerformanceMeasurer(const glu::RenderContext &renderCtx, PerfCaseType measureType); ~ShaderPerformanceMeasurer(void)85 ~ShaderPerformanceMeasurer(void) 86 { 87 deinit(); 88 } 89 90 void init(uint32_t program, const std::vector<AttribSpec> &attributes, int calibratorInitialNumCalls); 91 void deinit(void); 92 void iterate(void); 93 94 void logParameters(tcu::TestLog &log) const; isFinished(void) const95 bool isFinished(void) const 96 { 97 return m_state == STATE_FINISHED; 98 } getResult(void) const99 Result getResult(void) const 100 { 101 DE_ASSERT(m_state == STATE_FINISHED); 102 return m_result; 103 } 104 void logMeasurementInfo(tcu::TestLog &log) const; 105 106 void setGridSize(int gridW, int gridH); 107 void setViewportSize(int width, int height); 108 getGridWidth(void) const109 int getGridWidth(void) const 110 { 111 return m_gridSizeX; 112 } getGridHeight(void) const113 int getGridHeight(void) const 114 { 115 return m_gridSizeY; 116 } getViewportWidth(void) const117 int getViewportWidth(void) const 118 { 119 return m_viewportWidth; 120 } getViewportHeight(void) const121 int getViewportHeight(void) const 122 { 123 return m_viewportHeight; 124 } 125 getFinalCallCount(void) const126 int getFinalCallCount(void) const 127 { 128 DE_ASSERT(m_state == STATE_FINISHED); 129 return m_calibrator.getCallCount(); 130 } 131 132 private: 133 enum State 134 { 135 STATE_UNINITIALIZED = 0, 136 STATE_MEASURING, 137 STATE_FINISHED, 138 139 STATE_LAST 140 }; 141 142 void render(int numDrawCalls); 143 144 const glu::RenderContext &m_renderCtx; 145 int m_gridSizeX; 146 int m_gridSizeY; 147 int m_viewportWidth; 148 int m_viewportHeight; 149 150 State m_state; 151 bool m_isFirstIteration; 152 uint64_t m_prevRenderStartTime; 153 Result m_result; 154 TheilSenCalibrator m_calibrator; 155 uint32_t m_indexBuffer; 156 std::vector<AttribSpec> m_attributes; 157 std::vector<uint32_t> m_attribBuffers; 158 uint32_t m_vao; 159 }; 160 161 } // namespace gls 162 } // namespace deqp 163 164 #endif // _GLSSHADERPERFORMANCEMEASURER_HPP 165