Hash :
39b777c6
Author :
Date :
2020-10-29T16:55:06
Capture/Replay: Two cleanups. This changes from returning a vector to directly returning a pointer to the binary data for the serialized state. The second cleanup is to use a ContextID as a wrapped type which simplifies the output formatting code. Bug: angleproject:5247 Change-Id: Ieb8afdb9326a12968dd2d69c05e1ed811b93abff Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2506198 Reviewed-by: Courtney Goeltzenleuchter <courtneygo@google.com> Reviewed-by: Cody Northrop <cnorthrop@google.com> Commit-Queue: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
//
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// CaptureReplayTest.cpp:
// Application that runs replay for testing of capture replay
//
#include "common/system_utils.h"
#include "libANGLE/Context.h"
#include "libANGLE/frame_capture_utils.h"
#include "util/EGLPlatformParameters.h"
#include "util/EGLWindow.h"
#include "util/OSWindow.h"
#include <stdint.h>
#include <string.h>
#include <functional>
#include <iostream>
#include <list>
#include <memory>
#include <string>
#include <utility>
#include "util/frame_capture_test_utils.h"
// Build the right context header based on replay ID
// This will expand to "angle_capture_context<#>.h"
#include ANGLE_MACRO_STRINGIZE(ANGLE_CAPTURE_REPLAY_COMPOSITE_TESTS_HEADER)
constexpr char kResultTag[] = "*RESULT";
class CaptureReplayTests
{
public:
CaptureReplayTests(EGLint glesMajorVersion, EGLint glesMinorVersion)
: mOSWindow(nullptr), mEGLWindow(nullptr)
{
mPlatformParams.renderer = EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE;
mPlatformParams.deviceType = EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE;
// Load EGL library so we can initialize the display.
mEntryPointsLib.reset(
angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME, angle::SearchType::ApplicationDir));
mEGLWindow = EGLWindow::New(glesMajorVersion, glesMinorVersion);
mOSWindow = OSWindow::New();
mOSWindow->disableErrorMessageDialog();
}
~CaptureReplayTests()
{
EGLWindow::Delete(&mEGLWindow);
OSWindow::Delete(&mOSWindow);
}
bool initializeTest(uint32_t testIndex, TestTraceInfo &testTraceInfo)
{
if (!mOSWindow->initialize(testTraceInfo.testName, testTraceInfo.replayDrawSurfaceWidth,
testTraceInfo.replayDrawSurfaceHeight))
{
return false;
}
mOSWindow->disableErrorMessageDialog();
mOSWindow->setVisible(true);
ConfigParameters configParams;
configParams.redBits = testTraceInfo.defaultFramebufferRedBits;
configParams.greenBits = testTraceInfo.defaultFramebufferGreenBits;
configParams.blueBits = testTraceInfo.defaultFramebufferBlueBits;
configParams.alphaBits = testTraceInfo.defaultFramebufferAlphaBits;
configParams.depthBits = testTraceInfo.defaultFramebufferDepthBits;
configParams.stencilBits = testTraceInfo.defaultFramebufferStencilBits;
if (!mEGLWindow->initializeGL(mOSWindow, mEntryPointsLib.get(),
angle::GLESDriverType::AngleEGL, mPlatformParams,
configParams))
{
mOSWindow->destroy();
return false;
}
// Disable vsync
if (!mEGLWindow->setSwapInterval(0))
{
cleanupTest();
return false;
}
// Set CWD to executable directory.
std::string exeDir = angle::GetExecutableDirectory();
if (!angle::SetCWD(exeDir.c_str()))
{
cleanupTest();
return false;
}
if (testTraceInfo.isBinaryDataCompressed)
{
SetBinaryDataDecompressCallback(testIndex, angle::DecompressBinaryData);
}
SetBinaryDataDir(testIndex, ANGLE_CAPTURE_REPLAY_TEST_DATA_DIR);
SetupContextReplay(testIndex);
return true;
}
void cleanupTest()
{
mEGLWindow->destroyGL();
mOSWindow->destroy();
}
void swap() { mEGLWindow->swap(); }
int runTest(uint32_t testIndex, TestTraceInfo &testTraceInfo)
{
if (!initializeTest(testIndex, testTraceInfo))
{
return -1;
}
for (uint32_t frame = testTraceInfo.replayFrameStart; frame <= testTraceInfo.replayFrameEnd;
frame++)
{
ReplayContextFrame(testIndex, frame);
gl::Context *context = static_cast<gl::Context *>(mEGLWindow->getContext());
gl::BinaryOutputStream bos;
if (angle::SerializeContext(&bos, context) != angle::Result::Continue)
{
cleanupTest();
return -1;
}
bool isEqual = compareSerializedContexts(testIndex, frame, bos.getData());
if (!isEqual)
{
cleanupTest();
return -1;
}
swap();
}
cleanupTest();
return 0;
}
int run()
{
for (size_t i = 0; i < testTraceInfos.size(); i++)
{
int result = runTest(static_cast<uint32_t>(i), testTraceInfos[i]);
std::cout << kResultTag << " " << testTraceInfos[i].testName << " " << result << "\n";
}
return 0;
}
private:
bool compareSerializedContexts(uint32_t testIndex,
uint32_t frame,
const std::vector<uint8_t> &replaySerializedContextState)
{
return memcmp(replaySerializedContextState.data(),
GetSerializedContextState(testIndex, frame),
replaySerializedContextState.size()) == 0;
}
OSWindow *mOSWindow;
EGLWindow *mEGLWindow;
EGLPlatformParameters mPlatformParams;
// Handle to the entry point binding library.
std::unique_ptr<angle::Library> mEntryPointsLib;
};
int main(int argc, char **argv)
{
// TODO (nguyenmh): http://anglebug.com/4759: initialize app with arguments taken from cmdline
const EGLint glesMajorVersion = 2;
const GLint glesMinorVersion = 0;
CaptureReplayTests app(glesMajorVersion, glesMinorVersion);
return app.run();
}