xref: /aosp_15_r20/external/deqp/modules/glshared/glsShaderPerformanceCase.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL (ES) Module
3*35238bceSAndroid Build Coastguard Worker  * -----------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker  *
11*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker  *
19*35238bceSAndroid Build Coastguard Worker  *//*!
20*35238bceSAndroid Build Coastguard Worker  * \file
21*35238bceSAndroid Build Coastguard Worker  * \brief Single-program test case wrapper for ShaderPerformanceMeasurer.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "glsShaderPerformanceCase.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "deStringUtil.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "deMath.h"
28*35238bceSAndroid Build Coastguard Worker 
29*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
31*35238bceSAndroid Build Coastguard Worker 
32*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
33*35238bceSAndroid Build Coastguard Worker using tcu::Vec4;
34*35238bceSAndroid Build Coastguard Worker using namespace glw; // GL types
35*35238bceSAndroid Build Coastguard Worker 
36*35238bceSAndroid Build Coastguard Worker namespace deqp
37*35238bceSAndroid Build Coastguard Worker {
38*35238bceSAndroid Build Coastguard Worker namespace gls
39*35238bceSAndroid Build Coastguard Worker {
40*35238bceSAndroid Build Coastguard Worker 
ShaderPerformanceCase(tcu::TestContext & testCtx,glu::RenderContext & renderCtx,const char * name,const char * description,PerfCaseType caseType)41*35238bceSAndroid Build Coastguard Worker ShaderPerformanceCase::ShaderPerformanceCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx, const char *name,
42*35238bceSAndroid Build Coastguard Worker                                              const char *description, PerfCaseType caseType)
43*35238bceSAndroid Build Coastguard Worker     : tcu::TestCase(testCtx, tcu::NODETYPE_PERFORMANCE, name, description)
44*35238bceSAndroid Build Coastguard Worker     , m_renderCtx(renderCtx)
45*35238bceSAndroid Build Coastguard Worker     , m_caseType(caseType)
46*35238bceSAndroid Build Coastguard Worker     , m_program(DE_NULL)
47*35238bceSAndroid Build Coastguard Worker     , m_measurer(renderCtx, caseType)
48*35238bceSAndroid Build Coastguard Worker {
49*35238bceSAndroid Build Coastguard Worker }
50*35238bceSAndroid Build Coastguard Worker 
~ShaderPerformanceCase(void)51*35238bceSAndroid Build Coastguard Worker ShaderPerformanceCase::~ShaderPerformanceCase(void)
52*35238bceSAndroid Build Coastguard Worker {
53*35238bceSAndroid Build Coastguard Worker     ShaderPerformanceCase::deinit();
54*35238bceSAndroid Build Coastguard Worker }
55*35238bceSAndroid Build Coastguard Worker 
setGridSize(int gridW,int gridH)56*35238bceSAndroid Build Coastguard Worker void ShaderPerformanceCase::setGridSize(int gridW, int gridH)
57*35238bceSAndroid Build Coastguard Worker {
58*35238bceSAndroid Build Coastguard Worker     m_measurer.setGridSize(gridW, gridH);
59*35238bceSAndroid Build Coastguard Worker }
60*35238bceSAndroid Build Coastguard Worker 
setViewportSize(int width,int height)61*35238bceSAndroid Build Coastguard Worker void ShaderPerformanceCase::setViewportSize(int width, int height)
62*35238bceSAndroid Build Coastguard Worker {
63*35238bceSAndroid Build Coastguard Worker     m_measurer.setViewportSize(width, height);
64*35238bceSAndroid Build Coastguard Worker }
65*35238bceSAndroid Build Coastguard Worker 
setVertexFragmentRatio(float fragmentsPerVertices)66*35238bceSAndroid Build Coastguard Worker void ShaderPerformanceCase::setVertexFragmentRatio(float fragmentsPerVertices)
67*35238bceSAndroid Build Coastguard Worker {
68*35238bceSAndroid Build Coastguard Worker     const float eps = 0.01f;
69*35238bceSAndroid Build Coastguard Worker     int gridW       = 255;
70*35238bceSAndroid Build Coastguard Worker     int gridH       = 255;
71*35238bceSAndroid Build Coastguard Worker     int viewportW   = m_renderCtx.getRenderTarget().getWidth();
72*35238bceSAndroid Build Coastguard Worker     int viewportH   = m_renderCtx.getRenderTarget().getHeight();
73*35238bceSAndroid Build Coastguard Worker 
74*35238bceSAndroid Build Coastguard Worker     for (int i = 0; i < 10; i++)
75*35238bceSAndroid Build Coastguard Worker     {
76*35238bceSAndroid Build Coastguard Worker         int numVert = (gridW + 1) * (gridH + 1);
77*35238bceSAndroid Build Coastguard Worker         int numFrag = viewportW * viewportH;
78*35238bceSAndroid Build Coastguard Worker         float ratio = (float)numFrag / (float)numVert;
79*35238bceSAndroid Build Coastguard Worker 
80*35238bceSAndroid Build Coastguard Worker         if (de::abs(ratio - fragmentsPerVertices) < eps)
81*35238bceSAndroid Build Coastguard Worker             break;
82*35238bceSAndroid Build Coastguard Worker         else if (ratio < fragmentsPerVertices)
83*35238bceSAndroid Build Coastguard Worker         {
84*35238bceSAndroid Build Coastguard Worker             // Not enough fragments.
85*35238bceSAndroid Build Coastguard Worker             numVert = deRoundFloatToInt32((float)numFrag / fragmentsPerVertices);
86*35238bceSAndroid Build Coastguard Worker 
87*35238bceSAndroid Build Coastguard Worker             while ((gridW + 1) * (gridH + 1) > numVert)
88*35238bceSAndroid Build Coastguard Worker             {
89*35238bceSAndroid Build Coastguard Worker                 if (gridW > gridH)
90*35238bceSAndroid Build Coastguard Worker                     gridW -= 1;
91*35238bceSAndroid Build Coastguard Worker                 else
92*35238bceSAndroid Build Coastguard Worker                     gridH -= 1;
93*35238bceSAndroid Build Coastguard Worker             }
94*35238bceSAndroid Build Coastguard Worker         }
95*35238bceSAndroid Build Coastguard Worker         else
96*35238bceSAndroid Build Coastguard Worker         {
97*35238bceSAndroid Build Coastguard Worker             // Not enough vertices.
98*35238bceSAndroid Build Coastguard Worker             numFrag = deRoundFloatToInt32((float)numVert * fragmentsPerVertices);
99*35238bceSAndroid Build Coastguard Worker 
100*35238bceSAndroid Build Coastguard Worker             while (viewportW * viewportH > numFrag)
101*35238bceSAndroid Build Coastguard Worker             {
102*35238bceSAndroid Build Coastguard Worker                 if (viewportW > viewportH)
103*35238bceSAndroid Build Coastguard Worker                     viewportW -= 1;
104*35238bceSAndroid Build Coastguard Worker                 else
105*35238bceSAndroid Build Coastguard Worker                     viewportH -= 1;
106*35238bceSAndroid Build Coastguard Worker             }
107*35238bceSAndroid Build Coastguard Worker         }
108*35238bceSAndroid Build Coastguard Worker     }
109*35238bceSAndroid Build Coastguard Worker 
110*35238bceSAndroid Build Coastguard Worker     float finalRatio = (float)(viewportW * viewportH) / (float)((gridW + 1) * (gridH + 1));
111*35238bceSAndroid Build Coastguard Worker     m_testCtx.getLog() << TestLog::Message
112*35238bceSAndroid Build Coastguard Worker                        << "Requested fragment/vertex-ratio: " << de::floatToString(fragmentsPerVertices, 2) << "\n"
113*35238bceSAndroid Build Coastguard Worker                        << "Computed fragment/vertex-ratio: " << de::floatToString(finalRatio, 2) << TestLog::EndMessage;
114*35238bceSAndroid Build Coastguard Worker 
115*35238bceSAndroid Build Coastguard Worker     setGridSize(gridW, gridH);
116*35238bceSAndroid Build Coastguard Worker     setViewportSize(viewportW, viewportH);
117*35238bceSAndroid Build Coastguard Worker }
118*35238bceSAndroid Build Coastguard Worker 
logRenderTargetInfo(TestLog & log,const tcu::RenderTarget & renderTarget)119*35238bceSAndroid Build Coastguard Worker static void logRenderTargetInfo(TestLog &log, const tcu::RenderTarget &renderTarget)
120*35238bceSAndroid Build Coastguard Worker {
121*35238bceSAndroid Build Coastguard Worker     log << TestLog::Section("RenderTarget", "Render target") << TestLog::Message << "size: " << renderTarget.getWidth()
122*35238bceSAndroid Build Coastguard Worker         << "x" << renderTarget.getHeight() << TestLog::EndMessage << TestLog::Message << "bits:"
123*35238bceSAndroid Build Coastguard Worker         << " R" << renderTarget.getPixelFormat().redBits << " G" << renderTarget.getPixelFormat().greenBits << " B"
124*35238bceSAndroid Build Coastguard Worker         << renderTarget.getPixelFormat().blueBits << " A" << renderTarget.getPixelFormat().alphaBits << " D"
125*35238bceSAndroid Build Coastguard Worker         << renderTarget.getDepthBits() << " S" << renderTarget.getStencilBits() << TestLog::EndMessage;
126*35238bceSAndroid Build Coastguard Worker 
127*35238bceSAndroid Build Coastguard Worker     if (renderTarget.getNumSamples() != 0)
128*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << renderTarget.getNumSamples() << "x MSAA" << TestLog::EndMessage;
129*35238bceSAndroid Build Coastguard Worker     else
130*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "No MSAA" << TestLog::EndMessage;
131*35238bceSAndroid Build Coastguard Worker 
132*35238bceSAndroid Build Coastguard Worker     log << TestLog::EndSection;
133*35238bceSAndroid Build Coastguard Worker }
134*35238bceSAndroid Build Coastguard Worker 
init(void)135*35238bceSAndroid Build Coastguard Worker void ShaderPerformanceCase::init(void)
136*35238bceSAndroid Build Coastguard Worker {
137*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_testCtx.getLog();
138*35238bceSAndroid Build Coastguard Worker 
139*35238bceSAndroid Build Coastguard Worker     m_program = new glu::ShaderProgram(m_renderCtx, glu::makeVtxFragSources(m_vertShaderSource, m_fragShaderSource));
140*35238bceSAndroid Build Coastguard Worker 
141*35238bceSAndroid Build Coastguard Worker     if (m_program->isOk())
142*35238bceSAndroid Build Coastguard Worker     {
143*35238bceSAndroid Build Coastguard Worker         const int initialCallCount = m_initialCalibration ? m_initialCalibration->initialNumCalls : 1;
144*35238bceSAndroid Build Coastguard Worker         logRenderTargetInfo(log, m_renderCtx.getRenderTarget());
145*35238bceSAndroid Build Coastguard Worker         m_measurer.init(m_program->getProgram(), m_attributes, initialCallCount);
146*35238bceSAndroid Build Coastguard Worker         m_measurer.logParameters(log);
147*35238bceSAndroid Build Coastguard Worker         log << *m_program;
148*35238bceSAndroid Build Coastguard Worker     }
149*35238bceSAndroid Build Coastguard Worker     else
150*35238bceSAndroid Build Coastguard Worker     {
151*35238bceSAndroid Build Coastguard Worker         log << *m_program;
152*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Compile failed");
153*35238bceSAndroid Build Coastguard Worker         return; // Skip rest of init.
154*35238bceSAndroid Build Coastguard Worker     }
155*35238bceSAndroid Build Coastguard Worker 
156*35238bceSAndroid Build Coastguard Worker     setupProgram(m_program->getProgram());
157*35238bceSAndroid Build Coastguard Worker     setupRenderState();
158*35238bceSAndroid Build Coastguard Worker }
159*35238bceSAndroid Build Coastguard Worker 
deinit(void)160*35238bceSAndroid Build Coastguard Worker void ShaderPerformanceCase::deinit(void)
161*35238bceSAndroid Build Coastguard Worker {
162*35238bceSAndroid Build Coastguard Worker     delete m_program;
163*35238bceSAndroid Build Coastguard Worker     m_program = DE_NULL;
164*35238bceSAndroid Build Coastguard Worker 
165*35238bceSAndroid Build Coastguard Worker     m_measurer.deinit();
166*35238bceSAndroid Build Coastguard Worker }
167*35238bceSAndroid Build Coastguard Worker 
setupProgram(uint32_t program)168*35238bceSAndroid Build Coastguard Worker void ShaderPerformanceCase::setupProgram(uint32_t program)
169*35238bceSAndroid Build Coastguard Worker {
170*35238bceSAndroid Build Coastguard Worker     DE_UNREF(program);
171*35238bceSAndroid Build Coastguard Worker }
172*35238bceSAndroid Build Coastguard Worker 
setupRenderState(void)173*35238bceSAndroid Build Coastguard Worker void ShaderPerformanceCase::setupRenderState(void)
174*35238bceSAndroid Build Coastguard Worker {
175*35238bceSAndroid Build Coastguard Worker }
176*35238bceSAndroid Build Coastguard Worker 
iterate(void)177*35238bceSAndroid Build Coastguard Worker ShaderPerformanceCase::IterateResult ShaderPerformanceCase::iterate(void)
178*35238bceSAndroid Build Coastguard Worker {
179*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(m_program);
180*35238bceSAndroid Build Coastguard Worker 
181*35238bceSAndroid Build Coastguard Worker     if (!m_program->isOk()) // This happens when compilation failed in init().
182*35238bceSAndroid Build Coastguard Worker         return STOP;
183*35238bceSAndroid Build Coastguard Worker 
184*35238bceSAndroid Build Coastguard Worker     m_measurer.iterate();
185*35238bceSAndroid Build Coastguard Worker 
186*35238bceSAndroid Build Coastguard Worker     if (m_measurer.isFinished())
187*35238bceSAndroid Build Coastguard Worker     {
188*35238bceSAndroid Build Coastguard Worker         m_measurer.logMeasurementInfo(m_testCtx.getLog());
189*35238bceSAndroid Build Coastguard Worker 
190*35238bceSAndroid Build Coastguard Worker         if (m_initialCalibration)
191*35238bceSAndroid Build Coastguard Worker             m_initialCalibration->initialNumCalls = de::max(1, m_measurer.getFinalCallCount());
192*35238bceSAndroid Build Coastguard Worker 
193*35238bceSAndroid Build Coastguard Worker         const ShaderPerformanceMeasurer::Result result = m_measurer.getResult();
194*35238bceSAndroid Build Coastguard Worker         reportResult(result.megaVertPerSec, result.megaFragPerSec);
195*35238bceSAndroid Build Coastguard Worker         return STOP;
196*35238bceSAndroid Build Coastguard Worker     }
197*35238bceSAndroid Build Coastguard Worker     else
198*35238bceSAndroid Build Coastguard Worker         return CONTINUE;
199*35238bceSAndroid Build Coastguard Worker }
200*35238bceSAndroid Build Coastguard Worker 
reportResult(float mvertPerSecond,float mfragPerSecond)201*35238bceSAndroid Build Coastguard Worker void ShaderPerformanceCase::reportResult(float mvertPerSecond, float mfragPerSecond)
202*35238bceSAndroid Build Coastguard Worker {
203*35238bceSAndroid Build Coastguard Worker     float result = 0.0f;
204*35238bceSAndroid Build Coastguard Worker     switch (m_caseType)
205*35238bceSAndroid Build Coastguard Worker     {
206*35238bceSAndroid Build Coastguard Worker     case CASETYPE_VERTEX:
207*35238bceSAndroid Build Coastguard Worker         result = mvertPerSecond;
208*35238bceSAndroid Build Coastguard Worker         break;
209*35238bceSAndroid Build Coastguard Worker     case CASETYPE_FRAGMENT:
210*35238bceSAndroid Build Coastguard Worker         result = mfragPerSecond;
211*35238bceSAndroid Build Coastguard Worker         break;
212*35238bceSAndroid Build Coastguard Worker     case CASETYPE_BALANCED:
213*35238bceSAndroid Build Coastguard Worker         result = mfragPerSecond;
214*35238bceSAndroid Build Coastguard Worker         break;
215*35238bceSAndroid Build Coastguard Worker     default:
216*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(false);
217*35238bceSAndroid Build Coastguard Worker     }
218*35238bceSAndroid Build Coastguard Worker 
219*35238bceSAndroid Build Coastguard Worker     m_testCtx.setTestResult(QP_TEST_RESULT_PASS, de::floatToString(result, 2).c_str());
220*35238bceSAndroid Build Coastguard Worker }
221*35238bceSAndroid Build Coastguard Worker 
ShaderPerformanceCaseGroup(tcu::TestContext & testCtx,const char * name,const char * description)222*35238bceSAndroid Build Coastguard Worker ShaderPerformanceCaseGroup::ShaderPerformanceCaseGroup(tcu::TestContext &testCtx, const char *name,
223*35238bceSAndroid Build Coastguard Worker                                                        const char *description)
224*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(testCtx, name, description)
225*35238bceSAndroid Build Coastguard Worker     , m_initialCalibrationStorage(new ShaderPerformanceCase::InitialCalibration)
226*35238bceSAndroid Build Coastguard Worker {
227*35238bceSAndroid Build Coastguard Worker }
228*35238bceSAndroid Build Coastguard Worker 
addChild(ShaderPerformanceCase * perfCase)229*35238bceSAndroid Build Coastguard Worker void ShaderPerformanceCaseGroup::addChild(ShaderPerformanceCase *perfCase)
230*35238bceSAndroid Build Coastguard Worker {
231*35238bceSAndroid Build Coastguard Worker     perfCase->setCalibrationInitialParamStorage(m_initialCalibrationStorage);
232*35238bceSAndroid Build Coastguard Worker     TestCaseGroup::addChild(perfCase);
233*35238bceSAndroid Build Coastguard Worker }
234*35238bceSAndroid Build Coastguard Worker 
235*35238bceSAndroid Build Coastguard Worker } // namespace gls
236*35238bceSAndroid Build Coastguard Worker } // namespace deqp
237