Hash :
e39bcdc3
Author :
Date :
2025-04-09T17:26:34
Support GLES query counter bits ANGLE only support query GL_QUERY_COUNTER_BITS_EXT with TIME_ELAPSED_EXT or TIMESTAMP_EXT, but other targets should also be supported. Since the values are stored in 32 bits, we just return 32 for other target. An end2end test is added. Bug: angleproject:409674598 Change-Id: I98941f4dd36ef62c57bcb87475ebb9f626c1bbf9 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6437686 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Alexey Knyazev <lexa.knyazev@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
//
// Copyright 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// TimerQueriesTest.cpp
// Various tests for EXT_disjoint_timer_query functionality and validation
//
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
#include "util/EGLWindow.h"
#include "util/random_utils.h"
#include "util/test_utils.h"
using namespace angle;
class TimerQueriesTest : public ANGLETest<>
{
protected:
TimerQueriesTest() : mProgram(0), mProgramCostly(0)
{
setWindowWidth(128);
setWindowHeight(128);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
setConfigDepthBits(24);
}
void testSetUp() override
{
constexpr char kCostlyVS[] =
"attribute highp vec4 position; varying highp vec4 testPos; void main(void)\n"
"{\n"
" testPos = position;\n"
" gl_Position = position;\n"
"}\n";
constexpr char kCostlyFS[] =
"precision highp float; varying highp vec4 testPos; void main(void)\n"
"{\n"
" vec4 test = testPos;\n"
" for (int i = 0; i < 500; i++)\n"
" {\n"
" test = sqrt(test);\n"
" }\n"
" gl_FragColor = test;\n"
"}\n";
mProgram = CompileProgram(essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
ASSERT_NE(0u, mProgram) << "shader compilation failed.";
mProgramCostly = CompileProgram(kCostlyVS, kCostlyFS);
ASSERT_NE(0u, mProgramCostly) << "shader compilation failed.";
}
void testTearDown() override
{
glDeleteProgram(mProgram);
glDeleteProgram(mProgramCostly);
}
GLuint mProgram;
GLuint mProgramCostly;
};
// Test that all proc addresses are loadable
TEST_P(TimerQueriesTest, ProcAddresses)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_disjoint_timer_query"));
ASSERT_NE(nullptr, eglGetProcAddress("glGenQueriesEXT"));
ASSERT_NE(nullptr, eglGetProcAddress("glDeleteQueriesEXT"));
ASSERT_NE(nullptr, eglGetProcAddress("glIsQueryEXT"));
ASSERT_NE(nullptr, eglGetProcAddress("glBeginQueryEXT"));
ASSERT_NE(nullptr, eglGetProcAddress("glEndQueryEXT"));
ASSERT_NE(nullptr, eglGetProcAddress("glQueryCounterEXT"));
ASSERT_NE(nullptr, eglGetProcAddress("glGetQueryivEXT"));
ASSERT_NE(nullptr, eglGetProcAddress("glGetQueryObjectivEXT"));
ASSERT_NE(nullptr, eglGetProcAddress("glGetQueryObjectuivEXT"));
ASSERT_NE(nullptr, eglGetProcAddress("glGetQueryObjecti64vEXT"));
ASSERT_NE(nullptr, eglGetProcAddress("glGetQueryObjectui64vEXT"));
}
// Tests the time elapsed query
TEST_P(TimerQueriesTest, TimeElapsed)
{
// TODO(anglebug.com/40096747): Failing on ARM-based Apple DTKs.
ANGLE_SKIP_TEST_IF(IsMac() && IsARM64() && IsDesktopOpenGL());
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_disjoint_timer_query"));
// http://anglebug.com/42263715
ANGLE_SKIP_TEST_IF(IsMac() && IsOpenGL());
GLint queryTimeElapsedBits = 0;
glGetQueryivEXT(GL_TIME_ELAPSED_EXT, GL_QUERY_COUNTER_BITS_EXT, &queryTimeElapsedBits);
ASSERT_GL_NO_ERROR();
std::cout << "Time elapsed counter bits: " << queryTimeElapsedBits << std::endl;
// Skip test if the number of bits is 0
ANGLE_SKIP_TEST_IF(!queryTimeElapsedBits);
glDepthMask(GL_TRUE);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
GLuint query1 = 0;
GLuint query2 = 0;
glGenQueriesEXT(1, &query1);
glGenQueriesEXT(1, &query2);
// Test time elapsed for a single quad
glBeginQueryEXT(GL_TIME_ELAPSED_EXT, query1);
drawQuad(mProgram, essl1_shaders::PositionAttrib(), 0.8f);
glEndQueryEXT(GL_TIME_ELAPSED_EXT);
ASSERT_GL_NO_ERROR();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// Test time elapsed for costly quad
glBeginQueryEXT(GL_TIME_ELAPSED_EXT, query2);
drawQuad(mProgramCostly, "position", 0.8f);
glEndQueryEXT(GL_TIME_ELAPSED_EXT);
ASSERT_GL_NO_ERROR();
swapBuffers();
int timeout = 200000;
GLuint ready = GL_FALSE;
while (ready == GL_FALSE && timeout > 0)
{
angle::Sleep(0);
glGetQueryObjectuivEXT(query1, GL_QUERY_RESULT_AVAILABLE_EXT, &ready);
timeout--;
}
ready = GL_FALSE;
while (ready == GL_FALSE && timeout > 0)
{
angle::Sleep(0);
glGetQueryObjectuivEXT(query2, GL_QUERY_RESULT_AVAILABLE_EXT, &ready);
timeout--;
}
ASSERT_LT(0, timeout) << "Query result available timed out" << std::endl;
GLuint64 result1 = 0;
GLuint64 result2 = 0;
glGetQueryObjectui64vEXT(query1, GL_QUERY_RESULT_EXT, &result1);
glGetQueryObjectui64vEXT(query2, GL_QUERY_RESULT_EXT, &result2);
ASSERT_GL_NO_ERROR();
glDeleteQueriesEXT(1, &query1);
glDeleteQueriesEXT(1, &query2);
ASSERT_GL_NO_ERROR();
std::cout << "Elapsed time: " << result1 << " cheap quad" << std::endl;
std::cout << "Elapsed time: " << result2 << " costly quad" << std::endl;
// The time elapsed should be nonzero
EXPECT_LT(0ul, result1);
EXPECT_LT(0ul, result2);
// The time elapsed should be less than a second. Not an actual
// requirement, but longer than a second to draw something basic hints at
// an issue with the queries themselves.
EXPECT_LT(result1, 1000000000ul);
EXPECT_LT(result2, 1000000000ul);
// TODO(geofflang): Re-enable this check when it is non-flaky
// The costly quad should take longer than the cheap quad
// EXPECT_LT(result1, result2);
}
// Tests time elapsed for a non draw call (texture upload)
TEST_P(TimerQueriesTest, TimeElapsedTextureTest)
{
// OSX drivers don't seem to properly time non-draw calls so we skip the test on Mac
ANGLE_SKIP_TEST_IF(IsMac() && IsOpenGL());
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_disjoint_timer_query"));
GLint queryTimeElapsedBits = 0;
glGetQueryivEXT(GL_TIME_ELAPSED_EXT, GL_QUERY_COUNTER_BITS_EXT, &queryTimeElapsedBits);
ASSERT_GL_NO_ERROR();
std::cout << "Time elapsed counter bits: " << queryTimeElapsedBits << std::endl;
// Skip test if the number of bits is 0
ANGLE_SKIP_TEST_IF(!queryTimeElapsedBits);
std::vector<GLColor> texData{GLColor::black, GLColor::white, GLColor::white, GLColor::black};
// Query and texture initialization
GLuint texture;
GLuint query = 0;
glGenQueriesEXT(1, &query);
glGenTextures(1, &texture);
// Upload a texture inside the query
glBeginQueryEXT(GL_TIME_ELAPSED_EXT, query);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, texData.data());
glGenerateMipmap(GL_TEXTURE_2D);
glFinish();
glEndQueryEXT(GL_TIME_ELAPSED_EXT);
ASSERT_GL_NO_ERROR();
int timeout = 200000;
GLuint ready = GL_FALSE;
while (ready == GL_FALSE && timeout > 0)
{
angle::Sleep(0);
glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_AVAILABLE_EXT, &ready);
timeout--;
}
ASSERT_LT(0, timeout) << "Query result available timed out" << std::endl;
GLuint64 result = 0;
glGetQueryObjectui64vEXT(query, GL_QUERY_RESULT_EXT, &result);
ASSERT_GL_NO_ERROR();
glDeleteTextures(1, &texture);
glDeleteQueriesEXT(1, &query);
std::cout << "Elapsed time: " << result << std::endl;
EXPECT_LT(0ul, result);
// an issue with the queries themselves.
EXPECT_LT(result, 1000000000ul);
}
// Tests validation of query functions with respect to elapsed time query
TEST_P(TimerQueriesTest, TimeElapsedValidationTest)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_disjoint_timer_query"));
GLint queryTimeElapsedBits = 0;
glGetQueryivEXT(GL_TIME_ELAPSED_EXT, GL_QUERY_COUNTER_BITS_EXT, &queryTimeElapsedBits);
ASSERT_GL_NO_ERROR();
std::cout << "Time elapsed counter bits: " << queryTimeElapsedBits << std::endl;
// Skip test if the number of bits is 0
ANGLE_SKIP_TEST_IF(!queryTimeElapsedBits);
GLuint query = 0;
glGenQueriesEXT(-1, &query);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
glGenQueriesEXT(1, &query);
EXPECT_GL_NO_ERROR();
glBeginQueryEXT(GL_TIMESTAMP_EXT, query);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
glBeginQueryEXT(GL_TIME_ELAPSED_EXT, 0);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
glEndQueryEXT(GL_TIME_ELAPSED_EXT);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
glBeginQueryEXT(GL_TIME_ELAPSED_EXT, query);
EXPECT_GL_NO_ERROR();
glBeginQueryEXT(GL_TIME_ELAPSED_EXT, query);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
glEndQueryEXT(GL_TIME_ELAPSED_EXT);
EXPECT_GL_NO_ERROR();
glEndQueryEXT(GL_TIME_ELAPSED_EXT);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
}
// Tests timer queries operating under multiple EGL contexts with mid-query switching
TEST_P(TimerQueriesTest, TimeElapsedMulticontextTest)
{
// TODO(jmadill): Figure out why this test is flaky on AMD/OpenGL.
// http://anglebug.com/42260520
ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
// TODO(anglebug.com/40096747): Failing on ARM-based Apple DTKs.
ANGLE_SKIP_TEST_IF(IsMac() && IsARM64() && IsDesktopOpenGL());
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_disjoint_timer_query"));
// Test skipped because the Vulkan backend doesn't account for (and remove) time spent in other
// contexts.
ANGLE_SKIP_TEST_IF(IsVulkan());
GLint queryTimeElapsedBits = 0;
glGetQueryivEXT(GL_TIME_ELAPSED_EXT, GL_QUERY_COUNTER_BITS_EXT, &queryTimeElapsedBits);
ASSERT_GL_NO_ERROR();
std::cout << "Time elapsed counter bits: " << queryTimeElapsedBits << std::endl;
// Skip test if the number of bits is 0
ANGLE_SKIP_TEST_IF(!queryTimeElapsedBits);
// Without a glClear, the first draw call on GL takes a huge amount of time when run after the
// D3D test on certain NVIDIA drivers
glDepthMask(GL_TRUE);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
EGLint contextAttributes[] = {
EGL_CONTEXT_MAJOR_VERSION_KHR,
GetParam().majorVersion,
EGL_CONTEXT_MINOR_VERSION_KHR,
GetParam().minorVersion,
EGL_NONE,
};
EGLWindow *window = getEGLWindow();
EGLDisplay display = window->getDisplay();
EGLConfig config = window->getConfig();
EGLSurface surface = window->getSurface();
struct ContextInfo
{
EGLContext context;
GLuint program;
GLuint query;
EGLDisplay display;
ContextInfo() : context(EGL_NO_CONTEXT), program(0), query(0), display(EGL_NO_DISPLAY) {}
~ContextInfo()
{
if (context != EGL_NO_CONTEXT && display != EGL_NO_DISPLAY)
{
eglDestroyContext(display, context);
}
}
};
ContextInfo contexts[2];
constexpr char kCostlyVS[] =
"attribute highp vec4 position; varying highp vec4 testPos; void main(void)\n"
"{\n"
" testPos = position;\n"
" gl_Position = position;\n"
"}\n";
constexpr char kCostlyFS[] =
"precision highp float; varying highp vec4 testPos; void main(void)\n"
"{\n"
" vec4 test = testPos;\n"
" for (int i = 0; i < 500; i++)\n"
" {\n"
" test = sqrt(test);\n"
" }\n"
" gl_FragColor = test;\n"
"}\n";
// Setup the first context with a cheap shader
contexts[0].context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttributes);
contexts[0].display = display;
ASSERT_NE(contexts[0].context, EGL_NO_CONTEXT);
eglMakeCurrent(display, surface, surface, contexts[0].context);
contexts[0].program = CompileProgram(essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
glGenQueriesEXT(1, &contexts[0].query);
ASSERT_GL_NO_ERROR();
// Setup the second context with an expensive shader
contexts[1].context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttributes);
contexts[1].display = display;
ASSERT_NE(contexts[1].context, EGL_NO_CONTEXT);
eglMakeCurrent(display, surface, surface, contexts[1].context);
contexts[1].program = CompileProgram(kCostlyVS, kCostlyFS);
glGenQueriesEXT(1, &contexts[1].query);
ASSERT_GL_NO_ERROR();
// Start the query and draw a quad on the first context without ending the query
eglMakeCurrent(display, surface, surface, contexts[0].context);
glBeginQueryEXT(GL_TIME_ELAPSED_EXT, contexts[0].query);
drawQuad(contexts[0].program, essl1_shaders::PositionAttrib(), 0.8f);
ASSERT_GL_NO_ERROR();
// Switch contexts, draw the expensive quad and end its query
eglMakeCurrent(display, surface, surface, contexts[1].context);
glBeginQueryEXT(GL_TIME_ELAPSED_EXT, contexts[1].query);
drawQuad(contexts[1].program, "position", 0.8f);
glEndQueryEXT(GL_TIME_ELAPSED_EXT);
ASSERT_GL_NO_ERROR();
// Go back to the first context, end its query, and get the result
eglMakeCurrent(display, surface, surface, contexts[0].context);
glEndQueryEXT(GL_TIME_ELAPSED_EXT);
GLuint64 result1 = 0;
GLuint64 result2 = 0;
glGetQueryObjectui64vEXT(contexts[0].query, GL_QUERY_RESULT_EXT, &result1);
glDeleteQueriesEXT(1, &contexts[0].query);
glDeleteProgram(contexts[0].program);
ASSERT_GL_NO_ERROR();
// Get the 2nd context's results
eglMakeCurrent(display, surface, surface, contexts[1].context);
glGetQueryObjectui64vEXT(contexts[1].query, GL_QUERY_RESULT_EXT, &result2);
glDeleteQueriesEXT(1, &contexts[1].query);
glDeleteProgram(contexts[1].program);
ASSERT_GL_NO_ERROR();
// Switch back to main context
eglMakeCurrent(display, surface, surface, window->getContext());
// Compare the results. The cheap quad should be smaller than the expensive one if
// virtualization is working correctly
std::cout << "Elapsed time: " << result1 << " cheap quad" << std::endl;
std::cout << "Elapsed time: " << result2 << " costly quad" << std::endl;
EXPECT_LT(0ul, result1);
EXPECT_LT(0ul, result2);
EXPECT_LT(result1, 1000000000ul);
EXPECT_LT(result2, 1000000000ul);
// This check can never really be non-flaky. http://anglebug.com/42263737
// EXPECT_LT(result1, result2);
}
// Tests GPU timestamp functionality
TEST_P(TimerQueriesTest, Timestamp)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_disjoint_timer_query"));
GLint queryTimestampBits = 0;
glGetQueryivEXT(GL_TIMESTAMP_EXT, GL_QUERY_COUNTER_BITS_EXT, &queryTimestampBits);
ASSERT_GL_NO_ERROR();
std::cout << "Timestamp counter bits: " << queryTimestampBits << std::endl;
// Macs for some reason return 0 bits so skip the test for now if either are 0
ANGLE_SKIP_TEST_IF(!queryTimestampBits);
glDepthMask(GL_TRUE);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
GLuint query1 = 0;
GLuint query2 = 0;
glGenQueriesEXT(1, &query1);
glGenQueriesEXT(1, &query2);
glQueryCounterEXT(query1, GL_TIMESTAMP_EXT);
drawQuad(mProgram, essl1_shaders::PositionAttrib(), 0.8f);
glQueryCounterEXT(query2, GL_TIMESTAMP_EXT);
ASSERT_GL_NO_ERROR();
swapBuffers();
int timeout = 200000;
GLuint ready = GL_FALSE;
while (ready == GL_FALSE && timeout > 0)
{
angle::Sleep(0);
glGetQueryObjectuivEXT(query1, GL_QUERY_RESULT_AVAILABLE_EXT, &ready);
timeout--;
}
ready = GL_FALSE;
while (ready == GL_FALSE && timeout > 0)
{
angle::Sleep(0);
glGetQueryObjectuivEXT(query2, GL_QUERY_RESULT_AVAILABLE_EXT, &ready);
timeout--;
}
ASSERT_LT(0, timeout) << "Query result available timed out" << std::endl;
GLuint64 result1 = 0;
GLuint64 result2 = 0;
glGetQueryObjectui64vEXT(query1, GL_QUERY_RESULT_EXT, &result1);
glGetQueryObjectui64vEXT(query2, GL_QUERY_RESULT_EXT, &result2);
ASSERT_GL_NO_ERROR();
glDeleteQueriesEXT(1, &query1);
glDeleteQueriesEXT(1, &query2);
std::cout << "Timestamps: " << result1 << " " << result2 << std::endl;
EXPECT_LT(0ul, result1);
EXPECT_LT(0ul, result2);
EXPECT_LT(result1, result2);
}
void getQueryResult(GLuint queryObjectName, GLuint64 *result)
{
GLuint queryResult = GL_FALSE;
while (queryResult != GL_TRUE)
{
glGetQueryObjectuivEXT(queryObjectName, GL_QUERY_RESULT_AVAILABLE, &queryResult);
ASSERT_GL_NO_ERROR();
angle::Sleep(50);
}
glGetQueryObjectui64vEXT(queryObjectName, GL_QUERY_RESULT_EXT, result);
}
class TimerstampQueriesTest : public TimerQueriesTest
{};
// Tests getting timestamps via glGetQueryObjectui64vEXT
TEST_P(TimerstampQueriesTest, TimestampBasic)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_disjoint_timer_query"));
ANGLE_SKIP_TEST_IF(!IsD3D11() || !IsWindows());
GLint queryTimestampBits = 0;
glGetQueryivEXT(GL_TIMESTAMP_EXT, GL_QUERY_COUNTER_BITS_EXT, &queryTimestampBits);
ASSERT_GL_NO_ERROR();
std::cout << "Timestamp counter bits: " << queryTimestampBits << std::endl;
GLQuery queryObject1, queryObject2;
glQueryCounterEXT(queryObject1, GL_TIMESTAMP_EXT);
ASSERT_GL_NO_ERROR();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
drawQuad(mProgramCostly, "position", 0.8f);
glQueryCounterEXT(queryObject2, GL_TIMESTAMP_EXT);
ASSERT_GL_NO_ERROR();
GLuint64 result1 = 0;
getQueryResult(queryObject1, &result1);
GLuint64 result2 = 0;
getQueryResult(queryObject2, &result2);
std::cout << "Timestamps: " << result1 << " " << result2 << std::endl;
if (queryTimestampBits != 0)
{
ASSERT_TRUE(result1 != 0 && result2 > result1);
}
}
class TimerQueriesTestES3 : public TimerQueriesTest
{};
// Tests getting timestamps via glGetInteger64v
TEST_P(TimerQueriesTestES3, TimestampGetInteger64)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_disjoint_timer_query"));
// http://anglebug.com/40096654
ANGLE_SKIP_TEST_IF(IsAndroid());
GLint queryTimestampBits = 0;
glGetQueryivEXT(GL_TIMESTAMP_EXT, GL_QUERY_COUNTER_BITS_EXT, &queryTimestampBits);
ASSERT_GL_NO_ERROR();
std::cout << "Timestamp counter bits: " << queryTimestampBits << std::endl;
ANGLE_SKIP_TEST_IF(!queryTimestampBits);
glDepthMask(GL_TRUE);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
GLint64 result1 = 0;
GLint64 result2 = 0;
glGetInteger64v(GL_TIMESTAMP_EXT, &result1);
drawQuad(mProgram, essl1_shaders::PositionAttrib(), 0.8f);
glGetInteger64v(GL_TIMESTAMP_EXT, &result2);
ASSERT_GL_NO_ERROR();
std::cout << "Timestamps (getInteger64v): " << result1 << " " << result2 << std::endl;
EXPECT_LT(0l, result1);
EXPECT_LT(0l, result2);
EXPECT_LT(result1, result2);
}
// Test glQueryCounterEXT with target GL_TIMESTAMP_EXT after query id has been used for
// GL_ANY_SAMPLES_PASSED
TEST_P(TimerQueriesTest, QueryCounterEXTWithTypeMismatch)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_disjoint_timer_query"));
GLuint query = 0;
GLint result = 0;
glGenQueriesEXT(1, &query);
glBeginQueryEXT(GL_ANY_SAMPLES_PASSED, query);
glEndQueryEXT(GL_ANY_SAMPLES_PASSED);
glGetQueryObjectivEXT(query, GL_QUERY_RESULT_EXT, &result);
ASSERT_GL_NO_ERROR();
glQueryCounterEXT(query, GL_TIMESTAMP_EXT);
ASSERT_GL_ERROR(GL_INVALID_OPERATION);
}
// Tests glGetQueryivEXT with GL_QUERY_COUNTER_BITS_EXT works for all targets.
TEST_P(TimerQueriesTest, QueryCounterBits)
{
ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3);
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_disjoint_timer_query"));
GLint result;
glGetQueryivEXT(GL_ANY_SAMPLES_PASSED, GL_QUERY_COUNTER_BITS_EXT, &result);
ASSERT_GL_NO_ERROR();
EXPECT_EQ(result, 1);
glGetQueryivEXT(GL_ANY_SAMPLES_PASSED_CONSERVATIVE, GL_QUERY_COUNTER_BITS_EXT, &result);
ASSERT_GL_NO_ERROR();
EXPECT_EQ(result, 1);
glGetQueryivEXT(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, GL_QUERY_COUNTER_BITS_EXT, &result);
ASSERT_GL_NO_ERROR();
EXPECT_EQ(result, 32);
// Value is returned from Vulkan, so we do not need to check the value since it can vary on
// different platforms
glGetQueryivEXT(GL_TIME_ELAPSED_EXT, GL_QUERY_COUNTER_BITS_EXT, &result);
ASSERT_GL_NO_ERROR();
glGetQueryivEXT(GL_TIMESTAMP_EXT, GL_QUERY_COUNTER_BITS_EXT, &result);
ASSERT_GL_NO_ERROR();
}
ANGLE_INSTANTIATE_TEST_ES2_AND(TimerstampQueriesTest,
ES3_D3D11().disable(Feature::EnableTimestampQueries),
ES3_D3D11().enable(Feature::EnableTimestampQueries));
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(TimestampQueriesTest);
ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(TimerQueriesTest);
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(TimerQueriesTestES3);
ANGLE_INSTANTIATE_TEST_ES3(TimerQueriesTestES3);