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, ...@@ -1076,19 +1076,14 @@ void WriteCppReplay(bool compression,
if (serializeStateEnabled) if (serializeStateEnabled)
{ {
gl::BinaryOutputStream serializedContextData{}; angle::JsonSerializer serializedContextData;
if (SerializeContext(&serializedContextData, const_cast<gl::Context *>(context)) == if (SerializeContext(&serializedContextData, const_cast<gl::Context *>(context)) ==
Result::Continue) Result::Continue)
{ {
size_t serializedContextLength = serializedContextData.length(); out << "const char *" << FmtGetSerializedContextStateFunction(context->id(), frameIndex)
size_t serializedContextOffset = rx::roundUpPow2(binaryData->size(), kBinaryAlignment); << "\n";
binaryData->resize(serializedContextOffset + serializedContextLength);
memcpy(binaryData->data() + serializedContextOffset, serializedContextData.data(),
serializedContextLength);
out << "const uint8_t *"
<< FmtGetSerializedContextStateFunction(context->id(), frameIndex) << "\n";
out << "{\n"; out << "{\n";
out << " return &gBinaryData[" << serializedContextOffset << "];\n"; out << " return R\"(" << serializedContextData.data() << ")\";\n";
out << "}\n"; out << "}\n";
out << "\n"; out << "\n";
} }
...@@ -1212,7 +1207,7 @@ void WriteCppReplayIndexFiles(bool compression, ...@@ -1212,7 +1207,7 @@ void WriteCppReplayIndexFiles(bool compression,
header << "ANGLE_REPLAY_EXPORT void ResetContext" << contextId << "Replay();\n"; header << "ANGLE_REPLAY_EXPORT void ResetContext" << contextId << "Replay();\n";
if (serializeStateEnabled) if (serializeStateEnabled)
{ {
header << "ANGLE_REPLAY_EXPORT const uint8_t *GetSerializedContext" << contextId header << "ANGLE_REPLAY_EXPORT const char * GetSerializedContext" << contextId
<< "State(uint32_t frameIndex);\n"; << "State(uint32_t frameIndex);\n";
} }
header << "\n"; header << "\n";
...@@ -1225,7 +1220,7 @@ void WriteCppReplayIndexFiles(bool compression, ...@@ -1225,7 +1220,7 @@ void WriteCppReplayIndexFiles(bool compression,
{ {
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex) 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"; << FmtGetSerializedContextStateFunction(contextId, frameIndex) << ";\n";
} }
header << "\n"; header << "\n";
...@@ -1379,8 +1374,7 @@ void WriteCppReplayIndexFiles(bool compression, ...@@ -1379,8 +1374,7 @@ void WriteCppReplayIndexFiles(bool compression,
if (serializeStateEnabled) if (serializeStateEnabled)
{ {
source << "const uint8_t *GetSerializedContext" << contextId source << "const char *GetSerializedContext" << contextId << "State(uint32_t frameIndex)\n";
<< "State(uint32_t frameIndex)\n";
source << "{\n"; source << "{\n";
source << " switch (frameIndex)\n"; source << " switch (frameIndex)\n";
source << " {\n"; source << " {\n";
......
...@@ -11,14 +11,18 @@ ...@@ -11,14 +11,18 @@
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
namespace angle
{
class JsonSerializer;
} // namespace angle
namespace gl namespace gl
{ {
class BinaryOutputStream;
class Context; class Context;
} // namespace gl } // namespace gl
namespace angle namespace angle
{ {
Result SerializeContext(gl::BinaryOutputStream *bos, const gl::Context *context); Result SerializeContext(JsonSerializer *bos, const gl::Context *context);
} // namespace angle } // namespace angle
#endif // FRAME_CAPTURE_UTILS_H_ #endif // FRAME_CAPTURE_UTILS_H_
...@@ -116,7 +116,7 @@ using DecompressCallback = uint8_t *(*)(const std::vector<uint8_t> &); ...@@ -116,7 +116,7 @@ using DecompressCallback = uint8_t *(*)(const std::vector<uint8_t> &);
void SetupContextReplay(uint32_t test); void SetupContextReplay(uint32_t test);
void ReplayContextFrame(uint32_t test, uint32_t frameIndex); void ReplayContextFrame(uint32_t test, uint32_t frameIndex);
void ResetContextReplay(uint32_t test); 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 SetBinaryDataDecompressCallback(uint32_t test, DecompressCallback callback);
void SetBinaryDataDir(uint32_t test, const char *dataDir); void SetBinaryDataDir(uint32_t test, const char *dataDir);
...@@ -164,7 +164,7 @@ void ResetContextReplay(uint32_t test) ...@@ -164,7 +164,7 @@ void ResetContextReplay(uint32_t test)
{reset_context1_replay_switch_statement} {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} {get_serialized_context1_state_data_switch_statement}
}} }}
......
...@@ -33,6 +33,7 @@ if (angle_build_capture_replay_tests) { ...@@ -33,6 +33,7 @@ if (angle_build_capture_replay_tests) {
"$angle_root:angle_common", "$angle_root:angle_common",
"$angle_root:angle_compression", "$angle_root:angle_compression",
"$angle_root:libEGL_with_capture_static", "$angle_root:libEGL_with_capture_static",
"$angle_root:libjson_serializer",
"$angle_root/util:angle_util_static", "$angle_root/util:angle_util_static",
] ]
configs += [ configs += [
......
...@@ -10,16 +10,19 @@ ...@@ -10,16 +10,19 @@
#include "common/system_utils.h" #include "common/system_utils.h"
#include "libANGLE/Context.h" #include "libANGLE/Context.h"
#include "libANGLE/capture/frame_capture_utils.h" #include "libANGLE/capture/frame_capture_utils.h"
#include "libANGLE/serializer/JsonSerializer.h"
#include "util/EGLPlatformParameters.h" #include "util/EGLPlatformParameters.h"
#include "util/EGLWindow.h" #include "util/EGLWindow.h"
#include "util/OSWindow.h" #include "util/OSWindow.h"
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <fstream>
#include <functional> #include <functional>
#include <iostream> #include <iostream>
#include <list> #include <list>
#include <memory> #include <memory>
#include <ostream>
#include <string> #include <string>
#include <utility> #include <utility>
...@@ -128,13 +131,13 @@ class CaptureReplayTests ...@@ -128,13 +131,13 @@ class CaptureReplayTests
{ {
ReplayContextFrame(testIndex, frame); ReplayContextFrame(testIndex, frame);
gl::Context *context = static_cast<gl::Context *>(mEGLWindow->getContext()); gl::Context *context = static_cast<gl::Context *>(mEGLWindow->getContext());
gl::BinaryOutputStream bos; angle::JsonSerializer json;
if (angle::SerializeContext(&bos, context) != angle::Result::Continue) if (angle::SerializeContext(&json, context) != angle::Result::Continue)
{ {
cleanupTest(); cleanupTest();
return -1; 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 always to allow RenderDoc/other tools to capture frames.
swap(); swap();
if (!isEqual) if (!isEqual)
...@@ -160,12 +163,10 @@ class CaptureReplayTests ...@@ -160,12 +163,10 @@ class CaptureReplayTests
private: private:
bool compareSerializedContexts(uint32_t testIndex, bool compareSerializedContexts(uint32_t testIndex,
uint32_t frame, uint32_t frame,
const std::vector<uint8_t> &replaySerializedContextState) const char *replaySerializedContextState)
{ {
return memcmp(replaySerializedContextState.data(), return !strcmp(replaySerializedContextState, GetSerializedContextState(testIndex, frame));
GetSerializedContextState(testIndex, frame),
replaySerializedContextState.size()) == 0;
} }
OSWindow *mOSWindow = nullptr; 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