[Impeller] Add OpenGL debugging utilities. (flutter/engine#56515)

* CheckFramebufferStatus needs to be called with the enum for the target type and not the target itself.
* Fix dumping the framebuffer type and object name.

The results should be the following for the default FBO0.
```
[IMPORTANT:flutter/impeller/renderer/backend/gles/render_pass_gles.cc(281)] The default framebuffer (FBO0) was bound.
```

and the following for an offscreen framebuffer:
```
[IMPORTANT:flutter/impeller/renderer/backend/gles/render_pass_gles.cc(281)] The default framebuffer (FBO0) was bound.
[IMPORTANT:flutter/impeller/renderer/backend/gles/render_pass_gles.cc(281)] FBO 1: GL_FRAMEBUFFER_COMPLETE
Framebuffer is complete.
Description: 
Color Attachment: GL_TEXTURE(5)
Depth Attachment: GL_RENDERBUFFER(1)
Stencil Attachment: GL_RENDERBUFFER(1)

```

cc @lyceel
This commit is contained in:
Chinmay Garde
2024-11-11 20:58:26 -08:00
committed by GitHub
parent 99c0b7b50d
commit e6c61d2570
2 changed files with 53 additions and 11 deletions

View File

@@ -9,6 +9,7 @@
#include "fml/closure.h"
#include "impeller/base/allocation.h"
#include "impeller/base/comparable.h"
#include "impeller/base/strings.h"
#include "impeller/base/validation.h"
#include "impeller/renderer/backend/gles/capabilities_gles.h"
#include "impeller/renderer/capabilities.h"
@@ -241,24 +242,24 @@ static const char* AttachmentTypeString(GLint type) {
static std::string DescribeFramebufferAttachment(const ProcTableGLES& gl,
GLenum attachment) {
GLint param = GL_NONE;
GLint type = GL_NONE;
gl.GetFramebufferAttachmentParameteriv(
GL_FRAMEBUFFER, // target
attachment, // attachment
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, // parameter name
&param // parameter
&type // parameter
);
if (param != GL_NONE) {
param = GL_NONE;
if (type != GL_NONE) {
GLint object = GL_NONE;
gl.GetFramebufferAttachmentParameteriv(
GL_FRAMEBUFFER, // target
attachment, // attachment
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, // parameter name
&param // parameter
&object // parameter
);
std::stringstream stream;
stream << AttachmentTypeString(param) << "(" << param << ")";
stream << AttachmentTypeString(type) << "(" << object << ")";
return stream.str();
}
@@ -268,11 +269,15 @@ static std::string DescribeFramebufferAttachment(const ProcTableGLES& gl,
std::string ProcTableGLES::DescribeCurrentFramebuffer() const {
GLint framebuffer = GL_NONE;
GetIntegerv(GL_FRAMEBUFFER_BINDING, &framebuffer);
if (framebuffer == GL_NONE) {
return "The default framebuffer (FBO0) was bound.";
}
if (IsFramebuffer(framebuffer) == GL_FALSE) {
return "No framebuffer or the default window framebuffer is bound.";
return SPrintF("The framebuffer binding (%d) was not a valid framebuffer.",
framebuffer);
}
GLenum status = CheckFramebufferStatus(framebuffer);
GLenum status = CheckFramebufferStatus(GL_FRAMEBUFFER);
std::stringstream stream;
stream << "FBO "
<< ((framebuffer == GL_NONE) ? "(Default)"
@@ -287,10 +292,10 @@ std::string ProcTableGLES::DescribeCurrentFramebuffer() const {
stream << "Color Attachment: "
<< DescribeFramebufferAttachment(*this, GL_COLOR_ATTACHMENT0)
<< std::endl;
stream << "Color Attachment: "
stream << "Depth Attachment: "
<< DescribeFramebufferAttachment(*this, GL_DEPTH_ATTACHMENT)
<< std::endl;
stream << "Color Attachment: "
stream << "Stencil Attachment: "
<< DescribeFramebufferAttachment(*this, GL_STENCIL_ATTACHMENT)
<< std::endl;
return stream.str();
@@ -303,7 +308,7 @@ bool ProcTableGLES::IsCurrentFramebufferComplete() const {
// The default framebuffer is always complete.
return true;
}
GLenum status = CheckFramebufferStatus(framebuffer);
GLenum status = CheckFramebufferStatus(GL_FRAMEBUFFER);
return status == GL_FRAMEBUFFER_COMPLETE;
}

View File

@@ -45,6 +45,31 @@ struct AutoErrorCheck {
}
};
template <class Type>
void BuildGLArgumentsStream(std::stringstream& stream, Type arg) {
stream << arg;
}
constexpr void BuildGLArgumentsStream(std::stringstream& stream) {}
template <class Type, class... Rest>
void BuildGLArgumentsStream(std::stringstream& stream,
Type arg,
Rest... other_args) {
BuildGLArgumentsStream(stream, arg);
stream << ", ";
BuildGLArgumentsStream(stream, other_args...);
}
template <class... Type>
[[nodiscard]] std::string BuildGLArguments(Type... args) {
std::stringstream stream;
stream << "(";
BuildGLArgumentsStream(stream, args...);
stream << ")";
return stream.str();
}
template <class T>
struct GLProc {
using GLFunctionType = T;
@@ -66,6 +91,14 @@ struct GLProc {
///
PFNGLGETERRORPROC error_fn = nullptr;
//----------------------------------------------------------------------------
/// Whether the OpenGL call and its arguments should be logged.
///
/// Only works in IMPELLER_DEBUG and for environments where traditional
/// tracing is hard. Expect log spam and only use during development.
///
bool log_calls = false;
//----------------------------------------------------------------------------
/// @brief Call the GL function with the appropriate parameters. Lookup
/// the documentation for the GL function being called to
@@ -81,6 +114,10 @@ struct GLProc {
// validation log will at least give us a hint as to what's going on.
FML_CHECK(IsAvailable()) << "GL function " << name << " is not available. "
<< "This is likely due to a missing extension.";
if (log_calls) {
FML_LOG(IMPORTANT) << name
<< BuildGLArguments(std::forward<Args>(args)...);
}
#endif // defined(IMPELLER_DEBUG) && !defined(NDEBUG)
return function(std::forward<Args>(args)...);
}