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_, const tcu::Vec4& p11_)
49 		: name		(name_)
50 		, p00		(p00_)
51 		, p01		(p01_)
52 		, p10		(p10_)
53 		, p11		(p11_)
54 	{
55 	}
56 
AttribSpecdeqp::gls::AttribSpec57 	AttribSpec (void) {}
58 
59 	std::string		name;
60 	tcu::Vec4		p00;	//!< Bottom left.
61 	tcu::Vec4		p01;	//!< Bottom right.
62 	tcu::Vec4		p10;	//!< Top left.
63 	tcu::Vec4		p11;	//!< Top right.
64 };
65 
66 class ShaderPerformanceMeasurer
67 {
68 public:
69 	struct Result
70 	{
71 		float megaVertPerSec;
72 		float megaFragPerSec;
73 
Resultdeqp::gls::ShaderPerformanceMeasurer::Result74 		Result (float megaVertPerSec_, float megaFragPerSec_) : megaVertPerSec(megaVertPerSec_), megaFragPerSec(megaFragPerSec_) {}
75 	};
76 
77 										ShaderPerformanceMeasurer	(const glu::RenderContext& renderCtx, PerfCaseType measureType);
~ShaderPerformanceMeasurer(void)78 										~ShaderPerformanceMeasurer	(void) { deinit(); }
79 
80 	void								init						(deUint32 program, const std::vector<AttribSpec>& attributes, int calibratorInitialNumCalls);
81 	void								deinit						(void);
82 	void								iterate						(void);
83 
84 	void								logParameters				(tcu::TestLog& log)		const;
isFinished(void) const85 	bool								isFinished					(void)					const { return m_state == STATE_FINISHED; }
getResult(void) const86 	Result								getResult					(void)					const { DE_ASSERT(m_state == STATE_FINISHED); return m_result; }
87 	void								logMeasurementInfo			(tcu::TestLog& log)		const;
88 
89 	void								setGridSize					(int gridW, int gridH);
90 	void								setViewportSize				(int width, int height);
91 
getGridWidth(void) const92 	int									getGridWidth				(void) const { return m_gridSizeX;		}
getGridHeight(void) const93 	int									getGridHeight				(void) const { return m_gridSizeY;		}
getViewportWidth(void) const94 	int									getViewportWidth			(void) const { return m_viewportWidth;	}
getViewportHeight(void) const95 	int									getViewportHeight			(void) const { return m_viewportHeight;	}
96 
getFinalCallCount(void) const97 	int									getFinalCallCount			(void) const { DE_ASSERT(m_state == STATE_FINISHED); return m_calibrator.getCallCount(); }
98 
99 private:
100 	enum State
101 	{
102 		STATE_UNINITIALIZED = 0,
103 		STATE_MEASURING,
104 		STATE_FINISHED,
105 
106 		STATE_LAST
107 	};
108 
109 	void								render						(int numDrawCalls);
110 
111 	const glu::RenderContext&			m_renderCtx;
112 	int									m_gridSizeX;
113 	int									m_gridSizeY;
114 	int									m_viewportWidth;
115 	int									m_viewportHeight;
116 
117 	State								m_state;
118 	bool								m_isFirstIteration;
119 	deUint64							m_prevRenderStartTime;
120 	Result								m_result;
121 	TheilSenCalibrator					m_calibrator;
122 	deUint32							m_indexBuffer;
123 	std::vector<AttribSpec>				m_attributes;
124 	std::vector<deUint32>				m_attribBuffers;
125 	deUint32							m_vao;
126 };
127 
128 } // gls
129 } // deqp
130 
131 #endif // _GLSSHADERPERFORMANCEMEASURER_HPP
132