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