Hash :
1a3411c7
        
        Author :
  
        
        Date :
2022-04-01T18:42:51
        
      
Set SKIPPED status on skipped tests, rely on it in Gold tests.
Gold tests check for '[  SKIPPED ] {test_name}' notice in test output
instead of assuming that missing screenshot means SKIP. Now missing
screenshot raises an exception.
Also log the reason why the test was skipped.
Example:
[ RUN      ] TracePerfTest.Run/native_asphalt_8
../../src/tests/perf_tests/ANGLEPerfTest.cpp:837: Skipped
Test skipped due to missing extension:
GL_KHR_texture_compression_astc_ldr
[  SKIPPED ] TracePerfTest.Run/native_asphalt_8 (182 ms)
Bug: angleproject:6854
Change-Id: I2d88e2063a68ae95399a7932700f74032737ec91
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3565561
Reviewed-by: Cody Northrop <cnorthrop@google.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Roman Lavrov <romanl@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
//
// Copyright 2016 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.
//
// BindingPerf:
//   Performance test for binding objects
//
#include "ANGLEPerfTest.h"
#include <iostream>
#include <random>
#include <sstream>
#include "test_utils/angle_test_instantiate.h"
#include "util/shader_utils.h"
namespace angle
{
namespace
{
constexpr unsigned int kIterationsPerStep = 128;
enum TestMode
{
    VertexArray,
    MultipleBindings,
};
enum AllocationStyle
{
    EVERY_ITERATION,
    AT_INITIALIZATION
};
struct BindingsParams final : public RenderTestParams
{
    BindingsParams()
    {
        // Common default params
        majorVersion = 2;
        minorVersion = 0;
        windowWidth  = 720;
        windowHeight = 720;
        numObjects        = 100;
        allocationStyle   = EVERY_ITERATION;
        iterationsPerStep = kIterationsPerStep;
    }
    std::string story() const override;
    TestMode testMode = TestMode::MultipleBindings;
    size_t numObjects;
    AllocationStyle allocationStyle;
};
std::ostream &operator<<(std::ostream &os, const BindingsParams ¶ms)
{
    os << params.backendAndStory().substr(1);
    return os;
}
std::string BindingsParams::story() const
{
    std::stringstream strstr;
    strstr << RenderTestParams::story();
    if (testMode == TestMode::VertexArray)
    {
        strstr << "_vertexarray";
    }
    else
    {
        strstr << "_" << numObjects << "_objects";
        switch (allocationStyle)
        {
            case EVERY_ITERATION:
                strstr << "_allocated_every_iteration";
                break;
            case AT_INITIALIZATION:
                strstr << "_allocated_at_initialization";
                break;
            default:
                strstr << "_err";
                break;
        }
    }
    return strstr.str();
}
class BindingsBenchmark : public ANGLERenderTest,
                          public ::testing::WithParamInterface<BindingsParams>
{
  public:
    BindingsBenchmark();
    void initializeBenchmark() override;
    void destroyBenchmark() override;
    void drawBenchmark() override;
  private:
    // TODO: Test binding perf of more than just buffers
    std::vector<GLuint> mBuffers;
    std::vector<GLenum> mBindingPoints;
    GLuint mMaxVertexAttribs = 0;
};
BindingsBenchmark::BindingsBenchmark() : ANGLERenderTest("Bindings", GetParam())
{
    if (GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
    {
        skipTest("http://anglebug.com/6264 Flaky on OpenGL");
    }
}
void BindingsBenchmark::initializeBenchmark()
{
    const BindingsParams ¶ms = GetParam();
    mBuffers.resize(params.numObjects, 0);
    if (params.allocationStyle == AT_INITIALIZATION)
    {
        glGenBuffers(static_cast<GLsizei>(mBuffers.size()), mBuffers.data());
        for (size_t bufferIdx = 0; bufferIdx < mBuffers.size(); bufferIdx++)
        {
            glBindBuffer(GL_ARRAY_BUFFER, mBuffers[bufferIdx]);
        }
        glBindBuffer(GL_ARRAY_BUFFER, 0);
    }
    if (params.testMode == TestMode::MultipleBindings)
    {
        mBindingPoints.push_back(GL_ARRAY_BUFFER);
        mBindingPoints.push_back(GL_ELEMENT_ARRAY_BUFFER);
        if (params.majorVersion >= 3)
        {
            mBindingPoints.push_back(GL_PIXEL_PACK_BUFFER);
            mBindingPoints.push_back(GL_PIXEL_UNPACK_BUFFER);
            mBindingPoints.push_back(GL_COPY_READ_BUFFER);
            mBindingPoints.push_back(GL_COPY_WRITE_BUFFER);
            mBindingPoints.push_back(GL_TRANSFORM_FEEDBACK_BUFFER);
            mBindingPoints.push_back(GL_UNIFORM_BUFFER);
        }
        if (params.majorVersion > 3 || (params.majorVersion == 3 && params.minorVersion >= 1))
        {
            mBindingPoints.push_back(GL_ATOMIC_COUNTER_BUFFER);
            mBindingPoints.push_back(GL_SHADER_STORAGE_BUFFER);
            mBindingPoints.push_back(GL_DRAW_INDIRECT_BUFFER);
            mBindingPoints.push_back(GL_DISPATCH_INDIRECT_BUFFER);
        }
    }
    else
    {
        mBindingPoints.resize(mBuffers.size(), GL_ARRAY_BUFFER);
    }
    glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, reinterpret_cast<GLint *>(&mMaxVertexAttribs));
}
void BindingsBenchmark::destroyBenchmark()
{
    const BindingsParams ¶ms = GetParam();
    if (params.allocationStyle == AT_INITIALIZATION)
    {
        glDeleteBuffers(static_cast<GLsizei>(mBuffers.size()), mBuffers.data());
    }
}
void BindingsBenchmark::drawBenchmark()
{
    const BindingsParams ¶ms = GetParam();
    for (unsigned int it = 0; it < params.iterationsPerStep; ++it)
    {
        // Generate a buffer (if needed) and bind it to a "random" binding point
        if (params.allocationStyle == EVERY_ITERATION)
        {
            glGenBuffers(static_cast<GLsizei>(mBuffers.size()), mBuffers.data());
        }
        // Fetch a few variables from the underlying data structure to keep them in registers.
        // Otherwise each loop iteration they'll be fetched again because the compiler cannot
        // guarantee that those are unchanged when calling glBindBuffer.
        const GLuint *buffers       = mBuffers.data();
        const GLenum *bindingPoints = mBindingPoints.data();
        size_t bindingPointsSize    = mBindingPoints.size();
        size_t buffersSize          = mBuffers.size();
        size_t bindingIndex         = it % bindingPointsSize;
        for (GLuint bufferIdx = 0; bufferIdx < buffersSize; bufferIdx++)
        {
            GLenum binding = bindingPoints[bindingIndex];
            glBindBuffer(binding, buffers[bufferIdx]);
            // Instead of doing a costly division to get an index in the range [0,bindingPointsSize)
            // do a bounds-check and reset the index.
            ++bindingIndex;
            bindingIndex = (bindingIndex >= bindingPointsSize) ? 0 : bindingIndex;
            if (params.testMode == TestMode::VertexArray)
            {
                GLuint vertexAttribIndex = bufferIdx % mMaxVertexAttribs;
                glVertexAttribPointer(vertexAttribIndex, 1, GL_FLOAT, GL_FALSE, 0, 0);
            }
        }
        // Delete all the buffers
        if (params.allocationStyle == EVERY_ITERATION)
        {
            glDeleteBuffers(static_cast<GLsizei>(mBuffers.size()), mBuffers.data());
        }
    }
    ASSERT_GL_NO_ERROR();
}
BindingsParams D3D11Params(AllocationStyle allocationStyle)
{
    BindingsParams params;
    params.eglParameters   = egl_platform::D3D11_NULL();
    params.allocationStyle = allocationStyle;
    return params;
}
BindingsParams OpenGLOrGLESParams(AllocationStyle allocationStyle)
{
    BindingsParams params;
    params.eglParameters   = egl_platform::OPENGL_OR_GLES_NULL();
    params.allocationStyle = allocationStyle;
    return params;
}
BindingsParams VulkanParams(AllocationStyle allocationStyle, TestMode testMode)
{
    BindingsParams params;
    params.eglParameters   = egl_platform::VULKAN_NULL();
    params.allocationStyle = allocationStyle;
    params.testMode        = testMode;
    return params;
}
TEST_P(BindingsBenchmark, Run)
{
    run();
}
}  // namespace
ANGLE_INSTANTIATE_TEST(BindingsBenchmark,
                       D3D11Params(EVERY_ITERATION),
                       D3D11Params(AT_INITIALIZATION),
                       OpenGLOrGLESParams(EVERY_ITERATION),
                       OpenGLOrGLESParams(AT_INITIALIZATION),
                       VulkanParams(EVERY_ITERATION, TestMode::MultipleBindings),
                       VulkanParams(AT_INITIALIZATION, TestMode::MultipleBindings),
                       VulkanParams(AT_INITIALIZATION, TestMode::VertexArray));
}  // namespace angle