Hash :
b980c563
        
        Author :
  
        
        Date :
2018-11-27T11:34:27
        
      
Reformat all cpp and h files. This applies git cl format --full to all ANGLE sources. Bug: angleproject:2986 Change-Id: Ib504e618c1589332a37e97696cdc3515d739308f Reviewed-on: https://chromium-review.googlesource.com/c/1351367 Reviewed-by: Jamie Madill <jmadill@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 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 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
//
// Copyright 2018 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.
//
// CompilerPerfTest:
//   Performance test for the shader translator. The test initializes the compiler once and then
//   compiles the same shader repeatedly. There are different variations of the tests using
//   different shaders.
//
#include "ANGLEPerfTest.h"
#include "GLSLANG/ShaderLang.h"
#include "compiler/translator/Compiler.h"
#include "compiler/translator/InitializeGlobals.h"
#include "compiler/translator/PoolAlloc.h"
namespace
{
const char *kSimpleESSL100FragSource = R"(
precision mediump float;
void main()
{
    gl_FragColor = vec4(0, 1, 0, 1);
}
)";
const char *kSimpleESSL100Id = "SimpleESSL100";
const char *kSimpleESSL300FragSource = R"(#version 300 es
precision highp float;
out vec4 outColor;
void main()
{
    outColor = vec4(0, 1, 0, 1);
}
)";
const char *kSimpleESSL300Id = "SimpleESSL300";
const char *kRealWorldESSL100FragSource = R"(precision highp float;
precision highp sampler2D;
precision highp int;
varying vec2 vPixelCoords; // in pixels
uniform int uCircleCount;
uniform sampler2D uCircleParameters;
uniform sampler2D uBrushTex;
void main(void)
{
    float destAlpha = 0.0;
    for (int i = 0; i < 32; ++i)
    {
        vec4 parameterColor = texture2D(uCircleParameters,vec2(0.25, (float(i) + 0.5) / 32.0));
        vec2 center = parameterColor.xy;
        float circleRadius = parameterColor.z;
        float circleFlowAlpha = parameterColor.w;
        vec4 parameterColor2 = texture2D(uCircleParameters,vec2(0.75, (float(i) + 0.5) / 32.0));
        float circleRotation = parameterColor2.x;
        vec2 centerDiff = vPixelCoords - center;
        float radius = max(circleRadius, 0.5);
        float flowAlpha = (circleRadius < 0.5) ? circleFlowAlpha * circleRadius * circleRadius * 4.0: circleFlowAlpha;
        float antialiasMult = clamp((radius + 1.0 - length(centerDiff)) * 0.5, 0.0, 1.0);
        mat2 texRotation = mat2(cos(circleRotation), -sin(circleRotation), sin(circleRotation), cos(circleRotation));
        vec2 texCoords = texRotation * centerDiff / radius * 0.5 + 0.5;
        float texValue = texture2D(uBrushTex, texCoords).r;
        float circleAlpha = flowAlpha * antialiasMult * texValue;
        if (i < uCircleCount)
        {
            destAlpha = clamp(circleAlpha + (1.0 - circleAlpha) * destAlpha, 0.0, 1.0);
        }
    }
    gl_FragColor = vec4(0.0, 0.0, 0.0, destAlpha);
})";
const char *kRealWorldESSL100Id = "RealWorldESSL100";
// This shader is intended to trigger many AST transformations, particularly on the HLSL backend.
const char *kTrickyESSL300FragSource = R"(#version 300 es
precision highp float;
precision highp sampler2D;
precision highp isampler2D;
precision highp int;
float globalF;
uniform ivec4 uivec;
uniform int ui;
struct SS
{
    int iField;
    float fField;
    vec2 f2Field;
    sampler2D sField;
    isampler2D isField;
};
uniform SS us;
out vec4 my_FragColor;
float[3] sideEffectArray()
{
    globalF += 1.0;
    return float[3](globalF, globalF * 2.0, globalF * 3.0);
}
// This struct is unused and can be pruned.
struct SUnused
{
    vec2 fField;
};
void main()
{
    struct S2
    {
        float fField;
    } s2;
    vec4 foo = vec4(ui);
    mat4 fooM = mat4(foo.x);
    // Some unused variables that can be pruned.
    float fUnused, fUnused2;
    ivec4 iUnused, iUnused2;
    globalF = us.fField;
    s2.fField = us.fField;
    float[3] fa = sideEffectArray();
    globalF -= us.fField;
    if (fa == sideEffectArray())
    {
        globalF += us.fField * sin(2.0);
    }
    // Switch with fall-through.
    switch (ui)
    {
      case 0:
        // Sequence operator and matrix and vector dynamic indexing.
        (globalF += 1.0, fooM[ui][ui] += fooM[ui - 1][uivec[ui] + 1]);
      case 1:
        // Built-in emulation.
        foo[3] = tanh(foo[1]);
      default:
        // Sequence operator and length of an array expression with side effects.
        foo[2] += (globalF -= 1.0, float((sideEffectArray()).length() * 2));
    }
    int i = 0;
    do
    {
        s2.fField = us.fField * us.f2Field.x;
        // Sequence operator and short-circuiting operator with side effects on the right hand side.
    } while ((++i, i < int(us.fField) && ++i <= ui || ++i < ui * 2 - 3));
    // Samplers in structures and integer texture sampling.
    foo += texture(us.sField, us.f2Field) + intBitsToFloat(texture(us.isField, us.f2Field + 4.0));
    my_FragColor = foo * s2.fField * globalF + fooM[ui];
})";
const char *kTrickyESSL300Id = "TrickyESSL300";
constexpr int kNumIterationsPerStep = 4;
struct CompilerPerfParameters final : public angle::CompilerParameters
{
    CompilerPerfParameters(ShShaderOutput output,
                           const char *shaderSource,
                           const char *shaderSourceId)
        : angle::CompilerParameters(output), shaderSource(shaderSource)
    {
        testId = shaderSourceId;
        testId += "_";
        testId += angle::CompilerParameters::str();
    }
    const char *shaderSource;
    std::string testId;
};
std::ostream &operator<<(std::ostream &stream, const CompilerPerfParameters &p)
{
    stream << p.testId;
    return stream;
}
class CompilerPerfTest : public ANGLEPerfTest,
                         public ::testing::WithParamInterface<CompilerPerfParameters>
{
  public:
    CompilerPerfTest();
    void step() override;
    void SetUp() override;
    void TearDown() override;
  protected:
    void setTestShader(const char *str) { mTestShader = str; }
  private:
    const char *mTestShader;
    ShBuiltInResources mResources;
    TPoolAllocator mAllocator;
    sh::TCompiler *mTranslator;
};
CompilerPerfTest::CompilerPerfTest()
    : ANGLEPerfTest("CompilerPerf", GetParam().testId, kNumIterationsPerStep)
{}
void CompilerPerfTest::SetUp()
{
    ANGLEPerfTest::SetUp();
    InitializePoolIndex();
    mAllocator.push();
    SetGlobalPoolAllocator(&mAllocator);
    const auto ¶ms = GetParam();
    mTranslator = sh::ConstructCompiler(GL_FRAGMENT_SHADER, SH_WEBGL2_SPEC, params.output);
    sh::InitBuiltInResources(&mResources);
    mResources.FragmentPrecisionHigh = true;
    if (!mTranslator->Init(mResources))
    {
        SafeDelete(mTranslator);
    }
    setTestShader(params.shaderSource);
}
void CompilerPerfTest::TearDown()
{
    SafeDelete(mTranslator);
    SetGlobalPoolAllocator(nullptr);
    mAllocator.pop();
    FreePoolIndex();
    ANGLEPerfTest::TearDown();
}
void CompilerPerfTest::step()
{
    const char *shaderStrings[] = {mTestShader};
    ShCompileOptions compileOptions = SH_OBJECT_CODE | SH_VARIABLES |
                                      SH_INITIALIZE_UNINITIALIZED_LOCALS | SH_INIT_OUTPUT_VARIABLES;
#if !defined(NDEBUG)
    // Make sure that compilation succeeds and print the info log if it doesn't in debug mode.
    if (!mTranslator->compile(shaderStrings, 1, compileOptions))
    {
        std::cout << "Compiling perf test shader failed with log:\n"
                  << mTranslator->getInfoSink().info.c_str();
    }
#endif
    for (unsigned int iteration = 0; iteration < kNumIterationsPerStep; ++iteration)
    {
        mTranslator->compile(shaderStrings, 1, compileOptions);
    }
}
TEST_P(CompilerPerfTest, Run)
{
    run();
}
ANGLE_INSTANTIATE_TEST(
    CompilerPerfTest,
    CompilerPerfParameters(SH_HLSL_4_1_OUTPUT, kSimpleESSL100FragSource, kSimpleESSL100Id),
    CompilerPerfParameters(SH_HLSL_4_1_OUTPUT, kSimpleESSL300FragSource, kSimpleESSL300Id),
    CompilerPerfParameters(SH_HLSL_4_1_OUTPUT, kRealWorldESSL100FragSource, kRealWorldESSL100Id),
    CompilerPerfParameters(SH_HLSL_4_1_OUTPUT, kTrickyESSL300FragSource, kTrickyESSL300Id),
    CompilerPerfParameters(SH_GLSL_450_CORE_OUTPUT, kSimpleESSL100FragSource, kSimpleESSL100Id),
    CompilerPerfParameters(SH_GLSL_450_CORE_OUTPUT, kSimpleESSL300FragSource, kSimpleESSL300Id),
    CompilerPerfParameters(SH_GLSL_450_CORE_OUTPUT,
                           kRealWorldESSL100FragSource,
                           kRealWorldESSL100Id),
    CompilerPerfParameters(SH_GLSL_450_CORE_OUTPUT, kTrickyESSL300FragSource, kTrickyESSL300Id),
    CompilerPerfParameters(SH_ESSL_OUTPUT, kSimpleESSL100FragSource, kSimpleESSL100Id),
    CompilerPerfParameters(SH_ESSL_OUTPUT, kSimpleESSL300FragSource, kSimpleESSL300Id),
    CompilerPerfParameters(SH_ESSL_OUTPUT, kRealWorldESSL100FragSource, kRealWorldESSL100Id),
    CompilerPerfParameters(SH_ESSL_OUTPUT, kTrickyESSL300FragSource, kTrickyESSL300Id));
}  // anonymous namespace