Path: blob/main_old/src/tests/perf_tests/PreRotationPerf.cpp
1693 views
//1// Copyright 2020 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// PreRotationBenchmark:6// Performance test for pre-rotation code generation.7//89#include "ANGLEPerfTest.h"1011#include <iostream>12#include <random>13#include <sstream>1415#include "test_utils/gl_raii.h"16#include "util/shader_utils.h"1718using namespace angle;1920namespace21{22constexpr unsigned int kIterationsPerStep = 20;2324enum class PreRotation25{26_0,27_90,28_180,29_270,30};3132struct PreRotationParams final : public RenderTestParams33{34PreRotationParams()35{36iterationsPerStep = kIterationsPerStep;37trackGpuTime = true;3839preRotation = PreRotation::_0;40}4142std::string story() const override;4344PreRotation preRotation;45};4647std::ostream &operator<<(std::ostream &os, const PreRotationParams ¶ms)48{49return os << params.backendAndStory().substr(1);50}5152std::string PreRotationParams::story() const53{54std::stringstream strstr;5556strstr << RenderTestParams::story();5758switch (preRotation)59{60case PreRotation::_0:61strstr << "_NoPreRotation";62break;63case PreRotation::_90:64strstr << "_PreRotate90";65break;66case PreRotation::_180:67strstr << "_PreRotate180";68break;69case PreRotation::_270:70strstr << "_PreRotate270";71break;72}7374return strstr.str();75}7677class PreRotationBenchmark : public ANGLERenderTest,78public ::testing::WithParamInterface<PreRotationParams>79{80public:81PreRotationBenchmark();8283void initializeBenchmark() override;84void destroyBenchmark() override;8586void drawBenchmark() override;8788protected:89GLuint mProgram = 0;90};9192PreRotationBenchmark::PreRotationBenchmark() : ANGLERenderTest("PreRotation", GetParam()) {}9394void PreRotationBenchmark::initializeBenchmark()95{96constexpr char kVS[] = R"(97attribute mediump vec4 positionIn;98void main()99{100gl_Position = positionIn;101})";102103constexpr char kFS[] = R"(precision mediump float;104void main()105{106gl_FragColor = vec4(0);107})";108109mProgram = CompileProgram(kVS, kFS);110ASSERT_NE(0u, mProgram);111112glUseProgram(mProgram);113114ASSERT_GL_NO_ERROR();115116glClearColor(0.0f, 0.0f, 0.0f, 0.0f);117glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight());118119// Perform a draw so everything is flushed.120glDrawArrays(GL_TRIANGLES, 0, 3);121122ASSERT_GL_NO_ERROR();123}124125void PreRotationBenchmark::destroyBenchmark()126{127glDeleteProgram(mProgram);128}129130void PreRotationBenchmark::drawBenchmark()131{132const auto ¶ms = GetParam();133134constexpr uint32_t kDrawCallSize = 100'000;135136GLint attribLocation = glGetAttribLocation(mProgram, "positionIn");137ASSERT_NE(-1, attribLocation);138139startGpuTimer();140for (unsigned int iteration = 0; iteration < params.iterationsPerStep; ++iteration)141{142// Set the position attribute such that every generated primitive is out of bounds and is143// clipped. This means the test is spending its time almost entirely with vertex shaders.144// The vertex shader itself is simple so that any code that is added for pre-rotation will145// contribute a comparably sizable chunk of code.146switch (iteration % 5)147{148case 0:149glVertexAttrib4f(attribLocation, -2.0f, 0.0f, 0.0f, 1.0f);150break;151case 1:152glVertexAttrib4f(attribLocation, 2.0f, 0.0f, 0.0f, 1.0f);153break;154case 2:155glVertexAttrib4f(attribLocation, 0.0f, -2.0f, 0.0f, 1.0f);156break;157case 3:158glVertexAttrib4f(attribLocation, 0.0f, 2.0f, 0.0f, 1.0f);159break;160case 4:161glVertexAttrib4f(attribLocation, 0.0f, 0.0f, -2.0f, 1.0f);162break;163}164165// Draw many points, all which are culled.166glDrawArrays(GL_POINTS, 0, kDrawCallSize);167}168stopGpuTimer();169170ASSERT_GL_NO_ERROR();171}172173PreRotationParams VulkanParams(PreRotation preRotation)174{175PreRotationParams params;176params.eglParameters = egl_platform::VULKAN();177params.preRotation = preRotation;178179switch (preRotation)180{181case PreRotation::_0:182break;183case PreRotation::_90:184params.eglParameters.emulatedPrerotation = 90;185break;186case PreRotation::_180:187params.eglParameters.emulatedPrerotation = 180;188break;189case PreRotation::_270:190params.eglParameters.emulatedPrerotation = 270;191break;192}193194return params;195}196197} // anonymous namespace198199TEST_P(PreRotationBenchmark, Run)200{201run();202}203204using namespace params;205206GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(PreRotationBenchmark);207ANGLE_INSTANTIATE_TEST(PreRotationBenchmark,208VulkanParams(PreRotation::_0),209VulkanParams(PreRotation::_90),210VulkanParams(PreRotation::_180),211VulkanParams(PreRotation::_270));212213214