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()
#endif // defined(ANGLE_PLATFORM_ANDROID)
}
std::ostream &operator<<(std::ostream &os, gl::ContextID contextId)
{
os << static_cast<int>(contextId.value);
return os;
}
struct FmtCapturePrefix
{
FmtCapturePrefix(gl::ContextID contextIdIn, const std::string &captureLabelIn)
......@@ -222,7 +228,7 @@ std::ostream &operator<<(std::ostream &os, const FmtCapturePrefix &fmt)
{
os << fmt.captureLabel;
}
os << "_capture_context" << static_cast<int>(fmt.contextId);
os << "_capture_context" << fmt.contextId;
return os;
}
......@@ -249,7 +255,7 @@ struct FmtReplayFunction
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)
{
os << "Part" << fmt.partId;
......@@ -270,7 +276,7 @@ struct FmtSetupFunction
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)
{
os << "Part" << fmt.partId;
......@@ -288,7 +294,7 @@ struct FmtResetFunction
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;
}
......@@ -331,19 +337,18 @@ std::ostream &operator<<(std::ostream &os, const FmtFunction &fmt)
return os;
}
struct FmtGetSerializedContextStateDataFunction
struct FmtGetSerializedContextStateFunction
{
FmtGetSerializedContextStateDataFunction(gl::ContextID contextIdIn, uint32_t frameIndexIn)
FmtGetSerializedContextStateFunction(gl::ContextID contextIdIn, uint32_t frameIndexIn)
: contextId(contextIdIn), frameIndex(frameIndexIn)
{}
gl::ContextID contextId;
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"
<< fmt.frameIndex << "Data()";
os << "GetSerializedContext" << fmt.contextId << "StateFrame" << fmt.frameIndex << "Data()";
return os;
}
......@@ -1148,14 +1153,10 @@ void WriteCppReplay(bool compression,
binaryData->resize(serializedContextOffset + serializedContextLength);
memcpy(binaryData->data() + serializedContextOffset, serializedContextData.data(),
serializedContextLength);
out << "std::vector<uint8_t> "
<< FmtGetSerializedContextStateDataFunction(context->id(), frameIndex) << "\n";
out << "const uint8_t *"
<< FmtGetSerializedContextStateFunction(context->id(), frameIndex) << "\n";
out << "{\n";
out << " std::vector<uint8_t> serializedContextData(" << serializedContextLength
<< ");\n";
out << " memcpy(serializedContextData.data(), &gBinaryData["
<< serializedContextOffset << "], " << serializedContextLength << ");\n";
out << " return serializedContextData;\n";
out << " return &gBinaryData[" << serializedContextOffset << "];\n";
out << "}\n";
out << "\n";
}
......@@ -1249,14 +1250,13 @@ void WriteCppReplayIndexFiles(bool compression,
<< ";\n";
header << "// End Trace Metadata\n";
header << "\n";
header << "void SetupContext" << static_cast<int>(contextId) << "Replay();\n";
header << "void ReplayContext" << static_cast<int>(contextId)
<< "Frame(uint32_t frameIndex);\n";
header << "void ResetContext" << static_cast<int>(contextId) << "Replay();\n";
header << "void SetupContext" << contextId << "Replay();\n";
header << "void ReplayContext" << contextId << "Frame(uint32_t frameIndex);\n";
header << "void ResetContext" << contextId << "Replay();\n";
if (serializeStateEnabled)
{
header << "std::vector<uint8_t> GetSerializedContext" << static_cast<int>(contextId)
<< "StateData(uint32_t frameIndex);\n";
header << "const uint8_t *GetSerializedContext" << contextId
<< "State(uint32_t frameIndex);\n";
}
header << "\n";
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
......@@ -1268,8 +1268,8 @@ void WriteCppReplayIndexFiles(bool compression,
{
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
{
header << "std::vector<uint8_t> "
<< FmtGetSerializedContextStateDataFunction(contextId, frameIndex) << ";\n";
header << "const uint8_t *"
<< FmtGetSerializedContextStateFunction(contextId, frameIndex) << ";\n";
}
header << "\n";
}
......@@ -1383,15 +1383,14 @@ void WriteCppReplayIndexFiles(bool compression,
header << "\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 << " switch (frameIndex)\n";
source << " {\n";
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
{
source << " case " << frameIndex << ":\n";
source << " ReplayContext" << static_cast<int>(contextId) << "Frame"
<< frameIndex << "();\n";
source << " ReplayContext" << contextId << "Frame" << frameIndex << "();\n";
source << " break;\n";
}
source << " default:\n";
......@@ -1402,7 +1401,7 @@ void WriteCppReplayIndexFiles(bool compression,
if (writeResetContextCall)
{
source << "void ResetContext" << Str(static_cast<int>(contextId)) << "Replay()\n";
source << "void ResetContext" << contextId << "Replay()\n";
source << "{\n";
source << " // Reset context is empty because context is destroyed before end "
"frame is reached\n";
......@@ -1412,8 +1411,8 @@ void WriteCppReplayIndexFiles(bool compression,
if (serializeStateEnabled)
{
source << "std::vector<uint8_t> GetSerializedContext" << static_cast<int>(contextId)
<< "StateData(uint32_t frameIndex)\n";
source << "const uint8_t *GetSerializedContext" << contextId
<< "State(uint32_t frameIndex)\n";
source << "{\n";
source << " switch (frameIndex)\n";
source << " {\n";
......@@ -1421,7 +1420,7 @@ void WriteCppReplayIndexFiles(bool compression,
{
source << " case " << frameIndex << ":\n";
source << " return "
<< FmtGetSerializedContextStateDataFunction(contextId, frameIndex) << ";\n";
<< FmtGetSerializedContextStateFunction(contextId, frameIndex) << ";\n";
}
source << " default:\n";
source << " return {};\n";
......
......@@ -114,7 +114,7 @@ bool IsTextureCompatibleWithSampler(TextureType texture, TextureType sampler)
return false;
}
int gIDCounter = 1;
uint32_t gIDCounter = 1;
} // namespace
template <typename BindingT, typename... ArgsT>
......@@ -293,7 +293,7 @@ State::State(const State *shareContextState,
bool robustResourceInit,
bool programBinaryCacheEnabled,
EGLenum contextPriority)
: mID(gIDCounter++),
: mID({gIDCounter++}),
mClientType(clientType),
mContextPriority(contextPriority),
mClientVersion(clientVersion),
......
......@@ -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_2 = Version(3, 2);
using ContextID = uintptr_t;
template <typename T>
using BufferBindingMap = angle::PackedEnumMap<BufferBinding, T>;
using BoundBufferMap = BufferBindingMap<BindingPointer<Buffer>>;
......
......@@ -1890,12 +1890,12 @@ bool Texture::isSamplerComplete(const Context *context, const Sampler *optionalS
}
Texture::SamplerCompletenessCache::SamplerCompletenessCache()
: context(0), samplerState(), samplerComplete(false)
: context({0}), samplerState(), samplerComplete(false)
{}
void Texture::invalidateCompletenessCache() const
{
mCompletenessCache.context = 0;
mCompletenessCache.context = {0};
}
angle::Result Texture::ensureInitialized(const Context *context)
......
......@@ -753,7 +753,25 @@ enum class RenderToTextureImageIndex
template <typename 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;
......
......@@ -100,7 +100,7 @@ constexpr ANGLE_INLINE ReturnType GetDefaultReturnValue()
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
......
......@@ -76,7 +76,7 @@ StateManagerGL::StateManagerGL(const FunctionsGL *functions,
mTransformFeedback(0),
mCurrentTransformFeedback(nullptr),
mQueries(),
mPrevDrawContext(0),
mPrevDrawContext({0}),
mUnpackAlignment(4),
mUnpackRowLength(0),
mUnpackSkipRows(0),
......
......@@ -109,7 +109,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);
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 SetBinaryDataDir(uint32_t test, const char *dataDir);
......@@ -153,7 +153,7 @@ void ResetContextReplay(uint32_t test)
{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}
}}
......@@ -714,7 +714,7 @@ class TestBatch():
reset_context1_replay_switch_statement = WriteGeneratedSwitchStatements(
tests, "ResetContextReplay", "")
get_serialized_context1_state_data_switch_statement = WriteGeneratedSwitchStatements(
tests, "GetSerializedContextStateData", "frameIndex", True, "{}")
tests, "GetSerializedContextState", "frameIndex", True, "{}")
set_binary_data_decompress_callback_switch_statement = WriteGeneratedSwitchStatements(
tests, "SetBinaryDataDecompressCallback", "callback")
set_binary_data_dir_switch_statement = WriteGeneratedSwitchStatements(
......
......@@ -127,7 +127,7 @@ class CaptureReplayTests
cleanupTest();
return -1;
}
bool isEqual = compareSerializedStates(testIndex, frame, bos);
bool isEqual = compareSerializedContexts(testIndex, frame, bos.getData());
if (!isEqual)
{
cleanupTest();
......@@ -150,12 +150,14 @@ class CaptureReplayTests
}
private:
bool compareSerializedStates(uint32_t testIndex,
uint32_t frame,
const gl::BinaryOutputStream &replaySerializedContextData)
bool compareSerializedContexts(uint32_t testIndex,
uint32_t frame,
const std::vector<uint8_t> &replaySerializedContextState)
{
return GetSerializedContextStateData(testIndex, frame) ==
replaySerializedContextData.getData();
return memcmp(replaySerializedContextState.data(),
GetSerializedContextState(testIndex, frame),
replaySerializedContextState.size()) == 0;
}
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