From f714e791fec2a4474f2a7963b058eaf2de032759 Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Thu, 28 Dec 2023 09:24:48 -0500 Subject: [PATCH 1/4] Fix memory leak in Optick when ThreadEntry is terminated while still in scope (i.e. exit) --- neo/libs/optick/optick_core.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/neo/libs/optick/optick_core.h b/neo/libs/optick/optick_core.h index ba4e319c..b53d6682 100644 --- a/neo/libs/optick/optick_core.h +++ b/neo/libs/optick/optick_core.h @@ -342,6 +342,9 @@ struct ThreadEntry { *threadTLS = nullptr; } + + // SRS - make sure thread storage is empty before thread entry terminates + storage.Clear(false); } void Activate(Mode::Type mode); void Sort(); From 6e2c63757800a3cc29a2201e2062a809f71732be Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Thu, 28 Dec 2023 09:29:47 -0500 Subject: [PATCH 2/4] valgrind: Fix uninitialized variables in debug tools - ImmediateMode and Optick --- neo/libs/optick/optick_gpu.vulkan.cpp | 1 + neo/renderer/ImmediateMode.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/neo/libs/optick/optick_gpu.vulkan.cpp b/neo/libs/optick/optick_gpu.vulkan.cpp index 5c824e08..db138155 100644 --- a/neo/libs/optick/optick_gpu.vulkan.cpp +++ b/neo/libs/optick/optick_gpu.vulkan.cpp @@ -150,6 +150,7 @@ namespace Optick queryPoolCreateInfo.flags = 0; queryPoolCreateInfo.queryType = VK_QUERY_TYPE_TIMESTAMP; queryPoolCreateInfo.queryCount = MAX_QUERIES_COUNT + 1; + queryPoolCreateInfo.pipelineStatistics = 0; VkCommandPoolCreateInfo commandPoolCreateInfo; commandPoolCreateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; diff --git a/neo/renderer/ImmediateMode.h b/neo/renderer/ImmediateMode.h index c2d6078c..f9603ad8 100644 --- a/neo/renderer/ImmediateMode.h +++ b/neo/renderer/ImmediateMode.h @@ -86,7 +86,7 @@ private: static idIndexBuffer indexBuffer; bool geometryOnly; - float currentTexCoord[2]; + float currentTexCoord[2] = {}; GFXenum currentMode; byte currentColor[4]; idImage* currentTexture; From 7d67082a1018ec13388df5a8287a02155d7ce8fb Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Thu, 28 Dec 2023 09:32:06 -0500 Subject: [PATCH 3/4] Fix clang compile failure in GuiModel: use static_cast in initializer list --- neo/renderer/GuiModel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neo/renderer/GuiModel.cpp b/neo/renderer/GuiModel.cpp index 5db04303..fc83ca3f 100644 --- a/neo/renderer/GuiModel.cpp +++ b/neo/renderer/GuiModel.cpp @@ -395,9 +395,9 @@ void idGuiModel::EmitImGui( ImDrawData* drawData ) idScreenRect clipRect = { static_cast( pcmd->ClipRect.x ), - io.DisplaySize.y - static_cast( pcmd->ClipRect.w ), + static_cast( io.DisplaySize.y - pcmd->ClipRect.w ), static_cast( pcmd->ClipRect.z ), - io.DisplaySize.y - static_cast( pcmd->ClipRect.y ), + static_cast( io.DisplaySize.y - pcmd->ClipRect.y ), 0.0f, 1.0f }; From dd17edbdc1f6a05f21a2af35cc9d10096dc5d6db Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Thu, 28 Dec 2023 09:41:18 -0500 Subject: [PATCH 4/4] Simplify OPTICK_THREAD() instrumentation and fix scope for common_frame --- neo/framework/File_SaveGame.cpp | 8 -------- neo/framework/common_frame.cpp | 6 ------ neo/idlib/ParallelJobList.cpp | 2 -- neo/idlib/Thread.cpp | 6 ++++++ neo/sys/common/savegame.cpp | 2 -- 5 files changed, 6 insertions(+), 18 deletions(-) diff --git a/neo/framework/File_SaveGame.cpp b/neo/framework/File_SaveGame.cpp index 65e2e94b..dc54eb65 100644 --- a/neo/framework/File_SaveGame.cpp +++ b/neo/framework/File_SaveGame.cpp @@ -71,8 +71,6 @@ class idSGFcompressThread : public idSysThread public: virtual int Run() { - OPTICK_THREAD( "idSGFcompressThread" ); - sgf->CompressBlock(); return 0; } @@ -83,8 +81,6 @@ class idSGFdecompressThread : public idSysThread public: virtual int Run() { - OPTICK_THREAD( "idSGFdecompressThread" ); - sgf->DecompressBlock(); return 0; } @@ -95,8 +91,6 @@ class idSGFwriteThread : public idSysThread public: virtual int Run() { - OPTICK_THREAD( "idSGFwriteThread" ); - sgf->WriteBlock(); return 0; } @@ -107,8 +101,6 @@ class idSGFreadThread : public idSysThread public: virtual int Run() { - OPTICK_THREAD( "idSGFreadThread" ); - sgf->ReadBlock(); return 0; } diff --git a/neo/framework/common_frame.cpp b/neo/framework/common_frame.cpp index 1591458c..3062c5ba 100644 --- a/neo/framework/common_frame.cpp +++ b/neo/framework/common_frame.cpp @@ -90,12 +90,6 @@ be called directly in the foreground thread for comparison. */ int idGameThread::Run() { - if( com_smp.GetBool() ) - { - // SRS - label thread in smp mode only, otherwise CPU frame number is missing - OPTICK_THREAD( "idGameThread" ); - } - commonLocal.frameTiming.startGameTime = Sys_Microseconds(); // debugging tool to test frame dropping behavior diff --git a/neo/idlib/ParallelJobList.cpp b/neo/idlib/ParallelJobList.cpp index 54b14c5d..c05857c9 100644 --- a/neo/idlib/ParallelJobList.cpp +++ b/neo/idlib/ParallelJobList.cpp @@ -1145,8 +1145,6 @@ idJobThread::Run */ int idJobThread::Run() { - OPTICK_THREAD( GetName() ); - threadJobListState_t threadJobListState[MAX_JOBLISTS]; int numJobLists = 0; int lastStalledJobList = -1; diff --git a/neo/idlib/Thread.cpp b/neo/idlib/Thread.cpp index 1be284cd..5405284d 100644 --- a/neo/idlib/Thread.cpp +++ b/neo/idlib/Thread.cpp @@ -237,12 +237,18 @@ int idSysThread::ThreadProc( idSysThread* thread ) break; } + // SRS - generalize thread instrumentation with correct Run() scope + OPTICK_THREAD( thread->GetName() ); + retVal = thread->Run(); } thread->signalWorkerDone.Raise(); } else { + // SRS - generalize thread instrumentation with correct Run() scope + OPTICK_THREAD( thread->GetName() ); + retVal = thread->Run(); } } diff --git a/neo/sys/common/savegame.cpp b/neo/sys/common/savegame.cpp index e5c63e49..1cdfa4f6 100644 --- a/neo/sys/common/savegame.cpp +++ b/neo/sys/common/savegame.cpp @@ -747,8 +747,6 @@ idSaveGameThread::Run */ int idSaveGameThread::Run() { - OPTICK_THREAD( "idSaveGameThread" ); - int ret = ERROR_SUCCESS; try