Hash :
f576a708
Author :
Date :
2019-02-04T16:52:12
Add glmark2 to angle_perftests Bug: angleproject:3125 Change-Id: I9242743c6b5c6e18d0a23ff853ef6b9b370865a6 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1452956 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Cody Northrop <cnorthrop@google.com>
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 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
//
// Copyright 2019 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.
//
// glmark2Benchmark:
// Runs the glmark2 benchmark.
//
#include <gtest/gtest.h>
#include <stdio.h>
#include <sstream>
#include "../perf_tests/third_party/perf/perf_test.h"
#include "ANGLEPerfTestArgs.h"
#include "common/platform.h"
#include "common/system_utils.h"
#include "test_utils/angle_test_configs.h"
#include "test_utils/angle_test_instantiate.h"
using namespace angle;
namespace
{
struct BenchmarkInfo
{
const char *glmark2Config;
const char *gtestSuffix;
};
// Each glmark2 scene is individually benchmarked. If glmark2 is run without a specific benchmark,
// it can produce an aggregate score, which is not interesting at the moment. Adding an empty
// string ("") to this list will enable a test where glmark2 is run with the default scenes and the
// score for each test as well as the overall score is output.
constexpr BenchmarkInfo kBenchmarks[] = {
{"build:use-vbo=false", "build"},
{"build:use-vbo=true", "build_vbo"},
{"texture:texture-filter=nearest", "texture_nearest"},
{"texture:texture-filter=linear", "texture_linear"},
{"texture:texture-filter=mipmap", "texture_mipmap"},
{"shading:shading=gouraud", "shading_gouraud"},
{"shading:shading=blinn-phong-inf", "shading_blinn_phong"},
{"shading:shading=phong", "shading_phong"},
{"shading:shading=cel", "shading_cel"},
{"bump:bump-render=high-poly", "bump_high_poly"},
{"bump:bump-render=normals", "bump_normals"},
{"bump:bump-render=height", "bump_height"},
{"effect2d:kernel=0,1,0;1,-4,1;0,1,0;", "effect2d_edge"},
{"effect2d:kernel=1,1,1,1,1;1,1,1,1,1;1,1,1,1,1;", "effect2d_blur"},
{"pulsar:light=false:quads=5:texture=false", "pulsar"},
{"desktop:blur-radius=5:effect=blur:passes=1:separable=true:windows=4", "desktop_blur"},
{"desktop:effect=shadow:windows=4", "desktop_shadow"},
{"buffer:columns=200:interleave=false:update-dispersion=0.9:update-fraction=0.5:update-method="
"map",
"buffer_map"},
{"buffer:columns=200:interleave=false:update-dispersion=0.9:update-fraction=0.5:update-method="
"subdata",
"buffer_subdata"},
{"buffer:columns=200:interleave=true:update-dispersion=0.9:update-fraction=0.5:update-method="
"map",
"buffer_map_interleave"},
{"ideas:speed=duration", "ideas"},
{"jellyfish", "jellyfish"},
{"terrain", "terrain"},
{"shadow", "shadow"},
{"refract", "refract"},
{"conditionals:fragment-steps=0:vertex-steps=0", "conditionals"},
{"conditionals:fragment-steps=5:vertex-steps=0", "conditionals_fragment"},
{"conditionals:fragment-steps=0:vertex-steps=5", "conditionals_vertex"},
{"function:fragment-complexity=low:fragment-steps=5", "function"},
{"function:fragment-complexity=medium:fragment-steps=5", "function_complex"},
{"loop:fragment-loop=false:fragment-steps=5:vertex-steps=5", "loop_no_fsloop"},
{"loop:fragment-steps=5:fragment-uniform=false:vertex-steps=5", "loop_no_uniform"},
{"loop:fragment-steps=5:fragment-uniform=true:vertex-steps=5", "loop"},
};
using GLMark2BenchmarkTestParams = std::tuple<PlatformParameters, size_t>;
std::string GLMark2BenchmarkPrint(
const ::testing::TestParamInfo<GLMark2BenchmarkTestParams> ¶msInfo)
{
const GLMark2BenchmarkTestParams ¶ms = paramsInfo.param;
std::ostringstream out;
out << std::get<0>(params) << '_';
out << kBenchmarks[std::get<1>(params)].gtestSuffix;
return out.str();
}
class GLMark2Benchmark : public testing::TestWithParam<GLMark2BenchmarkTestParams>
{
public:
GLMark2Benchmark()
{
switch (std::get<0>(GetParam()).getRenderer())
{
case EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE:
mBackend = "d3d11";
break;
case EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE:
mBackend = "gl";
break;
case EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE:
mBackend = "vulkan";
break;
default:
break;
}
}
void run()
{
// Only supported on Linux and Windows at the moment.
if (!IsLinux() && !IsWindows())
{
return;
}
const char *benchmark = kBenchmarks[std::get<1>(GetParam())].glmark2Config;
bool completeRun = benchmark == nullptr || benchmark[0] == '\0';
Optional<std::string> cwd = GetCWD();
// Set the current working directory to the executable's, as the data path of glmark2 is
// set relative to that path.
std::string executableDir = GetExecutableDirectory();
SetCWD(executableDir.c_str());
SetEnvironmentVar("ANGLE_DEFAULT_PLATFORM", mBackend);
std::vector<const char *> args = {
"glmark2_angle",
};
if (OneFrame())
{
args.push_back("--validate");
}
if (!completeRun)
{
args.push_back("--benchmark");
args.push_back(benchmark);
fprintf(stderr, "Running benchmark: %s\n", benchmark);
}
args.push_back(nullptr);
std::string output;
int exitCode;
bool success = RunApp(args, &output, nullptr, &exitCode);
// Restore the current working directory for the next tests.
if (cwd.valid())
{
SetCWD(cwd.value().c_str());
}
ASSERT_TRUE(success);
ASSERT_EQ(EXIT_SUCCESS, exitCode);
if (!OneFrame())
{
parseOutput(output, completeRun);
}
}
private:
void parseOutput(const std::string &output, bool completeRun)
{
// Output is in the following format:
//
// =======================================================
// glmark2 2017.07
// =======================================================
// OpenGL Information
// GL_VENDOR: ...
// GL_RENDERER: ...
// GL_VERSION: ...
// =======================================================
// [test] config: FPS: uint FrameTime: float ms
// [test] config: Not Supported
// ...
// =======================================================
// glmark2 Score: uint
// =======================================================
//
// This function skips the header, prints one line for each test/config line where there's
// an FPS value, and finally prints the overall score.
std::istringstream glmark2Output(output);
std::string line;
// Expect ==== at the top of the header
std::getline(glmark2Output, line);
ASSERT_EQ('=', line[0]);
// Skip one line
std::getline(glmark2Output, line);
// Expect ==== in the middle of the header
std::getline(glmark2Output, line);
ASSERT_EQ('=', line[0]);
// Skip four lines
std::getline(glmark2Output, line);
std::getline(glmark2Output, line);
std::getline(glmark2Output, line);
std::getline(glmark2Output, line);
// The fourth line is the GL_VERSION. Expect it to include ANGLE, otherwise we are not
// running against ANGLE.
ASSERT_NE(line.find("ANGLE"), std::string::npos);
// Expect ==== at the bottom of the header
std::getline(glmark2Output, line);
ASSERT_EQ('=', line[0]);
// Read configs until the top of the footer is reached
while (std::getline(glmark2Output, line) && line[0] != '=')
{
// Parse the line
std::istringstream lin(line);
std::string testName, testConfig;
lin >> testName >> testConfig;
EXPECT_TRUE(lin);
std::string fpsTag, frametimeTag;
size_t fps;
float frametime;
lin >> fpsTag >> fps >> frametimeTag >> frametime;
// If the line is not in `FPS: uint FrameTime: Float ms` format, the test is not
// supported. It will be skipped.
if (!lin)
{
continue;
}
EXPECT_EQ("FPS:", fpsTag);
EXPECT_EQ("FrameTime:", frametimeTag);
perf_test::PrintResult(testName + testConfig, mBackend, "fps", fps, "", true);
}
// Get the score line: `glmark2 Score: uint`
std::string glmark2Tag, scoreTag;
size_t score;
glmark2Output >> glmark2Tag >> scoreTag >> score;
EXPECT_TRUE(glmark2Output);
EXPECT_EQ("glmark2", glmark2Tag);
EXPECT_EQ("Score:", scoreTag);
if (!completeRun)
{
perf_test::PrintResult("glmark2", mBackend, "score", score, "", true);
}
}
const char *mBackend = "invalid";
};
TEST_P(GLMark2Benchmark, Run)
{
run();
}
ANGLE_INSTANTIATE_TEST_COMBINE_1(GLMark2Benchmark,
GLMark2BenchmarkPrint,
testing::Range(static_cast<size_t>(0), ArraySize(kBenchmarks)),
ES2_D3D11(),
ES2_OPENGLES(),
ES2_VULKAN());
} // namespace