1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program EGL Module
3 * ---------------------------------------
5 * Copyright 2014 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief eglMakeCurrent performance tests.
22 *//*--------------------------------------------------------------------*/
24 #include "teglMakeCurrentPerfTests.hpp"
26 #include "egluNativeWindow.hpp"
27 #include "egluNativePixmap.hpp"
28 #include "egluUtil.hpp"
30 #include "eglwLibrary.hpp"
31 #include "eglwEnums.hpp"
33 #include "tcuTestLog.hpp"
35 #include "deRandom.hpp"
36 #include "deStringUtil.hpp"
48 using std::ostringstream;
61 class MakeCurrentPerfCase : public TestCase
66 SURFACETYPE_PBUFFER = (1<<0),
67 SURFACETYPE_WINDOW = (1<<1),
68 SURFACETYPE_PIXMAP = (1<<2)
73 SurfaceType surfaceTypes;
82 string toName (void) const;
83 string toDescription (void) const;
85 MakeCurrentPerfCase (EglTestContext& eglTestCtx, const Spec& spec, const char* name, const char* description);
86 ~MakeCurrentPerfCase (void);
90 IterateResult iterate (void);
98 vector<EGLContext> m_contexts;
99 vector<EGLSurface> m_surfaces;
101 vector<eglu::NativeWindow*> m_windows;
102 vector<eglu::NativePixmap*> m_pixmaps;
104 vector<deUint64> m_samples;
106 void chooseConfig (void);
107 void createSurfaces (void);
108 void createContexts (void);
110 void destroySurfaces (void);
111 void destroyContexts (void);
113 void createPBuffer (void);
114 void createWindow (void);
115 void createPixmap (void);
117 void logTestInfo (void);
118 void logResults (void);
120 MakeCurrentPerfCase (const MakeCurrentPerfCase&);
121 MakeCurrentPerfCase& operator= (const MakeCurrentPerfCase&);
124 string MakeCurrentPerfCase::Spec::toName (void) const
130 if (contextCount > 1)
131 name << "s_" << contextCount;
133 if ((surfaceTypes & SURFACETYPE_WINDOW) != 0)
134 name << "_window" << (surfaceCount > 1 ? "s" : "");
136 if ((surfaceTypes & SURFACETYPE_PIXMAP) != 0)
137 name << "_pixmap" << (surfaceCount > 1 ? "s" : "");
139 if ((surfaceTypes & SURFACETYPE_PBUFFER) != 0)
140 name << "_pbuffer" << (surfaceCount > 1 ? "s" : "");
142 if (surfaceCount > 1)
143 name << "_" << surfaceCount;
151 string MakeCurrentPerfCase::Spec::toDescription (void) const
153 // \todo [mika] Generate descrpition
157 MakeCurrentPerfCase::MakeCurrentPerfCase (EglTestContext& eglTestCtx, const Spec& spec, const char* name, const char* description)
158 : TestCase (eglTestCtx, tcu::NODETYPE_PERFORMANCE, name, description)
160 , m_rnd (deStringHash(name))
161 , m_display (EGL_NO_DISPLAY)
166 MakeCurrentPerfCase::~MakeCurrentPerfCase (void)
171 void MakeCurrentPerfCase::init (void)
173 m_display = eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
180 void MakeCurrentPerfCase::deinit (void)
185 if (m_display != EGL_NO_DISPLAY)
187 m_eglTestCtx.getLibrary().terminate(m_display);
188 m_display = EGL_NO_DISPLAY;
192 void MakeCurrentPerfCase::chooseConfig (void)
194 const EGLint surfaceBits = ((m_spec.surfaceTypes & SURFACETYPE_WINDOW) != 0 ? EGL_WINDOW_BIT : 0)
195 | ((m_spec.surfaceTypes & SURFACETYPE_PIXMAP) != 0 ? EGL_PIXMAP_BIT : 0)
196 | ((m_spec.surfaceTypes & SURFACETYPE_PBUFFER) != 0 ? EGL_PBUFFER_BIT : 0);
198 const EGLint attribList[] = {
199 EGL_SURFACE_TYPE, surfaceBits,
200 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
204 const Library& egl = m_eglTestCtx.getLibrary();
205 EGLint configCount = 0;
207 EGLU_CHECK_CALL(egl, chooseConfig(m_display, attribList, &m_config, 1, &configCount));
209 if (configCount <= 0)
210 throw tcu::NotSupportedError("No compatible configs found");
213 void MakeCurrentPerfCase::createSurfaces (void)
215 vector<SurfaceType> types;
217 if ((m_spec.surfaceTypes & SURFACETYPE_WINDOW) != 0)
218 types.push_back(SURFACETYPE_WINDOW);
220 if ((m_spec.surfaceTypes & SURFACETYPE_PIXMAP) != 0)
221 types.push_back(SURFACETYPE_PIXMAP);
223 if ((m_spec.surfaceTypes & SURFACETYPE_PBUFFER) != 0)
224 types.push_back(SURFACETYPE_PBUFFER);
226 DE_ASSERT((int)types.size() <= m_spec.surfaceCount);
229 for (int surfaceNdx = 0; surfaceNdx < m_spec.surfaceCount; surfaceNdx++)
231 SurfaceType type = types[surfaceNdx % types.size()];
235 case SURFACETYPE_PBUFFER:
239 case SURFACETYPE_WINDOW:
243 case SURFACETYPE_PIXMAP:
253 void MakeCurrentPerfCase::createPBuffer (void)
255 const Library& egl = m_eglTestCtx.getLibrary();
256 const EGLint width = 256;
257 const EGLint height = 256;
259 const EGLint attribList[] = {
265 EGLSurface surface = egl.createPbufferSurface(m_display, m_config, attribList);
267 EGLU_CHECK_MSG(egl, "eglCreatePbufferSurface()");
269 m_surfaces.push_back(surface);
272 void MakeCurrentPerfCase::createWindow (void)
274 const Library& egl = m_eglTestCtx.getLibrary();
275 const EGLint width = 256;
276 const EGLint height = 256;
278 const eglu::NativeWindowFactory& windowFactory = eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
280 eglu::NativeWindow* window = DE_NULL;
281 EGLSurface surface = EGL_NO_SURFACE;
285 window = windowFactory.createWindow(&m_eglTestCtx.getNativeDisplay(), m_display, m_config, DE_NULL, eglu::WindowParams(width, height, eglu::parseWindowVisibility(m_eglTestCtx.getTestContext().getCommandLine())));
286 surface = eglu::createWindowSurface(m_eglTestCtx.getNativeDisplay(), *window, m_display, m_config, DE_NULL);
290 if (surface != EGL_NO_SURFACE)
291 egl.destroySurface(m_display, surface);
297 m_windows.push_back(window);
298 m_surfaces.push_back(surface);
301 void MakeCurrentPerfCase::createPixmap (void)
303 const Library& egl = m_eglTestCtx.getLibrary();
304 const EGLint width = 256;
305 const EGLint height = 256;
307 const eglu::NativePixmapFactory& pixmapFactory = eglu::selectNativePixmapFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
309 eglu::NativePixmap* pixmap = DE_NULL;
310 EGLSurface surface = EGL_NO_SURFACE;
314 pixmap = pixmapFactory.createPixmap(&m_eglTestCtx.getNativeDisplay(), m_display, m_config, DE_NULL, width, height);
315 surface = eglu::createPixmapSurface(m_eglTestCtx.getNativeDisplay(), *pixmap, m_display, m_config, DE_NULL);
319 if (surface != EGL_NO_SURFACE)
320 egl.destroySurface(m_display, surface);
326 m_pixmaps.push_back(pixmap);
327 m_surfaces.push_back(surface);
330 void MakeCurrentPerfCase::destroySurfaces (void)
332 const Library& egl = m_eglTestCtx.getLibrary();
334 if (m_surfaces.size() > 0)
336 EGLDisplay display = m_display;
339 for (vector<EGLSurface>::iterator iter = m_surfaces.begin(); iter != m_surfaces.end(); ++iter)
341 if (*iter != EGL_NO_SURFACE)
342 EGLU_CHECK_CALL(egl, destroySurface(display, *iter));
343 *iter = EGL_NO_SURFACE;
349 for (vector<eglu::NativePixmap*>::iterator iter = m_pixmaps.begin(); iter != m_pixmaps.end(); ++iter)
358 for (vector<eglu::NativeWindow*>::iterator iter = m_windows.begin(); iter != m_windows.end(); ++iter)
366 // Clear all surface handles
371 void MakeCurrentPerfCase::createContexts (void)
373 const Library& egl = m_eglTestCtx.getLibrary();
375 for (int contextNdx = 0; contextNdx < m_spec.contextCount; contextNdx++)
377 const EGLint attribList[] = {
378 EGL_CONTEXT_CLIENT_VERSION, 2,
382 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
383 EGLContext context = egl.createContext(m_display, m_config, EGL_NO_CONTEXT, attribList);
384 EGLU_CHECK_MSG(egl, "eglCreateContext()");
386 m_contexts.push_back(context);
390 void MakeCurrentPerfCase::destroyContexts (void)
392 const Library& egl = m_eglTestCtx.getLibrary();
393 if (m_contexts.size() > 0)
395 EGLDisplay display = m_display;
397 for (vector<EGLContext>::iterator iter = m_contexts.begin(); iter != m_contexts.end(); ++iter)
399 if (*iter != EGL_NO_CONTEXT)
400 EGLU_CHECK_CALL(egl, destroyContext(display, *iter));
401 *iter = EGL_NO_CONTEXT;
408 void MakeCurrentPerfCase::logTestInfo (void)
410 TestLog& log = m_testCtx.getLog();
413 tcu::ScopedLogSection section(log, "Test Info", "Test case information.");
415 log << TestLog::Message << "Context count: " << m_contexts.size() << TestLog::EndMessage;
416 log << TestLog::Message << "Surfaces count: " << m_surfaces.size() << TestLog::EndMessage;
417 log << TestLog::Message << "Sample count: " << m_spec.sampleCount << TestLog::EndMessage;
418 log << TestLog::Message << "Iteration count: " << m_spec.iterationCount << TestLog::EndMessage;
419 log << TestLog::Message << "Window count: " << m_windows.size() << TestLog::EndMessage;
420 log << TestLog::Message << "Pixmap count: " << m_pixmaps.size() << TestLog::EndMessage;
421 log << TestLog::Message << "PBuffer count: " << (m_surfaces.size() - m_windows.size() - m_pixmaps.size()) << TestLog::EndMessage;
424 log << TestLog::Message << "Context is released after each use. Both binding and releasing context are included in result time." << TestLog::EndMessage;
428 void MakeCurrentPerfCase::logResults (void)
430 TestLog& log = m_testCtx.getLog();
432 log << TestLog::SampleList("Result", "Result")
433 << TestLog::SampleInfo << TestLog::ValueInfo("Time", "Time", "us", QP_SAMPLE_VALUE_TAG_RESPONSE)
434 << TestLog::EndSampleInfo;
436 for (int sampleNdx = 0; sampleNdx < (int)m_samples.size(); sampleNdx++)
437 log << TestLog::Sample << deInt64(m_samples[sampleNdx]) << TestLog::EndSample;
439 log << TestLog::EndSampleList;
443 deUint64 totalTimeUs = 0;
444 deUint64 totalIterationCount = 0;
446 float iterationTimeMeanUs = 0.0f;
447 float iterationTimeMedianUs = 0.0f;
448 float iterationTimeVarianceUs = 0.0f;
449 float iterationTimeSkewnessUs = 0.0f;
450 float iterationTimeMinUs = std::numeric_limits<float>::max();
451 float iterationTimeMaxUs = 0.0f;
453 std::sort(m_samples.begin(), m_samples.end());
456 for (int sampleNdx = 0; sampleNdx < (int)m_samples.size(); sampleNdx++)
458 totalTimeUs += m_samples[sampleNdx];
459 totalIterationCount += m_spec.iterationCount;
462 // Calculate mean and median
463 iterationTimeMeanUs = ((float)(((double)totalTimeUs) / (double)totalIterationCount));
464 iterationTimeMedianUs = ((float)(((double)m_samples[m_samples.size() / 2]) / (double)m_spec.iterationCount));
466 // Calculate variance
467 for (int sampleNdx = 0; sampleNdx < (int)m_samples.size(); sampleNdx++)
469 float iterationTimeUs = (float)(((double)m_samples[sampleNdx]) / m_spec.iterationCount);
470 iterationTimeVarianceUs += std::pow(iterationTimeUs - iterationTimeMedianUs, 2.0f);
473 // Calculate min and max
474 for (int sampleNdx = 0; sampleNdx < (int)m_samples.size(); sampleNdx++)
476 float iterationTimeUs = (float)(((double)m_samples[sampleNdx]) / m_spec.iterationCount);
477 iterationTimeMinUs = std::min<float>(iterationTimeMinUs, iterationTimeUs);
478 iterationTimeMaxUs = std::max<float>(iterationTimeMaxUs, iterationTimeUs);
481 iterationTimeVarianceUs /= (float)m_samples.size();
483 // Calculate skewness
484 for (int sampleNdx = 0; sampleNdx < (int)m_samples.size(); sampleNdx++)
486 float iterationTimeUs = (float)(((double)m_samples[sampleNdx]) / m_spec.iterationCount);
487 iterationTimeSkewnessUs = std::pow((iterationTimeUs - iterationTimeMedianUs) / iterationTimeVarianceUs, 2.0f);
490 iterationTimeSkewnessUs /= (float)m_samples.size();
493 tcu::ScopedLogSection section(log, "Result", "Statistics from results.");
495 log << TestLog::Message << "Total time: " << totalTimeUs << "us" << TestLog::EndMessage;
496 log << TestLog::Message << "Mean: " << iterationTimeMeanUs << "us" << TestLog::EndMessage;
497 log << TestLog::Message << "Median: " << iterationTimeMedianUs << "us" << TestLog::EndMessage;
498 log << TestLog::Message << "Variance: " << iterationTimeVarianceUs << "us" << TestLog::EndMessage;
499 log << TestLog::Message << "Skewness: " << iterationTimeSkewnessUs << "us" << TestLog::EndMessage;
500 log << TestLog::Message << "Min: " << iterationTimeMinUs << "us" << TestLog::EndMessage;
501 log << TestLog::Message << "Max: " << iterationTimeMaxUs << "us" << TestLog::EndMessage;
504 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, de::floatToString((float)(((double)totalTimeUs)/(double)totalIterationCount), 2).c_str());
508 TestCase::IterateResult MakeCurrentPerfCase::iterate (void)
510 const Library& egl = m_eglTestCtx.getLibrary();
511 if (m_samples.size() == 0)
515 EGLDisplay display = m_display;
516 deUint64 beginTimeUs = deGetMicroseconds();
518 for (int iteration = 0; iteration < m_spec.iterationCount; iteration++)
520 EGLContext context = m_contexts[m_rnd.getUint32() % m_contexts.size()];
521 EGLSurface surface = m_surfaces[m_rnd.getUint32() % m_surfaces.size()];
523 egl.makeCurrent(display, surface, surface, context);
526 egl.makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
529 m_samples.push_back(deGetMicroseconds() - beginTimeUs);
531 egl.makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
532 EGLU_CHECK_MSG(egl, "eglMakeCurrent()");
535 if ((int)m_samples.size() == m_spec.sampleCount)
544 MakeCurrentPerfTests::MakeCurrentPerfTests (EglTestContext& eglTestCtx)
545 : TestCaseGroup(eglTestCtx, "make_current", "eglMakeCurrent performance tests")
549 void MakeCurrentPerfTests::init (void)
551 const int iterationCount = 100;
552 const int sampleCount = 100;
554 // Add simple test group
556 TestCaseGroup* simple = new TestCaseGroup(m_eglTestCtx, "simple", "Simple eglMakeCurrent performance tests using single context and surface");
558 const MakeCurrentPerfCase::SurfaceType types[] = {
559 MakeCurrentPerfCase::SURFACETYPE_PBUFFER,
560 MakeCurrentPerfCase::SURFACETYPE_PIXMAP,
561 MakeCurrentPerfCase::SURFACETYPE_WINDOW
564 for (int typeNdx = 0; typeNdx < DE_LENGTH_OF_ARRAY(types); typeNdx++)
566 for (int releaseNdx = 0; releaseNdx < 2; releaseNdx++)
568 MakeCurrentPerfCase::Spec spec;
570 spec.surfaceTypes = types[typeNdx];
571 spec.contextCount = 1;
572 spec.surfaceCount = 1;
573 spec.release = (releaseNdx == 1);
574 spec.iterationCount = iterationCount;
575 spec.sampleCount = sampleCount;
577 simple->addChild(new MakeCurrentPerfCase(m_eglTestCtx, spec, spec.toName().c_str(), spec.toDescription().c_str()));
584 // Add multi context test group
586 TestCaseGroup* multiContext = new TestCaseGroup(m_eglTestCtx, "multi_context", "eglMakeCurrent performance tests using multiple contexts and single surface");
588 const MakeCurrentPerfCase::SurfaceType types[] = {
589 MakeCurrentPerfCase::SURFACETYPE_PBUFFER,
590 MakeCurrentPerfCase::SURFACETYPE_PIXMAP,
591 MakeCurrentPerfCase::SURFACETYPE_WINDOW
594 const int contextCounts[] = {
598 for (int contextCountNdx = 0; contextCountNdx < DE_LENGTH_OF_ARRAY(contextCounts); contextCountNdx++)
600 for (int typeNdx = 0; typeNdx < DE_LENGTH_OF_ARRAY(types); typeNdx++)
602 for (int releaseNdx = 0; releaseNdx < 2; releaseNdx++)
604 MakeCurrentPerfCase::Spec spec;
606 spec.surfaceTypes = types[typeNdx];
607 spec.contextCount = contextCounts[contextCountNdx];
608 spec.surfaceCount = 1;
609 spec.release = (releaseNdx == 1);
610 spec.iterationCount = iterationCount;
611 spec.sampleCount = sampleCount;
613 multiContext->addChild(new MakeCurrentPerfCase(m_eglTestCtx, spec, spec.toName().c_str(), spec.toDescription().c_str()));
618 addChild(multiContext);
621 // Add multi surface test group
623 TestCaseGroup* multiSurface = new TestCaseGroup(m_eglTestCtx, "multi_surface", "eglMakeCurrent performance tests using single context and multiple surfaces");
625 const MakeCurrentPerfCase::SurfaceType types[] = {
626 MakeCurrentPerfCase::SURFACETYPE_PBUFFER,
627 MakeCurrentPerfCase::SURFACETYPE_PIXMAP,
628 MakeCurrentPerfCase::SURFACETYPE_WINDOW,
630 (MakeCurrentPerfCase::SurfaceType)(MakeCurrentPerfCase::SURFACETYPE_PBUFFER |MakeCurrentPerfCase::SURFACETYPE_PIXMAP),
631 (MakeCurrentPerfCase::SurfaceType)(MakeCurrentPerfCase::SURFACETYPE_PBUFFER |MakeCurrentPerfCase::SURFACETYPE_WINDOW),
632 (MakeCurrentPerfCase::SurfaceType)(MakeCurrentPerfCase::SURFACETYPE_PIXMAP |MakeCurrentPerfCase::SURFACETYPE_WINDOW),
634 (MakeCurrentPerfCase::SurfaceType)(MakeCurrentPerfCase::SURFACETYPE_PBUFFER|MakeCurrentPerfCase::SURFACETYPE_PIXMAP|MakeCurrentPerfCase::SURFACETYPE_WINDOW)
637 const int surfaceCounts[] = {
641 for (int surfaceCountNdx = 0; surfaceCountNdx < DE_LENGTH_OF_ARRAY(surfaceCounts); surfaceCountNdx++)
643 for (int typeNdx = 0; typeNdx < DE_LENGTH_OF_ARRAY(types); typeNdx++)
645 for (int releaseNdx = 0; releaseNdx < 2; releaseNdx++)
647 MakeCurrentPerfCase::Spec spec;
649 spec.surfaceTypes = types[typeNdx];
650 spec.surfaceCount = surfaceCounts[surfaceCountNdx];
651 spec.contextCount = 1;
652 spec.release = (releaseNdx == 1);
653 spec.iterationCount = iterationCount;
654 spec.sampleCount = sampleCount;
656 multiSurface->addChild(new MakeCurrentPerfCase(m_eglTestCtx, spec, spec.toName().c_str(), spec.toDescription().c_str()));
661 addChild(multiSurface);
664 // Add Complex? test group
666 TestCaseGroup* multi = new TestCaseGroup(m_eglTestCtx, "complex", "eglMakeCurrent performance tests using multiple contexts and multiple surfaces");
668 const MakeCurrentPerfCase::SurfaceType types[] = {
669 MakeCurrentPerfCase::SURFACETYPE_PBUFFER,
670 MakeCurrentPerfCase::SURFACETYPE_PIXMAP,
671 MakeCurrentPerfCase::SURFACETYPE_WINDOW,
673 (MakeCurrentPerfCase::SurfaceType)(MakeCurrentPerfCase::SURFACETYPE_PBUFFER |MakeCurrentPerfCase::SURFACETYPE_PIXMAP),
674 (MakeCurrentPerfCase::SurfaceType)(MakeCurrentPerfCase::SURFACETYPE_PBUFFER |MakeCurrentPerfCase::SURFACETYPE_WINDOW),
675 (MakeCurrentPerfCase::SurfaceType)(MakeCurrentPerfCase::SURFACETYPE_PIXMAP |MakeCurrentPerfCase::SURFACETYPE_WINDOW),
677 (MakeCurrentPerfCase::SurfaceType)(MakeCurrentPerfCase::SURFACETYPE_PBUFFER|MakeCurrentPerfCase::SURFACETYPE_PIXMAP|MakeCurrentPerfCase::SURFACETYPE_WINDOW)
680 const int surfaceCounts[] = {
685 const int contextCounts[] = {
689 for (int surfaceCountNdx = 0; surfaceCountNdx < DE_LENGTH_OF_ARRAY(surfaceCounts); surfaceCountNdx++)
691 for (int contextCountNdx = 0; contextCountNdx < DE_LENGTH_OF_ARRAY(contextCounts); contextCountNdx++)
693 for (int typeNdx = 0; typeNdx < DE_LENGTH_OF_ARRAY(types); typeNdx++)
695 for (int releaseNdx = 0; releaseNdx < 2; releaseNdx++)
697 MakeCurrentPerfCase::Spec spec;
699 spec.surfaceTypes = types[typeNdx];
700 spec.contextCount = contextCounts[contextCountNdx];
701 spec.surfaceCount = surfaceCounts[surfaceCountNdx];
702 spec.release = (releaseNdx == 1);
703 spec.iterationCount = iterationCount;
704 spec.sampleCount = sampleCount;
706 multi->addChild(new MakeCurrentPerfCase(m_eglTestCtx, spec, spec.toName().c_str(), spec.toDescription().c_str()));