Skip to content

Commit 39b777c

Browse files
null77Commit Bot
authored andcommitted
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/+/2506198 Reviewed-by: Courtney Goeltzenleuchter <courtneygo@google.com> Reviewed-by: Cody Northrop <cnorthrop@google.com> Commit-Queue: Jamie Madill <jmadill@chromium.org>
1 parent 04d7be3 commit 39b777c

File tree

9 files changed

+66
-49
lines changed

9 files changed

+66
-49
lines changed

src/libANGLE/FrameCapture.cpp

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ std::string GetCaptureTrigger()
203203
#endif // defined(ANGLE_PLATFORM_ANDROID)
204204
}
205205

206+
std::ostream &operator<<(std::ostream &os, gl::ContextID contextId)
207+
{
208+
os << static_cast<int>(contextId.value);
209+
return os;
210+
}
211+
206212
struct FmtCapturePrefix
207213
{
208214
FmtCapturePrefix(gl::ContextID contextIdIn, const std::string &captureLabelIn)
@@ -222,7 +228,7 @@ std::ostream &operator<<(std::ostream &os, const FmtCapturePrefix &fmt)
222228
{
223229
os << fmt.captureLabel;
224230
}
225-
os << "_capture_context" << static_cast<int>(fmt.contextId);
231+
os << "_capture_context" << fmt.contextId;
226232
return os;
227233
}
228234

@@ -249,7 +255,7 @@ struct FmtReplayFunction
249255

250256
std::ostream &operator<<(std::ostream &os, const FmtReplayFunction &fmt)
251257
{
252-
os << "ReplayContext" << static_cast<int>(fmt.contextId) << "Frame" << fmt.frameIndex;
258+
os << "ReplayContext" << fmt.contextId << "Frame" << fmt.frameIndex;
253259
if (fmt.partId != kNoPartId)
254260
{
255261
os << "Part" << fmt.partId;
@@ -270,7 +276,7 @@ struct FmtSetupFunction
270276

271277
std::ostream &operator<<(std::ostream &os, const FmtSetupFunction &fmt)
272278
{
273-
os << "SetupContext" << Str(static_cast<int>(fmt.contextId)) << "Replay";
279+
os << "SetupContext" << fmt.contextId << "Replay";
274280
if (fmt.partId != kNoPartId)
275281
{
276282
os << "Part" << fmt.partId;
@@ -288,7 +294,7 @@ struct FmtResetFunction
288294

289295
std::ostream &operator<<(std::ostream &os, const FmtResetFunction &fmt)
290296
{
291-
os << "ResetContext" << Str(static_cast<int>(fmt.contextId)) << "Replay()";
297+
os << "ResetContext" << fmt.contextId << "Replay()";
292298
return os;
293299
}
294300

@@ -331,19 +337,18 @@ std::ostream &operator<<(std::ostream &os, const FmtFunction &fmt)
331337
return os;
332338
}
333339

334-
struct FmtGetSerializedContextStateDataFunction
340+
struct FmtGetSerializedContextStateFunction
335341
{
336-
FmtGetSerializedContextStateDataFunction(gl::ContextID contextIdIn, uint32_t frameIndexIn)
342+
FmtGetSerializedContextStateFunction(gl::ContextID contextIdIn, uint32_t frameIndexIn)
337343
: contextId(contextIdIn), frameIndex(frameIndexIn)
338344
{}
339345
gl::ContextID contextId;
340346
uint32_t frameIndex;
341347
};
342348

343-
std::ostream &operator<<(std::ostream &os, const FmtGetSerializedContextStateDataFunction &fmt)
349+
std::ostream &operator<<(std::ostream &os, const FmtGetSerializedContextStateFunction &fmt)
344350
{
345-
os << "GetSerializedContext" << static_cast<int>(fmt.contextId) << "StateFrame"
346-
<< fmt.frameIndex << "Data()";
351+
os << "GetSerializedContext" << fmt.contextId << "StateFrame" << fmt.frameIndex << "Data()";
347352
return os;
348353
}
349354

@@ -1148,14 +1153,10 @@ void WriteCppReplay(bool compression,
11481153
binaryData->resize(serializedContextOffset + serializedContextLength);
11491154
memcpy(binaryData->data() + serializedContextOffset, serializedContextData.data(),
11501155
serializedContextLength);
1151-
out << "std::vector<uint8_t> "
1152-
<< FmtGetSerializedContextStateDataFunction(context->id(), frameIndex) << "\n";
1156+
out << "const uint8_t *"
1157+
<< FmtGetSerializedContextStateFunction(context->id(), frameIndex) << "\n";
11531158
out << "{\n";
1154-
out << " std::vector<uint8_t> serializedContextData(" << serializedContextLength
1155-
<< ");\n";
1156-
out << " memcpy(serializedContextData.data(), &gBinaryData["
1157-
<< serializedContextOffset << "], " << serializedContextLength << ");\n";
1158-
out << " return serializedContextData;\n";
1159+
out << " return &gBinaryData[" << serializedContextOffset << "];\n";
11591160
out << "}\n";
11601161
out << "\n";
11611162
}
@@ -1249,14 +1250,13 @@ void WriteCppReplayIndexFiles(bool compression,
12491250
<< ";\n";
12501251
header << "// End Trace Metadata\n";
12511252
header << "\n";
1252-
header << "void SetupContext" << static_cast<int>(contextId) << "Replay();\n";
1253-
header << "void ReplayContext" << static_cast<int>(contextId)
1254-
<< "Frame(uint32_t frameIndex);\n";
1255-
header << "void ResetContext" << static_cast<int>(contextId) << "Replay();\n";
1253+
header << "void SetupContext" << contextId << "Replay();\n";
1254+
header << "void ReplayContext" << contextId << "Frame(uint32_t frameIndex);\n";
1255+
header << "void ResetContext" << contextId << "Replay();\n";
12561256
if (serializeStateEnabled)
12571257
{
1258-
header << "std::vector<uint8_t> GetSerializedContext" << static_cast<int>(contextId)
1259-
<< "StateData(uint32_t frameIndex);\n";
1258+
header << "const uint8_t *GetSerializedContext" << contextId
1259+
<< "State(uint32_t frameIndex);\n";
12601260
}
12611261
header << "\n";
12621262
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
@@ -1268,8 +1268,8 @@ void WriteCppReplayIndexFiles(bool compression,
12681268
{
12691269
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
12701270
{
1271-
header << "std::vector<uint8_t> "
1272-
<< FmtGetSerializedContextStateDataFunction(contextId, frameIndex) << ";\n";
1271+
header << "const uint8_t *"
1272+
<< FmtGetSerializedContextStateFunction(contextId, frameIndex) << ";\n";
12731273
}
12741274
header << "\n";
12751275
}
@@ -1383,15 +1383,14 @@ void WriteCppReplayIndexFiles(bool compression,
13831383
header << "\n";
13841384

13851385
source << "\n";
1386-
source << "void ReplayContext" << static_cast<int>(contextId) << "Frame(uint32_t frameIndex)\n";
1386+
source << "void ReplayContext" << contextId << "Frame(uint32_t frameIndex)\n";
13871387
source << "{\n";
13881388
source << " switch (frameIndex)\n";
13891389
source << " {\n";
13901390
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
13911391
{
13921392
source << " case " << frameIndex << ":\n";
1393-
source << " ReplayContext" << static_cast<int>(contextId) << "Frame"
1394-
<< frameIndex << "();\n";
1393+
source << " ReplayContext" << contextId << "Frame" << frameIndex << "();\n";
13951394
source << " break;\n";
13961395
}
13971396
source << " default:\n";
@@ -1402,7 +1401,7 @@ void WriteCppReplayIndexFiles(bool compression,
14021401

14031402
if (writeResetContextCall)
14041403
{
1405-
source << "void ResetContext" << Str(static_cast<int>(contextId)) << "Replay()\n";
1404+
source << "void ResetContext" << contextId << "Replay()\n";
14061405
source << "{\n";
14071406
source << " // Reset context is empty because context is destroyed before end "
14081407
"frame is reached\n";
@@ -1412,16 +1411,16 @@ void WriteCppReplayIndexFiles(bool compression,
14121411

14131412
if (serializeStateEnabled)
14141413
{
1415-
source << "std::vector<uint8_t> GetSerializedContext" << static_cast<int>(contextId)
1416-
<< "StateData(uint32_t frameIndex)\n";
1414+
source << "const uint8_t *GetSerializedContext" << contextId
1415+
<< "State(uint32_t frameIndex)\n";
14171416
source << "{\n";
14181417
source << " switch (frameIndex)\n";
14191418
source << " {\n";
14201419
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
14211420
{
14221421
source << " case " << frameIndex << ":\n";
14231422
source << " return "
1424-
<< FmtGetSerializedContextStateDataFunction(contextId, frameIndex) << ";\n";
1423+
<< FmtGetSerializedContextStateFunction(contextId, frameIndex) << ";\n";
14251424
}
14261425
source << " default:\n";
14271426
source << " return {};\n";

src/libANGLE/State.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ bool IsTextureCompatibleWithSampler(TextureType texture, TextureType sampler)
114114
return false;
115115
}
116116

117-
int gIDCounter = 1;
117+
uint32_t gIDCounter = 1;
118118
} // namespace
119119

120120
template <typename BindingT, typename... ArgsT>
@@ -293,7 +293,7 @@ State::State(const State *shareContextState,
293293
bool robustResourceInit,
294294
bool programBinaryCacheEnabled,
295295
EGLenum contextPriority)
296-
: mID(gIDCounter++),
296+
: mID({gIDCounter++}),
297297
mClientType(clientType),
298298
mContextPriority(contextPriority),
299299
mClientVersion(clientVersion),

src/libANGLE/State.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ static constexpr Version ES_3_0 = Version(3, 0);
5959
static constexpr Version ES_3_1 = Version(3, 1);
6060
static constexpr Version ES_3_2 = Version(3, 2);
6161

62-
using ContextID = uintptr_t;
63-
6462
template <typename T>
6563
using BufferBindingMap = angle::PackedEnumMap<BufferBinding, T>;
6664
using BoundBufferMap = BufferBindingMap<BindingPointer<Buffer>>;

src/libANGLE/Texture.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,12 +1890,12 @@ bool Texture::isSamplerComplete(const Context *context, const Sampler *optionalS
18901890
}
18911891

18921892
Texture::SamplerCompletenessCache::SamplerCompletenessCache()
1893-
: context(0), samplerState(), samplerComplete(false)
1893+
: context({0}), samplerState(), samplerComplete(false)
18941894
{}
18951895

18961896
void Texture::invalidateCompletenessCache() const
18971897
{
1898-
mCompletenessCache.context = 0;
1898+
mCompletenessCache.context = {0};
18991899
}
19001900

19011901
angle::Result Texture::ensureInitialized(const Context *context)

src/libANGLE/angletypes.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,25 @@ enum class RenderToTextureImageIndex
753753
template <typename T>
754754
using RenderToTextureImageMap = angle::PackedEnumMap<RenderToTextureImageIndex, T>;
755755

756-
using ContextID = uintptr_t;
756+
struct ContextID
757+
{
758+
uint32_t value;
759+
};
760+
761+
inline bool operator==(ContextID lhs, ContextID rhs)
762+
{
763+
return lhs.value == rhs.value;
764+
}
765+
766+
inline bool operator!=(ContextID lhs, ContextID rhs)
767+
{
768+
return lhs.value != rhs.value;
769+
}
770+
771+
inline bool operator<(ContextID lhs, ContextID rhs)
772+
{
773+
return lhs.value < rhs.value;
774+
}
757775

758776
constexpr size_t kCubeFaceCount = 6;
759777

src/libANGLE/entry_points_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ constexpr ANGLE_INLINE ReturnType GetDefaultReturnValue()
100100

101101
inline int CID(const Context *context)
102102
{
103-
return context != nullptr ? static_cast<int>(context->id()) : 0;
103+
return context == nullptr ? 0 : static_cast<int>(context->id().value);
104104
}
105105
} // namespace gl
106106

src/libANGLE/renderer/gl/StateManagerGL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ StateManagerGL::StateManagerGL(const FunctionsGL *functions,
7676
mTransformFeedback(0),
7777
mCurrentTransformFeedback(nullptr),
7878
mQueries(),
79-
mPrevDrawContext(0),
79+
mPrevDrawContext({0}),
8080
mUnpackAlignment(4),
8181
mUnpackRowLength(0),
8282
mUnpackSkipRows(0),

src/tests/capture_replay_tests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
void SetupContextReplay(uint32_t test);
110110
void ReplayContextFrame(uint32_t test, uint32_t frameIndex);
111111
void ResetContextReplay(uint32_t test);
112-
std::vector<uint8_t> GetSerializedContextStateData(uint32_t test, uint32_t frameIndex);
112+
const uint8_t *GetSerializedContextState(uint32_t test, uint32_t frameIndex);
113113
void SetBinaryDataDecompressCallback(uint32_t test, DecompressCallback callback);
114114
void SetBinaryDataDir(uint32_t test, const char *dataDir);
115115
@@ -153,7 +153,7 @@
153153
{reset_context1_replay_switch_statement}
154154
}}
155155
156-
std::vector<uint8_t> GetSerializedContextStateData(uint32_t test, uint32_t frameIndex)
156+
const uint8_t *GetSerializedContextState(uint32_t test, uint32_t frameIndex)
157157
{{
158158
{get_serialized_context1_state_data_switch_statement}
159159
}}
@@ -714,7 +714,7 @@ def CreateTestsCompositeFiles(self, trace_folder_path, composite_file_id, tests)
714714
reset_context1_replay_switch_statement = WriteGeneratedSwitchStatements(
715715
tests, "ResetContextReplay", "")
716716
get_serialized_context1_state_data_switch_statement = WriteGeneratedSwitchStatements(
717-
tests, "GetSerializedContextStateData", "frameIndex", True, "{}")
717+
tests, "GetSerializedContextState", "frameIndex", True, "{}")
718718
set_binary_data_decompress_callback_switch_statement = WriteGeneratedSwitchStatements(
719719
tests, "SetBinaryDataDecompressCallback", "callback")
720720
set_binary_data_dir_switch_statement = WriteGeneratedSwitchStatements(

src/tests/capture_replay_tests/CaptureReplayTests.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class CaptureReplayTests
127127
cleanupTest();
128128
return -1;
129129
}
130-
bool isEqual = compareSerializedStates(testIndex, frame, bos);
130+
bool isEqual = compareSerializedContexts(testIndex, frame, bos.getData());
131131
if (!isEqual)
132132
{
133133
cleanupTest();
@@ -150,12 +150,14 @@ class CaptureReplayTests
150150
}
151151

152152
private:
153-
bool compareSerializedStates(uint32_t testIndex,
154-
uint32_t frame,
155-
const gl::BinaryOutputStream &replaySerializedContextData)
153+
bool compareSerializedContexts(uint32_t testIndex,
154+
uint32_t frame,
155+
const std::vector<uint8_t> &replaySerializedContextState)
156156
{
157-
return GetSerializedContextStateData(testIndex, frame) ==
158-
replaySerializedContextData.getData();
157+
158+
return memcmp(replaySerializedContextState.data(),
159+
GetSerializedContextState(testIndex, frame),
160+
replaySerializedContextState.size()) == 0;
159161
}
160162

161163
OSWindow *mOSWindow;

0 commit comments

Comments
 (0)