Path: blob/main_old/src/tests/perf_tests/LinkProgramPerfTest.cpp
1693 views
//1// Copyright 2016 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// LinkProgramPerfTest:6// Performance tests compiling a lot of shaders.7//89#include "ANGLEPerfTest.h"1011#include <array>1213#include "common/vector_utils.h"14#include "util/shader_utils.h"1516using namespace angle;1718namespace19{2021enum class TaskOption22{23CompileOnly,24CompileAndLink,2526Unspecified27};2829enum class ThreadOption30{31SingleThread,32MultiThread,3334Unspecified35};3637struct LinkProgramParams final : public RenderTestParams38{39LinkProgramParams(TaskOption taskOptionIn, ThreadOption threadOptionIn)40{41iterationsPerStep = 1;4243majorVersion = 2;44minorVersion = 0;45windowWidth = 256;46windowHeight = 256;47taskOption = taskOptionIn;48threadOption = threadOptionIn;49}5051std::string story() const override52{53std::stringstream strstr;54strstr << RenderTestParams::story();5556if (taskOption == TaskOption::CompileOnly)57{58strstr << "_compile_only";59}60else if (taskOption == TaskOption::CompileAndLink)61{62strstr << "_compile_and_link";63}6465if (threadOption == ThreadOption::SingleThread)66{67strstr << "_single_thread";68}69else if (threadOption == ThreadOption::MultiThread)70{71strstr << "_multi_thread";72}7374if (eglParameters.deviceType == EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE)75{76strstr << "_null";77}7879return strstr.str();80}8182TaskOption taskOption;83ThreadOption threadOption;84};8586std::ostream &operator<<(std::ostream &os, const LinkProgramParams ¶ms)87{88os << params.backendAndStory().substr(1);89return os;90}9192class LinkProgramBenchmark : public ANGLERenderTest,93public ::testing::WithParamInterface<LinkProgramParams>94{95public:96LinkProgramBenchmark();9798void initializeBenchmark() override;99void destroyBenchmark() override;100void drawBenchmark() override;101102protected:103GLuint mVertexBuffer = 0;104};105106LinkProgramBenchmark::LinkProgramBenchmark() : ANGLERenderTest("LinkProgram", GetParam()) {}107108void LinkProgramBenchmark::initializeBenchmark()109{110if (GetParam().threadOption == ThreadOption::SingleThread)111{112glMaxShaderCompilerThreadsKHR(0);113}114115std::array<Vector3, 6> vertices = {{Vector3(-1.0f, 1.0f, 0.5f), Vector3(-1.0f, -1.0f, 0.5f),116Vector3(1.0f, -1.0f, 0.5f), Vector3(-1.0f, 1.0f, 0.5f),117Vector3(1.0f, -1.0f, 0.5f), Vector3(1.0f, 1.0f, 0.5f)}};118119glGenBuffers(1, &mVertexBuffer);120glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);121glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vector3), vertices.data(),122GL_STATIC_DRAW);123}124125void LinkProgramBenchmark::destroyBenchmark()126{127glDeleteBuffers(1, &mVertexBuffer);128}129130void LinkProgramBenchmark::drawBenchmark()131{132static const char *vertexShader =133"attribute vec2 position;\n"134"void main() {\n"135" gl_Position = vec4(position, 0, 1);\n"136"}";137static const char *fragmentShader =138"precision mediump float;\n"139"void main() {\n"140" gl_FragColor = vec4(1, 0, 0, 1);\n"141"}";142GLuint vs = CompileShader(GL_VERTEX_SHADER, vertexShader);143GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fragmentShader);144145ASSERT_NE(0u, vs);146ASSERT_NE(0u, fs);147if (GetParam().taskOption == TaskOption::CompileOnly)148{149glDeleteShader(vs);150glDeleteShader(fs);151return;152}153154GLuint program = glCreateProgram();155ASSERT_NE(0u, program);156157glAttachShader(program, vs);158glDeleteShader(vs);159glAttachShader(program, fs);160glDeleteShader(fs);161glLinkProgram(program);162glUseProgram(program);163164GLint positionLoc = glGetAttribLocation(program, "position");165glVertexAttribPointer(positionLoc, 2, GL_FLOAT, GL_FALSE, 8, nullptr);166glEnableVertexAttribArray(positionLoc);167168// Draw with the program to ensure the shader gets compiled and used.169glDrawArrays(GL_TRIANGLES, 0, 6);170171glDeleteProgram(program);172}173174using namespace egl_platform;175176LinkProgramParams LinkProgramD3D11Params(TaskOption taskOption, ThreadOption threadOption)177{178LinkProgramParams params(taskOption, threadOption);179params.eglParameters = D3D11();180return params;181}182183LinkProgramParams LinkProgramOpenGLOrGLESParams(TaskOption taskOption, ThreadOption threadOption)184{185LinkProgramParams params(taskOption, threadOption);186params.eglParameters = OPENGL_OR_GLES();187return params;188}189190LinkProgramParams LinkProgramVulkanParams(TaskOption taskOption, ThreadOption threadOption)191{192LinkProgramParams params(taskOption, threadOption);193params.eglParameters = VULKAN();194return params;195}196197TEST_P(LinkProgramBenchmark, Run)198{199run();200}201202ANGLE_INSTANTIATE_TEST(203LinkProgramBenchmark,204LinkProgramD3D11Params(TaskOption::CompileOnly, ThreadOption::MultiThread),205LinkProgramOpenGLOrGLESParams(TaskOption::CompileOnly, ThreadOption::MultiThread),206LinkProgramVulkanParams(TaskOption::CompileOnly, ThreadOption::MultiThread),207LinkProgramD3D11Params(TaskOption::CompileAndLink, ThreadOption::MultiThread),208LinkProgramOpenGLOrGLESParams(TaskOption::CompileAndLink, ThreadOption::MultiThread),209LinkProgramVulkanParams(TaskOption::CompileAndLink, ThreadOption::MultiThread),210LinkProgramD3D11Params(TaskOption::CompileOnly, ThreadOption::SingleThread),211LinkProgramOpenGLOrGLESParams(TaskOption::CompileOnly, ThreadOption::SingleThread),212LinkProgramVulkanParams(TaskOption::CompileOnly, ThreadOption::SingleThread),213LinkProgramD3D11Params(TaskOption::CompileAndLink, ThreadOption::SingleThread),214LinkProgramOpenGLOrGLESParams(TaskOption::CompileAndLink, ThreadOption::SingleThread),215LinkProgramVulkanParams(TaskOption::CompileAndLink, ThreadOption::SingleThread));216217} // anonymous namespace218219220