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 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
//
// 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.
//
// VulkanBarriersPerf:
// Performance tests for ANGLE's Vulkan backend w.r.t barrier efficiency.
//
#include <sstream>
#include "ANGLEPerfTest.h"
#include "test_utils/gl_raii.h"
#include "util/shader_utils.h"
using namespace angle;
namespace
{
constexpr unsigned int kIterationsPerStep = 10;
struct VulkanBarriersPerfParams final : public RenderTestParams
{
VulkanBarriersPerfParams(bool largeTransfers, bool slowFS)
{
iterationsPerStep = kIterationsPerStep;
// Common default parameters
eglParameters = egl_platform::VULKAN();
majorVersion = 2;
minorVersion = 0;
windowWidth = 256;
windowHeight = 256;
trackGpuTime = true;
doLargeTransfers = largeTransfers;
doSlowFragmentShaders = slowFS;
}
std::string story() const override;
// Static parameters
static constexpr int kImageSizes[3] = {256, 512, 4096};
bool doLargeTransfers;
bool doSlowFragmentShaders;
};
constexpr int VulkanBarriersPerfParams::kImageSizes[];
std::ostream &operator<<(std::ostream &os, const VulkanBarriersPerfParams ¶ms)
{
os << params.backendAndStory().substr(1);
return os;
}
class VulkanBarriersPerfBenchmark : public ANGLERenderTest,
public ::testing::WithParamInterface<VulkanBarriersPerfParams>
{
public:
VulkanBarriersPerfBenchmark();
void initializeBenchmark() override;
void destroyBenchmark() override;
void drawBenchmark() override;
private:
void createTexture(uint32_t textureIndex, uint32_t sizeIndex, bool compressed);
void createFramebuffer(uint32_t fboIndex, uint32_t textureIndex, uint32_t sizeIndex);
void createResources();
// Handle to the program object
GLProgram mProgram;
// Attribute locations
GLint mPositionLoc;
GLint mTexCoordLoc;
// Sampler location
GLint mSamplerLoc;
// Texture handles
GLTexture mTextures[4];
// Framebuffer handles
GLFramebuffer mFbos[2];
// Buffer handle
GLBuffer mVertexBuffer;
GLBuffer mIndexBuffer;
static constexpr size_t kSmallFboIndex = 0;
static constexpr size_t kLargeFboIndex = 1;
static constexpr size_t kSmallTextureIndex = 0;
static constexpr size_t kLargeTextureIndex = 1;
static constexpr size_t kTransferTexture1Index = 2;
static constexpr size_t kTransferTexture2Index = 3;
static constexpr size_t kSmallSizeIndex = 0;
static constexpr size_t kLargeSizeIndex = 1;
static constexpr size_t kHugeSizeIndex = 2;
};
std::string VulkanBarriersPerfParams::story() const
{
std::ostringstream sout;
sout << RenderTestParams::story();
if (doLargeTransfers)
{
sout << "_transfer";
}
if (doSlowFragmentShaders)
{
sout << "_slowfs";
}
return sout.str();
}
VulkanBarriersPerfBenchmark::VulkanBarriersPerfBenchmark()
: ANGLERenderTest("VulkanBarriersPerf", GetParam()),
mPositionLoc(-1),
mTexCoordLoc(-1),
mSamplerLoc(-1)
{}
constexpr char kVS[] = R"(attribute vec4 a_position;
attribute vec2 a_texCoord;
varying vec2 v_texCoord;
void main()
{
gl_Position = a_position;
v_texCoord = a_texCoord;
})";
constexpr char kShortFS[] = R"(precision mediump float;
varying vec2 v_texCoord;
uniform sampler2D s_texture;
void main()
{
gl_FragColor = texture2D(s_texture, v_texCoord);
})";
constexpr char kSlowFS[] = R"(precision mediump float;
varying vec2 v_texCoord;
uniform sampler2D s_texture;
void main()
{
vec4 outColor = vec4(0);
if (v_texCoord.x < 0.2)
{
for (int i = 0; i < 100; ++i)
{
outColor += texture2D(s_texture, v_texCoord);
}
}
gl_FragColor = outColor;
})";
void VulkanBarriersPerfBenchmark::createTexture(uint32_t textureIndex,
uint32_t sizeIndex,
bool compressed)
{
const auto ¶ms = GetParam();
// TODO(syoussefi): compressed copy using vkCmdCopyImage not yet implemented in the vulkan
// backend. http://anglebug.com/2999
glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, params.kImageSizes[sizeIndex],
params.kImageSizes[sizeIndex], 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
// Disable mipmapping
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
void VulkanBarriersPerfBenchmark::createFramebuffer(uint32_t fboIndex,
uint32_t textureIndex,
uint32_t sizeIndex)
{
createTexture(textureIndex, sizeIndex, false);
glBindFramebuffer(GL_FRAMEBUFFER, mFbos[fboIndex]);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
mTextures[textureIndex], 0);
}
void VulkanBarriersPerfBenchmark::createResources()
{
const auto ¶ms = GetParam();
mProgram.makeRaster(kVS, params.doSlowFragmentShaders ? kSlowFS : kShortFS);
ASSERT_TRUE(mProgram.valid());
// Get the attribute locations
mPositionLoc = glGetAttribLocation(mProgram, "a_position");
mTexCoordLoc = glGetAttribLocation(mProgram, "a_texCoord");
// Get the sampler location
mSamplerLoc = glGetUniformLocation(mProgram, "s_texture");
// Build the vertex buffer
GLfloat vertices[] = {
-0.5f, 0.5f, 0.0f, // Position 0
0.0f, 0.0f, // TexCoord 0
-0.5f, -0.5f, 0.0f, // Position 1
0.0f, 1.0f, // TexCoord 1
0.5f, -0.5f, 0.0f, // Position 2
1.0f, 1.0f, // TexCoord 2
0.5f, 0.5f, 0.0f, // Position 3
1.0f, 0.0f // TexCoord 3
};
glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
GLushort indices[] = {0, 1, 2, 0, 2, 3};
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
// Use tightly packed data
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// Create four textures. Two of them are going to be framebuffers, and two are used for large
// transfers.
createFramebuffer(kSmallFboIndex, kSmallTextureIndex, kSmallSizeIndex);
createFramebuffer(kLargeFboIndex, kLargeTextureIndex, kLargeSizeIndex);
if (params.doLargeTransfers)
{
createTexture(kTransferTexture1Index, kHugeSizeIndex, true);
createTexture(kTransferTexture2Index, kHugeSizeIndex, true);
}
}
void VulkanBarriersPerfBenchmark::initializeBenchmark()
{
createResources();
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
ASSERT_GL_NO_ERROR();
}
void VulkanBarriersPerfBenchmark::destroyBenchmark() {}
void VulkanBarriersPerfBenchmark::drawBenchmark()
{
const auto ¶ms = GetParam();
glUseProgram(mProgram);
// Bind the buffers
glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
// Load the vertex position
glVertexAttribPointer(mPositionLoc, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0);
// Load the texture coordinate
glVertexAttribPointer(mTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat),
reinterpret_cast<void *>(3 * sizeof(GLfloat)));
glEnableVertexAttribArray(mPositionLoc);
glEnableVertexAttribArray(mTexCoordLoc);
// Set the texture sampler to texture unit to 0
glUniform1i(mSamplerLoc, 0);
/*
* The perf benchmark does the following:
*
* - Alternately clear and draw from fbo 1 into fbo 2 and back. This would use the color
* attachment and shader read-only layouts in the fragment shader and color attachment stages.
*
* Once compressed texture copies are supported, alternately transfer large chunks of data from
* texture 1 into texture 2 and back. This would use the transfer layouts in the transfer
* stage.
*
* Once compute shader support is added, another independent set of operations could be a few
* dispatches. This would use the general and shader read-only layouts in the compute stage.
*
* The idea is to create independent pipelines of operations that would run in parallel on the
* GPU. Regressions or inefficiencies in the barrier implementation could result in
* serialization of these jobs, resulting in a hit in performance.
*
* The above operations for example should ideally run on the GPU threads in parallel:
*
* + |---draw---||---draw---||---draw---||---draw---||---draw---|
* + |-----------transfer------------||-----------transfer------------|
* + |-----dispatch------||------dispatch------||------dispatch------|
*
* If barriers are too restrictive, situations like this could happen (draw is blocking
* transfer):
*
* + |---draw---||---draw---||---draw---||---draw---||---draw---|
* + |-----------transfer------------||-----------transfer------------|
*
* Or like this (transfer is blocking draw):
*
* + |---draw---| |---draw---| |---draw---|
* + |-----------transfer------------||-----------transfer------------|
*
* Or like this (draw and transfer blocking each other):
*
* + |---draw---| |---draw---|
* + |-----------transfer------------| |-----------transfer------------|
*
* The idea of doing slow FS calls is to make the second case above slower (by making the draw
* slower than the transfer):
*
* + |------------------draw------------------| |-...draw...-|
* + |-----------transfer------------| |-----------transfer------------|
*/
startGpuTimer();
for (unsigned int iteration = 0; iteration < params.iterationsPerStep; ++iteration)
{
bool altEven = iteration % 2 == 0;
const int fboDestIndex = altEven ? kLargeFboIndex : kSmallFboIndex;
const int fboTexSrcIndex = altEven ? kSmallTextureIndex : kLargeTextureIndex;
const int fboDestSizeIndex = altEven ? kLargeSizeIndex : kSmallSizeIndex;
// Set the viewport
glViewport(0, 0, fboDestSizeIndex, fboDestSizeIndex);
// Clear the color buffer
glClear(GL_COLOR_BUFFER_BIT);
// Bind the framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, mFbos[fboDestIndex]);
// Bind the texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, mTextures[fboTexSrcIndex]);
ASSERT_GL_NO_ERROR();
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
}
stopGpuTimer();
ASSERT_GL_NO_ERROR();
}
} // namespace
TEST_P(VulkanBarriersPerfBenchmark, Run)
{
run();
}
ANGLE_INSTANTIATE_TEST(VulkanBarriersPerfBenchmark,
VulkanBarriersPerfParams(false, false),
VulkanBarriersPerfParams(true, false),
VulkanBarriersPerfParams(true, true));