Commit 421c665c by Gert Wollny Committed by Commit Bot

Capture: Make writeCppReplayIndexFiles a method of FrameCapture

This is useful to not pass a large amount of parameters around. Bug: angleproject:5965 Change-Id: I3890a0ca852729bbf74725fb9e5f4062e20e9158 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2894485 Commit-Queue: Gert Wollny <gert.wollny@collabora.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com>
parent 328a5c89
......@@ -1172,196 +1172,6 @@ void WriteCppReplay(bool compression,
}
}
void WriteCppReplayIndexFiles(bool compression,
const std::string &outDir,
const gl::Context *context,
const std::string &captureLabel,
uint32_t frameCount,
const SurfaceDimensions &drawSurfaceDimensions,
const HasResourceTypeMap &hasResourceType,
bool serializeStateEnabled,
bool writeResetContextCall,
std::vector<uint8_t> &binaryData)
{
const gl::ContextID contextId = context->id();
const egl::Config *config = context->getConfig();
const egl::AttributeMap &attributes = context->getDisplay()->getAttributeMap();
std::stringstream header;
std::stringstream source;
header << "#pragma once\n";
header << "\n";
header << "#include <EGL/egl.h>\n";
header << "#include <cstdint>\n";
header << "\n";
if (!captureLabel.empty())
{
header << "namespace " << captureLabel << "\n";
header << "{\n";
}
header << "// Begin Trace Metadata\n";
header << "#define ANGLE_REPLAY_VERSION";
if (!captureLabel.empty())
{
std::string captureLabelUpper = captureLabel;
angle::ToUpper(&captureLabelUpper);
header << "_" << captureLabelUpper;
}
header << " " << ANGLE_REVISION << "\n";
header << "constexpr uint32_t kReplayContextClientMajorVersion = "
<< context->getClientMajorVersion() << ";\n";
header << "constexpr uint32_t kReplayContextClientMinorVersion = "
<< context->getClientMinorVersion() << ";\n";
header << "constexpr EGLint kReplayPlatformType = "
<< attributes.getAsInt(EGL_PLATFORM_ANGLE_TYPE_ANGLE) << ";\n";
header << "constexpr EGLint kReplayDeviceType = "
<< attributes.getAsInt(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE) << ";\n";
header << "constexpr uint32_t kReplayFrameStart = 1;\n";
header << "constexpr uint32_t kReplayFrameEnd = " << frameCount << ";\n";
header << "constexpr EGLint kReplayDrawSurfaceWidth = "
<< drawSurfaceDimensions.at(contextId).width << ";\n";
header << "constexpr EGLint kReplayDrawSurfaceHeight = "
<< drawSurfaceDimensions.at(contextId).height << ";\n";
header << "constexpr EGLint kDefaultFramebufferRedBits = "
<< (config ? std::to_string(config->redSize) : "EGL_DONT_CARE") << ";\n";
header << "constexpr EGLint kDefaultFramebufferGreenBits = "
<< (config ? std::to_string(config->greenSize) : "EGL_DONT_CARE") << ";\n";
header << "constexpr EGLint kDefaultFramebufferBlueBits = "
<< (config ? std::to_string(config->blueSize) : "EGL_DONT_CARE") << ";\n";
header << "constexpr EGLint kDefaultFramebufferAlphaBits = "
<< (config ? std::to_string(config->alphaSize) : "EGL_DONT_CARE") << ";\n";
header << "constexpr EGLint kDefaultFramebufferDepthBits = "
<< (config ? std::to_string(config->depthSize) : "EGL_DONT_CARE") << ";\n";
header << "constexpr EGLint kDefaultFramebufferStencilBits = "
<< (config ? std::to_string(config->stencilSize) : "EGL_DONT_CARE") << ";\n";
header << "constexpr bool kIsBinaryDataCompressed = " << (compression ? "true" : "false")
<< ";\n";
header << "constexpr bool kAreClientArraysEnabled = "
<< (context->getState().areClientArraysEnabled() ? "true" : "false") << ";\n";
header << "constexpr bool kbindGeneratesResources = "
<< (context->getState().isBindGeneratesResourceEnabled() ? "true" : "false") << ";\n";
header << "constexpr bool kWebGLCompatibility = "
<< (context->getState().getExtensions().webglCompatibility ? "true" : "false") << ";\n";
header << "constexpr bool kRobustResourceInit = "
<< (context->getState().isRobustResourceInitEnabled() ? "true" : "false") << ";\n";
header << "// End Trace Metadata\n";
header << "\n";
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
{
header << "void " << FmtReplayFunction(contextId, frameIndex) << ";\n";
}
header << "\n";
if (serializeStateEnabled)
{
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
{
header << "const char *" << FmtGetSerializedContextStateFunction(contextId, frameIndex)
<< ";\n";
}
header << "\n";
}
source << "#include \"" << FmtCapturePrefix(contextId, captureLabel) << ".h\"\n";
source << "#include \"trace_fixture.h\"\n";
source << "\n";
if (!captureLabel.empty())
{
source << "using namespace " << captureLabel << ";\n";
source << "\n";
}
source << "extern \"C\" {\n";
source << "void ReplayFrame(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 << " " << FmtReplayFunction(contextId, frameIndex) << ";\n";
source << " break;\n";
}
source << " default:\n";
source << " break;\n";
source << " }\n";
source << "}\n";
source << "\n";
if (writeResetContextCall)
{
source << "void ResetReplay()\n";
source << "{\n";
source << " // Reset context is empty because context is destroyed before end "
"frame is reached\n";
source << "}\n";
source << "\n";
}
if (serializeStateEnabled)
{
source << "const char *GetSerializedContextState(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 << " return "
<< FmtGetSerializedContextStateFunction(contextId, frameIndex) << ";\n";
}
source << " default:\n";
source << " return \"\";\n";
source << " }\n";
source << "}\n";
source << "\n";
}
source << "} // extern \"C\"\n";
if (!captureLabel.empty())
{
header << "} // namespace " << captureLabel << "\n";
}
{
std::string headerContents = header.str();
std::stringstream headerPathStream;
headerPathStream << outDir << FmtCapturePrefix(contextId, captureLabel) << ".h";
std::string headerPath = headerPathStream.str();
SaveFileHelper saveHeader(headerPath);
saveHeader << headerContents;
}
{
std::string sourceContents = source.str();
std::stringstream sourcePathStream;
sourcePathStream << outDir << FmtCapturePrefix(contextId, captureLabel) << ".cpp";
std::string sourcePath = sourcePathStream.str();
SaveFileHelper saveSource(sourcePath);
saveSource << sourceContents;
}
{
std::stringstream indexPathStream;
indexPathStream << outDir << FmtCapturePrefix(contextId, captureLabel) << "_files.txt";
std::string indexPath = indexPathStream.str();
SaveFileHelper saveIndex(indexPath);
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
{
saveIndex << GetCaptureFileName(contextId, captureLabel, frameIndex, ".cpp") << "\n";
}
}
}
ProgramSources GetAttachedProgramSources(const gl::Program *program)
{
ProgramSources sources;
......@@ -4810,9 +4620,7 @@ void FrameCapture::onEndFrame(const gl::Context *context)
if (mFrameIndex == mCaptureEndFrame)
{
// Save the index files after the last frame.
WriteCppReplayIndexFiles(mCompression, mOutDirectory, context, mCaptureLabel,
getFrameCount(), mDrawSurfaceDimensions, mHasResourceType,
mSerializeStateEnabled, false, mBinaryData);
writeCppReplayIndexFiles(context, false);
if (!mBinaryData.empty())
{
SaveBinaryData(mCompression, mOutDirectory, context->id(), mCaptureLabel,
......@@ -4860,9 +4668,7 @@ void FrameCapture::onDestroyContext(const gl::Context *context)
// It doesnt make sense to write the index files when no frame has been recorded
mFrameIndex -= 1;
mCaptureEndFrame = mFrameIndex;
WriteCppReplayIndexFiles(mCompression, mOutDirectory, context, mCaptureLabel,
getFrameCount(), mDrawSurfaceDimensions, mHasResourceType,
mSerializeStateEnabled, true, mBinaryData);
writeCppReplayIndexFiles(context, true);
if (!mBinaryData.empty())
{
SaveBinaryData(mCompression, mOutDirectory, context->id(), mCaptureLabel, mBinaryData);
......@@ -5095,6 +4901,190 @@ void FrameCapture::replay(gl::Context *context)
}
}
void FrameCapture::writeCppReplayIndexFiles(const gl::Context *context, bool writeResetContextCall)
{
const gl::ContextID contextId = context->id();
const egl::Config *config = context->getConfig();
const egl::AttributeMap &attributes = context->getDisplay()->getAttributeMap();
unsigned frameCount = getFrameCount();
std::stringstream header;
std::stringstream source;
header << "#pragma once\n";
header << "\n";
header << "#include <EGL/egl.h>\n";
header << "#include <cstdint>\n";
header << "\n";
if (!mCaptureLabel.empty())
{
header << "namespace " << mCaptureLabel << "\n";
header << "{\n";
}
header << "// Begin Trace Metadata\n";
header << "#define ANGLE_REPLAY_VERSION";
if (!mCaptureLabel.empty())
{
std::string captureLabelUpper = mCaptureLabel;
angle::ToUpper(&captureLabelUpper);
header << "_" << captureLabelUpper;
}
header << " " << ANGLE_REVISION << "\n";
header << "constexpr uint32_t kReplayContextClientMajorVersion = "
<< context->getClientMajorVersion() << ";\n";
header << "constexpr uint32_t kReplayContextClientMinorVersion = "
<< context->getClientMinorVersion() << ";\n";
header << "constexpr EGLint kReplayPlatformType = "
<< attributes.getAsInt(EGL_PLATFORM_ANGLE_TYPE_ANGLE) << ";\n";
header << "constexpr EGLint kReplayDeviceType = "
<< attributes.getAsInt(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE) << ";\n";
header << "constexpr uint32_t kReplayFrameStart = 1;\n";
header << "constexpr uint32_t kReplayFrameEnd = " << frameCount << ";\n";
header << "constexpr EGLint kReplayDrawSurfaceWidth = "
<< mDrawSurfaceDimensions.at(contextId).width << ";\n";
header << "constexpr EGLint kReplayDrawSurfaceHeight = "
<< mDrawSurfaceDimensions.at(contextId).height << ";\n";
header << "constexpr EGLint kDefaultFramebufferRedBits = "
<< (config ? std::to_string(config->redSize) : "EGL_DONT_CARE") << ";\n";
header << "constexpr EGLint kDefaultFramebufferGreenBits = "
<< (config ? std::to_string(config->greenSize) : "EGL_DONT_CARE") << ";\n";
header << "constexpr EGLint kDefaultFramebufferBlueBits = "
<< (config ? std::to_string(config->blueSize) : "EGL_DONT_CARE") << ";\n";
header << "constexpr EGLint kDefaultFramebufferAlphaBits = "
<< (config ? std::to_string(config->alphaSize) : "EGL_DONT_CARE") << ";\n";
header << "constexpr EGLint kDefaultFramebufferDepthBits = "
<< (config ? std::to_string(config->depthSize) : "EGL_DONT_CARE") << ";\n";
header << "constexpr EGLint kDefaultFramebufferStencilBits = "
<< (config ? std::to_string(config->stencilSize) : "EGL_DONT_CARE") << ";\n";
header << "constexpr bool kIsBinaryDataCompressed = " << (mCompression ? "true" : "false")
<< ";\n";
header << "constexpr bool kAreClientArraysEnabled = "
<< (context->getState().areClientArraysEnabled() ? "true" : "false") << ";\n";
header << "constexpr bool kbindGeneratesResources = "
<< (context->getState().isBindGeneratesResourceEnabled() ? "true" : "false") << ";\n";
header << "constexpr bool kWebGLCompatibility = "
<< (context->getState().getExtensions().webglCompatibility ? "true" : "false") << ";\n";
header << "constexpr bool kRobustResourceInit = "
<< (context->getState().isRobustResourceInitEnabled() ? "true" : "false") << ";\n";
header << "// End Trace Metadata\n";
header << "\n";
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
{
header << "void " << FmtReplayFunction(contextId, frameIndex) << ";\n";
}
header << "\n";
if (mSerializeStateEnabled)
{
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
{
header << "const char *" << FmtGetSerializedContextStateFunction(contextId, frameIndex)
<< ";\n";
}
header << "\n";
}
source << "#include \"" << FmtCapturePrefix(contextId, mCaptureLabel) << ".h\"\n";
source << "#include \"trace_fixture.h\"\n";
source << "\n";
if (!mCaptureLabel.empty())
{
source << "using namespace " << mCaptureLabel << ";\n";
source << "\n";
}
source << "extern \"C\" {\n";
source << "void ReplayFrame(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 << " " << FmtReplayFunction(contextId, frameIndex) << ";\n";
source << " break;\n";
}
source << " default:\n";
source << " break;\n";
source << " }\n";
source << "}\n";
source << "\n";
if (writeResetContextCall)
{
source << "void ResetReplay()\n";
source << "{\n";
source << " // Reset context is empty because context is destroyed before end "
"frame is reached\n";
source << "}\n";
source << "\n";
}
if (mSerializeStateEnabled)
{
source << "const char *GetSerializedContextState(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 << " return "
<< FmtGetSerializedContextStateFunction(contextId, frameIndex) << ";\n";
}
source << " default:\n";
source << " return \"\";\n";
source << " }\n";
source << "}\n";
source << "\n";
}
source << "} // extern \"C\"\n";
if (!mCaptureLabel.empty())
{
header << "} // namespace " << mCaptureLabel << "\n";
}
{
std::string headerContents = header.str();
std::stringstream headerPathStream;
headerPathStream << mOutDirectory << FmtCapturePrefix(contextId, mCaptureLabel) << ".h";
std::string headerPath = headerPathStream.str();
SaveFileHelper saveHeader(headerPath);
saveHeader << headerContents;
}
{
std::string sourceContents = source.str();
std::stringstream sourcePathStream;
sourcePathStream << mOutDirectory << FmtCapturePrefix(contextId, mCaptureLabel) << ".cpp";
std::string sourcePath = sourcePathStream.str();
SaveFileHelper saveSource(sourcePath);
saveSource << sourceContents;
}
{
std::stringstream indexPathStream;
indexPathStream << mOutDirectory << FmtCapturePrefix(contextId, mCaptureLabel)
<< "_files.txt";
std::string indexPath = indexPathStream.str();
SaveFileHelper saveIndex(indexPath);
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
{
saveIndex << GetCaptureFileName(contextId, mCaptureLabel, frameIndex, ".cpp") << "\n";
}
}
}
void FrameCapture::reset()
{
mFrameCalls.clear();
......
......@@ -370,6 +370,8 @@ class FrameCapture final : angle::NonCopyable
ResourceTracker &getResouceTracker() { return mResourceTracker; }
private:
void writeCppReplayIndexFiles(const gl::Context *, bool writeResetContextCall);
void captureClientArraySnapshot(const gl::Context *context,
size_t vertexCount,
size_t instanceCount);
......
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