Hash :
82ff27bf
Author :
Date :
2022-07-08T12:38:41
Add Metal to the perf tests Bug: angleproject:7296 Change-Id: I69cd17c464d48b933c51466bf9d21c278438c4e1 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3753277 Reviewed-by: Yuly Novikov <ynovikov@chromium.org> Commit-Queue: Yuly Novikov <ynovikov@chromium.org> Reviewed-by: 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 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
//
// 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 MetalParams()
{
VertexArrayParams params;
params.eglParameters = egl_platform::METAL();
return params;
}
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,
MetalParams(),
VulkanParams(),
VulkanNullParams(TestMode::BindBuffer),
VulkanNullParams(TestMode::BufferData),
VulkanNullParams(TestMode::UpdateBufferData),
params::Native(VertexArrayParams()));
} // namespace