Hash :
2f3e4db8
Author :
Date :
2021-09-02T10:31:13
Capture/Replay: Serialize trace metadata to a JSON file. This will allow us to remove more code auto-generation for the trace tests. The trace info now can be loaded directly from JSON instead of from the autogenerated information. Bug: angleproject:5133 Change-Id: I04e22b9279b19282df274bc8defcd363d0449111 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3140218 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Cody Northrop <cnorthrop@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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
//
// 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/debug.h"
#include "common/system_utils.h"
#include "util/EGLPlatformParameters.h"
#include "util/EGLWindow.h"
#include "util/OSWindow.h"
#include <stdint.h>
#include <string.h>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <memory>
#include <ostream>
#include <string>
#include <utility>
#include "util/capture/frame_capture_test_utils.h"
constexpr char kResultTag[] = "*RESULT";
constexpr char kTracePath[] = ANGLE_CAPTURE_REPLAY_TEST_NAMES_PATH;
class CaptureReplayTests
{
public:
CaptureReplayTests()
{
// Load EGL library so we can initialize the display.
mEntryPointsLib.reset(
angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME, angle::SearchType::ModuleDir));
mOSWindow = OSWindow::New();
mOSWindow->disableErrorMessageDialog();
}
~CaptureReplayTests()
{
EGLWindow::Delete(&mEGLWindow);
OSWindow::Delete(&mOSWindow);
}
bool initializeTest(const angle::TraceInfo &traceInfo)
{
if (!mOSWindow->initialize(traceInfo.name, traceInfo.drawSurfaceWidth,
traceInfo.drawSurfaceHeight))
{
return false;
}
mOSWindow->disableErrorMessageDialog();
mOSWindow->setVisible(true);
if (mEGLWindow && !mEGLWindow->isContextVersion(traceInfo.contextClientMajorVersion,
traceInfo.contextClientMinorVersion))
{
EGLWindow::Delete(&mEGLWindow);
mEGLWindow = nullptr;
}
if (!mEGLWindow)
{
mEGLWindow = EGLWindow::New(traceInfo.contextClientMajorVersion,
traceInfo.contextClientMinorVersion);
}
ConfigParameters configParams;
configParams.redBits = traceInfo.configRedBits;
configParams.greenBits = traceInfo.configGreenBits;
configParams.blueBits = traceInfo.configBlueBits;
configParams.alphaBits = traceInfo.configAlphaBits;
configParams.depthBits = traceInfo.configDepthBits;
configParams.stencilBits = traceInfo.configStencilBits;
configParams.clientArraysEnabled = traceInfo.areClientArraysEnabled;
configParams.bindGeneratesResource = traceInfo.isBindGeneratesResourcesEnabled;
configParams.webGLCompatibility = traceInfo.isWebGLCompatibilityEnabled;
configParams.robustResourceInit = traceInfo.isRobustResourceInitEnabled;
mPlatformParams.renderer = traceInfo.displayPlatformType;
mPlatformParams.deviceType = traceInfo.displayDeviceType;
mPlatformParams.forceInitShaderVariables = EGL_TRUE;
if (!mEGLWindow->initializeGL(mOSWindow, mEntryPointsLib.get(),
angle::GLESDriverType::AngleEGL, mPlatformParams,
configParams))
{
mOSWindow->destroy();
return false;
}
// Disable vsync
if (!mEGLWindow->setSwapInterval(0))
{
cleanupTest();
return false;
}
// Load trace
mTraceLibrary.reset(new angle::TraceLibrary(traceInfo.name));
if (!mTraceLibrary->valid())
{
std::cout << "Failed to load trace library: " << traceInfo.name << "\n";
return false;
}
if (traceInfo.isBinaryDataCompressed)
{
mTraceLibrary->setBinaryDataDecompressCallback(angle::DecompressBinaryData);
}
mTraceLibrary->setBinaryDataDir(ANGLE_CAPTURE_REPLAY_TEST_DATA_DIR);
mTraceLibrary->setupReplay();
return true;
}
void cleanupTest()
{
mTraceLibrary.reset(nullptr);
mEGLWindow->destroyGL();
mOSWindow->destroy();
}
void swap() { mEGLWindow->swap(); }
int runTest(const angle::TraceInfo &traceInfo)
{
if (!initializeTest(traceInfo))
{
return -1;
}
for (uint32_t frame = traceInfo.frameStart; frame <= traceInfo.frameEnd; frame++)
{
mTraceLibrary->replayFrame(frame);
const char *capturedSerializedState =
reinterpret_cast<const char *>(glGetString(GL_SERIALIZED_CONTEXT_STRING_ANGLE));
const char *replayedSerializedState = mTraceLibrary->getSerializedContextState(frame);
bool isEqual =
(capturedSerializedState && replayedSerializedState)
? compareSerializedContexts(replayedSerializedState, capturedSerializedState)
: (capturedSerializedState == replayedSerializedState);
// Swap always to allow RenderDoc/other tools to capture frames.
swap();
if (!isEqual)
{
std::ostringstream replayName;
replayName << traceInfo.name << "_ContextReplayed" << frame << ".json";
std::ofstream debugReplay(replayName.str());
debugReplay << (replayedSerializedState ? replayedSerializedState : "") << "\n";
std::ostringstream captureName;
captureName << traceInfo.name << "_ContextCaptured" << frame << ".json";
std::ofstream debugCapture(captureName.str());
debugCapture << (capturedSerializedState ? capturedSerializedState : "") << "\n";
cleanupTest();
return -1;
}
}
cleanupTest();
return 0;
}
int run()
{
std::string startingDirectory = angle::GetCWD().value();
// Set CWD to executable directory.
std::string exeDir = angle::GetExecutableDirectory();
if (!angle::SetCWD(exeDir.c_str()))
{
std::cout << "Unable to SetCWD to trace directory: " << exeDir << "\n";
return 1;
}
std::vector<std::string> traces;
if (!angle::LoadTraceNamesFromJSON(kTracePath, &traces))
{
std::cout << "Unable to load trace names from " << kTracePath << "\n";
return 1;
}
for (const std::string &trace : traces)
{
std::stringstream traceJsonPathStream;
traceJsonPathStream << ANGLE_CAPTURE_REPLAY_TEST_DATA_DIR << angle::GetPathSeparator()
<< trace << ".json";
std::string traceJsonPath = traceJsonPathStream.str();
int result = -1;
angle::TraceInfo traceInfo = {};
if (!angle::LoadTraceInfoFromJSON(trace, traceJsonPath, &traceInfo))
{
std::cout << "Unable to load trace data: " << traceJsonPath << "\n";
}
else
{
result = runTest(traceInfo);
}
std::cout << kResultTag << " " << trace << " " << result << "\n";
}
angle::SetCWD(startingDirectory.c_str());
return 0;
}
private:
bool compareSerializedContexts(const char *capturedSerializedContextState,
const char *replaySerializedContextState)
{
return !strcmp(replaySerializedContextState, capturedSerializedContextState);
}
OSWindow *mOSWindow = nullptr;
EGLWindow *mEGLWindow = nullptr;
EGLPlatformParameters mPlatformParams;
// Handle to the entry point binding library.
std::unique_ptr<angle::Library> mEntryPointsLib;
std::unique_ptr<angle::TraceLibrary> mTraceLibrary;
};
int main(int argc, char **argv)
{
CaptureReplayTests app;
return app.run();
}