Skip to content

Commit

Permalink
Capture/Replay: Write comments to the capture
Browse files Browse the repository at this point in the history
Useful for tracking why things are happening in the frame, from the
perspective of the tracer.

Allows for entries like this:

    // DEBUG: AttachShader called, checking for IDs;
    glAttachShader(gShaderProgramMap2[6943], gShaderProgramMap2[1531]);
    // DEBUG: AttachShader called, checking for IDs;
    glAttachShader(gShaderProgramMap2[6943], gShaderProgramMap2[1511]);

Good for debugging or knowing we've skipped invalid/unsupported calls.

This CL includes one use of comments to mark calls we've skipped,
meaning the app or ANGLE submitted them, but omitted from capture.

Bug: angleproject:345851268
Change-Id: Ied917c7480704afc3fdfb8cbb617b323eb7403a5
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3233876
Reviewed-by: Mark Łobodziński <[email protected]>
Commit-Queue: Cody Northrop <[email protected]>
Reviewed-by: Roman Lavrov <[email protected]>
  • Loading branch information
cnorthrop authored and Angle LUCI CQ committed Jun 18, 2024
1 parent aeff80f commit 1917377
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/libANGLE/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10128,6 +10128,19 @@ GLenum ErrorSet::getGraphicsResetStatus(rx::ContextImpl *contextImpl)
return ToGLenum(mResetStatus);
}

GLenum ErrorSet::getErrorForCapture() const
{
if (mErrors.empty())
{
return GL_NO_ERROR;
}
else
{
// Return the error without clearing it
return *mErrors.begin();
}
}

// StateCache implementation.
StateCache::StateCache()
: mCachedNonInstancedVertexElementLimit(0),
Expand Down
2 changes: 2 additions & 0 deletions src/libANGLE/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class ErrorSet : angle::NonCopyable
bool isContextLost() const { return mContextLost.load(std::memory_order_relaxed) != 0; }
GLenum getGraphicsResetStatus(rx::ContextImpl *contextImpl);
GLenum getResetStrategy() const { return mResetStrategy; }
GLenum getErrorForCapture() const;

private:
void setContextLost();
Expand Down Expand Up @@ -781,6 +782,7 @@ class Context final : public egl::LabeledObject, angle::NonCopyable, public angl
{
return mTransformFeedbackMap;
}
GLenum getErrorForCapture() const { return mErrors.getErrorForCapture(); }

void onPreSwap();

Expand Down
36 changes: 36 additions & 0 deletions src/libANGLE/capture/FrameCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,13 +812,33 @@ void WriteBinaryParamReplay(ReplayWriter &replayWriter,
}
}

void WriteComment(std::ostream &out, const CallCapture &call)
{
// Read the string parameter
const ParamCapture &stringParam =
call.params.getParam("comment", ParamType::TGLcharConstPointer, 0);
const std::vector<uint8_t> &data = stringParam.data[0];
ASSERT(data.size() > 0 && data.back() == '\0');
std::string str(data.begin(), data.end() - 1);

// Write the string prefixed with single line comment
out << "// " << str;
}

void WriteCppReplayForCall(const CallCapture &call,
ReplayWriter &replayWriter,
std::ostream &out,
std::ostream &header,
std::vector<uint8_t> *binaryData,
size_t *maxResourceIDBufferSize)
{
if (call.customFunctionName == "Comment")
{
// Just write it directly to the file and move on
WriteComment(out, call);
return;
}

std::ostringstream callOut;

callOut << call.name() << "(";
Expand Down Expand Up @@ -945,6 +965,16 @@ void WriteCppReplayForCall(const CallCapture &call,
out << callOut.str();
}

void AddComment(std::vector<CallCapture> *outCalls, const std::string &comment)
{

ParamBuffer commentParamBuffer;
ParamCapture commentParam("comment", ParamType::TGLcharConstPointer);
CaptureString(comment.c_str(), &commentParam);
commentParamBuffer.addParam(std::move(commentParam));
outCalls->emplace_back("Comment", std::move(commentParamBuffer));
}

size_t MaxClientArraySize(const gl::AttribArray<size_t> &clientArraySizes)
{
size_t found = 0;
Expand Down Expand Up @@ -8398,6 +8428,12 @@ void FrameCaptureShared::captureCall(gl::Context *context, CallCapture &&inCall,
}
INFO() << msg.str();
}

std::stringstream skipCall;
skipCall << "Skipping invalid call to " << GetEntryPointName(inCall.entryPoint)
<< " with error: "
<< gl::GLenumToString(gl::GLESEnum::ErrorCode, context->getErrorForCapture());
AddComment(&mFrameCalls, skipCall.str());
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/tests/capture_tests/CapturedTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,13 @@ void CapturedTest::frame4()
// Draw shaders & program created before capture
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
EXPECT_PIXEL_EQ(108, 108, 0, 0, 255, 255);

// Add an invalid call so it shows up in capture as a comment.
// This is unrelated to the rest of the frame, but needs a home.
GLuint nonExistentBinding = 666;
GLuint nonExistentTexture = 777;
glBindTexture(nonExistentBinding, nonExistentTexture);
glGetError();
}

// Test captured by capture_tests.py
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"TraceMetadata": {
"AreClientArraysEnabled": true,
"CaptureRevision": 22823,
"CaptureRevision": 23284,
"ConfigAlphaBits": 8,
"ConfigBlueBits": 8,
"ConfigDepthBits": 24,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ void ReplayFrame4(void)
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, (const GLubyte *)&gBinaryData[608]);
glReadPixels(108, 108, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void *)gReadBuffer);
glGetError();
// Skipping invalid call to glBindTexture with error: GL_INVALID_ENUM;
glGetError();
}

// Public Functions
Expand Down

0 comments on commit 1917377

Please sign in to comment.