Path: blob/main_old/src/tests/capture_replay_tests/CaptureReplayTests.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// CaptureReplayTest.cpp:6// Application that runs replay for testing of capture replay7//89#include "common/debug.h"10#include "common/system_utils.h"11#include "util/EGLPlatformParameters.h"12#include "util/EGLWindow.h"13#include "util/OSWindow.h"1415#include <stdint.h>16#include <string.h>17#include <fstream>18#include <functional>19#include <iostream>20#include <list>21#include <memory>22#include <ostream>23#include <string>24#include <utility>2526#include "util/frame_capture_test_utils.h"2728// Build the right context header based on replay ID29// This will expand to "angle_capture_context<#>.h"30#include ANGLE_MACRO_STRINGIZE(ANGLE_CAPTURE_REPLAY_COMPOSITE_TESTS_HEADER)3132constexpr char kResultTag[] = "*RESULT";3334class CaptureReplayTests35{36public:37CaptureReplayTests()38{39// Load EGL library so we can initialize the display.40mEntryPointsLib.reset(41angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME, angle::SearchType::ModuleDir));4243mOSWindow = OSWindow::New();44mOSWindow->disableErrorMessageDialog();45}4647~CaptureReplayTests()48{49EGLWindow::Delete(&mEGLWindow);50OSWindow::Delete(&mOSWindow);51}5253bool initializeTest(uint32_t testIndex, const TestTraceInfo &testTraceInfo)54{55if (!mOSWindow->initialize(testTraceInfo.testName, testTraceInfo.replayDrawSurfaceWidth,56testTraceInfo.replayDrawSurfaceHeight))57{58return false;59}6061mOSWindow->disableErrorMessageDialog();62mOSWindow->setVisible(true);6364if (mEGLWindow && !mEGLWindow->isContextVersion(testTraceInfo.replayContextMajorVersion,65testTraceInfo.replayContextMinorVersion))66{67EGLWindow::Delete(&mEGLWindow);68mEGLWindow = nullptr;69}7071if (!mEGLWindow)72{73mEGLWindow = EGLWindow::New(testTraceInfo.replayContextMajorVersion,74testTraceInfo.replayContextMinorVersion);75}7677ConfigParameters configParams;78configParams.redBits = testTraceInfo.defaultFramebufferRedBits;79configParams.greenBits = testTraceInfo.defaultFramebufferGreenBits;80configParams.blueBits = testTraceInfo.defaultFramebufferBlueBits;81configParams.alphaBits = testTraceInfo.defaultFramebufferAlphaBits;82configParams.depthBits = testTraceInfo.defaultFramebufferDepthBits;83configParams.stencilBits = testTraceInfo.defaultFramebufferStencilBits;8485configParams.clientArraysEnabled = testTraceInfo.areClientArraysEnabled;86configParams.bindGeneratesResource = testTraceInfo.bindGeneratesResources;87configParams.webGLCompatibility = testTraceInfo.webGLCompatibility;88configParams.robustResourceInit = testTraceInfo.robustResourceInit;8990mPlatformParams.renderer = testTraceInfo.replayPlatformType;91mPlatformParams.deviceType = testTraceInfo.replayDeviceType;92mPlatformParams.forceInitShaderVariables = EGL_TRUE;9394if (!mEGLWindow->initializeGL(mOSWindow, mEntryPointsLib.get(),95angle::GLESDriverType::AngleEGL, mPlatformParams,96configParams))97{98mOSWindow->destroy();99return false;100}101// Disable vsync102if (!mEGLWindow->setSwapInterval(0))103{104cleanupTest();105return false;106}107108mStartingDirectory = angle::GetCWD().value();109110// Load trace111mTraceLibrary.reset(new angle::TraceLibrary(testTraceInfo.testName.c_str()));112113// Set CWD to executable directory.114std::string exeDir = angle::GetExecutableDirectory();115if (!angle::SetCWD(exeDir.c_str()))116{117cleanupTest();118return false;119}120if (testTraceInfo.isBinaryDataCompressed)121{122mTraceLibrary->setBinaryDataDecompressCallback(angle::DecompressBinaryData);123}124mTraceLibrary->setBinaryDataDir(ANGLE_CAPTURE_REPLAY_TEST_DATA_DIR);125126mTraceLibrary->setupReplay();127return true;128}129130void cleanupTest()131{132angle::SetCWD(mStartingDirectory.c_str());133mTraceLibrary.reset(nullptr);134mEGLWindow->destroyGL();135mOSWindow->destroy();136}137138void swap() { mEGLWindow->swap(); }139140int runTest(uint32_t testIndex, const TestTraceInfo &testTraceInfo)141{142if (!initializeTest(testIndex, testTraceInfo))143{144return -1;145}146147for (uint32_t frame = testTraceInfo.replayFrameStart; frame <= testTraceInfo.replayFrameEnd;148frame++)149{150mTraceLibrary->replayFrame(frame);151152const char *capturedSerializedState =153reinterpret_cast<const char *>(glGetString(GL_SERIALIZED_CONTEXT_STRING_ANGLE));154const char *replayedSerializedState = mTraceLibrary->getSerializedContextState(frame);155156bool isEqual =157(capturedSerializedState && replayedSerializedState)158? compareSerializedContexts(replayedSerializedState, capturedSerializedState)159: (capturedSerializedState == replayedSerializedState);160161// Swap always to allow RenderDoc/other tools to capture frames.162swap();163if (!isEqual)164{165std::ostringstream replayName;166replayName << testTraceInfo.testName << "_ContextReplayed" << frame << ".json";167std::ofstream debugReplay(replayName.str());168debugReplay << (replayedSerializedState ? replayedSerializedState : "") << "\n";169170std::ostringstream captureName;171captureName << testTraceInfo.testName << "_ContextCaptured" << frame << ".json";172std::ofstream debugCapture(captureName.str());173174debugCapture << (capturedSerializedState ? capturedSerializedState : "") << "\n";175176cleanupTest();177return -1;178}179}180cleanupTest();181return 0;182}183184int run()185{186for (size_t i = 0; i < testTraceInfos.size(); i++)187{188int result = runTest(static_cast<uint32_t>(i), testTraceInfos[i]);189std::cout << kResultTag << " " << testTraceInfos[i].testName << " " << result << "\n";190}191return 0;192}193194private:195bool compareSerializedContexts(const char *capturedSerializedContextState,196const char *replaySerializedContextState)197{198199return !strcmp(replaySerializedContextState, capturedSerializedContextState);200}201202std::string mStartingDirectory;203OSWindow *mOSWindow = nullptr;204EGLWindow *mEGLWindow = nullptr;205EGLPlatformParameters mPlatformParams;206// Handle to the entry point binding library.207std::unique_ptr<angle::Library> mEntryPointsLib;208std::unique_ptr<angle::TraceLibrary> mTraceLibrary;209};210211int main(int argc, char **argv)212{213CaptureReplayTests app;214return app.run();215}216217218