Hash :
8af9ef3b
Author :
Date :
2020-10-06T10:59:07
Add emulated format clear perf test Bug: angleproject:4836 Change-Id: If900d288630ba5fbf82b8b1ce2ccab681cfc50c3 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2451481 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: 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
//
// 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.
//
// ClearPerf:
// Performance test for clearing framebuffers.
//
#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 = 256;
struct ClearParams final : public RenderTestParams
{
ClearParams()
{
iterationsPerStep = kIterationsPerStep;
trackGpuTime = true;
fboSize = 2048;
textureSize = 16;
internalFormat = GL_RGBA8;
}
std::string story() const override;
GLsizei fboSize;
GLsizei textureSize;
GLenum internalFormat;
};
std::ostream &operator<<(std::ostream &os, const ClearParams ¶ms)
{
os << params.backendAndStory().substr(1);
return os;
}
std::string ClearParams::story() const
{
std::stringstream strstr;
strstr << RenderTestParams::story();
if (internalFormat == GL_RGB8)
{
strstr << "_rgb";
}
return strstr.str();
}
class ClearBenchmark : public ANGLERenderTest, public ::testing::WithParamInterface<ClearParams>
{
public:
ClearBenchmark();
void initializeBenchmark() override;
void destroyBenchmark() override;
void drawBenchmark() override;
private:
void initShaders();
std::vector<GLuint> mTextures;
GLuint mProgram;
};
ClearBenchmark::ClearBenchmark() : ANGLERenderTest("Clear", GetParam()), mProgram(0u)
{
// Crashes on nvidia+d3d11. http://crbug.com/945415
if (GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
{
mSkipTest = true;
}
}
void ClearBenchmark::initializeBenchmark()
{
initShaders();
glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight());
ASSERT_GL_NO_ERROR();
}
void ClearBenchmark::initShaders()
{
constexpr char kVS[] = R"(void main()
{
gl_Position = vec4(0, 0, 0, 1);
})";
constexpr char kFS[] = R"(precision mediump float;
void main()
{
gl_FragColor = vec4(0);
})";
mProgram = CompileProgram(kVS, kFS);
ASSERT_NE(0u, mProgram);
glUseProgram(mProgram);
glDisable(GL_DEPTH_TEST);
ASSERT_GL_NO_ERROR();
}
void ClearBenchmark::destroyBenchmark()
{
glDeleteProgram(mProgram);
}
void ClearBenchmark::drawBenchmark()
{
const auto ¶ms = GetParam();
std::vector<float> textureData(params.textureSize * params.textureSize * 4, 0.5);
GLRenderbuffer colorRbo;
glBindRenderbuffer(GL_RENDERBUFFER, colorRbo);
glRenderbufferStorage(GL_RENDERBUFFER, params.internalFormat, params.fboSize, params.fboSize);
GLRenderbuffer depthRbo;
glBindRenderbuffer(GL_RENDERBUFFER, depthRbo);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, params.fboSize, params.fboSize);
GLFramebuffer fbo;
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRbo);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRbo);
startGpuTimer();
for (size_t it = 0; it < params.iterationsPerStep; ++it)
{
float clearValue = (it % 2) * 0.5f + 0.2f;
glClearColor(clearValue, clearValue, clearValue, clearValue);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 3);
}
stopGpuTimer();
ASSERT_GL_NO_ERROR();
}
ClearParams D3D11Params()
{
ClearParams params;
params.eglParameters = egl_platform::D3D11();
return params;
}
ClearParams OpenGLOrGLESParams()
{
ClearParams params;
params.eglParameters = egl_platform::OPENGL_OR_GLES();
return params;
}
ClearParams VulkanParams(bool emulatedFormat)
{
ClearParams params;
params.eglParameters = egl_platform::VULKAN();
if (emulatedFormat)
{
params.internalFormat = GL_RGB8;
}
return params;
}
} // anonymous namespace
TEST_P(ClearBenchmark, Run)
{
run();
}
ANGLE_INSTANTIATE_TEST(ClearBenchmark,
D3D11Params(),
OpenGLOrGLESParams(),
VulkanParams(false),
VulkanParams(true));