1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2020 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 // PreRotationBenchmark:
7*8975f5c5SAndroid Build Coastguard Worker // Performance test for pre-rotation code generation.
8*8975f5c5SAndroid Build Coastguard Worker //
9*8975f5c5SAndroid Build Coastguard Worker
10*8975f5c5SAndroid Build Coastguard Worker #include "ANGLEPerfTest.h"
11*8975f5c5SAndroid Build Coastguard Worker
12*8975f5c5SAndroid Build Coastguard Worker #include <iostream>
13*8975f5c5SAndroid Build Coastguard Worker #include <random>
14*8975f5c5SAndroid Build Coastguard Worker #include <sstream>
15*8975f5c5SAndroid Build Coastguard Worker
16*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/gl_raii.h"
17*8975f5c5SAndroid Build Coastguard Worker #include "util/shader_utils.h"
18*8975f5c5SAndroid Build Coastguard Worker
19*8975f5c5SAndroid Build Coastguard Worker using namespace angle;
20*8975f5c5SAndroid Build Coastguard Worker
21*8975f5c5SAndroid Build Coastguard Worker namespace
22*8975f5c5SAndroid Build Coastguard Worker {
23*8975f5c5SAndroid Build Coastguard Worker constexpr unsigned int kIterationsPerStep = 20;
24*8975f5c5SAndroid Build Coastguard Worker
25*8975f5c5SAndroid Build Coastguard Worker enum class PreRotation
26*8975f5c5SAndroid Build Coastguard Worker {
27*8975f5c5SAndroid Build Coastguard Worker _0,
28*8975f5c5SAndroid Build Coastguard Worker _90,
29*8975f5c5SAndroid Build Coastguard Worker _180,
30*8975f5c5SAndroid Build Coastguard Worker _270,
31*8975f5c5SAndroid Build Coastguard Worker };
32*8975f5c5SAndroid Build Coastguard Worker
33*8975f5c5SAndroid Build Coastguard Worker struct PreRotationParams final : public RenderTestParams
34*8975f5c5SAndroid Build Coastguard Worker {
PreRotationParams__anon3e9f36190111::PreRotationParams35*8975f5c5SAndroid Build Coastguard Worker PreRotationParams()
36*8975f5c5SAndroid Build Coastguard Worker {
37*8975f5c5SAndroid Build Coastguard Worker iterationsPerStep = kIterationsPerStep;
38*8975f5c5SAndroid Build Coastguard Worker trackGpuTime = true;
39*8975f5c5SAndroid Build Coastguard Worker
40*8975f5c5SAndroid Build Coastguard Worker preRotation = PreRotation::_0;
41*8975f5c5SAndroid Build Coastguard Worker }
42*8975f5c5SAndroid Build Coastguard Worker
43*8975f5c5SAndroid Build Coastguard Worker std::string story() const override;
44*8975f5c5SAndroid Build Coastguard Worker
45*8975f5c5SAndroid Build Coastguard Worker PreRotation preRotation;
46*8975f5c5SAndroid Build Coastguard Worker };
47*8975f5c5SAndroid Build Coastguard Worker
operator <<(std::ostream & os,const PreRotationParams & params)48*8975f5c5SAndroid Build Coastguard Worker std::ostream &operator<<(std::ostream &os, const PreRotationParams ¶ms)
49*8975f5c5SAndroid Build Coastguard Worker {
50*8975f5c5SAndroid Build Coastguard Worker return os << params.backendAndStory().substr(1);
51*8975f5c5SAndroid Build Coastguard Worker }
52*8975f5c5SAndroid Build Coastguard Worker
story() const53*8975f5c5SAndroid Build Coastguard Worker std::string PreRotationParams::story() const
54*8975f5c5SAndroid Build Coastguard Worker {
55*8975f5c5SAndroid Build Coastguard Worker std::stringstream strstr;
56*8975f5c5SAndroid Build Coastguard Worker
57*8975f5c5SAndroid Build Coastguard Worker strstr << RenderTestParams::story();
58*8975f5c5SAndroid Build Coastguard Worker
59*8975f5c5SAndroid Build Coastguard Worker switch (preRotation)
60*8975f5c5SAndroid Build Coastguard Worker {
61*8975f5c5SAndroid Build Coastguard Worker case PreRotation::_0:
62*8975f5c5SAndroid Build Coastguard Worker strstr << "_NoPreRotation";
63*8975f5c5SAndroid Build Coastguard Worker break;
64*8975f5c5SAndroid Build Coastguard Worker case PreRotation::_90:
65*8975f5c5SAndroid Build Coastguard Worker strstr << "_PreRotate90";
66*8975f5c5SAndroid Build Coastguard Worker break;
67*8975f5c5SAndroid Build Coastguard Worker case PreRotation::_180:
68*8975f5c5SAndroid Build Coastguard Worker strstr << "_PreRotate180";
69*8975f5c5SAndroid Build Coastguard Worker break;
70*8975f5c5SAndroid Build Coastguard Worker case PreRotation::_270:
71*8975f5c5SAndroid Build Coastguard Worker strstr << "_PreRotate270";
72*8975f5c5SAndroid Build Coastguard Worker break;
73*8975f5c5SAndroid Build Coastguard Worker }
74*8975f5c5SAndroid Build Coastguard Worker
75*8975f5c5SAndroid Build Coastguard Worker return strstr.str();
76*8975f5c5SAndroid Build Coastguard Worker }
77*8975f5c5SAndroid Build Coastguard Worker
78*8975f5c5SAndroid Build Coastguard Worker class PreRotationBenchmark : public ANGLERenderTest,
79*8975f5c5SAndroid Build Coastguard Worker public ::testing::WithParamInterface<PreRotationParams>
80*8975f5c5SAndroid Build Coastguard Worker {
81*8975f5c5SAndroid Build Coastguard Worker public:
82*8975f5c5SAndroid Build Coastguard Worker PreRotationBenchmark();
83*8975f5c5SAndroid Build Coastguard Worker
84*8975f5c5SAndroid Build Coastguard Worker void initializeBenchmark() override;
85*8975f5c5SAndroid Build Coastguard Worker void destroyBenchmark() override;
86*8975f5c5SAndroid Build Coastguard Worker
87*8975f5c5SAndroid Build Coastguard Worker void drawBenchmark() override;
88*8975f5c5SAndroid Build Coastguard Worker
89*8975f5c5SAndroid Build Coastguard Worker protected:
90*8975f5c5SAndroid Build Coastguard Worker GLuint mProgram = 0;
91*8975f5c5SAndroid Build Coastguard Worker };
92*8975f5c5SAndroid Build Coastguard Worker
PreRotationBenchmark()93*8975f5c5SAndroid Build Coastguard Worker PreRotationBenchmark::PreRotationBenchmark() : ANGLERenderTest("PreRotation", GetParam()) {}
94*8975f5c5SAndroid Build Coastguard Worker
initializeBenchmark()95*8975f5c5SAndroid Build Coastguard Worker void PreRotationBenchmark::initializeBenchmark()
96*8975f5c5SAndroid Build Coastguard Worker {
97*8975f5c5SAndroid Build Coastguard Worker constexpr char kVS[] = R"(
98*8975f5c5SAndroid Build Coastguard Worker attribute mediump vec4 positionIn;
99*8975f5c5SAndroid Build Coastguard Worker void main()
100*8975f5c5SAndroid Build Coastguard Worker {
101*8975f5c5SAndroid Build Coastguard Worker gl_Position = positionIn;
102*8975f5c5SAndroid Build Coastguard Worker })";
103*8975f5c5SAndroid Build Coastguard Worker
104*8975f5c5SAndroid Build Coastguard Worker constexpr char kFS[] = R"(precision mediump float;
105*8975f5c5SAndroid Build Coastguard Worker void main()
106*8975f5c5SAndroid Build Coastguard Worker {
107*8975f5c5SAndroid Build Coastguard Worker gl_FragColor = vec4(0);
108*8975f5c5SAndroid Build Coastguard Worker })";
109*8975f5c5SAndroid Build Coastguard Worker
110*8975f5c5SAndroid Build Coastguard Worker mProgram = CompileProgram(kVS, kFS);
111*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(0u, mProgram);
112*8975f5c5SAndroid Build Coastguard Worker
113*8975f5c5SAndroid Build Coastguard Worker glUseProgram(mProgram);
114*8975f5c5SAndroid Build Coastguard Worker
115*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
116*8975f5c5SAndroid Build Coastguard Worker
117*8975f5c5SAndroid Build Coastguard Worker glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
118*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight());
119*8975f5c5SAndroid Build Coastguard Worker
120*8975f5c5SAndroid Build Coastguard Worker // Perform a draw so everything is flushed.
121*8975f5c5SAndroid Build Coastguard Worker glDrawArrays(GL_TRIANGLES, 0, 3);
122*8975f5c5SAndroid Build Coastguard Worker
123*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
124*8975f5c5SAndroid Build Coastguard Worker }
125*8975f5c5SAndroid Build Coastguard Worker
destroyBenchmark()126*8975f5c5SAndroid Build Coastguard Worker void PreRotationBenchmark::destroyBenchmark()
127*8975f5c5SAndroid Build Coastguard Worker {
128*8975f5c5SAndroid Build Coastguard Worker glDeleteProgram(mProgram);
129*8975f5c5SAndroid Build Coastguard Worker }
130*8975f5c5SAndroid Build Coastguard Worker
drawBenchmark()131*8975f5c5SAndroid Build Coastguard Worker void PreRotationBenchmark::drawBenchmark()
132*8975f5c5SAndroid Build Coastguard Worker {
133*8975f5c5SAndroid Build Coastguard Worker const auto ¶ms = GetParam();
134*8975f5c5SAndroid Build Coastguard Worker
135*8975f5c5SAndroid Build Coastguard Worker constexpr uint32_t kDrawCallSize = 100'000;
136*8975f5c5SAndroid Build Coastguard Worker
137*8975f5c5SAndroid Build Coastguard Worker GLint attribLocation = glGetAttribLocation(mProgram, "positionIn");
138*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(-1, attribLocation);
139*8975f5c5SAndroid Build Coastguard Worker
140*8975f5c5SAndroid Build Coastguard Worker startGpuTimer();
141*8975f5c5SAndroid Build Coastguard Worker for (unsigned int iteration = 0; iteration < params.iterationsPerStep; ++iteration)
142*8975f5c5SAndroid Build Coastguard Worker {
143*8975f5c5SAndroid Build Coastguard Worker // Set the position attribute such that every generated primitive is out of bounds and is
144*8975f5c5SAndroid Build Coastguard Worker // clipped. This means the test is spending its time almost entirely with vertex shaders.
145*8975f5c5SAndroid Build Coastguard Worker // The vertex shader itself is simple so that any code that is added for pre-rotation will
146*8975f5c5SAndroid Build Coastguard Worker // contribute a comparably sizable chunk of code.
147*8975f5c5SAndroid Build Coastguard Worker switch (iteration % 5)
148*8975f5c5SAndroid Build Coastguard Worker {
149*8975f5c5SAndroid Build Coastguard Worker case 0:
150*8975f5c5SAndroid Build Coastguard Worker glVertexAttrib4f(attribLocation, -2.0f, 0.0f, 0.0f, 1.0f);
151*8975f5c5SAndroid Build Coastguard Worker break;
152*8975f5c5SAndroid Build Coastguard Worker case 1:
153*8975f5c5SAndroid Build Coastguard Worker glVertexAttrib4f(attribLocation, 2.0f, 0.0f, 0.0f, 1.0f);
154*8975f5c5SAndroid Build Coastguard Worker break;
155*8975f5c5SAndroid Build Coastguard Worker case 2:
156*8975f5c5SAndroid Build Coastguard Worker glVertexAttrib4f(attribLocation, 0.0f, -2.0f, 0.0f, 1.0f);
157*8975f5c5SAndroid Build Coastguard Worker break;
158*8975f5c5SAndroid Build Coastguard Worker case 3:
159*8975f5c5SAndroid Build Coastguard Worker glVertexAttrib4f(attribLocation, 0.0f, 2.0f, 0.0f, 1.0f);
160*8975f5c5SAndroid Build Coastguard Worker break;
161*8975f5c5SAndroid Build Coastguard Worker case 4:
162*8975f5c5SAndroid Build Coastguard Worker glVertexAttrib4f(attribLocation, 0.0f, 0.0f, -2.0f, 1.0f);
163*8975f5c5SAndroid Build Coastguard Worker break;
164*8975f5c5SAndroid Build Coastguard Worker }
165*8975f5c5SAndroid Build Coastguard Worker
166*8975f5c5SAndroid Build Coastguard Worker // Draw many points, all which are culled.
167*8975f5c5SAndroid Build Coastguard Worker glDrawArrays(GL_POINTS, 0, kDrawCallSize);
168*8975f5c5SAndroid Build Coastguard Worker }
169*8975f5c5SAndroid Build Coastguard Worker stopGpuTimer();
170*8975f5c5SAndroid Build Coastguard Worker
171*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
172*8975f5c5SAndroid Build Coastguard Worker }
173*8975f5c5SAndroid Build Coastguard Worker
VulkanParams(PreRotation preRotation)174*8975f5c5SAndroid Build Coastguard Worker PreRotationParams VulkanParams(PreRotation preRotation)
175*8975f5c5SAndroid Build Coastguard Worker {
176*8975f5c5SAndroid Build Coastguard Worker PreRotationParams params;
177*8975f5c5SAndroid Build Coastguard Worker params.eglParameters = egl_platform::VULKAN();
178*8975f5c5SAndroid Build Coastguard Worker params.preRotation = preRotation;
179*8975f5c5SAndroid Build Coastguard Worker
180*8975f5c5SAndroid Build Coastguard Worker switch (preRotation)
181*8975f5c5SAndroid Build Coastguard Worker {
182*8975f5c5SAndroid Build Coastguard Worker case PreRotation::_0:
183*8975f5c5SAndroid Build Coastguard Worker break;
184*8975f5c5SAndroid Build Coastguard Worker case PreRotation::_90:
185*8975f5c5SAndroid Build Coastguard Worker params.eglParameters.enable(Feature::EmulatedPrerotation90);
186*8975f5c5SAndroid Build Coastguard Worker break;
187*8975f5c5SAndroid Build Coastguard Worker case PreRotation::_180:
188*8975f5c5SAndroid Build Coastguard Worker params.eglParameters.enable(Feature::EmulatedPrerotation180);
189*8975f5c5SAndroid Build Coastguard Worker break;
190*8975f5c5SAndroid Build Coastguard Worker case PreRotation::_270:
191*8975f5c5SAndroid Build Coastguard Worker params.eglParameters.enable(Feature::EmulatedPrerotation270);
192*8975f5c5SAndroid Build Coastguard Worker break;
193*8975f5c5SAndroid Build Coastguard Worker }
194*8975f5c5SAndroid Build Coastguard Worker
195*8975f5c5SAndroid Build Coastguard Worker return params;
196*8975f5c5SAndroid Build Coastguard Worker }
197*8975f5c5SAndroid Build Coastguard Worker
198*8975f5c5SAndroid Build Coastguard Worker } // anonymous namespace
199*8975f5c5SAndroid Build Coastguard Worker
TEST_P(PreRotationBenchmark,Run)200*8975f5c5SAndroid Build Coastguard Worker TEST_P(PreRotationBenchmark, Run)
201*8975f5c5SAndroid Build Coastguard Worker {
202*8975f5c5SAndroid Build Coastguard Worker run();
203*8975f5c5SAndroid Build Coastguard Worker }
204*8975f5c5SAndroid Build Coastguard Worker
205*8975f5c5SAndroid Build Coastguard Worker using namespace params;
206*8975f5c5SAndroid Build Coastguard Worker
207*8975f5c5SAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(PreRotationBenchmark);
208*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST(PreRotationBenchmark,
209*8975f5c5SAndroid Build Coastguard Worker VulkanParams(PreRotation::_0),
210*8975f5c5SAndroid Build Coastguard Worker VulkanParams(PreRotation::_90),
211*8975f5c5SAndroid Build Coastguard Worker VulkanParams(PreRotation::_180),
212*8975f5c5SAndroid Build Coastguard Worker VulkanParams(PreRotation::_270));
213