Commit cee0bfd6 by Gert Wollny Committed by Commit Bot

Capture/Replay: serialize context to JSON

Bug: angleproject:5715 Change-Id: Ibc6897d7567fedab4a2ba7bf8d2bd5a7e496bd4b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2760325Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent d00bd105
......@@ -1076,19 +1076,14 @@ void WriteCppReplay(bool compression,
if (serializeStateEnabled)
{
gl::BinaryOutputStream serializedContextData{};
angle::JsonSerializer serializedContextData;
if (SerializeContext(&serializedContextData, const_cast<gl::Context *>(context)) ==
Result::Continue)
{
size_t serializedContextLength = serializedContextData.length();
size_t serializedContextOffset = rx::roundUpPow2(binaryData->size(), kBinaryAlignment);
binaryData->resize(serializedContextOffset + serializedContextLength);
memcpy(binaryData->data() + serializedContextOffset, serializedContextData.data(),
serializedContextLength);
out << "const uint8_t *"
<< FmtGetSerializedContextStateFunction(context->id(), frameIndex) << "\n";
out << "const char *" << FmtGetSerializedContextStateFunction(context->id(), frameIndex)
<< "\n";
out << "{\n";
out << " return &gBinaryData[" << serializedContextOffset << "];\n";
out << " return R\"(" << serializedContextData.data() << ")\";\n";
out << "}\n";
out << "\n";
}
......@@ -1212,7 +1207,7 @@ void WriteCppReplayIndexFiles(bool compression,
header << "ANGLE_REPLAY_EXPORT void ResetContext" << contextId << "Replay();\n";
if (serializeStateEnabled)
{
header << "ANGLE_REPLAY_EXPORT const uint8_t *GetSerializedContext" << contextId
header << "ANGLE_REPLAY_EXPORT const char * GetSerializedContext" << contextId
<< "State(uint32_t frameIndex);\n";
}
header << "\n";
......@@ -1225,7 +1220,7 @@ void WriteCppReplayIndexFiles(bool compression,
{
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
{
header << "ANGLE_REPLAY_EXPORT const uint8_t *"
header << "ANGLE_REPLAY_EXPORT const char *"
<< FmtGetSerializedContextStateFunction(contextId, frameIndex) << ";\n";
}
header << "\n";
......@@ -1379,8 +1374,7 @@ void WriteCppReplayIndexFiles(bool compression,
if (serializeStateEnabled)
{
source << "const uint8_t *GetSerializedContext" << contextId
<< "State(uint32_t frameIndex)\n";
source << "const char *GetSerializedContext" << contextId << "State(uint32_t frameIndex)\n";
source << "{\n";
source << " switch (frameIndex)\n";
source << " {\n";
......
......@@ -11,14 +11,18 @@
#include "libANGLE/Error.h"
namespace angle
{
class JsonSerializer;
} // namespace angle
namespace gl
{
class BinaryOutputStream;
class Context;
} // namespace gl
namespace angle
{
Result SerializeContext(gl::BinaryOutputStream *bos, const gl::Context *context);
Result SerializeContext(JsonSerializer *bos, const gl::Context *context);
} // namespace angle
#endif // FRAME_CAPTURE_UTILS_H_
......@@ -116,7 +116,7 @@ using DecompressCallback = uint8_t *(*)(const std::vector<uint8_t> &);
void SetupContextReplay(uint32_t test);
void ReplayContextFrame(uint32_t test, uint32_t frameIndex);
void ResetContextReplay(uint32_t test);
const uint8_t *GetSerializedContextState(uint32_t test, uint32_t frameIndex);
const char *GetSerializedContextState(uint32_t test, uint32_t frameIndex);
void SetBinaryDataDecompressCallback(uint32_t test, DecompressCallback callback);
void SetBinaryDataDir(uint32_t test, const char *dataDir);
......@@ -164,7 +164,7 @@ void ResetContextReplay(uint32_t test)
{reset_context1_replay_switch_statement}
}}
const uint8_t *GetSerializedContextState(uint32_t test, uint32_t frameIndex)
const char *GetSerializedContextState(uint32_t test, uint32_t frameIndex)
{{
{get_serialized_context1_state_data_switch_statement}
}}
......
......@@ -33,6 +33,7 @@ if (angle_build_capture_replay_tests) {
"$angle_root:angle_common",
"$angle_root:angle_compression",
"$angle_root:libEGL_with_capture_static",
"$angle_root:libjson_serializer",
"$angle_root/util:angle_util_static",
]
configs += [
......
......@@ -10,16 +10,19 @@
#include "common/system_utils.h"
#include "libANGLE/Context.h"
#include "libANGLE/capture/frame_capture_utils.h"
#include "libANGLE/serializer/JsonSerializer.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>
......@@ -128,13 +131,13 @@ class CaptureReplayTests
{
ReplayContextFrame(testIndex, frame);
gl::Context *context = static_cast<gl::Context *>(mEGLWindow->getContext());
gl::BinaryOutputStream bos;
if (angle::SerializeContext(&bos, context) != angle::Result::Continue)
angle::JsonSerializer json;
if (angle::SerializeContext(&json, context) != angle::Result::Continue)
{
cleanupTest();
return -1;
}
bool isEqual = compareSerializedContexts(testIndex, frame, bos.getData());
bool isEqual = compareSerializedContexts(testIndex, frame, json.data());
// Swap always to allow RenderDoc/other tools to capture frames.
swap();
if (!isEqual)
......@@ -160,12 +163,10 @@ class CaptureReplayTests
private:
bool compareSerializedContexts(uint32_t testIndex,
uint32_t frame,
const std::vector<uint8_t> &replaySerializedContextState)
const char *replaySerializedContextState)
{
return memcmp(replaySerializedContextState.data(),
GetSerializedContextState(testIndex, frame),
replaySerializedContextState.size()) == 0;
return !strcmp(replaySerializedContextState, GetSerializedContextState(testIndex, frame));
}
OSWindow *mOSWindow = nullptr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment