Jamie Madill | 457aa6c | 2016-11-22 18:36:31 -0500 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2016 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | // LinkProgramPerfTest: |
| 7 | // Performance tests compiling a lot of shaders. |
| 8 | // |
| 9 | |
| 10 | #include "ANGLEPerfTest.h" |
| 11 | |
| 12 | #include <array> |
| 13 | |
Corentin Wallez | 922cbfc | 2016-11-25 16:23:18 -0500 | [diff] [blame] | 14 | #include "common/vector_utils.h" |
Jamie Madill | 457aa6c | 2016-11-22 18:36:31 -0500 | [diff] [blame] | 15 | #include "shader_utils.h" |
| 16 | |
| 17 | using namespace angle; |
| 18 | |
| 19 | namespace |
| 20 | { |
| 21 | |
| 22 | struct LinkProgramParams final : public RenderTestParams |
| 23 | { |
| 24 | LinkProgramParams() |
| 25 | { |
| 26 | majorVersion = 2; |
| 27 | minorVersion = 0; |
| 28 | windowWidth = 256; |
| 29 | windowHeight = 256; |
| 30 | } |
| 31 | |
| 32 | std::string suffix() const override |
| 33 | { |
| 34 | std::stringstream strstr; |
| 35 | strstr << RenderTestParams::suffix(); |
| 36 | |
| 37 | if (eglParameters.deviceType == EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE) |
| 38 | { |
| 39 | strstr << "_null"; |
| 40 | } |
| 41 | |
| 42 | return strstr.str(); |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | std::ostream &operator<<(std::ostream &os, const LinkProgramParams ¶ms) |
| 47 | { |
| 48 | os << params.suffix().substr(1); |
| 49 | return os; |
| 50 | } |
| 51 | |
| 52 | class LinkProgramBenchmark : public ANGLERenderTest, |
| 53 | public ::testing::WithParamInterface<LinkProgramParams> |
| 54 | { |
| 55 | public: |
| 56 | LinkProgramBenchmark(); |
| 57 | |
| 58 | void initializeBenchmark() override; |
| 59 | void destroyBenchmark() override; |
| 60 | void drawBenchmark() override; |
| 61 | |
| 62 | protected: |
| 63 | GLuint mVertexBuffer = 0; |
| 64 | }; |
| 65 | |
| 66 | LinkProgramBenchmark::LinkProgramBenchmark() : ANGLERenderTest("LinkProgram", GetParam()) |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | void LinkProgramBenchmark::initializeBenchmark() |
| 71 | { |
| 72 | std::array<Vector3, 6> vertices = {{Vector3(-1.0f, 1.0f, 0.5f), Vector3(-1.0f, -1.0f, 0.5f), |
| 73 | Vector3(1.0f, -1.0f, 0.5f), Vector3(-1.0f, 1.0f, 0.5f), |
| 74 | Vector3(1.0f, -1.0f, 0.5f), Vector3(1.0f, 1.0f, 0.5f)}}; |
| 75 | |
| 76 | glGenBuffers(1, &mVertexBuffer); |
| 77 | glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer); |
| 78 | glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vector3), vertices.data(), |
| 79 | GL_STATIC_DRAW); |
| 80 | }; |
| 81 | |
| 82 | void LinkProgramBenchmark::destroyBenchmark() |
| 83 | { |
| 84 | glDeleteBuffers(1, &mVertexBuffer); |
| 85 | } |
| 86 | |
| 87 | void LinkProgramBenchmark::drawBenchmark() |
| 88 | { |
| 89 | static const char *vertexShader = |
| 90 | "attribute vec2 position;\n" |
| 91 | "void main() {\n" |
| 92 | " gl_Position = vec4(position, 0, 1);\n" |
| 93 | "}"; |
| 94 | static const char *fragmentShader = |
| 95 | "precision mediump float;\n" |
| 96 | "void main() {\n" |
| 97 | " gl_FragColor = vec4(1, 0, 0, 1);\n" |
| 98 | "}"; |
| 99 | |
| 100 | GLuint program = CompileProgram(vertexShader, fragmentShader); |
| 101 | ASSERT_NE(0u, program); |
| 102 | |
| 103 | glUseProgram(program); |
| 104 | |
| 105 | GLint positionLoc = glGetAttribLocation(program, "position"); |
| 106 | glVertexAttribPointer(positionLoc, 2, GL_FLOAT, GL_FALSE, 8, nullptr); |
| 107 | glEnableVertexAttribArray(positionLoc); |
| 108 | |
| 109 | // Draw with the program to ensure the shader gets compiled and used. |
| 110 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 111 | |
| 112 | glDeleteProgram(program); |
| 113 | } |
| 114 | |
| 115 | using namespace egl_platform; |
| 116 | |
| 117 | LinkProgramParams LinkProgramD3D11Params() |
| 118 | { |
| 119 | LinkProgramParams params; |
| 120 | params.eglParameters = D3D11(); |
| 121 | return params; |
| 122 | } |
| 123 | |
| 124 | LinkProgramParams LinkProgramD3D9Params() |
| 125 | { |
| 126 | LinkProgramParams params; |
| 127 | params.eglParameters = D3D9(); |
| 128 | return params; |
| 129 | } |
| 130 | |
| 131 | LinkProgramParams LinkProgramOpenGLParams() |
| 132 | { |
| 133 | LinkProgramParams params; |
| 134 | params.eglParameters = OPENGL(); |
| 135 | return params; |
| 136 | } |
| 137 | |
| 138 | TEST_P(LinkProgramBenchmark, Run) |
| 139 | { |
| 140 | run(); |
| 141 | } |
| 142 | |
| 143 | ANGLE_INSTANTIATE_TEST(LinkProgramBenchmark, |
| 144 | LinkProgramD3D11Params(), |
| 145 | LinkProgramD3D9Params(), |
| 146 | LinkProgramOpenGLParams()); |
| 147 | |
| 148 | } // anonymous namespace |