1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program EGL Module
3 * ---------------------------------------
5 * Copyright 2017 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 Test the EGL_ANDROID_get_frame_timestamps extension.
22 *//*--------------------------------------------------------------------*/
24 #include "teglGetFrameTimestampsTests.hpp"
26 #include "teglSimpleConfigCase.hpp"
28 #include "egluNativeWindow.hpp"
29 #include "egluUtil.hpp"
30 #include "egluUnique.hpp"
31 #include "eglwLibrary.hpp"
32 #include "eglwEnums.hpp"
34 #include "gluDefs.hpp"
35 #include "glwEnums.hpp"
36 #include "glwFunctions.hpp"
38 #include "tcuResultCollector.hpp"
39 #include "tcuTestLog.hpp"
40 #include "tcuSurface.hpp"
41 #include "tcuTexture.hpp"
42 #include "tcuTextureUtil.hpp"
43 #include "tcuImageCompare.hpp"
44 #include "tcuVector.hpp"
45 #include "tcuVectorUtil.hpp"
49 #include "deUniquePtr.hpp"
50 #include "deStringUtil.hpp"
51 #include "deThread.hpp"
58 // Tentative EGL header definitions for EGL_ANDROID_get_Frame_timestamps.
59 // \todo [2017-01-25 brianderson] Remove once defined in the official headers.
60 #define EGL_TIMESTAMPS_ANDROID 0x3430
61 #define EGL_COMPOSITE_DEADLINE_ANDROID 0x3431
62 #define EGL_COMPOSITE_INTERVAL_ANDROID 0x3432
63 #define EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID 0x3433
64 #define EGL_REQUESTED_PRESENT_TIME_ANDROID 0x3434
65 #define EGL_RENDERING_COMPLETE_TIME_ANDROID 0x3435
66 #define EGL_COMPOSITION_LATCH_TIME_ANDROID 0x3436
67 #define EGL_FIRST_COMPOSITION_START_TIME_ANDROID 0x3437
68 #define EGL_LAST_COMPOSITION_START_TIME_ANDROID 0x3438
69 #define EGL_FIRST_COMPOSITION_GPU_FINISHED_TIME_ANDROID 0x3439
70 #define EGL_DISPLAY_PRESENT_TIME_ANDROID 0x343A
71 #define EGL_DEQUEUE_READY_TIME_ANDROID 0x343B
72 #define EGL_READS_DONE_TIME_ANDROID 0x343C
73 typedef deInt64 EGLnsecsANDROID;
74 typedef deUint64 EGLuint64KHR;
75 #define EGL_TIMESTAMP_PENDING_ANDROID (-2)
76 #define EGL_TIMESTAMP_INVALID_ANDROID (-1)
77 typedef EGLW_APICALL eglw::EGLBoolean (EGLW_APIENTRY* eglGetNextFrameIdANDROIDFunc) (eglw::EGLDisplay dpy, eglw::EGLSurface surface, EGLuint64KHR *frameId);
78 typedef EGLW_APICALL eglw::EGLBoolean (EGLW_APIENTRY* eglGetCompositorTimingANDROIDFunc) (eglw::EGLDisplay dpy, eglw::EGLSurface surface, eglw::EGLint numTimestamps, const eglw::EGLint *names, EGLnsecsANDROID *values);
79 typedef EGLW_APICALL eglw::EGLBoolean (EGLW_APIENTRY* eglGetCompositorTimingSupportedANDROIDFunc) (eglw::EGLDisplay dpy, eglw::EGLSurface surface, eglw::EGLint name);
80 typedef EGLW_APICALL eglw::EGLBoolean (EGLW_APIENTRY* eglGetFrameTimestampsANDROIDFunc) (eglw::EGLDisplay dpy, eglw::EGLSurface surface, EGLuint64KHR frameId, eglw::EGLint numTimestamps, const eglw::EGLint *timestamps, EGLnsecsANDROID *values);
81 typedef EGLW_APICALL eglw::EGLBoolean (EGLW_APIENTRY* eglGetFrameTimestampSupportedANDROIDFunc) (eglw::EGLDisplay dpy, eglw::EGLSurface surface, eglw::EGLint timestamp);
83 #define CHECK_NAKED_EGL_CALL(EGLW, CALL) do { CALL; eglu::checkError((EGLW).getError(), #CALL, __FILE__, __LINE__); } while (deGetFalse())
98 // Careful: This has microsecond precision, which can cause timestamps to
99 // appear non monotonic when compared to the nanosecond precision timestamps
100 // we get from the eglGetFrameTimestamps extension.
101 // Current test expectations only make sure microsecond precision timestamps
102 // are less than the nanosecond precision timestamps, so this is okay.
103 EGLnsecsANDROID getNanoseconds (void)
105 return deGetMicroseconds() * 1000;
112 , swapBufferBeginNs (-1)
113 , compositeDeadline (-1)
114 , compositeInterval (-1)
115 , compositeToPresentLatency (-1)
116 , requestedPresent (-1)
118 , firstCompositionStart (-1)
119 , lastCompositionStart (-1)
121 , renderingComplete (-1)
122 , firstCompositionGpuFinished (-1)
123 , displayPresent (-1)
128 EGLuint64KHR frameId;
130 // Timestamps sampled by the test.
131 EGLnsecsANDROID swapBufferBeginNs;
134 EGLnsecsANDROID compositeDeadline;
135 EGLnsecsANDROID compositeInterval;
136 EGLnsecsANDROID compositeToPresentLatency;
139 EGLnsecsANDROID requestedPresent;
140 EGLnsecsANDROID latch;
141 EGLnsecsANDROID firstCompositionStart;
142 EGLnsecsANDROID lastCompositionStart;
143 EGLnsecsANDROID dequeueReady;
146 EGLnsecsANDROID renderingComplete;
147 EGLnsecsANDROID firstCompositionGpuFinished;
148 EGLnsecsANDROID displayPresent;
149 EGLnsecsANDROID readsDone;
162 TimestampInfo(bool required_, bool supported_, size_t supportedIndex_)
163 : required(required_)
164 , supported(supported_)
165 , supportedIndex(supportedIndex_)
171 size_t supportedIndex;
174 typedef std::map<eglw::EGLint, TimestampInfo> TimestampInfoMap;
176 EGLnsecsANDROID getTimestamp(eglw::EGLint name, TimestampInfoMap& map, const std::vector<EGLnsecsANDROID>& supportedValues)
178 TimestampInfo& info = map[name];
179 return info.supported ? supportedValues[info.supportedIndex] : EGL_TIMESTAMP_INVALID_ANDROID;
182 void populateFrameTimes(FrameTimes* frameTimes, TimestampInfoMap& map, const std::vector<EGLnsecsANDROID>& supportedValues)
184 frameTimes->requestedPresent = getTimestamp(EGL_REQUESTED_PRESENT_TIME_ANDROID, map, supportedValues);
185 frameTimes->renderingComplete = getTimestamp(EGL_RENDERING_COMPLETE_TIME_ANDROID, map, supportedValues);
186 frameTimes->latch = getTimestamp(EGL_COMPOSITION_LATCH_TIME_ANDROID, map, supportedValues);
187 frameTimes->firstCompositionStart = getTimestamp(EGL_FIRST_COMPOSITION_START_TIME_ANDROID, map, supportedValues);
188 frameTimes->lastCompositionStart = getTimestamp(EGL_LAST_COMPOSITION_START_TIME_ANDROID, map, supportedValues);
189 frameTimes->firstCompositionGpuFinished = getTimestamp(EGL_FIRST_COMPOSITION_GPU_FINISHED_TIME_ANDROID, map, supportedValues);
190 frameTimes->displayPresent = getTimestamp(EGL_DISPLAY_PRESENT_TIME_ANDROID, map, supportedValues);
191 frameTimes->dequeueReady = getTimestamp(EGL_DEQUEUE_READY_TIME_ANDROID, map, supportedValues);
192 frameTimes->readsDone = getTimestamp(EGL_READS_DONE_TIME_ANDROID, map, supportedValues);
195 bool timestampValid (EGLnsecsANDROID timestamp)
197 return (timestamp >= 0) || (timestamp == EGL_TIMESTAMP_PENDING_ANDROID);
200 bool timestampPending (EGLnsecsANDROID timestamp)
202 return timestamp == EGL_TIMESTAMP_PENDING_ANDROID;
206 void check_lt(tcu::ResultCollector& result, const T& a, const T& b, const std::string& msg) {
209 std::string m = msg + "!(" + de::toString(a) + " < " + de::toString(b) + ")";
214 void check_le(tcu::ResultCollector& result, const T& a, const T& b, const std::string& msg) {
217 std::string m = msg + "!(" + de::toString(a) + " <= " + de::toString(b) + ")";
221 void verifySingleFrame (const FrameTimes& frameTimes, tcu::ResultCollector& result, bool verifyReadsDone)
223 // Verify CPU timeline is monotonic.
224 check_lt(result, frameTimes.swapBufferBeginNs, frameTimes.latch, "Buffer latched before it was swapped.");
225 check_lt(result, frameTimes.latch, frameTimes.firstCompositionStart, "Buffer composited before it was latched.");
226 check_le(result, frameTimes.firstCompositionStart, frameTimes.lastCompositionStart, "First composition start after last composition start.");
227 check_lt(result, frameTimes.lastCompositionStart, frameTimes.dequeueReady, "Buffer composited after it was ready to be dequeued.");
229 // Verify GPU timeline is monotonic.
230 if (timestampValid(frameTimes.firstCompositionGpuFinished))
231 check_lt(result, frameTimes.renderingComplete, frameTimes.firstCompositionGpuFinished, "Buffer rendering completed after compositor GPU work finished.");
233 if (timestampValid(frameTimes.displayPresent))
234 check_lt(result, frameTimes.renderingComplete, frameTimes.displayPresent, "Buffer displayed before rendering completed.");
236 if (timestampValid(frameTimes.firstCompositionGpuFinished) && timestampValid(frameTimes.displayPresent))
237 check_lt(result, frameTimes.firstCompositionGpuFinished, frameTimes.displayPresent, "Buffer displayed before compositor GPU work completed");
239 // Drivers may maintain shadow copies of the buffer, so the readsDone time
240 // of the real buffer may be earlier than apparent dependencies. We can only
241 // be sure that the readsDone time must be after the renderingComplete time.
242 // It may also be equal to the renderingComplete time if no reads were
245 check_le(result, frameTimes.renderingComplete, frameTimes.readsDone, "Buffer rendering completed after reads completed.");
247 // Verify CPU/GPU dependencies
248 if (timestampValid(frameTimes.firstCompositionGpuFinished))
249 check_lt(result, frameTimes.firstCompositionStart, frameTimes.firstCompositionGpuFinished, "Composition CPU work started after GPU work finished.");
251 if (timestampValid(frameTimes.displayPresent))
252 check_lt(result, frameTimes.firstCompositionStart, frameTimes.displayPresent, "Buffer displayed before it was composited.");
255 void verifyNeighboringFrames (const FrameTimes& frame1, const FrameTimes& frame2, tcu::ResultCollector& result, bool verifyReadsDone)
258 check_lt(result, frame1.swapBufferBeginNs, frame2.swapBufferBeginNs, "Swap begin times not monotonic.");
259 check_lt(result, frame1.latch, frame2.latch, "Latch times not monotonic.");
260 check_lt(result, frame1.lastCompositionStart, frame2.latch, "Old buffer composited after new buffer latched.");
261 check_lt(result, frame1.lastCompositionStart, frame2.firstCompositionStart, "Composition times overlap.");
262 check_lt(result, frame1.dequeueReady, frame2.dequeueReady, "Dequeue ready times not monotonic.");
265 check_lt(result, frame1.renderingComplete, frame2.renderingComplete, "Rendering complete times not monotonic.");
267 if (timestampValid(frame1.firstCompositionGpuFinished) && timestampValid(frame2.firstCompositionGpuFinished))
268 check_lt(result, frame1.firstCompositionGpuFinished, frame2.firstCompositionGpuFinished, "Composition GPU work complete times not monotonic.");
270 if (timestampValid(frame1.displayPresent) && timestampValid(frame2.displayPresent))
271 check_lt(result, frame1.displayPresent, frame2.displayPresent, "Display present times not monotonic.");
273 if (verifyReadsDone && timestampValid(frame1.readsDone) && timestampValid(frame2.readsDone))
274 check_lt(result, frame1.readsDone, frame2.readsDone, "Reads done times not monotonic.");
277 EGLContext createGLES2Context (const Library& egl, EGLDisplay display, EGLConfig config)
279 EGLContext context = EGL_NO_CONTEXT;
280 const EGLint attribList[] =
282 EGL_CONTEXT_CLIENT_VERSION, 2,
286 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
288 context = egl.createContext(display, config, EGL_NO_CONTEXT, attribList);
289 EGLU_CHECK_MSG(egl, "eglCreateContext() failed");
295 class GetFrameTimestampTest : public SimpleConfigCase
298 GetFrameTimestampTest (EglTestContext& eglTestCtx, const NamedFilterList& filters);
299 ~GetFrameTimestampTest (void);
302 void executeForConfig (EGLDisplay display, EGLConfig config);
303 void initializeExtension (const Library& egl);
306 GetFrameTimestampTest (const GetFrameTimestampTest&);
307 GetFrameTimestampTest& operator= (const GetFrameTimestampTest&);
309 // TODO: Move these to eglw::Library.
310 eglGetNextFrameIdANDROIDFunc m_eglGetNextFrameIdANDROID;
311 eglGetCompositorTimingANDROIDFunc m_eglGetCompositorTimingANDROID;
312 eglGetCompositorTimingSupportedANDROIDFunc m_eglGetCompositorTimingSupportedANDROID;
313 eglGetFrameTimestampsANDROIDFunc m_eglGetFrameTimestampsANDROID;
314 eglGetFrameTimestampSupportedANDROIDFunc m_eglGetFrameTimestampSupportedANDROID;
316 tcu::ResultCollector m_result;
319 GetFrameTimestampTest::GetFrameTimestampTest (EglTestContext& eglTestCtx, const NamedFilterList& filters)
320 : SimpleConfigCase (eglTestCtx, filters.getName(), filters.getDescription(), filters)
321 , m_eglGetNextFrameIdANDROID (DE_NULL)
322 , m_eglGetCompositorTimingANDROID (DE_NULL)
323 , m_eglGetCompositorTimingSupportedANDROID (DE_NULL)
324 , m_eglGetFrameTimestampsANDROID (DE_NULL)
325 , m_eglGetFrameTimestampSupportedANDROID (DE_NULL)
326 , m_result (m_testCtx.getLog())
330 GetFrameTimestampTest::~GetFrameTimestampTest (void)
334 void GetFrameTimestampTest::initializeExtension (const Library& egl)
336 m_eglGetNextFrameIdANDROID = reinterpret_cast<eglGetNextFrameIdANDROIDFunc>(egl.getProcAddress("eglGetNextFrameIdANDROID"));
337 EGLU_CHECK_MSG(egl, "getProcAddress of eglGetNextFrameIdANDROID failed.");
338 m_eglGetCompositorTimingANDROID = reinterpret_cast<eglGetCompositorTimingANDROIDFunc>(egl.getProcAddress("eglGetCompositorTimingANDROID"));
339 EGLU_CHECK_MSG(egl, "getProcAddress of eglGetCompositorTimingANDROID failed.");
340 m_eglGetCompositorTimingSupportedANDROID = reinterpret_cast<eglGetCompositorTimingSupportedANDROIDFunc>(egl.getProcAddress("eglGetCompositorTimingSupportedANDROID"));
341 EGLU_CHECK_MSG(egl, "getProcAddress of eglGetCompositorTimingSupportedANDROID failed.");
342 m_eglGetFrameTimestampsANDROID = reinterpret_cast<eglGetFrameTimestampsANDROIDFunc>(egl.getProcAddress("eglGetFrameTimestampsANDROID"));
343 EGLU_CHECK_MSG(egl, "getProcAddress of eglGetFrameTimestampsANDROID failed.");
344 m_eglGetFrameTimestampSupportedANDROID = reinterpret_cast<eglGetFrameTimestampSupportedANDROIDFunc>(egl.getProcAddress("eglGetFrameTimestampSupportedANDROID"));
345 EGLU_CHECK_MSG(egl, "getProcAddress of eglGetFrameTimestampSupportedANDROID failed.");
349 string getConfigIdString (const Library& egl, EGLDisplay display, EGLConfig config)
351 std::ostringstream stream;
354 EGLU_CHECK_CALL(egl, getConfigAttrib(display, config , EGL_CONFIG_ID, &id));
361 deUint32 createGLES2Program (const glw::Functions& gl, TestLog& log)
363 const char* const vertexShaderSource =
364 "attribute highp vec2 a_pos;\n"
367 "\tgl_Position = vec4(a_pos, 0.0, 1.0);\n"
370 const char* const fragmentShaderSource =
373 "\tgl_FragColor = vec4(0.9, 0.1, 0.4, 1.0);\n"
376 deUint32 program = 0;
377 deUint32 vertexShader = 0;
378 deUint32 fragmentShader = 0;
380 deInt32 vertexCompileStatus;
381 string vertexInfoLog;
382 deInt32 fragmentCompileStatus;
383 string fragmentInfoLog;
385 string programInfoLog;
389 program = gl.createProgram();
390 vertexShader = gl.createShader(GL_VERTEX_SHADER);
391 fragmentShader = gl.createShader(GL_FRAGMENT_SHADER);
393 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to create shaders and program");
395 gl.shaderSource(vertexShader, 1, &vertexShaderSource, DE_NULL);
396 gl.compileShader(vertexShader);
397 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup vertex shader");
399 gl.shaderSource(fragmentShader, 1, &fragmentShaderSource, DE_NULL);
400 gl.compileShader(fragmentShader);
401 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup fragment shader");
404 deInt32 infoLogLength = 0;
406 gl.getShaderiv(vertexShader, GL_COMPILE_STATUS, &vertexCompileStatus);
407 gl.getShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &infoLogLength);
409 vertexInfoLog.resize(infoLogLength, '\0');
411 gl.getShaderInfoLog(vertexShader, (glw::GLsizei)vertexInfoLog.length(), &infoLogLength, &(vertexInfoLog[0]));
412 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to get vertex shader compile info");
414 vertexInfoLog.resize(infoLogLength);
418 deInt32 infoLogLength = 0;
420 gl.getShaderiv(fragmentShader, GL_COMPILE_STATUS, &fragmentCompileStatus);
421 gl.getShaderiv(fragmentShader, GL_INFO_LOG_LENGTH, &infoLogLength);
423 fragmentInfoLog.resize(infoLogLength, '\0');
425 gl.getShaderInfoLog(fragmentShader, (glw::GLsizei)fragmentInfoLog.length(), &infoLogLength, &(fragmentInfoLog[0]));
426 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to get fragment shader compile info");
428 fragmentInfoLog.resize(infoLogLength);
431 gl.attachShader(program, vertexShader);
432 gl.attachShader(program, fragmentShader);
433 gl.linkProgram(program);
434 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup program");
437 deInt32 infoLogLength = 0;
439 gl.getProgramiv(program, GL_LINK_STATUS, &linkStatus);
440 gl.getProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
442 programInfoLog.resize(infoLogLength, '\0');
444 gl.getProgramInfoLog(program, (glw::GLsizei)programInfoLog.length(), &infoLogLength, &(programInfoLog[0]));
445 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to get program link info");
447 programInfoLog.resize(infoLogLength);
450 if (linkStatus == 0 || vertexCompileStatus == 0 || fragmentCompileStatus == 0)
453 log.startShaderProgram(linkStatus != 0, programInfoLog.c_str());
455 log << TestLog::Shader(QP_SHADER_TYPE_VERTEX, vertexShaderSource, vertexCompileStatus != 0, vertexInfoLog);
456 log << TestLog::Shader(QP_SHADER_TYPE_FRAGMENT, fragmentShaderSource, fragmentCompileStatus != 0, fragmentInfoLog);
458 log.endShaderProgram();
461 gl.deleteShader(vertexShader);
462 gl.deleteShader(fragmentShader);
463 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to delete shaders");
465 TCU_CHECK(linkStatus != 0 && vertexCompileStatus != 0 && fragmentCompileStatus != 0);
470 gl.deleteProgram(program);
473 gl.deleteShader(vertexShader);
476 gl.deleteShader(fragmentShader);
484 void GetFrameTimestampTest::executeForConfig (EGLDisplay display, EGLConfig config)
486 const Library& egl = m_eglTestCtx.getLibrary();
488 if (!eglu::hasExtension(egl, display, "EGL_ANDROID_get_frame_timestamps"))
489 TCU_THROW(NotSupportedError, "EGL_ANDROID_get_frame_timestamps is not supported");
491 initializeExtension(egl);
493 const string configIdStr (getConfigIdString(egl, display, config));
494 tcu::ScopedLogSection logSection (m_testCtx.getLog(), ("Config ID " + configIdStr).c_str(), ("Config ID " + configIdStr).c_str());
495 const eglu::NativeWindowFactory& factory = eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
498 TestLog& log = m_testCtx.getLog();
500 log << TestLog::Message << "EGL_RED_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_RED_SIZE) << TestLog::EndMessage;
501 log << TestLog::Message << "EGL_GREEN_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_GREEN_SIZE) << TestLog::EndMessage;
502 log << TestLog::Message << "EGL_BLUE_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_BLUE_SIZE) << TestLog::EndMessage;
503 log << TestLog::Message << "EGL_ALPHA_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_ALPHA_SIZE) << TestLog::EndMessage;
504 log << TestLog::Message << "EGL_DEPTH_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_DEPTH_SIZE) << TestLog::EndMessage;
505 log << TestLog::Message << "EGL_STENCIL_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_STENCIL_SIZE) << TestLog::EndMessage;
506 log << TestLog::Message << "EGL_SAMPLES: " << eglu::getConfigAttribInt(egl, display, config, EGL_SAMPLES) << TestLog::EndMessage;
509 de::UniquePtr<eglu::NativeWindow> window (factory.createWindow(&m_eglTestCtx.getNativeDisplay(), display, config, DE_NULL, eglu::WindowParams(128, 128, eglu::WindowParams::VISIBILITY_VISIBLE)));
511 eglu::UniqueSurface surface (egl, display, eglu::createWindowSurface(m_eglTestCtx.getNativeDisplay(), *window, display, config, DE_NULL));
512 eglu::UniqueContext context (egl, display, createGLES2Context(egl, display, config));
514 deUint32 program = 0;
516 EGLU_CHECK_CALL(egl, surfaceAttrib(display, *surface, EGL_TIMESTAMPS_ANDROID, EGL_TRUE));
518 m_eglTestCtx.initGLFunctions(&gl, glu::ApiType::es(2,0));
520 EGLU_CHECK_CALL(egl, makeCurrent(display, *surface, *surface, *context));
524 // EGL_DISPLAY_PRESENT_TIME_ANDROID support is currently optional
525 // but should be required once HWC1 is no longer supported.
526 // All HWC2 devices should support EGL_DISPLAY_PRESENT_TIME_ANDROID.
527 TimestampInfoMap timestamps;
528 timestamps[EGL_REQUESTED_PRESENT_TIME_ANDROID] = TimestampInfo(true, false, 0);
529 timestamps[EGL_RENDERING_COMPLETE_TIME_ANDROID] = TimestampInfo(true, false, 0);
530 timestamps[EGL_COMPOSITION_LATCH_TIME_ANDROID] = TimestampInfo(true, false, 0);
531 timestamps[EGL_FIRST_COMPOSITION_START_TIME_ANDROID] = TimestampInfo(true, false, 0);
532 timestamps[EGL_LAST_COMPOSITION_START_TIME_ANDROID] = TimestampInfo(true, false, 0);
533 timestamps[EGL_FIRST_COMPOSITION_GPU_FINISHED_TIME_ANDROID] = TimestampInfo(true, false, 0);
534 timestamps[EGL_DISPLAY_PRESENT_TIME_ANDROID] = TimestampInfo(false, false, 0);
535 timestamps[EGL_DEQUEUE_READY_TIME_ANDROID] = TimestampInfo(true, false, 0);
536 timestamps[EGL_READS_DONE_TIME_ANDROID] = TimestampInfo(true, false, 0);
538 const eglw::EGLint invalidTimestampName = EGL_READS_DONE_TIME_ANDROID + 1;
540 // Verify required timestamps are supported and populate supportedNames.
541 std::vector<eglw::EGLint> supportedNames;
542 for (TimestampInfoMap::iterator i = timestamps.begin(); i != timestamps.end(); i++)
544 TimestampInfo& info = i->second;
545 info.supported = m_eglGetFrameTimestampSupportedANDROID(display, *surface, i->first) != EGL_FALSE;
546 EGLU_CHECK_MSG(egl, "eglGetFrameTimestampSupportedANDROID failed.");
550 info.supportedIndex = supportedNames.size();
551 supportedNames.push_back(i->first);
554 TCU_CHECK_MSG(!info.required, "Required timestamp not supported.");
557 // Verify unsupported timestamps are reported properly.
558 const bool invalidSupported = m_eglGetFrameTimestampSupportedANDROID(display, *surface, invalidTimestampName) != EGL_FALSE;
559 EGLU_CHECK_MSG(egl, "eglGetFrameTimestampSupportedANDROID failed.");
560 TCU_CHECK_MSG(!invalidSupported, "Non existant timestamp reports that it is supported.");
562 // Verify compositor timings are supported.
563 const bool deadlineSupported = m_eglGetCompositorTimingSupportedANDROID(display, *surface, EGL_COMPOSITE_DEADLINE_ANDROID) != EGL_FALSE;
564 EGLU_CHECK_MSG(egl, "eglGetCompositorTimingSupportedANDROID failed.");
565 TCU_CHECK_MSG(deadlineSupported, "EGL_COMPOSITE_DEADLINE_ANDROID not supported.");
566 const bool intervalSupported = m_eglGetCompositorTimingSupportedANDROID(display, *surface, EGL_COMPOSITE_INTERVAL_ANDROID) != EGL_FALSE;
567 EGLU_CHECK_MSG(egl, "eglGetCompositorTimingSupportedANDROID failed.");
568 TCU_CHECK_MSG(intervalSupported, "EGL_COMPOSITE_INTERVAL_ANDROID not supported.");
569 const bool latencySupported = m_eglGetCompositorTimingSupportedANDROID(display, *surface, EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID) != EGL_FALSE;
570 EGLU_CHECK_MSG(egl, "eglGetCompositorTimingSupportedANDROID failed.");
571 TCU_CHECK_MSG(latencySupported, "EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID not supported.");
573 const float positions1[] =
584 const float positions2[] =
595 deUint32 posLocation;
597 program = createGLES2Program(gl, m_testCtx.getLog());
599 gl.useProgram(program);
600 posLocation = gl.getAttribLocation(program, "a_pos");
601 gl.enableVertexAttribArray(posLocation);
602 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup shader program for rendering");
604 const size_t frameCount = 120;
605 std::vector<FrameTimes> frameTimes(frameCount);
606 for (size_t i = 0; i < frameCount; i++)
608 FrameTimes& frame = frameTimes[i];
610 const eglw::EGLint compositorTimingNames[] =
612 EGL_COMPOSITE_DEADLINE_ANDROID,
613 EGL_COMPOSITE_INTERVAL_ANDROID,
614 EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID,
616 const EGLint compositorTimingCount = DE_LENGTH_OF_ARRAY(compositorTimingNames);
617 EGLnsecsANDROID compositorTimingValues[compositorTimingCount] = { -2 };
619 // Get the current time before making any API calls in case "now"
620 // just happens to get sampled near one of the composite deadlines.
621 EGLnsecsANDROID now = getNanoseconds();
624 EGLuint64KHR nextFrameId = 0;
625 CHECK_NAKED_EGL_CALL(egl, m_eglGetNextFrameIdANDROID(display, *surface, &nextFrameId));
626 frame.frameId = nextFrameId;
628 // Get the compositor timing.
629 CHECK_NAKED_EGL_CALL(egl, m_eglGetCompositorTimingANDROID(
630 display, *surface, compositorTimingCount,
631 compositorTimingNames, compositorTimingValues));
632 frame.compositeDeadline = compositorTimingValues[0];
633 frame.compositeInterval = compositorTimingValues[1];
634 frame.compositeToPresentLatency = compositorTimingValues[2];
636 // Verify compositor timing is sane.
637 check_lt<EGLnsecsANDROID>(m_result, 1000000, frame.compositeInterval, "Reported refresh rate greater than 1kHz.");
638 check_lt<EGLnsecsANDROID>(m_result, frame.compositeInterval, 1000000000, "Reported refresh rate less than 1Hz.");
639 check_lt<EGLnsecsANDROID>(m_result, 0, frame.compositeToPresentLatency, "Composite to present latency must be greater than 0.");
640 check_lt(m_result, frame.compositeToPresentLatency, frame.compositeInterval * 3, "Composite to present latency is more than 3 vsyncs.");
641 const EGLnsecsANDROID minDeadline = now;
642 check_lt(m_result, minDeadline, frame.compositeDeadline, "Next composite deadline is in the past.");
643 const EGLnsecsANDROID maxDeadline = now + frame.compositeInterval * 2;
644 check_lt(m_result, frame.compositeDeadline, maxDeadline, "Next composite deadline over two intervals away.");
646 const float colorAngle = (static_cast<float>(i) / static_cast<float>(frameCount)) * 6.28318f;
647 gl.clearColor((1.0f + deFloatSin(colorAngle)) / 2.0f, 0.7f, (1.0f + deFloatCos(colorAngle)) / 2.0f, 1.0f);
648 gl.clear(GL_COLOR_BUFFER_BIT);
649 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to clear surface");
651 const bool posSelect = ((i % 2) == 0);
652 gl.vertexAttribPointer(posLocation, 2, GL_FLOAT, GL_FALSE, 0, posSelect ? positions1 : positions2);
653 gl.drawArrays(GL_TRIANGLES, 0, 6);
654 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to render");
656 frame.swapBufferBeginNs = getNanoseconds();
657 EGLU_CHECK_CALL(egl, swapBuffers(display, *surface));
659 // All timestamps from 5 frames ago should definitely be available.
660 const size_t frameDelay = 5;
663 // \todo [2017-01-25 brianderson] Remove this work around once reads done is fixed.
664 const bool verifyReadsDone = i > (frameDelay + 3);
665 FrameTimes& frame5ago = frameTimes[i-frameDelay];
666 std::vector<EGLnsecsANDROID> supportedValues(supportedNames.size(), 0);
668 CHECK_NAKED_EGL_CALL(egl, m_eglGetFrameTimestampsANDROID(
669 display, *surface, frame5ago.frameId, static_cast<eglw::EGLint>(supportedNames.size()),
670 &supportedNames[0], &supportedValues[0]));
671 populateFrameTimes(&frame5ago, timestamps, supportedValues);
673 verifySingleFrame(frame5ago, m_result, verifyReadsDone);
674 if (i >= frameDelay + 1)
676 FrameTimes& frame6ago = frameTimes[i-frameDelay-1];
677 verifyNeighboringFrames(frame6ago, frame5ago, m_result, verifyReadsDone);
682 // All timestamps for the most recently swapped frame should
683 // become available by only polling eglGetFrametimestamps.
684 // No additional swaps should be necessary.
685 FrameTimes& lastFrame = frameTimes.back();
686 const EGLnsecsANDROID pollingDeadline = lastFrame.swapBufferBeginNs + 1000000000;
687 bool finalTimestampAvailable = false;
691 std::vector<EGLnsecsANDROID> supportedValues(supportedNames.size(), 0);
692 CHECK_NAKED_EGL_CALL(egl, m_eglGetFrameTimestampsANDROID(
693 display, *surface, lastFrame.frameId, static_cast<eglw::EGLint>(supportedNames.size()),
694 &supportedNames[0], &supportedValues[0]));
695 populateFrameTimes(&lastFrame, timestamps, supportedValues);
697 // Poll for present if it's supported.
698 // Otherwise, poll for firstCompositionStart.
699 if (timestamps[EGL_DISPLAY_PRESENT_TIME_ANDROID].supported)
700 finalTimestampAvailable = !timestampPending(lastFrame.displayPresent);
702 finalTimestampAvailable = !timestampPending(lastFrame.firstCompositionStart);
703 } while (!finalTimestampAvailable && (getNanoseconds() < pollingDeadline));
705 m_result.check(finalTimestampAvailable, "Timed out polling for timestamps of last swap.");
706 m_result.check((lastFrame.requestedPresent >= 0), "Requested present of last swap not avaiable.");
707 m_result.check((lastFrame.renderingComplete >= 0), "Rendering complete of last swap not avaiable.");
708 m_result.check((lastFrame.latch >= 0), "Latch of last swap not avaiable.");
709 m_result.check((lastFrame.firstCompositionStart >= 0), "First composite time of last swap not avaiable.");
710 m_result.check((lastFrame.lastCompositionStart >= 0), "Last composite time of last swap not avaiable.");
712 window->processEvents();
713 gl.disableVertexAttribArray(posLocation);
715 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to release program state");
717 gl.deleteProgram(program);
719 GLU_EXPECT_NO_ERROR(gl.getError(), "glDeleteProgram()");
721 m_result.setTestContextResult(m_testCtx);
726 gl.deleteProgram(program);
728 EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
732 EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
735 class GetFrameTimestampsTests : public TestCaseGroup
738 GetFrameTimestampsTests (EglTestContext& eglTestCtx);
742 GetFrameTimestampsTests (const GetFrameTimestampsTests&);
743 GetFrameTimestampsTests& operator= (const GetFrameTimestampsTests&);
747 GetFrameTimestampsTests::GetFrameTimestampsTests (EglTestContext& eglTestCtx)
748 : TestCaseGroup(eglTestCtx, "get_frame_timestamps", "Get frame timestamp tests")
752 bool isWindow (const eglu::CandidateConfig& c)
754 return (c.surfaceType() & EGL_WINDOW_BIT) != 0;
757 void GetFrameTimestampsTests::init (void)
759 eglu::FilterList baseFilters;
760 baseFilters << isWindow;
762 vector<NamedFilterList> filterLists;
763 getDefaultFilterLists(filterLists, baseFilters);
765 for (vector<NamedFilterList>::iterator i = filterLists.begin(); i != filterLists.end(); i++)
766 addChild(new GetFrameTimestampTest(m_eglTestCtx, *i));
771 TestCaseGroup* createGetFrameTimestampsTests (EglTestContext& eglTestCtx)
773 return new GetFrameTimestampsTests(eglTestCtx);