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
//
// 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.
//
// FramebufferAttachPerfTest:
//   Performance test for attaching and detaching resources to a Framebuffer.
//
#include "ANGLEPerfTest.h"
#include "test_utils/gl_raii.h"
#include <iostream>
#include <random>
#include <sstream>
namespace angle
{
constexpr unsigned int kIterationsPerStep = 256;
constexpr unsigned int kTextureSize       = 256;
constexpr std::size_t kTextureCount       = 4;
constexpr std::size_t kFboCount           = kTextureCount;
constexpr std::size_t kAdditionalFboCount = kFboCount * kFboCount;
struct FramebufferAttachmentParams final : public RenderTestParams
{
    FramebufferAttachmentParams()
    {
        iterationsPerStep = kIterationsPerStep;
        // Common default params
        majorVersion = 3;
        minorVersion = 0;
        windowWidth  = kTextureSize;
        windowHeight = kTextureSize;
    }
    std::string story() const override;
};
std::ostream &operator<<(std::ostream &os, const FramebufferAttachmentParams ¶ms)
{
    os << params.backendAndStory().substr(1);
    return os;
}
std::string FramebufferAttachmentParams::story() const
{
    std::stringstream strstr;
    strstr << RenderTestParams::story();
    return strstr.str();
}
class FramebufferAttachmentBenchmark
    : public ANGLERenderTest,
      public ::testing::WithParamInterface<FramebufferAttachmentParams>
{
  public:
    FramebufferAttachmentBenchmark() : ANGLERenderTest("Framebuffers", GetParam()) {}
    void initializeBenchmark() override;
    void drawBenchmark() override;
  protected:
    void initTextures();
    std::array<GLTexture, kTextureCount> mTextures;
    std::array<GLFramebuffer, kFboCount> mFbo;
};
void FramebufferAttachmentBenchmark::initializeBenchmark()
{
    initTextures();
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight());
    ASSERT_GL_NO_ERROR();
    GLint maxAttachmentCount;
    glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxAttachmentCount);
    if (mTextures.size() > static_cast<size_t>(maxAttachmentCount))
    {
        skipTest("Texture count exceeds maximum attachment unit count");
    }
}
void FramebufferAttachmentBenchmark::initTextures()
{
    std::vector<GLubyte> textureData(kTextureSize * kTextureSize * 4);
    for (auto &byte : textureData)
    {
        byte = rand() % 255u;
    }
    for (GLTexture &texture : mTextures)
    {
        glBindTexture(GL_TEXTURE_2D, texture);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kTextureSize, kTextureSize, 0, GL_RGBA,
                     GL_UNSIGNED_BYTE, textureData.data());
        glBindTexture(GL_TEXTURE_2D, 0);
    }
}
void FramebufferAttachmentBenchmark::drawBenchmark()
{
    const auto ¶ms = GetParam();
    size_t fboCount     = mFbo.size();
    size_t textureCount = mTextures.size();
    for (size_t it = 0; it < params.iterationsPerStep; ++it)
    {
        // Attach
        for (size_t fboIndex = 0; fboIndex < fboCount; fboIndex++)
        {
            glBindFramebuffer(GL_FRAMEBUFFER, mFbo[fboIndex]);
            for (size_t textureIndex = 0; textureIndex < textureCount; textureIndex++)
            {
                glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + textureIndex,
                                       GL_TEXTURE_2D, mTextures[textureIndex], 0);
            }
            glBindFramebuffer(GL_FRAMEBUFFER, 0);
        }
        // Detach
        for (size_t fboIndex = 0; fboIndex < fboCount; fboIndex++)
        {
            glBindFramebuffer(GL_FRAMEBUFFER, mFbo[fboIndex]);
            for (size_t index = 0; index < textureCount; index++)
            {
                size_t textureIndex = mTextures.size() - (index + 1);
                glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + textureIndex,
                                       GL_TEXTURE_2D, 0, 0);
            }
            glBindFramebuffer(GL_FRAMEBUFFER, 0);
        }
    }
    ASSERT_GL_NO_ERROR();
}
class FramebufferAttachmentStateUpdateBenchmark : public FramebufferAttachmentBenchmark
{
  public:
    FramebufferAttachmentStateUpdateBenchmark() : FramebufferAttachmentBenchmark() {}
    void initializeBenchmark() override;
    void destroyBenchmark() override;
    void drawBenchmark() override;
  private:
    std::array<GLFramebuffer, kAdditionalFboCount> mAdditionalFbo;
};
void FramebufferAttachmentStateUpdateBenchmark::initializeBenchmark()
{
    FramebufferAttachmentBenchmark::initializeBenchmark();
    // Attach
    for (size_t fboIndex = 0; fboIndex < mAdditionalFbo.size(); fboIndex++)
    {
        glBindFramebuffer(GL_FRAMEBUFFER, mAdditionalFbo[fboIndex]);
        for (size_t textureIndex = 0; textureIndex < mTextures.size(); textureIndex++)
        {
            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + textureIndex,
                                   GL_TEXTURE_2D, mTextures[textureIndex], 0);
        }
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
    }
}
void FramebufferAttachmentStateUpdateBenchmark::destroyBenchmark()
{
    // Detach
    for (size_t fboIndex = 0; fboIndex < mAdditionalFbo.size(); fboIndex++)
    {
        glBindFramebuffer(GL_FRAMEBUFFER, mAdditionalFbo[fboIndex]);
        for (size_t index = 0; index < mTextures.size(); index++)
        {
            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + index, GL_TEXTURE_2D, 0,
                                   0);
        }
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
    }
    FramebufferAttachmentBenchmark::destroyBenchmark();
}
void FramebufferAttachmentStateUpdateBenchmark::drawBenchmark()
{
    const auto ¶ms = GetParam();
    size_t textureCount  = mTextures.size();
    GLenum nearestFilter = GL_NEAREST;
    GLenum linearFilter  = GL_LINEAR;
    for (size_t it = 0; it < params.iterationsPerStep; ++it)
    {
        for (size_t textureIndex = 0; textureIndex < textureCount; textureIndex++)
        {
            glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
                            (it % 2) ? linearFilter : nearestFilter);
            glBindTexture(GL_TEXTURE_2D, 0);
        }
    }
    ASSERT_GL_NO_ERROR();
}
FramebufferAttachmentParams VulkanParams()
{
    FramebufferAttachmentParams params;
    params.eglParameters = egl_platform::VULKAN_NULL();
    return params;
}
TEST_P(FramebufferAttachmentBenchmark, Run)
{
    run();
}
TEST_P(FramebufferAttachmentStateUpdateBenchmark, Run)
{
    run();
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FramebufferAttachmentBenchmark);
ANGLE_INSTANTIATE_TEST(FramebufferAttachmentBenchmark, VulkanParams());
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FramebufferAttachmentStateUpdateBenchmark);
ANGLE_INSTANTIATE_TEST(FramebufferAttachmentStateUpdateBenchmark, VulkanParams());
}  // namespace angle