Path: blob/main_old/src/tests/perf_tests/BlitFramebufferPerf.cpp
1693 views
//1// Copyright 2017 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// BlitFramebufferPerf:6// Performance tests for glBlitFramebuffer in ES3. Includes tests for7// color, depth, and stencil blit, as well as the mutlisample versions.8// The test works by clearing a framebuffer, then blitting it to a second.910#include "ANGLEPerfTest.h"1112#include "util/gles_loader_autogen.h"1314namespace15{16constexpr unsigned int kIterationsPerStep = 5;1718enum class BufferType19{20COLOR,21DEPTH,22STENCIL,23DEPTH_STENCIL24};2526const char *BufferTypeString(BufferType type)27{28switch (type)29{30case BufferType::COLOR:31return "color";32case BufferType::DEPTH:33return "depth";34case BufferType::STENCIL:35return "stencil";36case BufferType::DEPTH_STENCIL:37return "depth_stencil";38default:39return "error";40}41}4243GLbitfield BufferTypeMask(BufferType type)44{45switch (type)46{47case BufferType::COLOR:48return GL_COLOR_BUFFER_BIT;49case BufferType::DEPTH:50return GL_DEPTH_BUFFER_BIT;51case BufferType::STENCIL:52return GL_STENCIL_BUFFER_BIT;53case BufferType::DEPTH_STENCIL:54return (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);55default:56return 0;57}58}5960GLenum BufferTypeFormat(BufferType type)61{62switch (type)63{64case BufferType::COLOR:65return GL_RGBA8;66case BufferType::DEPTH:67return GL_DEPTH_COMPONENT24;68case BufferType::STENCIL:69return GL_STENCIL_INDEX8;70case BufferType::DEPTH_STENCIL:71return GL_DEPTH24_STENCIL8;72default:73return GL_NONE;74}75}7677GLenum BufferTypeAttachment(BufferType type)78{79switch (type)80{81case BufferType::COLOR:82return GL_COLOR_ATTACHMENT0;83case BufferType::DEPTH:84return GL_DEPTH_ATTACHMENT;85case BufferType::STENCIL:86return GL_STENCIL_ATTACHMENT;87case BufferType::DEPTH_STENCIL:88return GL_DEPTH_STENCIL_ATTACHMENT;89default:90return GL_NONE;91}92}9394struct BlitFramebufferParams final : public RenderTestParams95{96BlitFramebufferParams()97{98iterationsPerStep = kIterationsPerStep;99majorVersion = 3;100minorVersion = 0;101windowWidth = 256;102windowHeight = 256;103}104105std::string story() const override106{107std::stringstream storyStr;108storyStr << RenderTestParams::story();109storyStr << "_" << BufferTypeString(type);110if (samples > 1)111{112storyStr << "_" << samples << "_samples";113}114return storyStr.str();115}116117BufferType type = BufferType::COLOR;118unsigned int framebufferSize = 512;119unsigned int samples = 0;120};121122std::ostream &operator<<(std::ostream &os, const BlitFramebufferParams ¶ms)123{124os << params.backendAndStory().substr(1);125return os;126}127128class BlitFramebufferPerf : public ANGLERenderTest,129public ::testing::WithParamInterface<BlitFramebufferParams>130{131public:132BlitFramebufferPerf() : ANGLERenderTest("BlitFramebufferPerf", GetParam()) {}133134void initializeBenchmark() override;135void destroyBenchmark() override;136void drawBenchmark() override;137138private:139GLuint mReadFramebuffer = 0;140GLuint mReadRenderbuffer = 0;141GLuint mDrawFramebuffer = 0;142GLuint mDrawRenderbuffer = 0;143};144145void BlitFramebufferPerf::initializeBenchmark()146{147const auto ¶m = GetParam();148149glGenFramebuffers(1, &mReadFramebuffer);150glGenFramebuffers(1, &mDrawFramebuffer);151152glBindFramebuffer(GL_READ_FRAMEBUFFER, mReadFramebuffer);153glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDrawFramebuffer);154155// Create source and destination Renderbuffers.156glGenRenderbuffers(1, &mReadRenderbuffer);157glGenRenderbuffers(1, &mDrawRenderbuffer);158159ASSERT_GL_NO_ERROR();160161GLenum format = BufferTypeFormat(param.type);162GLuint size = param.framebufferSize;163GLenum attachment = BufferTypeAttachment(param.type);164165glBindRenderbuffer(GL_RENDERBUFFER, mReadRenderbuffer);166glRenderbufferStorageMultisample(GL_RENDERBUFFER, param.samples, format, size, size);167glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, attachment, GL_RENDERBUFFER, mReadRenderbuffer);168ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_READ_FRAMEBUFFER));169170glBindRenderbuffer(GL_RENDERBUFFER, mDrawRenderbuffer);171glRenderbufferStorageMultisample(GL_RENDERBUFFER, 0, format, size, size);172glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, attachment, GL_RENDERBUFFER, mDrawRenderbuffer);173ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER));174175ASSERT_GL_NO_ERROR();176}177178void BlitFramebufferPerf::destroyBenchmark()179{180glDeleteFramebuffers(1, &mReadFramebuffer);181glDeleteRenderbuffers(1, &mReadRenderbuffer);182glDeleteFramebuffers(1, &mDrawFramebuffer);183glDeleteRenderbuffers(1, &mDrawRenderbuffer);184}185186void BlitFramebufferPerf::drawBenchmark()187{188const auto ¶m = GetParam();189auto size = param.framebufferSize;190auto mask = BufferTypeMask(param.type);191192// We don't read from the draw buffer (ie rendering) to simplify the test, but we could.193// This might trigger a flush, or we could trigger a flush manually to ensure the blit happens.194// TODO(jmadill): Investigate performance on Vulkan, and placement of Clear call.195196switch (param.type)197{198case BufferType::COLOR:199{200GLfloat clearValues[4] = {1.0f, 0.0f, 0.0f, 1.0f};201glClearBufferfv(GL_COLOR, 0, clearValues);202break;203}204case BufferType::DEPTH:205{206GLfloat clearDepthValue = 0.5f;207glClearBufferfv(GL_DEPTH, 0, &clearDepthValue);208break;209}210case BufferType::STENCIL:211{212GLint clearStencilValue = 1;213glClearBufferiv(GL_STENCIL, 0, &clearStencilValue);214break;215}216case BufferType::DEPTH_STENCIL:217glClearBufferfi(GL_DEPTH_STENCIL, 0, 0.5f, 1);218break;219}220221for (unsigned int iteration = 0; iteration < param.iterationsPerStep; ++iteration)222{223glBlitFramebuffer(0, 0, size, size, 0, 0, size, size, mask, GL_NEAREST);224}225}226227TEST_P(BlitFramebufferPerf, Run)228{229run();230}231232BlitFramebufferParams D3D11(BufferType type, unsigned int samples)233{234BlitFramebufferParams params;235params.eglParameters = angle::egl_platform::D3D11();236params.type = type;237params.samples = samples;238return params;239}240} // anonymous namespace241242// TODO(jmadill): Programatically generate these combinations.243ANGLE_INSTANTIATE_TEST(BlitFramebufferPerf,244D3D11(BufferType::COLOR, 0),245D3D11(BufferType::DEPTH, 0),246D3D11(BufferType::STENCIL, 0),247D3D11(BufferType::DEPTH_STENCIL, 0),248D3D11(BufferType::COLOR, 2),249D3D11(BufferType::DEPTH, 2),250D3D11(BufferType::STENCIL, 2),251D3D11(BufferType::DEPTH_STENCIL, 2));252253// This test suite is not instantiated on some OSes.254GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(BlitFramebufferPerf);255256257