Hash :
0f566fc7
Author :
Date :
2019-03-20T11:36:29
Introduce ConfigParameters test helper struct. This allows us to more easily compare sets of parameters used in our tests. The config parameters are stuff like the red / gree / blue bits used in an EGL config. Or particular sets of extensions or other EGL options. This will more easily allow us to determine when we need to use a new EGL display instead of reusing a prior. Bug: angleproject:3261 Change-Id: Ia1f0ede988e0b4084fbb4d55097e94fd89ee4899 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1531535 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Yuly Novikov <ynovikov@chromium.org>
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
//
// Copyright (c) 2014 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.
//
// ANGLEPerfTests:
// Base class for google test performance tests
//
#include "ANGLEPerfTest.h"
#include "ANGLEPerfTestArgs.h"
#include "common/platform.h"
#include "third_party/perf/perf_test.h"
#include "util/shader_utils.h"
#include "util/system_utils.h"
#include <cassert>
#include <cmath>
#include <fstream>
#include <iostream>
#include <sstream>
#include <json/json.h>
#if defined(ANGLE_USE_UTIL_LOADER) && defined(ANGLE_PLATFORM_WINDOWS)
# include "util/windows/WGLWindow.h"
#endif // defined(ANGLE_USE_UTIL_LOADER) &&defined(ANGLE_PLATFORM_WINDOWS)
using namespace angle;
namespace
{
constexpr size_t kInitialTraceEventBufferSize = 50000;
constexpr double kMicroSecondsPerSecond = 1e6;
constexpr double kNanoSecondsPerSecond = 1e9;
constexpr double kCalibrationRunTimeSeconds = 1.0;
constexpr double kMaximumRunTimeSeconds = 10.0;
constexpr unsigned int kNumTrials = 3;
struct TraceCategory
{
unsigned char enabled;
const char *name;
};
constexpr TraceCategory gTraceCategories[2] = {
{1, "gpu.angle"},
{1, "gpu.angle.gpu"},
};
void EmptyPlatformMethod(angle::PlatformMethods *, const char *) {}
void OverrideWorkaroundsD3D(angle::PlatformMethods *platform, angle::WorkaroundsD3D *workaroundsD3D)
{
auto *angleRenderTest = static_cast<ANGLERenderTest *>(platform->context);
angleRenderTest->overrideWorkaroundsD3D(workaroundsD3D);
}
angle::TraceEventHandle AddTraceEvent(angle::PlatformMethods *platform,
char phase,
const unsigned char *categoryEnabledFlag,
const char *name,
unsigned long long id,
double timestamp,
int numArgs,
const char **argNames,
const unsigned char *argTypes,
const unsigned long long *argValues,
unsigned char flags)
{
if (!gEnableTrace)
return 0;
// Discover the category name based on categoryEnabledFlag. This flag comes from the first
// parameter of TraceCategory, and corresponds to one of the entries in gTraceCategories.
static_assert(offsetof(TraceCategory, enabled) == 0,
"|enabled| must be the first field of the TraceCategory class.");
const TraceCategory *category = reinterpret_cast<const TraceCategory *>(categoryEnabledFlag);
ANGLERenderTest *renderTest = static_cast<ANGLERenderTest *>(platform->context);
std::vector<TraceEvent> &buffer = renderTest->getTraceEventBuffer();
buffer.emplace_back(phase, category->name, name, timestamp);
return buffer.size();
}
const unsigned char *GetTraceCategoryEnabledFlag(angle::PlatformMethods *platform,
const char *categoryName)
{
if (gEnableTrace)
{
for (const TraceCategory &category : gTraceCategories)
{
if (strcmp(category.name, categoryName) == 0)
{
return &category.enabled;
}
}
}
constexpr static unsigned char kZero = 0;
return &kZero;
}
void UpdateTraceEventDuration(angle::PlatformMethods *platform,
const unsigned char *categoryEnabledFlag,
const char *name,
angle::TraceEventHandle eventHandle)
{
// Not implemented.
}
double MonotonicallyIncreasingTime(angle::PlatformMethods *platform)
{
ANGLERenderTest *renderTest = static_cast<ANGLERenderTest *>(platform->context);
// Move the time origin to the first call to this function, to avoid generating unnecessarily
// large timestamps.
static double origin = renderTest->getTimer()->getAbsoluteTime();
return renderTest->getTimer()->getAbsoluteTime() - origin;
}
void DumpTraceEventsToJSONFile(const std::vector<TraceEvent> &traceEvents,
const char *outputFileName)
{
Json::Value eventsValue(Json::arrayValue);
for (const TraceEvent &traceEvent : traceEvents)
{
Json::Value value(Json::objectValue);
std::stringstream phaseName;
phaseName << traceEvent.phase;
unsigned long long microseconds =
static_cast<unsigned long long>(traceEvent.timestamp * 1000.0 * 1000.0);
value["name"] = traceEvent.name;
value["cat"] = traceEvent.categoryName;
value["ph"] = phaseName.str();
value["ts"] = microseconds;
value["pid"] = "ANGLE";
value["tid"] = strcmp(traceEvent.categoryName, "gpu.angle.gpu") == 0 ? "GPU" : "CPU";
eventsValue.append(value);
}
Json::Value root(Json::objectValue);
root["traceEvents"] = eventsValue;
std::ofstream outFile;
outFile.open(outputFileName);
Json::StyledWriter styledWrite;
outFile << styledWrite.write(root);
outFile.close();
}
} // anonymous namespace
ANGLEPerfTest::ANGLEPerfTest(const std::string &name,
const std::string &suffix,
unsigned int iterationsPerStep)
: mName(name),
mSuffix(suffix),
mTimer(CreateTimer()),
mGPUTimeNs(0),
mSkipTest(false),
mStepsToRun(std::numeric_limits<unsigned int>::max()),
mNumStepsPerformed(0),
mIterationsPerStep(iterationsPerStep),
mRunning(true)
{}
ANGLEPerfTest::~ANGLEPerfTest()
{
SafeDelete(mTimer);
}
void ANGLEPerfTest::run()
{
if (mSkipTest)
{
return;
}
// Calibrate to a fixed number of steps during an initial set time.
if (!gStepsToRunOverride.valid())
{
doRunLoop(kCalibrationRunTimeSeconds);
// Scale steps down according to the time that exeeded one second.
double scale = kCalibrationRunTimeSeconds / mTimer->getElapsedTime();
mStepsToRun = static_cast<size_t>(static_cast<double>(mNumStepsPerformed) * scale);
// Calibration allows the perf test runner script to save some time.
if (gCalibration)
{
printResult("steps", static_cast<size_t>(mStepsToRun), "count", false);
return;
}
}
else
{
mStepsToRun = gStepsToRunOverride.value();
}
// Do another warmup run. Seems to consistently improve results.
doRunLoop(kMaximumRunTimeSeconds);
double totalTime = 0.0;
for (unsigned int trial = 0; trial < kNumTrials; ++trial)
{
doRunLoop(kMaximumRunTimeSeconds);
totalTime += printResults();
}
double average = totalTime / kNumTrials;
std::ostringstream averageString;
averageString << "for " << kNumTrials << " runs";
printResult("average", average, averageString.str(), false);
}
void ANGLEPerfTest::doRunLoop(double maxRunTime)
{
mNumStepsPerformed = 0;
mRunning = true;
mTimer->start();
startTest();
while (mRunning)
{
step();
if (mRunning)
{
++mNumStepsPerformed;
if (mTimer->getElapsedTime() > maxRunTime)
{
mRunning = false;
}
else if (mNumStepsPerformed >= mStepsToRun)
{
mRunning = false;
}
}
}
finishTest();
mTimer->stop();
}
void ANGLEPerfTest::printResult(const std::string &trace,
double value,
const std::string &units,
bool important) const
{
perf_test::PrintResult(mName, mSuffix, trace, value, units, important);
}
void ANGLEPerfTest::printResult(const std::string &trace,
size_t value,
const std::string &units,
bool important) const
{
perf_test::PrintResult(mName, mSuffix, trace, value, units, important);
}
void ANGLEPerfTest::SetUp() {}
void ANGLEPerfTest::TearDown() {}
double ANGLEPerfTest::printResults()
{
double elapsedTimeSeconds[2] = {
mTimer->getElapsedTime(),
mGPUTimeNs * 1e-9,
};
const char *clockNames[2] = {
"wall_time",
"gpu_time",
};
// If measured gpu time is non-zero, print that too.
size_t clocksToOutput = mGPUTimeNs > 0 ? 2 : 1;
double retValue = 0.0;
for (size_t i = 0; i < clocksToOutput; ++i)
{
double secondsPerStep = elapsedTimeSeconds[i] / static_cast<double>(mNumStepsPerformed);
double secondsPerIteration = secondsPerStep / static_cast<double>(mIterationsPerStep);
// Give the result a different name to ensure separate graphs if we transition.
if (secondsPerIteration > 1e-3)
{
double microSecondsPerIteration = secondsPerIteration * kMicroSecondsPerSecond;
retValue = microSecondsPerIteration;
printResult(clockNames[i], microSecondsPerIteration, "us", true);
}
else
{
double nanoSecPerIteration = secondsPerIteration * kNanoSecondsPerSecond;
retValue = nanoSecPerIteration;
printResult(clockNames[i], nanoSecPerIteration, "ns", true);
}
}
return retValue;
}
double ANGLEPerfTest::normalizedTime(size_t value) const
{
return static_cast<double>(value) / static_cast<double>(mNumStepsPerformed);
}
std::string RenderTestParams::suffix() const
{
switch (driver)
{
case angle::GLESDriverType::AngleEGL:
break;
case angle::GLESDriverType::SystemEGL:
return "_native";
case angle::GLESDriverType::SystemWGL:
return "_wgl";
default:
assert(0);
return "_unk";
}
switch (getRenderer())
{
case EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE:
return "_d3d11";
case EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE:
return "_d3d9";
case EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE:
return "_gl";
case EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE:
return "_gles";
case EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE:
return "_default";
case EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE:
return "_vulkan";
default:
assert(0);
return "_unk";
}
}
ANGLERenderTest::ANGLERenderTest(const std::string &name, const RenderTestParams &testParams)
: ANGLEPerfTest(name, testParams.suffix(), OneFrame() ? 1 : testParams.iterationsPerStep),
mTestParams(testParams),
mGLWindow(nullptr),
mOSWindow(nullptr)
{
// Force fast tests to make sure our slowest bots don't time out.
if (OneFrame())
{
const_cast<RenderTestParams &>(testParams).iterationsPerStep = 1;
}
// Try to ensure we don't trigger allocation during execution.
mTraceEventBuffer.reserve(kInitialTraceEventBufferSize);
switch (testParams.driver)
{
case angle::GLESDriverType::AngleEGL:
mGLWindow = createEGLWindow(testParams);
mEntryPointsLib.reset(angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME));
break;
case angle::GLESDriverType::SystemEGL:
std::cerr << "Not implemented." << std::endl;
mSkipTest = true;
break;
case angle::GLESDriverType::SystemWGL:
#if defined(ANGLE_USE_UTIL_LOADER) && defined(ANGLE_PLATFORM_WINDOWS)
mGLWindow = WGLWindow::New(testParams.majorVersion, testParams.minorVersion);
mEntryPointsLib.reset(angle::OpenSharedLibrary("opengl32"));
#else
std::cout << "WGL driver not available. Skipping test." << std::endl;
mSkipTest = true;
#endif // defined(ANGLE_USE_UTIL_LOADER) && defined(ANGLE_PLATFORM_WINDOWS)
break;
default:
std::cerr << "Error in switch." << std::endl;
mSkipTest = true;
break;
}
}
ANGLERenderTest::~ANGLERenderTest()
{
OSWindow::Delete(&mOSWindow);
GLWindowBase::Delete(&mGLWindow);
}
void ANGLERenderTest::addExtensionPrerequisite(const char *extensionName)
{
mExtensionPrerequisites.push_back(extensionName);
}
void ANGLERenderTest::SetUp()
{
if (mSkipTest)
{
return;
}
ANGLEPerfTest::SetUp();
// Set a consistent CPU core affinity and high priority.
angle::StabilizeCPUForBenchmarking();
mOSWindow = OSWindow::New();
if (!mGLWindow)
{
mSkipTest = true;
return;
}
// Disable vsync.
mConfigParams.swapInterval = 0;
mPlatformMethods.overrideWorkaroundsD3D = OverrideWorkaroundsD3D;
mPlatformMethods.logError = EmptyPlatformMethod;
mPlatformMethods.logWarning = EmptyPlatformMethod;
mPlatformMethods.logInfo = EmptyPlatformMethod;
mPlatformMethods.addTraceEvent = AddTraceEvent;
mPlatformMethods.getTraceCategoryEnabledFlag = GetTraceCategoryEnabledFlag;
mPlatformMethods.updateTraceEventDuration = UpdateTraceEventDuration;
mPlatformMethods.monotonicallyIncreasingTime = MonotonicallyIncreasingTime;
mPlatformMethods.context = this;
mConfigParams.platformMethods = &mPlatformMethods;
if (!mOSWindow->initialize(mName, mTestParams.windowWidth, mTestParams.windowHeight))
{
mSkipTest = true;
FAIL() << "Failed initializing OSWindow";
// FAIL returns.
}
if (!mGLWindow->initializeGL(mOSWindow, mEntryPointsLib.get(), mConfigParams))
{
mSkipTest = true;
FAIL() << "Failed initializing GL Window";
// FAIL returns.
}
if (!areExtensionPrerequisitesFulfilled())
{
mSkipTest = true;
}
if (mSkipTest)
{
return;
}
initializeBenchmark();
if (mTestParams.iterationsPerStep == 0)
{
mSkipTest = true;
FAIL() << "Please initialize 'iterationsPerStep'.";
// FAIL returns.
}
}
void ANGLERenderTest::TearDown()
{
if (!mSkipTest)
{
destroyBenchmark();
}
if (mGLWindow)
{
mGLWindow->destroyGL();
mGLWindow = nullptr;
}
if (mOSWindow)
{
mOSWindow->destroy();
mOSWindow = nullptr;
}
// Dump trace events to json file.
if (gEnableTrace)
{
DumpTraceEventsToJSONFile(mTraceEventBuffer, gTraceFile);
}
ANGLEPerfTest::TearDown();
}
void ANGLERenderTest::step()
{
// Clear events that the application did not process from this frame
Event event;
bool closed = false;
while (popEvent(&event))
{
// If the application did not catch a close event, close now
if (event.Type == Event::EVENT_CLOSED)
{
closed = true;
}
}
if (closed)
{
abortTest();
}
else
{
drawBenchmark();
// Swap is needed so that the GPU driver will occasionally flush its
// internal command queue to the GPU. This is enabled for null back-end
// devices because some back-ends (e.g. Vulkan) also accumulate internal
// command queues.
mGLWindow->swap();
mOSWindow->messageLoop();
}
}
void ANGLERenderTest::startGpuTimer()
{
if (mTestParams.trackGpuTime)
{
glBeginQueryEXT(GL_TIME_ELAPSED_EXT, mTimestampQuery);
}
}
void ANGLERenderTest::stopGpuTimer()
{
if (mTestParams.trackGpuTime)
{
glEndQueryEXT(GL_TIME_ELAPSED_EXT);
uint64_t gpuTimeNs = 0;
glGetQueryObjectui64vEXT(mTimestampQuery, GL_QUERY_RESULT_EXT, &gpuTimeNs);
mGPUTimeNs += gpuTimeNs;
}
}
void ANGLERenderTest::startTest()
{
if (mTestParams.trackGpuTime)
{
glGenQueriesEXT(1, &mTimestampQuery);
mGPUTimeNs = 0;
}
}
void ANGLERenderTest::finishTest()
{
if (mTestParams.trackGpuTime)
{
glDeleteQueriesEXT(1, &mTimestampQuery);
}
if (mTestParams.eglParameters.deviceType != EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE)
{
glFinish();
}
}
bool ANGLERenderTest::popEvent(Event *event)
{
return mOSWindow->popEvent(event);
}
OSWindow *ANGLERenderTest::getWindow()
{
return mOSWindow;
}
bool ANGLERenderTest::areExtensionPrerequisitesFulfilled() const
{
for (const char *extension : mExtensionPrerequisites)
{
if (!CheckExtensionExists(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)),
extension))
{
std::cout << "Test skipped due to missing extension: " << extension << std::endl;
return false;
}
}
return true;
}
void ANGLERenderTest::setWebGLCompatibilityEnabled(bool webglCompatibility)
{
mConfigParams.webGLCompatibility = webglCompatibility;
}
void ANGLERenderTest::setRobustResourceInit(bool enabled)
{
mConfigParams.robustResourceInit = enabled;
}
std::vector<TraceEvent> &ANGLERenderTest::getTraceEventBuffer()
{
return mTraceEventBuffer;
}
// static
EGLWindow *ANGLERenderTest::createEGLWindow(const RenderTestParams &testParams)
{
return EGLWindow::New(testParams.majorVersion, testParams.minorVersion,
testParams.eglParameters);
}