Hash :
2f4a7518
Author :
Date :
2019-08-16T14:09:13
Refactor perf tests to fix metric/story swapping Refactors the perf tests to fix the issue of metric and story being swapped, which causes issues when trying to convert to histograms. Specifically, does the following: 1. Rolls the version of src/tests/perf_tests/third_party/perf/ to Chromium 476dae823269c8d05b544271af97ad1adb0db8ee 2. Switch to using PerfResultReporter instead of PrintResult directly. 3. Split RenderTestParams::suffix into backend and story; backend is used as part of the metric, while story is used as the story. 4. Remove the "average" metric that was being automatically reported by ANGLEPerfTest, as reported results are automatically averaged. 5. Update the reported metric to more clearly distinguish between test, backend, and metric. It is now name_backend.metric. e.g. DrawCallPerf_vulkan.wall_time. Bug: chromium:923564,chromium:924618 Change-Id: I00cc191407052f23df57dbfa53b6fb088fc26960 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1762360 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Jonah Ryan-Davis <jonahr@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 276 277 278 279 280 281 282 283 284 285
//
// 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.
//
// TextureUploadBenchmark:
// Performance test for uploading texture data.
//
#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 = 2;
struct TextureUploadParams final : public RenderTestParams
{
TextureUploadParams()
{
iterationsPerStep = kIterationsPerStep;
trackGpuTime = true;
baseSize = 1024;
subImageSize = 64;
webgl = false;
}
std::string story() const override;
GLsizei baseSize;
GLsizei subImageSize;
bool webgl;
};
std::ostream &operator<<(std::ostream &os, const TextureUploadParams ¶ms)
{
os << params.backendAndStory().substr(1);
return os;
}
std::string TextureUploadParams::story() const
{
std::stringstream strstr;
strstr << RenderTestParams::story();
if (webgl)
{
strstr << "_webgl";
}
return strstr.str();
}
class TextureUploadBenchmarkBase : public ANGLERenderTest,
public ::testing::WithParamInterface<TextureUploadParams>
{
public:
TextureUploadBenchmarkBase(const char *benchmarkName);
void initializeBenchmark() override;
void destroyBenchmark() override;
protected:
void initShaders();
GLuint mProgram = 0;
GLint mPositionLoc = -1;
GLint mSamplerLoc = -1;
GLuint mTexture = 0;
std::vector<float> mTextureData;
};
class TextureUploadSubImageBenchmark : public TextureUploadBenchmarkBase
{
public:
TextureUploadSubImageBenchmark() : TextureUploadBenchmarkBase("TexSubImage")
{
addExtensionPrerequisite("GL_EXT_texture_storage");
}
void initializeBenchmark() override
{
TextureUploadBenchmarkBase::initializeBenchmark();
const auto ¶ms = GetParam();
glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, params.baseSize, params.baseSize);
}
void drawBenchmark() override;
};
class TextureUploadFullMipBenchmark : public TextureUploadBenchmarkBase
{
public:
TextureUploadFullMipBenchmark() : TextureUploadBenchmarkBase("TextureUpload") {}
void drawBenchmark() override;
};
TextureUploadBenchmarkBase::TextureUploadBenchmarkBase(const char *benchmarkName)
: ANGLERenderTest(benchmarkName, GetParam())
{
setWebGLCompatibilityEnabled(GetParam().webgl);
setRobustResourceInit(GetParam().webgl);
// Crashes on nvidia+d3d11. http://crbug.com/945415
if (GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
{
mSkipTest = true;
}
}
void TextureUploadBenchmarkBase::initializeBenchmark()
{
const auto ¶ms = GetParam();
initShaders();
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight());
if (params.webgl)
{
glRequestExtensionANGLE("GL_EXT_disjoint_timer_query");
}
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &mTexture);
glBindTexture(GL_TEXTURE_2D, mTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
ASSERT_TRUE(params.baseSize >= params.subImageSize);
mTextureData.resize(params.baseSize * params.baseSize * 4, 0.5);
ASSERT_GL_NO_ERROR();
}
void TextureUploadBenchmarkBase::initShaders()
{
constexpr char kVS[] = R"(attribute vec4 a_position;
void main()
{
gl_Position = a_position;
})";
constexpr char kFS[] = R"(precision mediump float;
uniform sampler2D s_texture;
void main()
{
gl_FragColor = texture2D(s_texture, vec2(0, 0));
})";
mProgram = CompileProgram(kVS, kFS);
ASSERT_NE(0u, mProgram);
mPositionLoc = glGetAttribLocation(mProgram, "a_position");
mSamplerLoc = glGetUniformLocation(mProgram, "s_texture");
glUseProgram(mProgram);
glUniform1i(mSamplerLoc, 0);
glDisable(GL_DEPTH_TEST);
ASSERT_GL_NO_ERROR();
}
void TextureUploadBenchmarkBase::destroyBenchmark()
{
glDeleteTextures(1, &mTexture);
glDeleteProgram(mProgram);
}
void TextureUploadSubImageBenchmark::drawBenchmark()
{
const auto ¶ms = GetParam();
startGpuTimer();
for (unsigned int iteration = 0; iteration < params.iterationsPerStep; ++iteration)
{
glTexSubImage2D(GL_TEXTURE_2D, 0, rand() % (params.baseSize - params.subImageSize),
rand() % (params.baseSize - params.subImageSize), params.subImageSize,
params.subImageSize, GL_RGBA, GL_UNSIGNED_BYTE, mTextureData.data());
// Perform a draw just so the texture data is flushed. With the position attributes not
// set, a constant default value is used, resulting in a very cheap draw.
glDrawArrays(GL_TRIANGLES, 0, 3);
}
stopGpuTimer();
ASSERT_GL_NO_ERROR();
}
void TextureUploadFullMipBenchmark::drawBenchmark()
{
const auto ¶ms = GetParam();
startGpuTimer();
for (size_t it = 0; it < params.iterationsPerStep; ++it)
{
// Stage data for all mips
GLint mip = 0;
for (GLsizei levelSize = params.baseSize; levelSize > 0; levelSize >>= 1)
{
glTexImage2D(GL_TEXTURE_2D, mip++, GL_RGBA, levelSize, levelSize, 0, GL_RGBA,
GL_UNSIGNED_BYTE, mTextureData.data());
}
// Perform a draw just so the texture data is flushed. With the position attributes not
// set, a constant default value is used, resulting in a very cheap draw.
glDrawArrays(GL_TRIANGLES, 0, 3);
}
stopGpuTimer();
ASSERT_GL_NO_ERROR();
}
TextureUploadParams D3D11Params(bool webglCompat)
{
TextureUploadParams params;
params.eglParameters = egl_platform::D3D11();
params.webgl = webglCompat;
return params;
}
TextureUploadParams OpenGLOrGLESParams(bool webglCompat)
{
TextureUploadParams params;
params.eglParameters = egl_platform::OPENGL_OR_GLES();
params.webgl = webglCompat;
return params;
}
TextureUploadParams VulkanParams(bool webglCompat)
{
TextureUploadParams params;
params.eglParameters = egl_platform::VULKAN();
params.webgl = webglCompat;
return params;
}
} // anonymous namespace
TEST_P(TextureUploadSubImageBenchmark, Run)
{
run();
}
TEST_P(TextureUploadFullMipBenchmark, Run)
{
run();
}
using namespace params;
ANGLE_INSTANTIATE_TEST(TextureUploadSubImageBenchmark,
D3D11Params(false),
D3D11Params(true),
OpenGLOrGLESParams(false),
OpenGLOrGLESParams(true),
VulkanParams(false),
NullDevice(VulkanParams(false)),
VulkanParams(true));
ANGLE_INSTANTIATE_TEST(TextureUploadFullMipBenchmark,
D3D11Params(false),
D3D11Params(true),
OpenGLOrGLESParams(false),
OpenGLOrGLESParams(true),
VulkanParams(false),
NullDevice(VulkanParams(false)),
VulkanParams(true));