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

Closed
wants to merge 11 commits into 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

rts/Lua/LuaOpenGL.cpp Outdated Show resolved Hide resolved
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.

Copy link
Contributor Author

@Beherith Beherith Jan 15, 2025

Choose a reason for hiding this comment

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

GL.MAX_DEBUG_MESSAGE_LENGTH is openGL driver specific, and its quite long, and this is for functionality that only a handful of developers will ever use

Copy link
Collaborator

Choose a reason for hiding this comment

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

Being driver specific is exactly why failures should be graceful though.

rts/Lua/LuaOpenGL.cpp Outdated Show resolved Hide resolved
rts/Lua/LuaVBO.cpp Show resolved Hide resolved
@Beherith
Copy link
Contributor Author

Issues resolved, ready for merge

@lhog
Copy link
Collaborator

lhog commented Jan 18, 2025

Unsure....
It doesn't compile and my comments seem to not have been addressed.

@Beherith
Copy link
Contributor Author

Unsure.... It doesn't compile and my comments seem to not have been addressed.

Please remind me of your comments, I have forgotten them :(

@lhog
Copy link
Collaborator

lhog commented Jan 23, 2025

Unsure.... It doesn't compile and my comments seem to not have been addressed.

Please remind me of your comments, I have forgotten them :(

Basically guard injection of these functions into Lua space by checking for presence of GLEW_KHR_debug
Otherwise any call to these functions without GLEW_KHR_debug support is a nullptr exception.

rts/Lua/LuaOpenGL.cpp Outdated Show resolved Hide resolved
* @function gl.ObjectLabel labels an object for use with debugging tools
* @param objectTypeIdentifier GLenum Specifies the type of object being labeled.
* @param objectID GLuint Specifies the name or ID of the object to label.
* @param label string A null-terminated string containing the label to be assigned to the object.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Aren't Lua strings null terminated by default? Sounds redundant.

@@ -44,6 +45,7 @@ namespace springproc {
cores. */
int GetNumPhysicalCores() const { return numPhysicalCores; }
int GetNumLogicalCores() const { return numLogicalCores; }
std::string GetCPUBrand() const { return cpuid_brand; }
Copy link
Collaborator

@sprunk sprunk Feb 3, 2025

Choose a reason for hiding this comment

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

  1. looks unrelated to OpenGL driver debug messages (it looks ok so I don't mind that much, but maybe it's accidental part of some larger CPU related WIP?)
  2. perhaps would be good if it was a const reference? It doesn't look like something that would need copying by default and it's in a singleton so there's no worry about lifetime.

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.

Being driver specific is exactly why failures should be graceful though.

Comment on lines 5718 to 5723
if (GLEW_KHR_debug){
glPushDebugGroup((source ? GL_DEBUG_SOURCE_APPLICATION: GL_DEBUG_SOURCE_THIRD_PARTY) , id, -1, message);
}
else {
luaL_error(L, "PushDebugGroup requires GL_KHR_debug extension");
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as bd6c8c4

Suggested change
if (GLEW_KHR_debug){
glPushDebugGroup((source ? GL_DEBUG_SOURCE_APPLICATION: GL_DEBUG_SOURCE_THIRD_PARTY) , id, -1, message);
}
else {
luaL_error(L, "PushDebugGroup requires GL_KHR_debug extension");
}
if (!GLEW_KHR_debug)
return 0;
glPushDebugGroup((source ? GL_DEBUG_SOURCE_APPLICATION: GL_DEBUG_SOURCE_THIRD_PARTY) , id, -1, message);

@lhog
Copy link
Collaborator

lhog commented Feb 7, 2025

I'm going to redo this one. Because of multiple changes happened to master it's really hard to rebase it.

@lhog lhog closed this Feb 7, 2025
@lhog lhog reopened this Feb 7, 2025
@lhog
Copy link
Collaborator

lhog commented Feb 7, 2025

#1930

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.

3 participants