1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker // EGLInitializePerfTest:
7*8975f5c5SAndroid Build Coastguard Worker // Performance test for device creation.
8*8975f5c5SAndroid Build Coastguard Worker //
9*8975f5c5SAndroid Build Coastguard Worker
10*8975f5c5SAndroid Build Coastguard Worker #include "ANGLEPerfTest.h"
11*8975f5c5SAndroid Build Coastguard Worker #include "platform/PlatformMethods.h"
12*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/angle_test_configs.h"
13*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/angle_test_instantiate.h"
14*8975f5c5SAndroid Build Coastguard Worker #include "util/Timer.h"
15*8975f5c5SAndroid Build Coastguard Worker
16*8975f5c5SAndroid Build Coastguard Worker using namespace testing;
17*8975f5c5SAndroid Build Coastguard Worker
18*8975f5c5SAndroid Build Coastguard Worker namespace
19*8975f5c5SAndroid Build Coastguard Worker {
20*8975f5c5SAndroid Build Coastguard Worker // Only applies to D3D11
21*8975f5c5SAndroid Build Coastguard Worker struct Captures final : private angle::NonCopyable
22*8975f5c5SAndroid Build Coastguard Worker {
23*8975f5c5SAndroid Build Coastguard Worker Timer timer;
24*8975f5c5SAndroid Build Coastguard Worker size_t loadDLLsMS = 0;
25*8975f5c5SAndroid Build Coastguard Worker size_t createDeviceMS = 0;
26*8975f5c5SAndroid Build Coastguard Worker size_t initResourcesMS = 0;
27*8975f5c5SAndroid Build Coastguard Worker };
28*8975f5c5SAndroid Build Coastguard Worker
CapturePlatform_currentTime(angle::PlatformMethods * platformMethods)29*8975f5c5SAndroid Build Coastguard Worker double CapturePlatform_currentTime(angle::PlatformMethods *platformMethods)
30*8975f5c5SAndroid Build Coastguard Worker {
31*8975f5c5SAndroid Build Coastguard Worker Captures *captures = static_cast<Captures *>(platformMethods->context);
32*8975f5c5SAndroid Build Coastguard Worker return captures->timer.getElapsedWallClockTime();
33*8975f5c5SAndroid Build Coastguard Worker }
34*8975f5c5SAndroid Build Coastguard Worker
CapturePlatform_histogramCustomCounts(angle::PlatformMethods * platformMethods,const char * name,int sample,int,int,int)35*8975f5c5SAndroid Build Coastguard Worker void CapturePlatform_histogramCustomCounts(angle::PlatformMethods *platformMethods,
36*8975f5c5SAndroid Build Coastguard Worker const char *name,
37*8975f5c5SAndroid Build Coastguard Worker int sample,
38*8975f5c5SAndroid Build Coastguard Worker int /*min*/,
39*8975f5c5SAndroid Build Coastguard Worker int /*max*/,
40*8975f5c5SAndroid Build Coastguard Worker int /*bucketCount*/)
41*8975f5c5SAndroid Build Coastguard Worker {
42*8975f5c5SAndroid Build Coastguard Worker Captures *captures = static_cast<Captures *>(platformMethods->context);
43*8975f5c5SAndroid Build Coastguard Worker
44*8975f5c5SAndroid Build Coastguard Worker // These must match the names of the histograms.
45*8975f5c5SAndroid Build Coastguard Worker if (strcmp(name, "GPU.ANGLE.Renderer11InitializeDLLsMS") == 0)
46*8975f5c5SAndroid Build Coastguard Worker {
47*8975f5c5SAndroid Build Coastguard Worker captures->loadDLLsMS += static_cast<size_t>(sample);
48*8975f5c5SAndroid Build Coastguard Worker }
49*8975f5c5SAndroid Build Coastguard Worker // Note: not captured in debug, due to creating a debug device
50*8975f5c5SAndroid Build Coastguard Worker else if (strcmp(name, "GPU.ANGLE.D3D11CreateDeviceMS") == 0)
51*8975f5c5SAndroid Build Coastguard Worker {
52*8975f5c5SAndroid Build Coastguard Worker captures->createDeviceMS += static_cast<size_t>(sample);
53*8975f5c5SAndroid Build Coastguard Worker }
54*8975f5c5SAndroid Build Coastguard Worker else if (strcmp(name, "GPU.ANGLE.Renderer11InitializeDeviceMS") == 0)
55*8975f5c5SAndroid Build Coastguard Worker {
56*8975f5c5SAndroid Build Coastguard Worker captures->initResourcesMS += static_cast<size_t>(sample);
57*8975f5c5SAndroid Build Coastguard Worker }
58*8975f5c5SAndroid Build Coastguard Worker }
59*8975f5c5SAndroid Build Coastguard Worker
60*8975f5c5SAndroid Build Coastguard Worker class EGLInitializePerfTest : public ANGLEPerfTest,
61*8975f5c5SAndroid Build Coastguard Worker public WithParamInterface<angle::PlatformParameters>
62*8975f5c5SAndroid Build Coastguard Worker {
63*8975f5c5SAndroid Build Coastguard Worker public:
64*8975f5c5SAndroid Build Coastguard Worker EGLInitializePerfTest();
65*8975f5c5SAndroid Build Coastguard Worker ~EGLInitializePerfTest();
66*8975f5c5SAndroid Build Coastguard Worker
67*8975f5c5SAndroid Build Coastguard Worker void step() override;
68*8975f5c5SAndroid Build Coastguard Worker void SetUp() override;
69*8975f5c5SAndroid Build Coastguard Worker void TearDown() override;
70*8975f5c5SAndroid Build Coastguard Worker
71*8975f5c5SAndroid Build Coastguard Worker private:
72*8975f5c5SAndroid Build Coastguard Worker OSWindow *mOSWindow;
73*8975f5c5SAndroid Build Coastguard Worker EGLDisplay mDisplay;
74*8975f5c5SAndroid Build Coastguard Worker Captures mCaptures;
75*8975f5c5SAndroid Build Coastguard Worker };
76*8975f5c5SAndroid Build Coastguard Worker
EGLInitializePerfTest()77*8975f5c5SAndroid Build Coastguard Worker EGLInitializePerfTest::EGLInitializePerfTest()
78*8975f5c5SAndroid Build Coastguard Worker : ANGLEPerfTest("EGLInitialize", "", "_run", 1), mOSWindow(nullptr), mDisplay(EGL_NO_DISPLAY)
79*8975f5c5SAndroid Build Coastguard Worker {
80*8975f5c5SAndroid Build Coastguard Worker auto platform = GetParam().eglParameters;
81*8975f5c5SAndroid Build Coastguard Worker
82*8975f5c5SAndroid Build Coastguard Worker std::vector<EGLint> displayAttributes;
83*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE);
84*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(platform.renderer);
85*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE);
86*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(platform.majorVersion);
87*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE);
88*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(platform.minorVersion);
89*8975f5c5SAndroid Build Coastguard Worker
90*8975f5c5SAndroid Build Coastguard Worker if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE ||
91*8975f5c5SAndroid Build Coastguard Worker platform.renderer == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
92*8975f5c5SAndroid Build Coastguard Worker {
93*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE);
94*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(platform.deviceType);
95*8975f5c5SAndroid Build Coastguard Worker }
96*8975f5c5SAndroid Build Coastguard Worker displayAttributes.push_back(EGL_NONE);
97*8975f5c5SAndroid Build Coastguard Worker
98*8975f5c5SAndroid Build Coastguard Worker mOSWindow = OSWindow::New();
99*8975f5c5SAndroid Build Coastguard Worker mOSWindow->initialize("EGLInitialize Test", 64, 64);
100*8975f5c5SAndroid Build Coastguard Worker
101*8975f5c5SAndroid Build Coastguard Worker auto eglGetPlatformDisplayEXT = reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(
102*8975f5c5SAndroid Build Coastguard Worker eglGetProcAddress("eglGetPlatformDisplayEXT"));
103*8975f5c5SAndroid Build Coastguard Worker if (eglGetPlatformDisplayEXT == nullptr)
104*8975f5c5SAndroid Build Coastguard Worker {
105*8975f5c5SAndroid Build Coastguard Worker std::cerr << "Error getting platform display!" << std::endl;
106*8975f5c5SAndroid Build Coastguard Worker return;
107*8975f5c5SAndroid Build Coastguard Worker }
108*8975f5c5SAndroid Build Coastguard Worker
109*8975f5c5SAndroid Build Coastguard Worker mDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE,
110*8975f5c5SAndroid Build Coastguard Worker reinterpret_cast<void *>(mOSWindow->getNativeDisplay()),
111*8975f5c5SAndroid Build Coastguard Worker &displayAttributes[0]);
112*8975f5c5SAndroid Build Coastguard Worker }
113*8975f5c5SAndroid Build Coastguard Worker
SetUp()114*8975f5c5SAndroid Build Coastguard Worker void EGLInitializePerfTest::SetUp()
115*8975f5c5SAndroid Build Coastguard Worker {
116*8975f5c5SAndroid Build Coastguard Worker ANGLEPerfTest::SetUp();
117*8975f5c5SAndroid Build Coastguard Worker
118*8975f5c5SAndroid Build Coastguard Worker angle::PlatformMethods *platformMethods = nullptr;
119*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(ANGLEGetDisplayPlatform(mDisplay, angle::g_PlatformMethodNames,
120*8975f5c5SAndroid Build Coastguard Worker angle::g_NumPlatformMethods, &mCaptures, &platformMethods));
121*8975f5c5SAndroid Build Coastguard Worker
122*8975f5c5SAndroid Build Coastguard Worker platformMethods->currentTime = CapturePlatform_currentTime;
123*8975f5c5SAndroid Build Coastguard Worker platformMethods->histogramCustomCounts = CapturePlatform_histogramCustomCounts;
124*8975f5c5SAndroid Build Coastguard Worker
125*8975f5c5SAndroid Build Coastguard Worker mReporter->RegisterImportantMetric(".LoadDLLs", "ms");
126*8975f5c5SAndroid Build Coastguard Worker mReporter->RegisterImportantMetric(".D3D11CreateDevice", "ms");
127*8975f5c5SAndroid Build Coastguard Worker mReporter->RegisterImportantMetric(".InitResources", "ms");
128*8975f5c5SAndroid Build Coastguard Worker }
129*8975f5c5SAndroid Build Coastguard Worker
~EGLInitializePerfTest()130*8975f5c5SAndroid Build Coastguard Worker EGLInitializePerfTest::~EGLInitializePerfTest()
131*8975f5c5SAndroid Build Coastguard Worker {
132*8975f5c5SAndroid Build Coastguard Worker OSWindow::Delete(&mOSWindow);
133*8975f5c5SAndroid Build Coastguard Worker }
134*8975f5c5SAndroid Build Coastguard Worker
step()135*8975f5c5SAndroid Build Coastguard Worker void EGLInitializePerfTest::step()
136*8975f5c5SAndroid Build Coastguard Worker {
137*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(EGL_NO_DISPLAY, mDisplay);
138*8975f5c5SAndroid Build Coastguard Worker
139*8975f5c5SAndroid Build Coastguard Worker EGLint majorVersion, minorVersion;
140*8975f5c5SAndroid Build Coastguard Worker ASSERT_EQ(static_cast<EGLBoolean>(EGL_TRUE),
141*8975f5c5SAndroid Build Coastguard Worker eglInitialize(mDisplay, &majorVersion, &minorVersion));
142*8975f5c5SAndroid Build Coastguard Worker ASSERT_EQ(static_cast<EGLBoolean>(EGL_TRUE), eglTerminate(mDisplay));
143*8975f5c5SAndroid Build Coastguard Worker }
144*8975f5c5SAndroid Build Coastguard Worker
TearDown()145*8975f5c5SAndroid Build Coastguard Worker void EGLInitializePerfTest::TearDown()
146*8975f5c5SAndroid Build Coastguard Worker {
147*8975f5c5SAndroid Build Coastguard Worker ANGLEPerfTest::TearDown();
148*8975f5c5SAndroid Build Coastguard Worker mReporter->AddResult(".LoadDLLs", normalizedTime(mCaptures.loadDLLsMS));
149*8975f5c5SAndroid Build Coastguard Worker mReporter->AddResult(".D3D11CreateDevice", normalizedTime(mCaptures.createDeviceMS));
150*8975f5c5SAndroid Build Coastguard Worker mReporter->AddResult(".InitResources", normalizedTime(mCaptures.initResourcesMS));
151*8975f5c5SAndroid Build Coastguard Worker
152*8975f5c5SAndroid Build Coastguard Worker ANGLEResetDisplayPlatform(mDisplay);
153*8975f5c5SAndroid Build Coastguard Worker }
154*8975f5c5SAndroid Build Coastguard Worker
TEST_P(EGLInitializePerfTest,Run)155*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLInitializePerfTest, Run)
156*8975f5c5SAndroid Build Coastguard Worker {
157*8975f5c5SAndroid Build Coastguard Worker run();
158*8975f5c5SAndroid Build Coastguard Worker }
159*8975f5c5SAndroid Build Coastguard Worker
160*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST(EGLInitializePerfTest,
161*8975f5c5SAndroid Build Coastguard Worker angle::ES2_D3D11(),
162*8975f5c5SAndroid Build Coastguard Worker angle::ES2_METAL(),
163*8975f5c5SAndroid Build Coastguard Worker angle::ES2_VULKAN());
164*8975f5c5SAndroid Build Coastguard Worker
165*8975f5c5SAndroid Build Coastguard Worker } // namespace
166