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