Hash :
4b608a6c
Author :
Date :
2021-02-17T22:14:18
Tests: Add Messenger Lite trace Test: angle_perftests --gtest_filter="*messenger_lite*" Bug: b/180562361 Bug: angleproject:5659 Bug: angleproject:5663 Change-Id: I9938b925962ea13fd626f2b82676655d07d78c0d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2703733 Reviewed-by: Tim Van Patten <timvp@google.com> Commit-Queue: Cody Northrop <cnorthrop@google.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 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994
//
// Copyright 2020 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.
//
// TracePerf:
// Performance test for ANGLE replaying traces.
//
#include <gtest/gtest.h>
#include "common/PackedEnums.h"
#include "common/system_utils.h"
#include "tests/perf_tests/ANGLEPerfTest.h"
#include "tests/perf_tests/ANGLEPerfTestArgs.h"
#include "tests/perf_tests/DrawCallPerfParams.h"
#include "util/egl_loader_autogen.h"
#include "util/frame_capture_test_utils.h"
#include "util/png_utils.h"
#include "util/test_utils.h"
#include "restricted_traces/restricted_traces_autogen.h"
#include <cassert>
#include <functional>
#include <sstream>
using namespace angle;
using namespace egl_platform;
namespace
{
struct TracePerfParams final : public RenderTestParams
{
// Common default options
TracePerfParams()
{
majorVersion = 3;
minorVersion = 1;
// Display the frame after every drawBenchmark invocation
iterationsPerStep = 1;
}
std::string story() const override
{
std::stringstream strstr;
strstr << RenderTestParams::story() << "_" << GetTraceInfo(testID).name;
return strstr.str();
}
RestrictedTraceID testID;
};
std::ostream &operator<<(std::ostream &os, const TracePerfParams ¶ms)
{
os << params.backendAndStory().substr(1);
return os;
}
class TracePerfTest : public ANGLERenderTest, public ::testing::WithParamInterface<TracePerfParams>
{
public:
TracePerfTest();
void initializeBenchmark() override;
void destroyBenchmark() override;
void drawBenchmark() override;
void onReplayFramebufferChange(GLenum target, GLuint framebuffer);
void onReplayInvalidateFramebuffer(GLenum target,
GLsizei numAttachments,
const GLenum *attachments);
void onReplayInvalidateSubFramebuffer(GLenum target,
GLsizei numAttachments,
const GLenum *attachments,
GLint x,
GLint y,
GLsizei width,
GLsizei height);
void onReplayDrawBuffers(GLsizei n, const GLenum *bufs);
void onReplayReadBuffer(GLenum src);
void onReplayDiscardFramebufferEXT(GLenum target,
GLsizei numAttachments,
const GLenum *attachments);
bool isDefaultFramebuffer(GLenum target) const;
uint32_t mStartFrame;
uint32_t mEndFrame;
double getHostTimeFromGLTime(GLint64 glTime);
int getStepAlignment() const override
{
// Align step counts to the number of frames in a trace.
const TraceInfo &traceInfo = GetTraceInfo(GetParam().testID);
return static_cast<int>(traceInfo.endFrame - traceInfo.startFrame + 1);
}
private:
struct QueryInfo
{
GLuint beginTimestampQuery;
GLuint endTimestampQuery;
GLuint framebuffer;
};
struct TimeSample
{
GLint64 glTime;
double hostTime;
};
void sampleTime();
void saveScreenshot(const std::string &screenshotName) override;
void swap();
// For tracking RenderPass/FBO change timing.
QueryInfo mCurrentQuery = {};
std::vector<QueryInfo> mRunningQueries;
std::vector<TimeSample> mTimeline;
std::string mStartingDirectory;
bool mUseTimestampQueries = false;
GLuint mOffscreenFramebuffer = 0;
GLuint mOffscreenTexture = 0;
GLuint mOffscreenDepthStencil = 0;
int mWindowWidth = 0;
int mWindowHeight = 0;
GLuint mDrawFramebufferBinding = 0;
GLuint mReadFramebufferBinding = 0;
uint32_t mCurrentFrame = 0;
uint32_t mOffscreenFrameCount = 0;
bool mScreenshotSaved = false;
};
class TracePerfTest;
TracePerfTest *gCurrentTracePerfTest = nullptr;
// Don't forget to include KHRONOS_APIENTRY in override methods. Neccessary on Win/x86.
void KHRONOS_APIENTRY BindFramebufferProc(GLenum target, GLuint framebuffer)
{
gCurrentTracePerfTest->onReplayFramebufferChange(target, framebuffer);
}
void KHRONOS_APIENTRY InvalidateFramebufferProc(GLenum target,
GLsizei numAttachments,
const GLenum *attachments)
{
gCurrentTracePerfTest->onReplayInvalidateFramebuffer(target, numAttachments, attachments);
}
void KHRONOS_APIENTRY InvalidateSubFramebufferProc(GLenum target,
GLsizei numAttachments,
const GLenum *attachments,
GLint x,
GLint y,
GLsizei width,
GLsizei height)
{
gCurrentTracePerfTest->onReplayInvalidateSubFramebuffer(target, numAttachments, attachments, x,
y, width, height);
}
void KHRONOS_APIENTRY DrawBuffersProc(GLsizei n, const GLenum *bufs)
{
gCurrentTracePerfTest->onReplayDrawBuffers(n, bufs);
}
void KHRONOS_APIENTRY ReadBufferProc(GLenum src)
{
gCurrentTracePerfTest->onReplayReadBuffer(src);
}
void KHRONOS_APIENTRY DiscardFramebufferEXTProc(GLenum target,
GLsizei numAttachments,
const GLenum *attachments)
{
gCurrentTracePerfTest->onReplayDiscardFramebufferEXT(target, numAttachments, attachments);
}
angle::GenericProc KHRONOS_APIENTRY TraceLoadProc(const char *procName)
{
if (strcmp(procName, "glBindFramebuffer") == 0)
{
return reinterpret_cast<angle::GenericProc>(BindFramebufferProc);
}
if (strcmp(procName, "glInvalidateFramebuffer") == 0)
{
return reinterpret_cast<angle::GenericProc>(InvalidateFramebufferProc);
}
if (strcmp(procName, "glInvalidateSubFramebuffer") == 0)
{
return reinterpret_cast<angle::GenericProc>(InvalidateSubFramebufferProc);
}
if (strcmp(procName, "glDrawBuffers") == 0)
{
return reinterpret_cast<angle::GenericProc>(DrawBuffersProc);
}
if (strcmp(procName, "glReadBuffer") == 0)
{
return reinterpret_cast<angle::GenericProc>(ReadBufferProc);
}
if (strcmp(procName, "glDiscardFramebufferEXT") == 0)
{
return reinterpret_cast<angle::GenericProc>(DiscardFramebufferEXTProc);
}
return gCurrentTracePerfTest->getGLWindow()->getProcAddress(procName);
}
TracePerfTest::TracePerfTest()
: ANGLERenderTest("TracePerf", GetParam(), "ms"), mStartFrame(0), mEndFrame(0)
{
const TracePerfParams ¶m = GetParam();
// TODO: http://anglebug.com/4533 This fails after the upgrade to the 26.20.100.7870 driver.
if (IsWindows() && IsIntel() && param.getRenderer() == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE &&
param.testID == RestrictedTraceID::manhattan_10)
{
mSkipTest = true;
}
// TODO: http://anglebug.com/4731 Fails on older Intel drivers. Passes in newer.
if (IsWindows() && IsIntel() && param.driver != GLESDriverType::AngleEGL &&
param.testID == RestrictedTraceID::angry_birds_2_1500)
{
mSkipTest = true;
}
if (param.surfaceType != SurfaceType::Window && !gEnableAllTraceTests)
{
printf("Test skipped. Use --enable-all-trace-tests to run.\n");
mSkipTest = true;
}
if (param.eglParameters.deviceType != EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE &&
!gEnableAllTraceTests)
{
printf("Test skipped. Use --enable-all-trace-tests to run.\n");
mSkipTest = true;
}
if (param.testID == RestrictedTraceID::cod_mobile)
{
// TODO: http://anglebug.com/4967 Vulkan: GL_EXT_color_buffer_float not supported on Pixel 2
// The COD:Mobile trace uses a framebuffer attachment with:
// format = GL_RGB
// type = GL_UNSIGNED_INT_10F_11F_11F_REV
// That combination is only renderable if GL_EXT_color_buffer_float is supported.
// It happens to not be supported on Pixel 2's Vulkan driver.
addExtensionPrerequisite("GL_EXT_color_buffer_float");
// TODO: http://anglebug.com/4731 This extension is missing on older Intel drivers.
addExtensionPrerequisite("GL_OES_EGL_image_external");
}
if (param.testID == RestrictedTraceID::brawl_stars)
{
addExtensionPrerequisite("GL_EXT_shadow_samplers");
}
if (param.testID == RestrictedTraceID::free_fire)
{
addExtensionPrerequisite("GL_OES_EGL_image_external");
}
if (param.testID == RestrictedTraceID::marvel_contest_of_champions)
{
addExtensionPrerequisite("GL_EXT_color_buffer_half_float");
}
if (param.testID == RestrictedTraceID::world_of_tanks_blitz)
{
addExtensionPrerequisite("GL_EXT_disjoint_timer_query");
}
if (param.testID == RestrictedTraceID::dragon_ball_legends)
{
addExtensionPrerequisite("GL_KHR_texture_compression_astc_ldr");
}
if (param.testID == RestrictedTraceID::lego_legacy)
{
addExtensionPrerequisite("GL_EXT_shadow_samplers");
}
if (param.testID == RestrictedTraceID::world_war_doh)
{
// Linux+Nvidia doesn't support GL_KHR_texture_compression_astc_ldr (possibly others also)
addExtensionPrerequisite("GL_KHR_texture_compression_astc_ldr");
}
if (param.testID == RestrictedTraceID::saint_seiya_awakening)
{
addExtensionPrerequisite("GL_EXT_shadow_samplers");
// TODO(https://anglebug.com/5517) Linux+Intel generates "Framebuffer is incomplete" errors.
if (IsLinux() && IsIntel() && param.getRenderer() == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE)
{
mSkipTest = true;
}
}
if (param.testID == RestrictedTraceID::magic_tiles_3)
{
// Linux+Nvidia doesn't support GL_KHR_texture_compression_astc_ldr (possibly others also)
addExtensionPrerequisite("GL_KHR_texture_compression_astc_ldr");
}
if (param.testID == RestrictedTraceID::real_gangster_crime)
{
// Linux+Nvidia doesn't support GL_KHR_texture_compression_astc_ldr (possibly others also)
addExtensionPrerequisite("GL_KHR_texture_compression_astc_ldr");
}
if (param.testID == RestrictedTraceID::asphalt_8)
{
addExtensionPrerequisite("GL_KHR_texture_compression_astc_ldr");
}
if (param.testID == RestrictedTraceID::hearthstone)
{
addExtensionPrerequisite("GL_KHR_texture_compression_astc_ldr");
}
if (param.testID == RestrictedTraceID::efootball_pes_2021)
{
// TODO(https://anglebug.com/5517) Linux+Intel and Pixel 2 generate "Framebuffer is
// incomplete" errors with the Vulkan backend.
if (param.getRenderer() == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE &&
((IsLinux() && IsIntel()) || IsPixel2()))
{
mSkipTest = true;
}
}
if (param.testID == RestrictedTraceID::manhattan_31)
{
// TODO: http://anglebug.com/5591 Trace crashes on Pixel 2 in vulkan driver
if (IsPixel2() && param.getRenderer() == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE)
{
mSkipTest = true;
}
}
if (param.testID == RestrictedTraceID::shadow_fight_2)
{
addExtensionPrerequisite("GL_OES_EGL_image_external");
addExtensionPrerequisite("GL_KHR_texture_compression_astc_ldr");
}
if (param.testID == RestrictedTraceID::rise_of_kingdoms)
{
addExtensionPrerequisite("GL_OES_EGL_image_external");
}
if (param.testID == RestrictedTraceID::happy_color)
{
if (IsWindows() && IsAMD() && param.getRenderer() == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE)
{
mSkipTest = true;
}
}
if (param.testID == RestrictedTraceID::bus_simulator_indonesia)
{
// TODO(https://anglebug.com/5629) Linux+(Intel|AMD) native GLES generates
// GL_INVALID_OPERATION
if (IsLinux() && (IsIntel() || IsAMD()) &&
param.getRenderer() != EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE)
{
mSkipTest = true;
}
}
if (param.testID == RestrictedTraceID::messenger_lite)
{
// TODO: https://anglebug.com/5663 Incorrect pixels on Nvidia Windows for first frame
if (IsWindows() && IsNVIDIA() &&
param.getRenderer() == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE)
{
mSkipTest = true;
}
}
// We already swap in TracePerfTest::drawBenchmark, no need to swap again in the harness.
disableTestHarnessSwap();
gCurrentTracePerfTest = this;
}
void TracePerfTest::initializeBenchmark()
{
const auto ¶ms = GetParam();
mStartingDirectory = angle::GetCWD().value();
// To load the trace data path correctly we set the CWD to the executable dir.
if (!IsAndroid())
{
std::string exeDir = angle::GetExecutableDirectory();
angle::SetCWD(exeDir.c_str());
}
trace_angle::LoadGLES(TraceLoadProc);
const TraceInfo &traceInfo = GetTraceInfo(params.testID);
mStartFrame = traceInfo.startFrame;
mEndFrame = traceInfo.endFrame;
SetBinaryDataDecompressCallback(params.testID, DecompressBinaryData);
std::string relativeTestDataDir = std::string("src/tests/restricted_traces/") + traceInfo.name;
constexpr size_t kMaxDataDirLen = 1000;
char testDataDir[kMaxDataDirLen];
if (!angle::FindTestDataPath(relativeTestDataDir.c_str(), testDataDir, kMaxDataDirLen))
{
ERR() << "Could not find test data folder.";
mSkipTest = true;
}
SetBinaryDataDir(params.testID, testDataDir);
mWindowWidth = mTestParams.windowWidth;
mWindowHeight = mTestParams.windowHeight;
mCurrentFrame = mStartFrame;
if (IsAndroid())
{
// On Android, set the orientation used by the app, based on width/height
getWindow()->setOrientation(mTestParams.windowWidth, mTestParams.windowHeight);
}
// If we're rendering offscreen we set up a default backbuffer.
if (params.surfaceType == SurfaceType::Offscreen)
{
if (!IsAndroid())
{
mWindowWidth *= 4;
mWindowHeight *= 4;
}
glGenFramebuffers(1, &mOffscreenFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, mOffscreenFramebuffer);
// Hard-code RGBA8/D24S8. This should be specified in the trace info.
glGenTextures(1, &mOffscreenTexture);
glBindTexture(GL_TEXTURE_2D, mOffscreenTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mWindowWidth, mWindowHeight, 0, GL_RGBA,
GL_UNSIGNED_BYTE, nullptr);
glGenRenderbuffers(1, &mOffscreenDepthStencil);
glBindRenderbuffer(GL_RENDERBUFFER, mOffscreenDepthStencil);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, mWindowWidth, mWindowHeight);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
mOffscreenTexture, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
mOffscreenDepthStencil);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
mOffscreenDepthStencil);
glBindTexture(GL_TEXTURE_2D, 0);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
}
// Potentially slow. Can load a lot of resources.
SetupReplay(params.testID);
glFinish();
ASSERT_TRUE(mEndFrame > mStartFrame);
getWindow()->ignoreSizeEvents();
getWindow()->setVisible(true);
// If we're re-tracing, trigger capture start after setup. This ensures the Setup function gets
// recaptured into another Setup function and not merged with the first frame.
if (angle::gStartTraceAfterSetup)
{
angle::SetEnvironmentVar("ANGLE_CAPTURE_TRIGGER", "0");
getGLWindow()->swap();
}
}
#undef TRACE_TEST_CASE
void TracePerfTest::destroyBenchmark()
{
if (mOffscreenTexture != 0)
{
glDeleteTextures(1, &mOffscreenTexture);
mOffscreenTexture = 0;
}
if (mOffscreenDepthStencil != 0)
{
glDeleteRenderbuffers(1, &mOffscreenDepthStencil);
mOffscreenDepthStencil = 0;
}
if (mOffscreenFramebuffer != 0)
{
glDeleteFramebuffers(1, &mOffscreenFramebuffer);
mOffscreenFramebuffer = 0;
}
// In order for the next test to load, restore the working directory
angle::SetCWD(mStartingDirectory.c_str());
}
void TracePerfTest::sampleTime()
{
if (mUseTimestampQueries)
{
GLint64 glTime;
// glGetInteger64vEXT is exported by newer versions of the timer query extensions.
// Unfortunately only the core EP is exposed by some desktop drivers (e.g. NVIDIA).
if (glGetInteger64vEXT)
{
glGetInteger64vEXT(GL_TIMESTAMP_EXT, &glTime);
}
else
{
glGetInteger64v(GL_TIMESTAMP_EXT, &glTime);
}
mTimeline.push_back({glTime, angle::GetHostTimeSeconds()});
}
}
void TracePerfTest::drawBenchmark()
{
constexpr uint32_t kFramesPerX = 6;
constexpr uint32_t kFramesPerY = 4;
constexpr uint32_t kFramesPerXY = kFramesPerY * kFramesPerX;
const uint32_t kOffscreenOffsetX =
static_cast<uint32_t>(static_cast<double>(mTestParams.windowWidth) / 3.0f);
const uint32_t kOffscreenOffsetY =
static_cast<uint32_t>(static_cast<double>(mTestParams.windowHeight) / 3.0f);
const uint32_t kOffscreenWidth = kOffscreenOffsetX;
const uint32_t kOffscreenHeight = kOffscreenOffsetY;
const uint32_t kOffscreenFrameWidth = static_cast<uint32_t>(
static_cast<double>(kOffscreenWidth / static_cast<double>(kFramesPerX)));
const uint32_t kOffscreenFrameHeight = static_cast<uint32_t>(
static_cast<double>(kOffscreenHeight / static_cast<double>(kFramesPerY)));
const TracePerfParams ¶ms = GetParam();
// Add a time sample from GL and the host.
if (mCurrentFrame == mStartFrame)
{
sampleTime();
}
char frameName[32];
sprintf(frameName, "Frame %u", mCurrentFrame);
beginInternalTraceEvent(frameName);
startGpuTimer();
ReplayFrame(params.testID, mCurrentFrame);
stopGpuTimer();
if (params.surfaceType == SurfaceType::Offscreen)
{
GLint currentDrawFBO, currentReadFBO;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤tDrawFBO);
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, ¤tReadFBO);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBindFramebuffer(GL_READ_FRAMEBUFFER, mOffscreenFramebuffer);
uint32_t frameX = (mOffscreenFrameCount % kFramesPerXY) % kFramesPerX;
uint32_t frameY = (mOffscreenFrameCount % kFramesPerXY) / kFramesPerX;
uint32_t windowX = kOffscreenOffsetX + frameX * kOffscreenFrameWidth;
uint32_t windowY = kOffscreenOffsetY + frameY * kOffscreenFrameHeight;
if (gVerboseLogging)
{
printf("Frame %d: x %d y %d (screen x %d, screen y %d)\n", mOffscreenFrameCount, frameX,
frameY, windowX, windowY);
}
GLboolean scissorTest = GL_FALSE;
glGetBooleanv(GL_SCISSOR_TEST, &scissorTest);
if (scissorTest)
{
glDisable(GL_SCISSOR_TEST);
}
glBlitFramebuffer(0, 0, mWindowWidth, mWindowHeight, windowX, windowY,
windowX + kOffscreenFrameWidth, windowY + kOffscreenFrameHeight,
GL_COLOR_BUFFER_BIT, GL_NEAREST);
if (frameX == kFramesPerX - 1 && frameY == kFramesPerY - 1)
{
swap();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClear(GL_COLOR_BUFFER_BIT);
mOffscreenFrameCount = 0;
}
else
{
mOffscreenFrameCount++;
}
if (scissorTest)
{
glEnable(GL_SCISSOR_TEST);
}
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, currentDrawFBO);
glBindFramebuffer(GL_READ_FRAMEBUFFER, currentReadFBO);
}
else
{
swap();
}
endInternalTraceEvent(frameName);
if (mCurrentFrame == mEndFrame)
{
ResetReplay(params.testID);
mCurrentFrame = mStartFrame;
}
else
{
mCurrentFrame++;
}
// Process any running queries once per iteration.
for (size_t queryIndex = 0; queryIndex < mRunningQueries.size();)
{
const QueryInfo &query = mRunningQueries[queryIndex];
GLuint endResultAvailable = 0;
glGetQueryObjectuivEXT(query.endTimestampQuery, GL_QUERY_RESULT_AVAILABLE,
&endResultAvailable);
if (endResultAvailable == GL_TRUE)
{
char fboName[32];
sprintf(fboName, "FBO %u", query.framebuffer);
GLint64 beginTimestamp = 0;
glGetQueryObjecti64vEXT(query.beginTimestampQuery, GL_QUERY_RESULT, &beginTimestamp);
glDeleteQueriesEXT(1, &query.beginTimestampQuery);
double beginHostTime = getHostTimeFromGLTime(beginTimestamp);
beginGLTraceEvent(fboName, beginHostTime);
GLint64 endTimestamp = 0;
glGetQueryObjecti64vEXT(query.endTimestampQuery, GL_QUERY_RESULT, &endTimestamp);
glDeleteQueriesEXT(1, &query.endTimestampQuery);
double endHostTime = getHostTimeFromGLTime(endTimestamp);
endGLTraceEvent(fboName, endHostTime);
mRunningQueries.erase(mRunningQueries.begin() + queryIndex);
}
else
{
queryIndex++;
}
}
}
// Converts a GL timestamp into a host-side CPU time aligned with "GetHostTimeSeconds".
// This check is necessary to line up sampled trace events in a consistent timeline.
// Uses a linear interpolation from a series of samples. We do a blocking call to sample
// both host and GL time once per swap. We then find the two closest GL timestamps and
// interpolate the host times between them to compute our result. If we are past the last
// GL timestamp we sample a new data point pair.
double TracePerfTest::getHostTimeFromGLTime(GLint64 glTime)
{
// Find two samples to do a lerp.
size_t firstSampleIndex = mTimeline.size() - 1;
while (firstSampleIndex > 0)
{
if (mTimeline[firstSampleIndex].glTime < glTime)
{
break;
}
firstSampleIndex--;
}
// Add an extra sample if we're missing an ending sample.
if (firstSampleIndex == mTimeline.size() - 1)
{
sampleTime();
}
const TimeSample &start = mTimeline[firstSampleIndex];
const TimeSample &end = mTimeline[firstSampleIndex + 1];
// Note: we have observed in some odd cases later timestamps producing values that are
// smaller than preceding timestamps. This bears further investigation.
// Compute the scaling factor for the lerp.
double glDelta = static_cast<double>(glTime - start.glTime);
double glRange = static_cast<double>(end.glTime - start.glTime);
double t = glDelta / glRange;
// Lerp(t1, t2, t)
double hostRange = end.hostTime - start.hostTime;
return mTimeline[firstSampleIndex].hostTime + hostRange * t;
}
// Triggered when the replay calls glBindFramebuffer.
void TracePerfTest::onReplayFramebufferChange(GLenum target, GLuint framebuffer)
{
if (framebuffer == 0 && GetParam().surfaceType == SurfaceType::Offscreen)
{
glBindFramebuffer(target, mOffscreenFramebuffer);
}
else
{
glBindFramebuffer(target, framebuffer);
}
switch (target)
{
case GL_FRAMEBUFFER:
mDrawFramebufferBinding = framebuffer;
mReadFramebufferBinding = framebuffer;
break;
case GL_DRAW_FRAMEBUFFER:
mDrawFramebufferBinding = framebuffer;
break;
case GL_READ_FRAMEBUFFER:
mReadFramebufferBinding = framebuffer;
return;
default:
UNREACHABLE();
break;
}
if (!mUseTimestampQueries)
return;
// We have at most one active timestamp query at a time. This code will end the current
// query and immediately start a new one.
if (mCurrentQuery.beginTimestampQuery != 0)
{
glGenQueriesEXT(1, &mCurrentQuery.endTimestampQuery);
glQueryCounterEXT(mCurrentQuery.endTimestampQuery, GL_TIMESTAMP_EXT);
mRunningQueries.push_back(mCurrentQuery);
mCurrentQuery = {};
}
ASSERT(mCurrentQuery.beginTimestampQuery == 0);
glGenQueriesEXT(1, &mCurrentQuery.beginTimestampQuery);
glQueryCounterEXT(mCurrentQuery.beginTimestampQuery, GL_TIMESTAMP_EXT);
mCurrentQuery.framebuffer = framebuffer;
}
bool TracePerfTest::isDefaultFramebuffer(GLenum target) const
{
switch (target)
{
case GL_FRAMEBUFFER:
case GL_DRAW_FRAMEBUFFER:
return (mDrawFramebufferBinding == 0);
case GL_READ_FRAMEBUFFER:
return (mReadFramebufferBinding == 0);
default:
UNREACHABLE();
return false;
}
}
GLenum ConvertDefaultFramebufferEnum(GLenum value)
{
switch (value)
{
case GL_NONE:
return GL_NONE;
case GL_BACK:
case GL_COLOR:
return GL_COLOR_ATTACHMENT0;
case GL_DEPTH:
return GL_DEPTH_ATTACHMENT;
case GL_STENCIL:
return GL_STENCIL_ATTACHMENT;
case GL_DEPTH_STENCIL:
return GL_DEPTH_STENCIL_ATTACHMENT;
default:
UNREACHABLE();
return GL_NONE;
}
}
std::vector<GLenum> ConvertDefaultFramebufferEnums(GLsizei numAttachments,
const GLenum *attachments)
{
std::vector<GLenum> translatedAttachments;
for (GLsizei attachmentIndex = 0; attachmentIndex < numAttachments; ++attachmentIndex)
{
GLenum converted = ConvertDefaultFramebufferEnum(attachments[attachmentIndex]);
translatedAttachments.push_back(converted);
}
return translatedAttachments;
}
// Needs special handling to treat the 0 framebuffer in offscreen mode.
void TracePerfTest::onReplayInvalidateFramebuffer(GLenum target,
GLsizei numAttachments,
const GLenum *attachments)
{
if (GetParam().surfaceType != SurfaceType::Offscreen || !isDefaultFramebuffer(target))
{
glInvalidateFramebuffer(target, numAttachments, attachments);
}
else
{
std::vector<GLenum> translatedAttachments =
ConvertDefaultFramebufferEnums(numAttachments, attachments);
glInvalidateFramebuffer(target, numAttachments, translatedAttachments.data());
}
}
void TracePerfTest::onReplayInvalidateSubFramebuffer(GLenum target,
GLsizei numAttachments,
const GLenum *attachments,
GLint x,
GLint y,
GLsizei width,
GLsizei height)
{
if (GetParam().surfaceType != SurfaceType::Offscreen || !isDefaultFramebuffer(target))
{
glInvalidateSubFramebuffer(target, numAttachments, attachments, x, y, width, height);
}
else
{
std::vector<GLenum> translatedAttachments =
ConvertDefaultFramebufferEnums(numAttachments, attachments);
glInvalidateSubFramebuffer(target, numAttachments, translatedAttachments.data(), x, y,
width, height);
}
}
void TracePerfTest::onReplayDrawBuffers(GLsizei n, const GLenum *bufs)
{
if (GetParam().surfaceType != SurfaceType::Offscreen ||
!isDefaultFramebuffer(GL_DRAW_FRAMEBUFFER))
{
glDrawBuffers(n, bufs);
}
else
{
std::vector<GLenum> translatedBufs = ConvertDefaultFramebufferEnums(n, bufs);
glDrawBuffers(n, translatedBufs.data());
}
}
void TracePerfTest::onReplayReadBuffer(GLenum src)
{
if (GetParam().surfaceType != SurfaceType::Offscreen ||
!isDefaultFramebuffer(GL_READ_FRAMEBUFFER))
{
glReadBuffer(src);
}
else
{
GLenum translated = ConvertDefaultFramebufferEnum(src);
glReadBuffer(translated);
}
}
void TracePerfTest::onReplayDiscardFramebufferEXT(GLenum target,
GLsizei numAttachments,
const GLenum *attachments)
{
if (GetParam().surfaceType != SurfaceType::Offscreen || !isDefaultFramebuffer(target))
{
glDiscardFramebufferEXT(target, numAttachments, attachments);
}
else
{
std::vector<GLenum> translatedAttachments =
ConvertDefaultFramebufferEnums(numAttachments, attachments);
glDiscardFramebufferEXT(target, numAttachments, translatedAttachments.data());
}
}
void TracePerfTest::swap()
{
// Capture a screenshot if enabled.
if (gScreenShotDir != nullptr && !mScreenshotSaved)
{
std::stringstream screenshotNameStr;
screenshotNameStr << gScreenShotDir << GetPathSeparator() << "angle" << mBackend << "_"
<< mStory << ".png";
std::string screenshotName = screenshotNameStr.str();
saveScreenshot(screenshotName);
mScreenshotSaved = true;
}
getGLWindow()->swap();
}
void TracePerfTest::saveScreenshot(const std::string &screenshotName)
{
// The frame is already rendered and is waiting in the default framebuffer.
// RGBA 4-byte data.
uint32_t pixelCount = mTestParams.windowWidth * mTestParams.windowHeight;
std::vector<uint8_t> pixelData(pixelCount * 4);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glReadPixels(0, 0, mTestParams.windowWidth, mTestParams.windowHeight, GL_RGBA, GL_UNSIGNED_BYTE,
pixelData.data());
// Convert to RGB and flip y.
std::vector<uint8_t> rgbData(pixelCount * 3);
for (EGLint y = 0; y < mTestParams.windowHeight; ++y)
{
for (EGLint x = 0; x < mTestParams.windowWidth; ++x)
{
EGLint srcPixel = x + y * mTestParams.windowWidth;
EGLint dstPixel = x + (mTestParams.windowHeight - y - 1) * mTestParams.windowWidth;
memcpy(&rgbData[dstPixel * 3], &pixelData[srcPixel * 4], 3);
}
}
if (!angle::SavePNGRGB(screenshotName.c_str(), "ANGLE Screenshot", mTestParams.windowWidth,
mTestParams.windowHeight, rgbData))
{
FAIL() << "Error saving screenshot: " << screenshotName;
}
else
{
printf("Saved screenshot: '%s'\n", screenshotName.c_str());
}
}
TEST_P(TracePerfTest, Run)
{
run();
}
TracePerfParams CombineTestID(const TracePerfParams &in, RestrictedTraceID id)
{
const TraceInfo &traceInfo = GetTraceInfo(id);
TracePerfParams out = in;
out.testID = id;
out.windowWidth = traceInfo.drawSurfaceWidth;
out.windowHeight = traceInfo.drawSurfaceHeight;
return out;
}
bool NoAndroidMockICD(const TracePerfParams &in)
{
return in.eglParameters.deviceType != EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE || !IsAndroid();
}
TracePerfParams CombineWithSurfaceType(const TracePerfParams &in, SurfaceType surfaceType)
{
TracePerfParams out = in;
out.surfaceType = surfaceType;
if (!IsAndroid() && surfaceType == SurfaceType::Offscreen)
{
out.windowWidth /= 4;
out.windowHeight /= 4;
}
// We track GPU time only in frame-rate-limited cases.
out.trackGpuTime = surfaceType == SurfaceType::WindowWithVSync;
return out;
}
using namespace params;
using P = TracePerfParams;
std::vector<P> gTestsWithID =
CombineWithValues({P()}, AllEnums<RestrictedTraceID>(), CombineTestID);
std::vector<P> gTestsWithSurfaceType =
CombineWithValues(gTestsWithID,
{SurfaceType::Offscreen, SurfaceType::Window, SurfaceType::WindowWithVSync},
CombineWithSurfaceType);
std::vector<P> gTestsWithRenderer =
CombineWithFuncs(gTestsWithSurfaceType,
{Vulkan<P>, VulkanMockICD<P>, VulkanSwiftShader<P>, Native<P>});
std::vector<P> gTestsWithoutMockICD = FilterWithFunc(gTestsWithRenderer, NoAndroidMockICD);
ANGLE_INSTANTIATE_TEST_ARRAY(TracePerfTest, gTestsWithoutMockICD);
} // anonymous namespace