Hash :
dce37b7d
Author :
Date :
2020-06-21T22:27:06
Serialize framebuffers + compare contexts for CaptureReplayTests Adds to frame capture the ability to serialize a frame's pre-swap GL state and store it in the binary data file Adds to CaptureReplayTests the ability to compare its serialized GL state with the serialized state pulled from the binary data file Adds a serialization module that serializes framebuffers' GL states and the contents of their color attachments Adds checks to automation script so that it would skips tests that do not produce the expected trace files Adds exception handling to automation script so that it will not crash when a replay build crashes Bug: angleproject:4779 Change-Id: I40a02e018073749e79f0ddbfd3d4065745548f46 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2258295 Commit-Queue: Manh Nguyen <nguyenmh@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
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
//
// 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 <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_TEST_HEADER)
// Assign the context numbered functions based on GN arg selecting replay ID
std::function<void()> SetupContextReplay = reinterpret_cast<void (*)()>(
ANGLE_MACRO_CONCAT(SetupContext,
ANGLE_MACRO_CONCAT(ANGLE_CAPTURE_REPLAY_TEST_CONTEXT_ID, Replay)));
std::function<void(int)> ReplayContextFrame = reinterpret_cast<void (*)(int)>(
ANGLE_MACRO_CONCAT(ReplayContext,
ANGLE_MACRO_CONCAT(ANGLE_CAPTURE_REPLAY_TEST_CONTEXT_ID, Frame)));
std::function<void()> ResetContextReplay = reinterpret_cast<void (*)()>(
ANGLE_MACRO_CONCAT(ResetContext,
ANGLE_MACRO_CONCAT(ANGLE_CAPTURE_REPLAY_TEST_CONTEXT_ID, Replay)));
std::function<std::vector<uint8_t>()> GetSerializedContextStateData =
reinterpret_cast<std::vector<uint8_t> (*)()>(
ANGLE_MACRO_CONCAT(GetSerializedContextState,
ANGLE_MACRO_CONCAT(ANGLE_CAPTURE_REPLAY_TEST_CONTEXT_ID, Data)));
class CaptureReplayTest
{
public:
CaptureReplayTest(int width, int height, EGLint glesMajorVersion, EGLint glesMinorVersion)
: mWidth(width), mHeight(height), 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();
}
~CaptureReplayTest()
{
EGLWindow::Delete(&mEGLWindow);
OSWindow::Delete(&mOSWindow);
}
bool initialize()
{
// Set CWD to executable directory.
std::string exeDir = angle::GetExecutableDirectory();
if (!angle::SetCWD(exeDir.c_str()))
return false;
if (kIsBinaryDataCompressed)
{
SetBinaryDataDecompressCallback(angle::DecompressBinaryData);
}
SetBinaryDataDir(ANGLE_CAPTURE_REPLAY_TEST_DATA_DIR);
SetupContextReplay();
return true;
}
void draw() { ReplayContextFrame(0); }
void swap() { mEGLWindow->swap(); }
int run()
{
if (!mOSWindow->initialize("Capture Replay Test", mWidth, mHeight))
{
return -1;
}
mOSWindow->setVisible(true);
ConfigParameters configParams;
configParams.redBits = 8;
configParams.greenBits = 8;
configParams.blueBits = 8;
configParams.alphaBits = 8;
configParams.depthBits = 24;
configParams.stencilBits = 8;
if (!mEGLWindow->initializeGL(mOSWindow, mEntryPointsLib.get(),
angle::GLESDriverType::AngleEGL, mPlatformParams,
configParams))
{
return -1;
}
// Disable vsync
if (!mEGLWindow->setSwapInterval(0))
{
return -1;
}
int result = 0;
if (!initialize())
{
result = -1;
}
draw();
gl::Context *context = static_cast<gl::Context *>(mEGLWindow->getContext());
gl::BinaryOutputStream bos;
if (angle::SerializeContext(&bos, context) != angle::Result::Continue)
{
return -1;
}
bool isEqual = compareSerializedStates(bos);
if (!isEqual)
{
result = -1;
}
swap();
mEGLWindow->destroyGL();
mOSWindow->destroy();
return result;
}
private:
bool compareSerializedStates(const gl::BinaryOutputStream &replaySerializedContextData)
{
return GetSerializedContextStateData() == replaySerializedContextData.getData();
}
uint32_t mWidth;
uint32_t mHeight;
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 int width = 128;
const int height = 128;
const EGLint glesMajorVersion = 2;
const GLint glesMinorVersion = 0;
CaptureReplayTest app(width, height, glesMajorVersion, glesMinorVersion);
return app.run();
}