Path: blob/main_old/src/tests/perf_tests/EGLInitializePerf.cpp
1693 views
//1// Copyright 2015 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// EGLInitializePerfTest:6// Performance test for device creation.7//89#include "ANGLEPerfTest.h"10#include "platform/PlatformMethods.h"11#include "test_utils/angle_test_configs.h"12#include "test_utils/angle_test_instantiate.h"13#include "util/Timer.h"1415using namespace testing;1617namespace18{19// Only applies to D3D1120struct Captures final : private angle::NonCopyable21{22Timer timer;23size_t loadDLLsMS = 0;24size_t createDeviceMS = 0;25size_t initResourcesMS = 0;26};2728double CapturePlatform_currentTime(angle::PlatformMethods *platformMethods)29{30Captures *captures = static_cast<Captures *>(platformMethods->context);31return captures->timer.getElapsedTime();32}3334void CapturePlatform_histogramCustomCounts(angle::PlatformMethods *platformMethods,35const char *name,36int sample,37int /*min*/,38int /*max*/,39int /*bucketCount*/)40{41Captures *captures = static_cast<Captures *>(platformMethods->context);4243// These must match the names of the histograms.44if (strcmp(name, "GPU.ANGLE.Renderer11InitializeDLLsMS") == 0)45{46captures->loadDLLsMS += static_cast<size_t>(sample);47}48// Note: not captured in debug, due to creating a debug device49else if (strcmp(name, "GPU.ANGLE.D3D11CreateDeviceMS") == 0)50{51captures->createDeviceMS += static_cast<size_t>(sample);52}53else if (strcmp(name, "GPU.ANGLE.Renderer11InitializeDeviceMS") == 0)54{55captures->initResourcesMS += static_cast<size_t>(sample);56}57}5859class EGLInitializePerfTest : public ANGLEPerfTest,60public WithParamInterface<angle::PlatformParameters>61{62public:63EGLInitializePerfTest();64~EGLInitializePerfTest();6566void step() override;67void SetUp() override;68void TearDown() override;6970private:71OSWindow *mOSWindow;72EGLDisplay mDisplay;73Captures mCaptures;74};7576EGLInitializePerfTest::EGLInitializePerfTest()77: ANGLEPerfTest("EGLInitialize", "", "_run", 1), mOSWindow(nullptr), mDisplay(EGL_NO_DISPLAY)78{79auto platform = GetParam().eglParameters;8081std::vector<EGLint> displayAttributes;82displayAttributes.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE);83displayAttributes.push_back(platform.renderer);84displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE);85displayAttributes.push_back(platform.majorVersion);86displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE);87displayAttributes.push_back(platform.minorVersion);8889if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE ||90platform.renderer == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)91{92displayAttributes.push_back(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE);93displayAttributes.push_back(platform.deviceType);94}95displayAttributes.push_back(EGL_NONE);9697mOSWindow = OSWindow::New();98mOSWindow->initialize("EGLInitialize Test", 64, 64);99100auto eglGetPlatformDisplayEXT = reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(101eglGetProcAddress("eglGetPlatformDisplayEXT"));102if (eglGetPlatformDisplayEXT == nullptr)103{104std::cerr << "Error getting platform display!" << std::endl;105return;106}107108mDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE,109reinterpret_cast<void *>(mOSWindow->getNativeDisplay()),110&displayAttributes[0]);111}112113void EGLInitializePerfTest::SetUp()114{115ANGLEPerfTest::SetUp();116117angle::PlatformMethods *platformMethods = nullptr;118ASSERT_TRUE(ANGLEGetDisplayPlatform(mDisplay, angle::g_PlatformMethodNames,119angle::g_NumPlatformMethods, &mCaptures, &platformMethods));120121platformMethods->currentTime = CapturePlatform_currentTime;122platformMethods->histogramCustomCounts = CapturePlatform_histogramCustomCounts;123124mReporter->RegisterImportantMetric(".LoadDLLs", "ms");125mReporter->RegisterImportantMetric(".D3D11CreateDevice", "ms");126mReporter->RegisterImportantMetric(".InitResources", "ms");127}128129EGLInitializePerfTest::~EGLInitializePerfTest()130{131OSWindow::Delete(&mOSWindow);132}133134void EGLInitializePerfTest::step()135{136ASSERT_NE(EGL_NO_DISPLAY, mDisplay);137138EGLint majorVersion, minorVersion;139ASSERT_EQ(static_cast<EGLBoolean>(EGL_TRUE),140eglInitialize(mDisplay, &majorVersion, &minorVersion));141ASSERT_EQ(static_cast<EGLBoolean>(EGL_TRUE), eglTerminate(mDisplay));142}143144void EGLInitializePerfTest::TearDown()145{146ANGLEPerfTest::TearDown();147mReporter->AddResult(".LoadDLLs", normalizedTime(mCaptures.loadDLLsMS));148mReporter->AddResult(".D3D11CreateDevice", normalizedTime(mCaptures.createDeviceMS));149mReporter->AddResult(".InitResources", normalizedTime(mCaptures.initResourcesMS));150151ANGLEResetDisplayPlatform(mDisplay);152}153154TEST_P(EGLInitializePerfTest, Run)155{156run();157}158159ANGLE_INSTANTIATE_TEST(EGLInitializePerfTest, angle::ES2_D3D11(), angle::ES2_VULKAN());160161} // namespace162163164