-
Notifications
You must be signed in to change notification settings - Fork 104
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -471,6 +471,11 @@ bool LuaOpenGL::PushEntries(lua_State* L) | |
REGISTER_LUA_CFUNC(GetWaterRendering); | ||
REGISTER_LUA_CFUNC(GetMapRendering); | ||
|
||
|
||
REGISTER_LUA_CFUNC(ObjectLabel); | ||
REGISTER_LUA_CFUNC(PushDebugGroup); | ||
REGISTER_LUA_CFUNC(PopDebugGroup); | ||
|
||
if (canUseShaders) | ||
LuaShaders::PushEntries(L); | ||
|
||
|
@@ -5661,5 +5666,69 @@ int LuaOpenGL::GetMapRendering(lua_State* L) | |
return 0; | ||
} | ||
|
||
|
||
/** | ||
* @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. | ||
* @treturn nil | ||
*/ | ||
int LuaOpenGL::ObjectLabel(lua_State* L) { | ||
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; | ||
} | ||
GLuint objectID = (GLuint)luaL_checkinteger(L, 2); | ||
const char* label = luaL_checkstring(L, 3); | ||
|
||
// Ensure that identifier is a valid GLenum | ||
// The length should be passed as -1 because the strings are null terminated | ||
// Check that the GLuint name refers to a valid openGL object | ||
// Check that the label is a valid string | ||
Comment on lines
+5690
to
+5691
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
glObjectLabel(identifier, objectID, -1, label); | ||
|
||
return 0; | ||
} | ||
|
||
|
||
// https://registry.khronos.org/OpenGL-Refpages/gl4/html/glPushDebugGroup.xhtml | ||
/** | ||
* @function gl.PushDebugGroup pushes a debug marker for nVidia nSight 2024.04, does not seem to work when FBO's are raw bound | ||
* @param id GLuint A numeric identifier for the group. | ||
* @param message string A human-readable string describing the debug group. | ||
* @param source boolean true for GL_DEBUG_SOURCE_APPLICATION, false for GL_DEBUG_SOURCE_THIRD_PARTY. default false | ||
* @treturn nil | ||
*/ | ||
int LuaOpenGL::PushDebugGroup(lua_State* L) { | ||
GLuint id = (GLuint)luaL_checkinteger(L, 1); | ||
const char* message = luaL_checkstring(L, 2); | ||
bool source = luaL_optboolean(L, 3, false); | ||
|
||
GLint maxLength; | ||
glGetIntegerv(GL_MAX_DEBUG_MESSAGE_LENGTH, &maxLength); | ||
|
||
if (strlen(message) >= maxLength) { | ||
luaL_error(L, "Message length exceeds GL_MAX_DEBUG_MESSAGE_LENGTH"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ( |
||
return 0; | ||
} | ||
|
||
glPushDebugGroup((source ? GL_DEBUG_SOURCE_APPLICATION: GL_DEBUG_SOURCE_THIRD_PARTY) , id, -1, message); | ||
|
||
return 0; | ||
} | ||
|
||
/** | ||
* @function gl.PopDebugGroup | ||
* @treturn nil | ||
*/ | ||
int LuaOpenGL::PopDebugGroup(lua_State* L) { | ||
glPopDebugGroup(); | ||
return 0; | ||
} | ||
|
||
/******************************************************************************/ | ||
/******************************************************************************/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice if there were getters for every relevant object type. |
||
); | ||
|
||
gl.set("VBO", sol::lua_nil); // don't want this to be accessible directly without gl.GetVBO | ||
|
There was a problem hiding this comment.
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:
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 inLuaConstGL.cpp
(GL.PROGRAM
etc) or if this accepted a string ("program" etc).