Files
godot-angle-static/samples/capture_replay/CaptureReplay.cpp
Roman Lavrov 5215293366 Add trace_interface: functions and callbacks for traces
Defines the interface between the test suite
(or an other TraceLibrary class user) and trace libraries.

TraceFunctions defines entry points for calls suite->trace, such as
SetupReplay() or SetBinaryDataDir().

TraceCallbacks defines entry points for calls trace->suite, for example
for loading .angledata.gz files.

These are set up via the exported SetupEntryPoints() call. Functions
like SetupReplay etc no longer need to be exported from the trace
library.

TraceInfo (parsed representation of the trace json) is moved to
trace_interface as is. This is convenient for further changes to the
fixture that will allow to easily move some of the captured parameters
to json.

This also moves Decompress functionality (and memory ownership) to test
suite entirely, which avoids Decompress/Delete callbacks - the trace
just calls LoadBinaryData via TraceCallbacks and TraceLibrary releases
the memory either on FinishReplay or in its destructor.
This should also take care of the memory leak described in
https://crrev.com/c/3858185

Bug: b/286072760
Change-Id: Ibc6f6f64156ad805b1917c8fc41a3b0d2c0d6375
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4594445
Reviewed-by: Amirali Abdolrashidi <abdolrashidi@google.com>
Commit-Queue: Roman Lavrov <romanl@google.com>
Reviewed-by: Cody Northrop <cnorthrop@google.com>
2023-06-08 20:06:15 +00:00

84 lines
2.7 KiB
C++

//
// Copyright 2019 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.
//
// CaptureReplay: Template for replaying a frame capture with ANGLE.
#include "SampleApplication.h"
#include <functional>
#include "util/capture/frame_capture_test_utils.h"
class CaptureReplaySample : public SampleApplication
{
public:
CaptureReplaySample(int argc, char **argv, const angle::TraceInfo &traceInfo)
: SampleApplication("CaptureReplaySample",
argc,
argv,
ClientType::ES3_0,
traceInfo.drawSurfaceWidth,
traceInfo.drawSurfaceHeight),
mTraceInfo(traceInfo)
{}
bool initialize() override
{
mTraceLibrary.reset(new angle::TraceLibrary("capture_replay_sample_trace"));
assert(mTraceLibrary->valid());
std::stringstream binaryPathStream;
binaryPathStream << angle::GetExecutableDirectory() << angle::GetPathSeparator()
<< ANGLE_CAPTURE_REPLAY_SAMPLE_DATA_DIR;
mTraceLibrary->setBinaryDataDir(binaryPathStream.str().c_str());
mTraceLibrary->setupReplay();
return true;
}
void destroy() override { mTraceLibrary->finishReplay(); }
void draw() override
{
// Compute the current frame, looping from frameStart to frameEnd.
uint32_t frame = mTraceInfo.frameStart +
(mCurrentFrame % ((mTraceInfo.frameEnd - mTraceInfo.frameStart) + 1));
if (mPreviousFrame > frame)
{
mTraceLibrary->resetReplay();
}
mTraceLibrary->replayFrame(frame);
mPreviousFrame = frame;
mCurrentFrame++;
}
private:
uint32_t mCurrentFrame = 0;
uint32_t mPreviousFrame = 0;
const angle::TraceInfo mTraceInfo;
std::unique_ptr<angle::TraceLibrary> mTraceLibrary;
};
int main(int argc, char **argv)
{
std::string exeDir = angle::GetExecutableDirectory();
std::stringstream traceJsonPathStream;
traceJsonPathStream << exeDir << angle::GetPathSeparator()
<< ANGLE_CAPTURE_REPLAY_SAMPLE_DATA_DIR << angle::GetPathSeparator()
<< "angle_capture.json";
std::string traceJsonPath = traceJsonPathStream.str();
angle::TraceInfo traceInfo = {};
if (!angle::LoadTraceInfoFromJSON("capture_replay_sample_trace", traceJsonPath, &traceInfo))
{
std::cout << "Unable to load trace data: " << traceJsonPath << "\n";
return 1;
}
CaptureReplaySample app(argc, argv, traceInfo);
return app.run();
}