Commit e94c35a1 by Jamie Madill Committed by Commit Bot

Capture/Replay: Always base replays on frame "1".

No functional change. When we trigger a capture at frame X, the value of X is not important. Instead we'll record the frames as 1,2,3,etc. Helps keep the traces more consistent and re-trace the same way as they are captured. Bug: angleproject:5134 Change-Id: Icd8654d509423edcc74cd0ef694795a787f5cc05 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2500602 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com> Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com>
parent 47e66f22
...@@ -1061,8 +1061,7 @@ void WriteCppReplay(bool compression, ...@@ -1061,8 +1061,7 @@ void WriteCppReplay(bool compression,
const gl::Context *context, const gl::Context *context,
const std::string &captureLabel, const std::string &captureLabel,
uint32_t frameIndex, uint32_t frameIndex,
uint32_t frameStart, uint32_t frameCount,
uint32_t frameEnd,
const std::vector<CallCapture> &frameCalls, const std::vector<CallCapture> &frameCalls,
const std::vector<CallCapture> &setupCalls, const std::vector<CallCapture> &setupCalls,
ResourceTracker *resourceTracker, ResourceTracker *resourceTracker,
...@@ -1087,7 +1086,7 @@ void WriteCppReplay(bool compression, ...@@ -1087,7 +1086,7 @@ void WriteCppReplay(bool compression,
out << "{\n"; out << "{\n";
} }
if (frameIndex == frameStart) if (frameIndex == 1)
{ {
std::stringstream setupCallStream; std::stringstream setupCallStream;
...@@ -1103,7 +1102,7 @@ void WriteCppReplay(bool compression, ...@@ -1103,7 +1102,7 @@ void WriteCppReplay(bool compression,
out << "\n"; out << "\n";
} }
if (frameIndex == frameEnd) if (frameIndex == frameCount)
{ {
// Emit code to reset back to starting state // Emit code to reset back to starting state
out << "void " << FmtResetFunction(context->id()) << "\n"; out << "void " << FmtResetFunction(context->id()) << "\n";
...@@ -1185,8 +1184,7 @@ void WriteCppReplayIndexFiles(bool compression, ...@@ -1185,8 +1184,7 @@ void WriteCppReplayIndexFiles(bool compression,
const std::string &outDir, const std::string &outDir,
const gl::ContextID contextId, const gl::ContextID contextId,
const std::string &captureLabel, const std::string &captureLabel,
uint32_t frameStart, uint32_t frameCount,
uint32_t frameEnd,
EGLint drawSurfaceWidth, EGLint drawSurfaceWidth,
EGLint drawSurfaceHeight, EGLint drawSurfaceHeight,
size_t readBufferSize, size_t readBufferSize,
...@@ -1230,8 +1228,8 @@ void WriteCppReplayIndexFiles(bool compression, ...@@ -1230,8 +1228,8 @@ void WriteCppReplayIndexFiles(bool compression,
header << "_" << captureLabelUpper; header << "_" << captureLabelUpper;
} }
header << " " << ANGLE_REVISION << "\n"; header << " " << ANGLE_REVISION << "\n";
header << "constexpr uint32_t kReplayFrameStart = " << frameStart << ";\n"; header << "constexpr uint32_t kReplayFrameStart = 1;\n";
header << "constexpr uint32_t kReplayFrameEnd = " << frameEnd << ";\n"; header << "constexpr uint32_t kReplayFrameEnd = " << frameCount << ";\n";
header << "constexpr EGLint kReplayDrawSurfaceWidth = " << drawSurfaceWidth << ";\n"; header << "constexpr EGLint kReplayDrawSurfaceWidth = " << drawSurfaceWidth << ";\n";
header << "constexpr EGLint kReplayDrawSurfaceHeight = " << drawSurfaceHeight << ";\n"; header << "constexpr EGLint kReplayDrawSurfaceHeight = " << drawSurfaceHeight << ";\n";
header << "constexpr EGLint kDefaultFramebufferRedBits = " header << "constexpr EGLint kDefaultFramebufferRedBits = "
...@@ -1260,14 +1258,14 @@ void WriteCppReplayIndexFiles(bool compression, ...@@ -1260,14 +1258,14 @@ void WriteCppReplayIndexFiles(bool compression,
<< "StateData(uint32_t frameIndex);\n"; << "StateData(uint32_t frameIndex);\n";
} }
header << "\n"; header << "\n";
for (uint32_t frameIndex = frameStart; frameIndex <= frameEnd; ++frameIndex) for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
{ {
header << "void " << FmtReplayFunction(contextId, frameIndex) << ";\n"; header << "void " << FmtReplayFunction(contextId, frameIndex) << ";\n";
} }
header << "\n"; header << "\n";
if (serializeStateEnabled) if (serializeStateEnabled)
{ {
for (uint32_t frameIndex = frameStart; frameIndex <= frameEnd; ++frameIndex) for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
{ {
header << "std::vector<uint8_t> " header << "std::vector<uint8_t> "
<< FmtGetSerializedContextStateDataFunction(contextId, frameIndex) << ";\n"; << FmtGetSerializedContextStateDataFunction(contextId, frameIndex) << ";\n";
...@@ -1388,7 +1386,7 @@ void WriteCppReplayIndexFiles(bool compression, ...@@ -1388,7 +1386,7 @@ void WriteCppReplayIndexFiles(bool compression,
source << "{\n"; source << "{\n";
source << " switch (frameIndex)\n"; source << " switch (frameIndex)\n";
source << " {\n"; source << " {\n";
for (uint32_t frameIndex = frameStart; frameIndex <= frameEnd; ++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" << static_cast<int>(contextId) << "Frame"
...@@ -1418,7 +1416,7 @@ void WriteCppReplayIndexFiles(bool compression, ...@@ -1418,7 +1416,7 @@ void WriteCppReplayIndexFiles(bool compression,
source << "{\n"; source << "{\n";
source << " switch (frameIndex)\n"; source << " switch (frameIndex)\n";
source << " {\n"; source << " {\n";
for (uint32_t frameIndex = frameStart; frameIndex <= frameEnd; ++frameIndex) for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
{ {
source << " case " << frameIndex << ":\n"; source << " case " << frameIndex << ":\n";
source << " return " source << " return "
...@@ -1554,7 +1552,7 @@ void WriteCppReplayIndexFiles(bool compression, ...@@ -1554,7 +1552,7 @@ void WriteCppReplayIndexFiles(bool compression,
std::string indexPath = indexPathStream.str(); std::string indexPath = indexPathStream.str();
SaveFileHelper saveIndex(indexPath); SaveFileHelper saveIndex(indexPath);
for (uint32_t frameIndex = frameStart; frameIndex <= frameEnd; ++frameIndex) for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
{ {
saveIndex << GetCaptureFileName(contextId, captureLabel, frameIndex, ".cpp") << "\n"; saveIndex << GetCaptureFileName(contextId, captureLabel, frameIndex, ".cpp") << "\n";
} }
...@@ -3596,9 +3594,9 @@ FrameCapture::FrameCapture() ...@@ -3596,9 +3594,9 @@ FrameCapture::FrameCapture()
mSerializeStateEnabled(false), mSerializeStateEnabled(false),
mCompression(true), mCompression(true),
mClientVertexArrayMap{}, mClientVertexArrayMap{},
mFrameIndex(0), mFrameIndex(1),
mFrameStart(0), mCaptureStartFrame(1),
mFrameEnd(10), mCaptureEndFrame(10),
mClientArraySizes{}, mClientArraySizes{},
mReadBufferSize(0), mReadBufferSize(0),
mHasResourceType{}, mHasResourceType{},
...@@ -3635,13 +3633,13 @@ FrameCapture::FrameCapture() ...@@ -3635,13 +3633,13 @@ FrameCapture::FrameCapture()
std::string startFromEnv = angle::GetEnvironmentVar(kFrameStartVarName); std::string startFromEnv = angle::GetEnvironmentVar(kFrameStartVarName);
if (!startFromEnv.empty()) if (!startFromEnv.empty())
{ {
mFrameStart = atoi(startFromEnv.c_str()); mCaptureStartFrame = atoi(startFromEnv.c_str());
} }
std::string endFromEnv = angle::GetEnvironmentVar(kFrameEndVarName); std::string endFromEnv = angle::GetEnvironmentVar(kFrameEndVarName);
if (!endFromEnv.empty()) if (!endFromEnv.empty())
{ {
mFrameEnd = atoi(endFromEnv.c_str()); mCaptureEndFrame = atoi(endFromEnv.c_str());
} }
std::string captureTriggerFromEnv = angle::GetEnvironmentVar(kCaptureTriggerVarName); std::string captureTriggerFromEnv = angle::GetEnvironmentVar(kCaptureTriggerVarName);
...@@ -3651,10 +3649,8 @@ FrameCapture::FrameCapture() ...@@ -3651,10 +3649,8 @@ FrameCapture::FrameCapture()
// If the trigger has been populated, ignore the other frame range variables by setting them // If the trigger has been populated, ignore the other frame range variables by setting them
// to unreasonable values. This isn't perfect, but it is effective. // to unreasonable values. This isn't perfect, but it is effective.
// TODO (anglebug.com/4949): Improve this, possibly by moving away from default start frame. mCaptureStartFrame = mCaptureEndFrame = std::numeric_limits<uint32_t>::max();
mFrameStart = mFrameEnd = std::numeric_limits<uint32_t>::max(); INFO() << "Capture trigger detected, disabling capture start/end frame.";
INFO() << "Capture trigger detected, overriding mFrameStart and mFrameEnd to "
<< mFrameStart;
} }
std::string labelFromEnv = angle::GetEnvironmentVar(kCaptureLabel); std::string labelFromEnv = angle::GetEnvironmentVar(kCaptureLabel);
...@@ -3941,7 +3937,7 @@ void FrameCapture::maybeCapturePreCallUpdates(const gl::Context *context, CallCa ...@@ -3941,7 +3937,7 @@ void FrameCapture::maybeCapturePreCallUpdates(const gl::Context *context, CallCa
mBufferDataMap.erase(bufferDataInfo); mBufferDataMap.erase(bufferDataInfo);
} }
// If we're capturing, track what new buffers have been genned // If we're capturing, track what new buffers have been genned
if (mFrameIndex >= mFrameStart) if (mFrameIndex >= mCaptureStartFrame)
{ {
mResourceTracker.setDeletedBuffer(bufferIDs[i]); mResourceTracker.setDeletedBuffer(bufferIDs[i]);
} }
...@@ -3958,7 +3954,7 @@ void FrameCapture::maybeCapturePreCallUpdates(const gl::Context *context, CallCa ...@@ -3958,7 +3954,7 @@ void FrameCapture::maybeCapturePreCallUpdates(const gl::Context *context, CallCa
for (GLsizei i = 0; i < count; i++) for (GLsizei i = 0; i < count; i++)
{ {
// If we're capturing, track what new buffers have been genned // If we're capturing, track what new buffers have been genned
if (mFrameIndex >= mFrameStart) if (mFrameIndex >= mCaptureStartFrame)
{ {
mResourceTracker.setGennedBuffer(bufferIDs[i]); mResourceTracker.setGennedBuffer(bufferIDs[i]);
} }
...@@ -4351,12 +4347,12 @@ void FrameCapture::checkForCaptureTrigger() ...@@ -4351,12 +4347,12 @@ void FrameCapture::checkForCaptureTrigger()
if (captureTrigger != mCaptureTrigger) if (captureTrigger != mCaptureTrigger)
{ {
// Start mid-execution capture for the next frame // Start mid-execution capture for the next frame
mFrameStart = mFrameIndex + 1; mCaptureStartFrame = mFrameIndex + 1;
// Use the original trigger value as the frame count // Use the original trigger value as the frame count
mFrameEnd = mFrameStart + (mCaptureTrigger - 1); mCaptureEndFrame = mCaptureStartFrame + (mCaptureTrigger - 1);
INFO() << "Capture triggered at frame " << mFrameStart << " for " << mCaptureTrigger INFO() << "Capture triggered at frame " << mCaptureStartFrame << " for " << mCaptureTrigger
<< " frames"; << " frames";
// Stop polling // Stop polling
...@@ -4370,21 +4366,21 @@ void FrameCapture::onEndFrame(const gl::Context *context) ...@@ -4370,21 +4366,21 @@ void FrameCapture::onEndFrame(const gl::Context *context)
checkForCaptureTrigger(); checkForCaptureTrigger();
// Note that we currently capture before the start frame to collect shader and program sources. // Note that we currently capture before the start frame to collect shader and program sources.
if (!mFrameCalls.empty() && mFrameIndex >= mFrameStart) if (!mFrameCalls.empty() && mFrameIndex >= mCaptureStartFrame)
{ {
if (mIsFirstFrame) if (mIsFirstFrame)
{ {
mFrameStart = mFrameIndex; mCaptureStartFrame = mFrameIndex;
mIsFirstFrame = false; mIsFirstFrame = false;
} }
WriteCppReplay(mCompression, mOutDirectory, context, mCaptureLabel, mFrameIndex, WriteCppReplay(mCompression, mOutDirectory, context, mCaptureLabel, getReplayFrameIndex(),
mFrameStart, mFrameEnd, mFrameCalls, mSetupCalls, &mResourceTracker, getFrameCount(), mFrameCalls, mSetupCalls, &mResourceTracker, &mBinaryData,
&mBinaryData, mSerializeStateEnabled); mSerializeStateEnabled);
if (mFrameIndex == mFrameEnd) if (mFrameIndex == mCaptureEndFrame)
{ {
// Save the index files after the last frame. // Save the index files after the last frame.
WriteCppReplayIndexFiles( WriteCppReplayIndexFiles(
mCompression, mOutDirectory, context->id(), mCaptureLabel, mFrameStart, mFrameEnd, mCompression, mOutDirectory, context->id(), mCaptureLabel, getFrameCount(),
mDrawSurfaceWidth, mDrawSurfaceHeight, mReadBufferSize, mClientArraySizes, mDrawSurfaceWidth, mDrawSurfaceHeight, mReadBufferSize, mClientArraySizes,
mHasResourceType, mSerializeStateEnabled, false, context->getConfig(), mBinaryData); mHasResourceType, mSerializeStateEnabled, false, context->getConfig(), mBinaryData);
if (!mBinaryData.empty()) if (!mBinaryData.empty())
...@@ -4414,7 +4410,7 @@ void FrameCapture::onEndFrame(const gl::Context *context) ...@@ -4414,7 +4410,7 @@ void FrameCapture::onEndFrame(const gl::Context *context)
reset(); reset();
mFrameIndex++; mFrameIndex++;
if (enabled() && mFrameIndex == mFrameStart) if (enabled() && mFrameIndex == mCaptureStartFrame)
{ {
mSetupCalls.clear(); mSetupCalls.clear();
CaptureMidExecutionSetup(context, &mSetupCalls, &mResourceTracker, this); CaptureMidExecutionSetup(context, &mSetupCalls, &mResourceTracker, this);
...@@ -4427,15 +4423,15 @@ void FrameCapture::onDestroyContext(const gl::Context *context) ...@@ -4427,15 +4423,15 @@ void FrameCapture::onDestroyContext(const gl::Context *context)
{ {
return; return;
} }
if (!mWroteIndexFile && mFrameIndex > mFrameStart) if (!mWroteIndexFile && mFrameIndex > mCaptureStartFrame)
{ {
// If context is destroyed before end frame is reached and at least // If context is destroyed before end frame is reached and at least
// 1 frame has been recorded, then write the index files. // 1 frame has been recorded, then write the index files.
// It doesnt make sense to write the index files when no frame has been recorded // It doesnt make sense to write the index files when no frame has been recorded
mFrameIndex -= 1; mFrameIndex -= 1;
mFrameEnd = mFrameIndex; mCaptureEndFrame = mFrameIndex;
WriteCppReplayIndexFiles(mCompression, mOutDirectory, context->id(), mCaptureLabel, WriteCppReplayIndexFiles(mCompression, mOutDirectory, context->id(), mCaptureLabel,
mFrameStart, mFrameEnd, mDrawSurfaceWidth, mDrawSurfaceHeight, getFrameCount(), mDrawSurfaceWidth, mDrawSurfaceHeight,
mReadBufferSize, mClientArraySizes, mHasResourceType, mReadBufferSize, mClientArraySizes, mHasResourceType,
mSerializeStateEnabled, true, context->getConfig(), mBinaryData); mSerializeStateEnabled, true, context->getConfig(), mBinaryData);
if (!mBinaryData.empty()) if (!mBinaryData.empty())
...@@ -4567,7 +4563,17 @@ bool FrameCapture::isCapturing() const ...@@ -4567,7 +4563,17 @@ bool FrameCapture::isCapturing() const
// Currently we will always do a capture up until the last frame. In the future we could improve // Currently we will always do a capture up until the last frame. In the future we could improve
// mid execution capture by only capturing between the start and end frames. The only necessary // mid execution capture by only capturing between the start and end frames. The only necessary
// reason we need to capture before the start is for attached program and shader sources. // reason we need to capture before the start is for attached program and shader sources.
return mEnabled && mFrameIndex <= mFrameEnd; return mEnabled && mFrameIndex <= mCaptureEndFrame;
}
uint32_t FrameCapture::getFrameCount() const
{
return mCaptureEndFrame - mCaptureStartFrame + 1;
}
uint32_t FrameCapture::getReplayFrameIndex() const
{
return mFrameIndex - mCaptureStartFrame + 1;
} }
void FrameCapture::replay(gl::Context *context) void FrameCapture::replay(gl::Context *context)
......
...@@ -316,6 +316,10 @@ class FrameCapture final : angle::NonCopyable ...@@ -316,6 +316,10 @@ class FrameCapture final : angle::NonCopyable
bool isCapturing() const; bool isCapturing() const;
void replay(gl::Context *context); void replay(gl::Context *context);
uint32_t getFrameCount() const;
// Returns a frame index starting from "1" as the first frame.
uint32_t getReplayFrameIndex() const;
void trackBufferMapping(CallCapture *call, void trackBufferMapping(CallCapture *call,
gl::BufferID id, gl::BufferID id,
...@@ -356,8 +360,8 @@ class FrameCapture final : angle::NonCopyable ...@@ -356,8 +360,8 @@ class FrameCapture final : angle::NonCopyable
bool mCompression; bool mCompression;
gl::AttribArray<int> mClientVertexArrayMap; gl::AttribArray<int> mClientVertexArrayMap;
uint32_t mFrameIndex; uint32_t mFrameIndex;
uint32_t mFrameStart; uint32_t mCaptureStartFrame;
uint32_t mFrameEnd; uint32_t mCaptureEndFrame;
bool mIsFirstFrame = true; bool mIsFirstFrame = true;
bool mWroteIndexFile = false; bool mWroteIndexFile = false;
EGLint mDrawSurfaceWidth = 0; EGLint mDrawSurfaceWidth = 0;
......
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