From 4b07dcc9aa258f9af44d8c5a919a5264329584be Mon Sep 17 00:00:00 2001 From: Pursche Date: Tue, 11 Aug 2026 02:51:13 +0200 Subject: [PATCH] Fix slang global session leak in ShaderCooker SlangBridge's destructor never freed its SlangBridgeData, leaking the slang global session it owns, and ShaderCompiler::Run constructed a new SlangBridge for every shader file - one leaked global session (each holding a compiled slang core module, ~160 MB) per shader. Cooking 65 shaders peaked at ~10.1 GiB RSS and climbed monotonically, OOMing the CI runner. Delete the bridge data in the destructor and construct a single bridge above the shader loop; a global session is designed to be shared for a whole compilation run, and each redundant one was also recompiling the slang core module. Measured on a full 65-shader force recook (Release, 16 threads): peak RSS 10.1 GiB -> 272 MB, wall time 24.0s -> 11.9s. --- Source/ShaderCooker/ShaderCooker/ShaderCompiler.cpp | 4 ++-- Source/ShaderCooker/ShaderCooker/SlangBridge.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/ShaderCooker/ShaderCooker/ShaderCompiler.cpp b/Source/ShaderCooker/ShaderCooker/ShaderCompiler.cpp index 29195fb6..9c4fc04d 100644 --- a/Source/ShaderCooker/ShaderCooker/ShaderCompiler.cpp +++ b/Source/ShaderCooker/ShaderCooker/ShaderCompiler.cpp @@ -258,6 +258,8 @@ namespace ShaderCooker } else if (_stageInfo.stage == Stage::COMPILATION) { + ShaderCooker::SlangBridge slangBridge(_sourceDirPath); + for (Shader& shader : _shaders) { if (!shader.hasResolvedIncludes) @@ -269,8 +271,6 @@ namespace ShaderCooker continue; } - ShaderCooker::SlangBridge slangBridge(_sourceDirPath); - // Figure out the actual permutations u32 numPermutationGroups = static_cast(shader.permutationGroups.size()); diff --git a/Source/ShaderCooker/ShaderCooker/SlangBridge.cpp b/Source/ShaderCooker/ShaderCooker/SlangBridge.cpp index ff6a8915..83529eba 100644 --- a/Source/ShaderCooker/ShaderCooker/SlangBridge.cpp +++ b/Source/ShaderCooker/ShaderCooker/SlangBridge.cpp @@ -39,7 +39,7 @@ namespace ShaderCooker SlangBridge::~SlangBridge() { - + delete static_cast(_data); } void SlangBridge::AddDefine(const std::string& name, const std::string& value)