Path: blob/main_old/src/tests/perf_tests/MultisampledRenderToTexturePerf.cpp
1693 views
//1// Copyright 2020 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// MultisampledRenderToTextureBenchmark:6// Performance test for rendering to multisampled-render-to-texture attachments.7//89#include "ANGLEPerfTest.h"1011#include <iostream>12#include <random>13#include <sstream>1415#include "test_utils/gl_raii.h"16#include "util/shader_utils.h"1718using namespace angle;1920namespace21{22constexpr uint32_t kMultipassPassCount = 5;2324struct MultisampledRenderToTextureParams final : public RenderTestParams25{26MultisampledRenderToTextureParams()27{28iterationsPerStep = 1;29trackGpuTime = true;3031textureWidth = 1920;32textureHeight = 1080;3334multiplePasses = false;35withDepthStencil = false;36}3738std::string story() const override;3940GLsizei textureWidth;41GLsizei textureHeight;4243bool multiplePasses;44bool withDepthStencil;45};4647std::ostream &operator<<(std::ostream &os, const MultisampledRenderToTextureParams ¶ms)48{49return os << params.backendAndStory().substr(1);50}5152std::string MultisampledRenderToTextureParams::story() const53{54std::stringstream strstr;5556strstr << RenderTestParams::story();5758if (multiplePasses)59{60strstr << "_multipass";61}6263if (withDepthStencil)64{65strstr << "_ds";66}6768return strstr.str();69}7071class MultisampledRenderToTextureBenchmark72: public ANGLERenderTest,73public ::testing::WithParamInterface<MultisampledRenderToTextureParams>74{75public:76MultisampledRenderToTextureBenchmark();7778void initializeBenchmark() override;79void destroyBenchmark() override;80void drawBenchmark() override;8182protected:83void initShaders();8485GLuint mFramebuffer = 0;86GLuint mProgram = 0;87GLuint mColorTexture = 0;88GLuint mDepthStencilRenderbuffer = 0;8990std::vector<uint8_t> mTextureData;91};9293MultisampledRenderToTextureBenchmark::MultisampledRenderToTextureBenchmark()94: ANGLERenderTest("MultisampledRenderToTexture", GetParam())95{96// Crashes on nvidia+d3d11. http://crbug.com/94541597if (GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)98{99mSkipTest = true;100}101102// Fails on Windows7 NVIDIA Vulkan, presumably due to old drivers. http://crbug.com/1096510103if (IsWindows7() && IsNVIDIA() &&104GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE)105{106mSkipTest = true;107}108109// Fails on Pixel 4 GLES: http://anglebug.com/5120110if (IsPixel4() && GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)111{112mSkipTest = true;113}114115// http://anglebug.com/5380116if (IsLinux() && IsAMD() &&117GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE &&118GetParam().multiplePasses && GetParam().withDepthStencil)119{120mSkipTest = true;121}122123// http://anglebug.com/6319124if (IsLinux() && IsIntel() &&125GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)126{127mSkipTest = true;128}129}130131void MultisampledRenderToTextureBenchmark::initializeBenchmark()132{133if (!IsGLExtensionEnabled("GL_EXT_multisampled_render_to_texture"))134{135mSkipTest = true;136return;137}138139const auto ¶ms = GetParam();140141initShaders();142glClearColor(0.0f, 0.0f, 0.0f, 0.0f);143glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight());144145glGenFramebuffers(1, &mFramebuffer);146glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);147148glGenTextures(1, &mColorTexture);149glBindTexture(GL_TEXTURE_2D, mColorTexture);150151glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, params.textureWidth, params.textureHeight, 0, GL_RGBA,152GL_UNSIGNED_BYTE, nullptr);153glFramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,154mColorTexture, 0, 4);155156if (params.withDepthStencil)157{158glGenRenderbuffers(1, &mDepthStencilRenderbuffer);159glBindRenderbuffer(GL_RENDERBUFFER, mDepthStencilRenderbuffer);160glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8,161params.textureWidth, params.textureHeight);162glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,163mDepthStencilRenderbuffer);164}165166ASSERT_GL_NO_ERROR();167}168169void MultisampledRenderToTextureBenchmark::initShaders()170{171constexpr char kVS[] = R"(void main()172{173gl_Position = vec4(0, 0, 0, 1);174})";175176constexpr char kFS[] = R"(precision mediump float;177void main()178{179gl_FragColor = vec4(0);180})";181182mProgram = CompileProgram(kVS, kFS);183ASSERT_NE(0u, mProgram);184185glUseProgram(mProgram);186187ASSERT_GL_NO_ERROR();188}189190void MultisampledRenderToTextureBenchmark::destroyBenchmark()191{192glDeleteFramebuffers(1, &mFramebuffer);193glDeleteRenderbuffers(1, &mDepthStencilRenderbuffer);194glDeleteTextures(1, &mColorTexture);195glDeleteProgram(mProgram);196}197198void MultisampledRenderToTextureBenchmark::drawBenchmark()199{200const auto ¶ms = GetParam();201202GLTexture mMockTexture;203glBindTexture(GL_TEXTURE_2D, mMockTexture);204205startGpuTimer();206207// Initially clear the color attachment to avoid having to load from the resolved image. The208// depth/stencil attachment doesn't need this as it's contents are always undefined between209// render passes.210glClear(GL_COLOR_BUFFER_BIT);211212const uint32_t passCount = params.multiplePasses ? kMultipassPassCount : 1;213for (uint32_t pass = 0; pass < passCount; ++pass)214{215// Perform a draw just to have something in the render pass. With the position attributes216// not set, a constant default value is used, resulting in a very cheap draw.217glDrawArrays(GL_TRIANGLES, 0, 3);218219// Force the render pass to break by cheaply reading back from the color attachment.220glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 1, 1, 0);221}222stopGpuTimer();223224ASSERT_GL_NO_ERROR();225}226227MultisampledRenderToTextureParams D3D11Params(bool multiplePasses, bool withDepthStencil)228{229MultisampledRenderToTextureParams params;230params.eglParameters = egl_platform::D3D11();231params.majorVersion = 3;232params.minorVersion = 0;233params.multiplePasses = multiplePasses;234params.withDepthStencil = withDepthStencil;235return params;236}237238MultisampledRenderToTextureParams OpenGLOrGLESParams(bool multiplePasses, bool withDepthStencil)239{240MultisampledRenderToTextureParams params;241params.eglParameters = egl_platform::OPENGL_OR_GLES();242params.majorVersion = 3;243params.minorVersion = 0;244params.multiplePasses = multiplePasses;245params.withDepthStencil = withDepthStencil;246return params;247}248249MultisampledRenderToTextureParams VulkanParams(bool multiplePasses, bool withDepthStencil)250{251MultisampledRenderToTextureParams params;252params.eglParameters = egl_platform::VULKAN();253params.majorVersion = 3;254params.minorVersion = 0;255params.multiplePasses = multiplePasses;256params.withDepthStencil = withDepthStencil;257return params;258}259260} // anonymous namespace261262TEST_P(MultisampledRenderToTextureBenchmark, Run)263{264run();265}266267using namespace params;268269ANGLE_INSTANTIATE_TEST(MultisampledRenderToTextureBenchmark,270D3D11Params(false, false),271D3D11Params(true, true),272OpenGLOrGLESParams(false, false),273OpenGLOrGLESParams(true, true),274VulkanParams(false, false),275VulkanParams(true, false),276VulkanParams(false, true),277VulkanParams(true, true));278279280