xref: /aosp_15_r20/external/angle/src/tests/perf_tests/EGLMakeCurrentPerf.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2018 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 // EGLMakeCurrentPerfTest:
7*8975f5c5SAndroid Build Coastguard Worker //   Performance test for eglMakeCurrent.
8*8975f5c5SAndroid Build Coastguard Worker //
9*8975f5c5SAndroid Build Coastguard Worker 
10*8975f5c5SAndroid Build Coastguard Worker #include "ANGLEPerfTest.h"
11*8975f5c5SAndroid Build Coastguard Worker #include "common/platform.h"
12*8975f5c5SAndroid Build Coastguard Worker #include "common/system_utils.h"
13*8975f5c5SAndroid Build Coastguard Worker #include "platform/PlatformMethods.h"
14*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/angle_test_configs.h"
15*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/angle_test_instantiate.h"
16*8975f5c5SAndroid Build Coastguard Worker 
17*8975f5c5SAndroid Build Coastguard Worker #define ITERATIONS 20
18*8975f5c5SAndroid Build Coastguard Worker 
19*8975f5c5SAndroid Build Coastguard Worker using namespace testing;
20*8975f5c5SAndroid Build Coastguard Worker 
21*8975f5c5SAndroid Build Coastguard Worker namespace
22*8975f5c5SAndroid Build Coastguard Worker {
23*8975f5c5SAndroid Build Coastguard Worker class EGLMakeCurrentPerfTest : public ANGLEPerfTest,
24*8975f5c5SAndroid Build Coastguard Worker                                public WithParamInterface<angle::PlatformParameters>
25*8975f5c5SAndroid Build Coastguard Worker {
26*8975f5c5SAndroid Build Coastguard Worker   public:
27*8975f5c5SAndroid Build Coastguard Worker     EGLMakeCurrentPerfTest();
28*8975f5c5SAndroid Build Coastguard Worker 
29*8975f5c5SAndroid Build Coastguard Worker     void step() override;
30*8975f5c5SAndroid Build Coastguard Worker     void SetUp() override;
31*8975f5c5SAndroid Build Coastguard Worker     void TearDown() override;
32*8975f5c5SAndroid Build Coastguard Worker 
33*8975f5c5SAndroid Build Coastguard Worker   private:
34*8975f5c5SAndroid Build Coastguard Worker     OSWindow *mOSWindow;
35*8975f5c5SAndroid Build Coastguard Worker     EGLDisplay mDisplay;
36*8975f5c5SAndroid Build Coastguard Worker     EGLSurface mSurface;
37*8975f5c5SAndroid Build Coastguard Worker     EGLConfig mConfig;
38*8975f5c5SAndroid Build Coastguard Worker     std::array<EGLContext, 2> mContexts;
39*8975f5c5SAndroid Build Coastguard Worker     std::unique_ptr<angle::Library> mEGLLibrary;
40*8975f5c5SAndroid Build Coastguard Worker };
41*8975f5c5SAndroid Build Coastguard Worker 
EGLMakeCurrentPerfTest()42*8975f5c5SAndroid Build Coastguard Worker EGLMakeCurrentPerfTest::EGLMakeCurrentPerfTest()
43*8975f5c5SAndroid Build Coastguard Worker     : ANGLEPerfTest("EGLMakeCurrent", "", "_run", ITERATIONS),
44*8975f5c5SAndroid Build Coastguard Worker       mOSWindow(nullptr),
45*8975f5c5SAndroid Build Coastguard Worker       mDisplay(EGL_NO_DISPLAY),
46*8975f5c5SAndroid Build Coastguard Worker       mSurface(EGL_NO_SURFACE),
47*8975f5c5SAndroid Build Coastguard Worker       mConfig(nullptr),
48*8975f5c5SAndroid Build Coastguard Worker       mContexts({})
49*8975f5c5SAndroid Build Coastguard Worker {
50*8975f5c5SAndroid Build Coastguard Worker     auto platform = GetParam().eglParameters;
51*8975f5c5SAndroid Build Coastguard Worker 
52*8975f5c5SAndroid Build Coastguard Worker     std::vector<EGLint> displayAttributes;
53*8975f5c5SAndroid Build Coastguard Worker     displayAttributes.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE);
54*8975f5c5SAndroid Build Coastguard Worker     displayAttributes.push_back(platform.renderer);
55*8975f5c5SAndroid Build Coastguard Worker     displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE);
56*8975f5c5SAndroid Build Coastguard Worker     displayAttributes.push_back(platform.majorVersion);
57*8975f5c5SAndroid Build Coastguard Worker     displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE);
58*8975f5c5SAndroid Build Coastguard Worker     displayAttributes.push_back(platform.minorVersion);
59*8975f5c5SAndroid Build Coastguard Worker     displayAttributes.push_back(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE);
60*8975f5c5SAndroid Build Coastguard Worker     displayAttributes.push_back(platform.deviceType);
61*8975f5c5SAndroid Build Coastguard Worker     displayAttributes.push_back(EGL_NONE);
62*8975f5c5SAndroid Build Coastguard Worker 
63*8975f5c5SAndroid Build Coastguard Worker     mOSWindow = OSWindow::New();
64*8975f5c5SAndroid Build Coastguard Worker     mOSWindow->initialize("EGLMakeCurrent Test", 64, 64);
65*8975f5c5SAndroid Build Coastguard Worker 
66*8975f5c5SAndroid Build Coastguard Worker     mEGLLibrary.reset(
67*8975f5c5SAndroid Build Coastguard Worker         angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME, angle::SearchType::ModuleDir));
68*8975f5c5SAndroid Build Coastguard Worker 
69*8975f5c5SAndroid Build Coastguard Worker     LoadProc getProc = reinterpret_cast<LoadProc>(mEGLLibrary->getSymbol("eglGetProcAddress"));
70*8975f5c5SAndroid Build Coastguard Worker 
71*8975f5c5SAndroid Build Coastguard Worker     if (!getProc)
72*8975f5c5SAndroid Build Coastguard Worker     {
73*8975f5c5SAndroid Build Coastguard Worker         abortTest();
74*8975f5c5SAndroid Build Coastguard Worker     }
75*8975f5c5SAndroid Build Coastguard Worker     else
76*8975f5c5SAndroid Build Coastguard Worker     {
77*8975f5c5SAndroid Build Coastguard Worker         LoadUtilEGL(getProc);
78*8975f5c5SAndroid Build Coastguard Worker         // Test harness warmup calls glFinish so we need GLES too.
79*8975f5c5SAndroid Build Coastguard Worker         LoadUtilGLES(getProc);
80*8975f5c5SAndroid Build Coastguard Worker 
81*8975f5c5SAndroid Build Coastguard Worker         if (!eglGetPlatformDisplayEXT)
82*8975f5c5SAndroid Build Coastguard Worker         {
83*8975f5c5SAndroid Build Coastguard Worker             abortTest();
84*8975f5c5SAndroid Build Coastguard Worker         }
85*8975f5c5SAndroid Build Coastguard Worker         else
86*8975f5c5SAndroid Build Coastguard Worker         {
87*8975f5c5SAndroid Build Coastguard Worker             mDisplay = eglGetPlatformDisplayEXT(
88*8975f5c5SAndroid Build Coastguard Worker                 EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void *>(mOSWindow->getNativeDisplay()),
89*8975f5c5SAndroid Build Coastguard Worker                 &displayAttributes[0]);
90*8975f5c5SAndroid Build Coastguard Worker         }
91*8975f5c5SAndroid Build Coastguard Worker     }
92*8975f5c5SAndroid Build Coastguard Worker }
93*8975f5c5SAndroid Build Coastguard Worker 
SetUp()94*8975f5c5SAndroid Build Coastguard Worker void EGLMakeCurrentPerfTest::SetUp()
95*8975f5c5SAndroid Build Coastguard Worker {
96*8975f5c5SAndroid Build Coastguard Worker     ANGLEPerfTest::SetUp();
97*8975f5c5SAndroid Build Coastguard Worker 
98*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(EGL_NO_DISPLAY, mDisplay);
99*8975f5c5SAndroid Build Coastguard Worker     EGLint majorVersion, minorVersion;
100*8975f5c5SAndroid Build Coastguard Worker     ASSERT_TRUE(eglInitialize(mDisplay, &majorVersion, &minorVersion));
101*8975f5c5SAndroid Build Coastguard Worker 
102*8975f5c5SAndroid Build Coastguard Worker     EGLint numConfigs;
103*8975f5c5SAndroid Build Coastguard Worker     EGLint configAttrs[] = {EGL_RED_SIZE,
104*8975f5c5SAndroid Build Coastguard Worker                             8,
105*8975f5c5SAndroid Build Coastguard Worker                             EGL_GREEN_SIZE,
106*8975f5c5SAndroid Build Coastguard Worker                             8,
107*8975f5c5SAndroid Build Coastguard Worker                             EGL_BLUE_SIZE,
108*8975f5c5SAndroid Build Coastguard Worker                             8,
109*8975f5c5SAndroid Build Coastguard Worker                             EGL_RENDERABLE_TYPE,
110*8975f5c5SAndroid Build Coastguard Worker                             GetParam().majorVersion == 3 ? EGL_OPENGL_ES3_BIT : EGL_OPENGL_ES2_BIT,
111*8975f5c5SAndroid Build Coastguard Worker                             EGL_SURFACE_TYPE,
112*8975f5c5SAndroid Build Coastguard Worker                             EGL_WINDOW_BIT,
113*8975f5c5SAndroid Build Coastguard Worker                             EGL_NONE};
114*8975f5c5SAndroid Build Coastguard Worker 
115*8975f5c5SAndroid Build Coastguard Worker     ASSERT_TRUE(eglChooseConfig(mDisplay, configAttrs, &mConfig, 1, &numConfigs));
116*8975f5c5SAndroid Build Coastguard Worker 
117*8975f5c5SAndroid Build Coastguard Worker     mContexts[0] = eglCreateContext(mDisplay, mConfig, EGL_NO_CONTEXT, nullptr);
118*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(EGL_NO_CONTEXT, mContexts[0]);
119*8975f5c5SAndroid Build Coastguard Worker     mContexts[1] = eglCreateContext(mDisplay, mConfig, EGL_NO_CONTEXT, nullptr);
120*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(EGL_NO_CONTEXT, mContexts[1]);
121*8975f5c5SAndroid Build Coastguard Worker 
122*8975f5c5SAndroid Build Coastguard Worker     mSurface = eglCreateWindowSurface(mDisplay, mConfig, mOSWindow->getNativeWindow(), nullptr);
123*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(EGL_NO_SURFACE, mSurface);
124*8975f5c5SAndroid Build Coastguard Worker     ASSERT_TRUE(eglMakeCurrent(mDisplay, mSurface, mSurface, mContexts[0]));
125*8975f5c5SAndroid Build Coastguard Worker }
126*8975f5c5SAndroid Build Coastguard Worker 
TearDown()127*8975f5c5SAndroid Build Coastguard Worker void EGLMakeCurrentPerfTest::TearDown()
128*8975f5c5SAndroid Build Coastguard Worker {
129*8975f5c5SAndroid Build Coastguard Worker     ANGLEPerfTest::TearDown();
130*8975f5c5SAndroid Build Coastguard Worker     eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
131*8975f5c5SAndroid Build Coastguard Worker     eglDestroySurface(mDisplay, mSurface);
132*8975f5c5SAndroid Build Coastguard Worker     eglDestroyContext(mDisplay, mContexts[0]);
133*8975f5c5SAndroid Build Coastguard Worker     eglDestroyContext(mDisplay, mContexts[1]);
134*8975f5c5SAndroid Build Coastguard Worker }
135*8975f5c5SAndroid Build Coastguard Worker 
step()136*8975f5c5SAndroid Build Coastguard Worker void EGLMakeCurrentPerfTest::step()
137*8975f5c5SAndroid Build Coastguard Worker {
138*8975f5c5SAndroid Build Coastguard Worker     int mCurrContext = 0;
139*8975f5c5SAndroid Build Coastguard Worker     for (int x = 0; x < ITERATIONS; x++)
140*8975f5c5SAndroid Build Coastguard Worker     {
141*8975f5c5SAndroid Build Coastguard Worker         mCurrContext = (mCurrContext + 1) % mContexts.size();
142*8975f5c5SAndroid Build Coastguard Worker         eglMakeCurrent(mDisplay, mSurface, mSurface, mContexts[mCurrContext]);
143*8975f5c5SAndroid Build Coastguard Worker     }
144*8975f5c5SAndroid Build Coastguard Worker }
145*8975f5c5SAndroid Build Coastguard Worker 
TEST_P(EGLMakeCurrentPerfTest,Run)146*8975f5c5SAndroid Build Coastguard Worker TEST_P(EGLMakeCurrentPerfTest, Run)
147*8975f5c5SAndroid Build Coastguard Worker {
148*8975f5c5SAndroid Build Coastguard Worker     run();
149*8975f5c5SAndroid Build Coastguard Worker }
150*8975f5c5SAndroid Build Coastguard Worker 
151*8975f5c5SAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLMakeCurrentPerfTest);
152*8975f5c5SAndroid Build Coastguard Worker // We want to run this test on GL(ES) and Vulkan everywhere except Android
153*8975f5c5SAndroid Build Coastguard Worker #if !defined(ANGLE_PLATFORM_ANDROID)
154*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST(EGLMakeCurrentPerfTest,
155*8975f5c5SAndroid Build Coastguard Worker                        angle::ES2_D3D11(),
156*8975f5c5SAndroid Build Coastguard Worker                        angle::ES2_METAL(),
157*8975f5c5SAndroid Build Coastguard Worker                        angle::ES2_OPENGL(),
158*8975f5c5SAndroid Build Coastguard Worker                        angle::ES2_OPENGLES(),
159*8975f5c5SAndroid Build Coastguard Worker                        angle::ES2_VULKAN());
160*8975f5c5SAndroid Build Coastguard Worker #endif
161*8975f5c5SAndroid Build Coastguard Worker 
162*8975f5c5SAndroid Build Coastguard Worker }  // namespace
163