Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/src/tests/capture_replay_tests/CaptureReplayTests.cpp
1693 views
1
//
2
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
3
// Use of this source code is governed by a BSD-style license that can be
4
// found in the LICENSE file.
5
//
6
// CaptureReplayTest.cpp:
7
// Application that runs replay for testing of capture replay
8
//
9
10
#include "common/debug.h"
11
#include "common/system_utils.h"
12
#include "util/EGLPlatformParameters.h"
13
#include "util/EGLWindow.h"
14
#include "util/OSWindow.h"
15
16
#include <stdint.h>
17
#include <string.h>
18
#include <fstream>
19
#include <functional>
20
#include <iostream>
21
#include <list>
22
#include <memory>
23
#include <ostream>
24
#include <string>
25
#include <utility>
26
27
#include "util/frame_capture_test_utils.h"
28
29
// Build the right context header based on replay ID
30
// This will expand to "angle_capture_context<#>.h"
31
#include ANGLE_MACRO_STRINGIZE(ANGLE_CAPTURE_REPLAY_COMPOSITE_TESTS_HEADER)
32
33
constexpr char kResultTag[] = "*RESULT";
34
35
class CaptureReplayTests
36
{
37
public:
38
CaptureReplayTests()
39
{
40
// Load EGL library so we can initialize the display.
41
mEntryPointsLib.reset(
42
angle::OpenSharedLibrary(ANGLE_EGL_LIBRARY_NAME, angle::SearchType::ModuleDir));
43
44
mOSWindow = OSWindow::New();
45
mOSWindow->disableErrorMessageDialog();
46
}
47
48
~CaptureReplayTests()
49
{
50
EGLWindow::Delete(&mEGLWindow);
51
OSWindow::Delete(&mOSWindow);
52
}
53
54
bool initializeTest(uint32_t testIndex, const TestTraceInfo &testTraceInfo)
55
{
56
if (!mOSWindow->initialize(testTraceInfo.testName, testTraceInfo.replayDrawSurfaceWidth,
57
testTraceInfo.replayDrawSurfaceHeight))
58
{
59
return false;
60
}
61
62
mOSWindow->disableErrorMessageDialog();
63
mOSWindow->setVisible(true);
64
65
if (mEGLWindow && !mEGLWindow->isContextVersion(testTraceInfo.replayContextMajorVersion,
66
testTraceInfo.replayContextMinorVersion))
67
{
68
EGLWindow::Delete(&mEGLWindow);
69
mEGLWindow = nullptr;
70
}
71
72
if (!mEGLWindow)
73
{
74
mEGLWindow = EGLWindow::New(testTraceInfo.replayContextMajorVersion,
75
testTraceInfo.replayContextMinorVersion);
76
}
77
78
ConfigParameters configParams;
79
configParams.redBits = testTraceInfo.defaultFramebufferRedBits;
80
configParams.greenBits = testTraceInfo.defaultFramebufferGreenBits;
81
configParams.blueBits = testTraceInfo.defaultFramebufferBlueBits;
82
configParams.alphaBits = testTraceInfo.defaultFramebufferAlphaBits;
83
configParams.depthBits = testTraceInfo.defaultFramebufferDepthBits;
84
configParams.stencilBits = testTraceInfo.defaultFramebufferStencilBits;
85
86
configParams.clientArraysEnabled = testTraceInfo.areClientArraysEnabled;
87
configParams.bindGeneratesResource = testTraceInfo.bindGeneratesResources;
88
configParams.webGLCompatibility = testTraceInfo.webGLCompatibility;
89
configParams.robustResourceInit = testTraceInfo.robustResourceInit;
90
91
mPlatformParams.renderer = testTraceInfo.replayPlatformType;
92
mPlatformParams.deviceType = testTraceInfo.replayDeviceType;
93
mPlatformParams.forceInitShaderVariables = EGL_TRUE;
94
95
if (!mEGLWindow->initializeGL(mOSWindow, mEntryPointsLib.get(),
96
angle::GLESDriverType::AngleEGL, mPlatformParams,
97
configParams))
98
{
99
mOSWindow->destroy();
100
return false;
101
}
102
// Disable vsync
103
if (!mEGLWindow->setSwapInterval(0))
104
{
105
cleanupTest();
106
return false;
107
}
108
109
mStartingDirectory = angle::GetCWD().value();
110
111
// Load trace
112
mTraceLibrary.reset(new angle::TraceLibrary(testTraceInfo.testName.c_str()));
113
114
// Set CWD to executable directory.
115
std::string exeDir = angle::GetExecutableDirectory();
116
if (!angle::SetCWD(exeDir.c_str()))
117
{
118
cleanupTest();
119
return false;
120
}
121
if (testTraceInfo.isBinaryDataCompressed)
122
{
123
mTraceLibrary->setBinaryDataDecompressCallback(angle::DecompressBinaryData);
124
}
125
mTraceLibrary->setBinaryDataDir(ANGLE_CAPTURE_REPLAY_TEST_DATA_DIR);
126
127
mTraceLibrary->setupReplay();
128
return true;
129
}
130
131
void cleanupTest()
132
{
133
angle::SetCWD(mStartingDirectory.c_str());
134
mTraceLibrary.reset(nullptr);
135
mEGLWindow->destroyGL();
136
mOSWindow->destroy();
137
}
138
139
void swap() { mEGLWindow->swap(); }
140
141
int runTest(uint32_t testIndex, const TestTraceInfo &testTraceInfo)
142
{
143
if (!initializeTest(testIndex, testTraceInfo))
144
{
145
return -1;
146
}
147
148
for (uint32_t frame = testTraceInfo.replayFrameStart; frame <= testTraceInfo.replayFrameEnd;
149
frame++)
150
{
151
mTraceLibrary->replayFrame(frame);
152
153
const char *capturedSerializedState =
154
reinterpret_cast<const char *>(glGetString(GL_SERIALIZED_CONTEXT_STRING_ANGLE));
155
const char *replayedSerializedState = mTraceLibrary->getSerializedContextState(frame);
156
157
bool isEqual =
158
(capturedSerializedState && replayedSerializedState)
159
? compareSerializedContexts(replayedSerializedState, capturedSerializedState)
160
: (capturedSerializedState == replayedSerializedState);
161
162
// Swap always to allow RenderDoc/other tools to capture frames.
163
swap();
164
if (!isEqual)
165
{
166
std::ostringstream replayName;
167
replayName << testTraceInfo.testName << "_ContextReplayed" << frame << ".json";
168
std::ofstream debugReplay(replayName.str());
169
debugReplay << (replayedSerializedState ? replayedSerializedState : "") << "\n";
170
171
std::ostringstream captureName;
172
captureName << testTraceInfo.testName << "_ContextCaptured" << frame << ".json";
173
std::ofstream debugCapture(captureName.str());
174
175
debugCapture << (capturedSerializedState ? capturedSerializedState : "") << "\n";
176
177
cleanupTest();
178
return -1;
179
}
180
}
181
cleanupTest();
182
return 0;
183
}
184
185
int run()
186
{
187
for (size_t i = 0; i < testTraceInfos.size(); i++)
188
{
189
int result = runTest(static_cast<uint32_t>(i), testTraceInfos[i]);
190
std::cout << kResultTag << " " << testTraceInfos[i].testName << " " << result << "\n";
191
}
192
return 0;
193
}
194
195
private:
196
bool compareSerializedContexts(const char *capturedSerializedContextState,
197
const char *replaySerializedContextState)
198
{
199
200
return !strcmp(replaySerializedContextState, capturedSerializedContextState);
201
}
202
203
std::string mStartingDirectory;
204
OSWindow *mOSWindow = nullptr;
205
EGLWindow *mEGLWindow = nullptr;
206
EGLPlatformParameters mPlatformParams;
207
// Handle to the entry point binding library.
208
std::unique_ptr<angle::Library> mEntryPointsLib;
209
std::unique_ptr<angle::TraceLibrary> mTraceLibrary;
210
};
211
212
int main(int argc, char **argv)
213
{
214
CaptureReplayTests app;
215
return app.run();
216
}
217
218