Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow adding debug annotations to OpenGL objects, as well as defining GPU "zones" to achieve functionality very similar to Tracy, but on the GPU. #1845

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Beherith
Copy link
Contributor

@Beherith Beherith commented Dec 21, 2024

Implements #1833

Assists in assigning OpenGL id's to actual human readable names in performance debuggging.

IMPORTANT nVidia nSight 2022.04 was the only version that reliably worked for me.

New callouts:

  • gl.ObjectLabel(objectTypeIdentifier, objectID, name)

    • Allows marking of buffers and shaders (and textures and pretty much anything else) with a label that is visible in GL call stacks.
  • gl.PushDebugGroup(objectID, name, bool thirdparty = false)

    • To be used just like tracy.ZoneBeginN(name)
  • gl.PopDebugGroup()

    • counterpart of tracy.ZoneEnd()

Results, with only some minor modifications to LuaShader.lua to label, push and pop things:

image

@Beherith
Copy link
Contributor Author

Companion game PR is: beyond-all-reason/Beyond-All-Reason#4054

Comment on lines +5678 to +5684
GLenum identifier = (GLenum)luaL_checkinteger(L, 1);
if (identifier != GL_BUFFER && identifier != GL_SHADER && identifier != GL_PROGRAM &&
identifier != GL_VERTEX_ARRAY && identifier != GL_QUERY && identifier != GL_PROGRAM_PIPELINE &&
identifier != GL_TRANSFORM_FEEDBACK && identifier != GL_TEXTURE && identifier != GL_RENDERBUFFER &&
identifier != GL_FRAMEBUFFER) {
return 0;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this snippet in the gameside PR:

local GL_PROGRAM = 0x82E2
gl.ObjectLabel(GL_PROGRAM, gl_program_id, self.shaderName)

Sounds bad if the game needs to know those magic 0x82E2 constants to use the function. Would be good if there were either appropriate named constants in LuaConstGL.cpp (GL.PROGRAM etc) or if this accepted a string ("program" etc).

glGetIntegerv(GL_MAX_DEBUG_MESSAGE_LENGTH, &maxLength);

if (strlen(message) >= maxLength) {
luaL_error(L, "Message length exceeds GL_MAX_DEBUG_MESSAGE_LENGTH");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps just trim the message to the appropriate length? Otherwise a portable way of preventing this error (GL.MAX_DEBUG_MESSAGE_LENGTH lua constant?) would be nice.

Comment on lines +5690 to +5691
// Check that the GLuint name refers to a valid openGL object
// Check that the label is a valid string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these "check this, check that" comments mean that the code is WIP and those checks should be added?

@@ -64,7 +64,8 @@ bool LuaVBOs::PushEntries(lua_State* L)
"UnbindBufferRange", &LuaVBOImpl::UnbindBufferRange,

"DumpDefinition", &LuaVBOImpl::DumpDefinition,
"GetBufferSize", &LuaVBOImpl::GetBufferSize
"GetBufferSize", &LuaVBOImpl::GetBufferSize,
"GetID", &LuaVBOImpl::GetID
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if there were getters for every relevant object type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants