Commit 39b777c6 by Jamie Madill Committed by Commit Bot

Capture/Replay: Two cleanups.

This changes from returning a vector to directly returning a pointer to the binary data for the serialized state. The second cleanup is to use a ContextID as a wrapped type which simplifies the output formatting code. Bug: angleproject:5247 Change-Id: Ieb8afdb9326a12968dd2d69c05e1ed811b93abff Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2506198Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 04d7be3f
...@@ -203,6 +203,12 @@ std::string GetCaptureTrigger() ...@@ -203,6 +203,12 @@ std::string GetCaptureTrigger()
#endif // defined(ANGLE_PLATFORM_ANDROID) #endif // defined(ANGLE_PLATFORM_ANDROID)
} }
std::ostream &operator<<(std::ostream &os, gl::ContextID contextId)
{
os << static_cast<int>(contextId.value);
return os;
}
struct FmtCapturePrefix struct FmtCapturePrefix
{ {
FmtCapturePrefix(gl::ContextID contextIdIn, const std::string &captureLabelIn) FmtCapturePrefix(gl::ContextID contextIdIn, const std::string &captureLabelIn)
...@@ -222,7 +228,7 @@ std::ostream &operator<<(std::ostream &os, const FmtCapturePrefix &fmt) ...@@ -222,7 +228,7 @@ std::ostream &operator<<(std::ostream &os, const FmtCapturePrefix &fmt)
{ {
os << fmt.captureLabel; os << fmt.captureLabel;
} }
os << "_capture_context" << static_cast<int>(fmt.contextId); os << "_capture_context" << fmt.contextId;
return os; return os;
} }
...@@ -249,7 +255,7 @@ struct FmtReplayFunction ...@@ -249,7 +255,7 @@ struct FmtReplayFunction
std::ostream &operator<<(std::ostream &os, const FmtReplayFunction &fmt) std::ostream &operator<<(std::ostream &os, const FmtReplayFunction &fmt)
{ {
os << "ReplayContext" << static_cast<int>(fmt.contextId) << "Frame" << fmt.frameIndex; os << "ReplayContext" << fmt.contextId << "Frame" << fmt.frameIndex;
if (fmt.partId != kNoPartId) if (fmt.partId != kNoPartId)
{ {
os << "Part" << fmt.partId; os << "Part" << fmt.partId;
...@@ -270,7 +276,7 @@ struct FmtSetupFunction ...@@ -270,7 +276,7 @@ struct FmtSetupFunction
std::ostream &operator<<(std::ostream &os, const FmtSetupFunction &fmt) std::ostream &operator<<(std::ostream &os, const FmtSetupFunction &fmt)
{ {
os << "SetupContext" << Str(static_cast<int>(fmt.contextId)) << "Replay"; os << "SetupContext" << fmt.contextId << "Replay";
if (fmt.partId != kNoPartId) if (fmt.partId != kNoPartId)
{ {
os << "Part" << fmt.partId; os << "Part" << fmt.partId;
...@@ -288,7 +294,7 @@ struct FmtResetFunction ...@@ -288,7 +294,7 @@ struct FmtResetFunction
std::ostream &operator<<(std::ostream &os, const FmtResetFunction &fmt) std::ostream &operator<<(std::ostream &os, const FmtResetFunction &fmt)
{ {
os << "ResetContext" << Str(static_cast<int>(fmt.contextId)) << "Replay()"; os << "ResetContext" << fmt.contextId << "Replay()";
return os; return os;
} }
...@@ -331,19 +337,18 @@ std::ostream &operator<<(std::ostream &os, const FmtFunction &fmt) ...@@ -331,19 +337,18 @@ std::ostream &operator<<(std::ostream &os, const FmtFunction &fmt)
return os; return os;
} }
struct FmtGetSerializedContextStateDataFunction struct FmtGetSerializedContextStateFunction
{ {
FmtGetSerializedContextStateDataFunction(gl::ContextID contextIdIn, uint32_t frameIndexIn) FmtGetSerializedContextStateFunction(gl::ContextID contextIdIn, uint32_t frameIndexIn)
: contextId(contextIdIn), frameIndex(frameIndexIn) : contextId(contextIdIn), frameIndex(frameIndexIn)
{} {}
gl::ContextID contextId; gl::ContextID contextId;
uint32_t frameIndex; uint32_t frameIndex;
}; };
std::ostream &operator<<(std::ostream &os, const FmtGetSerializedContextStateDataFunction &fmt) std::ostream &operator<<(std::ostream &os, const FmtGetSerializedContextStateFunction &fmt)
{ {
os << "GetSerializedContext" << static_cast<int>(fmt.contextId) << "StateFrame" os << "GetSerializedContext" << fmt.contextId << "StateFrame" << fmt.frameIndex << "Data()";
<< fmt.frameIndex << "Data()";
return os; return os;
} }
...@@ -1148,14 +1153,10 @@ void WriteCppReplay(bool compression, ...@@ -1148,14 +1153,10 @@ void WriteCppReplay(bool compression,
binaryData->resize(serializedContextOffset + serializedContextLength); binaryData->resize(serializedContextOffset + serializedContextLength);
memcpy(binaryData->data() + serializedContextOffset, serializedContextData.data(), memcpy(binaryData->data() + serializedContextOffset, serializedContextData.data(),
serializedContextLength); serializedContextLength);
out << "std::vector<uint8_t> " out << "const uint8_t *"
<< FmtGetSerializedContextStateDataFunction(context->id(), frameIndex) << "\n"; << FmtGetSerializedContextStateFunction(context->id(), frameIndex) << "\n";
out << "{\n"; out << "{\n";
out << " std::vector<uint8_t> serializedContextData(" << serializedContextLength out << " return &gBinaryData[" << serializedContextOffset << "];\n";
<< ");\n";
out << " memcpy(serializedContextData.data(), &gBinaryData["
<< serializedContextOffset << "], " << serializedContextLength << ");\n";
out << " return serializedContextData;\n";
out << "}\n"; out << "}\n";
out << "\n"; out << "\n";
} }
...@@ -1249,14 +1250,13 @@ void WriteCppReplayIndexFiles(bool compression, ...@@ -1249,14 +1250,13 @@ void WriteCppReplayIndexFiles(bool compression,
<< ";\n"; << ";\n";
header << "// End Trace Metadata\n"; header << "// End Trace Metadata\n";
header << "\n"; header << "\n";
header << "void SetupContext" << static_cast<int>(contextId) << "Replay();\n"; header << "void SetupContext" << contextId << "Replay();\n";
header << "void ReplayContext" << static_cast<int>(contextId) header << "void ReplayContext" << contextId << "Frame(uint32_t frameIndex);\n";
<< "Frame(uint32_t frameIndex);\n"; header << "void ResetContext" << contextId << "Replay();\n";
header << "void ResetContext" << static_cast<int>(contextId) << "Replay();\n";
if (serializeStateEnabled) if (serializeStateEnabled)
{ {
header << "std::vector<uint8_t> GetSerializedContext" << static_cast<int>(contextId) header << "const uint8_t *GetSerializedContext" << contextId
<< "StateData(uint32_t frameIndex);\n"; << "State(uint32_t frameIndex);\n";
} }
header << "\n"; header << "\n";
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex) for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
...@@ -1268,8 +1268,8 @@ void WriteCppReplayIndexFiles(bool compression, ...@@ -1268,8 +1268,8 @@ void WriteCppReplayIndexFiles(bool compression,
{ {
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex) for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
{ {
header << "std::vector<uint8_t> " header << "const uint8_t *"
<< FmtGetSerializedContextStateDataFunction(contextId, frameIndex) << ";\n"; << FmtGetSerializedContextStateFunction(contextId, frameIndex) << ";\n";
} }
header << "\n"; header << "\n";
} }
...@@ -1383,15 +1383,14 @@ void WriteCppReplayIndexFiles(bool compression, ...@@ -1383,15 +1383,14 @@ void WriteCppReplayIndexFiles(bool compression,
header << "\n"; header << "\n";
source << "\n"; source << "\n";
source << "void ReplayContext" << static_cast<int>(contextId) << "Frame(uint32_t frameIndex)\n"; source << "void ReplayContext" << contextId << "Frame(uint32_t frameIndex)\n";
source << "{\n"; source << "{\n";
source << " switch (frameIndex)\n"; source << " switch (frameIndex)\n";
source << " {\n"; source << " {\n";
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex) for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
{ {
source << " case " << frameIndex << ":\n"; source << " case " << frameIndex << ":\n";
source << " ReplayContext" << static_cast<int>(contextId) << "Frame" source << " ReplayContext" << contextId << "Frame" << frameIndex << "();\n";
<< frameIndex << "();\n";
source << " break;\n"; source << " break;\n";
} }
source << " default:\n"; source << " default:\n";
...@@ -1402,7 +1401,7 @@ void WriteCppReplayIndexFiles(bool compression, ...@@ -1402,7 +1401,7 @@ void WriteCppReplayIndexFiles(bool compression,
if (writeResetContextCall) if (writeResetContextCall)
{ {
source << "void ResetContext" << Str(static_cast<int>(contextId)) << "Replay()\n"; source << "void ResetContext" << contextId << "Replay()\n";
source << "{\n"; source << "{\n";
source << " // Reset context is empty because context is destroyed before end " source << " // Reset context is empty because context is destroyed before end "
"frame is reached\n"; "frame is reached\n";
...@@ -1412,8 +1411,8 @@ void WriteCppReplayIndexFiles(bool compression, ...@@ -1412,8 +1411,8 @@ void WriteCppReplayIndexFiles(bool compression,
if (serializeStateEnabled) if (serializeStateEnabled)
{ {
source << "std::vector<uint8_t> GetSerializedContext" << static_cast<int>(contextId) source << "const uint8_t *GetSerializedContext" << contextId
<< "StateData(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";
...@@ -1421,7 +1420,7 @@ void WriteCppReplayIndexFiles(bool compression, ...@@ -1421,7 +1420,7 @@ void WriteCppReplayIndexFiles(bool compression,
{ {
source << " case " << frameIndex << ":\n"; source << " case " << frameIndex << ":\n";
source << " return " source << " return "
<< FmtGetSerializedContextStateDataFunction(contextId, frameIndex) << ";\n"; << FmtGetSerializedContextStateFunction(contextId, frameIndex) << ";\n";
} }
source << " default:\n"; source << " default:\n";
source << " return {};\n"; source << " return {};\n";
......
...@@ -114,7 +114,7 @@ bool IsTextureCompatibleWithSampler(TextureType texture, TextureType sampler) ...@@ -114,7 +114,7 @@ bool IsTextureCompatibleWithSampler(TextureType texture, TextureType sampler)
return false; return false;
} }
int gIDCounter = 1; uint32_t gIDCounter = 1;
} // namespace } // namespace
template <typename BindingT, typename... ArgsT> template <typename BindingT, typename... ArgsT>
...@@ -293,7 +293,7 @@ State::State(const State *shareContextState, ...@@ -293,7 +293,7 @@ State::State(const State *shareContextState,
bool robustResourceInit, bool robustResourceInit,
bool programBinaryCacheEnabled, bool programBinaryCacheEnabled,
EGLenum contextPriority) EGLenum contextPriority)
: mID(gIDCounter++), : mID({gIDCounter++}),
mClientType(clientType), mClientType(clientType),
mContextPriority(contextPriority), mContextPriority(contextPriority),
mClientVersion(clientVersion), mClientVersion(clientVersion),
......
...@@ -59,8 +59,6 @@ static constexpr Version ES_3_0 = Version(3, 0); ...@@ -59,8 +59,6 @@ static constexpr Version ES_3_0 = Version(3, 0);
static constexpr Version ES_3_1 = Version(3, 1); static constexpr Version ES_3_1 = Version(3, 1);
static constexpr Version ES_3_2 = Version(3, 2); static constexpr Version ES_3_2 = Version(3, 2);
using ContextID = uintptr_t;
template <typename T> template <typename T>
using BufferBindingMap = angle::PackedEnumMap<BufferBinding, T>; using BufferBindingMap = angle::PackedEnumMap<BufferBinding, T>;
using BoundBufferMap = BufferBindingMap<BindingPointer<Buffer>>; using BoundBufferMap = BufferBindingMap<BindingPointer<Buffer>>;
......
...@@ -1890,12 +1890,12 @@ bool Texture::isSamplerComplete(const Context *context, const Sampler *optionalS ...@@ -1890,12 +1890,12 @@ bool Texture::isSamplerComplete(const Context *context, const Sampler *optionalS
} }
Texture::SamplerCompletenessCache::SamplerCompletenessCache() Texture::SamplerCompletenessCache::SamplerCompletenessCache()
: context(0), samplerState(), samplerComplete(false) : context({0}), samplerState(), samplerComplete(false)
{} {}
void Texture::invalidateCompletenessCache() const void Texture::invalidateCompletenessCache() const
{ {
mCompletenessCache.context = 0; mCompletenessCache.context = {0};
} }
angle::Result Texture::ensureInitialized(const Context *context) angle::Result Texture::ensureInitialized(const Context *context)
......
...@@ -753,7 +753,25 @@ enum class RenderToTextureImageIndex ...@@ -753,7 +753,25 @@ enum class RenderToTextureImageIndex
template <typename T> template <typename T>
using RenderToTextureImageMap = angle::PackedEnumMap<RenderToTextureImageIndex, T>; using RenderToTextureImageMap = angle::PackedEnumMap<RenderToTextureImageIndex, T>;
using ContextID = uintptr_t; struct ContextID
{
uint32_t value;
};
inline bool operator==(ContextID lhs, ContextID rhs)
{
return lhs.value == rhs.value;
}
inline bool operator!=(ContextID lhs, ContextID rhs)
{
return lhs.value != rhs.value;
}
inline bool operator<(ContextID lhs, ContextID rhs)
{
return lhs.value < rhs.value;
}
constexpr size_t kCubeFaceCount = 6; constexpr size_t kCubeFaceCount = 6;
......
...@@ -100,7 +100,7 @@ constexpr ANGLE_INLINE ReturnType GetDefaultReturnValue() ...@@ -100,7 +100,7 @@ constexpr ANGLE_INLINE ReturnType GetDefaultReturnValue()
inline int CID(const Context *context) inline int CID(const Context *context)
{ {
return context != nullptr ? static_cast<int>(context->id()) : 0; return context == nullptr ? 0 : static_cast<int>(context->id().value);
} }
} // namespace gl } // namespace gl
......
...@@ -76,7 +76,7 @@ StateManagerGL::StateManagerGL(const FunctionsGL *functions, ...@@ -76,7 +76,7 @@ StateManagerGL::StateManagerGL(const FunctionsGL *functions,
mTransformFeedback(0), mTransformFeedback(0),
mCurrentTransformFeedback(nullptr), mCurrentTransformFeedback(nullptr),
mQueries(), mQueries(),
mPrevDrawContext(0), mPrevDrawContext({0}),
mUnpackAlignment(4), mUnpackAlignment(4),
mUnpackRowLength(0), mUnpackRowLength(0),
mUnpackSkipRows(0), mUnpackSkipRows(0),
......
...@@ -109,7 +109,7 @@ using DecompressCallback = uint8_t *(*)(const std::vector<uint8_t> &); ...@@ -109,7 +109,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);
std::vector<uint8_t> GetSerializedContextStateData(uint32_t test, uint32_t frameIndex); const uint8_t *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);
...@@ -153,7 +153,7 @@ void ResetContextReplay(uint32_t test) ...@@ -153,7 +153,7 @@ void ResetContextReplay(uint32_t test)
{reset_context1_replay_switch_statement} {reset_context1_replay_switch_statement}
}} }}
std::vector<uint8_t> GetSerializedContextStateData(uint32_t test, uint32_t frameIndex) const uint8_t *GetSerializedContextState(uint32_t test, uint32_t frameIndex)
{{ {{
{get_serialized_context1_state_data_switch_statement} {get_serialized_context1_state_data_switch_statement}
}} }}
...@@ -714,7 +714,7 @@ class TestBatch(): ...@@ -714,7 +714,7 @@ class TestBatch():
reset_context1_replay_switch_statement = WriteGeneratedSwitchStatements( reset_context1_replay_switch_statement = WriteGeneratedSwitchStatements(
tests, "ResetContextReplay", "") tests, "ResetContextReplay", "")
get_serialized_context1_state_data_switch_statement = WriteGeneratedSwitchStatements( get_serialized_context1_state_data_switch_statement = WriteGeneratedSwitchStatements(
tests, "GetSerializedContextStateData", "frameIndex", True, "{}") tests, "GetSerializedContextState", "frameIndex", True, "{}")
set_binary_data_decompress_callback_switch_statement = WriteGeneratedSwitchStatements( set_binary_data_decompress_callback_switch_statement = WriteGeneratedSwitchStatements(
tests, "SetBinaryDataDecompressCallback", "callback") tests, "SetBinaryDataDecompressCallback", "callback")
set_binary_data_dir_switch_statement = WriteGeneratedSwitchStatements( set_binary_data_dir_switch_statement = WriteGeneratedSwitchStatements(
......
...@@ -127,7 +127,7 @@ class CaptureReplayTests ...@@ -127,7 +127,7 @@ class CaptureReplayTests
cleanupTest(); cleanupTest();
return -1; return -1;
} }
bool isEqual = compareSerializedStates(testIndex, frame, bos); bool isEqual = compareSerializedContexts(testIndex, frame, bos.getData());
if (!isEqual) if (!isEqual)
{ {
cleanupTest(); cleanupTest();
...@@ -150,12 +150,14 @@ class CaptureReplayTests ...@@ -150,12 +150,14 @@ class CaptureReplayTests
} }
private: private:
bool compareSerializedStates(uint32_t testIndex, bool compareSerializedContexts(uint32_t testIndex,
uint32_t frame, uint32_t frame,
const gl::BinaryOutputStream &replaySerializedContextData) const std::vector<uint8_t> &replaySerializedContextState)
{ {
return GetSerializedContextStateData(testIndex, frame) ==
replaySerializedContextData.getData(); return memcmp(replaySerializedContextState.data(),
GetSerializedContextState(testIndex, frame),
replaySerializedContextState.size()) == 0;
} }
OSWindow *mOSWindow; OSWindow *mOSWindow;
......
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