Metal PSO 预热内存问题

[Image Removed]

hi,ios预热pso后,内存增长近百M,像是PSO内存没有卸载,项目里面 rhi.Metal.CacheShaderPipelines 配置的是0

发现 FMetalCompiledShaderCache 有个成员 TMap<FMetalCompiledShaderKey, mtlpp::Function> Cache,会缓存底层的 mtlpp::Function,这里是否要在 TMetalBaseShader 销毁的地方手动释放一下,比如下面这样

template<typename BaseResourceType, int32 ShaderType>
void TMetalBaseShader<BaseResourceType, ShaderType>::Destroy()
{
	@autoreleasepool{
			[GlslCodeNSString release];

			//Add Begin
			Function = nil;
			Library = nil;

			uint32 FunctionConstantHash = ConstantValueHash;
			FMetalCompiledShaderKey Key(SourceLen, SourceCRC, FunctionConstantHash);
			GetMetalCompiledShaderCache().Remove(Key);
			//Add End
	}
}

struct FMetalCompiledShaderCache
{
bool Remove(FMetalCompiledShaderKey Key)
{
	bool bReleased = false;

	@autoreleasepool{
		FRWScopeLock ScopedLock(Lock, SLT_Write);
		if (Cache.FindRef(Key) != nil)
		{
			mtlpp::Function::Type FuncPtr = Cache.FindRef(Key).GetPtr();

			LibCache.Remove(FuncPtr);

			Cache.Remove(Key);

			bReleased = true;
		}
	}
	return bReleased;
}
}




[Attachment Removed]

Steps to Reproduce
ios pso预热即可复现

[Attachment Removed]

Hi,

你好,4.27的版本确实有这个问题,mtlpp以及引擎层都有一些引用和cache导致function以及没有用到的pso没有被释放。我映像里mtlpp里也需要做一些修改,否则可能也释放不了function,之前好像看过一些,但是好像没有完成,只能给你一些线索。

另外这里有篇文章介绍了一些Vulkan上的思路,供参考 https://zhuanlan.zhihu.com/p/669562389。

[Image Removed]

[Attachment Removed]