Trace Interpreter: Move to a shared library.

Based on https://crrev.com/c/4178024 but does only one thing:
makes trace interpreter a shared library (as if it was a compiled trace)

I am not sure what impact this actually has on the TracePerfTest
callbacks (mentioned in the CL above) as I see onEglMakeCurrent callback
getting called without this CL as well. Anyways, this makes things a bit
more consistent.

* Gets rid of TraceReplayInterface
* TraceInterpreter is now an implementation detail
* Need to additionally pass list of trace files to TraceLibrary
(new SetTraceInfo replay export)
* GetResourceIDMapValue is just moved as is to the right lib

Bug: b/276742336
Change-Id: I67ea9fbcb4f7db999ab71c8443ea91c5631df942
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4423869
Commit-Queue: Roman Lavrov <romanl@google.com>
Reviewed-by: Cody Northrop <cnorthrop@google.com>
This commit is contained in:
Roman Lavrov
2023-04-13 11:47:34 -04:00
committed by Angle LUCI CQ
parent 735fb48079
commit 2c7f31af6f
11 changed files with 164 additions and 165 deletions

View File

@@ -18,7 +18,7 @@
"third_party/OpenGL-Registry/src/xml/wgl.xml":
"eae784bf4d1b983a42af5671b140b7c4",
"util/capture/trace_fixture.h":
"7eebdec11ef0719cf3fb46d6218eae7f",
"a53c68629f9a6873d34e6dd223dfb7a3",
"util/capture/trace_interpreter_autogen.cpp":
"d89b2766ca28ffe273a72f5e9d22c46b"
}

View File

@@ -511,6 +511,7 @@ if (build_angle_trace_tests) {
"$angle_root:angle_compression",
"$angle_root/util:angle_frame_capture_test_utils",
"$angle_root/util:angle_png_utils",
"$angle_root/util:angle_trace_interpreter",
"restricted_traces:angle_restricted_traces",
]

View File

@@ -295,7 +295,7 @@ class CaptureReplayTests
#endif
// Load trace
mTraceLibrary.reset(new angle::TraceLibrary(traceInfo.name));
mTraceLibrary.reset(new angle::TraceLibrary(traceInfo.name, traceInfo));
if (!mTraceLibrary->valid())
{
std::cout << "Failed to load trace library: " << traceInfo.name << "\n";

View File

@@ -15,7 +15,6 @@
#include "tests/perf_tests/ANGLEPerfTestArgs.h"
#include "tests/perf_tests/DrawCallPerfParams.h"
#include "util/capture/frame_capture_test_utils.h"
#include "util/capture/trace_interpreter.h"
#include "util/capture/traces_export.h"
#include "util/egl_loader_autogen.h"
#include "util/png_utils.h"
@@ -233,7 +232,7 @@ class TracePerfTest : public ANGLERenderTest
uint32_t mTotalFrameCount = 0;
bool mScreenshotSaved = false;
uint32_t mScreenshotFrame = gScreenshotFrame;
std::unique_ptr<TraceReplayInterface> mTraceReplay;
std::unique_ptr<TraceLibrary> mTraceReplay;
};
TracePerfTest *gCurrentTracePerfTest = nullptr;
@@ -1651,14 +1650,14 @@ void TracePerfTest::initializeBenchmark()
if (gTraceInterpreter)
{
mTraceReplay.reset(new TraceInterpreter(traceInfo, testDataDir, gVerboseLogging));
mTraceReplay.reset(new TraceLibrary("angle_trace_interpreter", traceInfo));
}
else
{
std::stringstream traceNameStr;
traceNameStr << "angle_restricted_traces_" << traceInfo.name;
std::string traceName = traceNameStr.str();
mTraceReplay.reset(new TraceLibrary(traceName.c_str()));
mTraceReplay.reset(new TraceLibrary(traceNameStr.str(), traceInfo));
}
LoadTraceEGL(TraceLoadProc);

View File

@@ -239,23 +239,33 @@ if (angle_has_frame_capture) {
angle_source_set("angle_frame_capture_test_utils") {
testonly = true
sources = [
"capture/frame_capture_replay_autogen.cpp",
"capture/frame_capture_test_utils.cpp",
"capture/frame_capture_test_utils.h",
]
deps = [ "$angle_root/third_party/rapidjson" ]
public_configs += [ ":angle_frame_capture_test_utils_config" ]
public_deps = [
"$angle_root:angle_capture_common",
"$angle_root:angle_common",
"$angle_root:angle_compression",
]
}
angle_shared_library("angle_trace_interpreter") {
testonly = true
sources = [
"capture/frame_capture_replay_autogen.cpp",
"capture/trace_interpreter.cpp",
"capture/trace_interpreter.h",
"capture/trace_interpreter_autogen.cpp",
]
deps = [
":angle_frame_capture_test_utils",
":angle_trace_fixture",
":angle_trace_loader",
"$angle_root:angle_capture_common",
"$angle_root:angle_common",
"$angle_root:angle_compression",
"$angle_root/third_party/rapidjson",
]
public_configs += [ ":angle_frame_capture_test_utils_config" ]
defines = [ "ANGLE_REPLAY_IMPLEMENTATION" ]
}
}

View File

@@ -11,7 +11,6 @@
#include "common/frame_capture_utils.h"
#include "common/string_utils.h"
#include "trace_fixture.h"
#include <rapidjson/document.h>
#include <rapidjson/istreamwrapper.h>
@@ -154,46 +153,21 @@ bool LoadTraceInfoFromJSON(const std::string &traceName,
return true;
}
void ReplayTraceFunction(const TraceFunction &func, const TraceFunctionMap &customFunctions)
TraceLibrary::TraceLibrary(const std::string &traceName, const TraceInfo &traceInfo)
{
for (const CallCapture &call : func)
{
ReplayTraceFunctionCall(call, customFunctions);
}
}
std::stringstream libNameStr;
#if !defined(ANGLE_PLATFORM_WINDOWS)
libNameStr << "lib";
#endif // !defined(ANGLE_PLATFORM_WINDOWS)
libNameStr << traceName;
#if defined(ANGLE_PLATFORM_ANDROID) && defined(COMPONENT_BUILD)
// Added to shared library names in Android component builds in
// https://chromium.googlesource.com/chromium/src/+/9bacc8c4868cc802f69e1e858eea6757217a508f/build/toolchain/toolchain.gni#56
libNameStr << ".cr";
#endif // defined(ANGLE_PLATFORM_ANDROID) && defined(COMPONENT_BUILD)
std::string libName = libNameStr.str();
mTraceLibrary.reset(OpenSharedLibrary(libName.c_str(), SearchType::ModuleDir));
GLuint GetResourceIDMapValue(ResourceIDType resourceIDType, GLuint key)
{
switch (resourceIDType)
{
case ResourceIDType::Buffer:
return gBufferMap[key];
case ResourceIDType::FenceNV:
return gFenceNVMap[key];
case ResourceIDType::Framebuffer:
return gFramebufferMap[key];
case ResourceIDType::ProgramPipeline:
return gProgramPipelineMap[key];
case ResourceIDType::Query:
return gQueryMap[key];
case ResourceIDType::Renderbuffer:
return gRenderbufferMap[key];
case ResourceIDType::Sampler:
return gSamplerMap[key];
case ResourceIDType::Semaphore:
return gSemaphoreMap[key];
case ResourceIDType::ShaderProgram:
return gShaderProgramMap[key];
case ResourceIDType::Texture:
return gTextureMap[key];
case ResourceIDType::TransformFeedback:
return gTransformFeedbackMap[key];
case ResourceIDType::VertexArray:
return gVertexArrayMap[key];
default:
printf("Incompatible resource ID type: %d\n", static_cast<int>(resourceIDType));
UNREACHABLE();
return 0;
}
callFunc<SetTraceInfoFunc>("SetTraceInfo", traceInfo.traceFiles);
}
} // namespace angle

View File

@@ -70,80 +70,46 @@ using ResetReplayFunc = void (*)();
using FinishReplayFunc = void (*)();
using GetSerializedContextStateFunc = const char *(*)(uint32_t);
using SetValidateSerializedStateCallbackFunc = void (*)(ValidateSerializedStateCallback);
using SetTraceInfoFunc = void (*)(const std::vector<std::string> &);
class TraceReplayInterface : angle::NonCopyable
struct TraceInfo;
class TraceLibrary : angle::NonCopyable
{
public:
virtual ~TraceReplayInterface() {}
TraceLibrary(const std::string &traceName, const TraceInfo &traceInfo);
virtual bool valid() const = 0;
virtual void setBinaryDataDir(const char *dataDir) = 0;
virtual void setBinaryDataDecompressCallback(DecompressCallback decompressCallback,
DeleteCallback deleteCallback) = 0;
virtual void replayFrame(uint32_t frameIndex) = 0;
virtual void setupReplay() = 0;
virtual void resetReplay() = 0;
virtual void finishReplay() = 0;
virtual const char *getSerializedContextState(uint32_t frameIndex) = 0;
virtual void setValidateSerializedStateCallback(ValidateSerializedStateCallback callback) = 0;
protected:
TraceReplayInterface() {}
};
class TraceLibrary : public TraceReplayInterface
{
public:
TraceLibrary(const char *traceNameIn)
{
std::stringstream traceNameStr;
#if !defined(ANGLE_PLATFORM_WINDOWS)
traceNameStr << "lib";
#endif // !defined(ANGLE_PLATFORM_WINDOWS)
traceNameStr << traceNameIn;
#if defined(ANGLE_PLATFORM_ANDROID) && defined(COMPONENT_BUILD)
// Added to shared library names in Android component builds in
// https://chromium.googlesource.com/chromium/src/+/9bacc8c4868cc802f69e1e858eea6757217a508f/build/toolchain/toolchain.gni#56
traceNameStr << ".cr";
#endif // defined(ANGLE_PLATFORM_ANDROID) && defined(COMPONENT_BUILD)
std::string traceName = traceNameStr.str();
mTraceLibrary.reset(OpenSharedLibrary(traceName.c_str(), SearchType::ModuleDir));
}
bool valid() const override
bool valid() const
{
return (mTraceLibrary != nullptr) && (mTraceLibrary->getNative() != nullptr);
}
void setBinaryDataDir(const char *dataDir) override
void setBinaryDataDir(const char *dataDir)
{
callFunc<SetBinaryDataDirFunc>("SetBinaryDataDir", dataDir);
}
void setBinaryDataDecompressCallback(DecompressCallback decompressCallback,
DeleteCallback deleteCallback) override
DeleteCallback deleteCallback)
{
callFunc<SetBinaryDataDecompressCallbackFunc>("SetBinaryDataDecompressCallback",
decompressCallback, deleteCallback);
}
void replayFrame(uint32_t frameIndex) override
{
callFunc<ReplayFrameFunc>("ReplayFrame", frameIndex);
}
void replayFrame(uint32_t frameIndex) { callFunc<ReplayFrameFunc>("ReplayFrame", frameIndex); }
void setupReplay() override { callFunc<SetupReplayFunc>("SetupReplay"); }
void setupReplay() { callFunc<SetupReplayFunc>("SetupReplay"); }
void resetReplay() override { callFunc<ResetReplayFunc>("ResetReplay"); }
void resetReplay() { callFunc<ResetReplayFunc>("ResetReplay"); }
void finishReplay() override { callFunc<FinishReplayFunc>("FinishReplay"); }
void finishReplay() { callFunc<FinishReplayFunc>("FinishReplay"); }
const char *getSerializedContextState(uint32_t frameIndex) override
const char *getSerializedContextState(uint32_t frameIndex)
{
return callFunc<GetSerializedContextStateFunc>("GetSerializedContextState", frameIndex);
}
void setValidateSerializedStateCallback(ValidateSerializedStateCallback callback) override
void setValidateSerializedStateCallback(ValidateSerializedStateCallback callback)
{
return callFunc<SetValidateSerializedStateCallbackFunc>(
"SetValidateSerializedStateCallback", callback);
@@ -206,7 +172,6 @@ bool LoadTraceInfoFromJSON(const std::string &traceName,
using TraceFunction = std::vector<CallCapture>;
using TraceFunctionMap = std::map<std::string, TraceFunction>;
void ReplayTraceFunction(const TraceFunction &func, const TraceFunctionMap &customFunctions);
void ReplayTraceFunctionCall(const CallCapture &call, const TraceFunctionMap &customFunctions);
void ReplayCustomFunctionCall(const CallCapture &call, const TraceFunctionMap &customFunctions);

View File

@@ -24,7 +24,6 @@ void UpdateResourceMap(GLuint *resourceMap, GLuint id, GLsizei readBufferOffset)
DecompressCallback gDecompressCallback;
DeleteCallback gDeleteCallback;
std::string gBinaryDataDir = ".";
void DeleteBinaryData()
{
@@ -198,6 +197,8 @@ EGLContext *gContextMap2;
GLsync *gSyncMap2;
EGLSync *gEGLSyncMap;
std::string gBinaryDataDir = ".";
void SetBinaryDataDecompressCallback(DecompressCallback decompressCallback,
DeleteCallback deleteCallback)
{
@@ -404,6 +405,13 @@ void SetValidateSerializedStateCallback(ValidateSerializedStateCallback callback
gValidateSerializedStateCallback = callback;
}
std::vector<std::string> gTraceFiles;
void SetTraceInfo(const std::vector<std::string> &traceFiles)
{
gTraceFiles = traceFiles;
}
void UpdateClientArrayPointer(int arrayIndex, const void *data, uint64_t size)
{
memcpy(gClientArrays[arrayIndex], data, static_cast<size_t>(size));

View File

@@ -42,6 +42,9 @@ extern SurfaceMap gSurfaceMap;
using ContextMap = std::unordered_map<uintptr_t, EGLContext>;
extern ContextMap gContextMap;
extern std::string gBinaryDataDir;
extern std::vector<std::string> gTraceFiles;
using DecompressCallback = uint8_t *(*)(const std::vector<uint8_t> &);
using DeleteCallback = void (*)(uint8_t *);
using ValidateSerializedStateCallback = void (*)(const char *, const char *, uint32_t);
@@ -62,6 +65,7 @@ ANGLE_REPLAY_EXPORT void SetValidateSerializedStateCallback(
// Only defined if serialization is enabled.
ANGLE_REPLAY_EXPORT const char *GetSerializedContextState(uint32_t frameIndex);
ANGLE_REPLAY_EXPORT void SetTraceInfo(const std::vector<std::string> &traceFiles);
#endif // defined(__cplusplus)
// Exported trace functions.

View File

@@ -7,10 +7,9 @@
// Parser and interpreter for the C-based replays.
//
#define ANGLE_REPLAY_EXPORT
#include "trace_interpreter.h"
#include "anglebase/no_destructor.h"
#include "common/gl_enum_utils.h"
#include "common/string_utils.h"
#include "trace_fixture.h"
@@ -30,6 +29,14 @@ bool ShouldSkipFile(const std::string &file)
return false;
}
void ReplayTraceFunction(const TraceFunction &func, const TraceFunctionMap &customFunctions)
{
for (const CallCapture &call : func)
{
ReplayTraceFunctionCall(call, customFunctions);
}
}
class Parser : angle::NonCopyable
{
public:
@@ -502,31 +509,25 @@ void PackConstPointerParameter(ParamBuffer &params, ParamType paramType, const T
reinterpret_cast<const T *>(static_cast<uintptr_t>(offset)));
}
}
} // anonymous namespace
TraceInterpreter::TraceInterpreter(const TraceInfo &traceInfo,
const char *testDataDir,
bool verboseLogging)
: mTraceInfo(traceInfo), mTestDataDir(testDataDir), mVerboseLogging(verboseLogging)
{}
TraceInterpreter::~TraceInterpreter() = default;
bool TraceInterpreter::valid() const
class TraceInterpreter : angle::NonCopyable
{
return true;
}
public:
TraceInterpreter() = default;
~TraceInterpreter() = default;
void TraceInterpreter::setBinaryDataDir(const char *dataDir)
{
SetBinaryDataDir(dataDir);
}
void replayFrame(uint32_t frameIndex);
void setupReplay();
void resetReplay();
const char *getSerializedContextState(uint32_t frameIndex);
void TraceInterpreter::setBinaryDataDecompressCallback(DecompressCallback decompressCallback,
DeleteCallback deleteCallback)
{
SetBinaryDataDecompressCallback(decompressCallback, deleteCallback);
}
private:
void runTraceFunction(const char *name) const;
TraceFunctionMap mTraceFunctions;
TraceStringMap mTraceStrings;
bool mVerboseLogging = true;
};
void TraceInterpreter::replayFrame(uint32_t frameIndex)
{
@@ -537,7 +538,7 @@ void TraceInterpreter::replayFrame(uint32_t frameIndex)
void TraceInterpreter::setupReplay()
{
for (const std::string &file : mTraceInfo.traceFiles)
for (const std::string &file : gTraceFiles)
{
if (ShouldSkipFile(file))
{
@@ -553,7 +554,7 @@ void TraceInterpreter::setupReplay()
printf("Parsing functions from %s\n", file.c_str());
}
std::stringstream pathStream;
pathStream << mTestDataDir << GetPathSeparator() << file;
pathStream << gBinaryDataDir << GetPathSeparator() << file;
std::string path = pathStream.str();
std::string fileData;
@@ -581,11 +582,6 @@ void TraceInterpreter::resetReplay()
runTraceFunction("ResetReplay");
}
void TraceInterpreter::finishReplay()
{
FinishReplay();
}
const char *TraceInterpreter::getSerializedContextState(uint32_t frameIndex)
{
// TODO: Necessary for complete self-testing. http://anglebug.com/7779
@@ -593,11 +589,6 @@ const char *TraceInterpreter::getSerializedContextState(uint32_t frameIndex)
return nullptr;
}
void TraceInterpreter::setValidateSerializedStateCallback(ValidateSerializedStateCallback callback)
{
SetValidateSerializedStateCallback(callback);
}
void TraceInterpreter::runTraceFunction(const char *name) const
{
auto iter = mTraceFunctions.find(name);
@@ -610,6 +601,14 @@ void TraceInterpreter::runTraceFunction(const char *name) const
ReplayTraceFunction(func, mTraceFunctions);
}
TraceInterpreter &GetInterpreter()
{
static angle::base::NoDestructor<std::unique_ptr<TraceInterpreter>> sTraceInterpreter(
new TraceInterpreter());
return *sTraceInterpreter.get()->get();
}
} // anonymous namespace
template <>
void PackParameter<uint32_t>(ParamBuffer &params, const Token &token, const TraceStringMap &strings)
{
@@ -950,4 +949,62 @@ void PackParameter<unsigned long>(ParamBuffer &params,
PackIntParameter<uint64_t>(params, ParamType::TGLuint64, token);
}
#endif // defined(ANGLE_PLATFORM_APPLE) || !defined(ANGLE_IS_64_BIT_CPU)
GLuint GetResourceIDMapValue(ResourceIDType resourceIDType, GLuint key)
{
switch (resourceIDType)
{
case ResourceIDType::Buffer:
return gBufferMap[key];
case ResourceIDType::FenceNV:
return gFenceNVMap[key];
case ResourceIDType::Framebuffer:
return gFramebufferMap[key];
case ResourceIDType::ProgramPipeline:
return gProgramPipelineMap[key];
case ResourceIDType::Query:
return gQueryMap[key];
case ResourceIDType::Renderbuffer:
return gRenderbufferMap[key];
case ResourceIDType::Sampler:
return gSamplerMap[key];
case ResourceIDType::Semaphore:
return gSemaphoreMap[key];
case ResourceIDType::ShaderProgram:
return gShaderProgramMap[key];
case ResourceIDType::Texture:
return gTextureMap[key];
case ResourceIDType::TransformFeedback:
return gTransformFeedbackMap[key];
case ResourceIDType::VertexArray:
return gVertexArrayMap[key];
default:
printf("Incompatible resource ID type: %d\n", static_cast<int>(resourceIDType));
UNREACHABLE();
return 0;
}
}
} // namespace angle
extern "C" {
void SetupReplay()
{
angle::GetInterpreter().setupReplay();
}
void ReplayFrame(uint32_t frameIndex)
{
angle::GetInterpreter().replayFrame(frameIndex);
}
void ResetReplay()
{
angle::GetInterpreter().resetReplay();
}
const char *GetSerializedContextState(uint32_t frameIndex)
{
return angle::GetInterpreter().getSerializedContextState(frameIndex);
}
} // extern "C"

View File

@@ -12,6 +12,7 @@
#include "common/frame_capture_utils.h"
#include "frame_capture_test_utils.h"
#include "traces_export.h"
namespace angle
{
@@ -22,33 +23,6 @@ struct TraceString
};
using TraceStringMap = std::map<std::string, TraceString>;
class TraceInterpreter : public TraceReplayInterface
{
public:
TraceInterpreter(const TraceInfo &traceInfo, const char *testDataDir, bool verboseLogging);
~TraceInterpreter() override;
bool valid() const override;
void setBinaryDataDir(const char *dataDir) override;
void setBinaryDataDecompressCallback(DecompressCallback decompressCallback,
DeleteCallback deleteCallback) override;
void replayFrame(uint32_t frameIndex) override;
void setupReplay() override;
void resetReplay() override;
void finishReplay() override;
const char *getSerializedContextState(uint32_t frameIndex) override;
void setValidateSerializedStateCallback(ValidateSerializedStateCallback callback) override;
private:
void runTraceFunction(const char *name) const;
const TraceInfo &mTraceInfo;
const char *mTestDataDir;
TraceFunctionMap mTraceFunctions;
TraceStringMap mTraceStrings;
bool mVerboseLogging;
};
constexpr size_t kMaxTokenSize = 200;
constexpr size_t kMaxParameters = 32;
using Token = char[kMaxTokenSize];
@@ -312,4 +286,11 @@ ParamBuffer ParseParameters(const Token *paramTokens, const TraceStringMap &stri
}
} // namespace angle
extern "C" {
ANGLE_REPLAY_EXPORT void SetupReplay();
ANGLE_REPLAY_EXPORT void ReplayFrame(uint32_t frameIndex);
ANGLE_REPLAY_EXPORT void ResetReplay();
ANGLE_REPLAY_EXPORT const char *GetSerializedContextState(uint32_t frameIndex);
} // extern "C"
#endif // ANGLE_TRACE_INTERPRETER_H_