Hash :
268653c9
Author :
Date :
2021-11-25T13:37:58
Vulkan: Update a test to triger large dirty bit handling Some traces bind one VBO to a large number of VAOs,and use glBufferData to change buffer size frequently,this will cause glBufferData spending a lot of time doing VAO dirty bit handling, which leads to high cpu load in these traces.This test could triger this issue. Bug: angleproject:6371 Change-Id: I99292825b8cb5bba58cc6b37e3baa7adcd02c780 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3301536 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@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 212 213 214 215 216 217 218 219 220 221 222 223
//
// Copyright 2021 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.
//
// VertexArrayPerfTest:
// Performance test for glBindVertexArray.
//
#include "ANGLEPerfTest.h"
#include "DrawCallPerfParams.h"
#include "test_utils/gl_raii.h"
using namespace angle;
namespace
{
enum class TestMode
{
BufferData,
BindBuffer,
UpdateBufferData,
};
struct VertexArrayParams final : public RenderTestParams
{
VertexArrayParams()
{
iterationsPerStep = 1;
// Common default params
majorVersion = 3;
minorVersion = 0;
windowWidth = 720;
windowHeight = 720;
}
std::string story() const override;
int numVertexArrays = 2000;
int numBuffers = 5;
GLuint bufferSize[5] = {384, 1028, 192, 384, 192};
TestMode testMode = TestMode::BufferData;
};
std::ostream &operator<<(std::ostream &os, const VertexArrayParams ¶ms)
{
os << params.backendAndStory().substr(1);
return os;
}
std::string VertexArrayParams::story() const
{
std::stringstream strstr;
strstr << RenderTestParams::story();
if (testMode == TestMode::BindBuffer)
{
strstr << "_bindbuffer";
}
else if (testMode == TestMode::UpdateBufferData)
{
strstr << "_updatebufferdata";
}
return strstr.str();
}
class VertexArrayBenchmark : public ANGLERenderTest,
public ::testing::WithParamInterface<VertexArrayParams>
{
public:
VertexArrayBenchmark();
void initializeBenchmark() override;
void destroyBenchmark() override;
void drawBenchmark() override;
void rebindVertexArray(GLuint vertexArrayID, GLuint bufferID);
void updateBufferData(GLuint vertexArrayID, GLuint bufferID, GLuint bufferSize);
private:
std::vector<GLuint> mBuffers;
GLuint mProgram = 0;
GLint mAttribLocation = 0;
std::vector<GLuint> mVertexArrays;
};
VertexArrayBenchmark::VertexArrayBenchmark() : ANGLERenderTest("VertexArrayPerf", GetParam()) {}
void VertexArrayBenchmark::initializeBenchmark()
{
constexpr char kVS[] = R"(attribute vec4 position;
attribute float in_attrib;
varying float v_attrib;
void main()
{
v_attrib = in_attrib;
gl_Position = position;
})";
constexpr char kFS[] = R"(precision mediump float;
varying float v_attrib;
void main()
{
gl_FragColor = vec4(v_attrib, 0, 0, 1);
})";
mProgram = CompileProgram(kVS, kFS);
ASSERT_NE(0u, mProgram);
mAttribLocation = glGetAttribLocation(mProgram, "in_attrib");
ASSERT_NE(mAttribLocation, -1);
// Generate 5 buffers.
int numBuffers = GetParam().numBuffers;
mBuffers.resize(numBuffers, 0);
glGenBuffers(numBuffers, mBuffers.data());
int numVertexArrays = GetParam().numVertexArrays;
mVertexArrays.resize(numVertexArrays, 0);
glGenVertexArrays(numVertexArrays, mVertexArrays.data());
// Bind one VBO to all VAOs.
for (GLuint vertexArray : mVertexArrays)
{
rebindVertexArray(vertexArray, mBuffers[0]);
}
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, mBuffers[0]);
}
void VertexArrayBenchmark::rebindVertexArray(GLuint vertexArrayID, GLuint bufferID)
{
// Rebind a vertex array object and a generic vertex attribute inside of it.
glBindVertexArray(vertexArrayID);
glBindBuffer(GL_ARRAY_BUFFER, bufferID);
glEnableVertexAttribArray(mAttribLocation);
glVertexAttribPointer(mAttribLocation, 1, GL_FLOAT, GL_FALSE, 4, nullptr);
glVertexAttribDivisor(mAttribLocation, 1);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void VertexArrayBenchmark::updateBufferData(GLuint vertexArrayID,
GLuint bufferID,
GLuint bufferSize)
{
glBindVertexArray(vertexArrayID);
glBindBuffer(GL_ARRAY_BUFFER, bufferID);
glEnableVertexAttribArray(mAttribLocation);
glVertexAttribPointer(mAttribLocation, 1, GL_FLOAT, GL_FALSE, 4, nullptr);
glBufferData(GL_ARRAY_BUFFER, bufferSize, nullptr, GL_STATIC_DRAW);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void VertexArrayBenchmark::destroyBenchmark()
{
glDeleteProgram(mProgram);
glDeleteVertexArrays(static_cast<GLsizei>(mVertexArrays.size()), mVertexArrays.data());
mVertexArrays.clear();
glDeleteBuffers(static_cast<GLsizei>(mBuffers.size()), mBuffers.data());
mBuffers.clear();
}
void VertexArrayBenchmark::drawBenchmark()
{
const VertexArrayParams ¶ms = GetParam();
if (params.testMode == TestMode::BufferData)
{
glBufferData(GL_ARRAY_BUFFER, 128, nullptr, GL_STATIC_DRAW);
}
else if (params.testMode == TestMode::UpdateBufferData)
{
int bufferSizeIndex = 0;
for (GLuint vertexArray : mVertexArrays)
{
bufferSizeIndex = ((bufferSizeIndex + 1) == 5) ? 0 : (bufferSizeIndex + 1);
updateBufferData(vertexArray, mBuffers[0], params.bufferSize[bufferSizeIndex]);
}
}
else
{
int bufferIndex = 0;
for (GLuint vertexArray : mVertexArrays)
{
bufferIndex = ((bufferIndex + 1) == params.numBuffers) ? 0 : (bufferIndex + 1);
rebindVertexArray(vertexArray, mBuffers[bufferIndex]);
}
}
}
TEST_P(VertexArrayBenchmark, Run)
{
run();
}
VertexArrayParams VulkanParams()
{
VertexArrayParams params;
params.eglParameters = egl_platform::VULKAN();
return params;
}
VertexArrayParams VulkanNullParams(TestMode testMode)
{
VertexArrayParams params;
params.eglParameters = egl_platform::VULKAN_NULL();
params.testMode = testMode;
return params;
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VertexArrayBenchmark);
ANGLE_INSTANTIATE_TEST(VertexArrayBenchmark,
VulkanParams(),
VulkanNullParams(TestMode::BindBuffer),
VulkanNullParams(TestMode::BufferData),
VulkanNullParams(TestMode::UpdateBufferData),
params::Native(VertexArrayParams()));
} // namespace