xref: /aosp_15_r20/external/deqp/modules/glshared/glsShaderPerformanceMeasurer.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker #ifndef _GLSSHADERPERFORMANCEMEASURER_HPP
2*35238bceSAndroid Build Coastguard Worker #define _GLSSHADERPERFORMANCEMEASURER_HPP
3*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL (ES) Module
5*35238bceSAndroid Build Coastguard Worker  * -----------------------------------------------
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
8*35238bceSAndroid Build Coastguard Worker  *
9*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
10*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
11*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
14*35238bceSAndroid Build Coastguard Worker  *
15*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
16*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
17*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
19*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
20*35238bceSAndroid Build Coastguard Worker  *
21*35238bceSAndroid Build Coastguard Worker  *//*!
22*35238bceSAndroid Build Coastguard Worker  * \file
23*35238bceSAndroid Build Coastguard Worker  * \brief Shader performance measurer; handles calibration and measurement
24*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
25*35238bceSAndroid Build Coastguard Worker 
26*35238bceSAndroid Build Coastguard Worker #include "tcuDefs.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "tcuTestCase.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "tcuVector.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "gluRenderContext.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "glsCalibration.hpp"
31*35238bceSAndroid Build Coastguard Worker 
32*35238bceSAndroid Build Coastguard Worker namespace deqp
33*35238bceSAndroid Build Coastguard Worker {
34*35238bceSAndroid Build Coastguard Worker namespace gls
35*35238bceSAndroid Build Coastguard Worker {
36*35238bceSAndroid Build Coastguard Worker 
37*35238bceSAndroid Build Coastguard Worker enum PerfCaseType
38*35238bceSAndroid Build Coastguard Worker {
39*35238bceSAndroid Build Coastguard Worker     CASETYPE_VERTEX = 0,
40*35238bceSAndroid Build Coastguard Worker     CASETYPE_FRAGMENT,
41*35238bceSAndroid Build Coastguard Worker     CASETYPE_BALANCED,
42*35238bceSAndroid Build Coastguard Worker 
43*35238bceSAndroid Build Coastguard Worker     CASETYPE_LAST
44*35238bceSAndroid Build Coastguard Worker };
45*35238bceSAndroid Build Coastguard Worker 
46*35238bceSAndroid Build Coastguard Worker struct AttribSpec
47*35238bceSAndroid Build Coastguard Worker {
AttribSpecdeqp::gls::AttribSpec48*35238bceSAndroid Build Coastguard Worker     AttribSpec(const char *name_, const tcu::Vec4 &p00_, const tcu::Vec4 &p01_, const tcu::Vec4 &p10_,
49*35238bceSAndroid Build Coastguard Worker                const tcu::Vec4 &p11_)
50*35238bceSAndroid Build Coastguard Worker         : name(name_)
51*35238bceSAndroid Build Coastguard Worker         , p00(p00_)
52*35238bceSAndroid Build Coastguard Worker         , p01(p01_)
53*35238bceSAndroid Build Coastguard Worker         , p10(p10_)
54*35238bceSAndroid Build Coastguard Worker         , p11(p11_)
55*35238bceSAndroid Build Coastguard Worker     {
56*35238bceSAndroid Build Coastguard Worker     }
57*35238bceSAndroid Build Coastguard Worker 
AttribSpecdeqp::gls::AttribSpec58*35238bceSAndroid Build Coastguard Worker     AttribSpec(void)
59*35238bceSAndroid Build Coastguard Worker     {
60*35238bceSAndroid Build Coastguard Worker     }
61*35238bceSAndroid Build Coastguard Worker 
62*35238bceSAndroid Build Coastguard Worker     std::string name;
63*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 p00; //!< Bottom left.
64*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 p01; //!< Bottom right.
65*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 p10; //!< Top left.
66*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 p11; //!< Top right.
67*35238bceSAndroid Build Coastguard Worker };
68*35238bceSAndroid Build Coastguard Worker 
69*35238bceSAndroid Build Coastguard Worker class ShaderPerformanceMeasurer
70*35238bceSAndroid Build Coastguard Worker {
71*35238bceSAndroid Build Coastguard Worker public:
72*35238bceSAndroid Build Coastguard Worker     struct Result
73*35238bceSAndroid Build Coastguard Worker     {
74*35238bceSAndroid Build Coastguard Worker         float megaVertPerSec;
75*35238bceSAndroid Build Coastguard Worker         float megaFragPerSec;
76*35238bceSAndroid Build Coastguard Worker 
Resultdeqp::gls::ShaderPerformanceMeasurer::Result77*35238bceSAndroid Build Coastguard Worker         Result(float megaVertPerSec_, float megaFragPerSec_)
78*35238bceSAndroid Build Coastguard Worker             : megaVertPerSec(megaVertPerSec_)
79*35238bceSAndroid Build Coastguard Worker             , megaFragPerSec(megaFragPerSec_)
80*35238bceSAndroid Build Coastguard Worker         {
81*35238bceSAndroid Build Coastguard Worker         }
82*35238bceSAndroid Build Coastguard Worker     };
83*35238bceSAndroid Build Coastguard Worker 
84*35238bceSAndroid Build Coastguard Worker     ShaderPerformanceMeasurer(const glu::RenderContext &renderCtx, PerfCaseType measureType);
~ShaderPerformanceMeasurer(void)85*35238bceSAndroid Build Coastguard Worker     ~ShaderPerformanceMeasurer(void)
86*35238bceSAndroid Build Coastguard Worker     {
87*35238bceSAndroid Build Coastguard Worker         deinit();
88*35238bceSAndroid Build Coastguard Worker     }
89*35238bceSAndroid Build Coastguard Worker 
90*35238bceSAndroid Build Coastguard Worker     void init(uint32_t program, const std::vector<AttribSpec> &attributes, int calibratorInitialNumCalls);
91*35238bceSAndroid Build Coastguard Worker     void deinit(void);
92*35238bceSAndroid Build Coastguard Worker     void iterate(void);
93*35238bceSAndroid Build Coastguard Worker 
94*35238bceSAndroid Build Coastguard Worker     void logParameters(tcu::TestLog &log) const;
isFinished(void) const95*35238bceSAndroid Build Coastguard Worker     bool isFinished(void) const
96*35238bceSAndroid Build Coastguard Worker     {
97*35238bceSAndroid Build Coastguard Worker         return m_state == STATE_FINISHED;
98*35238bceSAndroid Build Coastguard Worker     }
getResult(void) const99*35238bceSAndroid Build Coastguard Worker     Result getResult(void) const
100*35238bceSAndroid Build Coastguard Worker     {
101*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(m_state == STATE_FINISHED);
102*35238bceSAndroid Build Coastguard Worker         return m_result;
103*35238bceSAndroid Build Coastguard Worker     }
104*35238bceSAndroid Build Coastguard Worker     void logMeasurementInfo(tcu::TestLog &log) const;
105*35238bceSAndroid Build Coastguard Worker 
106*35238bceSAndroid Build Coastguard Worker     void setGridSize(int gridW, int gridH);
107*35238bceSAndroid Build Coastguard Worker     void setViewportSize(int width, int height);
108*35238bceSAndroid Build Coastguard Worker 
getGridWidth(void) const109*35238bceSAndroid Build Coastguard Worker     int getGridWidth(void) const
110*35238bceSAndroid Build Coastguard Worker     {
111*35238bceSAndroid Build Coastguard Worker         return m_gridSizeX;
112*35238bceSAndroid Build Coastguard Worker     }
getGridHeight(void) const113*35238bceSAndroid Build Coastguard Worker     int getGridHeight(void) const
114*35238bceSAndroid Build Coastguard Worker     {
115*35238bceSAndroid Build Coastguard Worker         return m_gridSizeY;
116*35238bceSAndroid Build Coastguard Worker     }
getViewportWidth(void) const117*35238bceSAndroid Build Coastguard Worker     int getViewportWidth(void) const
118*35238bceSAndroid Build Coastguard Worker     {
119*35238bceSAndroid Build Coastguard Worker         return m_viewportWidth;
120*35238bceSAndroid Build Coastguard Worker     }
getViewportHeight(void) const121*35238bceSAndroid Build Coastguard Worker     int getViewportHeight(void) const
122*35238bceSAndroid Build Coastguard Worker     {
123*35238bceSAndroid Build Coastguard Worker         return m_viewportHeight;
124*35238bceSAndroid Build Coastguard Worker     }
125*35238bceSAndroid Build Coastguard Worker 
getFinalCallCount(void) const126*35238bceSAndroid Build Coastguard Worker     int getFinalCallCount(void) const
127*35238bceSAndroid Build Coastguard Worker     {
128*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(m_state == STATE_FINISHED);
129*35238bceSAndroid Build Coastguard Worker         return m_calibrator.getCallCount();
130*35238bceSAndroid Build Coastguard Worker     }
131*35238bceSAndroid Build Coastguard Worker 
132*35238bceSAndroid Build Coastguard Worker private:
133*35238bceSAndroid Build Coastguard Worker     enum State
134*35238bceSAndroid Build Coastguard Worker     {
135*35238bceSAndroid Build Coastguard Worker         STATE_UNINITIALIZED = 0,
136*35238bceSAndroid Build Coastguard Worker         STATE_MEASURING,
137*35238bceSAndroid Build Coastguard Worker         STATE_FINISHED,
138*35238bceSAndroid Build Coastguard Worker 
139*35238bceSAndroid Build Coastguard Worker         STATE_LAST
140*35238bceSAndroid Build Coastguard Worker     };
141*35238bceSAndroid Build Coastguard Worker 
142*35238bceSAndroid Build Coastguard Worker     void render(int numDrawCalls);
143*35238bceSAndroid Build Coastguard Worker 
144*35238bceSAndroid Build Coastguard Worker     const glu::RenderContext &m_renderCtx;
145*35238bceSAndroid Build Coastguard Worker     int m_gridSizeX;
146*35238bceSAndroid Build Coastguard Worker     int m_gridSizeY;
147*35238bceSAndroid Build Coastguard Worker     int m_viewportWidth;
148*35238bceSAndroid Build Coastguard Worker     int m_viewportHeight;
149*35238bceSAndroid Build Coastguard Worker 
150*35238bceSAndroid Build Coastguard Worker     State m_state;
151*35238bceSAndroid Build Coastguard Worker     bool m_isFirstIteration;
152*35238bceSAndroid Build Coastguard Worker     uint64_t m_prevRenderStartTime;
153*35238bceSAndroid Build Coastguard Worker     Result m_result;
154*35238bceSAndroid Build Coastguard Worker     TheilSenCalibrator m_calibrator;
155*35238bceSAndroid Build Coastguard Worker     uint32_t m_indexBuffer;
156*35238bceSAndroid Build Coastguard Worker     std::vector<AttribSpec> m_attributes;
157*35238bceSAndroid Build Coastguard Worker     std::vector<uint32_t> m_attribBuffers;
158*35238bceSAndroid Build Coastguard Worker     uint32_t m_vao;
159*35238bceSAndroid Build Coastguard Worker };
160*35238bceSAndroid Build Coastguard Worker 
161*35238bceSAndroid Build Coastguard Worker } // namespace gls
162*35238bceSAndroid Build Coastguard Worker } // namespace deqp
163*35238bceSAndroid Build Coastguard Worker 
164*35238bceSAndroid Build Coastguard Worker #endif // _GLSSHADERPERFORMANCEMEASURER_HPP
165