From 6911e7a873ea11a19e11cb71ed0f7c57bff46c57 Mon Sep 17 00:00:00 2001 From: Beherith Date: Thu, 19 Dec 2024 17:16:42 +0100 Subject: [PATCH 1/8] objectlabel and debug groups --- rts/Lua/LuaOpenGL.cpp | 157 +++++++++++++++++++++++++++++++++ rts/Lua/LuaOpenGL.h | 4 + rts/lib/headlessStubs/glstub.c | 4 + 3 files changed, 165 insertions(+) diff --git a/rts/Lua/LuaOpenGL.cpp b/rts/Lua/LuaOpenGL.cpp index b5dd9c979c..b1e3f2c54b 100644 --- a/rts/Lua/LuaOpenGL.cpp +++ b/rts/Lua/LuaOpenGL.cpp @@ -5661,5 +5661,162 @@ int LuaOpenGL::GetMapRendering(lua_State* L) return 0; } + + +/* +void glObjectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label); +Parameters + + identifier: + Specifies the type of object being labeled. Possible values include: + GL_BUFFER: Buffer object. + GL_SHADER: Shader object. + GL_PROGRAM: Program object. + GL_VERTEX_ARRAY: Vertex array object (VAO). + GL_QUERY: Query object. + GL_PROGRAM_PIPELINE: Program pipeline object. + GL_TRANSFORM_FEEDBACK: Transform feedback object. + GL_TEXTURE: Texture object. + GL_RENDERBUFFER: Renderbuffer object. + GL_FRAMEBUFFER: Framebuffer object. + + name: + Specifies the name or ID of the object to label (e.g., the result of glGenBuffers, glCreateShader, etc.). + + length: + Specifies the length of the label string. If -1, the function treats the string as null-terminated. + + label: + A null-terminated string containing the label to be assigned to the object. + +Notes + + Length Handling: + If you provide -1 as the length, OpenGL assumes the label is null-terminated. + Otherwise, you must specify the exact length of the label string. + + Debugging Tools: + The label appears in OpenGL debug outputs and tools like RenderDoc, Nsight, or apitrace. + This makes it easier to trace operations and diagnose issues related to specific OpenGL objects. + + Portability: + Supported in OpenGL 4.3 and later. + Also available with the KHR_debug extension in earlier versions of OpenGL (if supported). + */ +// 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 +// Write a a docstring as well as a comment +// Write a lua interface for this function: +// void glObjectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label); + +/** + * @function gl.ObjectLabel + * @param identifier GLenum Specifies the type of object being labeled. + * @param name 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); + GLuint name = (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 + glObjectLabel(identifier, name, -1, label); + + return 0; +} + +/* + +`glPushDebugGroup` is a function in the OpenGL API that helps developers debug and profile OpenGL applications. It is part of the `KHR_debug` extension, which is integrated into the core OpenGL since version 4.3. + +### Purpose +`glPushDebugGroup` allows you to group a set of OpenGL commands into a named debug group. This helps in identifying and organizing sections of code in the debug output, making it easier to diagnose and analyze rendering issues. + +### Function Prototype +```c +void glPushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message); +``` + +### Parameters +1. **`source`**: Specifies the source of the debug group. Common values include: + - `GL_DEBUG_SOURCE_APPLICATION`: Indicates that the debug group is defined by the application. + - `GL_DEBUG_SOURCE_THIRD_PARTY`: Indicates that the group is defined by external tools or libraries. + +2. **`id`**: A numeric identifier for the group. This can be any value that uniquely identifies the group within the scope of the source. + +3. **`length`**: The length of the `message` string. If this is `-1`, the string is assumed to be null-terminated. + +4. **`message`**: A human-readable string describing the debug group. This message is used in debugging tools or logs. + +### Example Usage +```c +glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 1, -1, "Render Scene"); + +// OpenGL commands for rendering the scene +glDrawArrays(GL_TRIANGLES, 0, 36); +glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); + +glPopDebugGroup(); // End of the debug group +``` + +### Notes +- Each `glPushDebugGroup` must be matched with a corresponding `glPopDebugGroup`. +- The function adds a new debug group to the debug output stack. Groups can be nested for better organization. +- Debug groups are particularly useful when analyzing rendering performance or diagnosing errors in tools like OpenGL Debug Output or profilers. + +### Benefits +1. **Organized Debugging**: Clearly marks and groups commands for easier traceability. +2. **Better Profiling**: Tools can provide insights into specific debug groups. +3. **Improved Diagnostics**: Helps isolate and identify problematic sections of code. + +### Availability +- OpenGL 4.3 or later. +- Requires the `KHR_debug` extension in earlier versions of OpenGL (if supported). + +By using `glPushDebugGroup`, you can make debugging and profiling OpenGL applications much more structured and efficient. + +Write the lua interfaces for glPushDebugGroup and glPopDebugGroup + */ + +// 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 +// Write a a docstring as well as a comment +// Write a lua interface for this function: + +/** + * @function gl.PushDebugGroup + * @param source GLenum Specifies the source of the debug group. + * @param id GLuint A numeric identifier for the group. + * @param message string A human-readable string describing the debug group. + * @treturn nil + */ +int LuaOpenGL::PushDebugGroup(lua_State* L) { + GLenum source = (GLenum)luaL_checkinteger(L, 1); + GLuint id = (GLuint)luaL_checkinteger(L, 2); + const char* message = luaL_checkstring(L, 3); + + glPushDebugGroup(source, id, -1, message); + + return 0; +} + +/** + * @function gl.PopDebugGroup + * @treturn nil + */ +int LuaOpenGL::PopDebugGroup(lua_State* L) { + glPopDebugGroup(); + return 0; +} + /******************************************************************************/ /******************************************************************************/ diff --git a/rts/Lua/LuaOpenGL.h b/rts/Lua/LuaOpenGL.h index 8a9630f84c..5bd03a0f69 100644 --- a/rts/Lua/LuaOpenGL.h +++ b/rts/Lua/LuaOpenGL.h @@ -353,6 +353,10 @@ class LuaOpenGL { static int GetSun(lua_State* L); static int GetWaterRendering(lua_State* L); static int GetMapRendering(lua_State* L); + + static int ObjectLabel(lua_State* L); + static int PushDebugGroup(lua_State* L); + static int PopDebugGroup(lua_State* L); }; inline void LuaOpenGL::InitMatrixState(lua_State* L, const char* fn) { diff --git a/rts/lib/headlessStubs/glstub.c b/rts/lib/headlessStubs/glstub.c index e1e3820264..b7b716b297 100644 --- a/rts/lib/headlessStubs/glstub.c +++ b/rts/lib/headlessStubs/glstub.c @@ -605,6 +605,10 @@ GLAPI void APIENTRY glDepthRange(GLdouble nearVal, GLdouble farVal) {} GLAPI void APIENTRY glBeginConditionalRender(GLuint id, GLenum mode) {} GLAPI void APIENTRY glEndConditionalRender(void) {} +GLAPI void APIENTRY glObjectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label) {} +GLAPI void APIENTRY glPushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message) {} +GLAPI void APIENTRY glPopDebugGroup() {} + #ifdef __cplusplus } // extern "C" #endif From 154082728d9c2c25a0f549544023a586419ca3ef Mon Sep 17 00:00:00 2001 From: Beherith Date: Thu, 19 Dec 2024 17:17:40 +0100 Subject: [PATCH 2/8] marginally better error handling --- rts/Lua/LuaOpenGL.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/rts/Lua/LuaOpenGL.cpp b/rts/Lua/LuaOpenGL.cpp index b1e3f2c54b..f352e12967 100644 --- a/rts/Lua/LuaOpenGL.cpp +++ b/rts/Lua/LuaOpenGL.cpp @@ -5791,7 +5791,7 @@ Write the lua interfaces for glPushDebugGroup and glPopDebugGroup // Check that the label is a valid string // Write a a docstring as well as a comment // Write a lua interface for this function: - +// https://registry.khronos.org/OpenGL-Refpages/gl4/html/glPushDebugGroup.xhtml /** * @function gl.PushDebugGroup * @param source GLenum Specifies the source of the debug group. @@ -5800,13 +5800,26 @@ Write the lua interfaces for glPushDebugGroup and glPopDebugGroup * @treturn nil */ int LuaOpenGL::PushDebugGroup(lua_State* L) { - GLenum source = (GLenum)luaL_checkinteger(L, 1); - GLuint id = (GLuint)luaL_checkinteger(L, 2); - const char* message = luaL_checkstring(L, 3); + GLenum source = (GLenum)luaL_checkinteger(L, 1); + GLuint id = (GLuint)luaL_checkinteger(L, 2); + const char* message = luaL_checkstring(L, 3); - glPushDebugGroup(source, id, -1, message); + if (source != GL_DEBUG_SOURCE_APPLICATION && source != GL_DEBUG_SOURCE_THIRD_PARTY) { + luaL_error(L, "Invalid source value for gl.PushDebugGroup"); + return 0; + } - return 0; + GLint maxLength; + glGetIntegerv(GL_MAX_DEBUG_MESSAGE_LENGTH, &maxLength); + + if (strlen(message) >= maxLength) { + luaL_error(L, "Message length exceeds GL_MAX_DEBUG_MESSAGE_LENGTH"); + return 0; + } + + glPushDebugGroup(source, id, -1, message); + + return 0; } /** From 8bd8e301eac68155e21a83c571ad5ff5b998ea70 Mon Sep 17 00:00:00 2001 From: Beherith Date: Sat, 21 Dec 2024 21:43:34 +0100 Subject: [PATCH 3/8] Clean up docs, allow getting shader object ID and buffer object ID --- rts/Lua/LuaConstPlatform.cpp | 1 + rts/Lua/LuaOpenGL.cpp | 147 +++++------------------------- rts/Lua/LuaShaders.cpp | 4 +- rts/Lua/LuaVBO.cpp | 3 +- rts/Lua/LuaVBOImpl.cpp | 11 +++ rts/Lua/LuaVBOImpl.h | 2 + rts/System/Platform/CpuID.cpp | 1 + rts/System/Platform/CpuID.h | 4 + rts/System/Platform/Threading.cpp | 4 + rts/System/Platform/Threading.h | 2 + 10 files changed, 53 insertions(+), 126 deletions(-) diff --git a/rts/Lua/LuaConstPlatform.cpp b/rts/Lua/LuaConstPlatform.cpp index 7f897c0c68..445901c2a3 100644 --- a/rts/Lua/LuaConstPlatform.cpp +++ b/rts/Lua/LuaConstPlatform.cpp @@ -109,6 +109,7 @@ bool LuaConstPlatform::PushEntries(lua_State* L) LuaPushNamedString(L, "hwConfig", Platform::GetHardwareStr()); LuaPushNamedNumber(L, "cpuLogicalCores", Threading::GetLogicalCpuCores()); LuaPushNamedNumber(L, "cpuPhysicalCores", Threading::GetPhysicalCpuCores()); + LuaPushNamedString(L, "cpuBrand", Threading::GetCPUBrand()); LuaPushNamedString(L, "sysInfoHash", Platform::GetSysInfoHash()); LuaPushNamedString(L, "macAddrHash", Platform::GetMacAddrHash()); diff --git a/rts/Lua/LuaOpenGL.cpp b/rts/Lua/LuaOpenGL.cpp index f352e12967..86ea89453c 100644 --- a/rts/Lua/LuaOpenGL.cpp +++ b/rts/Lua/LuaOpenGL.cpp @@ -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); @@ -5662,152 +5667,46 @@ int LuaOpenGL::GetMapRendering(lua_State* L) } - -/* -void glObjectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label); -Parameters - - identifier: - Specifies the type of object being labeled. Possible values include: - GL_BUFFER: Buffer object. - GL_SHADER: Shader object. - GL_PROGRAM: Program object. - GL_VERTEX_ARRAY: Vertex array object (VAO). - GL_QUERY: Query object. - GL_PROGRAM_PIPELINE: Program pipeline object. - GL_TRANSFORM_FEEDBACK: Transform feedback object. - GL_TEXTURE: Texture object. - GL_RENDERBUFFER: Renderbuffer object. - GL_FRAMEBUFFER: Framebuffer object. - - name: - Specifies the name or ID of the object to label (e.g., the result of glGenBuffers, glCreateShader, etc.). - - length: - Specifies the length of the label string. If -1, the function treats the string as null-terminated. - - label: - A null-terminated string containing the label to be assigned to the object. - -Notes - - Length Handling: - If you provide -1 as the length, OpenGL assumes the label is null-terminated. - Otherwise, you must specify the exact length of the label string. - - Debugging Tools: - The label appears in OpenGL debug outputs and tools like RenderDoc, Nsight, or apitrace. - This makes it easier to trace operations and diagnose issues related to specific OpenGL objects. - - Portability: - Supported in OpenGL 4.3 and later. - Also available with the KHR_debug extension in earlier versions of OpenGL (if supported). - */ -// 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 -// Write a a docstring as well as a comment -// Write a lua interface for this function: -// void glObjectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label); - /** - * @function gl.ObjectLabel - * @param identifier GLenum Specifies the type of object being labeled. - * @param name GLuint Specifies the name or ID of the object to label. + * @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); - GLuint name = (GLuint)luaL_checkinteger(L, 2); + 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 - glObjectLabel(identifier, name, -1, label); + glObjectLabel(identifier, objectID, -1, label); return 0; } -/* - -`glPushDebugGroup` is a function in the OpenGL API that helps developers debug and profile OpenGL applications. It is part of the `KHR_debug` extension, which is integrated into the core OpenGL since version 4.3. - -### Purpose -`glPushDebugGroup` allows you to group a set of OpenGL commands into a named debug group. This helps in identifying and organizing sections of code in the debug output, making it easier to diagnose and analyze rendering issues. - -### Function Prototype -```c -void glPushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message); -``` - -### Parameters -1. **`source`**: Specifies the source of the debug group. Common values include: - - `GL_DEBUG_SOURCE_APPLICATION`: Indicates that the debug group is defined by the application. - - `GL_DEBUG_SOURCE_THIRD_PARTY`: Indicates that the group is defined by external tools or libraries. - -2. **`id`**: A numeric identifier for the group. This can be any value that uniquely identifies the group within the scope of the source. - -3. **`length`**: The length of the `message` string. If this is `-1`, the string is assumed to be null-terminated. -4. **`message`**: A human-readable string describing the debug group. This message is used in debugging tools or logs. - -### Example Usage -```c -glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 1, -1, "Render Scene"); - -// OpenGL commands for rendering the scene -glDrawArrays(GL_TRIANGLES, 0, 36); -glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); - -glPopDebugGroup(); // End of the debug group -``` - -### Notes -- Each `glPushDebugGroup` must be matched with a corresponding `glPopDebugGroup`. -- The function adds a new debug group to the debug output stack. Groups can be nested for better organization. -- Debug groups are particularly useful when analyzing rendering performance or diagnosing errors in tools like OpenGL Debug Output or profilers. - -### Benefits -1. **Organized Debugging**: Clearly marks and groups commands for easier traceability. -2. **Better Profiling**: Tools can provide insights into specific debug groups. -3. **Improved Diagnostics**: Helps isolate and identify problematic sections of code. - -### Availability -- OpenGL 4.3 or later. -- Requires the `KHR_debug` extension in earlier versions of OpenGL (if supported). - -By using `glPushDebugGroup`, you can make debugging and profiling OpenGL applications much more structured and efficient. - -Write the lua interfaces for glPushDebugGroup and glPopDebugGroup - */ - -// 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 -// Write a a docstring as well as a comment -// Write a lua interface for this function: // https://registry.khronos.org/OpenGL-Refpages/gl4/html/glPushDebugGroup.xhtml /** - * @function gl.PushDebugGroup - * @param source GLenum Specifies the source of the debug group. + * @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) { - GLenum source = (GLenum)luaL_checkinteger(L, 1); - GLuint id = (GLuint)luaL_checkinteger(L, 2); - const char* message = luaL_checkstring(L, 3); - - if (source != GL_DEBUG_SOURCE_APPLICATION && source != GL_DEBUG_SOURCE_THIRD_PARTY) { - luaL_error(L, "Invalid source value for gl.PushDebugGroup"); - return 0; - } + 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); @@ -5817,7 +5716,7 @@ int LuaOpenGL::PushDebugGroup(lua_State* L) { return 0; } - glPushDebugGroup(source, id, -1, message); + glPushDebugGroup((source ? GL_DEBUG_SOURCE_APPLICATION: GL_DEBUG_SOURCE_THIRD_PARTY) , id, -1, message); return 0; } diff --git a/rts/Lua/LuaShaders.cpp b/rts/Lua/LuaShaders.cpp index b0b17a5d7b..0308e39c85 100644 --- a/rts/Lua/LuaShaders.cpp +++ b/rts/Lua/LuaShaders.cpp @@ -555,6 +555,7 @@ GLint LuaShaders::GetUniformLocation(LuaShaders::Program* p, const char* name) * @function gl.CreateShader ( table shaderParams ) * @tparam table shaderParams * @treturn number shaderID + * @treturn number glProgID * * ({[ vertex = "glsl code" ,] * [ tcs = "glsl code" ,] @@ -738,7 +739,8 @@ int LuaShaders::CreateShader(lua_State* L) // note: index, not raw ID lua_pushnumber(L, shaders.AddProgram(p)); - return 1; + lua_pushnumber(L, (int) prog); + return 2; } diff --git a/rts/Lua/LuaVBO.cpp b/rts/Lua/LuaVBO.cpp index 5e21066f35..3bd3d4a179 100644 --- a/rts/Lua/LuaVBO.cpp +++ b/rts/Lua/LuaVBO.cpp @@ -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 ); gl.set("VBO", sol::lua_nil); // don't want this to be accessible directly without gl.GetVBO diff --git a/rts/Lua/LuaVBOImpl.cpp b/rts/Lua/LuaVBOImpl.cpp index 8f13e3148c..90f0507017 100644 --- a/rts/Lua/LuaVBOImpl.cpp +++ b/rts/Lua/LuaVBOImpl.cpp @@ -1445,6 +1445,17 @@ void LuaVBOImpl::DumpDefinition() LOG("%s", ss.str().c_str()); } +/*** Gets the OpenGL Buffer ID + * + * @function VBO:GetID + * @treturn number buffer ID + */ +uint32_t LuaVBOImpl::GetID() +{ + VBOExistenceCheck(vbo, __func__); + return vbo->GetId(); +} + void LuaVBOImpl::AllocGLBuffer(size_t byteSize) { if (defTarget == GL_UNIFORM_BUFFER && bufferSizeInBytes > UBO_SAFE_SIZE_BYTES) { diff --git a/rts/Lua/LuaVBOImpl.h b/rts/Lua/LuaVBOImpl.h index 8c6ca3d996..e5654415b3 100644 --- a/rts/Lua/LuaVBOImpl.h +++ b/rts/Lua/LuaVBOImpl.h @@ -52,6 +52,8 @@ class LuaVBOImpl { int UnbindBufferRange(const GLuint index, const sol::optional elemOffsetOpt, const sol::optional elemCountOpt, const sol::optional targetOpt); void DumpDefinition(); + uint32_t GetID(); + public: static bool Supported(GLenum target); private: diff --git a/rts/System/Platform/CpuID.cpp b/rts/System/Platform/CpuID.cpp index 02898409e0..5bb68fdc9e 100644 --- a/rts/System/Platform/CpuID.cpp +++ b/rts/System/Platform/CpuID.cpp @@ -150,6 +150,7 @@ namespace springproc { for (int group = 0; group < system.num_cpu_types; ++group) { cpu_id_t cpu_id = system.cpu_types[group]; + cpuid_brand = std::string(cpu_id.brand_str); switch(cpu_id.purpose) { case PURPOSE_GENERAL: case PURPOSE_PERFORMANCE: diff --git a/rts/System/Platform/CpuID.h b/rts/System/Platform/CpuID.h index a3c7765ae5..f77ca2724d 100644 --- a/rts/System/Platform/CpuID.h +++ b/rts/System/Platform/CpuID.h @@ -10,6 +10,7 @@ #endif #include +#include namespace springproc { _noinline void ExecCPUID(unsigned int* a, unsigned int* b, unsigned int* c, unsigned int* d); @@ -44,6 +45,7 @@ namespace springproc { cores. */ int GetNumPhysicalCores() const { return numPhysicalCores; } int GetNumLogicalCores() const { return numLogicalCores; } + std::string GetCPUBrand() const { return cpuid_brand; } /** Total number of physical processor dies in the system. */ int GetTotalNumPackages() const { return totalNumPackages; } @@ -71,6 +73,8 @@ namespace springproc { uint64_t affinityMaskOfPackages[MAX_PROCESSORS]; uint64_t availableProceesorAffinityMask; + std::string cpuid_brand; + //////////////////////// // Intel specific fields diff --git a/rts/System/Platform/Threading.cpp b/rts/System/Platform/Threading.cpp index 92ccec0e8b..2da83e3614 100644 --- a/rts/System/Platform/Threading.cpp +++ b/rts/System/Platform/Threading.cpp @@ -213,6 +213,10 @@ namespace Threading { return springproc::CPUID::GetInstance().GetNumPhysicalCores(); } + std::string GetCPUBrand() { + return springproc::CPUID::GetInstance().GetCPUBrand(); + } + bool HasHyperThreading() { return (GetLogicalCpuCores() > GetPhysicalCpuCores()); } diff --git a/rts/System/Platform/Threading.h b/rts/System/Platform/Threading.h index 17ac5cab90..58de5d2c0a 100644 --- a/rts/System/Platform/Threading.h +++ b/rts/System/Platform/Threading.h @@ -124,6 +124,8 @@ namespace Threading { int GetLogicalCpuCores(); /// physical + hyperthreading bool HasHyperThreading(); + std::string GetCPUBrand(); + /** * Inform the OS kernel that we are a cpu-intensive task */ From 48bc40a0117417e2bfed17fdeb0e9c19ef443788 Mon Sep 17 00:00:00 2001 From: Beherith Date: Sat, 18 Jan 2025 21:33:05 +0100 Subject: [PATCH 4/8] Add the relevant identifiers to GL table --- docker-build/build_and_copy.sh | 14 +++++++++ ...ld_and_copy.sh\357\200\272Zone.Identifier" | 0 rts/Lua/LuaConstGL.cpp | 29 +++++++++++++++++++ rts/Lua/LuaOpenGL.cpp | 12 ++++++-- 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 docker-build/build_and_copy.sh create mode 100644 "docker-build/build_and_copy.sh\357\200\272Zone.Identifier" diff --git a/docker-build/build_and_copy.sh b/docker-build/build_and_copy.sh new file mode 100644 index 0000000000..e945ba3b96 --- /dev/null +++ b/docker-build/build_and_copy.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +start_time=$(date +%s) + +./build.sh -o -t RELEASE -C -DTRACY_ENABLE=1 -w + +cp ../build-windows-64-RELEASE/spring.exe "/mnt/c/Users/Peti/Documents/My Games/Spring/engine/105.1.1-2724-g34671c0 bar/spring.exe" + +end_time=$(date +%s) +elapsed_time=$((end_time - start_time)) + +echo "Copied spring.exe, elapsed time: $elapsed_time seconds" + +powershell.exe '[console]::beep(261.6,700)' \ No newline at end of file diff --git "a/docker-build/build_and_copy.sh\357\200\272Zone.Identifier" "b/docker-build/build_and_copy.sh\357\200\272Zone.Identifier" new file mode 100644 index 0000000000..e69de29bb2 diff --git a/rts/Lua/LuaConstGL.cpp b/rts/Lua/LuaConstGL.cpp index 2b24bc1252..d227d8b80f 100644 --- a/rts/Lua/LuaConstGL.cpp +++ b/rts/Lua/LuaConstGL.cpp @@ -703,6 +703,35 @@ bool LuaConstGL::PushEntries(lua_State* L) /// @field GL_STENCIL_ATTACHMENT_EXT 0x8D20 PUSH_GL(STENCIL_ATTACHMENT_EXT); + +/*** + * OpenGL Object Types + * @section objecttypes + */ + + /*** + * @table GL + * @number BUFFER + * @number SHADER + * @number PROGRAM + * @number VERTEX_ARRAY + * @number QUERY + * @number PROGRAM_PIPELINE + * @number TRANSFORM_FEEDBACK + * @number RENDERBUFFER + * @number FRAMEBUFFER + */ + PUSH_GL(BUFFER); + PUSH_GL(SHADER); + PUSH_GL(PROGRAM); + PUSH_GL(VERTEX_ARRAY); + PUSH_GL(QUERY); + PUSH_GL(PROGRAM_PIPELINE); + PUSH_GL(TRANSFORM_FEEDBACK); + PUSH_GL(RENDERBUFFER); + PUSH_GL(FRAMEBUFFER); + + return true; } diff --git a/rts/Lua/LuaOpenGL.cpp b/rts/Lua/LuaOpenGL.cpp index 86ea89453c..1ac187c042 100644 --- a/rts/Lua/LuaOpenGL.cpp +++ b/rts/Lua/LuaOpenGL.cpp @@ -5687,8 +5687,16 @@ int LuaOpenGL::ObjectLabel(lua_State* L) { // 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 + + // Check that the GLuint name refers to a valid openGL object + if (!glIsBuffer(objectID) && !glIsShader(objectID) && !glIsProgram(objectID) && + !glIsVertexArray(objectID) && !glIsQuery(objectID) && !glIsProgramPipeline(objectID) && + !glIsTransformFeedback(objectID) && !glIsTexture(objectID) && !glIsRenderbuffer(objectID) && + !glIsFramebuffer(objectID)) { + luaL_error(L, "Invalid OpenGL object ID"); + return 0; + } + glObjectLabel(identifier, objectID, -1, label); return 0; From 4837858e067db30427cbf26fa483b519342c0f14 Mon Sep 17 00:00:00 2001 From: Beherith Date: Sat, 18 Jan 2025 21:37:10 +0100 Subject: [PATCH 5/8] But remove local files --- docker-build/build_and_copy.sh | 14 -------------- .../build_and_copy.sh\357\200\272Zone.Identifier" | 0 2 files changed, 14 deletions(-) delete mode 100644 docker-build/build_and_copy.sh delete mode 100644 "docker-build/build_and_copy.sh\357\200\272Zone.Identifier" diff --git a/docker-build/build_and_copy.sh b/docker-build/build_and_copy.sh deleted file mode 100644 index e945ba3b96..0000000000 --- a/docker-build/build_and_copy.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -start_time=$(date +%s) - -./build.sh -o -t RELEASE -C -DTRACY_ENABLE=1 -w - -cp ../build-windows-64-RELEASE/spring.exe "/mnt/c/Users/Peti/Documents/My Games/Spring/engine/105.1.1-2724-g34671c0 bar/spring.exe" - -end_time=$(date +%s) -elapsed_time=$((end_time - start_time)) - -echo "Copied spring.exe, elapsed time: $elapsed_time seconds" - -powershell.exe '[console]::beep(261.6,700)' \ No newline at end of file diff --git "a/docker-build/build_and_copy.sh\357\200\272Zone.Identifier" "b/docker-build/build_and_copy.sh\357\200\272Zone.Identifier" deleted file mode 100644 index e69de29bb2..0000000000 From f26df6a4fba8456762417889271e08eb446c3c25 Mon Sep 17 00:00:00 2001 From: Beherith Date: Sun, 19 Jan 2025 19:05:51 +0100 Subject: [PATCH 6/8] fix compilation --- rts/Lua/LuaOpenGL.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/rts/Lua/LuaOpenGL.cpp b/rts/Lua/LuaOpenGL.cpp index 1ac187c042..368439b98e 100644 --- a/rts/Lua/LuaOpenGL.cpp +++ b/rts/Lua/LuaOpenGL.cpp @@ -5685,20 +5685,7 @@ int LuaOpenGL::ObjectLabel(lua_State* L) { 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 - if (!glIsBuffer(objectID) && !glIsShader(objectID) && !glIsProgram(objectID) && - !glIsVertexArray(objectID) && !glIsQuery(objectID) && !glIsProgramPipeline(objectID) && - !glIsTransformFeedback(objectID) && !glIsTexture(objectID) && !glIsRenderbuffer(objectID) && - !glIsFramebuffer(objectID)) { - luaL_error(L, "Invalid OpenGL object ID"); - return 0; - } - glObjectLabel(identifier, objectID, -1, label); - return 0; } From 1e10cdc31ae45d6d76f3da9a4ec24d47d70a0c1e Mon Sep 17 00:00:00 2001 From: Beherith Date: Sat, 25 Jan 2025 13:03:42 +0100 Subject: [PATCH 7/8] Gate gl debug functions behind GLEW_KHR_debug --- rts/Lua/LuaOpenGL.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/rts/Lua/LuaOpenGL.cpp b/rts/Lua/LuaOpenGL.cpp index 368439b98e..7744d713fa 100644 --- a/rts/Lua/LuaOpenGL.cpp +++ b/rts/Lua/LuaOpenGL.cpp @@ -5685,7 +5685,12 @@ int LuaOpenGL::ObjectLabel(lua_State* L) { GLuint objectID = (GLuint)luaL_checkinteger(L, 2); const char* label = luaL_checkstring(L, 3); - glObjectLabel(identifier, objectID, -1, label); + if (GLEW_KHR_debug){ + glObjectLabel(identifier, objectID, -1, label); + } + else { + luaL_error(L, "ObjectLabel requires GL_KHR_debug extension"); + } return 0; } @@ -5710,9 +5715,12 @@ int LuaOpenGL::PushDebugGroup(lua_State* L) { luaL_error(L, "Message length exceeds GL_MAX_DEBUG_MESSAGE_LENGTH"); return 0; } - - glPushDebugGroup((source ? GL_DEBUG_SOURCE_APPLICATION: GL_DEBUG_SOURCE_THIRD_PARTY) , id, -1, message); - + 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"); + } return 0; } From e45b71efe4746c96234e8b4468633333f0e5b8f2 Mon Sep 17 00:00:00 2001 From: Beherith Date: Sat, 25 Jan 2025 13:40:58 +0100 Subject: [PATCH 8/8] Fix headless compilation --- rts/Lua/LuaOpenGL.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/rts/Lua/LuaOpenGL.cpp b/rts/Lua/LuaOpenGL.cpp index 7744d713fa..2b970bfb99 100644 --- a/rts/Lua/LuaOpenGL.cpp +++ b/rts/Lua/LuaOpenGL.cpp @@ -5684,13 +5684,14 @@ int LuaOpenGL::ObjectLabel(lua_State* L) { } GLuint objectID = (GLuint)luaL_checkinteger(L, 2); const char* label = luaL_checkstring(L, 3); - - if (GLEW_KHR_debug){ - glObjectLabel(identifier, objectID, -1, label); - } - else { - luaL_error(L, "ObjectLabel requires GL_KHR_debug extension"); - } + #if (defined(GL_ARB_debug_output) && !defined(HEADLESS)) + if (GLEW_KHR_debug){ + glObjectLabel(identifier, objectID, -1, label); + } + else { + luaL_error(L, "ObjectLabel requires GL_KHR_debug extension"); + } + #endif return 0; } @@ -5715,12 +5716,14 @@ int LuaOpenGL::PushDebugGroup(lua_State* L) { luaL_error(L, "Message length exceeds GL_MAX_DEBUG_MESSAGE_LENGTH"); return 0; } - 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 (defined(GL_ARB_debug_output) && !defined(HEADLESS)) + 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"); + } + #endif return 0; }